luna.wrappers.base module¶
- class AtomWrapper(atm_obj, mol_obj=None)[source]¶
Bases:
object
This class provides util functions to access atomic properties and other information from RDKit and Open Babel objects.
- Parameters
atm_obj (
AtomWrapper
,rdkit.Chem.rdchem.Atom
, oropenbabel.OBAtom
) – An atom to wrap.mol_obj (
MolWrapper
,rdkit.Chem.rdchem.Mol
,openbabel.pybel.Molecule
, or None) – The molecule that contains the atomatom
. If None, the molecule is recovered directly from the atom object.
- Raises
AtomObjectTypeError – If the atom object is not an instance of
MolWrapper
,rdkit.Chem.rdchem.Mol
, oropenbabel.pybel.Molecule
.
- property atm_obj¶
The wrapped atom object.
- Type
rdkit.Chem.rdchem.Atom
oropenbabel.OBAtom
- get_atomic_invariants()[source]¶
Get the atomic invariants of this atom.
Atomic invariants are derived from ECFP 1 and E3FP 2 and consists of seven fields:
Number of heavy atoms;
Valence - Number of hydrogens;
Atomic number;
Isotope number;
Formal charge;
Number of hydrogens;
If the atom belongs to a ring or not.
- Return type
- get_atomic_mass()[source]¶
Get this atom’s atomic mass given by standard IUPAC average molar mass.
- Return type
- get_bonds(wrapped=True)[source]¶
Get this atom’s bonds.
- Parameters
wrapped (bool) – If True, wrap each bond with
BondWrapper
.- Return type
iterable of
BondWrapper
,rdkit.Chem.rdchem.Bond
, oropenbabel.OBBond
- get_h_count()[source]¶
Get the total number of hydrogens (implicit and explicit) bound to this atom.
- Return type
- get_id()[source]¶
Get this atom’s unique id.
When using RDKit,
get_id()
andget_idx()
returns the same value.- Return type
- get_mass()[source]¶
Get this atom’s exact atomic mass, which can vary given the isotope.
- Return type
- get_neighbors(wrapped=True)[source]¶
Get all atoms that are bound to this atom.
- Parameters
wrapped (bool) – If True, wrap each atom with
AtomWrapper
.- Return type
iterable of
AtomWrapper
,rdkit.Chem.rdchem.Atom
, oropenbabel.OBAtom
- get_neighbors_number(only_heavy_atoms=False)[source]¶
Get the number of atoms bound to this atom.
- Parameters
only_heavy_atoms (bool) – If True, count only heavy atoms.
- Return type
- get_parent(wrapped=True)[source]¶
Get the molecule that contains this atom.
- Parameters
wrapped (bool) – If True, wrap the molecule with
MolWrapper
.- Return type
MolWrapper
,rdkit.Chem.rdchem.Mol
, oropenbabel.pybel.Molecule
- matches_smarts(smarts)[source]¶
Check if this atom matches the substructure through a SMARTS substructure search.
Note: currently, this function only works with molecules read with Open Babel.
- Parameters
smarts (str) – A substructure defined as SMARTS.
- Returns
Whether matches occurred. Return None if the molecule was read with RDKit.
- Return type
bool or None
Examples
First, let’s read a molecule (glutamine) using Open Babel.
>>> from luna.wrappers.base import MolWrapper >>> mol_obj = MolWrapper.from_smiles("N[C@@H](CCC(N)=O)C(O)=O", mol_obj_type="openbabel")
Now, we’ll loop over the list of atoms in the glutamine and check which atom is the amide’s carbon. To do so, we can call the function
MolWrapper.get_atoms()
, which, by default, returnsAtomWrapper
objects and then callmatches_smarts()
.>>> for atm in mol_obj.get_atoms(): >>> print("%d %s %s" % (atm.get_idx(), atm.get_symbol(), atm.matches_smarts("C(N)(C)=O"))) 1 N False 2 C False 3 C False 4 C False 5 C True 6 N False 7 O False 8 C False 9 O False 10 O False
- property parent¶
The molecule that contains this atom.
- Type
MolWrapper
,rdkit.Chem.rdchem.Mol
, oropenbabel.pybel.Molecule
- set_as_aromatic(is_aromatic)[source]¶
Set whether this atom is aromatic or not.
- Parameters
is_aromatic (bool)
- set_in_ring(in_ring)[source]¶
Set whether this atom belongs to a ring or not.
- Parameters
in_ring (bool)
- unwrap()[source]¶
Return the original atomic object.
- Return type
rdkit.Chem.rdchem.Atom
oropenbabel.OBAtom
- class BondType(value)[source]¶
Bases:
enum.Enum
An enumeration of bond types available at RDKit.
- AROMATIC = 12¶
- DATIVE = 17¶
- DATIVEL = 18¶
- DATIVEONE = 16¶
- DATIVER = 19¶
- DOUBLE = 2¶
- FIVEANDAHALF = 11¶
- FOURANDAHALF = 10¶
- HEXTUPLE = 6¶
- HYDROGEN = 14¶
- IONIC = 13¶
- ONEANDAHALF = 7¶
- OTHER = 20¶
- QUADRUPLE = 4¶
- QUINTUPLE = 5¶
- SINGLE = 1¶
- THREEANDAHALF = 9¶
- THREECENTER = 15¶
- TRIPLE = 3¶
- TWOANDAHALF = 8¶
- UNSPECIFIED = 0¶
- ZERO = 21¶
- class BondWrapper(bond_obj)[source]¶
Bases:
object
This class provides util functions to access bond properties and other information from RDKit and Open Babel objects.
- Parameters
bond_obj (
BondWrapper
,rdkit.Chem.rdchem.Bond
, oropenbabel.OBBond
) – A bond to wrap.- Raises
BondObjectTypeError – If the bond object is not an instance of
BondWrapper
,rdkit.Chem.rdchem.Bond
, oropenbabel.pybel.OBBond
.
- property bond_obj¶
The wrapped bond object.
- Type
rdkit.Chem.rdchem.Bond
oropenbabel.OBBond
- get_begin_atom(wrapped=True)[source]¶
Return the bond’s first atom.
- Parameters
wrapped (bool) – If True, wrap the atom with
AtomWrapper
.- Return type
AtomWrapper
,rdkit.Chem.rdchem.Atom
, oropenbabel.OBAtom
- get_end_atom(wrapped=True)[source]¶
Return the bond’s second atom.
- Parameters
wrapped (bool) – If True, wrap the atom with
AtomWrapper
.- Return type
AtomWrapper
,rdkit.Chem.rdchem.Atom
, oropenbabel.OBAtom
- get_partner_atom(atm, wrapped=True)[source]¶
Get the partner atom that forms this bond with
atm
.- Parameters
atm (
AtomWrapper
,rdkit.Chem.rdchem.Atom
, oropenbabel.OBAtom
) – Get the partner of this atom.wrapped (bool) – If True, wrap the partner atom with
AtomWrapper
.
- Return type
AtomWrapper
,rdkit.Chem.rdchem.Atom
, oropenbabel.OBAtom
- set_as_aromatic(is_aromatic)[source]¶
Set if this bond is aromatic or not.
- Parameters
is_aromatic (bool)
- set_bond_type(bond_type)[source]¶
Set the type of the bond as a
bond_type
.- Parameters
bond_type (
BondType
)
- unwrap()[source]¶
Return the original bond object.
- Return type
rdkit.Chem.rdchem.Bond
oropenbabel.OBBond
- class MolWrapper(mol_obj)[source]¶
Bases:
object
This class provides util functions to access molecule properties and other information from RDKit and Open Babel objects.
- Parameters
mol_obj (
MolWrapper
,rdkit.Chem.rdchem.Mol
, oropenbabel.pybel.Molecule
) – A molecule to wrap.- Raises
MoleculeObjectTypeError – If the molecular object is not an instance of
MolWrapper
,rdkit.Chem.rdchem.Mol
, oropenbabel.pybel.Molecule
.
- classmethod from_mol_block(block, mol_format, mol_obj_type='rdkit')[source]¶
Initialize a molecule from a string block.
- Parameters
block (str) – The molecular string block.
mol_format (str) – Define the format in which the molecule is represented (e.g., ‘mol2’ or ‘mol’).
mol_obj_type ({‘rdkit’, ‘openbabel’}) – Define which library (RDKit or Open Babel) to use to parse the molecular block. The default value is RDKit.
- Return type
- classmethod from_smiles(smiles, mol_obj_type='rdkit', name=None)[source]¶
Initialize a molecule from a SMILES string.
- Parameters
smiles (str) – The SMILES string. Define the format in which the molecule is represented (e.g., ‘mol2’ or ‘mol’).
mol_obj_type ({‘rdkit’, ‘openbabel’}) – Define which library (RDKit or Open Babel) to use to parse the molecular block. The default value is RDKit.
name (str, optional) – A name to identify the molecule.
- Return type
- Raises
MoleculeObjectError – If it could not create a molecule from the provided SMILES.
Examples
>>> from luna.wrappers.base import MolWrapper >>> mol_obj = MolWrapper.from_smiles("N[C@@H](CCC(N)=O)C(O)=O", mol_obj_type="openbabel", name="Glutamine")
- get_atom_coord_by_id(atm_id)[source]¶
Get the coordinates of an atom given by its id.
- Returns
Atomic coordinates (x, y, z).
- Return type
array_like of float (size 3)
- get_atoms(wrapped=True)[source]¶
Get all molecule’s atoms.
- Parameters
wrapped (bool) – If True, wrap all atoms with
AtomWrapper
.- Return type
iterable of
AtomWrapper
,rdkit.Chem.rdchem.Atom
, oropenbabel.OBAtom
- get_bonds(wrapped=True)[source]¶
Get all molecule’s bonds.
- Parameters
wrapped (bool) – If True, wrap all bonds with
BondWrapper
.- Return type
iterable of
BondWrapper
,rdkit.Chem.rdchem.Bond
, oropenbabel.OBBond
- property mol_obj¶
The wrapped molecular object.
- Type
rdkit.Chem.rdchem.Mol
oropenbabel.pybel.Molecule
- unwrap()[source]¶
Return the original molecular object.
- Return type
rdkit.Chem.rdchem.Mol
oropenbabel.pybel.Molecule
.
- class OBBondType(value)[source]¶
Bases:
enum.Enum
An enumeration of bond types available at Open Babel.
- AROMATIC = 5¶
- DOUBLE = 2¶
- SINGLE = 1¶
- TRIPLE = 3¶
References