StereoCondensedReactionGraph#

class stereomolgraph.StereoCondensedReactionGraph(mol_graph: MolGraph | None = None)#

Bases: StereoMolGraph, CondensedReactionGraph

CondenedReactionGraph with the ability to store stereochemistry information for atoms and (potentially changing) bonds.

active_atoms(additional_layer: int = 0) set[int]#

Atoms involved in the reaction with additional layers of atoms in the neighborhood.

Parameters:

additional_layer (int) – Number of additional layers of atoms to include, defaults to 0 (default: 0)

Return type:

set[int]

Returns:

Atoms involved in the reaction

copy(frozen: bool = False) Self#
Return type:

Self

Returns:

returns a copy of self

relabel_atoms(mapping: dict[int, int], copy: bool = True) Self#

Relabels the atoms of the graph and the chiral information accordingly

Parameters:
  • mapping (dict[int, int]) – Mapping of old atom ids to new atom ids

  • copy (bool) – If the graph should be copied before relabeling, defaults to True (default: True)

Return type:

Self

Returns:

Returns the relabeled graph or None if copy is False

reactant(keep_attributes: bool = True) StereoMolGraph#

Returns the reactant of the reaction

Parameters:

keep_attributes (bool) – If attributes should be kept , defaults to True (default: True)

Return type:

StereoMolGraph

Returns:

reactant

product(keep_attributes: bool = True) StereoMolGraph#

Returns the product of the reaction

Parameters:

keep_attributes (bool) – If attributes should be kept, defaults to True (default: True)

Return type:

StereoMolGraph

Returns:

product

add_atom(atom: int, atom_type: int | str, **attr: Any)#

Adds atom to the MolGraph

Parameters:
  • atom (int) – Atom ID

  • atom_type (int | str) – Atom Type

add_bond(atom1: int, atom2: int, **attr: Any)#

Adds a bond between atom1 and atom2.

Parameters:
  • atom1 (int) – id of atom1

  • atom2 (int) – id of atom2

add_broken_bond(atom1: int, atom2: int, **attr: Any)#

Adds a bond between atom1 and atom2 with reaction attribute set to BROKEN.

Parameters:
  • atom1 (int) – Atom1

  • atom2 (int) – Atom2

add_fleeting_bond(atom1: int, atom2: int, **attr: Any)#

Adds a bond between atom1 and atom2 with reaction attribute set to FLEETING.

Parameters:
  • atom1 (int) – Atom1

  • atom2 (int) – Atom2

add_formed_bond(atom1: int, atom2: int, **attr: Any)#

Adds a bond between atom1 and atom2 with reaction attribute set to FORMED.

Parameters:
  • atom1 (int) – Atom1

  • atom2 (int) – Atom2

property atom_types: tuple[int, ...]#
Returns:

Returns all atom types in the MolGraph

property atoms: Collection[int]#
Returns:

Returns all atoms of the molecule

property atoms_with_attributes: Mapping[int, dict[str, Any]]#
Returns:

Returns all atoms in the MolGraph with their attributes

bonded_to(atom: int) frozenset[int]#

Returns the atoms connected to the atom.

Parameters:

atom (int) – Id of the atom.

Return type:

frozenset[int]

Returns:

tuple of atoms connected to the atom.

property bonds: Collection[frozenset[int]]#
Returns:

Returns all bonds in the MolGraph

bonds_from_bond_order_matrix(matrix: ndarray, threshold: float = 0.5, include_bond_order: bool = False)#

Adds bonds the the graph based on bond orders from a matrix

Parameters:
  • matrix (ndarray) – Bond order Matrix

  • threshold (float) – Threshold for bonds to be included as edges, defaults to 0.5 (default: 0.5)

  • include_bond_order (bool) – If bond orders should be included as edge attributes, defaults to False (default: False)

property bonds_with_attributes: Mapping[frozenset[int], dict[str, Any]]#
Returns:

Returns all bonds in the MolGraph with their attributes

connected_components() list[set[int]]#
Return type:

list[set[int]]

Returns:

Returns the connected components of the graph

connectivity_matrix() ndarray[tuple[int, int], dtype[int8]]#

Returns a connectivity matrix of the graph as a list of lists. Order is the same as in self.atoms() 1 if nodes are connected, 0 if not.

Return type:

ndarray[tuple[int, int], dtype[int8]]

Returns:

Connectivity matrix as list of lists

delete_atom_attribute(atom: int, attr: str)#

Deletes the Attribute of the Atom Raises KeyError if attribute is not present. Raises KeyError if atom is not in graph.

Parameters:
  • atom (int) – Atom ID

  • attr (str) – Attribute

Raises:

ValueError – The attribute “atom_type” can not be deleted

delete_atom_stereo(atom: int)#

Deletes stereo information from the graph

Parameters:

atom (int) – Atom to be used for stereo information

delete_bond_attribute(atom1: int, atom2: int, attr: str)#

Deletes the Attribute of the bond between Atom1 and Atom2

Parameters:
  • atom1 (int)

  • atom2 (int) – Atom1

  • attr (str) – Attribute

delete_bond_stereo(bond: Iterable[int])#

Deletes the stereo information of the bond

Parameters:

bond (Iterable[int]) – Bond

freeze() Self#

Freeze the graph, making it immutable and hashable.

A frozen graph can be used in sets and as dict keys. Mutation methods will raise TypeError. Use copy() to get a mutable copy.

Return type:

Self

Returns:

self (for chaining)

classmethod from_atom_types_and_bond_order_matrix(atom_types: Sequence[int | str], matrix: ndarray, threshold: float = 0.5, include_bond_order: bool = False)#
Parameters:
  • atom_types (Sequence[int | str]) – list of atom types as integers or symbols, must correspond to the matrix

  • matrix (ndarray) – np.matrix of bond orders or connectivities ([0..1])

  • threshold (float) – Threshold for bonds to be included as edges, defaults to 0.5 (default: 0.5)

  • include_bond_order (bool) – If bond orders should be included as edge attributes, defaults to False (default: False)

Returns:

Returns MolGraph

classmethod from_geometry(geo: ~stereomolgraph.coords.Geometry, switching_function: ~stereomolgraph.coords.BondsFromDistance = <stereomolgraph.coords.BondsFromDistance object>) Self#

Creates a StereoMolGraph object from a Geometry and a switching function. Uses the Default switching function if none are given.

Parameters:
  • geo (Geometry) – Geometry

  • switching_function (BondsFromDistance) – Function to determine if two atoms are connected (default: <stereomolgraph.coords.BondsFromDistance object at 0x77e8e8b59940>)

Return type:

Self

Returns:

StereoMolGraph of molecule

classmethod from_geometry_and_bond_order_matrix(geo: Geometry, matrix: ndarray, threshold: float = 0.5, include_bond_order: bool = False) Self#

Creates a CiralMolGraph object from a Geometry and a bond order matrix

Parameters:
  • geo (Geometry) – Geometry

  • matrix (ndarray) – Bond order matrix

  • threshold (float) – Threshold for bonds to be included as edges, defaults to 0.5 (default: 0.5)

  • include_bond_order (bool) – If bond orders should be included as edge attributes, defaults to False (default: False)

Return type:

Self

Returns:

Returns MolGraph

classmethod from_rdmol(rdmol: Mol, use_atom_map_number: bool = False, stereo_complete: bool = False, resonance: bool = True, lone_pair_stereo: bool = True) Self#

Creates a StereoMolGraph from an RDKit Mol object. All hydrogens have to be explicit. Stereo information is conserved for tetrahedral atoms and double bonds.

Parameters:
  • rdmol (Mol) – RDKit Mol object

  • use_atom_map_number (bool) – If the atom map number should be used instead of the atom index, Default: False (default: False)

  • stereo_complete (bool) – If True, we assume that the stereochemistry in the RDKit Mol is complete and all non chiral tetrahedral centers are set to an arbitrary configuration instead of None. (default: False)

Return type:

