-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain.py
66 lines (44 loc) · 1.72 KB
/
Main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import sys
sys.path.insert(0, './Modules/')
import numpy as np
from file_reader import read_file
from mol_utils import get_fragments
from build_encoding import get_encodings, encode_molecule, decode_molecule, encode_list, save_decodings
from models import build_models
from training import train
from rewards import clean_good
from rdkit import rdBase
import logging
logging.getLogger().setLevel(logging.INFO)
rdBase.DisableLog('rdApp.error')
def main(fragment_file, lead_file):
fragment_mols = read_file(fragment_file)
lead_mols = read_file(lead_file)
fragment_mols += lead_mols
logging.info("Read %s molecules for fragmentation library", len(fragment_mols))
logging.info("Read %s lead moleculs", len(lead_mols))
fragments, used_mols = get_fragments(fragment_mols)
logging.info("Num fragments: %s", len(fragments))
logging.info("Total molecules used: %s", len(used_mols))
assert len(fragments)
assert len(used_mols)
encodings, decodings = get_encodings(fragments)
save_decodings(decodings)
logging.info("Saved decodings")
lead_mols = np.asarray(fragment_mols[-len(lead_mols):])[used_mols[-len(lead_mols):]]
X = encode_list(lead_mols, encodings)
logging.info("Building models")
actor, critic = build_models(X.shape[1:])
X = clean_good(X, decodings)
logging.info("Training")
history = train(X, actor, critic, decodings)
logging.info("Saving")
np.save("History/history.npy", history)
if __name__ == "__main__":
fragment_file = "Data/molecules.smi"
lead_file = "Data/dopamineD4props.csv"
if len(sys.argv) > 1:
fragment_file = sys.argv[1]
if len(sys.argv) > 2:
lead_file = sys.argv[2]
main(fragment_file, lead_file)