Created
December 10, 2015 16:39
-
-
Save leelasd/4722019e6db12a702f42 to your computer and use it in GitHub Desktop.
RDKit sample program
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 sys | |
import re | |
import numpy as np | |
import csv | |
from rdkit import Chem | |
names = open('fns') | |
def raa(fname): | |
m=Chem.MolFromMolFile('../'+fname) | |
natoms=len(m.GetAtoms()) | |
var=[] | |
aroma=[] | |
report="" | |
for i in range(0,natoms): | |
var.append(m.GetAtomWithIdx(i).IsInRing()) | |
aroma.append(m.GetAtomWithIdx(i).GetIsAromatic()) | |
if any(e is True for e in var)==True: | |
report=" Ring " | |
if any(e is True for e in aroma)==True: | |
report+="& Aromatic " | |
else: | |
report+=" noncyclic " | |
return report | |
grpnames=[] | |
fnames=[] | |
for name in names: | |
word=name.split() | |
m=Chem.MolFromMolFile('../'+word[0]) | |
grpnames.append(Chem.MolToSmiles(m)) | |
fnames.append(word[0]) | |
grpnames=np.array(grpnames) | |
fnames=np.array(fnames) | |
writer=csv.writer(open("Groups.csv","w")) | |
writer.writerows(zip(fnames,grpnames)) | |
####################################################### | |
halpatterns=['Cl','Br','F','I'] | |
#halpatterns=['I'] | |
nhalide=0 | |
for i in range(0,len(grpnames)): | |
dec=False | |
for pattern in halpatterns: | |
if re.search(pattern,grpnames[i]): | |
dec = dec | True | |
if dec == True: | |
nhalide+=1 | |
# print '%s %15s '%(fnames[i],grpnames[i]) | |
print 'Total No of Halides: %5d'%(nhalide) | |
######################################################## | |
ionpatterns=['\[N\+\]\(=O\)\[O\-\]','O\=\[N\+\]\(\[O\-\]\)'] | |
nion=0 | |
for i in range(0,len(grpnames)): | |
dec=False | |
for pattern in ionpatterns: | |
if re.search(pattern,grpnames[i]): | |
dec = dec | True | |
if dec == True: | |
nion+=1 | |
# print '%s %15s '%(fnames[i],grpnames[i]) | |
print 'Total No of Nitro compounds: %5d'%(nion) | |
######################################################## | |
roh=['CO$','^OC','C\(O\)'] | |
noh=0 | |
for i in range(0,len(grpnames)): | |
dec=False | |
for pattern in roh: | |
if re.search(pattern,grpnames[i]): | |
dec = dec | True | |
if dec == True: | |
noh+=1 | |
# print '%s %15s '%(fnames[i],grpnames[i]) | |
print 'Total No of Alcohols: %5d'%(noh) | |
######################################################## | |
rcoh=['[^O^=]C=O','O=C[^O^=]'] | |
ncoh=0 | |
for i in range(0,len(grpnames)): | |
dec=False | |
for pattern in rcoh: | |
if re.search(pattern,grpnames[i]): | |
dec = dec | True | |
if dec == True: | |
ncoh+=1 | |
# print '%s %15s '%(fnames[i],grpnames[i]) | |
print 'Total No of Aldehydes: %5d'%(ncoh) | |
######################################################## | |
#rnh=['CN$','^NC[^(]','CN','(C)N'] | |
#rnh=['CN$','NC.[^=^C]'] | |
#nnh=0 | |
#for pattern in rnh: | |
# for i in range(0,len(grpnames)): | |
# if re.search(pattern,grpnames[i]): | |
# nnh+=1 | |
# print '%s %15s '%(fnames[i],grpnames[i]) | |
#print 'Total No of Amines: %5d'%(nnh) | |
######################################################## | |
rcn=['C[#]N','N[#]C'] | |
ncn=0 | |
for i in range(0,len(grpnames)): | |
dec=False | |
for pattern in rcn: | |
if re.search(pattern,grpnames[i]): | |
dec = dec | True | |
if dec == True: | |
ncn+=1 | |
# print '%s %15s '%(fnames[i],grpnames[i]) | |
print 'Total No of Nitriles: %5d'%(ncn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment