CGRtools.containers package

Data classes.

class CGRtools.containers.CGRContainer
add_atom(atom: Union[DynamicElement, Element, int, str], *args, p_charge: int = 0, p_is_radical: bool = False, **kwargs)

new atom addition

add_bond(n, m, bond: Union[DynamicBond, Bond, int])

new bond addition

adjacency_matrix(set_bonds=False)

Adjacency matrix of Graph.

Parameters

set_bonds – if True set bond orders instead of 1.

aromatic_rings

existed or formed aromatic rings atoms numbers

atom(n: int) Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]
atoms() Iterator[Tuple[int, Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]]]

iterate over all atoms

atoms_count
atoms_numbers
atoms_order

Morgan like algorithm for graph nodes ordering

Returns

dict of atom-order pairs

atoms_rings

Dict of atoms rings which contains it.

atoms_rings_sizes

Sizes of rings containing atom.

augmented_substructure(atoms: Iterable[int], deep: int = 1, **kwargs) Graph

create substructure containing atoms and their neighbors

Parameters
  • atoms – list of core atoms in graph

  • deep – number of bonds between atoms and neighbors

  • meta – copy metadata to each substructure

  • as_query – return Query object based on graph substructure. for Molecule and CGR only

augmented_substructures(atoms: Iterable[int], deep: int = 1, **kwargs) List[Graph]

create list of substructures containing atoms and their neighbors

Parameters
  • atoms – list of core atoms in graph

  • deep – number of bonds between atoms and neighbors

  • meta – copy metadata to each substructure

  • as_query – return Query object based on graph substructure. for Molecule and CGR only

Returns

list of graphs containing atoms, atoms + first circle, atoms + 1st + 2nd, etc up to deep or while new nodes available

bond(n: int, m: int) Union[Bond, DynamicBond]
bonds() Iterator[Tuple[int, int, Union[Bond, DynamicBond]]]

iterate other all bonds

bonds_count
center_atoms

Get list of atoms of reaction center (atoms with dynamic: bonds, charges, radicals).

center_bonds

Get list of bonds of reaction center (bonds with dynamic orders).

centers_list

Get a list of lists of atoms of reaction centers

clean2d()

Calculate 2d layout of graph. https://pubs.acs.org/doi/10.1021/acs.jcim.7b00425 JS implementation used.

compose(other: Union[MoleculeContainer, CGRContainer]) CGRContainer

compose 2 graphs to CGR

Parameters

other – Molecule or CGR Container

Returns

CGRContainer

connected_components

Isolated components of single graph. E.g. salts as ion pair.

property connected_components_count: int

Number of components in graph

connected_rings

Rings groups with common atoms. E.g. naphthalene has two connected rings. Rings not atom ordered like sssr.

copy(**kwargs) CGRContainer

copy of graph

Parameters

meta – include metadata

decompose() Tuple[MoleculeContainer, MoleculeContainer]

decompose CGR to pair of Molecules, which represents reactants and products state of reaction

Returns

tuple of two molecules

delete_atom(n)

implementation of atom removing

delete_bond(n, m)

implementation of bond removing

depict(*, embedding=False)
depict3d(index: int = 0) str

Get X3DOM XML string.

Parameters

index – index of conformer

classmethod depict_settings(*, carbon: bool = False, bond_color: str = 'black', font_size: float = 0.5, aam: bool = True, aam_color: str = '#0305A7', bond_width: float = 0.04, dashes: Tuple[float, float] = (0.2, 0.1), query_color: str = '#5D8AA8', atoms_colors: tuple = ('#909090', '#D9FFFF', '#CC80FF', '#C2FF00', '#FFB5B5', '#101010', '#3050F8', '#FF0D0D', '#90E050', '#B3E3F5', '#AB5CF2', '#8AFF00', '#BFA6A6', '#F0C8A0', '#FF8000', '#C6C600', '#1FF01F', '#80D1E3', '#8F40D4', '#3DFF00', '#E6E6E6', '#BFC2C7', '#A6A6AB', '#8A99C7', '#9C7AC7', '#E06633', '#F090A0', '#50D050', '#C88033', '#7D80B0', '#C28F8F', '#668F8F', '#BD80E3', '#FFA100', '#A62929', '#5CB8D1', '#702EB0', '#00FF00', '#94FFFF', '#94E0E0', '#73C2C9', '#54B5B5', '#3B9E9E', '#248F8F', '#0A7D8C', '#006985', '#C0C0C0', '#FFD98F', '#A67573', '#668080', '#9E63B5', '#D47A00', '#940094', '#429EB0', '#57178F', '#00C900', '#70D4FF', '#FFFFC7', '#D9FFC7', '#C7FFC7', '#A3FFC7', '#8FFFC7', '#61FFC7', '#45FFC7', '#30FFC7', '#1FFFC7', '#00FF9C', '#00E675', '#00D452', '#00BF38', '#00AB24', '#4DC2FF', '#4DA6FF', '#2194D6', '#267DAB', '#266696', '#175487', '#D0D0E0', '#FFD123', '#B8B8D0', '#A6544D', '#575961', '#9E4FB5', '#AB5C00', '#754F45', '#428296', '#420066', '#007D00', '#70ABFA', '#00BAFF', '#00A1FF', '#008FFF', '#0080FF', '#006BFF', '#545CF2', '#785CE3', '#8A4FE3', '#A136D4', '#B31FD4', '#B31FBA', '#B30DA6', '#BD0D87', '#C70066', '#CC0059', '#D1004F', '#D90045', '#E00038', '#E6002E', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026'), dx_ci: float = 0.05, dy_ci: float = 0.2, triple_space: float = 0.13, aromatic_dashes: Tuple[float, float] = (0.15, 0.05), dy_nh: float = 0.15, formed_color: str = 'green', monochrome: bool = False, atom_radius: float = 0.2, dy_m: float = 0.2, symbols_font_style: str = 'sans-serif', other_size: float = 0.3, double_space: float = 0.06, dx_m: float = 0.05, span_dy: float = 0.15, span_size: float = 0.35, dx_nh: float = 0.075, other_font_style: str = 'monospace', cgr_aromatic_space: float = 0.18, aam_size: float = 0.25, other_color: str = 'black', broken_color: str = 'red', aromatic_space: float = 0.14, bond_radius=0.02)

Settings for depict of chemical structures

Parameters
  • carbon – if True, depict atom C

  • font_size – font size

  • aam_size – atom-to-atom mapping font size

  • span_size – font size for hydrogen count

  • other_size – isotope, radical, charges, neighbors and hybridization symbols size

  • bond_width – bond width

  • bond_color – color of bonds

  • aam_color – atom-to-atom mapping color

  • query_color – hybridization and neighbors color

  • atoms_colors – atom colors where key is atomic number - 1, value is atom color (str)

  • broken_color – only CGRContainer: color of broken bond

  • formed_color – only CGRContainer: color of formed bond

  • other_color – color for charges, radicals, isotopes

  • symbols_font_style – font style for atom symbols

  • other_font_style – font style for mapping, charges, radicals, isotopes, hybridization and neighbors

  • aam – if True, depict mapping

  • monochrome – if True, colors of items in molecule not used

  • dashes – first value is long of visible line, second is long of invisible line

  • aromatic_space – space between simple and aromatic bonds

  • triple_space – space between simple and triple bonds

  • double_space – space between simple and double bonds

  • cgr_aromatic_space – only CGRContainer: space between simple and aromatic bonds

  • aromatic_dashes – first value is long of visible line, second is long of invisible line

  • atom_radius – radius of atoms spheres in depict3d. if negative is multiplier to covalent radii

  • bond_radius – radius of bonds spheres in depict3d

  • dx_ci – x-axis offset relative to the center of the atom symbol for radical, charges, isotope

  • dy_ci – y-axis offset relative to the center of the atom symbol for radical, charges, isotope

  • dx_m – x-axis offset relative to the center of the atom symbol for atom-to-atom mapping

  • dy_m – y-axis offset relative to the center of the atom symbol for atom-to-atom mapping

  • dx_nh – x-axis offset relative to the center of the atom symbol for neighbors and hybridization

  • dy_nh – y-axis offset relative to the center of the atom symbol for neighbors and hybridization

  • span_dy – y-axis offset relative to the center of the atom symbol for hydrogen count

environment(atom: int, include_bond: bool = True, include_atom: bool = True) Tuple[Union[Tuple[int, Union[Bond, DynamicBond], Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]], Tuple[int, Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]], Tuple[int, Union[Bond, DynamicBond]], int], ...]

groups of (atom_number, bond, atom) connected to atom or groups of (atom_number, bond) connected to atom or groups of (atom_number, atom) connected to atom or neighbors atoms connected to atom

Parameters
  • atom – number

  • include_atom – include atom object

  • include_bond – include bond object

flush_cache()
get_automorphism_mapping() Iterator[Dict[int, int]]

Iterator of all possible automorphism mappings.

get_mapping(other: CGRContainer, **kwargs)

Get self to other substructure mapping generator.

Parameters
  • automorphism_filter – Skip matches to same atoms.

  • optimize – Morgan weights based automorphism preventing.

  • fallback – Try without optimization then nothing matched.

get_mcs_mapping(other: CGRContainer, **kwargs)

find maximum common substructure. based on clique searching in product graph.

Parameters

limit – limit tested cliques

has_atom(n: int) bool
has_bond(n: int, m: int) bool
is_automorphic()

Test for automorphism symmetry of graph.

is_equal(other) bool

Test self is same structure as other

is_substructure(other) bool

Test self is substructure of other

property meta: Dict
property name: str
neighbors(n: int) Tuple[int, int]

number of neighbors atoms excluding any-bonded

classmethod pickle_save_cache(arg: bool)

Store cache of Graph into pickle for speedup loading

remap(mapping, *, copy=False) CGRContainer
ring_atoms

Atoms in rings

rings_count

SSSR rings count.

skin_atoms

Atoms of rings and rings linkers [without terminal atoms]

skin_graph

Graph without terminal atoms. Only rings and linkers

smiles_atoms_order

Atoms order in canonic SMILES.

split(meta: bool = False) List[Graph]

split disconnected structure to connected substructures

Parameters

meta – copy metadata to each substructure

Returns

list of substructures

sssr

Smallest Set of Smallest Rings.

:return rings atoms numbers

substructure(atoms, *, as_query: bool = False, **kwargs) Union[CGRContainer, QueryCGRContainer]

create substructure containing atoms from atoms list

Parameters
  • atoms – list of atoms numbers of substructure

  • meta – if True metadata will be copied to substructure

  • as_query – return Query object based on graph substructure

union(other, **kwargs) CGRContainer

Merge Graphs into one.

Parameters

remap – if atoms has collisions then remap other graph atoms else raise exception.

view3d(index: int = 0, width='600px', height='400px')

Jupyter widget for 3D visualization.

Parameters
  • index – index of conformer

  • width – widget width

  • height – widget height

class CGRtools.containers.MoleculeContainer
add_atom(atom: Union[Element, int, str], *args, charge=0, is_radical=False, **kwargs)

Add new atom.

add_atom_stereo(n: int, env: Tuple[int, ...], mark: bool, *, clean_cache=True)

Add stereo data for specified neighbors bypass. Use it for tetrahedrons of allenes.

Parameters
  • n – number of tetrahedron atom or central atom of allene.

  • env – numbers of atoms with specified bypass

  • mark – clockwise or anti bypass.

See <https://www.daylight.com/dayhtml/doc/theory/theory.smiles.html> and <http://opensmiles.org/opensmiles.html>

add_bond(n, m, bond: Union[Bond, int])

Connect atoms with bonds.

For Thiele forms of molecule causes invalidation of internal state. Implicit hydrogens marks will not be set if atoms in aromatic rings. Call kekule() and thiele() in sequence to fix marks.

add_cis_trans_stereo(n: int, m: int, n1: int, n2: int, mark: bool, *, clean_cache=True)

Add stereo data to cis-trans double bonds (not allenes).

n1/n=m/n2

Parameters
  • n – number of starting atom of double bonds chain (alkenes of cumulenes)

  • m – number of ending atom of double bonds chain (alkenes of cumulenes)

  • n1 – number of neighboring atom of starting atom

  • n2 – number of neighboring atom of ending atom

  • mark – cis or trans

See <https://www.daylight.com/dayhtml/doc/theory/theory.smiles.html> and <http://opensmiles.org/opensmiles.html

add_wedge(n: int, m: int, mark: bool, *, clean_cache=True)

Add stereo data by wedge notation of bonds. Use it for tetrahedrons of allenes.

Parameters
  • n – number of atom from which wedge bond started

  • m – number of atom to which wedge bond coming

  • mark – up bond is True, down is False

adjacency_matrix(set_bonds=False)

Adjacency matrix of Graph.

Parameters

set_bonds – if True set bond orders instead of 1.

aromatic_rings

Aromatic rings atoms numbers

atom(n: int) Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]
atoms() Iterator[Tuple[int, Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]]]

iterate over all atoms

atoms_count
atoms_numbers
atoms_order

Morgan like algorithm for graph nodes ordering

Returns

dict of atom-order pairs

atoms_rings

Dict of atoms rings which contains it.

atoms_rings_sizes

Sizes of rings containing atom.

augmented_substructure(atoms: Iterable[int], deep: int = 1, **kwargs) Graph

create substructure containing atoms and their neighbors

Parameters
  • atoms – list of core atoms in graph

  • deep – number of bonds between atoms and neighbors

  • meta – copy metadata to each substructure

  • as_query – return Query object based on graph substructure. for Molecule and CGR only

augmented_substructures(atoms: Iterable[int], deep: int = 1, **kwargs) List[Graph]

create list of substructures containing atoms and their neighbors

