Chemical Objects Classes¶
LinChemIn provides two classes to store chemical objects:
Molecule and ChemicalEquation.
Molecule¶
Instances of the Molecule class hold information regarding chemical compounds
and can be initialized by using the MoleculeConstructor
constructor and its methods.
The MoleculeConstructor class can be instantiated by passing
a molecular_identity_property_name string, indicating which property determines the identity
of the object (e.g. ‘smiles’) and an hash_list, indicating which properties should be used to compute
additional hash keys.
Molecule objects are characterized by various attributes.
The molecular_identity_property_name attribute indicates which structured-derived molecular
identifier should be used to
compute the hash key (uid attribute) of the Molecule instance. The rdmol attribute represents
the RDKIT Mol object corresponding to the the Molecule instance and can be used for the dynamic calculation
of molecular properties and fingerprints. The smiles attribute contains the canonical smiles string
associated with the Molecule instance.
from linchemin.cheminfo.construcotrs import MoleculeConstructor
# The MoleculeConstructor is initiated
molecule_constructor = MoleculeConstructor(molecular_identity_property_name='smiles',
hash_list=['inchi_key', 'inchikey_KET_15T'])
# The Molecule instance is created from its smiles
mol_canonical = molecule_constructor.build_from_molecule_string(
molecule_string='CCNC(=O)CC', inp_fmt='smiles')
ChemicalEquation¶
Instances of the ChemicalEquation class hold information regarding chemical reactions
and can be initialized by using the ChemicalEquationConstructor
constructor and its methods.
The ChemicalEquationConstructor class can be instantiated by
passing a molecular_identity_property_name string, indicating which property determines the identity
of the molecules involved in the reaction (e.g. ‘smiles’) and a chemical_equation_identity_name string,
indicating which representation of the reaction should be used for determining the identity (e.g., ‘r_p’
only considers reactants and products, while ‘r_r_p’ also takes into account the reagents.
The methods :method:`~linchemin.cheminfo.constructors.ChemicalEquationConstructor.build_from_reaction_string`
and :method:`~linchemin.cheminfo.constructors.ChemicalEquationConstructor.build_from_rdrxn` can then be used to
create the new ChemicalEquation by passing, respectively, a reaction string and the type of string
(e.g., ‘smiles’ or ‘smarts’), or an rdkit ChemicalReaction object.
ChemicalEquation objects are characterized by various attributes.
The catalog attribute stores the instances of the Molecule objects involved in the reaction
The involved Molecules instances also appear in the role_map attributes that maps each of them
on the role they has in the reaction, so that a Molecule can be a ‘reagent’, a ‘reactant’ or a ‘product’.
The map of the role also determines the has key of the ChemicalEquation instance,
as it is based on the hash keys of the Molecule objects having the role of ‘reactants’ and ‘products’.
The hash key is stored in the uid attribute of the instance.
The stoichiometry_coefficients dictionary maps the stoichiometry coefficients of each Molecule object
involved in the reaction.
The rdrxn attribute, storing the rdkit ChemicalReaction object associated with the ChemicalEquation instance,
can be used to compute reaction properties and fingerprints. The smiles attribute
contains the smiles string associated with the ChemicalEquation instance.
If the object used to instantiate the new ChemicalEquation instance contains
the atom mapping information, three additional attributes will also be created:
mapping,disconnectionandtemplate.
from linchemin.cheminfo.constructors import ChemicalEquationConstructor
# The ChemicalEquationConstructor is initiated
chemical_equation_constructor = ChemicalEquationConstructor(molecular_identity_property_name='smiles',
chemical_equation_identity_name='r_p')
# The ChemicalEquation is created from its smiles
chemical_equation = chemical_equation_constructor.build_from_reaction_string(
reaction_string='CCN.CCOC(=O)CC>>CCNC(=O)CC',
inp_fmt='smiles')