rdmc.forcefield#

A module used to deal with force field supported by RDKit.

class rdmc.forcefield.OpenBabelFF(force_field: str = 'mmff94s')#

Bases: object

A wrapper to deal with Force field of Openbabel. It can handle both RDKit Mol and OBMol as input. We suggest to use this class for small scale calculations, due to its slowness.

add_angle_constraint(atoms: Sequence, angle: int | float)#

Add a angle constraint to the force field.

Parameters:
  • atoms (Sequence) – a length-3 sequence indicate the atom index.

  • value (int or float) – The degree value of the bond angle.

add_distance_constraint(atoms: Sequence, value: int | float)#

Add a distance constraint to the force field.

Parameters:
  • atoms (Sequence) – a length-2 sequence indicate the atom index.

  • value (int or float) – The distance value in Angstrom.

add_torsion_constraint(atoms: Sequence, angle: int | float)#

Add torsion constraint to the force field.

Parameters:
  • atoms (Sequence) – a length-4 sequence indicate the atom index.

  • value (int or float) – The degree value of the torsion angle.

available_force_field = ['mmff94s', 'mmff94', 'uff', 'gaff']#
available_solver = ['ConjugateGradients', 'SteepestDescent']#
fix_atom(atom_idx: int)#

Fix the coordinates of an atom given by its index.

Parameters:

atom_idx (int) – The atom index of the atom to fix.

get_optimized_mol() Mol#

Clean up the optimized molecule and return it. Please call this function once you believe the optimization is done, and ready to get the optimized molecule.

Returns:

Mol – The optimized molecule

is_optimizable(mol: Mol | None = None) bool#

Check if Openbabel has the parameters for all atom type in the molecule.

Parameters:

mol (Mol) – The molecule to be checked.

Returns:

bool – Whether RDKit has parameters.

property mol#

The molecule to be optimized.

optimize(max_step: int = 100000, tol: float = 1e-08, step_per_iter: int = 5)#

Optimize the openbabel molecule.

set_solver(solver_type: str)#
setup(mol: Mol | RDKitMol | OBMol | None = None, constraints: ob.OBFFConstraints | None = None)#

Setup the force field and get ready to be optimized.

property type#

Return the force field backend.

update_atom_idx(atoms: Sequence) list#

Update_atom_idx if a rdkit mol atom index is provided.

Parameters:

atoms (Sequence) –

class rdmc.forcefield.RDKitFF(force_field: str = 'mmff94s')#

Bases: object

A wrapper to deal with Force field in RDKit.

add_angle_constraint(atoms: Sequence, value: int | float | None = None, min_angle: int | float | None = None, max_angle: int | float | None = None, relative: bool = False, force_constant: int | float = 100000.0)#

Add a angle constraint to the force field. You should set either value or min_angle and max_angle.

Parameters:
  • atoms (Sequence) – a length-2 sequence indicate the atom index.

  • value (int or float) – Set angle to a certain value if value is provided.

  • min_angle (int or float) – The minimum angle value in degrees or in factor of current length (if relative==True).

  • max_angle (int or float) – The maximum angle value in degrees or in factor of current length (if relative==True).

  • relative (bool, optional) – Whether input as relative angle to the current length.

  • force_constant (int or float, optional) – the constant in optimization.

add_distance_constraint(atoms: Sequence, value: int | float | None = None, min_len: int | float | None = None, max_len: int | float | None = None, relative: bool = False, force_constant: int | float = 100000.0)#

Add a distance constraint to the force field. You should set either value or min_len and max_len.

Parameters:
  • atoms (Sequence) – a length-2 sequence indicate the atom index.

  • value (int or float) – Set distance to a certain value if value is provided.

  • min_len (int or float) – The minimum distance value in Angstrom or in factor of current length (if relative==True).

  • max_len (int or float) – The maximum distance value in Angstrom or in factor of current length (if relative==True).

  • relative (bool, optional) – Whether input as relative distance to the current length.

  • force_constant (int or float, optional) – the constant in optimization.

add_torsion_constraint(atoms: Sequence, value: int | float | None = None, min_angle: int | float | None = None, max_angle: int | float | None = None, relative: bool = False, force_constant: int | float = 100.0)#

Add a torsion constraint to the force field. You should set either value or min_angle and max_angle.

Parameters:
  • atoms (Sequence) – a length-2 sequence indicate the atom index.

  • value (int or float) – Set angle to a certain value if value is provided.

  • min_angle (int or float) – The minimum angle value in degrees or in factor of current length (if relative==True).

  • max_angle (int or float) – The maximum angle value in degrees or in factor of current length (if relative==True).

  • relative (bool, optional) – Whether input as relative angle to the current length.

  • force_constant (int or float, optional) – the constant in optimization.

available_force_field = ['mmff94s', 'mmff94', 'uff']#
fix_atom(atom_idx: int)#

Fix the coordinates of an atom given by its index.

Parameters:

atom_idx (int) – The atom index of the atom to fix.

get_conformer_energies()#