Parameters
  • atoms – list of core atoms in graph

  • deep – number of bonds between atoms and neighbors

  • meta – copy metadata to each substructure

  • as_query – return Query object based on graph substructure. for Molecule and CGR only

Returns

list of graphs containing atoms, atoms + first circle, atoms + 1st + 2nd, etc up to deep or while new nodes available

bond(n: int, m: int) Union[Bond, DynamicBond]
bonds() Iterator[Tuple[int, int, Union[Bond, DynamicBond]]]

iterate other all bonds

bonds_count
brutto

Counted atoms dict

calculate_cis_trans_from_2d(*, clean_cache=True)

Calculate cis-trans stereo bonds from given 2d coordinates. Unusable for SMILES and INCHI.

canonicalize(*, logging=False) Union[bool, List[Tuple[Tuple[int, ...], int, str]]]

Convert molecule to canonical forms of functional groups and aromatic rings without explicit hydrogens.

Parameters

logging – return log.

check_thiele(fast=True) bool

Check basic aromaticity errors of molecule.

Parameters

fast – don’t try to solve kekule form

check_valence() List[int]

Check valences of all atoms.

Works only on molecules with aromatic rings in Kekule form. :return: list of invalid atoms

clean2d()

Calculate 2d layout of graph. https://pubs.acs.org/doi/10.1021/acs.jcim.7b00425 JS implementation used.

clean_isotopes() bool

Clean isotope marks from molecule. Return True if any isotope found.

clean_stereo()

Remove stereo data

compose(other: Union[MoleculeContainer, CGRContainer]) CGRContainer

Compose 2 graphs to CGR.

connected_components

Isolated components of single graph. E.g. salts as ion pair.

property connected_components_count: int

Number of components in graph

connected_rings

Rings groups with common atoms. E.g. naphthalene has two connected rings. Rings not atom ordered like sssr.

connected_rings_cumulenes

Connected ring with attached cumulenes.

copy(**kwargs) MoleculeContainer

copy of graph

Parameters

meta – include metadata

cumulenes

Alkenes, allenes and cumulenes atoms numbers

delete_atom(n)

Remove atom.

For Thiele forms of molecule causes invalidation of internal state. Implicit hydrogens marks will not be set if atoms in aromatic rings. Call kekule() and thiele() in sequence to fix marks.

delete_bond(n, m)

Disconnect atoms.

For Thiele forms of molecule causes invalidation of internal state. Implicit hydrogens marks will not be set if atoms in aromatic rings. Call kekule() and thiele() in sequence to fix marks.

depict(*, embedding=False)
depict3d(index: int = 0) str

Get X3DOM XML string.

Parameters

index – index of conformer

classmethod depict_settings(*, carbon: bool = False, bond_color: str = 'black', font_size: float = 0.5, aam: bool = True, aam_color: str = '#0305A7', bond_width: float = 0.04, dashes: Tuple[float, float] = (0.2, 0.1), query_color: str = '#5D8AA8', atoms_colors: tuple = ('#909090', '#D9FFFF', '#CC80FF', '#C2FF00', '#FFB5B5', '#101010', '#3050F8', '#FF0D0D', '#90E050', '#B3E3F5', '#AB5CF2', '#8AFF00', '#BFA6A6', '#F0C8A0', '#FF8000', '#C6C600', '#1FF01F', '#80D1E3', '#8F40D4', '#3DFF00', '#E6E6E6', '#BFC2C7', '#A6A6AB', '#8A99C7', '#9C7AC7', '#E06633', '#F090A0', '#50D050', '#C88033', '#7D80B0', '#C28F8F', '#668F8F', '#BD80E3', '#FFA100', '#A62929', '#5CB8D1', '#702EB0', '#00FF00', '#94FFFF', '#94E0E0', '#73C2C9', '#54B5B5', '#3B9E9E', '#248F8F', '#0A7D8C', '#006985', '#C0C0C0', '#FFD98F', '#A67573', '#668080', '#9E63B5', '#D47A00', '#940094', '#429EB0', '#57178F', '#00C900', '#70D4FF', '#FFFFC7', '#D9FFC7', '#C7FFC7', '#A3FFC7', '#8FFFC7', '#61FFC7', '#45FFC7', '#30FFC7', '#1FFFC7', '#00FF9C', '#00E675', '#00D452', '#00BF38', '#00AB24', '#4DC2FF', '#4DA6FF', '#2194D6', '#267DAB', '#266696', '#175487', '#D0D0E0', '#FFD123', '#B8B8D0', '#A6544D', '#575961', '#9E4FB5', '#AB5C00', '#754F45', '#428296', '#420066', '#007D00', '#70ABFA', '#00BAFF', '#00A1FF', '#008FFF', '#0080FF', '#006BFF', '#545CF2', '#785CE3', '#8A4FE3', '#A136D4', '#B31FD4', '#B31FBA', '#B30DA6', '#BD0D87', '#C70066', '#CC0059', '#D1004F', '#D90045', '#E00038', '#E6002E', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026'), dx_ci: float = 0.05, dy_ci: float = 0.2, triple_space: float = 0.13, aromatic_dashes: Tuple[float, float] = (0.15, 0.05), dy_nh: float = 0.15, formed_color: str = 'green', monochrome: bool = False, atom_radius: float = 0.2, dy_m: float = 0.2, symbols_font_style: str = 'sans-serif', other_size: float = 0.3, double_space: float = 0.06, dx_m: float = 0.05, span_dy: float = 0.15, span_size: float = 0.35, dx_nh: float = 0.075, other_font_style: str = 'monospace', cgr_aromatic_space: float = 0.18, aam_size: float = 0.25, other_color: str = 'black', broken_color: str = 'red', aromatic_space: float = 0.14, bond_radius=0.02)

Settings for depict of chemical structures

Parameters
  • carbon – if True, depict atom C

  • font_size – font size

  • aam_size – atom-to-atom mapping font size

  • span_size – font size for hydrogen count

  • other_size – isotope, radical, charges, neighbors and hybridization symbols size

  • bond_width – bond width

  • bond_color – color of bonds

  • aam_color – atom-to-atom mapping color

  • query_color – hybridization and neighbors color

  • atoms_colors – atom colors where key is atomic number - 1, value is atom color (str)

  • broken_color – only CGRContainer: color of broken bond

  • formed_color – only CGRContainer: color of formed bond

  • other_color – color for charges, radicals, isotopes

  • symbols_font_style – font style for atom symbols

  • other_font_style – font style for mapping, charges, radicals, isotopes, hybridization and neighbors

  • aam – if True, depict mapping

  • monochrome – if True, colors of items in molecule not used

  • dashes – first value is long of visible line, second is long of invisible line

  • aromatic_space – space between simple and aromatic bonds

  • triple_space – space between simple and triple bonds

  • double_space – space between simple and double bonds

  • cgr_aromatic_space – only CGRContainer: space between simple and aromatic bonds

  • aromatic_dashes – first value is long of visible line, second is long of invisible line

  • atom_radius – radius of atoms spheres in depict3d. if negative is multiplier to covalent radii

  • bond_radius – radius of bonds spheres in depict3d

  • dx_ci – x-axis offset relative to the center of the atom symbol for radical, charges, isotope

  • dy_ci – y-axis offset relative to the center of the atom symbol for radical, charges, isotope

  • dx_m – x-axis offset relative to the center of the atom symbol for atom-to-atom mapping

  • dy_m – y-axis offset relative to the center of the atom symbol for atom-to-atom mapping

  • dx_nh – x-axis offset relative to the center of the atom symbol for neighbors and hybridization

  • dy_nh – y-axis offset relative to the center of the atom symbol for neighbors and hybridization

  • span_dy – y-axis offset relative to the center of the atom symbol for hydrogen count

enumerate_kekule()

Enumerate all possible kekule forms of molecule.

enumerate_tautomers(*, prepare_molecules=True, full=True, zwitter=True, ring_chain=True, keto_enol=True, limit: int = 1000) Iterator[MoleculeContainer]

Enumerate all possible tautomeric forms of molecule.

Parameters
  • prepare_molecules – Standardize structures before. Aromatization and implicit hydrogens required.

  • full – Do full enumeration.

  • zwitter – Enable acid-base tautomerization

  • ring_chain – Enable ring-chain tautomerization

  • keto_enol – Enable keto-enol tautomerization

  • limit – Maximum amount of generated structures.

environment(atom: int, include_bond: bool = True, include_atom: bool = True) Tuple[Union[Tuple[int, Union[Bond, DynamicBond], Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]], Tuple[int, Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]], Tuple[int, Union[Bond, DynamicBond]], int], ...]