Self

Returns:

StereoMolGraph

property frozen: bool#

Whether the graph is currently frozen (immutable).

get_atom_attribute(atom: int, attr: str) Any | None#

Returns the value of the attribute of the atom or None if the atom does not have this attribute. Raises KeyError if atom is not in graph.

Parameters:
  • atom (int) – Atom

  • attr (str) – Attribute

Raises:

KeyError – Atom not in graph

Return type:

Optional[Any]

Returns:

Returns the value of the attribute of the atom

get_atom_attributes(atom: int, attributes: Iterable[str] | None = None) Mapping[str, Any]#

Returns the attributes of the atom. If no attributes are given, all attributes are returned. Raises KeyError if atom is not in graph.

Parameters:
  • atom (int) – Atom

  • attributes (Optional[Iterable[str]]) – Specific attributes to return (default: None)

Return type:

Mapping[str, Any]

Returns:

Returns all or just the chosen attributes of the atom

get_atom_stereo(atom: int) None | AtomStereo#

Returns the stereo information of the atom if it exists else None. Raises a ValueError if the atom is not in the graph.

Parameters:
  • atom (int) – atom

  • default – Default value if no stereo information is found, defaults to None

Return type:

None | AtomStereo

Returns:

Stereo information of atom

get_atom_type(atom: int) int#

Returns the atom type of the atom. Raises KeyError if atom is not in graph.

Parameters:

atom (int) – Atom

Raises:

KeyError – Atom not in graph

Return type:

int

Returns:

Returns the atom type of the atom

get_bond_attribute(atom1: int, atom2: int, attr: str) Any#

Returns the value of the attribute of the bond between Atom1 and Atom2. Raises KeyError if bond is not in graph.

Parameters:
  • atom1 (int) – Atom1

  • atom2 (int) – Atom2

  • attr (str) – Attribute

Return type:

Any

Returns:

Returns the value of the attribute of the bond between Atom1 and Atom2

get_bond_attributes(atom1: int, atom2: int, attributes: Iterable[str] | None = None) Mapping[str, Any]#
Parameters:
  • atom1 (int) – Atom1

  • atom2 (int) – Atom2

  • attributes (Optional[Iterable[str]]) – Specific attributes to return (default: None)

Return type:

Mapping[str, Any]

Returns:

Returns chosen attributes of the bond between Atom1 and Atom2

get_bond_stereo(bond: Iterable[int]) None | BondStereo#

Gets the stereo information of the bond or None if it does not exist. Raises a ValueError if the bond s not in the graph.

Parameters:

bond (Iterable[int]) – Bond

Return type:

None | BondStereo

Returns:

stereo information of bond

get_broken_bonds() set[frozenset[int]]#

Returns all bonds that are broken during the reaction

Return type:

set[frozenset[int]]

Returns:

broken bonds

get_fleeting_bonds() set[frozenset[int]]#

Returns all bonds that are fleeting during the reaction.

Return type:

set[frozenset[int]]

Returns:

fleeting bonds

get_formed_bonds() set[frozenset[int]]#

Returns all bonds that are formed during the reaction

Return type:

set[frozenset[int]]

Returns:

formed bonds

has_atom(atom: int) bool#

Returns True if the molecules contains an atom with this id.

Parameters:

atom (int) – Atom

Return type:

bool

Returns:

value

has_bond(atom1: int, atom2: int) bool#

Returns True if bond is in MolGraph.

Parameters:
  • atom1 (int) – Atom1

  • atom2 (int) – Atom2

Return type:

bool

Returns:

If the bond is in MolGraph

is_stereo_valid() bool#

Checks if the bonds required to have the defined stereochemistry are present in the graph.

Return type:

bool

Returns:

True if the stereochemistry is valid

property n_atoms: int#
Returns:

Returns number of atoms in the MolGraph

property neighbors: Mapping[int, frozenset[int]]#
Returns:

Returns all neighbors of the atoms in the MolGraph

node_connected_component(atom: int) set[int]#
Parameters:

atom (int) – atom id

