Calling AssignStereochemistry() after you have called SantizeMol() should resolve this.
On Fri, Jan 15, 2021 at 3:48 AM Francois Berenger <mli...@ligand.eu> wrote: > On 14/01/2021 18:36, Greg Landrum wrote: > > Hi Francois, > > > > I would do this by setting the stereo to either STEREOCIS or > > STEREOTRANS and then calling Chem.AssignStereoChemistry(): > > > > In [6]: rwmol = Chem.RWMol() > > ...: # create the atoms > > ...: a0 = Chem.Atom(6) > > ...: a1 = Chem.Atom(7) > > ...: a2 = Chem.Atom(6) > > ...: a3 = Chem.Atom(16) > > ...: # add the atoms > > ...: rwmol.AddAtom(a0) > > ...: rwmol.AddAtom(a1) > > ...: rwmol.AddAtom(a2) > > ...: rwmol.AddAtom(a3) > > ...: # add the bonds > > ...: rwmol.AddBond(0, 1, rdkit.Chem.rdchem.BondType.SINGLE) > > ...: rwmol.AddBond(1, 2, rdkit.Chem.rdchem.BondType.DOUBLE) > > ...: rwmol.AddBond(2, 3, rdkit.Chem.rdchem.BondType.SINGLE) > > Out[6]: 3 > > > > In [7]: db = rwmol.GetBondWithIdx(1) > > > > In [8]: db.SetStereoAtoms(0,3) > > > > In [9]: db.SetStereo(Chem.BondStereo.STEREOCIS) > > > > In [10]: Chem.MolToSmiles(rwmol) > > Out[10]: 'CN=CS' > > > > In [11]: Chem.AssignStereochemistry(rwmol) > > > > In [12]: Chem.MolToSmiles(rwmol) > > Out[12]: 'C/N=C\\S' > > Here is the fun part: > > Chem.SanitizeMol(rwmol) > print(Chem.MolToSmiles(rwmol)) # --> CN=CS > > "Sanitization" of the rwmol got rid of the stereo info that > we just inserted. > > Is this a "feature" of SanitizeMol? > > I was being a good kid, I thought that someone must always sanitize > a RWMol prior to extracting the final resulting molecule (in the end > I want a SMILES). > > Regards, > F. > > > On Thu, Jan 14, 2021 at 9:46 AM Francois Berenger <mli...@ligand.eu> > > wrote: > > > >> Hello, > >> > >> Please tell me if you understand why the code below > >> is not working and if you know how to change it so that it does. > >> > >> Thanks a lot! :) > >> F. > >> > >> --- > >> #!/usr/bin/env python3 > >> > >> # try to construct a molecule with a Z stereo double bond using > >> RWMol > >> > >> import rdkit > >> from rdkit import Chem > >> > >> wanted_smi = 'C/N=C\\S' > >> > >> rwmol = Chem.RWMol() > >> # create the atoms > >> a0 = Chem.Atom(6) > >> a1 = Chem.Atom(7) > >> a2 = Chem.Atom(6) > >> a3 = Chem.Atom(16) > >> # add the atoms > >> rwmol.AddAtom(a0) > >> rwmol.AddAtom(a1) > >> rwmol.AddAtom(a2) > >> rwmol.AddAtom(a3) > >> # add the bonds > >> rwmol.AddBond(0, 1, rdkit.Chem.rdchem.BondType.SINGLE) > >> rwmol.AddBond(1, 2, rdkit.Chem.rdchem.BondType.DOUBLE) > >> rwmol.AddBond(2, 3, rdkit.Chem.rdchem.BondType.SINGLE) > >> # let's see what we have so far > >> print(Chem.MolToSmiles(rwmol)) # --> 'CN=CS'; so far so good > >> # try to specify a Z stereo bond > >> db = rwmol.GetBondWithIdx(1) > >> assert(db.GetBondType() == rdkit.Chem.rdchem.BondType.DOUBLE) # just > >> > >> checking > >> db.SetStereo(rdkit.Chem.rdchem.BondStereo.STEREOZ) > >> db.SetStereoAtoms(0, 3) > >> # let's see what we have now > >> print(Chem.MolToSmiles(rwmol)) # --> 'CN=CS'; not good enough > >> Chem.SanitizeMol(rwmol) # just checking > >> print(Chem.MolToSmiles(rwmol)) # --> 'CN=CS'; not getting better > >> --- > >> > >> _______________________________________________ > >> 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