I'm using the rdkit package to process some molecules. I noticed that when creating a molecule from a SMILES string the library does some syntactic and some semantic checks. This question regards the semantic part (sanitization). (Just in case someone wants to take a look, the checks are described in detail here.

In the sanitization process the explicit and implicit valence of all atoms is computed and it fails when atoms have illegal valence. I don't really understand what "illegal valence" mean in this context. I tried using some compounds with charged atoms to see if they have "illegal valence" but they didn't. Examples: Cc1cc(SCC(=O)c2ccc(Br)cc2)cc(C)[o+]1, O=[V]([O-])([O-])[O-] where the Oxygen in both cases is charged (once positively and once negatively).

  • What does "illegal valence" mean? Is it just using more electrons than the ones actually available in the atom? e.g. 2 bonds with a hydrogen.

  • Furthermore, if the previous is true, I suppose that even combinations that are potentially unstable (in practice) with a lot of charged atoms would still be considered "semantically valid"?


  • $\begingroup$ The positive oxygen charge is tripping your program. I noticed a similar thing happening in ChemDraw online. $\endgroup$ – Aniruddha Deb May 23 at 12:56
  • $\begingroup$ What do you mean by "tripping"? $\endgroup$ – Pani May 23 at 14:01
  • $\begingroup$ Are you able to share the molecules which produced the error? It's difficult to say whether this is a bug in the RDKit or just an incorrect SMILES string. 'Illegal valence' is likely to be a reference to an incorrect number of valence electrons. $\endgroup$ – thesketh May 26 at 14:00
  • $\begingroup$ No molecules produced any error. I'm trying to understand when this error is triggered :) $\endgroup$ – Pani May 26 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.