Molecular Geometry

get_center(mol)[source]

Get the geometric center of an RDKit molecule

Parameters:

mol – RDKit molecule

Return type:

ndarray

Returns:

center as a numpy array

get_shape_moments(mol)[source]

Calculate principal moments of inertia as defined in https://pubs.acs.org/doi/10.1021/ci025599w

Parameters:

mol – RDKit molecule

Return type:

tuple

Returns:

first 2 moments as a tuple

gen_3d(mol)[source]

Generate a 3D structure for a RDKit molecule

Parameters:

mol (Mol) – input molecule

Return type:

Optional[Mol]

Returns:

molecule with 3D coordinates

gen_conformers(mol, num_confs=50)[source]

Generate conformers for a molecule.

A molecule that is too rigid to support num_confs distinct conformers yields however many could be embedded, with a warning; that is a property of the molecule rather than an error. Genuine failures raise, so that they can be told apart from a small conformer count.

Parameters:
  • mol (Mol) – RDKit molecule

  • num_confs (int) – Number of conformers to generate

Raises:

ValueError – if no conformers could be embedded, or if MMFF parameters are not available for the molecule so conformer energies cannot be assigned

Return type:

Mol

Returns:

Molecule with conformers, each carrying an “Energy” property

refine_conformers(mol, energy_threshold=50, rms_threshold=0.5, use_symmetry=False)[source]

Refine the conformers of a molecule by removing those with high energy or low RMSD.

Conformers more than energy_threshold above the lowest-energy conformer are removed first. The remainder are then reduced so that no two conformers are within rms_threshold of each other, keeping the lowest-energy conformer of each redundant group.

Conformers are addressed by their RDKit conformer id throughout. Ids are not required to be contiguous or to start at zero, so a molecule whose conformers have already been trimmed (including by an earlier call to this function) is handled correctly.

Note that the conformers are removed from mol in place; the same molecule is returned for convenience. The surviving conformers keep the coordinates they came in with: RMSD comparison aligns the conformers it measures, so it is done against a throwaway copy rather than against mol itself.

Parameters:
  • mol (Mol) – RDKit molecule with conformers.

  • energy_threshold (float) – Energy threshold above which conformers are removed.

  • rms_threshold (Optional[float]) – RMSD threshold below which conformers are considered redundant and removed. If None, RMSD filtering is skipped.

  • use_symmetry (bool) – If True, compare conformers with a symmetry-aware RMSD (rdMolAlign.GetBestRMS) so that conformers differing only by a symmetric relabelling – a flipped phenyl, a rotated methyl – are recognised as redundant. The default symmetry-blind comparison reports such a pair as distinct and keeps both. Symmetry-aware comparison has to enumerate the substructure matches, so it is slower, and markedly so for molecules with many symmetric groups.

Return type:

Mol

Returns:

RDKit molecule with refined conformers.

get_conformer_energies(mol)[source]

Retrieve the energies of all conformers in a molecule.

Parameters:

mol (Mol) – RDKit molecule containing conformers.

Return type:

List[float]

Returns:

A list of energies for each conformer as floats.

mcs_rmsd(mol_1, mol_2, id_1=0, id_2=0, align=False, timeout=None, max_matches=10000)[source]

Calculate the RMSD (Root Mean Square Deviation) between the MCS (Maximum Common Substructure) of two molecules.

The RMSD is symmetry corrected: every way the MCS can be mapped onto each molecule is enumerated and the smallest RMSD is returned, so two poses that differ only by a symmetric relabeling, such as a flipped phenyl, a rotated methyl, or the two oxygens of a carboxylate, are recognized as the same arrangement rather than reported as far apart.

By default the two conformers are compared in the frame they arrive in, which is what comparing docked or co-folded poses against a crystal structure requires: the receptor defines a common frame and a pose that sits in the wrong place should score as wrong. Pass align=True to superpose the MCS atoms first, which is what comparing free conformers requires, where absolute position carries no meaning.

When both molecules have the same graph, align=True reproduces rdMolAlign.GetBestRMS(prb, ref, symmetrizeConjugatedTerminalGroups=False). RDKit’s conjugated-terminal-group symmetrization is not applied, and is not reachable from Python outside GetBestRMS, so the two oxygens of a carboxylic acid stay distinct here unless the MCS itself makes them equivalent. Prefer GetBestRMS when the two molecules are the same and that symmetrization is wanted; this function exists for the case GetBestRMS cannot handle, where the molecules differ and only a common substructure can be compared.

Parameters:
  • mol_1 (Mol) – First RDKit molecule

  • mol_2 (Mol) – Second RDKit molecule

  • id_1 (int) – Conformer ID for the first molecule

  • id_2 (int) – Conformer ID for the second molecule

  • align (bool) – If True, rigidly superpose the MCS atoms before measuring, discarding any difference in absolute position and orientation. If False (the default) the coordinates are compared as given.

  • timeout (Optional[int]) – Seconds to allow for the MCS search. None, the default, lets it run to completion. On timeout RDKit returns the largest substructure it found so far, so a timeout yields a smaller MCS rather than an error.

  • max_matches (int) – Cap on the number of MCS mappings enumerated per molecule. Highly symmetric structures admit a great many, and the RMSD is minimized over every pair, so the work grows as the product of the two counts. The cap bounds that; raising it makes the search exhaustive on such structures.

Return type:

Tuple[int, float]

Returns:

A tuple containing the number of MCS atoms and the RMSD value. If the molecules share no common substructure, the RMSD is float(“inf”).

mol_to_3D_view(mol_list, size=(300, 300), style='stick', surface=False, opacity=0.5)[source]

Draw a list of molecules in 3D

Mol_list:

list[rdMol], a list of rdMols to show

Size:

tuple(int, int), canvas size

Style:

str, type of drawing molecule, style can be ‘line’, ‘stick’, ‘sphere’, ‘cartoon’

Surface:

bool, display SAS

Opacity:

float, opacity of surface, range 0.0-1.0

Return type:

view

Returns:

viewer: py3Dmol.view, a class for constructing embedded 3Dmol.js views in ipython notebooks.