rdmc.conf

This module provides class and methods for dealing with RDKit Conformer.

class rdmc.conf.ConformerCluster(children: array, energies: array = None)

Bases: object

merge(clusters: list)

Merge the cluster with a list of clusters.

Parameters:

clusters (list) – A list of the ConformerCluster object to be merged in.

split_by_energies(decimals: int = 1, as_dict: bool = True)

Split the conformer by energies.

Parameters:
  • decimals (int, optional) – clustering children based on the number of digit after the dot of the energy values. For kcal/mol and J/mol, 0 or 1 is recommended; for hartree, 3 or 4 is recommended. Defaults to 1.

  • as_dict (bool, optional) – If True, return a dict object whose keys are energy values and values are divided ConformerCluster object. Otherwise, return a list of ConformerClusters. Defaults to True.

class rdmc.conf.ConformerFilter(mol: RDKitMol)

Bases: object

property atom_maps

Store all possible atommappings of the given molecules. There are usually combinatory explosion.

check_dihed_angle_diff(confs, threshold: float = 5.0, mask: Optional[ndarray] = None, adjust_periodicity: bool = False, as_dict: bool = True, as_list_idx: bool = False)

The implementation of checking individual dihedral angle difference. This approach is also implemented in the MSTor workflow.

Parameters:
  • confs (list) – A list of conformer IDs.

  • threshold (float, optional) – The difference (in degree) used for filtering. Defaults to 5.

  • mask (np.ndarray, optional) – An array that has the same length as torsions and values of True or False to indicate which torsions are not considered. This can be helpful, e.g., to exclude methyl torsional symmetry.

  • adjust_periodicity (bool, optional) – Since dihedral angles have a period of 360 degrees. Defaults to True. It is suggested to run twice with this value be True and False to get a better performance.

  • as_dict (bool) – Return the result as a dict object with keys for the index of clusters and values of conformer indexes (provided in confs). Otherwise, return as a list of grouped conformer indexes. Defaults to True.

  • as_list_idx (bool) – Return the indexes in the confs list other than the value in the confs.

Returns:

dict or list

filter_by_dihed_angles(clusters, threshold: float = 5.0, mask: ndarray = None, as_clusters: bool = True) list

A method to filter comformers by calculating the differences of dihedral angles between conformers. The check will be implemented twice, with and without considering periodicity.

Parameters:
  • clusters (ConformerCluster or list) – A single ConformerCluster object or a list of conformerClusters.

  • threshold (float, optional) – The threshold (in degree) used for hierarchy clustering. Defaults to 5.

  • mask (np.array, optional) – An array that has the same length as torsions and values of True or False to indicate which torsions are not considered. This can be helpful, e.g., to exclude methyl torsional symmetry.

  • as_clusters (bool, optional) – Return the results as a list of ConformerClusters (True) or a list of grouped conformer indexes (True). Defaults to True.

Returns:

list

filter_by_iter_hcluster(clusters: Union[list, ConformerCluster], threshold: float = 5.0, criterion: str = 'distance', method: str = 'average', max_iter: int = 10, as_clusters: bool = True)

A method to filter comformers by iteratively applying hierarchy clustering. In a new iteration, only the distinguishable representative conformers will be used that are generated in the previous iteration.

Parameters:
  • clusters (ConformerCluster or list) – A single ConformerCluster object or a list of conformerClusters.

  • threshold (float, optional) – The threshold (in degree) used for hierarchy clustering. Defaults to 5.

  • criterion (str, optional) – Specifies the criterion for forming flat clusters. Valid values are ‘inconsistent’, ‘distance’ (default), or ‘maxclust’ cluster formation algorithms

  • method (str, optional) – The linkage method to use. Valid values are single, complete, average (default), weighted, median centroid, and ward. Except median centroid (O(n^3)), others have a computational cost scaled by O(n^2).

  • adjust_periodicity (bool, optional) – Since dihedral angles have a period of 360 degrees. Defaults to True. It is suggested to run twice with this value be True and False to get a better performance.

  • max_iter (int, optional) – The max number of iterations. Defaults to 10. There is a early-stopping techinque if number of clusters doesn’t change with increasing number of iterations.

  • as_clusters (bool, optional) – Return the results as a list of ConformerClusters (True) or a list of grouped conformer indexes (True). Defaults to True.

Returns:

list

generate_rmsds_of_cluster(cluster, reflect: bool = False, reorder: bool = True, max_iters: int = 1000)

Get the RMSDs between the representative conformer and each conformer in the cluster.

get_tor_matrix(confs: Union[array, list], adjust_periodicity: bool = True) ndarray

Get the torsional matrix consists of torsional angles for the input list of conformer indexes.

Parameters:
  • confid (int) – The conformer ID

  • adjust_periodicity (bool) – Whether to adjust the periodicity for torsional angles.

Returns:

a M (the number of conformers indicated by confs) x N (the number of torsional angles) matrix

Return type:

np.array

