---------------------------------------------------------------------- This is the API documentation for the protomol library. ---------------------------------------------------------------------- ## Classes Core classes Rotor(*, axis: tuple[int, int], top: Annotated[tuple[int, ...], AfterValidator(func=)]) -> None A hindered rotor: the torsion about `axis` that turns `top` (P85, P86). `axis` is `(a, b)`, with the top hanging off b. For a linear chain (2-butyne's C≡C) a and b are the chain's outer ends, which aren't bonded. `top` is the atoms that turn, sorted, with no axis atom (MESS's `Group`): the smaller side by atom count, and on a tie the side of the higher-indexed end, so that a < b. >>> Rotor(axis=(0, 1), top=(7, 5, 6)) Rotor(axis=(0, 1), top=(5, 6, 7)) Umbrella(*, center: int, neighbors: Annotated[tuple[int, int, int], AfterValidator(func=)]) -> None A pyramidal centre left flexible: its inversion is a double well (P87). `neighbors` are the centre's three neighbours, sorted (MESS's `Plane` and `Group` come from them). >>> Umbrella(center=0, neighbors=(3, 1, 2)) Umbrella(center=0, neighbors=(1, 2, 3)) AtropBond(*, kind: Literal['AtropBond'] = 'AtropBond', atoms: tuple[protomol._stereo.OInt, protomol._stereo.OInt, int, int, protomol._stereo.OInt, protomol._stereo.OInt], parity: Literal[1, -1] | None = None, chain: tuple[int, ...] = ()) -> None A rigid single bond (atropisomer) or an even cumulated chain (allene axis). Same atom order as `PlanarBond`, with parity ±1 for the two helicities. Octahedral(*, kind: Literal['Octahedral'] = 'Octahedral', atoms: tuple[int, protomol._stereo.OInt, protomol._stereo.OInt, protomol._stereo.OInt, protomol._stereo.OInt, protomol._stereo.OInt, protomol._stereo.OInt], parity: Literal[1, -1] | None = None) -> None An octahedral centre: (center, n1, …, n6), n1 trans to n2, n3 to n5, n4 to n6. n3 → n4 → n5 → n6 go round the equator. Parity ±1 for the two handednesses, as in stereomolgraph (`Octahedral`). PlanarBond(*, kind: Literal['PlanarBond'] = 'PlanarBond', atoms: tuple[protomol._stereo.OInt, protomol._stereo.OInt, int, int, protomol._stereo.OInt, protomol._stereo.OInt], parity: Literal[0] | None = None, chain: tuple[int, ...] = ()) -> None A planar bond or an odd cumulated chain: (a, b, end1, end2, c, d). a and b sit on end1, and c and d on end2. The configuration is in the atom order (a is cis to c), so a determined LS has parity 0. `chain` lists the inner atoms from end1 to end2; it is empty for an ordinary double bond. SquarePlanar(*, kind: Literal['SquarePlanar'] = 'SquarePlanar', atoms: tuple[int, protomol._stereo.OInt, protomol._stereo.OInt, protomol._stereo.OInt, protomol._stereo.OInt], parity: Literal[0] | None = None) -> None A square-planar centre: (center, n1, n2, n3, n4). The neighbours go in order round the square (n1 trans to n3, n2 trans to n4). The configuration is in the atom order, so a determined LS has parity 0. It is achiral: `invert` returns it unchanged. StereoChange(*, reactant: protomol._stereo.Stereo | None = None, product: protomol._stereo.Stereo | None = None, ts: protomol._stereo.Stereo | None = None) -> None One stereo site that changes in a reaction: its LS on each side and at the TS. None in a slot means no LS there (not a stereo element on that side). stereomolgraph calls the slots BROKEN, FORMED and FLEETING. Tetrahedral(*, kind: Literal['Tetrahedral'] = 'Tetrahedral', atoms: tuple[int, protomol._stereo.OInt, protomol._stereo.OInt, protomol._stereo.OInt, protomol._stereo.OInt], parity: Literal[1, -1] | None = None) -> None A tetrahedral centre: (center, n1, n2, n3, n4). Seen with n1 at the back, n2 → n3 → n4 turn clockwise for parity 1 and counter-clockwise for parity -1 (stereomolgraph's convention). None marks a lone pair. TrigonalBipyramidal(*, kind: Literal['TrigonalBipyramidal'] = 'TrigonalBipyramidal', atoms: tuple[int, protomol._stereo.OInt, protomol._stereo.OInt, protomol._stereo.OInt, protomol._stereo.OInt, protomol._stereo.OInt], parity: Literal[1, -1] | None = None) -> None A trigonal-bipyramidal centre: (center, a1, a2, e1, e2, e3), e.g. an SN2 TS. a1 and a2 are axial (top and bottom). With e1 turned to the back, e2 → e3 go round the equator in the direction the parity gives (stereomolgraph's convention and diagram). MolGraph(*, type: Literal['MolGraph'] = 'MolGraph', symbols: _Symbols, bonds: _Pairs, charge: int = 0, spin: Annotated[int, Ge(ge=0)] = ) -> None A molecular graph: element symbols and bonds (pairs of atom indices). >>> MolGraph(symbols=["O", "H", "H"], bonds=[(1, 0), (0, 2)]) MolGraph(symbols=('O', 'H', 'H'), bonds=((0, 1), (0, 2)), charge=0, spin=0) The spin (unpaired electrons, 2S) defaults to the lowest the electron count allows: >>> MolGraph(symbols=["C", "H", "H", "H"], bonds=[(0, 1), (0, 2), (0, 3)]).spin 1 ReactionGraph(*, type: Literal['ReactionGraph'] = 'ReactionGraph', symbols: _Symbols, bonds: _Pairs, charge: int = 0, spin: Annotated[int, Ge(ge=0)] = , breaking: _Pairs = (), forming: _Pairs = ()) -> None A reaction or TS graph. `bonds` is every bond (the condensed graph's edges), and `breaking` and `forming` are disjoint subsets of it: the reactant side is `bonds` without `forming`, the product side `bonds` without `breaking`. >>> g = ReactionGraph( ... symbols=["H", "H", "H"], ... bonds=[(0, 1), (1, 2)], ... breaking=[(0, 1)], ... forming=[(2, 1)], ... ) >>> g.forming ((1, 2),) StereoMolGraph(*, type: Literal['StereoMolGraph'] = 'StereoMolGraph', symbols: _Symbols, bonds: _Pairs, charge: int = 0, spin: Annotated[int, Ge(ge=0)] = , atom_stereo: _AtomStereos = (), bond_stereo: _BondStereos = ()) -> None A molecular graph with local stereodescriptors (LS). `atom_stereo` holds the atom LS (sorted by centre) and `bond_stereo` the bond LS (sorted by end pair). Each LS lists exactly the neighbours of its atoms (P30). >>> g = StereoMolGraph( ... symbols=["C", "F", "Cl", "Br", "H"], ... bonds=[(0, 1), (0, 2), (0, 3), (0, 4)], ... atom_stereo=[Tetrahedral(atoms=(0, 1, 2, 3, 4), parity=1)], ... ) >>> g.atom_stereo[0].atoms (0, 1, 2, 3, 4) StereoReactionGraph(*, type: Literal['StereoReactionGraph'] = 'StereoReactionGraph', symbols: _Symbols, bonds: _Pairs, charge: int = 0, spin: Annotated[int, Ge(ge=0)] = , breaking: _Pairs = (), forming: _Pairs = (), atom_stereo: _AtomStereos = (), bond_stereo: _BondStereos = (), stereo_changes: _Changes = ()) -> None A reaction or TS graph with stereo. `atom_stereo` and `bond_stereo` hold the LS that don't change; each holds on both sides. `stereo_changes` holds the sites that change (atom sites by centre, then bond sites by end pair); a site is in one or the other, never both (P30). >>> tet = Tetrahedral(atoms=(0, 1, 2, 3, 4), parity=1) >>> g = StereoReactionGraph( ... symbols=["C", "F", "Cl", "Br", "H", "I"], ... bonds=[(0, 1), (0, 2), (0, 3), (0, 4), (0, 5)], ... breaking=[(0, 3)], ... forming=[(0, 5)], ... charge=-1, ... stereo_changes=[StereoChange(reactant=tet)], ... ) >>> g.stereo_changes[0].reactant == tet True ## Dataclasses Data-holding classes GeometryMismatches(missing_bonds: tuple[tuple[int, int], ...], extra_bonds: tuple[tuple[int, int], ...], reacting_bonds: tuple[tuple[int, int], ...], stereo: tuple[int | tuple[int, int], ...]) -> None Where a graph and a geometry disagree (`geometry_mismatches`). Each field is a sorted tuple. It is true when any field is non-empty, like a container, so `not geometry_mismatches(gra, geo)` means they agree (P77). Attributes: missing_bonds: The graph's bonds that the geometry doesn't have. extra_bonds: The geometry's bonds that the graph doesn't have. reacting_bonds: A reaction graph's breaking and forming bonds whose length in the geometry is outside a TS's range: a full bond (at most 1.05 times the covalent-radius sum), or longer than twice the sum (P69). Empty for a species. stereo: The sites (as `site(ls)` gives them) of the LS whose parity the geometry contradicts. ## Exceptions Exception classes GraphError Invalid graph input (stereomol's GraphError). Raised by `from_json`, and for graphs of mixed types given to `isomorphism` or `deduplicate`. ## Functions Public functions canonical_direction(gra: protomol._types.ReactionGraph | protomol._types.StereoReactionGraph) -> tuple[protomol._types.ReactionGraph | protomol._types.StereoReactionGraph, bool] `gra` or its reverse with the smaller canonical JSON, and whether reversed. A reaction graph and its `reverse` describe one TS from the two sides, and their canonical forms differ. This picks one of them by comparing `canonical_json`, so the result is the same for both, up to atom numbering if the two are equal (a symmetric self-reaction, where a tie keeps `gra`). Atom indices are kept, so an atom map from `canonical_form` of the result applies to the input's atoms as they are. `canonical_form` itself stays faithful to its input. The canonical TS, the same for a TS, its reverse and their mirror images (P60), is `canonical_direction(canonical_enantiomer(gra))`. >>> from protomol import examples >>> ts = examples.abstraction_ts() >>> chosen, flipped = canonical_direction(ts) >>> chosen2, flipped2 = canonical_direction(reverse(ts)) >>> chosen == chosen2, flipped != flipped2 (True, True) canonical_enantiomer(gra: AnyGraph) -> AnyGraph `gra` or its `enantiomer`, whichever has the smaller canonical JSON. A reproducible choice of one of two mirror images (like InChI's `/m0`); a tie (an achiral graph) keeps `gra`. Atom indices are kept. On a reaction graph the choice doesn't depend on its direction (P60): each of the two is compared in its canonical direction, `canonical_json(canonical_direction(x)[0])`, and the winner is returned in `gra`'s direction. >>> from protomol import from_smiles >>> r, s = from_smiles("C[C@H](O)CC"), from_smiles("C[C@@H](O)CC") >>> canonical_json(canonical_enantiomer(r)) == canonical_json(s) True >>> canonical_enantiomer(s) == s True canonical_form(gra: AnyGraph) -> tuple[protomol._types.AnyGraph, tuple[int, ...]] The canonical graph and the atom map to it: `(canonical, atom_map)`. Atom k of `canonical` is atom `atom_map[k]` of `gra` (AutoStorage's `atom_map` direction, P22), so `canonical == relabel(gra, atom_map)`. Two graphs are the same up to atom numbering exactly when their canonical graphs are equal, chain LS included (P92). >>> from protomol import from_smiles >>> canonical, atom_map = canonical_form(from_smiles("OC")) >>> canonical.symbols, atom_map (('C', 'O', 'H', 'H', 'H', 'H'), (1, 0, 2, 3, 4, 5)) >>> canonical == canonical_form(from_smiles("CO"))[0] True canonical_json(gra: AnyGraph) -> str The JSON of the canonical graph: `to_json(canonical_form(gra)[0])`. The value AutoStorage stores for a graph identity (P47). >>> from protomol import from_smiles >>> canonical_json(from_smiles("OC")) == canonical_json(from_smiles("CO")) True enantiomer(gra: AnyGraph) -> AnyGraph The mirror image: every chiral LS inverted, atom indices kept. `Tetrahedral`, `AtropBond`, `TrigonalBipyramidal` and `Octahedral` LS with a parity flip it, and so do the slots of a reaction graph's stereo changes; `PlanarBond` and `SquarePlanar` (their own mirror images) and undetermined LS are kept as they are. A graph without stereo fields is returned unchanged. Being index-aligned, the result needs no atom map: the geometry reflected through a plane is a geometry of it. A trivial site's fixed LS (a CH3 carbon's) is inverted too, as reading the reflected geometry would give it (P75); it describes the same configuration, so compare results by canonical JSON, not `==`. >>> from protomol import from_smiles >>> gra = from_smiles("C[C@H](O)/C=C/C") >>> canonical_json(enantiomer(gra)) == canonical_json( ... from_smiles("C[C@@H](O)/C=C/C") ... ) True >>> enantiomer(enantiomer(gra)) == gra True is_chiral(gra: AnyGraph) -> bool Whether the graph differs from its mirror image, up to atom numbering. `canonical_json(enantiomer(gra)) != canonical_json(gra)`. A reaction graph is compared in its canonical direction, since direction has nothing to do with chirality (P75): N inversion, whose mirror image is its own reverse, is achiral. >>> from protomol import from_smiles >>> is_chiral(from_smiles("C[C@H](O)CC")), is_chiral(from_smiles("C[C@H](O)C")) (True, False) >>> is_chiral(from_smiles("C[C@@H](O)[C@@H](O)C")) # meso False ts_graphs(reactants: protomol._types.MolGraph | protomol._types.StereoMolGraph, products: protomol._types.MolGraph | protomol._types.StereoMolGraph, *, extra_breaks: int = 2) -> list[protomol._types.ReactionGraph] | list[protomol._types.StereoReactionGraph] The topologically distinct TS channels from reactants to products (CCV). Each graph is in the reactants' atom order, and each channel is one elementary step that changes something (P44): the channel where nothing changes is never returned, so a degenerate reaction (CH4 + CH3 → CH3 + CH4) gives its bond-changing channels. With stereo inputs, the channels are the stereo-distinct ones whose two sides are the given reactants and products (stereo-aware isomorphism). If the two sides differ only in stereo, a channel with no bond changes and exactly one stereo change that needs no bonds (a rotation about a bond LS, or an inversion at a lone-pair centre) comes first. Otherwise, each topological channel's LS are enumerated at the sites its reaction touches, so diastereotopic atoms give separate channels (the two H of C3 in (R)-butan-2-ol, say), and every other LS stays unchanged: a channel that would need a stereo change at an untouched site is not one step, and is dropped. The `ts` slots are left empty: the TS-slot rules (P70) are the low-T scheme's (P84), so `low_t(ch)` sets them, and `stereoisomers(low_t(ch))` gives the TS stereoisomers of a channel (a rotation's two twisted TSs, P39). So the channels are one per topology and side stereo. `extra_breaks` is the most bonds the search breaks and re-forms beyond those the bond counts require. Raises: TypeError: If the two graphs are not both `MolGraph`s or both `StereoMolGraph`s. GraphError: If their charge or spin differ. deduplicate(graphs: collections.abc.Iterable[G]) -> list[G] The first graph of each isomorphism class, in input order. Graphs are bucketed by a fingerprint (stereo-aware colour refinement: equal for isomorphic graphs) and compared with `isomorphism` within a bucket. All graphs must be of one type (`GraphError` otherwise). >>> from protomol import from_smiles >>> kept = deduplicate([from_smiles("OC"), from_smiles("CC"), from_smiles("CO")]) >>> [g.symbols for g in kept] [('O', 'C', 'H', 'H', 'H', 'H'), ('C', 'C', 'H', 'H', 'H', 'H', 'H', 'H')] isomorphism(g1: G, g2: G) -> tuple[int, ...] | None An atom map `m` with `relabel(g1, m) == g2`, or None if there is none. Atom k of `g2` is atom `m[k]` of `g1` (the direction of `relabel` and of `canonical_form`'s `atom_map`). Test the result with `is not None`: two empty graphs give `()`. Both graphs must be of one type (`GraphError` otherwise). >>> from protomol import from_smiles, relabel >>> g1, g2 = from_smiles("OC"), from_smiles("CO") >>> m = isomorphism(g1, g2) >>> relabel(g1, m) == g2 True >>> isomorphism(from_smiles("C[C@H](O)F"), from_smiles("C[C@@H](O)F")) is None True display(gra: AnyGraph, *, atom_indices: bool = False) -> None Show the graph in Jupyter. The drawing shows a Lewis structure (bond orders, formal charges and radicals, perceived with the graph's charge and spin), the LS as wedges (undetermined ones marked; a CH3 or CH2 carbon's only with `atom_indices`), and for a reaction graph its breaking and forming bonds on the reactant structure: breaking bonds red, forming bonds blue (dashed), and the site of a stereo change magenta. An undetermined atom LS has a "?" on its centre, and an undetermined bond LS is drawn as a crossed double bond (a cumulated chain's has a "?" on its middle bond). Each graph type also draws itself in Jupyter (`_repr_svg_`), without the atom indices. Known limit: of a species' resonance structures (allyl, acetate), one is drawn. Args: gra: The graph. atom_indices: Label each atom with its index. Raises: ImportError: If IPython isn't installed. reacting_core(g: protomol._types.ReactionGraph | protomol._types.StereoReactionGraph) -> frozenset[int] The atoms CREST holds at a TS: those of the breaking and forming bonds (P67). For a channel with no bond change (a rotation, an inversion), the atoms of its changing sites: a bond's two ends, or an inverting centre. >>> from protomol import from_smiles, ts_graphs >>> sn2, _ = ts_graphs(from_smiles("CBr.[I-]"), from_smiles("CI.[Br-]")) >>> sorted(reacting_core(sn2)) [0, 1, 2] Raises: TypeError: If `g` is not a reaction graph. rings(g: AnyGraph) -> list[tuple[int, ...]] The rings of a graph: a minimum cycle basis (SSSR), sorted (P85). Each ring is in cycle order, from its lowest atom toward the lower of that atom's two ring neighbours. A reaction graph's rings are its condensed graph's, so a cyclic TS has its ring. Rings are fluxional in v1 (P88): no LS holds a ring's conformer. >>> from protomol import from_smiles >>> rings(from_smiles("C1CCCCC1")) [(0, 1, 2, 3, 4, 5)] >>> rings(from_smiles("CC")) [] rotors(g: protomol._types.StereoMolGraph | protomol._types.StereoReactionGraph) -> list[protomol._flex.Rotor] The hindered rotors of a stereo graph, sorted by their axes' atoms (P86). A bond is a rotor axis when no bond LS holds it (P9), it is in no ring, each end has another neighbour, and neither end is linear (sp: a triple bond or two double bonds). A linear chain (2-butyne's C≡C, or a cumulene with no chain LS) gives one axis between its outer ends; a chain LS holds it. At a TS the rules run on the condensed graph: a ring there is rigid (a cyclic TS too), an atom is linear if it is sp on both sides, a transferred atom (one breaking and one forming bond, the H of C···H···O) is linear, and a bond LS in any slot of a change holds its bond. To hold another torsion, put an `AtropBond` on it. >>> from protomol import from_smiles >>> rotors(from_smiles("CC")) [Rotor(axis=(0, 1), top=(5, 6, 7))] >>> rotors(from_smiles("CC#CC")) # one rotor across the linear chain [Rotor(axis=(0, 3), top=(7, 8, 9))] >>> rotors(from_smiles("C=C")), rotors(from_smiles("C1CCCCC1")) ([], []) Raises: TypeError: If `g` is not a stereo graph (`rotors(low_t(g))` gives a plain one its sites, P83). GraphError: If no Lewis structure fits a side (to find the linear atoms). symmetry_number(g: protomol._types.StereoMolGraph | protomol._types.StereoReactionGraph) -> int The symmetry number: the number of stereo-preserving automorphisms (P89). It is the total, for MESS's `SymmetryFactor` with every rotor at `Symmetry 1` (P64). A reaction graph's is its condensed graph's. Chain LS count, so allene is 4 (D2d). Rings are fluxional (P88), so a ring with a flexible bond is refused until a ring model exists (P90): its fluxional count would not match RRHO on one conformer. A centre or bond no LS holds is flexible too, so its inversion is counted (P91): isopropyl is 18 and vinyl 2, for a model that spans both forms (MESS's `Umbrella`, or the forms as conformers). With RRHO on one well, divide by 2 per umbrella; the result then includes the optical isomers (sec-butyl: 9 / 2). >>> from protomol import from_smiles >>> symmetry_number(from_smiles("C")), symmetry_number(from_smiles("CC")) (12, 18) >>> symmetry_number(from_smiles("C=C=C")) 4 Raises: TypeError: If `g` is not a stereo graph (P83). GraphError: If an LS is undetermined (`stereoisomers` gives the determined graphs, whose sigma may differ: meso against dl; an undetermined `ts` slot is allowed), or if a ring of 4 or more atoms has a bond no bond LS holds (PLAN open question 25: use an interim sigma). umbrellas(g: protomol._types.StereoMolGraph | protomol._types.StereoReactionGraph) -> list[protomol._flex.Umbrella] The pyramidal centres the LS leave flexible, sorted by centre (P87). An umbrella is an atom with exactly three neighbours that is no atom LS's centre and no bond LS's end, and is either a group-15 atom with a lone pair (N, P, As: pyramidal, but left flexible by the scheme) or a radical carbon (`[CH3]`). A low-T NH3 has none, since its `Tetrahedral` holds it (P9). At a TS the condensed graph's neighbours and every slot of a change count, and the lone pair or radical may be on either side. >>> from protomol import from_smiles, remove_stereo >>> umbrellas(from_smiles("N")), umbrellas(from_smiles("[CH3]")) ([], [Umbrella(center=0, neighbors=(1, 2, 3))]) >>> umbrellas(remove_stereo(from_smiles("N"), 0)) # high-T NH3: flexible [Umbrella(center=0, neighbors=(1, 2, 3))] Raises: TypeError: If `g` is not a stereo graph (P83). GraphError: If no Lewis structure fits a side. embed(gra: protomol._types.MolGraph | protomol._types.StereoMolGraph) -> autogeom._geometry.Geometry A 3D geometry of the graph, in its atom order, with its charge and spin. RDKit's ETKDG embeds a Lewis structure of the graph (`_lewis`), with each determined `Tetrahedral` (lone-pair centres included) as a chiral tag and each determined `PlanarBond` on a double bond as cis/trans bond stereo. Every determined LS is then read back from the coordinates, so `from_geometry(embed(gra))` has the same LS. An LS ETKDG can't hold (a radical's planar bond, a chain LS) is met by embedding again with the next random seed. Undetermined LS take whatever configuration comes out. The seeds are fixed, so the result is reproducible. The fragments of a disconnected graph are set 3 Å apart. >>> from protomol import examples, from_geometry >>> gra = examples.species() >>> geo = embed(gra) >>> geo.symbols == list(gra.symbols), geo.coordinates.shape (True, (16, 3)) >>> from_geometry(geo) == gra True Raises: TypeError: For a reaction graph. GraphError: If no Lewis structure fits the graph, or no embedding meets its LS. from_geometry(geo: autogeom._geometry.Geometry) -> protomol._types.StereoMolGraph The stereo graph of a geometry, keeping its atom order. Bonds come from covalent radii (`autogeom.adjacency_matrix`, with valences capped), and a Lewis structure from autogeom's solver, with the geometry's charge and spin. The LS sites are the ones `from_smiles` would give for that structure (the low-T approximation), and every site's parity is read from the coordinates, trivial sites included, so the graph describes this geometry atom for atom. A site whose coordinates don't decide it (a flat centre, a double bond twisted by about 90°) stays undetermined. >>> import autogeom >>> geo = autogeom.Geometry( ... symbols=["O", "H", "H"], ... coordinates=[[0.0, 0.0, 0.0], [0.96, 0.0, 0.0], [-0.24, 0.93, 0.0]], ... charge=0, ... spin=0, ... ) >>> from_geometry(geo).bonds ((0, 1), (0, 2)) Raises: GraphError: If no Lewis structure fits the bonds, charge and spin. geometry_mismatches(gra: AnyGraph, geo: autogeom._geometry.Geometry) -> protomol._geometry.GeometryMismatches Where the graph and the geometry disagree, atom i on atom i. Bonds are perceived from covalent radii as `from_geometry` perceives them, and each determined LS's parity is read with `from_geometry`'s readers. An LS the coordinates don't decide (a flat centre, a double bond twisted by about 90°) is not a mismatch, and neither is an undetermined LS. A reaction graph's geometry is its TS's: the bonds that neither break nor form are compared, the breaking and forming bonds must be partial (`reacting_bonds`), and the LS that don't change and the determined `ts` slots are read, a slot on its listed neighbours (P69). An end point is checked on its side: `geometry_mismatches(products(ts), geo)`. >>> from protomol import embed, examples, from_smiles >>> gra = examples.species() >>> geometry_mismatches(gra, embed(gra)) GeometryMismatches(missing_bonds=(), extra_bonds=(), reacting_bonds=(), stereo=()) >>> bool(geometry_mismatches(gra, embed(gra))) False >>> geometry_mismatches(gra, embed(from_smiles(r"C[C@H](O)/C=C/C"))).stereo (1,) Raises: GraphError: If the geometry's symbols differ from the graph's. NotImplementedError: For an LS kind the readers don't read (only `Tetrahedral`, `TrigonalBipyramidal`, `PlanarBond` and `AtropBond` are read). stereoisomers(g: protomol._types.StereoMolGraph | protomol._types.StereoReactionGraph) -> list[protomol._types.StereoMolGraph] | list[protomol._types.StereoReactionGraph] The distinct determined stereoisomers of a stereo graph, mirror images too. The graph is expanded at the LS it has: only readers and schemes assign LS (P83), so a `MolGraph` or `ReactionGraph` gets its sites first, `stereoisomers(low_t(g))`. Each undetermined LS takes every configuration, the determined ones are kept, and graphs equal up to atom numbering are given once, the first in the order of `isomers` (parity 1 first, the lowest site varying slowest). Atom indices are those of `g`. A determined graph gives itself. On a reaction graph each change's side slots are expanded, then its `ts` slot is set by the TS-slot rules (P70; a determined slot the rules allow is kept), so a rotation gives its two twisted TSs and `stereoisomers(low_t(ch))` gives a `ts_graphs` channel's TS stereoisomers (P84). A bifurcation's `ts` slot stays undetermined: one graph per product configuration, the channels (P74); `transition_state` gives their shared TS. >>> from protomol import from_smiles, stereo_at >>> isos = stereoisomers(from_smiles("CC(O)CC")) # butan-2-ol: (R) and (S) >>> [stereo_at(smg, 1).parity for smg in isos] [1, -1] >>> len(stereoisomers(from_smiles("CC(O)C(O)C"))) # two centres, one meso form 3 Raises: TypeError: If `g` is not a `StereoMolGraph` or `StereoReactionGraph`. transition_state(srg: protomol._types.StereoReactionGraph) -> protomol._types.StereoReactionGraph The TS of a channel: the side slots its TS doesn't fix made undetermined. Where the TS-slot rules leave a change's `ts` slot undetermined with its sides determined (a bifurcation: OH + 1-fluoropropyne makes a (Z) and an (E) alkenyl radical through one TS), the side slots become undetermined too, so the bifurcation's channels give one graph (P74, P5). Every other graph is returned as it is. A TS's stored identity is `canonical_direction(canonical_enantiomer(transition_state(g)))` (P60). >>> from protomol import from_smiles, low_t, ts_graphs >>> rct = from_smiles("CC#CF.[OH]") >>> (z,) = ts_graphs(rct, from_smiles(r"C/C(O)=[C]\F")) >>> (e,) = ts_graphs(rct, from_smiles(r"C/C(O)=[C]/F")) >>> z, e = low_t(z), low_t(e) # the TS slots, by the scheme (P84) >>> z == e, transition_state(z) == transition_state(e) (False, True) Raises: TypeError: If `srg` is not a `StereoReactionGraph`. from_json(string: str) -> AnyGraph The graph of the type named in the JSON, validated in strict mode. >>> from_json('{"type":"MolGraph","symbols":["H","H"],"bonds":[[0,1]],' ... '"charge":0,"spin":0}').bonds ((0, 1),) Raises: GraphError: If the string is not a JSON object, names no known type, has a field that doesn't belong to its type, has a value of the wrong JSON type (such as `"1"` or `1.0` for an int), or gives an invalid graph. to_json(g: AnyGraph) -> str The graph as compact JSON: its fields in field order, `type` first. >>> from protomol import MolGraph >>> to_json(MolGraph(symbols=["H", "H"], bonds=[(1, 0)])) '{"type":"MolGraph","symbols":["H","H"],"bonds":[[0,1]],"charge":0,"spin":0}' low_t(g: protomol._types.MolGraph | protomol._types.StereoMolGraph | protomol._types.ReactionGraph | protomol._types.StereoReactionGraph) -> protomol._types.StereoMolGraph | protomol._types.StereoReactionGraph The graph with the low-T scheme's stereo sites (P54), keeping its parities. The sites are perceived on a Lewis structure of the graph. A site the graph already has keeps its LS and parity; a site the scheme drops loses its LS; a site it adds is undetermined, or fixed if it is trivial. No parity is invented, so a plain graph gets the sites with only the trivial ones fixed. `low_t` is idempotent, and leaves the output of `from_smiles` and `from_geometry` as it is, except where the rules depend on which Lewis structure is read (open question 11). A reaction graph's two sides are reassigned separately: each `StereoChange` slot follows its side's site, and a change left with no LS on either side is removed (no TS-only sites, P68). A change at a TS site gets its `ts` slot by the TS-slot rules (P70; the scheme's choice, P84), keeping the given one where the rules allow it; where they allow two (the twisted TSs of a rotation), it is their LS undetermined, for `stereoisomers` to split. Other `ts` slots are kept as they are. >>> from protomol import from_smiles, without_stereo >>> gra = from_smiles("C[C@H](N)CC") >>> low_t(without_stereo(gra)).atom_stereo[1].parity is None # C1: undetermined True >>> low_t(gra) == gra True Raises: GraphError: If no Lewis structure fits the bonds, charge and spin. products(gra: protomol._types.ReactionGraph | protomol._types.StereoReactionGraph) -> protomol._types.MolGraph | protomol._types.StereoMolGraph The product side, as one (possibly disconnected) graph in the same atom order. Its bonds are `bonds` without `breaking`, and its LS are the unchanged LS and the `product` slot of each change. >>> g = ReactionGraph( ... symbols=["H", "H", "H"], bonds=[(0, 1), (1, 2)], breaking=[(0, 1)], ... forming=[(1, 2)], ... ) >>> products(g).bonds ((1, 2),) reactants(gra: protomol._types.ReactionGraph | protomol._types.StereoReactionGraph) -> protomol._types.MolGraph | protomol._types.StereoMolGraph The reactant side, as one (possibly disconnected) graph in the same atom order. Its bonds are `bonds` without `forming`, and its LS are the unchanged LS and the `reactant` slot of each change. >>> g = ReactionGraph( ... symbols=["H", "H", "H"], bonds=[(0, 1), (1, 2)], breaking=[(0, 1)], ... forming=[(1, 2)], ... ) >>> reactants(g).bonds ((0, 1),) reaction_graph(reactant: protomol._types.MolGraph | protomol._types.StereoMolGraph, product: protomol._types.MolGraph | protomol._types.StereoMolGraph) -> protomol._types.ReactionGraph | protomol._types.StereoReactionGraph The reaction graph of two index-aligned graphs (same symbols, charge and spin). Bonds only in the reactant are breaking, and bonds only in the product are forming. Equal LS stay unchanged (`atom_stereo`, `bond_stereo`); others become a `StereoChange(reactant=, product=, ts=)` in `stereo_changes`, with its `ts` slot empty: the TS-slot rules are the scheme's (P84), so `low_t` sets them. >>> r = MolGraph(symbols=["H", "H", "H"], bonds=[(0, 1)]) >>> p = MolGraph(symbols=["H", "H", "H"], bonds=[(1, 2)]) >>> g = reaction_graph(r, p) >>> g.bonds, g.breaking, g.forming (((0, 1), (1, 2)), ((0, 1),), ((1, 2),)) Raises: TypeError: If the two graphs are not both `MolGraph`s or both `StereoMolGraph`s. GraphError: If their symbols, charge or spin differ. relabel(gra: AnyGraph, atom_map: collections.abc.Sequence[int]) -> AnyGraph The graph with atom k of the result = atom `atom_map[k]` of `gra`. Same direction as AutoStorage's link `atom_map` (P22), whose `atom_map[k]` is the input index of canonical atom k: `relabel(gra, atom_map)` gives the canonical graph, and the inverse map (`numpy.argsort(atom_map)`) gives `gra` back. >>> g = MolGraph(symbols=["O", "H", "H"], bonds=[(0, 1), (0, 2)]) >>> relabel(g, [2, 0, 1]) MolGraph(symbols=('H', 'O', 'H'), bonds=((0, 1), (1, 2)), charge=0, spin=0) >>> relabel(relabel(g, [2, 0, 1]), [1, 2, 0]) == g # [1, 2, 0] is the inverse True Raises: ValueError: If `atom_map` is not a permutation of the atoms. reverse(gra: protomol._types.ReactionGraph | protomol._types.StereoReactionGraph) -> protomol._types.ReactionGraph | protomol._types.StereoReactionGraph The reverse reaction: breaking and forming swap, and so do the change slots. The TS slot of each change stays as it is. >>> g = ReactionGraph( ... symbols=["H", "H", "H"], bonds=[(0, 1), (1, 2)], breaking=[(0, 1)], ... forming=[(1, 2)], ... ) >>> reverse(g).breaking ((1, 2),) without_stereo(gra: protomol._types.StereoMolGraph | protomol._types.StereoReactionGraph) -> protomol._types.MolGraph | protomol._types.ReactionGraph The graph without its LS and changes, as a `MolGraph` or a `ReactionGraph`. >>> from protomol import Tetrahedral >>> g = StereoMolGraph( ... symbols=["C", "F", "Cl", "Br", "H"], ... bonds=[(0, 1), (0, 2), (0, 3), (0, 4)], ... atom_stereo=[Tetrahedral(atoms=(0, 1, 2, 3, 4), parity=1)], ... ) >>> type(without_stereo(g)).__name__ 'MolGraph' Raises: TypeError: If the graph has no stereo fields (a `MolGraph` or a `ReactionGraph`). from_reaction_smiles(smiles: str, *, charge: int | None = None, spin: int | None = None) -> protomol._types.StereoReactionGraph The stereo reaction graph of an atom-mapped reaction SMILES (P62). Atom k is the atom with the k-th smallest map number. Each side is perceived as `from_smiles` does; `without_stereo` gives the `ReactionGraph`. As a reader it also sets the `ts` slots by the TS-slot rules, as `low_t` does (P84); where they allow two (the twisted TSs of a rotation), the slot is their LS undetermined. >>> rxn = from_reaction_smiles("[H:1][H:2].[O:3][H:4]>>[H:1].[H:2][O:3][H:4]") >>> rxn.symbols ('H', 'H', 'O', 'H') >>> rxn.breaking, rxn.forming (((0, 1),), ((1, 2),)) Args: smiles: A reaction SMILES "reactants>>products" with no agents, in which every atom, H included, is written and mapped, and both sides have the same map numbers. charge: Checked against the sum of formal charges on each side; default: that sum. spin: Unpaired electrons (2S); default: the lower of the two sides' radical electron counts (`from_smiles`'s default). Raises: GraphError: For a SMILES that isn't a reaction SMILES or that RDKit can't parse, agents, an unmapped atom or implicit H, a map number used twice on a side, sides with different map numbers, symbols or charges, or a charge or spin `from_smiles` rejects. from_smiles(smiles: str, charge: int | None = None, spin: int | None = None) -> protomol._types.StereoMolGraph The stereo graph of a SMILES, with every atom explicit (stereomol's index rule). The atoms are the SMILES atoms in SMILES order, `[H]` atoms included where they are written, then the implicit H in the order of the atoms they're bonded to. Stereo uses the low-T scheme. Sites whose two configurations give the same graph get a fixed parity. Stereo elements the SMILES leaves unspecified stay undetermined (parity None) until `stereoisomers`. A cumulated chain gets one LS on its ends, a `PlanarBond` or an `AtropBond` with the inner atoms as its `chain`. A cumulene's `/` and `\` are read as a double bond's (`C/C=C=C=C/C` is trans); allene stereo has no RDKit reading, so it is never determined by the SMILES. A double bond or chain has stereo only if neither end is sp (linear). >>> gra = from_smiles("[H]OC") >>> gra.symbols ('H', 'O', 'C', 'H', 'H', 'H') >>> gra.atom_stereo[0].parity # C2's Tetrahedral is trivial, so it's filled 1 Args: smiles: A species SMILES; may have several fragments ("CC.[OH]"). charge: Checked against the sum of formal charges; default: that sum. spin: Unpaired electrons (2S); default: RDKit's radical-electron count (maximal pairing, then Hund's rule per atom: [CH2] and [O] → 2; O=O → 0). Raises: GraphError: For an unparsable SMILES, a reaction SMILES (use `from_reaction_smiles`, or `ts_graphs` for unmapped sides), a charge that differs from the formal charges, or a spin of the wrong parity. invert(ls: S) -> S The other configuration. An undetermined LS is returned unchanged. A chiral LS (parity ±1) gives its mirror image, by flipping the parity. `PlanarBond` swaps c and d (cis ⇄ trans). `SquarePlanar` is returned unchanged: it is its own mirror image, and it has three configurations, not two (`isomers` lists them). >>> invert(PlanarBond(atoms=(1, 2, 3, 4, 5, 6), parity=0)).atoms (1, 2, 3, 4, 6, 5) isomers(ls: S) -> tuple[S, ...] Every determined configuration of `ls`, in a fixed order. The order doesn't depend on the configuration of `ls`: by atom tuple, then parity 1 before parity -1. With distinct atoms there are 2 for `Tetrahedral`, `PlanarBond` and `AtropBond`, 3 for `SquarePlanar`, 20 for `TrigonalBipyramidal` and 30 for `Octahedral`. >>> [iso.parity for iso in isomers(Tetrahedral(atoms=(0, 1, 2, 3, 4)))] [1, -1] site(ls: protomol._stereo.Tetrahedral | protomol._stereo.SquarePlanar | protomol._stereo.TrigonalBipyramidal | protomol._stereo.Octahedral | protomol._stereo.PlanarBond | protomol._stereo.AtropBond) -> int | tuple[int, int] The centre atom, or the sorted pair of end atoms (the key in the graph's maps). >>> site(Tetrahedral(atoms=(0, 1, 2, 3, None))) 0 >>> site(PlanarBond(atoms=(5, 6, 3, 2, 7, 8))) (2, 3) is_determined(g: _StereoGraph) -> bool Whether every LS is determined (a workflow graph needs this). The `ts` slot of a change may stay undetermined (post-TS bifurcation, P5). >>> g = StereoMolGraph( ... symbols=["C", "F", "Cl", "Br", "H"], ... bonds=[(0, 1), (0, 2), (0, 3), (0, 4)], ... atom_stereo=[Tetrahedral(atoms=(0, 1, 2, 3, 4))], ... ) >>> is_determined(g) False neighbors(g: AnyGraph, i: int) -> tuple[int, ...] The sorted neighbours of atom `i`, over every bond (breaking and forming too). >>> neighbors(MolGraph(symbols=["O", "H", "H"], bonds=[(0, 1), (0, 2)]), 0) (1, 2) Raises: IndexError: If `i` is not an atom of the graph. remove_stereo(g: protomol._types.StereoMolGraph | protomol._types.StereoReactionGraph, site: _Site) -> protomol._types.StereoMolGraph | protomol._types.StereoReactionGraph A new graph without the LS or change at a site. >>> g = StereoMolGraph( ... symbols=["C", "F", "Cl", "Br", "H"], ... bonds=[(0, 1), (0, 2), (0, 3), (0, 4)], ... atom_stereo=[Tetrahedral(atoms=(0, 1, 2, 3, 4), parity=1)], ... ) >>> remove_stereo(g, 0).atom_stereo () Raises: KeyError: If there is no stereo at the site. stereo_at(g: _StereoGraph, site: _Site) -> protomol._stereo.AtomStereo | protomol._stereo.BondStereo | protomol._stereo.StereoChange | None The LS or change at a site (a centre atom or a bond's ends), or None. >>> g = StereoMolGraph( ... symbols=["C", "C", "H", "H", "H", "H"], ... bonds=[(0, 1), (0, 2), (0, 3), (1, 4), (1, 5)], ... bond_stereo=[PlanarBond(atoms=(2, 3, 0, 1, 4, 5), parity=0)], ... ) >>> stereo_at(g, (1, 0)).parity 0 >>> stereo_at(g, 0) is None True with_stereo(g: AnyGraph, *items: protomol._types._LS | protomol._stereo.StereoChange) -> protomol._types.StereoMolGraph | protomol._types.StereoReactionGraph A new graph with each item at its site, replacing what was there. An item is an LS or, for a reaction graph, a `StereoChange`; in a reaction graph an LS and a change at one site replace each other. A `MolGraph` gives a `StereoMolGraph` and a `ReactionGraph` a `StereoReactionGraph`. >>> g = MolGraph( ... symbols=["C", "F", "Cl", "Br", "H"], bonds=[(0, 1), (0, 2), (0, 3), (0, 4)] ... ) >>> new = with_stereo(g, Tetrahedral(atoms=(0, 1, 2, 3, 4), parity=1)) >>> type(new).__name__, len(new.atom_stereo) ('StereoMolGraph', 1) Raises: TypeError: If an item is not an LS or a `StereoChange`, or is a `StereoChange` for a molecule graph. ValueError: If the new graph is invalid (pydantic's `ValidationError`), for example with two items at one site. species() -> protomol._types.StereoMolGraph (E)-pent-3-en-2-ol, one enantiomer: C[C@@H](O)/C=C/C (16 atoms, singlet). A tetrahedral centre, a planar bond, and four rotors (2 CH3, OH, C-C). >>> gra = species() >>> len(gra.symbols), gra.spin (16, 0) abstraction_ts() -> protomol._types.StereoReactionGraph C2H6 + OH → C2H5 + H2O (10 atoms, doublet): H abstraction, one channel. A CH3 rotor, and the C···H···O torsion through the transferred H (P86). The channel from `ts_graphs` gets its `ts` slots from `low_t` (P84). >>> ts = abstraction_ts() >>> len(ts.symbols), ts.spin (10, 1) stereoisomerization_ts() -> protomol._types.StereoReactionGraph (Z) → (E) but-2-en-1-yl radical (11 atoms, doublet): rotation about C2=C3. The C2=C3 planar bond comes from radical resonance, so this is a low-T stereo element (high-T, i.e. InChI, drops it). No bonds change; only that PlanarBond does. The twisted TS is a chiral axis, and its two mirror images are two channels (P39): this is the one with `AtropBond` parity 1. >>> ts = stereoisomerization_ts() >>> len(ts.symbols), ts.spin, ts.breaking, ts.forming (11, 1, (), ()) ## Type Aliases Type alias definitions AtomStereo Type alias. Type aliases are created through the type statement:: type Alias = int In this example, Alias and int will be treated equivalently by static type checkers. At runtime, Alias is an instance of TypeAliasType. The __name__ attribute holds the name of the type alias. The value of the type alias is stored in the __value__ attribute. It is evaluated lazily, so the value is computed only if the attribute is accessed. The __module__ attribute holds the name of the module in which the type alias was defined; it can be assigned to. Type aliases can also be generic:: type ListOrSet[T] = list[T] | set[T] In this case, the type parameters of the alias are stored in the __type_params__ attribute. See PEP 695 for more information. BondStereo Type alias. Type aliases are created through the type statement:: type Alias = int In this example, Alias and int will be treated equivalently by static type checkers. At runtime, Alias is an instance of TypeAliasType. The __name__ attribute holds the name of the type alias. The value of the type alias is stored in the __value__ attribute. It is evaluated lazily, so the value is computed only if the attribute is accessed. The __module__ attribute holds the name of the module in which the type alias was defined; it can be assigned to. Type aliases can also be generic:: type ListOrSet[T] = list[T] | set[T] In this case, the type parameters of the alias are stored in the __type_params__ attribute. See PEP 695 for more information. Stereo Type alias. Type aliases are created through the type statement:: type Alias = int In this example, Alias and int will be treated equivalently by static type checkers. At runtime, Alias is an instance of TypeAliasType. The __name__ attribute holds the name of the type alias. The value of the type alias is stored in the __value__ attribute. It is evaluated lazily, so the value is computed only if the attribute is accessed. The __module__ attribute holds the name of the module in which the type alias was defined; it can be assigned to. Type aliases can also be generic:: type ListOrSet[T] = list[T] | set[T] In this case, the type parameters of the alias are stored in the __type_params__ attribute. See PEP 695 for more information. AnyGraph Type alias. Type aliases are created through the type statement:: type Alias = int In this example, Alias and int will be treated equivalently by static type checkers. At runtime, Alias is an instance of TypeAliasType. The __name__ attribute holds the name of the type alias. The value of the type alias is stored in the __value__ attribute. It is evaluated lazily, so the value is computed only if the attribute is accessed. The __module__ attribute holds the name of the module in which the type alias was defined; it can be assigned to. Type aliases can also be generic:: type ListOrSet[T] = list[T] | set[T] In this case, the type parameters of the alias are stored in the __type_params__ attribute. See PEP 695 for more information. ---------------------------------------------------------------------- This is the User Guide documentation for the package. ---------------------------------------------------------------------- ### Use cases These pages show protomol as AutoEngine (`ae`) and AutoStorage will use it, one page per interface. They are the place to review the API as it is called, alongside the code. protomol's API is the draft of stereomol's Python API, so what reads well here is what stereomol will offer. | page | interface | |---|---| | [Workflow entry](01-entry.qmd) | SMILES (or a reactant and product pair) to the graphs that start a workflow | | [Identity](02-identity.qmd) | AutoStorage's graph identities, and graphs as stored and passed data | | [Reaction coordinate](03-reaction.qmd) | What a saddle-point search and an IRC read from a TS graph | | [Flexibility and thermo](04-flexibility.qmd) | Conformer sampling, rotor, umbrella and ring scans, symmetry numbers, the kinetics network | | [Graph and geometry](05-geometry.qmd) | Seeding structures from a graph, and checking structures against it | ## Live and planned examples - **Live** examples are `>>>` blocks. pytest runs them as doctests (`--doctest-glob=*.qmd`) in pre-commit, so they always match the code. The `pm.display(...)` lines are skipped (`# doctest: +SKIP`): they draw the graph in a notebook. - **Planned** examples are plain code blocks under a "Planned" callout naming the phase (see protomol's `PLAN.md` in the project notes). They use the names already planned. A name that is not yet planned is marked `# PROPOSED:`. AutoEngine and AutoStorage code that doesn't exist yet is marked `# illustrative`: only the protomol calls in it are under review. - The step that implements a planned call turns its block into a live one. ### Workflow entry An `ae` workflow runs on one fixed graph: one stereoisomer of a species, or one TS channel. The user starts from SMILES, and the first step turns it into the distinct, fully determined graphs, one workflow each. ## A species: SMILES to stereoisomers `from_smiles` gives a stereo graph with every atom explicit: the SMILES atoms in SMILES order, then the implicit H in the order of the atoms they're bonded to. Stereo the SMILES leaves out stays undetermined, while sites whose two configurations give the same graph (the C of a methyl group) get a fixed parity: ```python >>> import protomol as pm >>> gra = pm.from_smiles("CC(O)CC") # butan-2-ol, centre not specified >>> gra.symbols[:5] ('C', 'C', 'O', 'C', 'C') >>> pm.is_determined(gra) # C1 has an undetermined Tetrahedral False >>> pm.stereo_at(gra, 1).parity is None True >>> pm.stereo_at(gra, 0).parity # a methyl C: trivial, so filled 1 >>> # in a notebook: "?" marks the undetermined C1 >>> pm.display(gra) # doctest: +SKIP ``` `stereoisomers` expands every undetermined LS into the distinct, determined graphs, with the atom indices of `gra`; both mirror images are kept: ```python >>> isomers = pm.stereoisomers(gra) # (R) and (S), as two determined graphs >>> [pm.is_determined(smg) for smg in isomers] [True, True] >>> [pm.stereo_at(smg, 1).parity for smg in isomers] [1, -1] >>> mirror = pm.enantiomer(isomers[0]) # the same graph as isomers[1], up to numbering >>> pm.canonical_json(mirror) == pm.canonical_json(isomers[1]) True >>> # one workflow each: >>> # for smg in isomers: >>> # run_species_workflow(smg) # ae, illustrative ``` Configurations that give the same graph are listed once: butane-2,3-diol has two centres but three stereoisomers, as (R,S) and (S,R) are one meso form. `stereoisomers` takes a stereo graph: a `MolGraph` (no stereo) gets its sites from a scheme first, here `low_t`: ```python >>> len(pm.stereoisomers(pm.from_smiles("CC(O)C(O)C"))) 3 >>> len(pm.stereoisomers(pm.low_t(pm.without_stereo(gra)))) 2 ``` A species given with full stereo needs no expansion: ```python >>> gra = pm.from_smiles("C[C@@H](O)/C=C/C") # one stereoisomer of pent-3-en-2-ol >>> pm.is_determined(gra) True >>> gra == pm.examples.species() # the test graph in protomol.examples True ``` ## A reaction: reactant and product SMILES to TS channels `ts_graphs` finds the distinct TS channels (CCV). The reactants and products are each one graph, which may hold several molecules (`"CC.[OH]"`), with the same charge and spin. The atoms of every channel follow the reactant graph's order, and the product LS are carried over through the channel's atom mapping: ```python >>> rct = pm.from_smiles("CC.[OH]") >>> prd = pm.from_smiles("C[CH2].O") >>> channels = pm.ts_graphs(rct, prd) # one StereoReactionGraph per distinct channel >>> len(channels) 1 >>> ts = channels[0] >>> ts.breaking, ts.forming # an H moves from C0 to O2 (((0, 3),), ((2, 3),)) >>> pm.reactants(ts) == rct True >>> pm.low_t(ts) == pm.examples.abstraction_ts() # the test graph, with its ts slots True >>> # the breaking C0-H3 in red, the forming O2-H3 in blue >>> pm.display(ts, atom_indices=True) # doctest: +SKIP ``` A bond homolysis gives two radicals, whose default spin is the triplet's; give the products the reactant's spin for the singlet channel: ```python >>> rct = pm.from_smiles("CCO") >>> len(pm.ts_graphs(rct, pm.from_smiles("[CH2]O.[CH3]", spin=rct.spin))) 1 ``` A channel whose sides leave some stereo open stands for several TSs. `stereoisomers` lists them: each undetermined LS on either side takes every configuration, and each change's `ts` slot follows by the TS-slot rules. SN2 at an open centre gives backside attack (the `TrigonalBipyramidal` TS, inversion) and frontside attack (retention), each with its mirror image: ```python >>> (srg,) = pm.ts_graphs(pm.from_smiles("FC(Cl)Br.[I-]"), pm.from_smiles("FC(Cl)I.[Br-]")) >>> sorted(pm.stereo_at(ts, 1).ts.kind for ts in pm.stereoisomers(srg)) ['Tetrahedral', 'Tetrahedral', 'TrigonalBipyramidal', 'TrigonalBipyramidal'] ``` ```python for srg in pm.ts_graphs(rct, prd): for ts in pm.stereoisomers(pm.low_t(srg)): # the TS stereoisomers (P84) run_ts_workflow(ts) # ae, illustrative ``` ## Atom-mapped reaction SMILES (the INCITE import) `from_reaction_smiles` reads an atom-mapped reaction SMILES. Atom k is the atom with the k-th smallest map number, and every atom, H included, must be written and mapped, on both sides. Each side is perceived as `from_smiles` does, and, as a reader, it sets the `ts` slots by the TS-slot rules, as `low_t` does: ```python >>> rxn = pm.from_reaction_smiles( ... "[C:1]([C:2]([H:7])([H:8])[H:9])([H:4])([H:5])[H:6].[O:3][H:10]" ... ">>[C:1]([C:2]([H:7])([H:8])[H:9])([H:5])[H:6].[H:4][O:3][H:10]" ... ) >>> rxn.breaking, rxn.forming (((0, 3),), ((2, 3),)) >>> rxn == pm.examples.abstraction_ts() # the same channel as `ts_graphs` gave above True >>> pm.from_reaction_smiles("[CH3:1][H:2].[OH:3]>>[CH3:1].[H:2][OH:3]") Traceback (most recent call last): ... protomol._types.GraphError: '[CH3:1][H:2].[OH:3]' has implicit H; write and map every H as an atom ``` ### Identity AutoStorage names each stationary point by several identity algorithms. The graph-based ones take the geometry and the graph the user is working with, index-aligned (`identity_fn(geo, gra, other_geos)`), and store a canonical form. ## Graphs as data A graph is a frozen value. `==` and `hash` compare its fields (labelled equality), and the JSON is one byte string per graph: ```python >>> import protomol as pm >>> gra = pm.MolGraph(symbols=["O", "H", "H"], bonds=[(0, 1), (0, 2)]) >>> pm.to_json(gra) '{"type":"MolGraph","symbols":["O","H","H"],"bonds":[[0,1],[0,2]],"charge":0,"spin":0}' >>> pm.from_json(pm.to_json(gra)) == gra True >>> len({gra, pm.MolGraph(symbols=["O", "H", "H"], bonds=[(2, 0), (1, 0)])}) 1 ``` Any graph type can be a field of another pydantic model, which is how a task's input or a row can carry one: ```python >>> from pydantic import BaseModel >>> class SpeciesTask(BaseModel): # ae, illustrative ... graph: pm.AnyGraph ... method: str >>> task = SpeciesTask(graph=gra, method="b3lyp/6-31g*") >>> SpeciesTask.model_validate_json(task.model_dump_json()).graph == gra True ``` Labelled equality is not isomorphism. The same molecule with its atoms in another order is a different graph: ```python >>> hoh = pm.MolGraph(symbols=["H", "O", "H"], bonds=[(0, 1), (1, 2)]) >>> hoh == gra False >>> # the atom indices show the order >>> pm.display(hoh, atom_indices=True) # doctest: +SKIP ``` `relabel(gra, atom_map)` reorders the atoms: atom k of the result is atom `atom_map[k]` of `gra`, the direction of AutoStorage's link `atom_map` (canonical atom k is input atom `atom_map[k]`). The inverse map, `np.argsort(atom_map)`, undoes it: ```python >>> pm.relabel(gra, [1, 0, 2]) == hoh True >>> pm.relabel(hoh, [1, 0, 2]) == gra # [1, 0, 2] is its own inverse True ``` `isomorphism(g1, g2)` compares two graphs up to atom numbering (VF2++). It returns an atom map `m` with `relabel(g1, m) == g2`, or `None`, and `deduplicate` keeps the first graph of each isomorphism class: ```python >>> pm.isomorphism(gra, hoh) (1, 0, 2) >>> pm.deduplicate([gra, hoh]) == [gra] True ``` ## Canonical form `canonical_form(gra)` returns the canonical graph and the atom map to it: atom k of the canonical graph is atom `atom_map[k]` of `gra`. Two numberings of one molecule give one canonical graph, and `canonical_json` is its JSON, the string AutoStorage stores: ```python >>> import numpy as np >>> can, atom_map = pm.canonical_form(hoh) >>> atom_map (1, 0, 2) >>> pm.relabel(hoh, atom_map) == can # atom_map is the relabelling True >>> pm.relabel(can, np.argsort(atom_map)) == hoh # its inverse recovers the input True >>> pm.canonical_json(hoh) == pm.canonical_json(gra) True >>> pm.canonical_json(gra) '{"type":"MolGraph","symbols":["O","H","H"],"bonds":[[0,1],[0,2]],"charge":0,"spin":0}' ``` ### Canonical direction A reaction graph and its `reverse` are one transition state seen from its two sides, but their canonical forms differ. `canonical_direction(gra)` returns whichever of the two has the smaller `canonical_json`, and whether it reversed; atom indices are kept: ```python >>> ts = pm.examples.abstraction_ts() >>> chosen, flipped = pm.canonical_direction(ts) >>> again, flipped_again = pm.canonical_direction(pm.reverse(ts)) >>> chosen == again, flipped != flipped_again (True, True) >>> pm.canonical_json(chosen) == min( ... pm.canonical_json(ts), pm.canonical_json(pm.reverse(ts)) ... ) True ``` ### Mirror images `enantiomer(gra)` is the mirror image: every chiral LS inverted (`Tetrahedral`, `AtropBond`, and a reaction graph's change slots too), planar bonds and undetermined LS kept, atom indices kept. `is_chiral(gra)` says whether it differs from `gra`, and `canonical_enantiomer(gra)` picks one of the two reproducibly, the one with the smaller canonical JSON (like InChI's `/m0`). That is the enantiomer AutoEngine computes, and AutoStorage stores the other as its mirror partner: ```python >>> smg = pm.examples.species() >>> pm.is_chiral(smg), pm.is_chiral(pm.from_smiles("C[C@@H](O)[C@@H](O)C")) # meso (True, False) >>> mirror = pm.enantiomer(smg) >>> pm.canonical_json(mirror) == pm.canonical_json(pm.from_smiles(r"C[C@H](O)/C=C/C")) True >>> pm.canonical_json(pm.canonical_enantiomer(smg)) == pm.canonical_json( ... pm.canonical_enantiomer(mirror) ... ) True ``` On a reaction graph the choice doesn't depend on the direction: each mirror image is compared in its canonical direction, and the winner is returned in the input's direction. ### The canonical TS A TS has four versions: the graph, its reverse, its mirror image, and the mirror image reversed. All four are one saddle point up to reflection, so they get one canonical TS: `canonical_direction(canonical_enantiomer(ts))`, the mirror image chosen first, then the direction. Atom indices are kept, so an atom map from `canonical_form` of the result applies to the TS geometry as it is (reflected, if `canonical_enantiomer` picked the mirror image): ```python >>> ts = pm.examples.stereoisomerization_ts() >>> def canonical_ts(ts): ... chosen, _ = pm.canonical_direction(pm.canonical_enantiomer(ts)) ... return pm.canonical_json(chosen) >>> versions = [ts, pm.reverse(ts), pm.enantiomer(ts), pm.reverse(pm.enantiomer(ts))] >>> len({canonical_ts(v) for v in versions}) 1 ``` A chain LS (an allene or cumulene axis) counts too, so an achiral allene is its own mirror image and a chiral one isn't: ```python >>> pm.is_chiral(pm.from_smiles("C=C=C")), pm.is_chiral(pm.from_smiles("C=C=CC")) (False, False) >>> axes = pm.stereoisomers(pm.from_smiles("CC=C=CC")) # penta-2,3-diene >>> [pm.is_chiral(axis) for axis in axes] [True, True] >>> pm.canonical_json(pm.enantiomer(axes[0])) == pm.canonical_json(axes[1]) True ``` ## Stereo sites: the low-T scheme Which features of a species get an LS is a scheme. `from_smiles` and `from_geometry` use the low-T scheme (pm P54); `low_t` applies it to any graph. A plain graph gets the scheme's sites, undetermined unless they are trivial, so `low_t` is how a `MolGraph` gets its stereo sites: ```python >>> amine = pm.from_smiles("C[N@](CC)C(C)O") >>> plain = pm.without_stereo(amine) >>> low = pm.low_t(plain) >>> [(ls.atoms[0], ls.parity) for ls in low.atom_stereo if ls.parity != 1] [(1, None), (4, None)] ``` The amine N and the CH centre are undetermined; the CH3 groups and the CH2 are trivial (parity 1). A site the graph already has keeps its parity, a site the scheme doesn't have loses its LS, and no parity is invented. So `low_t` leaves the output of `from_smiles` and `from_geometry` as it is, and applying it twice changes nothing: ```python >>> pm.low_t(amine) == amine True >>> pm.low_t(low) == low True ``` A reaction graph's two sides are reassigned separately, and each `StereoChange` slot follows its side's site. The TS slots are kept as they are: ```python >>> ts = pm.examples.stereoisomerization_ts() >>> pm.low_t(ts) == ts True ``` ::: {.callout-note} Planned: January (`high_t`, InChI's rules) and Phase 5 (TS sites). ::: ## An SMG identity algorithm ::: {.callout-note} Planned: Phases 2 and 3. The AutoStorage side (`IdentityResult`, the registry, the `graph=` argument) is AutoStorage's API, shown here only for the protomol calls in it. ::: ```python from autostorage import IdentityResult # illustrative def smg_low_t(geo, gra, other_geos): # registered as "smg_low_t@1", orders {0} if gra is None: # AutoStorage perceives one for order 0 gra = pm.from_geometry(geo) elif pm.geometry_mismatches(gra, geo): # disagree: warn, naming the atoms; perceive gra = pm.from_geometry(geo) low = fill_parities(pm.low_t(gra), geo) # added sites read from geo (private, P57) can, atom_map = pm.canonical_form(low) return IdentityResult(value=pm.canonical_json(can), atom_map=atom_map) ``` `smg_high_t@1` uses `high_t`, and `smg_conn@1` uses `pm.without_stereo`. The value is the canonical JSON; AutoStorage adds its hash for the uniqueness index (pm P47). ## Storing and finding a point by its graph ```python point = StationaryPointRow(geometry=geo, calculation=calc, order=0, graph=smg) # illustrative session.add(point) # the identities are computed on flush stmt = autostorage.query.stationary_points(graph=smg, algorithm="smg@1") # illustrative ``` ### Reaction coordinate A TS workflow runs on one `StereoReactionGraph` (a `ReactionGraph` if stereo doesn't matter). The graph says which bonds break and form, which stereo sites change, and what the two sides are. ## Bond changes H abstraction, CH4 + OH → CH3 + H2O (atoms: C0, H1–H4, O5, H6): ```python >>> import protomol as pm >>> ts = pm.ReactionGraph( ... symbols=["C", "H", "H", "H", "H", "O", "H"], ... bonds=[(0, 1), (0, 2), (0, 3), (0, 4), (5, 6), (1, 5)], ... breaking=[(0, 1)], ... forming=[(1, 5)], ... ) >>> ts.breaking, ts.forming (((0, 1),), ((1, 5),)) >>> ts.spin 1 ``` A saddle-point search scans or constrains the distances in `breaking` and `forming`. That is the whole reaction coordinate. `bonds` holds every bond of the TS, the changing ones included, so `pm.neighbors` gives the neighbours on either side: ```python >>> pm.neighbors(ts, 1) (0, 5) ``` ## Stereo that changes Each slot of a `StereoChange` (`reactant`, `product`, `ts`) holds the LS of that site on that side. `None` means the side has no stereo element there. An element whose configuration isn't chosen is an undetermined LS (`parity=None`), not `None`. SN2 at a stereocentre, I⁻ + CHFClBr → CHFClI + Br⁻ (atoms: C0, F1, Cl2, Br3, H4, I5). The centre's LS changes, so it is a `StereoChange`. Backside attack inverts the centre: I5 takes the place of Br3 with the opposite parity. At the TS the centre is five-coordinate, a `TrigonalBipyramidal` with I5 and Br3 axial. Its configuration follows from the reactant's. A constructor takes the slots as given, so this hand-built graph leaves it undetermined. The TS-slot rules are the low-T scheme's: `low_t` sets the slot, and so does the reader `from_reaction_smiles`, while `reaction_graph` and `ts_graphs`, which build a reaction graph from its sides, leave it empty. ```python >>> rct = pm.Tetrahedral(atoms=(0, 1, 2, 3, 4), parity=1) >>> prd = pm.Tetrahedral(atoms=(0, 1, 2, 5, 4), parity=-1) >>> tbp = pm.TrigonalBipyramidal(atoms=(0, 5, 3, 1, 2, 4)) >>> ts = pm.StereoReactionGraph( ... symbols=["C", "F", "Cl", "Br", "H", "I"], ... bonds=[(0, 1), (0, 2), (0, 3), (0, 4), (0, 5)], ... breaking=[(0, 3)], ... forming=[(0, 5)], ... charge=-1, ... stereo_changes=[pm.StereoChange(reactant=rct, product=prd, ts=tbp)], ... ) >>> change = pm.stereo_at(ts, 0) >>> change.reactant == rct, change.product == prd, change.ts.kind (True, True, 'TrigonalBipyramidal') >>> pm.stereo_at(pm.reaction_graph(pm.reactants(ts), pm.products(ts)), 0).ts is None True >>> pm.stereo_at(pm.low_t(ts), 0).ts TrigonalBipyramidal(kind='TrigonalBipyramidal', atoms=(0, 3, 5, 1, 2, 4), parity=1) ``` Each change at a TS site, an LS with an atom in a breaking or forming bond (or, with no bond change, at the changing site), gets its `ts` slot by rule from the two sides: an LS on one side only carries over (an abstraction centre is still pyramidal at the TS, an attacked face is fixed by the attack), inversion at a centre gives the backside `TrigonalBipyramidal` and retention a `Tetrahedral` with `None` where the leaving and attacking atoms meet, a lone-pair inversion is planar (`None`). The rules give the same slot in either direction. A stereo change needs no bond change. In the but-2-en-1-yl radical, CH2•–CH=CH–CH3 (atoms: C0–C3, H4–H10), resonance gives C1=C2 its double-bond character. Rotating about it turns (Z) into (E). The TS graph has no `breaking` or `forming` bonds, only a `StereoChange` at the bond (1, 2). A `PlanarBond` lists (a, b, end1, end2, c, d) with a cis to c, so (Z) has C0 cis to C3 and (E) has C0 cis to H7. At the TS the bond is twisted about 90°, which makes it a chiral axis: an `AtropBond`. Rotating one way or the other gives mirror-image TSs (parity 1 or -1). These are distinct saddle points, so they are two channels, and a kinetic model needs both. This graph leaves the axis undetermined, standing for either one: ```python >>> z = pm.PlanarBond(atoms=(0, 6, 1, 2, 3, 7), parity=0) >>> e = pm.PlanarBond(atoms=(0, 6, 1, 2, 7, 3), parity=0) >>> twist = pm.AtropBond(atoms=(0, 6, 1, 2, 3, 7)) >>> ts = pm.StereoReactionGraph( ... symbols=["C", "C", "C", "C"] + ["H"] * 7, ... bonds=[(0, 1), (1, 2), (2, 3), (0, 4), (0, 5), (1, 6), (2, 7), (3, 8), (3, 9), (3, 10)], ... stereo_changes=[pm.StereoChange(reactant=z, product=e, ts=twist)], ... ) >>> ts.breaking, ts.forming, ts.spin ((), (), 1) >>> change = pm.stereo_at(ts, (1, 2)) >>> change.reactant == z, change.product == e, change.ts.parity (True, True, None) >>> # the C1-C2 bond, whose stereo changes, in magenta >>> pm.display(ts) # doctest: +SKIP ``` This C1=C2 bond is a low-T stereo element: the other resonance form puts the double bond at C0=C1, so a high-T scheme (InChI) drops it. `protomol.examples` has one of the two channels, with the axis determined: ```python >>> channel = pm.examples.stereoisomerization_ts() >>> change = pm.stereo_at(channel, (1, 2)) >>> change.reactant == z, change.product == e, change.ts.parity (True, True, 1) ``` `ts_graphs` gives the channel with its `ts` slot empty; `low_t` sets it to the twist, undetermined, and `stereoisomers` gives both twisted TSs: ```python >>> (rotation,) = pm.ts_graphs(pm.from_smiles(r"[CH2]/C=C\C"), pm.from_smiles(r"[CH2]/C=C/C")) >>> pm.stereo_at(rotation, (1, 2)).ts is None True >>> twists = pm.stereoisomers(pm.low_t(rotation)) >>> sorted(pm.stereo_at(ts, (1, 2)).ts.parity for ts in twists) [-1, 1] >>> any(pm.isomorphism(channel, ts) is not None for ts in twists) True ``` ## Bifurcations When OH adds to 1-fluoropropyne, the alkenyl radical's (Z) or (E) configuration is set after the TS: one TS leads to both products. The `ts` slot stays undetermined, and each product configuration is its own channel. `transition_state` drops what the TS doesn't fix, so both channels give one TS: ```python >>> alkyne = pm.from_smiles("CC#CF.[OH]") >>> (either,) = pm.ts_graphs(alkyne, pm.from_smiles("CC(O)=[C]F")) >>> first, second = pm.stereoisomers(pm.low_t(either)) # one per product configuration >>> pm.stereo_at(first, (1, 2)).ts.parity is None True >>> first == second, pm.transition_state(first) == pm.transition_state(second) (False, True) ``` ## The two sides, and the IRC end points `reactants` and `products` give each side as a `StereoMolGraph` in the TS's atom order, with the unchanged LS and the matching slot of each change. `reverse` swaps the two: ```python >>> rct = pm.reactants(ts) >>> prd = pm.products(ts) >>> type(rct).__name__, rct.symbols == ts.symbols ('StereoMolGraph', True) >>> pm.stereo_at(rct, (1, 2)) == z, pm.stereo_at(prd, (1, 2)) == e (True, True) >>> pm.reactants(pm.reverse(ts)) == prd True ``` The sides index the IRC end points too, so `geometry_mismatches` checks each end point against the side it should be: the bonds, perceived from covalent radii, and the parity of every LS. Here an embedding of each side stands in for the IRC's end points: ```python >>> fwd, bwd = pm.embed(prd), pm.embed(rct) # stand in for the IRC's end points >>> pm.geometry_mismatches(prd, fwd) GeometryMismatches(missing_bonds=(), extra_bonds=(), reacting_bonds=(), stereo=()) >>> pm.geometry_mismatches(prd, bwd).stereo # the wrong end: (Z) at C1=C2 ((1, 2),) ``` The TS graph itself is checked against a TS geometry: the bonds that neither break nor form, the breaking and forming bonds, which must be partial (`reacting_bonds`), the LS that don't change, and each determined `ts` slot. A planar end point contradicts neither twist, but a twisted geometry agrees with only one of the two mirror-image TSs: ```python >>> import autogeom >>> twisted = autogeom.twist(bwd, (1, 2), 90, degrees=True) >>> plus = pm.examples.stereoisomerization_ts() # AtropBond parity 1 >>> twist = pm.stereo_at(plus, (1, 2)).ts >>> minus = pm.with_stereo(plus, pm.StereoChange(reactant=z, product=e, ts=pm.invert(twist))) >>> [pm.geometry_mismatches(g, bwd).stereo for g in (plus, minus)] [(), ()] >>> sorted(pm.geometry_mismatches(g, twisted).stereo for g in (plus, minus)) [(), ((1, 2),)] ``` ::: {.callout-note} Planned: Phase 4 (`reacting_core`). ::: ```python core = pm.reacting_core(ts) # atoms CREST freezes in a TS conformer search ``` Each side may hold several molecules. Splitting a side into its molecules, each with its own atom map, is not planned yet: ```python for mol, atom_map in pm.components(prd): # PROPOSED: name and return type ... ``` ### Flexibility and thermo The LS set is the dynamical model. A bond with an LS is rigid, and a bond without one may be a rotor. The same LS decide the symmetry number, so conformer sampling, scans and the partition function all agree. ## What the routines read now The charge, the spin and the neighbours are fields and functions today: ```python >>> import protomol as pm >>> ch3 = pm.MolGraph(symbols=["C", "H", "H", "H"], bonds=[(0, 1), (0, 2), (0, 3)]) >>> ch3.charge, ch3.spin (0, 1) >>> pm.neighbors(ch3, 0) (1, 2, 3) >>> pm.display(ch3) # doctest: +SKIP ``` ## Conformer sampling At a TS, CREST holds the reacting core: the atoms of the breaking and forming bonds. The rings are sampled by CREST too: they are fluxional in v1, with no LS on a ring's conformer, so each ring conformer is a CREST minimum of the same graph. ```python >>> ts = pm.examples.abstraction_ts() >>> sorted(pm.reacting_core(ts)) # TS only: the atoms CREST holds [0, 2, 3] >>> pm.rings(pm.from_smiles("C1CCCCC1")) # each ring in cycle order [(0, 1, 2, 3, 4, 5)] >>> # conformers = run_crest(pm.embed(ts), constrain=pm.reacting_core(ts)) # ae, illustrative ``` The torsions to sample are the rotors' axes. A bond with a bond LS is never one, and a linear chain gives one axis between its outer ends: ```python >>> [rotor.axis for rotor in pm.rotors(pm.examples.species())] # 2 CH3, OH, C1-C3 [(1, 0), (1, 2), (1, 3), (4, 5)] >>> pm.rotors(pm.from_smiles("CC#CC")) # 2-butyne: one torsion across C≡C [Rotor(axis=(0, 3), top=(7, 8, 9))] ``` A conformer search can invert a centre or flip a bond, so each conformer is checked against the graph, and kept only if nothing disagrees. Here an embedding of the graph and of its mirror image stand in for CREST's conformers: ```python >>> smg = pm.examples.species() >>> conformers = [pm.embed(smg), pm.embed(pm.enantiomer(smg))] # stand in for CREST's >>> kept = [geo for geo in conformers if not pm.geometry_mismatches(smg, geo)] >>> len(kept) 1 ``` ## Scans for the partition function A rotor's `top` is the smaller side, the atoms that turn (MESS's `Group`), and it hangs off `axis[1]`. MESS gets every rotor with `Symmetry 1` and its scan over 360°, with the total symmetry number below. At a TS the rotors are read on the condensed graph, and a transferred H counts as linear, so the abstraction TS has one torsion about C0···O2: ```python >>> pm.rotors(pm.examples.abstraction_ts()) [Rotor(axis=(0, 1), top=(6, 7, 8)), Rotor(axis=(0, 2), top=(9,))] >>> # for rotor in pm.rotors(smg): >>> # scan_torsion(geo, axis=rotor.axis, moving=rotor.top) # 360°, illustrative ``` An umbrella is a pyramidal centre the LS leave flexible, whose inversion is a double well: a radical C such as CH3's, or an amine N that a scheme left without its `Tetrahedral`. At low T, NH3's `Tetrahedral` holds it: ```python >>> pm.umbrellas(pm.from_smiles("[CH3]")) [Umbrella(center=0, neighbors=(1, 2, 3))] >>> pm.umbrellas(pm.from_smiles("N")), pm.umbrellas(pm.remove_stereo(pm.from_smiles("N"), 0)) ([], [Umbrella(center=0, neighbors=(1, 2, 3))]) >>> # for umb in pm.umbrellas(smg): >>> # scan_umbrella(geo, umb.center, umb.neighbors) # illustrative ``` The symmetry number is the total number of stereo-preserving automorphisms, for MESS's `SymmetryFactor` with every rotor at `Symmetry 1`. It needs every LS determined, since stereoisomers can differ in it, and it refuses a ring of 4 or more atoms with a flexible bond until a ring model exists (pm open question 25): there, use an interim value. ```python >>> pm.symmetry_number(pm.from_smiles("C")), pm.symmetry_number(pm.from_smiles("CC")) (12, 18) >>> pm.symmetry_number(pm.from_smiles("C=C=C")) # allene: D2d 4 >>> pm.symmetry_number(pm.from_smiles("C1CCCCC1")) Traceback (most recent call last): ... protomol._types.GraphError: The ring (0, 1, 2, 3, 4, 5) is flexible (a bond with no bond LS), and sigma for ring conformers isn't settled yet (open question 25): use an interim sigma ``` MESS-PF also takes `smg.spin` (as 2S + 1). ## The kinetics network ::: {.callout-note} The network API is open (am Phase 6). ::: ```python # Nodes are the identities of each TS's sides; enantiomeric nodes are lumped (illustrative) nodes = {identity(side) for ts in channels for side in (pm.reactants(ts), pm.products(ts))} ``` Two nodes are an enantiomeric pair, to lump and adjust sigma_eff, when one's mirror image has the other's canonical JSON: ```python >>> smg_a = pm.examples.species() >>> smg_b = pm.from_smiles(r"C[C@H](O)/C=C/C") >>> pm.canonical_json(pm.enantiomer(smg_a)) == pm.canonical_json(smg_b) True ``` ### Graph and geometry Atom i of a graph is atom i of its geometry. Every routine crosses between the two: it seeds a structure from the graph, and checks each structure it gets back against the graph. Geometries are autogeom's `Geometry`, which carries `charge` and `spin` too. ## Seeding a structure `embed` runs RDKit's ETKDG on a Lewis structure of the graph, with its determined LS as constraints, and keeps its atom order, charge and spin. Reading the structure back gives the same graph: ```python >>> import autogeom as ag >>> import protomol as pm >>> smg = pm.examples.species() >>> geo = pm.embed(smg) >>> isinstance(geo, ag.Geometry), geo.symbols == list(smg.symbols) (True, True) >>> pm.from_geometry(geo) == smg True ``` ## Checking a structure A conformer search or an optimization can invert a centre, flip a bond or break one. A structure is kept only if it is still the workflow's graph. `geometry_mismatches` perceives the bonds from covalent radii, as `from_geometry` does, and reads each determined LS's parity from the coordinates. All three fields empty means they agree, and the result is false, like an empty container: ```python >>> pm.geometry_mismatches(smg, geo) GeometryMismatches(missing_bonds=(), extra_bonds=(), reacting_bonds=(), stereo=()) >>> bool(pm.geometry_mismatches(smg, geo)) False ``` Each disagreement names its atoms: a bond as a pair, an LS by its site (the centre, or a bond's end pair). The (1S, 3Z) stereoisomer's structure contradicts both LS of the (1R, 3E) graph: ```python >>> other = pm.embed(pm.from_smiles(r"C[C@H](O)/C=C\C")) >>> pm.geometry_mismatches(smg, other).stereo (1, (3, 4)) ``` An LS the coordinates don't decide (a flat centre, a double bond twisted by about 90°) is not a mismatch, and neither is an undetermined one. On a reaction graph, only the bonds that neither break nor form and the LS that don't change are compared, so the end points of an IRC and the TS all agree with it (see [Reaction coordinate](03-reaction.qmd)). ## Perceiving a graph For a structure from outside a workflow (an INCITE geometry, an IRC end point), the atom order is kept. The LS sites are the low-T ones `from_smiles` gives, and every parity is read from the coordinates, so the graph describes this structure atom for atom: ```python >>> geo = ag.from_smiles(r"C[C@@H](O)/C=C/C") # stands in for an outside structure >>> gra = pm.from_geometry(geo) >>> gra.symbols[:5], (gra.charge, gra.spin), pm.is_determined(gra) (('C', 'C', 'O', 'C', 'C'), (0, 0), True) >>> pm.canonical_json(gra) == pm.canonical_json(pm.examples.species()) True >>> pm.display(gra, atom_indices=True) # doctest: +SKIP ``` Renumbering the geometry renumbers the graph the same way. A mirror-image structure gives the enantiomer: ```python >>> mirror = pm.from_geometry(ag.reflect(geo, [0.0, 0.0, 1.0])) >>> pm.canonical_json(mirror) == pm.canonical_json(pm.from_smiles(r"C[C@H](O)/C=C/C")) True ```