groups of (atom_number, bond, atom) connected to atom or groups of (atom_number, bond) connected to atom or groups of (atom_number, atom) connected to atom or neighbors atoms connected to atom

Parameters
  • atom – number

  • include_atom – include atom object

  • include_bond – include bond object

explicify_hydrogens(*, fix_stereo=True, start_map=None, return_maps=False) int

Add explicit hydrogens to atoms.

Returns

number of added atoms

flush_cache()
get_automorphism_mapping() Iterator[Dict[int, int]]

Iterator of all possible automorphism mappings.

get_fast_mapping(other: MoleculeContainer) Optional[Dict[int, int]]

Get self to other fast (suboptimal) structure mapping. Only one possible atoms mapping returned. Effective only for big molecules.

get_mapping(other: MoleculeContainer, **kwargs)

Get self to other substructure mapping generator.

Parameters
  • automorphism_filter – Skip matches to same atoms.

  • optimize – Morgan weights based automorphism preventing.

  • fallback – Try without optimization then nothing matched.

get_mcs_mapping(other: MoleculeContainer, **kwargs)

find maximum common substructure. based on clique searching in product graph.

Parameters

limit – limit tested cliques

has_atom(n: int) bool
has_bond(n: int, m: int) bool
heteroatoms(n: int) int

Number of neighbored heteroatoms (not carbon or hydrogen)

huckel_pi_electrons_energy

Huckel method based Pi electrons energy calculator. Parametrized for B C N O S.

implicify_hydrogens(*, fix_stereo=True) int

Remove explicit hydrogen if possible. Works only with Kekule forms of aromatic structures. Keeps isotopes of hydrogen.

Returns

number of removed hydrogens

is_automorphic()

Test for automorphism symmetry of graph.

is_equal(other) bool

Test self is same structure as other

is_radical

True if at least one atom is radical

is_substructure(other) bool

Test self is substructure of other

kekule() bool

Convert structure to kekule form. Return True if found any aromatic ring. Set implicit hydrogen count and hybridization marks on atoms.

Only one of possible double/single bonds positions will be set. For enumerate bonds positions use enumerate_kekule.

property meta: Dict
molecular_charge

Total charge of molecule

molecular_mass
property name: str
neighbors(n: int) int

number of neighbors atoms excluding any-bonded

neutralize(*, fix_stereo=True, logging=False) Union[bool, List[int]]

Transform biradical or dipole resonance structures into neutral form. Return True if structure form changed.

Parameters

logging – return list of changed atoms.

pack() bytes

Pack into compressed bytes. Note:

  • Less than 4096 atoms supported. Atoms mapping should be in range 1-4095.

  • Implicit hydrogens count should be in range 0-7

  • Isotope shift should be in range -15 - 15 relatively mdl.common_isotopes

  • Atoms neighbors should be in range 0-15

Format specification: Big endian bytes order 12 bit - number of atoms 12 bit - cis/trans stereo block size Atom block 9 bytes (repeated): 12 bit - atom number 4 bit - number of neighbors 2 bit tetrahedron sign (00 - not stereo, 10 or 11 - has stereo) 2 bit - allene sign 5 bit - isotope (00000 - not specified, over = isotope - common_isotope + 16) 7 bit - atomic number (<=118) 32 bit - XY float16 coordinates 3 bit - hydrogens (0-7) 4 bit - charge (charge + 4. possible range -4 - 4) 1 bit - radical state Connection table: flatten list of neighbors. neighbors count stored in atom block. For example CC(=O)O - {1: [2], 2: [1, 3, 4], 3: [2], 4: [2]} >> [2, 1, 3, 4, 2, 2]. Repeated block (equal to bonds count). 24 bit - paired 12 bit numbers. Bonds order block (repeated): 16 bit - 5 bonds grouped (3 bit each). 1 bit unused. Zero padding used than bonds count not proportional to 5. Cis/trans data block (repeated): 24 bit - atoms pair 7 bit - zero padding 1 bit - sign

classmethod pickle_save_cache(arg: bool)

Store cache of Graph into pickle for speedup loading

classmethod pure_unpack(data: bytes) MoleculeContainer

Unpack from compressed bytes. Python implementation.

remap(mapping, *, copy=False) MoleculeContainer
remove_hydrogen_bonds(*, keep_to_terminal=True, fix_stereo=True) int

Remove hydrogen bonds marked with 8 (any) bond

Parameters

keep_to_terminal – Keep any bonds to terminal hydrogens

Returns

removed bonds count

ring_atoms

Atoms in rings

rings_count

SSSR rings count.

skin_atoms

Atoms of rings and rings linkers [without terminal atoms]

skin_graph

Graph without terminal atoms. Only rings and linkers

smiles_atoms_order

Atoms order in canonic SMILES.

split(meta: bool = False) List[MoleculeContainer]

split disconnected structure to connected substructures

Parameters

meta – copy metadata to each substructure

Returns

list of substructures

sssr

Smallest Set of Smallest Rings.

:return rings atoms numbers

standardize(*, fix_stereo=True, logging=False) Union[bool, List[Tuple[Tuple[int, ...], int, str]]]

Standardize functional groups. Return True if any non-canonical group found.

Parameters

logging – return list of fixed atoms with matched rules.