get_torsional_angles(confid: int, adjust_periodicity: bool = True) array

Get torsional angles for a given conformers.

Parameters:
  • confid (int) – The conformer ID.

  • adjust_periodicity (bool) – Whether to adjust the periodicity for torsional angles. Defaults to True.

Returns:

A 1D array of torsional angles.

Return type:

np.array

hierarchy_cluster(confs, threshold: float = 5.0, criterion: str = 'distance', method: str = 'average', adjust_periodicity: bool = False, as_dict: bool = True, as_list_idx: bool = False)

The implementation of an hierarchy clustering method based on scipy. It is basically defining clusters based on points within a hypercube defined by threhold. More details refer to:

Parameters:
  • confs (list) – A list of conformer IDs.

  • threshold (float, optional) – The threshold (in degree) used for hierarchy clustering. Defaults to 5.

  • criterion (str, optional) – Specifies the criterion for forming flat clusters. Valid values are ‘inconsistent’, ‘distance’ (default), or ‘maxclust’ cluster formation algorithms

  • method (str, optional) – The linkage method to use. Valid values are single, complete, average (default), weighted, median centroid, and ward. Except median centroid (O(n^3)), others have a computational cost scaled by O(n^2).

  • adjust_periodicity (bool, optional) – Since dihedral angles have a period of 360 degrees. Defaults to True. It is suggested to run twice with this value be True and False to get a better performance.

  • as_dict (bool) – Return the result as a dict object with keys for the index of clusters and values of conformer indexes (provided in confs). Otherwise, return as a list of grouped conformer indexes. Defaults to True.

  • as_list_idx (bool) – Return the indexes in the confs list other than the value in the confs. Default to False.

pairwise_rmsd(i: int, j: int, reflect: bool = False, reorder: bool = True, max_iters: int = 1000)

The implementation of calculating pairwise RMSD values.

Parameters:
  • i (int) – Index of one of the conformer. Usually, used as the ‘reference’.

  • j (int) – Index of the other conformer.

  • reflect (bool, optional) – Whether to reflect the j conformer to rule out mirror symmetry. Defaults to False.

  • reorder (bool, optional) – Whether to allow atom index order to change (based on isomorphism check to rule out torsional symmetry and rotational symmetry).

  • max_iters (int, optional) – The max iteration in mimizing the RMSD.

reset_atom_maps(max_atom_maps=100000)

Reset the stored matches.

Parameters:

max_atom_maps (int) – The maximum number of atom maps to generate To avoid combinatory explosion, it is set to avoid the program to run forever. As a cost, you may miss some mappings.

class rdmc.conf.RDKitConf(conf)

Bases: object

A wrapper for rdchem.Conformer.

The method nomenclature follows the Camel style to be consistent with RDKit.

classmethod FromConformer(conf: Conformer) RDKitConf

Convert a RDKit Chem.rdchem.Conformer to a RDKitConf. This allows a more capable and flexible Conformer class.

Parameters:

conf (Chem.rdchem.Conformer) – A RDKit Conformer instance to be converted.

Returns:

The conformer corresponding to the RDKit Conformer in RDKitConf

Return type:

RDKitConf

classmethod FromMol(mol: Union[RWMol, Mol], id: int = 0) RDkitConf

Get a RDKitConf instance from a Chem.rdchem.Mol/RWMol instance.

Parameters:
  • mol (Union[RWMol, Mol]) – a Molecule in RDKit Default format.

  • id (int) – The id of the conformer to be extracted from the molecule.

Returns:

A Conformer in RDKitConf of the given molecule

Return type:

RDKitConf

classmethod FromRDKitMol(rdkitmol: RDKitMol, id: int = 0) RDkitConf

Get a RDKitConf instance from a RDKitMol instance. The owning molecule of the generated conformer is RDKitMol instead of Chem.rdchem.Mol.

Parameters:
  • rdkitmol (RDKitMol) – a Molecule in RDKitMol.

  • id (int) – The id of the conformer to be extracted from the molecule.

Returns:

A Conformer in RDKitConf of the given molecule

Return type:

RDKitConf

GetAllTorsionsDeg() list

Get the dihedral angles of all torsional modes (rotors) of the Conformer. The sequence of the values are corresponding to the torsions of the molecule (GetTorsionalModes).

Returns:

A list of dihedral angles of all torsional modes.

Return type:

list

GetAngleDeg(atomIds: Sequence[int]) float

Get the angle between atoms in degrees.

Parameters:

atomIds (Sequence) – A 3-element sequence object containing atom indexes.

Returns:

Angle value in degrees.

Return type:

float

GetAngleRad(atomIds: Sequence[int]) float

Get the angle between atoms in rads.

Parameters:

atomIds (Sequence) – A 3-element sequence object containing atom indexes.

Returns:

Angle value in rads.

Return type:

float

GetBondLength(atomIds: Sequence[int]) float

Get the bond length between atoms in Angstrom.

Parameters:

atomIds (Sequence) – A 3-element sequence object containing atom indexes.

Returns:

Bond length in Angstrom.

Return type:

float

GetDistanceMatrix() ndarray

Get the distance matrix of the conformer.

Returns:

n x n distance matrix such that n is the number of atom.

Return type:

array

GetOwningMol()

Get the owning molecule of the conformer.

Returns:

The owning molecule

Return type:

Union[Mol, RWMol, RDKitMol]

GetTorsionDeg(torsion: list) float

Get the dihedral angle of the torsion in degrees. The torsion can be defined by any atoms in the molecule (not necessarily bonded atoms.)

Parameters:

torsion (list) – A list of four atom indexes.

Returns:

The dihedral angle of the torsion.

Return type:

float

GetTorsionalModes(indexed1: bool = False, excludeMethyl: bool = False, includeRings: bool = False) list

Get all of the torsional modes (rotors) of the Conformer. This information is obtained from its owning molecule.

Parameters:
  • indexed1 – The atom index in RDKit starts from 0. If you want to have indexed 1 atom indexes, please set this argument to True.

  • excludeMethyl (bool) – Whether exclude the torsions with methyl groups. Defaults to False.

  • includeRings (bool) – Whether or not to include ring torsions. Defaults to False.

Returns:

A list of four-atom-indice to indicating the torsional modes.

Return type:

Optinal[list]

GetVdwMatrix(threshold=0.4) Optional[ndarray]

Get the derived Van der Waals matrix, which can be used to analyze the collision of atoms. More information can be found from generate_vdw_mat.

Parameters:

threshold – float indicating the threshold to use in the vdw matrix

Returns:

A 2D array of the derived Van der Waals Matrix, if the

the matrix exists, otherwise None.

Return type:

Optional[np.ndarray]

HasCollidingAtoms(threshold=0.4) ndarray
Parameters:

threshold – float indicating the threshold to use in the vdw matrix

HasOwningMol()

Whether the conformer has a owning molecule.

Returns:

True if the conformer has a owning molecule.

Return type:

bool

SetAllTorsionsDeg(angles: list)

Set the dihedral angles of all torsional modes (rotors) of the Conformer. The sequence of the values are corresponding to the torsions of the molecule (GetTorsionalModes).

Parameters:

angles (list) – A list of dihedral angles of all torsional modes.

SetAngleDeg(atomIds: Sequence[int], value: Union[int, float]) float

Set the angle between atoms in degrees.

Parameters:
  • atomIds (Sequence) – A 3-element sequence object containing atom indexes.

  • value (int or float, optional) – Bond angle in degrees.

SetAngleRad(atomIds: Sequence[int], value: Union[int, float]) float

Set the angle between atoms in rads.

Parameters:
  • atomIds (Sequence) – A 3-element sequence object containing atom indexes.

  • value (int or float, optional) – Bond angle in rads.

SetBondLength(atomIds: Sequence[int], value: Union[int, float]) float

Set the bond length between atoms in Angstrom.

Parameters:
  • atomIds (Sequence) – A 3-element sequence object containing atom indexes.

  • value (int or float, optional) – Bond length in Angstrom.

SetOwningMol(owningMol: Union[RDKitMol, Mol, RWMol])

Set the owning molecule of the conformer. It can be either RDKitMol or Chem.rdchem.Mol.

Parameters:

owningMol – Union[RDKitMol, Chem.rdchem.Mol] The owning molecule of the conformer.

Raises:

ValueError – Not a valid owning_mol input, when giving something else.

SetPositions(coords: Union[tuple, list])

Set the Positions of atoms of the conformer.

Parameters:

coords – a list of tuple of atom coordinates.

SetTorsionDeg(torsion: list, degree: Union[float, int])

Set the dihedral angle of the torsion in degrees. The torsion can only be defined by a chain of bonded atoms.

Parameters:
  • torsion (list) – A list of four atom indexes.

  • degree (float, int) – The dihedral angle of the torsion.

SetTorsionalModes(torsions: Union[list, tuple])

Set the torsional modes (rotors) of the Conformer. This is useful when the default torsion is not correct.

Parameters:

torsions (Union[list, tuple]) – A list of four-atom-lists indicating the torsional modes.

Raises:

ValueError – The torsional mode used is not valid.

ToConformer() Conformer

Get its backend RDKit Conformer object.

Returns:

The backend conformer

Return type:

Conformer

ToMol() RDKitMol

Convert conformer to mol.

Returns:

The new mol generated from the conformer

Return type:

RDKitMol

rdmc.conf.edit_conf_by_add_bonds(conf, function_name, atoms, value)

RDKit forbids modifying internal coordinates with non-bonding atoms. This function tries to provide a workaround.

Parameters:
  • conf (RDKitConf) – The conformer to be modified.

  • function_name (str) – The function name of the edit.

  • atoms (list) – A list of atoms representing the internal coordinates.

  • value (float) – Value to be set.