Get the energy of all conformers of the molecule. Surprisingly, there is no such a handy function built in the RDKit. The built-in function is CalcEnergy which you can only get the energy of the index 0 conformer (the default). The energies are in kcal/mol.

Returns:

list – Energies of all conformers of the molecule.

get_energy()#

Get the energy of the first conformer of the molecule in kcal/mol.

Returns:

float – the energy of the index 0 conformer

get_optimized_mol() Mol#

Clean up the optimized molecule and return it. Please call this function once you believe the optimization is done, and ready to get the optimized molecule.

Returns:

Mol – The optimized RDKitMol molecule

is_optimizable(mol: Mol | None = None) bool#

Check if RDKit has the parameters for all atom type in the molecule.

Parameters:

mol (Mol) – The molecule to be checked.

Returns:

bool – Whether RDKit has parameters.

make_optimizable(mol: RDKitMol | None = None, in_place: bool = False) tuple#

Make the molecule able to be optimized by the force field. Known problematic molecules:

  1. RO[O] is not optimizable by RDKit MMFF. By changing -O[O] to -OF, it allows the geometry to be optimized yielding reasonable results.

  2. [H].XXX and [O].XXX is not optimizable by RDKit MMFF. Changing [H] to [Cl], and [O] to [F].

  3. [H][H] is optimizable by RDKit MMFF. Changing to ClCl; when recovery change the bond length

    back to 74 pm.

  4. [O][O] is not optimizable by RDKit MMFF. when recovery change the bond length back to 120.8 pm.

Parameters:
  • mol ('Mol') – Molecule to be changed.

  • in_place (bool, optional) – Whether to make the change inplace. Defaults to False.

Returns:

(‘Mol’, dict) – A modified molecule and approaches to modify this molecule.

Raises:

NotImplementedError – Conversion strategy has not been implemented.

property mol#

The molecule to be optimized.

optimize(max_step: int = 100000, tol: float = 1e-08, step_per_iter: int = 5)#

Optimize the RDKit molecule.

optimize_confs(max_step: int = 100000, num_threads: int = 0, step_per_iter: int = 5)#

A wrapper for force field optimization for multiple conformers simultaneously.

It can take constraints for optimization, but all conformers share the same constraints. This can be confusing when using relative value constraints. When using relative constraints, the actual value to be used is only based on the first conformer. Therefore, if you are doing a torsional scan, you CANNOT first generate conformers with different torsional angles, and and then set the relative constraint with value = 1, and optimize using this function. You still should iterate conformers and use optmize() instead.

Parameters:
  • max_step (int, optional) – max iterations. Defaults to 200.

  • num_threads (int, optional) – number of threads to use. Defaults to 0 for all.

  • step_per_iter (int, optional) – number of outer cycle. Check convergence after maxIters. Defaults to 20.

Returns:
  • - int – 0 for optimization done; 1 for not optimized; -1 for not optimizable.

  • - float – energy

recover_mol(mol: Mol | None = None, edits: dict = {}, in_place: bool = True)#

Recover the molecule from modifications.

Parameters:
  • mol ('Mol') – Molecule to be changed.

  • edits (dict) – A dict of approach to modify this molecule

  • in_place (bool, optional) – Whether to make the change inplace. Defaults to True.

Returns:

‘Mol’ A recovered molecule.

Raises:

NotImplementedError – Conversion strategy has not been implemented.

setup(mol: Mol | RDKitMol | None = None, conf_id: int = -1, ignore_interfrag_interactions=False)#

Setup the force field and get ready to be optimized.

Parameters:
  • mol (Mol or RDKitMol, optional) – Setup the force field based on the molecule.

  • conf_id (int, optional) – The ID of the conformer to optimize.

  • ignore_interfrag_interactions (bool, optional) – Whether to ignore interfragment interactions. Defaults to False to allow a similar behavior as the other package.

torsional_scan_1d(torsion, num_points: int = 45, rigid: bool = True, init_angle: float | None = None, force_constant: float = 100, return_xyz: bool = False)#
property type#

Return the force field backend.

update_atom_idx(atoms: Sequence) list#

Update_atom_idx if a rdkit mol atom index is provided.

Parameters:

atoms (Sequence) –

rdmc.forcefield.get_roo_radical_atoms(mol: Mol) tuple#

Find the oxygen radical site of peroxide groups in the RDKit molecules. This atomtype is currently not optimizable by RDKit built-in MMFF algorithm.

Parameters:

mol – Union[RDKitMol, Mol, RWMol]: RDKitMol or RDKit molecule objects.

Returns:

tuple – The atom index of the oxygen radical site.

rdmc.forcefield.optimize_mol(mol: RDKitMol, force_field: str = 'MMFF94s', tol: float = 1e-08, step_size: int = 5, max_step: int = 10000, ignore_interfrag_interaction=False, frozen_bonds: list = [], frozen_non_bondings: list = [])#

A helper function to quickly launch forcefield optimization, and automatically retry Openbabel force field if RDKit force field fails.