substructure(atoms, *, as_query: bool = False, recalculate_hydrogens=True, **kwargs) Union[MoleculeContainer, QueryContainer]

Create substructure containing atoms from atoms list.

For Thiele forms of molecule In Molecule substructure causes invalidation of internal state. Implicit hydrogens marks will not be set if atoms in aromatic rings. Call kekule() and thiele() in sequence to fix marks.

Parameters
  • atoms – list of atoms numbers of substructure

  • meta – if True metadata will be copied to substructure

  • as_query – return Query object based on graph substructure

tautomerize(*, prepare_molecules=True, zwitter=True, ring_chain=True, keto_enol=True, limit: int = 1000) bool

Convert structure to canonical tautomeric form. Return True if structure changed.

tetrahedrons

Carbon sp3 atoms numbers

thiele(*, fix_tautomers=True) bool

Convert structure to aromatic form (Huckel rule ignored). Return True if found any kekule ring. Also marks atoms as aromatic.

Parameters

fix_tautomers – try to fix condensed rings with pyroles. N1C=CC2=NC=CC2=C1>>N1C=CC2=CN=CC=C12

union(other, **kwargs)

Merge Graphs into one.

Parameters

remap – if atoms has collisions then remap other graph atoms else raise exception.

classmethod unpack(data: bytes) MoleculeContainer

Unpack from compressed bytes.

view3d(index: int = 0, width='600px', height='400px')

Jupyter widget for 3D visualization.

Parameters
  • index – index of conformer

  • width – widget width

  • height – widget height

class CGRtools.containers.QueryCGRContainer
add_atom(atom: Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement, int, str], *args, p_charge: int = 0, p_is_radical: bool = False, neighbors: Optional[Union[int, List[int], Tuple[int, ...]]] = None, hybridization: Optional[Union[int, List[int], Tuple[int, ...]]] = None, p_neighbors: Optional[Union[int, List[int], Tuple[int, ...]]] = None, p_hybridization: Optional[Union[int, List[int], Tuple[int, ...]]] = None, **kwargs)

new atom addition

add_bond(n, m, bond: Union[DynamicBond, Bond, int])

new bond addition

adjacency_matrix(set_bonds=False)

Adjacency matrix of Graph.

Parameters

set_bonds – if True set bond orders instead of 1.

atom(n: int) Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]
atoms() Iterator[Tuple[int, Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]]]

iterate over all atoms

atoms_count
atoms_numbers
atoms_order

Morgan like algorithm for graph nodes ordering

Returns

dict of atom-order pairs

atoms_rings

Dict of atoms rings which contains it.

atoms_rings_sizes

Sizes of rings containing atom.

augmented_substructure(atoms: Iterable[int], deep: int = 1, **kwargs) Graph

create substructure containing atoms and their neighbors

Parameters
  • atoms – list of core atoms in graph

  • deep – number of bonds between atoms and neighbors

  • meta – copy metadata to each substructure

  • as_query – return Query object based on graph substructure. for Molecule and CGR only

augmented_substructures(atoms: Iterable[int], deep: int = 1, **kwargs) List[Graph]

create list of substructures containing atoms and their neighbors

Parameters
  • atoms – list of core atoms in graph

  • deep – number of bonds between atoms and neighbors

  • meta – copy metadata to each substructure

  • as_query – return Query object based on graph substructure. for Molecule and CGR only

Returns

list of graphs containing atoms, atoms + first circle, atoms + 1st + 2nd, etc up to deep or while new nodes available

bond(n: int, m: int) Union[Bond, DynamicBond]
bonds() Iterator[Tuple[int, int, Union[Bond, DynamicBond]]]

iterate other all bonds

bonds_count
clean2d()

Calculate 2d layout of graph. https://pubs.acs.org/doi/10.1021/acs.jcim.7b00425 JS implementation used.

connected_components

Isolated components of single graph. E.g. salts as ion pair.

property connected_components_count: int

Number of components in graph

connected_rings

Rings groups with common atoms. E.g. naphthalene has two connected rings. Rings not atom ordered like sssr.

copy(**kwargs) QueryCGRContainer

copy of graph

Parameters

meta – include metadata

delete_atom(n)

implementation of atom removing

delete_bond(n: int, m: int)

implementation of bond removing

depict(*, embedding=False)
classmethod depict_settings(*, carbon: bool = False, bond_color: str = 'black', font_size: float = 0.5, aam: bool = True, aam_color: str = '#0305A7', bond_width: float = 0.04, dashes: Tuple[float, float] = (0.2, 0.1), query_color: str = '#5D8AA8', atoms_colors: tuple = ('#909090', '#D9FFFF', '#CC80FF', '#C2FF00', '#FFB5B5', '#101010', '#3050F8', '#FF0D0D', '#90E050', '#B3E3F5', '#AB5CF2', '#8AFF00', '#BFA6A6', '#F0C8A0', '#FF8000', '#C6C600', '#1FF01F', '#80D1E3', '#8F40D4', '#3DFF00', '#E6E6E6', '#BFC2C7', '#A6A6AB', '#8A99C7', '#9C7AC7', '#E06633', '#F090A0', '#50D050', '#C88033', '#7D80B0', '#C28F8F', '#668F8F', '#BD80E3', '#FFA100', '#A62929', '#5CB8D1', '#702EB0', '#00FF00', '#94FFFF', '#94E0E0', '#73C2C9', '#54B5B5', '#3B9E9E', '#248F8F', '#0A7D8C', '#006985', '#C0C0C0', '#FFD98F', '#A67573', '#668080', '#9E63B5', '#D47A00', '#940094', '#429EB0', '#57178F', '#00C900', '#70D4FF', '#FFFFC7', '#D9FFC7', '#C7FFC7', '#A3FFC7', '#8FFFC7', '#61FFC7', '#45FFC7', '#30FFC7', '#1FFFC7', '#00FF9C', '#00E675', '#00D452', '#00BF38', '#00AB24', '#4DC2FF', '#4DA6FF', '#2194D6', '#267DAB', '#266696', '#175487', '#D0D0E0', '#FFD123', '#B8B8D0', '#A6544D', '#575961', '#9E4FB5', '#AB5C00', '#754F45', '#428296', '#420066', '#007D00', '#70ABFA', '#00BAFF', '#00A1FF', '#008FFF', '#0080FF', '#006BFF', '#545CF2', '#785CE3', '#8A4FE3', '#A136D4', '#B31FD4', '#B31FBA', '#B30DA6', '#BD0D87', '#C70066', '#CC0059', '#D1004F', '#D90045', '#E00038', '#E6002E', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026'), dx_ci: float = 0.05, dy_ci: float = 0.2, triple_space: float = 0.13, aromatic_dashes: Tuple[float, float] = (0.15, 0.05), dy_nh: float = 0.15, formed_color: str = 'green', monochrome: bool = False, atom_radius: float = 0.2, dy_m: float = 0.2, symbols_font_style: str = 'sans-serif', other_size: float = 0.3, double_space: float = 0.06, dx_m: float = 0.05, span_dy: float = 0.15, span_size: float = 0.35, dx_nh: float = 0.075, other_font_style: str = 'monospace', cgr_aromatic_space: float = 0.18, aam_size: float = 0.25, other_color: str = 'black', broken_color: str = 'red', aromatic_space: float = 0.14, bond_radius=0.02)

Settings for depict of chemical structures

Parameters
  • carbon – if True, depict atom C

  • font_size – font size

  • aam_size – atom-to-atom mapping font size

  • span_size – font size for hydrogen count

  • other_size – isotope, radical, charges, neighbors and hybridization symbols size

  • bond_width – bond width

  • bond_color – color of bonds

  • aam_color – atom-to-atom mapping color

  • query_color – hybridization and neighbors color

  • atoms_colors – atom colors where key is atomic number - 1, value is atom color (str)

  • broken_color – only CGRContainer: color of broken bond

  • formed_color – only CGRContainer: color of formed bond

  • other_color – color for charges, radicals, isotopes

  • symbols_font_style – font style for atom symbols

  • other_font_style – font style for mapping, charges, radicals, isotopes, hybridization and neighbors

  • aam – if True, depict mapping

  • monochrome – if True, colors of items in molecule not used

  • dashes – first value is long of visible line, second is long of invisible line

  • aromatic_space – space between simple and aromatic bonds

  • triple_space – space between simple and triple bonds

  • double_space – space between simple and double bonds

  • cgr_aromatic_space – only CGRContainer: space between simple and aromatic bonds

  • aromatic_dashes – first value is long of visible line, second is long of invisible line

  • atom_radius – radius of atoms spheres in depict3d. if negative is multiplier to covalent radii

  • bond_radius – radius of bonds spheres in depict3d

  • dx_ci – x-axis offset relative to the center of the atom symbol for radical, charges, isotope

  • dy_ci – y-axis offset relative to the center of the atom symbol for radical, charges, isotope

  • dx_m – x-axis offset relative to the center of the atom symbol for atom-to-atom mapping

  • dy_m – y-axis offset relative to the center of the atom symbol for atom-to-atom mapping

  • dx_nh – x-axis offset relative to the center of the atom symbol for neighbors and hybridization

  • dy_nh – y-axis offset relative to the center of the atom symbol for neighbors and hybridization

  • span_dy – y-axis offset relative to the center of the atom symbol for hydrogen count

environment(atom: int, include_bond: bool = True, include_atom: bool = True) Tuple[Union[Tuple[int, Union[Bond, DynamicBond], Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]], Tuple[int, Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]], Tuple[int, Union[Bond, DynamicBond]], int], ...]

