# pymatgen.analysis.molecule_matcher module¶

class AbstractMolAtomMapper[source]

Bases: monty.json.MSONable

Abstract molecular atom order mapping class. A mapping will be able to find the uniform atom order of two molecules that can pair the geometrically equivalent atoms.

classmethod from_dict(d)[source]
get_molecule_hash(mol)[source]

Defines a hash for molecules. This allows molecules to be grouped efficiently for comparison.

Parameters: mol – The molecule. OpenBabel OBMol or pymatgen Molecule object A hashable object. Examples can be string formulas, etc.
uniform_labels(mol1, mol2)[source]

Pair the geometrically equivalent atoms of the molecules.

Parameters: mol1 – First molecule. OpenBabel OBMol or pymatgen Molecule object. mol2 – Second molecule. OpenBabel OBMol or pymatgen Molecule object. (list1, list2) if uniform atom order is found. list1 and list2 are for mol1 and mol2, respectively. Their length equal to the number of atoms. They represents the uniform atom order of the two molecules. The value of each element is the original atom index in mol1 or mol2 of the current atom in uniform atom order. (None, None) if unform atom is not available.
class InchiMolAtomMapper(angle_tolerance=10.0)[source]

Pair atoms by inchi labels.

Parameters: angle_tolerance – Angle threshold to assume linear molecule. In degrees.
as_dict()[source]
classmethod from_dict(d)[source]
get_molecule_hash(mol)[source]

Return inchi as molecular hash

uniform_labels(mol1, mol2)[source]
class IsomorphismMolAtomMapper[source]

Pair atoms by isomorphism permutations in the OpenBabel::OBAlign class

as_dict()[source]
classmethod from_dict(d)[source]
get_molecule_hash(mol)[source]

Return inchi as molecular hash

uniform_labels(mol1, mol2)[source]

Pair the geometrically equivalent atoms of the molecules. Calculate RMSD on all possible isomorphism mappings and return mapping with the least RMSD

Parameters: mol1 – First molecule. OpenBabel OBMol or pymatgen Molecule object. mol2 – Second molecule. OpenBabel OBMol or pymatgen Molecule object. (list1, list2) if uniform atom order is found. list1 and list2 are for mol1 and mol2, respectively. Their length equal to the number of atoms. They represents the uniform atom order of the two molecules. The value of each element is the original atom index in mol1 or mol2 of the current atom in uniform atom order. (None, None) if unform atom is not available.
class MoleculeMatcher(tolerance=0.01, mapper=<pymatgen.analysis.molecule_matcher.InchiMolAtomMapper object>)[source]

Bases: monty.json.MSONable

Class to match molecules and identify whether molecules are the same.

Parameters: tolerance – RMSD difference threshold whether two molecules are different mapper – MolAtomMapper object that is able to map the atoms of two molecule to uniform order
as_dict()[source]
fit(mol1, mol2)[source]

Fit two molecules.

Parameters: mol1 – First molecule. OpenBabel OBMol or pymatgen Molecule object mol2 – Second molecule. OpenBabel OBMol or pymatgen Molecule object A boolean value indicates whether two molecules are the same.
classmethod from_dict(d)[source]
get_rmsd(mol1, mol2)[source]

Get RMSD between two molecule with arbitrary atom order.

Returns: RMSD if topology of the two molecules are the same Infinite if the topology is different
group_molecules(mol_list)[source]

Group molecules by structural equality.

Parameters: mol_list – List of OpenBabel OBMol or pymatgen objects A list of lists of matched molecules Assumption: if s1=s2 and s2=s3, then s1=s3 This may not be true for small tolerances.