Skip to content

Instantly share code, notes, and snippets.

@leelasd
Created July 23, 2018 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leelasd/b58217e3121d01723f41ce7b176c8c9b to your computer and use it in GitHub Desktop.
Save leelasd/b58217e3121d01723f41ce7b176c8c9b to your computer and use it in GitHub Desktop.
Write SDF file from bunch of mol files
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