Bond¶
This is the pydoc code for the bond module.
# molli.chem.bond
This submodule defines classes Bond, Connectivity and others.
- class molli.chem.bond.BondType(value)¶
Bases:
IntEnumThe BondType class is an Enumeration class for assigning bond types
- Parameters:
IntEnum – Accepts integer enumerations for different bond types
Examples
>>> ml.BondType(20) == ml.BondType.Aromatic True
- class molli.chem.bond.BondStereo(value)¶
Bases:
IntEnumThe BondStereo class is an Enumeration class for assigning bond geometry
- Parameters:
IntEnum – Accepts integer enumerations for different bond geometry
Examples
>>> ml.BondStereo(10) == ml.BondStereo.E True
- class molli.chem.bond.Bond(a1: Atom, a2: Atom, label: str = None, btype: BondType = BondType.Single, stereo: BondStereo = BondStereo.Unknown, f_order=1.0, attrib: dict = NOTHING, parent=None)¶
Bases:
objectThe class for bonds in the MOLLI package. a1 and a2 are the atoms that the bond connects and are interchangeable. The atoms are ordered upon initialization.
- evolve(**changes) Bond¶
Evolves the bond into a new bond with the changes specified
- Returns:
A new Bond instance with the changes specified
- Return type:
Examples
>>> benzene = ml.Molecule.load_mol2(ml.files.benzene_mol2) >>> bond = benzene.get_bond(0) >>> bond.btype <BondType.Aromatic: 20> >>> new_bond = bond.evolve(btype = ml.BondType.Double) >>> new_bond.btype <BondType.Double: 2>
- property order: float¶
returns: Returns the bond order as a float :rtype: float
Examples
- Bonds default to 1.0 when not specified
>>> bond = ml.Bond(a1 = ml.Atom("C"), a2= ml.Atom("C")) >>> bond.order 1.0
- Aromatic Bonds default to 1.5
>>> benzene = ml.Molecule.load_mol2(ml.files.benzene_mol2) >>> bond = benzene.get_bond(0) >>> bond.order 1.5
- as_dict(schema: List[str] = None) dict¶
Returns the bond as a dictionary
- Parameters:
schema (List[str], optional) – Can be used to specify if only certain properties are desired, by default None
- Returns:
This dictionary contains properties of the associated bond
- Return type:
dict
Examples
>>> ml.Bond(a1 = ml.Atom("C"), a2= ml.Atom("C")).as_dict() {'a1':{'element': C...}, 'a2': {'element': C ...}, 'label': None, ...} >>> bond = ml.Bond(a1 = ml.Atom("C"), a2= ml.Atom("C")).as_dict( ['a1','stereo','attrib'] ) {'a1':{'element': C...}, 'stereo': <BondStereo.Unknown: 0>, 'attrib': {}}}
- as_tuple(schema: List[str] = None) tuple¶
Returns the bond as a tuple
- Parameters:
schema (List[str], optional) – Can be used to specify if only certain properties are desired, by default None
- Returns:
This tuple contains properties of the associated bond, also returning a1 and a2 as tuples
- Return type:
tuple
Examples
>>> ml.Bond(a1 = ml.Atom("C"), a2= ml.Atom("C")).as_tuple() ((C,...),(C,...), None, <BondType.Single: 1>, ...) >>> bond = ml.Bond(a1 = ml.Atom("C"), a2= ml.Atom("C")).as_tuple( ['a1','stereo','attrib'] ) ((C,...),<BondStereo.Unknown: 0>, {})
- property expected_length: float¶
- returns: Returns an estimated value of a bond connection between two atoms
based on the covalent radius of a single bond
- Return type:
float
Examples
>>> a1, a2 = ml.Atom("Pb", label='a1'), ml.Atom("H", label="a2") >>> bond = ml.Bond(a1, a2) >>> bond.expected_length 1.76 # (Pb = 1.44, H = 0.32)
- get_mol2_type() str¶
Used to return the Sybyl Mol2 Type of a bond
- Returns:
Returns the Sybyl Mol2 type of a bond
- Return type:
str
Examples
>>> unknown_molli_bond.get_mol2_type() 'am' # Indicates it was an amide bond
- class molli.chem.bond.Connectivity(other: Promolecule = None, /, *, n_atoms: int = 0, name: str = None, copy_atoms: bool = False, charge: int = None, mult: int = None, **kwds)¶
Bases:
PromoleculeThis is a parent class that employs methods that work on Promolecule (i.e. a list of disconnected atoms with no structure or geometry assigned to them) and connections between these disconnected atoms. This can be thought of as an undirected graph of nodes (atoms) and edges (bonds) without explicit coordinates.
- property bonds: List[Bond]¶
returns: Returns an ordered list of the Bonds in the Connectivity instance :rtype: List[Bond]
Examples
- The Molecule class inherits bonds
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> dendrobine.bonds [Bond(a1=42, a2=22, ...), Bond(a1=41,a2=22, ...), ...]
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> connect.bonds [Bond(a1=42, a2=22, ...), Bond(a1=41,a2=22, ...), ...]
- property n_bonds: int¶
returns: Returns the total number of bonds in the Connectivity instance :rtype: int
Examples
- The Molecule class inherits n_bonds
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> dendrobine.n_bonds 47
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> connect.n_bonds 47
- lookup_bond(a1: Atom | int | str | Element, a2: Atom | int | str | Element) Bond | None¶
Retrieves the bond that connects two atoms
- Parameters:
- Returns:
Returns the bond found or None if the bond doesn’t exist
- Return type:
Bond | None
Examples
- The Molecule class inherits lookup_bond()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> a1, a2 = dendrobine.get_atoms(0,1) >>> dendrobine.lookup_bond(a1, a2) Bond(a1=0, a2=1, label=None, ...)
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> connect.lookup_bond(a1, a2) Bond(a1=0, a2=1, label=None, ...)
- index_bond(b: Bond) int¶
Fetches the atom index from the Connectivity instance
- Parameters:
b (Bond) – Must be a bond in the Connectivity instance list
- Returns:
Returns the index of the bond
- Return type:
int
Examples
- The Molecule class inherits index_bond()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> bond = dendrobine.lookup_bond(3,4) >>> dendrobine.index_bond(bond) 31
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> bond = connect.lookup_bond(3,4) >>> connect.index_bond(bond) 31
- get_bond(b: Bond | int) Bond¶
Fetches a bond from the Connectivity instance
Examples
- The Molecule class inherits get_bond()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> dendrobine.get_bond(10) Bond(a1=21, a2=39, label=None, btype=Single, stereo=Unknown, f_order=1.0)
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> connect.get_bond(10) Bond(a1=21, a2=39, label=None, btype=Single, stereo=Unknown, f_order=1.0)
- append_bond(bond: Bond) None¶
Appends a bond to the Connectivity instance
- Parameters:
bond (Bond) – A bond instance to be added
Examples
- The Molecule class inherits append_bond()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> a1, a2 = dendrobine.get_atoms(0,35) >>> new_bond = ml.Bond(a1,a2) >>> dendrobine.append_bond(new_bond) >>> dendrobine.lookup_bond(new_bond) Bond(a1=0, a2=35, label=None, btype=Single, stereo=Unknown, f_order=1.0)
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> a1, a2 = connect.get_atoms(0,35) >>> new_bond = ml.Bond(a1,a2) >>> connect.append_bond(new_bond) >>> connect.lookup_bond(new_bond) Bond(a1=0, a2=35, label=None, btype=Single, stereo=Unknown, f_order=1.0)
- append_bonds(*bonds: Bond) None¶
Appends multiple bonds to the Connectivity instance
Examples
- The Molecule class inherits append_bonds()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> a1, a2, a3 = dendrobine.get_atoms(0,35, 39) >>> b1 = ml.Bond(a1,a2) >>> b2 = ml.Bond(a1,a3) >>> dendrobine.append_bonds(b1,b2) >>> dendrobine.lookup_bond(a1,a2) Bond(a1=0, a2=35, label=None, btype=Single, stereo=Unknown, f_order=1.0) >>> dendrobine.lookup_bond(a1,a3) Bond(a1=0, a2=39, label=None, btype=Single, stereo=Unknown, f_order=1.0)
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> a1, a2, a3 = connect.get_atoms(0,35, 39) >>> b1 = ml.Bond(a1,a2) >>> b2 = ml.Bond(a1,a3) >>> connect.append_bonds(b1,b2) >>> connect.lookup_bond(a1,a2) Bond(a1=0, a2=35, label=None, btype=Single, stereo=Unknown, f_order=1.0) >>> connect.lookup_bond(a1,a3) Bond(a1=0, a2=39, label=None, btype=Single, stereo=Unknown, f_order=1.0)
- extend_bonds(bonds: Iterable[Bond]) None¶
Extends the list of bonds to the Connectivity instance
Examples
- The Molecule class inherits extend_bonds()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> a1, a2, a3 = dendrobine.get_atoms(0,35, 39) >>> b1 = ml.Bond(a1,a2) >>> b2 = ml.Bond(a1,a3) >>> dendrobine.extend_bonds([b1,b2]) >>> dendrobine.lookup_bond(a1,a2) Bond(a1=0, a2=35, label=None, btype=Single, stereo=Unknown, f_order=1.0) >>> dendrobine.lookup_bond(a1,a3) Bond(a1=0, a2=39, label=None, btype=Single, stereo=Unknown, f_order=1.0)
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> a1, a2, a3 = connect.get_atoms(0,35, 39) >>> b1 = ml.Bond(a1,a2) >>> b2 = ml.Bond(a1,a3) >>> connect.extend_bonds([b1,b2]) >>> connect.lookup_bond(a1,a2) Bond(a1=0, a2=35, label=None, btype=Single, stereo=Unknown, f_order=1.0) >>> connect.lookup_bond(a1,a3) Bond(a1=0, a2=39, label=None, btype=Single, stereo=Unknown, f_order=1.0)
- connect_like(other: Connectivity)¶
Connect the atoms in current instance like they are connected in other
This function assumes that the equivalent atom indices are the same in both sequences.
- Parameters:
other (Connectivity) – Instance to copy the connectivity from
- del_bond(b: Bond) None¶
Deletes a bond from the Connectivity instance
- Parameters:
b (Bond) – Bond to delete
Examples
- The Molecule class inherits del_bond()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> dendrobine.get_bond(0) Bond(a1=42, a2=22, label=None, btype=Single, stereo=Unknown, f_order=1.0) >>> dendrobine.del_bond(dendrobine.get_bond(0)) >>> dendrobine.get_bond(0) Bond(a1=41, a2=22, label=None, btype=Single, stereo=Unknown, f_order=1.0)
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> connect.get_bond(0) Bond(a1=42, a2=22, label=None, btype=Single, stereo=Unknown, f_order=1.0) >>> connect.del_bond(connect.get_bond(0)) >>> connect.get_bond(0) Bond(a1=41, a2=22, label=None, btype=Single, stereo=Unknown, f_order=1.0)
- del_atom(_a: Atom | int | str | Element)¶
Deletes an atom and its respective bonds from the Connectivity instance
- Parameters:
_a (AtomLike) – An atom, index, label, or Element. This will only delete the first instance of the label or Element found
Examples
- The Molecule class inherits del_atom()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> print(dendrobine.n_atoms, dendrobine.n_bonds) 44, 47 >>> dendrobine.del_atom(0) >>> print(dendrobine.n_atoms, dendrobine.n_bonds) 43, 44
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> print(connect.n_atoms, connect.n_bonds) 44, 47 >>> connect.del_bond(connect.get_bond(0)) >>> print(connect.n_atoms, connect.n_bonds) 44, 47
- bonds_with_atom(a: Atom | int | str | Element) Generator[Bond, None, None]¶
Yields bonds attached to an atom in a Connectivity instance
- Parameters:
a (AtomLike) – An atom, index, label, or Element. This will only delete the first instance of the label or Element found
- Yields:
Generator[Bond, None, None] – Yields generator of Bond instances
Examples
- The Molecule class inherits bonds_with_atom()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> dendrobine.bonds_with_atom(0) <generator object Connectivity.bonds_with_atom at ...>
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> connect.bonds_with_atom(0) <generator object Connectivity.bonds_with_atom at ...>
- connected_atoms(a: Atom | int | str | Element) Generator[Atom, None, None]¶
Yields atoms attached to an atom in a Connectivity instance
- Parameters:
a (AtomLike) – An atom, index, label, or Element. This will only delete the first instance of the label or Element found
- Yields:
Generator[Atom, None, None] – Yields generator of Atom instances
Examples
- The Molecule class inherits connected_atoms()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> dendrobine.connected_atoms(0) <generator object Connectivity.connected_atoms at ...>
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> connect.connected_atoms(0) <generator object Connectivity.connected_atoms at ...>
- bonded_valence(a: Atom | int | str | Element) float¶
Sum of valences of the atoms bonded in a Connectivity instance
- Parameters:
a (AtomLike) – An atom, index, label, or Element. This will only delete the first instance of the label or Element found
- Returns:
Returns sum of valences of atoms connected
- Return type:
float
Examples
- The Molecule class inherits bonded_valence()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> dendrobine.bonded_valence(0) 3.0
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> connect.bonded_valence(0) 3.0
- n_bonds_with_atom(a: Atom | int | str | Element) int¶
Total number of bonds to an atom in a Connectivity instance
- Parameters:
a (AtomLike) – An atom, index, label, or Element. This will only delete the first instance of the label or Element found
- Returns:
Returns the total number of bonds to an atom
- Return type:
int
Examples
- The Molecule class inherits n_bonds_with_atom()
>>> dendrobine = ml.Molecule.load_mol2(ml.files.dendrobine_mol2) >>> dendrobine.n_bonds_with_atom(0) 3
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dendrobine) >>> connect.n_bonds_with_atom(0) 3
- yield_bfsd(_start: Atom | int | str | Element, _direction: Atom | int | str | Element = None) Generator[Tuple[Atom, int], None, None]¶
Yields atoms in breadth-first search, in traversal order, Distance from the start atom is also yielded
- Parameters:
- Yields:
Generator[Tuple[Atom, int], None, None] – the atoms in breadth-first search, in traversal order, Distance from the start atom is also yielded
Examples
- The Molecule class inherits yield_bfsd()
>>> dmf = ml.Molecule.load_mol2(ml.files.dmf_mol2) >>> dmf.yield_bfsd(0) <generator object Connectivity.yield_bfsd at ...>
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dmf) >>> connect.yield_bfsd(0) <generator object Connectivity.yield_bfsd at ...>
- yield_bfs(_start: Atom | int | str | Element, _direction: Atom | int | str | Element = None) Generator[Atom, None, None]¶
Yields atoms in breadth-first search, in traversal order, Distance is not yielded
- Parameters:
- Yields:
Generator[Atom, None, None] – The Atoms in a breadth-first search, in traversal order
Examples
- The Molecule class inherits yield_bfsd()
>>> dmf = ml.Molecule.load_mol2(ml.files.dmf_mol2) >>> dmf.yield_bfsd(0) <generator object Connectivity.yield_bfs at ...>
- If desired, one can work directly with Connectivity class instead
>>> connect = ml.Connectivity(dmf) >>> connect.yield_bfsd(0) <generator object Connectivity.yield_bfs at ...>
- to_nxgraph() Graph¶
Converts an insantce of Connectivity class into networkx object
Returns:¶
- nx_mol: nx.Graph()
instance of Networkx Graph object
Notes:¶
In latest version, all the atom and bond attributes are added to Networkx Graph.
- find_cycle_containing_atom(start: Atom | int | str | Element) list¶
Finds the first cycle containing “start” atom Parameters: ———– start: ml.chem.AtomLike
atom or its atomic index or a unique identifier for starting searching for cycles (loops)
Returns:¶
- cycle: list
the first found cycle that countains “start” atom
Current implementation using networkx grpah. Should be rewritten w/o any extra dependencies.
- match(pattern: Connectivity, /, *, node_match: Callable[[dict, dict], bool] | None = None, edge_match: Callable[[dict, dict], bool] | None = None) Generator[dict | Any, None, None]¶
Checks two molli connectivities for isomorphism. Yields generator over subgraph isomorphism mappings.
```python for mapping in connectivity.match(pattern):
…
``` Parameters: ———– pattern: Connectivity
query-Connectivity (Molecule) to match with given Connectivity
- get_substr_indices(pattern: Connectivity) Generator[list[int], None, None]¶
Yields all possible combinations of substructure indices that matched with the given pattern.
Parameters:¶
pattern: Connectivity
Returns:¶
Generator over list of all possible mappings to pattern
If only one variation of substructure indices is needed, use next(ens.get_substr_indices(pattern))
``python for ens in tqdm(library):
- for mapping in ens.get_substr_indices(pattern):
…