Hi Nick,
On Mon, Oct 28, 2013 at 3:34 PM, Nicholas Firth <[email protected]>wrote:
>
> I am seeing some weird behaviour from the adding an atom and a bond to an
> EditableMol. It works fine in most cases however for this particular
> fragment I'm getting an extra hydrogen being added on for some reason.
>
> >>> mol = Chem.MolFromSmiles('O=C1NC2=C(N1)C(=O)NC(=O)N2')
> >>> Chem.Kekulize(mol, clearAromaticFlags = True)
> >>> tempMol = Chem.EditableMol(mol)
> >>> firstIdx = tempMol.AddAtom(dumAtom)
> >>> tempMol.AddBond(8, firstIdx, Chem.BondType.SINGLE)
> 14
> >>> print Chem.MolToSmiles(tempMol.GetMol())
> [*][NH]1C(=O)NC2=C(NC(=O)N2)C1=O
>
> So this molecule is not RDKit friendly, I don't really know why this is
> happening. I guess some form of conversion of an implicit hydrogen to an
> explicit hydrogen...
>
> Is there any way of stopping the magic hydrogen from appearing? Or away of
> easily getting rid of it after it's appeared?
>
The problem is the aromatic N. Here's a simpler example that shows the same
thing:
>>> mol = Chem.MolFromSmiles('N1C=CC=C1')
>>> Chem.Kekulize(mol,clearAromaticFlags=True)
>>> tempMol = Chem.EditableMol(mol)
>>> idx = tempMol.AddAtom(Chem.Atom(0))
>>> tempMol.AddBond(idx,0,Chem.BondType.SINGLE)
6
>>> nm = tempMol.GetMol()
>>> print Chem.MolToSmiles(nm)
[*][NH]1C=CC=C1
Here's what's happening: when you build the initial molecule, aromaticity
is assigned and the N atom has an "explicit" H marker added. When you
kekuulize the structure, the aromaticity flags get cleared away, but that H
is still there. This causes problems when you form the dummy bond to the N.
I need to look at it a bit to be sure, but this feels like an easily
fixable bug to me. If so I will go ahead and fix it. If it turns out to be
more complicated than I think, you can clean up the mess manually in your
code by doing something like this:
>>> mol = Chem.MolFromSmiles('N1C=CC=C1',sanitize=False)
>>> Chem.Kekulize(mol,clearAromaticFlags=True)
>>> for atom in mol.GetAtoms():
... if atom.GetAtomicNum() in (7,15,16) and atom.GetNumExplicitHs()==1:
... atom.SetNumExplicitHs(0)
...
>>> tempMol = Chem.EditableMol(mol)
>>> idx = tempMol.AddAtom(Chem.Atom(0))
>>> tempMol.AddBond(idx,0,Chem.BondType.SINGLE)
6
>>> nm = tempMol.GetMol()
>>> print Chem.MolToSmiles(nm)
[*]N1C=CC=C1
-greg
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss