orthonym.perception.substructure#

Note

Internal API. Names and behaviour may change between releases.

Substructure matches of a query whose atom order is not the caller’s choice.

RDKit’s matcher extends a partial match in the atom order of the query. A molecule parsed from an OPSIN name comes in OPSIN’s order, which can start at a leaf of a highly symmetric molecule (a methyl of one of fifteen tert-butyl groups); the matcher then tries the automorphisms of every leaf group before it reaches an atom that fails, and on such a molecule it does not return (measured: a 134-atom boron-carbazole emitter, no return in 130 s). The same query renumbered into its canonical SMILES order, which walks the molecule from a canonical start along bonds, matches in 0.08 s with the same matches. ordered_matches searches that renumbered query and returns each match indexed by the query’s own atoms, so callers read it as before.

orthonym.perception.substructure.ordered_matches(target, query, *, use_chirality=False, uniquify=True, max_matches=1000)#

ordered_match_array() as a list of tuples.

orthonym.perception.substructure.ordered_match_array(target, query, *, use_chirality=False, uniquify=True, max_matches=1000)#

target.GetSubstructMatches(query,...) searched in the canonical atom order of query.

One row per match, indexed by the atoms of query (as RDKit returns a match); an array, because a caller that ranks 100,000 matches of a large molecule spent seconds per call on the tuples alone. Which matches are found first can differ from a search in the query’s own order: uncapped and with uniquify=False the set of matches is the same; with uniquify=True the representative of a set of atoms can differ, and under max_matches the subset can.

orthonym.perception.substructure.same_graph_pair(target, query)#

(target, query, parameters) to match query onto target when they can be the same graph, else None.

A mixture drawn as one graph (a molecule with many identical or similar components) is a disconnected query, and RDKit’s matcher takes its atoms in the query’s order: it lets a one-atom component take a carbon of an ethane component of the target, finds that the ethane components do not fit only after the last component, and backtracks through every way of choosing which carbons the one-atom components take (measured: a 33-atom mixture of 19 components, no return in 30 s, the call cannot be interrupted). When the query and the target have the same number of atoms and of bonds and more than one component, every match is an isomorphism, and it maps each component onto a component of the same atom and bond count. Each atom of a copy of both graphs carries the atom and bond count of its component, and the matcher compares it (SubstructMatchParameters.atomProperties): the branches that it cuts hold no complete match, so the matches that remain are the matches of the plain call, in the order of the plain call, and so are the first n of them.

A connected pair of the same sizes is tagged with the local environment and the symmetry class of each atom (_connected_pair()) for the same reason: a molecule with many equivalent groups (a cyclodextrin with silyl ethers on its ring units, 142 atoms) sends the matcher into dead ends from which it does not come back, in the query’s own order and in its canonical order (measured: no return in 40 s for the first 100 matches; with the classes, 0.0 s), and so does a query of the input’s size that is another molecule (a name read with one bond order otherwise), which holds no match at all. None for any other pair: the plain call is made.

orthonym.perception.substructure.same_graph_matches(target, query, *, use_chirality=False, max_matches=64)#

target.GetSubstructMatches(query, uniquify=False, maxMatches=max_matches, useChirality=use_chirality), the same matches in the same order, for a query and a target that are the same graph up to atom order (same_graph_pair() says why the call returns for a mixture of many components).