Skip to main content

with_stereo()

A new graph with each item at its site, replacing what was there.

Usage

Source

with_stereo(g: MolGraph | StereoMolGraph, items: _LS = ()) -> StereoMolGraph
 
with_stereo(g: ReactionGraph | StereoReactionGraph, items: _LS | StereoChange = ()) -> StereoReactionGraph

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.