rdtools.compare#

A module contains functions to compare molecules and complexes.

rdtools.compare.get_match_and_recover_recipe(mol1: Mol, mol2: Mol) tuple[tuple[int, ...], dict[int, int]]#

Get the isomorphism match and the recipe to recover mol2 to mol1.

If swapping the atom indices in mol2 according to the recipe, mol2 should be the same as mol1.

Parameters:
  • mol1 (Chem.Mol) – The first molecule.

  • mol2 (Chem.Mol) – The second molecule.

Returns:

tuple[tuple[int, …], dict[int, int]] – The substructure match and a truncated atom mapping of mol2 to mol1.

rdtools.compare.get_resonance_structure_match(mol1_res: list[Mol], mol2_res: list[Mol]) tuple[int, ...]#

Get the match between two lists of resonance structures.

Parameters:
  • mol1_res (list[Chem.Mol]) – The first list of resonance structures.

  • mol2_res (list[Chem.Mol]) – The second list of resonance structures.

Returns:

tuple[int, …] – The match between the two lists of resonance structures. Empty tuple if no match is found.

rdtools.compare.get_unique_mols(mols: list[Mol], consider_atommap: bool = False, same_formula: bool = False) list[Mol]#

Find the unique molecules from a list of molecules.

Parameters:
  • mols (list[Chem.Mol]) – The molecules to be processed.

  • consider_atommap (bool, optional) – If treat chemically equivalent molecules with different atommap numbers as different molecules. Defaults to False.

  • same_formula (bool, optional) – If the mols has the same formula you may set it to True to save computational time. Defaults to False.

Returns:

list[Chem.Mol] – A list of unique molecules.

rdtools.compare.has_matched_mol(mol: Mol, mols: list[Mol], consider_atommap: bool = False) bool#

Check if a molecule has a isomorphic match in a list of molecules.

Parameters:
  • mol (Chem.Mol) – The target molecule.

  • mols (list[Chem.Mol]) – The list of molecules to be processed.

  • consider_atommap (bool, optional) – If treat chemically equivalent molecules with different atommap numbers as different molecules. Defaults to False.

Returns:

bool – if a matched molecules if found.

rdtools.compare.is_same_complex(complex1: Mol | Collection[Mol], complex2: Mol | Collection[Mol], resonance: bool = False) bool#

Check if two complexes are the same.

This check is regardless of the atom mapping and the order of the atoms in the molecule.

Parameters:
  • complex1 (Union[Chem.Mol, Collection[Chem.Mol]]) – The first complex.

  • complex2 (Union[Chem.Mol, Collection[Chem.Mol]]) – The second complex.

  • resonance (bool, optional) – Whether to consider resonance structures. Defaults to False.

Returns:

bool – Whether the two complexes are the same.

rdtools.compare.is_same_connectivity_conf(mol: Mol, conf_id: int = 0, backend: Literal['openbabel', 'xyz2mol'] = 'openbabel', **kwargs: Any) bool#

Check the connectivity of the conformer consistent with the molecule.

The conformer connectivity is defined by its spacial coordinates. This is an useful sanity check when coordinates are changed.

Parameters:
  • mol (Chem.Mol) – The molecule to be checked.

  • conf_id (int, optional) – The conformer ID. Defaults to 0.

  • backend (Literal["openbabel", "xyz2mol"], optional) – The backend to use for the comparison. Defaults to 'openbabel'.

  • **kwargs (Any) – The keyword arguments to pass to the backend.

Returns:

bool – Whether the conformer has the same connectivity as the molecule.

rdtools.compare.is_same_connectivity_mol(mol1: Mol, mol2: Mol) bool#

Check whether the two molecules has the same connectivity.

This is not an isomorphic check, and different atom ordering will be treated as “different connectivity”.

Parameters:
  • mol1 (Chem.Mol) – The first molecule.

  • mol2 (Chem.Mol) – The second molecule.

Returns:

bool – Whether the two molecules has the same connectivity.