Hi Pavel,

After you have first called AddHs(), all hydrogens in your molecule are now in the molecule graph as real atoms, and there are no more implicit/explicit Hs .

Therefore, when you call RemoveAtom(), you are removing a real atom from the molecule graph, and the implicit/explicit H count stays 0 for the parent heavy atom. Hence calling again AddHs() does not add any hydrogens.

If you wish the hydrogen to come back when you call AddHs(), you need to increase the explicit H count on the parent heavy atom:

print('---- load mol ----')
m = Chem.MolFromSmiles('c1ccccc1O')
print(Chem.MolToSmiles(m, allHsExplicit=True))
print('---- add Hs ----')
m = Chem.AddHs(m)
print(Chem.MolToSmiles(m, allHsExplicit=True))
print('---- remove H ----')
nbrs = m.GetAtomWithIdx(7).GetNeighbors()
if (len(nbrs) == 1 and nbrs[0].GetAtomicNum() > 1):
    nbrs[0].SetNumExplicitHs(nbrs[0].GetNumExplicitHs() + 1)
em = Chem.EditableMol(m)
em.RemoveAtom(7)
print(Chem.MolToSmiles(em.GetMol(), allHsExplicit=True))
print('---- add Hs ----')
mm = Chem.AddHs(em.GetMol())
print(Chem.MolToSmiles(mm, allHsExplicit=True))

---- load mol ----
[OH][c]1[cH][cH][cH][cH][cH]1
---- add Hs ----
[H][O][c]1[c]([H])[c]([H])[c]([H])[c]([H])[c]1[H]
---- remove H ----
[H][O][c]1[cH][c]([H])[c]([H])[c]([H])[c]1[H]
---- add Hs ----
[H][O][c]1[c]([H])[c]([H])[c]([H])[c]([H])[c]1[H]

HTH, cheers,
p.

On 03/22/19 10:20, Pavel wrote:

Hello,

  I encountered with an issue which I cannot understand and solve. This might be a bug or a feature. After removal of some specific hydrogens I could not add them back. Is it expected behavior or should I create an issue on github?

print('---- load mol ----')
m = Chem.MolFromSmiles('c1ccccc1O')
print(Chem.MolToSmiles(m, allHsExplicit=True))
print('---- add Hs ----')
m = Chem.AddHs(m)
print(Chem.MolToSmiles(m, allHsExplicit=True))
print('---- remove H ----')
em = Chem.EditableMol(m)
em.RemoveAtom(7)
print(Chem.MolToSmiles(em.GetMol(), allHsExplicit=True))
print('---- add Hs ----')
mm = Chem.AddHs(em.GetMol())
print(Chem.MolToSmiles(mm, allHsExplicit=True))
print('---- update property cache ----')
mm.UpdatePropertyCache()
print(Chem.MolToSmiles(mm, allHsExplicit=True))

output:

---- load mol ----
[OH][c]1[cH][cH][cH][cH][cH]1
---- add Hs ----
[H][O][c]1[c]([H])[c]([H])[c]([H])[c]([H])[c]1[H]
---- remove H ----
[H][O][c]1[c][c]([H])[c]([H])[c]([H])[c]1[H]
---- add Hs ----
[H][O][c]1[c][c]([H])[c]([H])[c]([H])[c]1[H]
---- update property cache ----
[H][O][c]1[c][c]([H])[c]([H])[c]([H])[c]1[H]

Pavel.




_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to