Return type:

set[int]

Returns:

Returns the connected component that includes atom_id

remove_atom(atom: int)#

Removes an atom from the graph and deletes all chiral information associated with it

Parameters:

atom (int) – Atom

remove_bond(atom1: int, atom2: int)#

Removes bond between Atom1 and Atom2.

Parameters:
  • atom1 (int) – Atom1

  • atom2 (int) – Atom2

reverse_reaction() Self#

Creates the reaction in the opposite direction.

Broken bonds and stereochemistry changes are turned into formed and the other way around.

Return type:

Self

Returns:

Reversed reaction

set_atom_attribute(atom: int, attr: str, value: Any)#

sets the Value of the Attribute on Atom. Raises KeyError if atom is not in graph.

Parameters:
  • atom (int) – Atom

  • attr (str) – Attribute

  • value (Any) – Value

Raises:
  • KeyError – Atom not in graph

  • ValueError – The attribute “atom_type” can only have values of type Element

set_atom_stereo(atom_stereo: AtomStereo)#

Adds stereo information to the graph

Parameters:
  • atom – Atoms to be used for chiral information

  • stereo – Chiral information

set_bond_attribute(atom1: int, atom2: int, attr: str, value: Any)#

sets the Attribute of the bond between Atom1 and Atom2.

Parameters:
  • atom1 (int) – Atom1

  • atom2 (int) – Atom2

  • attr (str) – Attribute

  • value (Any) – Value

set_bond_stereo(bond_stereo: BondStereo)#

Stets the stereo information of the bond

Parameters:
  • bond – Bond

  • bond_stereo (BondStereo) – Stereo information of the bond

subgraph(atoms: Iterable[int]) Self#

Returns a subgraph of the graph with the given atoms and the chiral information accordingly

Parameters:

atoms (Iterable[int]) – Atoms to be used for the subgraph

Return type:

Self

Returns:

Subgraph

enantiomer() Self#

Creates the enantiomer of the StereoCondensedReactionGraph by inversion of all chiral stereochemistries. The result can be identical to the molecule itself if the molecule is not chiral.

Return type:

Self

Returns:

Enantiomer

classmethod compose(mol_graphs: Iterable[MolGraph]) Self#

Creates a MolGraph object from a list of MolGraph objects

Parameters:

mol_graphs (Iterable[MolGraph]) – list of MolGraph objects

Return type:

Self

Returns:

Returns Combined MolGraph

classmethod from_graphs(reactant_graph: StereoMolGraph, product_graph: StereoMolGraph, ts_graph: None | StereoMolGraph = None) Self#

Creates a StereoCondensedReactionGraph from reactant and product StereoMolGraphs.

StereoCondensedReactionGraph is constructed from bond changes from reactant to the product. The atoms order and atom types of the reactant and product have to be the same.

Parameters:
Return type:

Self

Returns:

StereoCondensedReactionGraph

classmethod from_geometries(reactant_geo: ~stereomolgraph.coords.Geometry, product_geo: ~stereomolgraph.coords.Geometry, ts_geo: None | ~stereomolgraph.coords.Geometry = None, switching_function: ~stereomolgraph.coords.BondsFromDistance = <stereomolgraph.coords.BondsFromDistance object>) Self#

Creates a StereoCondensedReactionGraph from reactant, product and transition state Geometries.

StereoCondensedReactionGraph is constructed from bond changes from reactant to the product. The atoms order and atom types of the reactant and product have to be the same. The switching function is used to determine the connectivity of the atoms. Only the stereo information is taken from the transition state geometry.

Parameters:
  • reactant_geo (Geometry) – geometry of the reactant

  • product_geo (Geometry) – geometry of the product

  • ts_geo (None | Geometry) – geometry of the transition state (default: None)

  • switching_function (BondsFromDistance) – function to define the connectivity from geometry, defaults to StepSwitchingFunction() (default: <stereomolgraph.coords.BondsFromDistance object at 0x77e8e8b59350>)

Return type:

Self

Returns:

CondensedReactionGraph