-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate_smiles.py
45 lines (33 loc) · 1.04 KB
/
create_smiles.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
import numpy as np
from rdkit import Chem
import pickle
from tqdm import tqdm
from protein_ligand import PDBProtein, parse_sdf_file
data_path = "./data/crossdocked/crossdocked_pocket10/crossdocked_pocket10/"
index_path = './data/crossdocked/crossdocked_pocket10/index.pkl'
with open(index_path, 'rb') as f:
index = pickle.load(f)
filtered_index = []
for pl in index:
if(pl[3]<=0.5):
if(None not in pl):
filtered_index.append(pl)
print(len(filtered_index))
all_smiles = ''
# filtered_index = filtered_index[:10]
for ix in tqdm(range(len(filtered_index))):
protein_ligand = index[ix]
if(None in protein_ligand): continue
ligand_path = data_path + protein_ligand[1]
try:
rdmol = next(iter(Chem.SDMolSupplier(ligand_path)))
smiles = Chem.MolToSmiles(rdmol)
all_smiles += smiles
all_smiles += ', '
all_smiles += protein_ligand[1]
all_smiles += '\n'
except:
pass
with open('smiles_2.csv', 'w') as f:
f.write(all_smiles)
# print(all_smiles)