groups of (atom_number, bond, atom) connected to atom or groups of (atom_number, bond) connected to atom or groups of (atom_number, atom) connected to atom or neighbors atoms connected to atom

Parameters
  • atom – number

  • include_atom – include atom object

  • include_bond – include bond object

flush_cache()
get_automorphism_mapping() Iterator[Dict[int, int]]

Iterator of all possible automorphism mappings.

get_mapping(other: Union[QueryCGRContainer, CGRContainer], **kwargs)

Get self to other substructure mapping generator.

Parameters
  • automorphism_filter – Skip matches to same atoms.

  • optimize – Morgan weights based automorphism preventing.

  • fallback – Try without optimization then nothing matched.

get_mcs_mapping(other: Union[QueryCGRContainer, CGRContainer], **kwargs)

find maximum common substructure. based on clique searching in product graph.

Parameters

limit – limit tested cliques

has_atom(n: int) bool
has_bond(n: int, m: int) bool
is_automorphic()

Test for automorphism symmetry of graph.

is_equal(other) bool

Test self is same structure as other

is_substructure(other) bool

Test self is substructure of other

property meta: Dict
property name: str
classmethod pickle_save_cache(arg: bool)

Store cache of Graph into pickle for speedup loading

remap(mapping, *, copy=False) QueryCGRContainer
ring_atoms

Atoms in rings

rings_count

SSSR rings count.

skin_atoms

Atoms of rings and rings linkers [without terminal atoms]

skin_graph

Graph without terminal atoms. Only rings and linkers

smiles_atoms_order

Atoms order in canonic SMILES.

split(meta: bool = False) List[Graph]

split disconnected structure to connected substructures

Parameters

meta – copy metadata to each substructure

Returns

list of substructures

sssr

Smallest Set of Smallest Rings.

:return rings atoms numbers

substructure(atoms, **kwargs) QueryCGRContainer

create substructure containing atoms from atoms list

Parameters
  • atoms – list of atoms numbers of substructure

  • meta – if True metadata will be copied to substructure

union(other, **kwargs) QueryCGRContainer

Merge Graphs into one.

Parameters

remap – if atoms has collisions then remap other graph atoms else raise exception.

class CGRtools.containers.QueryContainer
add_atom(atom: Union[QueryElement, AnyElement, Element, int, str], *args, neighbors: Optional[Union[int, List[int], Tuple[int, ...]]] = None, hybridization: Optional[Union[int, List[int], Tuple[int, ...]]] = None, hydrogens: Optional[Union[int, List[int], Tuple[int, ...]]] = None, rings_sizes: Optional[Union[int, List[int], Tuple[int, ...]]] = None, heteroatoms: Optional[Union[int, List[int], Tuple[int, ...]]] = None, **kwargs)

new atom addition

add_bond(n, m, bond: Union[QueryBond, Bond, int, Tuple[int, ...]])

new bond addition

adjacency_matrix(set_bonds=False)

Adjacency matrix of Graph.

Parameters

set_bonds – if True set bond orders instead of 1.

aromatic_rings

Aromatic rings atoms numbers

atom(n: int) Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]
atoms() Iterator[Tuple[int, Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]]]

iterate over all atoms

atoms_count
atoms_numbers
atoms_order

Morgan like algorithm for graph nodes ordering

Returns

dict of atom-order pairs

atoms_rings

Dict of atoms rings which contains it.

atoms_rings_sizes

Sizes of rings containing atom.

augmented_substructure(atoms: Iterable[int], deep: int = 1, **kwargs) Graph

create substructure containing atoms and their neighbors

Parameters
  • atoms – list of core atoms in graph

  • deep – number of bonds between atoms and neighbors

  • meta – copy metadata to each substructure

  • as_query – return Query object based on graph substructure. for Molecule and CGR only

augmented_substructures(atoms: Iterable[int], deep: int = 1, **kwargs) List[Graph]

create list of substructures containing atoms and their neighbors

Parameters
  • atoms – list of core atoms in graph

  • deep – number of bonds between atoms and neighbors

  • meta – copy metadata to each substructure

  • as_query – return Query object based on graph substructure. for Molecule and CGR only

Returns

list of graphs containing atoms, atoms + first circle, atoms + 1st + 2nd, etc up to deep or while new nodes available

bond(n: int, m: int) Union[Bond, DynamicBond]
bonds() Iterator[Tuple[int, int, Union[Bond, DynamicBond]]]

