One more piece that might help: the allHsExplicit to MolToSmiles() is there
to make sure that implicit Hs (Hs not actually in the graph) show up in the
output SMILES inside square brackets:
 In [12]: m = Chem.MolFromSmiles('CC(O)(Cl)')

In [13]: Chem.MolToSmiles(m,allHsExplicit=True)
Out[13]: '[CH3][CH]([OH])[Cl]'

If you actually have Hs in the molecular graph they will always be in the
output SMILES, you don't need to use the allHsExplicit argument::
In [17]: m = Chem.MolFromSmiles('CC(O)(Cl)')

In [18]: mh = Chem.AddHs(m)

In [19]: Chem.MolToSmiles(mh)
Out[19]: '[H]OC([H])(Cl)C([H])([H])[H]'

-greg




On Mon, Dec 19, 2016 at 1:00 AM, Paolo Tosco <paolo.to...@unito.it> wrote:

> Dear Jean-Marc,
>
> as lactic2.sdf is a 3D structure which does not carry any stereochemistry
> information in the SDF file, you will need to perceive stereochemistry from
> the 3D structure with
>
> Chem.AssignAtomChiralTagsFromStructure(mol)
>
> before calling Chem.AssignStereochemistry().
> It looks like allHsExplicit=True prevents SMILES chirality specifications
> from being output:
>
> In [1]: from rdkit import Chem
>
> In [2]: molfilename = "lactic2.sdf"
>
> In [3]: mol = Chem.SDMolSupplier(molfilename, removeHs = False)[0]
>
> In [4]: Chem.AssignAtomChiralTagsFromStructure(mol)
>
> In [5]: Chem.AssignStereochemistry(mol, cleanIt=False, force=False,
> flagPossibleStereoCenters=True)
>
> In [6]: chiralAtoms = [a for a in mol.GetAtoms() if
> a.HasProp("_ChiralityPossible")]
>
> In [7]: chiralAtomNums = [a.GetIdx()+1 for a in chiralAtoms]
>
> In [8]: chiralAtomNums
> Out[8]: [4]
>
> In [9]: configs = [a.GetProp("_CIPCode") for a in chiralAtoms]
>
> In [10]: configs
> Out[10]: ['S']
>
> In [11]: smi = Chem.MolToSmiles(mol, isomericSmiles=True)
>
> In [12]: smi
> Out[12]: '[H]OC(=O)[C@@]([H])(O[H])C([H])([H])[H]'
>
> In [13]: smi = Chem.MolToSmiles(mol, isomericSmiles=True,
> allHsExplicit=True)
>
> In [14]: smi
> Out[14]: '[H][O][C](=[O])[C]([H])([O][H])[C]([H])([H])[H]'
>
>
> Cheers,
> p.
>
>
> On 12/18/2016 11:29 PM, Jean-Marc Nuzillard wrote:
>
> Hi again,
>
> When I run:
>
> #------------
> from rdkit import Chem
>
> molfilename = "lactic2.sdf"
> mol = Chem.SDMolSupplier(molfilename, removeHs = False)[0]
>
> Chem.AssignStereochemistry(mol, cleanIt=False, force=False,
> flagPossibleStereoCenters=True)
> chiralAtoms = [a for a in mol.GetAtoms() if a.HasProp("_ChiralityPossible")]
>
> chiralAtomNums = [a.GetIdx()+1 for a in chiralAtoms]
> print "chiral centers: ",
> print chiralAtomNums
> configs = [a.GetProp("_CIPCode") for a in chiralAtoms]
> print configs
>
> smi = Chem.MolToSmiles(mol, isomericSmiles=True, allHsExplicit=True)
> print smi
> #------------
>
> Two (related?) problems arise.
> First, _CIPCode rises a KeyError, even for atoms for which
> _ChiralityPossible is defined.
> When I comment the lines that define and print the configs variable, the
> second problem arises.
> The string smi does not contain any '@' or '@@', something I expected from
> a chiral molecule
> for an isomeric smiles string.
>
> The attached lactic2.sdf file comes from PubChem. I removed (set to 0) the
> parity flag for atom 4 (index 3)
> because there are no parity flags in the files I will have to deal with
> later.
> Keeping the parity flag does not change anything.
>
> What did I miss?
>
> All the best,
>
> Jean-Marc
>
>
>
> ------------------------------------------------------------------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
>
>
>
> _______________________________________________
> Rdkit-discuss mailing 
> listRdkit-discuss@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
>
>
> ------------------------------------------------------------
> ------------------
> Check out the vibrant tech community on one of the world's most
> engaging tech sites, SlashDot.org! http://sdm.link/slashdot
> _______________________________________________
> Rdkit-discuss mailing list
> Rdkit-discuss@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/rdkit-discuss
>
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most 
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to