Hi there Chan, Others,

First of all, many thanks for the helpful example and the explanation --
but I require some further clarification more specifically about the
following:

m = Chem.MolFromSmiles('O')
print m.GetAtomWithIdx(0).GetNumImplicitHs()
print m.GetAtomWithIdx(0).GetNumExplicitHs()
print m.GetAtomWithIdx(0).GetTotalNumHs()

m = Chem.MolFromSmiles('[OH2]')
print m.GetAtomWithIdx(0).GetNumImplicitHs()
print m.GetAtomWithIdx(0).GetNumExplicitHs()
print m.GetAtomWithIdx(0).GetTotalNumHs()

m = Chem.MolFromSmiles('O([H])[H]')
print m.GetAtomWithIdx(0).GetNumImplicitHs()
print m.GetAtomWithIdx(0).GetNumExplicitHs()
print m.GetAtomWithIdx(0).GetTotalNumHs()

## Results:
2 0 2
0 2 2
2 # ?? 0 # ?? 2

Why aren't the results of [OH2] and O([H])[H] the same?  is this another
SMILES gotcha?  Am I not declaring the Hs explicitly in both cases?  You
see why I am confused?

Your example works fine, unless the user specifies C(=O)[OH] - in that case
I need to remove the H manually in an editable mol (or I get the incorrect
valency errors).

Also this must be related to Greg's "Rethinking the RDKit's implicit
Hydrogen handling" (
https://www.mail-archive.com/[email protected]/msg00077.html).
 Does anyone know if this has been implemented? (My guess by reading the
Atom API doc is no
http://www.rdkit.org/Python_Docs/rdkit.Chem.rdchem.Atom-class.html)

Thank you all for your help!
JP


-
Jean-Paul Ebejer
Early Stage Researcher


On 15 January 2014 06:28, S.L. Chan <[email protected]> wrote:

>
>   ----- Forwarded Message -----
>  *From:* S.L. Chan <[email protected]>
> *To:* JP <[email protected]>
> *Sent:* Tuesday, January 14, 2014 10:03 PM
> *Subject:* Re: [Rdkit-discuss] Add a charge to an atom and modify Hs
> accordingly (protonation)
>
> Hello JP,
>
> You need to bear in mind that by default RDKit does not store the
> hydrogens explicitly. RemoveHs() generally does not do anything on
> a fresh molecule, and GetNumExplicitHs() generally returns 0 for all
> atoms.
>
> Implicit hydrogens mean the hydrogen atoms implied.
> GetNumImplicitHs() returns the number of hydrogens EXPECTED to
> be bonded to that atom. This is why it returned 1 even though
> your molecule did not have explicit hydrogens.
>
> With these in mind you should be able to achieve what you want:
>
> >>> m = Chem.MolFromSmiles('C(=O)O')
> >>> m2 = Chem.AddHs(m)
> >>> m2.GetNumAtoms()
> 5
> >>> m.GetAtomWithIdx(2).SetFormalCharge(-1)
> >>> Chem.SanitizeMol(m)
> >>> m3 = Chem.AddHs(m)
> >>> m3.GetNumAtoms()
> 4
> >>> Chem.MolToSmiles(m)
> 'O=C[O-]'
>
> Finally, remember that AddHs() does not generate coordinates for
> the hydrogens. You need to use AllChem.EmbedMolecule() if you
> need coordinates for them.
>
> Ling
>
>
>
>   ------------------------------
>  *From:* JP <[email protected]>
> *To:* "[email protected]" <
> [email protected]>
> *Sent:* Tuesday, January 14, 2014 10:58 AM
> *Subject:* [Rdkit-discuss] Add a charge to an atom and modify Hs
> accordingly (protonation)
>
> Hi there,
>
> This must be really easy -- but anything I am trying is failing and I am
> losing my mind.  I want to add a charge (+ / -) to an atom and add or
> delete a connected H accordingly.
>
> I thought an easy way to do this was to remove all Hs from the molecule
> (removeHs), add a charge (SetFormalCharge), and re-add all Hs (AddHs).
>  This doesn't work (the sanitization check fails in AddHs, incorrect
> valence - which I understand) - what is the best way to do this?
>
> Also,
>
> >>> m = Chem.MolFromSmiles('C(=O)O')
> >>> m.Debug()
> Atoms:
> 0 6 C chg: 0  deg: 2 exp: 3 imp: 1 hyb: 3 arom?: 0 chi: 0
>  1 8 O chg: 0  deg: 1 exp: 2 imp: 0 hyb: 3 arom?: 0 chi: 0
> 2 8 O chg: 0  deg: 1 exp: 1 imp: 1 hyb: 3 arom?: 0 chi: 0
> Bonds:
> 0 0->1 order: 2 conj?: 1 aromatic?: 0
> 1 0->2 order: 1 conj?: 1 aromatic?: 0
> >>> m_noHs = Chem.RemoveHs(m)
> >>> m_noHs.Debug()
> Atoms:
> 0 6 C chg: 0  deg: 2 exp: 3 imp: 1 hyb: 3 arom?: 0 chi: 0
> 1 8 O chg: 0  deg: 1 exp: 2 imp: 0 hyb: 3 arom?: 0 chi: 0
>  2 8 O chg: 0  deg: 1 exp: 1 imp: 1 hyb: 3 arom?: 0 chi: 0
> Bonds:
> 0 0->1 order: 2 conj?: 1 aromatic?: 0
>  1 0->2 order: 1 conj?: 1 aromatic?: 0
>
> >>> m_noHs.GetAtomWithIdx(2).GetNumExplicitHs()
> 0
> >>> m_noHs.GetAtomWithIdx(2).GetNumImplicitHs()
> 1
>
> Why is there still an implicit H after I "removed" them?
>
> I have tried to use ReplaceSubstructs() for this (a bit of an overkill)
> but I then lose the 3D information of the original atom.
>
> Many Thanks... and sorry for the repeated spamming :((((
>
> -
> Jean-Paul Ebejer
> Early Stage Researcher
>
>
> ------------------------------------------------------------------------------
> CenturyLink Cloud: The Leader in Enterprise Cloud Services.
> Learn Why More Businesses Are Choosing CenturyLink Cloud For
> Critical Workloads, Development Environments & Everything In Between.
> Get a Quote or Start a Free Trial Today.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
> _______________________________________________
> Rdkit-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
>
>
>
>
>
> ------------------------------------------------------------------------------
> CenturyLink Cloud: The Leader in Enterprise Cloud Services.
> Learn Why More Businesses Are Choosing CenturyLink Cloud For
> Critical Workloads, Development Environments & Everything In Between.
> Get a Quote or Start a Free Trial Today.
>
> http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
> _______________________________________________
> Rdkit-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
>
------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
Rdkit-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to