-
Notifications
You must be signed in to change notification settings - Fork 21
/
generate_example_data.py
37 lines (28 loc) · 1.05 KB
/
generate_example_data.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
"""
Generate example data starting from a .smi file.
We use QED of molecules as an example.
"""
import argparse
import os
from rdkit import Chem
from rdkit.Chem import QED
parser = argparse.ArgumentParser()
parser.add_argument("input_filepath", type=str, help="path to the .smi file.")
parser.add_argument("output_filepath", type=str, help="output where to store the data.")
def main() -> None:
"""Generate example data."""
args = parser.parse_args()
input_filepath = args.input_filepath
output_filepath = args.output_filepath
with open(input_filepath, "rt") as fpr:
with open(output_filepath, "wt") as fpw:
smiles_generator = (line.strip().split("\t")[0] for line in fpr)
for smiles in smiles_generator:
try:
fpw.write(
f"<qed>{QED.qed(Chem.MolFromSmiles(smiles)):.4}|{smiles}{os.linesep}"
)
except Exception:
print(f"Problem processing SMILES={smiles}")
if __name__ == "__main__":
main()