Dear James,
On Mon, Jul 5, 2010 at 12:31 PM, James Davidson <[email protected]> wrote:
>
> I have been exploring some interactivity between PyMOL and RDKit recently,
> and at the moment am ferrying molecules between the two in MOL format.
> However, I have come up against a bit of a problem that I wondered if anyone
> could help with?
>
> PyMOL does a pretty good job of setting bond valences automatically for
> ligands read-in as part of PDB files, and most of the time these ligands
> exported in MOL format are recognised fine by RDKit (a little bit of parsing
> is necessary to change things like 'Cl' being capitalised in some PDB files,
> etc!). However, it seems that when there is ambiguity about how to
> tautomerise 5-membered heteroaromatics, RDKit fails to create a mol object
> from the molfile. I have included an example Molfile below (a
> pyrazolopyrimidine).
>
> Ideally (from my point of view at least!) it would be great if in these
> situations RDKit yielded an arbitrary explicit H to 'mend' the problem.
> However, I am definitely open to workaround suggestions (including "go post
> on the PyMOL lists" :-) ). Maybe this is something that is relatively
> trivial to tackle using PyMOL's ChemPy module? (which I know very little
> about!).
As long as it's really ok that the tautomer you get is arbitrary, the
following code snippet might help :
#------------------------------------------------
def AdjustAromaticNs(m):
matches = [x[0] for x in m.GetSubstructMatches(Chem.MolFromSmarts('n'))]
foundOne=False
for idx in matches:
nm = Chem.Mol(m.ToBinary())
nm.GetAtomWithIdx(idx).SetNoImplicit(True)
nm.GetAtomWithIdx(idx).SetNumExplicitHs(1)
try:
Chem.SanitizeMol(nm)
except:
continue
else:
foundOne=True
break
if foundOne:
return nm
else:
return None
#------------------------------------------------
Use it like this:
#-----------
m = Chem.MolFromMolBlock(mb,False)
try:
Chem.SanitizeMol(m)
except ValueError:
nm=AdjustAromaticNs(m)
if nm is not None:
print Chem.MolToSmiles(nm)
#-------------
One could imagine making this more efficient or adding heuristics to
try and find the right answer more efficiently, but this ought to at
least get you started.
-greg
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss