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:
>>> 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
TrueChecking 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:
>>> pm.geometry_mismatches(smg, geo)
GeometryMismatches(missing_bonds=(), extra_bonds=(), reacting_bonds=(), stereo=())
>>> bool(pm.geometry_mismatches(smg, geo))
FalseEach 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:
>>> 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).
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:
>>> 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: +SKIPRenumbering the geometry renumbers the graph the same way. A mirror-image structure gives the enantiomer:
>>> 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