-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path2_generate_frag_sdf.py
36 lines (30 loc) · 1.48 KB
/
2_generate_frag_sdf.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
import os
from glob import glob
import shutil
import subprocess
from subprocess import PIPE
nodes = ['CuCu']
# change to the line below to reproduce paper result
# nodes = [i.split('_')[1].split('.sdf')[0] for i in os.listdir('data/conformers') if 'conformers' in i]
# create necessary folders
os.makedirs(f'data/sdf',exist_ok=True)
for node in nodes:
print(f'Now on node {node}')
TARGET_DIR = f'data/sdf/{node}/'
INPUT_SMILES=f'data/fragments_smi/frag_{node}.txt'
OUTPUT_TEMPLATE=f'hMOF'
OUT_DIR=f'data/fragments_all/{node}/'
CORES='18'
# generate sdf of molecular fragments
print('Generating molecule sdf files...')
os.makedirs(TARGET_DIR,exist_ok=True)
subprocess.run([f'python -W ignore utils/rdkit_conf_parallel.py {INPUT_SMILES} {OUTPUT_TEMPLATE} --cores {CORES}'],shell=True,stdout=PIPE,stderr=PIPE)
for sdf in glob('*.sdf'):
shutil.move(sdf,TARGET_DIR)
# generate sdf for fragment and connection atom
print(f'Generating fragment and connection atom sdf files...')
os.makedirs(OUT_DIR,exist_ok=True)
subprocess.run(f'python -W ignore utils/prepare_dataset_parallel.py --table {INPUT_SMILES} --sdf-dir {TARGET_DIR} --out-dir {OUT_DIR} --template {OUTPUT_TEMPLATE} --cores {CORES}',shell=True)
# filter and merge
print(f'Filtering and merging ...')
subprocess.run(f'python -W ignore utils/filter_and_merge.py --in-dir {OUT_DIR} --out-dir {OUT_DIR} --template {OUTPUT_TEMPLATE} --number-of-files {CORES}',shell=True)