orthonym.input_mol#

Note

Internal API. Names and behaviour may change between releases.

An RDKit molecule as the input of a public naming call.

The public functions (name_compound, name_with_tree, classify_limit and the Orthonym methods name, name_tiered, name_with_tree, name_with_confidence) take a SMILES string or an RDKit Chem.Mol. A string is named as it always was. A Mol is named through RDKit’s SMILES of it: each public call turns a Mol into that SMILES with:func:smiles_for and names the string, so a Mol gets exactly the result its SMILES gets.

smiles_for() writes the SMILES, Chem.MolToSmiles of a copy of the Mol (the caller’s object is never changed), and first proves that the SMILES holds the molecule RDKit reads from the Mol. Where the proof fails it raises InvalidInputError, a ValueError, rather than let the call name another molecule or another stereoisomer:

  1. RDKit reads the SMILES back (Chem.MolFromSmiles).

  2. RDKit’s standard InChI of the Mol as given (without its conformers, which the InChI writer would read instead of the stereo tags, and before any sanitization, which can change what the InChI writer reads) equals the InChI of that reading. RDKit makes no InChI for some molecules (a dummy atom, for one); then the other checks decide.

  3. Atom for atom, through the order in which the writer wrote the atoms (_smilesAtomOutputOrder), the reading has the atoms and bonds of the Mol (sanitized on a copy) and every tetrahedral centre and double bond of the Mol that can be stereogenic has the same configuration in the reading, or none in both (a tag on an atom that cannot be a stereocentre, as RDKit’s PDB reader sets, is dropped by the SMILES writer and not compared). This sees stereo that InChI does not (an amidine C=N, for one) and stereo a SMILES cannot hold (a double bond left open between two set ones gets a configuration in any SMILES). In a symmetric molecule the writer can write the configurations of a symmetric equivalent, so other matchings of the atoms are tried as well.

  4. Every lone-pair stereocentre of the SMILES has the same configuration in RDKit’s reading as in the standard reading of SMILES, which the naming of a string follows (_lone_pair_centres_read_alike()).

A Mol with an AND or OR stereo group (racemic, or one enantiomer of unknown configuration) is named through a CXSMILES string: the proven SMILES of the Mol without its groups, and the enhanced-stereo extension written for those atoms in the order of that SMILES (‘CC[C@H](C)O |&1:2|’), checked by reading it back (_with_stereo_groups()). The naming of such a string states the group (‘rac-‘, ‘rel-‘,, so the Mol is not named as one enantiomer.

A Mol with stereo this check cannot compare is declined before the SMILES is written: an atropisomer tag (a SMILES holds no axis configuration) or a CHI_OTHER chiral tag (RDKit’s SMILES writer can crash the process on one). Square-planar, trigonal-bipyramidal and octahedral tags pass: a SMILES holds them and no name states them, so the Mol gets the result of its SMILES.

Only a caller’s own call (outside any naming) hands None or another type to smiles_for(), where it raises; a non-str the engine itself passed to one of its entries keeps the path it had before Mol input existed (handles()).

A SMILES string is the Mol RDKit reads from it, so the same proof serves it: canonical_spelling() writes the canonical SMILES of the molecule a string draws and hands it to a public call to name in place of the string, so one molecule is named from one atom and bond order whatever order its SMILES wrote (the contributor guide core principle 4). Where the proof does not hold the string is named as written.

exception orthonym.input_mol.InvalidInputError#

Bases: ValueError

None, or a Mol whose SMILES does not hold the molecule RDKit reads from it, given to a public call; a ValueError, as for a SMILES RDKit cannot read.

orthonym.input_mol.handles(arg)#

Whether a public entry turns arg (not a str) into a SMILES with smiles_for(): a Mol always; any other type when the call is a caller’s own (outside any naming), where it raises.

orthonym.input_mol.smiles_for(arg)#

The SMILES a public call names for its non-str argument arg: RDKit’s canonical SMILES of the Mol, once the proof in the module docstring holds.

An empty Mol gives "", named as the empty string is. Raises InvalidInputError for None and for a Mol that the proof declines or that RDKit cannot sanitize or write; TypeError for any other type.

orthonym.input_mol.canonical_spelling(smiles)#

(the string to name, the atom order) for a SMILES string that is not RDKit’s canonical SMILES of the molecule it draws, else None (name the string as written).

The engine names the atoms in the order a string writes them, and a choice between two parts the rules rank alike (the ring that is the parent of two of one seniority, the order of two prefixes of one name) falls to that order: one molecule got a name for each spelling that put its parts in another order. RDKit’s canonical SMILES is a function of the molecule, so naming it names every spelling alike. A string that already is that SMILES is returned unchanged (no proof is needed to leave it as it is, and every corpus row of the evaluation splits is one).

The string drawn is the Mol RDKit reads from it, and the proof of:func:smiles_for holds for that Mol (the same InChI, the same atoms, bonds and stereo atom for atom, the same configuration at every lone-pair centre), and the canonical SMILES reads back as itself with as many atoms as the Mol has. order[k] is the atom of RDKit’s reading of smiles (hydrogens removed) that is atom k of the string, as for the other spellings of namer._lone_pair_input_enter. None, with the string left as written, where any of it fails, for a CXSMILES string (its extensions are not held by a plain SMILES; stereo groups and the brackets RDKit does not need are handled before), for a string RDKit cannot read, and where the canonical SMILES would write more atoms in brackets than the string does. A bracket atom carries its hydrogen count and no implicit hydrogens, which a producer that cuts a bond reads as a radical (namer._redundant_bracket_spelling), and RDKit’s writer brackets every atom that binds a metal or a dative bond (‘CC[S][Zn][S]CC’ for ‘CCS[Zn]SCC’), so such a molecule is named from the string as it was written: a molecule of the evaluation splits that named from the plain spelling named nothing from the bracketed one.