Skip to content

Instantly share code, notes, and snippets.

@abhik1368
Created July 21, 2014 14:58
Show Gist options
  • Save abhik1368/332a22bc7f8c5df36204 to your computer and use it in GitHub Desktop.
Save abhik1368/332a22bc7f8c5df36204 to your computer and use it in GitHub Desktop.
inchifrommol
# Create function
create or replace function inchi_mol(x text)
returns text
AS $$
from rdkit import Chem
from rdkit.Chem import AllChem
file = open("/home/chembl/logerror2.txt","a")
try :
m=Chem.MolFromInchi(x)
if m is not None :
try:
AllChem.Compute2DCoords(m)
except (RuntimeError,ValueError,TypeError,Exception):
pass
file.write("2DCoords Error:")
file.write(x)
file.write("\n")
try :
return Chem.MolToMolBlock(m)
except (RuntimeError,ValueError,TypeError,Exception) :
pass
file.write("Molblock Error:")
file.write(x)
file.write("\n")
else:
file.write("Inchi to Mol Error:")
file.write(x)
file.write("\n")
except :
pass
file.write("Mol Error:")
file.write("\n")
file.close()
$$ LANGUAGE plpython2u SECURITY DEFINER ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment