Created
July 23, 2018 14:24
-
-
Save leelasd/b58217e3121d01723f41ce7b176c8c9b to your computer and use it in GitHub Desktop.
Write SDF file from bunch of mol files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob | |
import rdkit | |
from rdkit import Chem | |
from rdkit.Chem import AllChem | |
import pandas as pd | |
#csvs = glob.glob('CSVS/*.csv') | |
csvs = open('List','r').readlines() | |
mol_list = ['MOLS/'+m[5:-4]+'mol' for m in csvs] | |
#fnames = pd.read_csv('ListMols',header=None) | |
#fnames.columns = ['MOL'],sanitize=False,strictParsing=False | |
w = Chem.SDWriter('database.sdf') | |
#mol_array = {} | |
for m in mol_list: | |
mol = Chem.MolFromMolFile(m,removeHs=False) | |
print(m) | |
if mol is not None: | |
df = pd.read_csv('CSVS/'+m[5:-4]+'.csv',na_filter = False,na_values=['_']) | |
mol.SetProp('OplsFF',df.to_string(index=False)) | |
mol.SetProp('Charge','%3.2f'%df.Q.sum()) | |
mol.SetProp("_Name","%s"%m) | |
w.write(mol) | |
else: print(m) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment