Hi Esben, The short form of the answer is "what you're doing is risky". The SMARTS parser only sets atom properties in very particular situations and is pretty conservative about when it does so.[1] Because of this, it is generally not safe to assume that things like the charge, number of "implicit" Hs, chirality, etc. have been set on an atom in a SMARTS.
As an aside: if you want to calculate valences on molecules constructed from SMARTS, you can always do: m2.UpdatePropertyCache(strict=False) -greg [1] Essentially the only time atom properties are still present on an atom is when the atomic SMARTS doesn't contain the logical operators ';', ',', or '&' and when the atomic properties provided are consistent: We could theoretically relax these constraints, but it's really easy to make mistakes and end up with results that don't make sense. I think this conservative approach is a lot safer. On Tue, May 21, 2019 at 2:49 PM Bjerrum, Esben Jannik < esben.bjer...@astrazeneca.com> wrote: > Hi All, > > I’m working with some generated SMARTS and get some errors related to > charges on nitrogens. This following script exemplifies the behavior I did > not expect. Why does the nitrogen charge gets different, depending on if > other SMARTS properties are set for that atom?? m1 has the explicit charge > on N, but not m2 > > > > Best Regards > > Esben > > > > *import* rdkit > > print(rdkit.__version__) > > *from* rdkit *import* Chem > > > > m1 *=* Chem.MolFromSmarts("O=[N+1](-[O-])-[C:2]") > > m2 *=* Chem.MolFromSmarts("O=[N+1;D3](-[O-])-[C:2]") > > > > a *=* m1.GetAtomWithIdx(1) > > print("Smarts 1: N charge %i"*%*a.GetFormalCharge()) > > a *=* m2.GetAtomWithIdx(1) > > print("Smarts 2: N charge %i"*%*a.GetFormalCharge()) > > print("Smarts 1 as smarts %s"*%*Chem.MolToSmarts(m1)) > > print("Smarts 2 as smarts %s"*%*Chem.MolToSmarts(m2)) > > print("Smarts 1 as smiles %s"*%*Chem.MolToSmiles(m1)) > > print("Smarts 2 as smiles %s"*%*Chem.MolToSmiles(m2)) > > Chem.MolFromSmiles(Chem.MolToSmiles(m1)) > > Chem.MolFromSmarts(Chem.MolToSmarts(m1)) > > Chem.MolFromSmarts(Chem.MolToSmarts(m2)) > > *#These fails with error: Explicit valence for atom # 1 N, 4, is greater > than permitted* > > m2.UpdatePropertyCache() > > Chem.MolFromSmiles(Chem.MolToSmiles(m2)) > > > > 2019.03.2 > > Smarts 1: N charge 1 > > Smarts 2: N charge 0 > > Smarts 1 as smarts O=[N&+](-[O&-])-[C:2] > > Smarts 2 as smarts O=[N&+&D3](-[O&-])-[C:2] > > Smarts 1 as smiles O=[N+]([O-])[CH3:2] > > Smarts 2 as smiles O=N([O-])[CH3:2] > > --------------------------------------------------------------------------- > > ValueError Traceback (most recent call > last) > > <ipython-input-1-f0121281240c> in <module> > > * 18* Chem.MolFromSmarts(Chem.MolToSmarts(m2)) > > * 19* #These fails with error: Explicit valence for atom # 1 N, 4, is > greater than permitted > > ---> 20 m2.UpdatePropertyCache() > > * 21* Chem.MolFromSmiles(Chem.MolToSmiles(m2)) > > > > ValueError: Sanitization error: Explicit valence for atom # 1 N, 4, is > greater than permitted > > [ ]: > > > > > ------------------------------ > > *Confidentiality Notice: *This message is private and may contain > confidential and proprietary information. If you have received this message > in error, please notify us and remove it from your system and note that you > must not copy, distribute or take any action in reliance on it. Any > unauthorized use or disclosure of the contents of this message is not > permitted and may be unlawful. > > _______________________________________________ > 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