iterate other all bonds

bonds_count
clean2d()

Calculate 2d layout of graph. https://pubs.acs.org/doi/10.1021/acs.jcim.7b00425 JS implementation used.

clean_stereo()

Remove stereo data

connected_components

Isolated components of single graph. E.g. salts as ion pair.

property connected_components_count: int

Number of components in graph

connected_rings

Rings groups with common atoms. E.g. naphthalene has two connected rings. Rings not atom ordered like sssr.

connected_rings_cumulenes

Connected ring with attached cumulenes.

copy(**kwargs) QueryContainer

copy of graph

Parameters

meta – include metadata

cumulenes

Alkenes, allenes and cumulenes atoms numbers

delete_atom(n)

implementation of atom removing

delete_bond(n, m)

implementation of bond removing

depict(*, embedding=False)
classmethod depict_settings(*, carbon: bool = False, bond_color: str = 'black', font_size: float = 0.5, aam: bool = True, aam_color: str = '#0305A7', bond_width: float = 0.04, dashes: Tuple[float, float] = (0.2, 0.1), query_color: str = '#5D8AA8', atoms_colors: tuple = ('#909090', '#D9FFFF', '#CC80FF', '#C2FF00', '#FFB5B5', '#101010', '#3050F8', '#FF0D0D', '#90E050', '#B3E3F5', '#AB5CF2', '#8AFF00', '#BFA6A6', '#F0C8A0', '#FF8000', '#C6C600', '#1FF01F', '#80D1E3', '#8F40D4', '#3DFF00', '#E6E6E6', '#BFC2C7', '#A6A6AB', '#8A99C7', '#9C7AC7', '#E06633', '#F090A0', '#50D050', '#C88033', '#7D80B0', '#C28F8F', '#668F8F', '#BD80E3', '#FFA100', '#A62929', '#5CB8D1', '#702EB0', '#00FF00', '#94FFFF', '#94E0E0', '#73C2C9', '#54B5B5', '#3B9E9E', '#248F8F', '#0A7D8C', '#006985', '#C0C0C0', '#FFD98F', '#A67573', '#668080', '#9E63B5', '#D47A00', '#940094', '#429EB0', '#57178F', '#00C900', '#70D4FF', '#FFFFC7', '#D9FFC7', '#C7FFC7', '#A3FFC7', '#8FFFC7', '#61FFC7', '#45FFC7', '#30FFC7', '#1FFFC7', '#00FF9C', '#00E675', '#00D452', '#00BF38', '#00AB24', '#4DC2FF', '#4DA6FF', '#2194D6', '#267DAB', '#266696', '#175487', '#D0D0E0', '#FFD123', '#B8B8D0', '#A6544D', '#575961', '#9E4FB5', '#AB5C00', '#754F45', '#428296', '#420066', '#007D00', '#70ABFA', '#00BAFF', '#00A1FF', '#008FFF', '#0080FF', '#006BFF', '#545CF2', '#785CE3', '#8A4FE3', '#A136D4', '#B31FD4', '#B31FBA', '#B30DA6', '#BD0D87', '#C70066', '#CC0059', '#D1004F', '#D90045', '#E00038', '#E6002E', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026', '#EB0026'), dx_ci: float = 0.05, dy_ci: float = 0.2, triple_space: float = 0.13, aromatic_dashes: Tuple[float, float] = (0.15, 0.05), dy_nh: float = 0.15, formed_color: str = 'green', monochrome: bool = False, atom_radius: float = 0.2, dy_m: float = 0.2, symbols_font_style: str = 'sans-serif', other_size: float = 0.3, double_space: float = 0.06, dx_m: float = 0.05, span_dy: float = 0.15, span_size: float = 0.35, dx_nh: float = 0.075, other_font_style: str = 'monospace', cgr_aromatic_space: float = 0.18, aam_size: float = 0.25, other_color: str = 'black', broken_color: str = 'red', aromatic_space: float = 0.14, bond_radius=0.02)

Settings for depict of chemical structures

Parameters
  • carbon – if True, depict atom C

  • font_size – font size

  • aam_size – atom-to-atom mapping font size

  • span_size – font size for hydrogen count

  • other_size – isotope, radical, charges, neighbors and hybridization symbols size

  • bond_width – bond width

  • bond_color – color of bonds

  • aam_color – atom-to-atom mapping color

  • query_color – hybridization and neighbors color

  • atoms_colors – atom colors where key is atomic number - 1, value is atom color (str)

  • broken_color – only CGRContainer: color of broken bond

  • formed_color – only CGRContainer: color of formed bond

  • other_color – color for charges, radicals, isotopes

  • symbols_font_style – font style for atom symbols

  • other_font_style – font style for mapping, charges, radicals, isotopes, hybridization and neighbors

  • aam – if True, depict mapping

  • monochrome – if True, colors of items in molecule not used

  • dashes – first value is long of visible line, second is long of invisible line

  • aromatic_space – space between simple and aromatic bonds

  • triple_space – space between simple and triple bonds

  • double_space – space between simple and double bonds

  • cgr_aromatic_space – only CGRContainer: space between simple and aromatic bonds

  • aromatic_dashes – first value is long of visible line, second is long of invisible line

  • atom_radius – radius of atoms spheres in depict3d. if negative is multiplier to covalent radii

  • bond_radius – radius of bonds spheres in depict3d

  • dx_ci – x-axis offset relative to the center of the atom symbol for radical, charges, isotope

  • dy_ci – y-axis offset relative to the center of the atom symbol for radical, charges, isotope

  • dx_m – x-axis offset relative to the center of the atom symbol for atom-to-atom mapping

  • dy_m – y-axis offset relative to the center of the atom symbol for atom-to-atom mapping

  • dx_nh – x-axis offset relative to the center of the atom symbol for neighbors and hybridization

  • dy_nh – y-axis offset relative to the center of the atom symbol for neighbors and hybridization

  • span_dy – y-axis offset relative to the center of the atom symbol for hydrogen count

environment(atom: int, include_bond: bool = True, include_atom: bool = True) Tuple[Union[Tuple[int, Union[Bond, DynamicBond], Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]], Tuple[int, Union[Element, DynamicElement, QueryElement, DynamicQueryElement, AnyElement, DynamicAnyElement, ListElement]], Tuple[int, Union[Bond, DynamicBond]], int], ...]

groups of (atom_number, bond, atom) connected to atom or groups of (atom_number, bond) connected to atom or groups of (atom_number, atom) connected to atom or neighbors atoms connected to atom

Parameters
  • atom – number

  • include_atom – include atom object

  • include_bond – include bond object

flush_cache()
get_automorphism_mapping() Iterator[Dict[int, int]]

Iterator of all possible automorphism mappings.

get_mapping(other: Union[QueryContainer, MoleculeContainer], **kwargs)

Get self to other substructure mapping generator.

Parameters
  • automorphism_filter – Skip matches to same atoms.

  • optimize – Morgan weights based automorphism preventing.

  • fallback – Try without optimization then nothing matched.

get_mcs_mapping(other: Union[QueryContainer, MoleculeContainer], **kwargs)

find maximum common substructure. based on clique searching in product graph.

Parameters

limit – limit tested cliques

has_atom(n: int) bool
has_bond(n: int, m: int) bool
is_automorphic()

Test for automorphism symmetry of graph.

is_equal(other) bool

Test self is same structure as other

is_substructure(other) bool

Test self is substructure of other

property meta: Dict
property name: str
classmethod pickle_save_cache(arg: bool)

Store cache of Graph into pickle for speedup loading

remap(mapping, *, copy=False) QueryContainer
ring_atoms

Atoms in rings

rings_count

SSSR rings count.

skin_atoms

Atoms of rings and rings linkers [without terminal atoms]

skin_graph

Graph without terminal atoms. Only rings and linkers

smiles_atoms_order

Atoms order in canonic SMILES.

split(meta: bool = False) List[Graph]

split disconnected structure to connected substructures

Parameters

meta – copy metadata to each substructure

Returns

list of substructures

sssr

Smallest Set of Smallest Rings.

:return rings atoms numbers

substructure(atoms, **kwargs) QueryContainer

create substructure containing atoms from atoms list

Parameters
  • atoms – list of atoms numbers of substructure

  • meta – if True metadata will be copied to substructure

tetrahedrons

Carbon sp3 atoms numbers

union(other, **kwargs) QueryContainer

Merge Graphs into one.

Parameters

remap – if atoms has collisions then remap other graph atoms else raise exception.

class CGRtools.containers.ReactionContainer(reactants: Iterable[Union[MoleculeContainer, QueryContainer, CGRContainer, QueryCGRContainer]] = (), products: Iterable[Union[MoleculeContainer, QueryContainer, CGRContainer, QueryCGRContainer]] = (), reagents: Iterable[Union[MoleculeContainer, QueryContainer, CGRContainer, QueryCGRContainer]] = (), meta: Optional[Dict] = None, name: Optional[str] = None)

Reaction storage. Contains reactants, products and reagents lists.

Reaction storage hashable and comparable. based on reaction unique signature (SMIRKS).

New reaction object creation

Parameters
  • reactants – list of MoleculeContainers [or other Structure Containers] in left side of reaction

  • products – right side of reaction. see reactants

  • reagents – middle side of reaction: solvents, catalysts, etc. see reactants

  • meta – dictionary of metadata. like DTYPE-DATUM in RDF

canonicalize(fix_mapping: bool = True, *, logging=False) Union[bool, Tuple[int, Tuple[int, ...], int, str]]

Convert molecules to canonical forms of functional groups and aromatic rings without explicit hydrogens. Works only for Molecules. Return True if in any molecule found not canonical group.

Parameters
  • fix_mapping – Search AAM errors of functional groups.

  • logging – return log from molecules with index of molecule at first position. Otherwise return True if these groups found in any molecule.

centers_list

Reaction centers with leaving and coming groups.

check_valence() List[Tuple[int, Tuple[int, ...]]]

Check valences of all atoms of all molecules.

Works only on molecules with aromatic rings in Kekule form. :return: list of invalid molecules with invalid atoms lists

clean2d()

Recalculate 2d coordinates

clean_isotopes() bool

Clean isotope marks for all molecules in reaction. Returns True if in any molecule found isotope.

clean_stereo()

Remove stereo data

compose() CGRContainer

Get CGR of reaction

Reagents will be presented as unchanged molecules :return: CGRContainer

contract_ions() bool

Contract ions into salts (Molecules with disconnected components). Note: works only for unambiguous cases. e.g. equal anions/cations and different or equal cations/anions.

Return True if any ions contracted.

copy() ReactionContainer

Get copy of object

depict()
static depict_settings(**kwargs)

Settings for depict of chemical structures

enumerate_centers() Iterator[ReactionContainer]

Get all possible single stage reactions from multistage. Note multicomponent molecules (salts etc) can be treated incorrectly.

explicify_hydrogens() int

Add explicit hydrogens to atoms

Returns

number of added atoms

extended_centers_list

Additionally to centers_list include: * First environment of dynamic atoms. * Whole formed cycles. For condensed cycles smallest is taken. * Whole aromatic cycle with at least one dynamic atom. * Whole small (3, 4) cycle with at least one dynamic atom. * Double or triple bonds connected to previous atoms.

Note for multiple RCs intersection possible. Use enumerate_centers to prevent unobvious RCs.

fix_mapping(*, logging: bool = False) bool

Fix atom-to-atom mapping of some functional groups. Return True if found AAM errors.

fix_positions()

Fix coordinates of molecules in reaction

flush_cache()
classmethod from_cgr(cgr: CGRContainer) ReactionContainer

Decompose CGR into reaction

implicify_hydrogens() int

Remove explicit hydrogens if possible

Returns

number of removed hydrogens

kekule() bool

Convert structures to kekule form. Works only for Molecules. Return True if in any molecule found aromatic ring

classmethod load_remapping_rules(reactions)

Load AAM fixing rules. Required pairs of bad mapped and good mapped reactions. Reactants in pairs should be fully equal (equal molecules and equal atom orders). Products should be equal but with different atom numbers.

property meta: Dict

Dictionary of metadata. Like DTYPE-DATUM in RDF

molecules() Iterator[Union[MoleculeContainer, QueryContainer, CGRContainer, QueryCGRContainer]]

Iterator of all reaction molecules

property name: str
neutralize(*, logging=False) Union[bool, Tuple[int, Tuple[int, ...]]]

Transform biradical or dipole resonance structures into neutral form. Works only for Molecules.

Parameters

logging – return log from molecules with index of molecule at first position. Otherwise return True if these groups found in any molecule.

classmethod pickle_save_cache(arg: bool)

Store cache of reaction into pickle for speedup loading

property products: Tuple[Union[MoleculeContainer, QueryContainer, CGRContainer, QueryCGRContainer], ...]
property reactants: Tuple[Union[MoleculeContainer, QueryContainer, CGRContainer, QueryCGRContainer], ...]
property reagents: Tuple[Union[MoleculeContainer, QueryContainer, CGRContainer, QueryCGRContainer], ...]
remove_reagents(*, keep_reagents: bool = False) bool

Preprocess reaction according to mapping, using the following idea: molecules(each separated graph) will be placed to reagents if it is not changed in the reaction (no bonds, charges reorders)

Return True if any reagent found.

standardize(fix_mapping: bool = True, *, logging=False) Union[bool, Tuple[int, Tuple[int, ...], int, str]]

Standardize functional groups. Works only for Molecules.

Parameters
  • fix_mapping – Search AAM errors of functional groups.

  • logging – return log from molecules with index of molecule at first position. Otherwise return True if these groups found in any molecule.

thiele() bool

Convert structures to aromatic form. Works only for Molecules. Return True if in any molecule found kekule ring