Skip to content

Torsion

Torsion Scans

rdworks.torsion finds rotatable torsions, builds torsion fragments, and calculates torsion energy profiles. Two scan methods store the same profile format in props['torsion'], a list of dicts with indices, angle, E_rel(kcal/mol), and torsion_angle_idx (plus frag and frag_indices when the torsion is scanned on a fragment, simplify=True).

Method What it does Where results go
torsion_scan() (also Conf.torsion_scan(), Mol.torsion_scan()) sets each torsion angle and relaxes the whole structure; fast, but the angle drifts during relaxation conf.props['torsion'] (mol.props['torsion'] for Mol)
torsion_drive() TorsionDrive (Qiu et al. 2020): constrained optimizations on a periodic grid with wavefront propagation, so each grid point keeps the lowest energy reachable from its neighbors conf.props['torsion']
from rdworks import Mol
from rdworks.torsion import torsion_drive, get_torsion_plot_data

mol = Mol("CC(=O)Nc1ccc(O)cc1", "acetaminophen").make_confs(n=10).optimize_confs().sort_confs()

# relaxed scan of the first conformer
mol = mol.torsion_scan(calculator="MMFF94", interval=20.0)

# TorsionDrive of one torsion with the OpenFF Sage force field
conf = mol.confs[0]
conf.get_torsion_angle_atoms()  # [(5, 4, 3, 1)]
conf = torsion_drive(conf, calculator="Sage", torsion_angle_idx=0, interval=15.0)
plot_data = get_torsion_plot_data(conf.props["torsion"])  # {'idx', 'angle', 'E_rel(kcal/mol)'}

Calculators

The same calculator values work in Conf.singlepoint(), Conf.optimize(), Mol.optimize_confs(), torsion_scan(), and torsion_drive():

calculator Module Install
'MMFF94', 'MMFF94s', 'UFF' RDKit included
ASE calculator object ASE the calculator's own package
'xTB' (not in torsion_drive()) rdworks.xtb xtb executable on PATH
'Parsley', 'Sage', 'Rosemary', 'GAFF', 'GAFF2' rdworks.openff (OpenMM) pip install "rdworks[openff]"; GAFF also needs conda-forge openmmforcefields ambertools
'AIMNet2', 'AIMNet2-B973c', ... rdworks.aimnet2 (TorchSim) pip install "rdworks[aimnet2]"
'UMA' (= uma-s-1p2p1-ft-d4rev, omol task), ... rdworks.uma (fairchem, ASE) pip install "rdworks[uma]" and Hugging Face access to facebook/UMA

GAFF/OpenFF, AIMNet2, and UMA calculations are in the gas phase; passing water with them raises ValueError. Each of these modules provides singlepoint(), optimize(), and constrained_optimize() with the same props and return values as Conf.singlepoint(), Conf.optimize(), and rdworks.torsion.wavefront.constrained_optimize().

Convergence

fmax is the max atomic force in eV/Å for ASE, GAFF/OpenFF, AIMNet2, and UMA (the RDKit force fields use their own convergence criteria). For soft, coupled torsions (e.g. diphenyl ether) a loose fmax can under-relax neighboring torsions and make torsion_drive() slow; tighten fmax rather than raising energy_decrease_thresh, which can give wrong profiles.

API

rdworks.torsion.sp_relaxation

Torsion energy scans (potential energy profiles).

Torsion scan functions take an rdworks.Conf and store potential energy profiles in conf.props['torsion']. Conf methods of the same names delegate here.

Classes

Functions:

torsion_energy_profile(conf, calculator, indices, simplify, interval, fmax, water, use_converged_only)

Calculate potential energy profile for one torsion angle.

Parameters:

  • conf (Conf) –

    reference conformer.

  • calculator (str | Callable) –

    'MMFF', 'UFF', 'xTB' or ASE calculator, passed to conf.optimize(); or 'GAFF', 'GAFF2', 'Parsley', 'Sage', 'Rosemary' (see rdworks.openff); or an AIMNet2 model such as 'AIMNet2' (see rdworks.aimnet2); or a UMA model such as 'UMA' (see rdworks.uma).

  • indices (tuple[int, ...]) –

    atom indices (i,j,k,l) for a torsion angle

  • simplify (bool) –

    whether to use fragmentation.

  • interval (float) –

    angle intervals.

  • fmax (float) –

    convergence limit for optimize. It will be passed to conf.optimize().

  • water (str) –

    water solvation model (choose 'gbsa' or 'alpb'). It will be passed to conf.optimize().

  • use_converged_only (bool) –

    whether to use only converged data.

Args for xTB calculator

water (str, optional): water solvation model (choose 'gbsa' or 'alpb') alpb: ALPB solvation model (Analytical Linearized Poisson-Boltzmann). gbsa: generalized Born (GB) model with Surface Area contributions. Defaults to None.

Returns:

  • dict[str, list] –

    dict[str, list]: A dictionary containing the torsion energy profile with indices, angle, and E_rel(kcal/mol) (plus frag and frag_indices if simplify). E_rel = E_init - median(E_last), shifted so that its minimum is 0.

torsion_scan(conf, calculator, torsion_angle_idx=None, simplify=True, interval=20.0, fmax=0.05, water=None, use_converged_only=True)

Calculates potential energy profiles for each torsion angle by relaxed scans.

Parameters:

  • conf (Conf) –

    reference conformer.

  • calculator (str | Callable) –

    'MMFF', 'UFF', 'xTB', ASE calculator, passed to conf.optimize(); or 'GAFF', 'GAFF2', 'Parsley', 'Sage', 'Rosemary' (see rdworks.openff); or an AIMNet2 model such as 'AIMNet2' (see rdworks.aimnet2); or a UMA model such as 'UMA' (see rdworks.uma).

  • torsion_angle_idx (int | None, default: None ) –

    key to the torsion indices to calculate. Defaults to None (all).

  • simplify (bool, default: True ) –

    whether to use fragment surrogate. Defaults to True.

  • interval (float, default: 20.0 ) –

    interval of torsion angles in degree. Defaults to 20.0.

  • fmax (float, default: 0.05 ) –

    fmax of ASE optimizer. It will be passed to conf.optimize(). Defaults to 0.05.

  • water (str, default: None ) –

    water solvation model (choose 'gbsa' or 'alpb'). It will be passed to conf.optimize(). Defaults to None.

  • use_converged_only (bool, default: True ) –

    whether to use only converged data. Defaults to True.

Args for xTB calculator

water (str, optional): water solvation model (choose 'gbsa' or 'alpb') alpb: ALPB solvation model (Analytical Linearized Poisson-Boltzmann). gbsa: generalized Born (GB) model with Surface Area contributions. Defaults to None.

Returns:

  • Conf ( Conf ) –

    conf with conf.props['torsion'] set to a list of profile dicts, one per torsion, each with indices, angle, E_rel(kcal/mol), and torsion_angle_idx (plus frag and frag_indices if simplify).

rdworks.torsion.wavefront

TorsionDrive: torsion scans driven by wavefront propagation.

Qiu, Y., Smith, D. G. A., Stern, C. D., Feng, M., Jang, H. & Wang, L.-P. Driving torsion scans with wavefront propagation. J. Chem. Phys. 152, 244116 (2020). https://doi.org/10.1063/5.0009232

Unlike rdworks.torsion.sp_relaxation, every grid point is a constrained optimization (the torsion angle is held fixed while all other degrees of freedom relax). Each optimized grid point seeds constrained optimizations at its neighboring grid points (the wavefront); whenever a grid point reaches a lower energy, it joins the next wavefront. The scan ends when no grid point improves, which removes the hysteresis of a one-directional scan.

The results are stored in conf.props['torsion'] in the same format as torsion_scan().

Attributes

logger = logging.getLogger(__name__) module-attribute

Classes

Functions:

constrained_optimize(conf, calculator, indices, angle, fmax=0.05, max_iter=1000, force_constant=1000.0)

Optimize a copy of conf with the torsion angle indices held at angle.

Parameters:

  • conf (Conf) –

    starting conformer (not modified).

  • calculator (str | Callable) –

    'MMFF94' (= 'MMFF'), 'MMFF94s', 'UFF', or ASE calculator; or 'GAFF', 'GAFF2', 'Parsley', 'Sage', 'Rosemary', an AIMNet2 model such as 'AIMNet2', or a UMA model such as 'UMA', which are delegated to the constrained_optimize() of rdworks.openff, rdworks.aimnet2, or rdworks.uma with their own torsion restraints or constraints.

  • indices (tuple[int, ...]) –

    atom indices (i,j,k,l) of the torsion angle.

  • angle (float) –

    target torsion angle in degrees.

  • fmax (float, default: 0.05 ) –

    force convergence limit of the ASE optimizer. Defaults to 0.05.

  • max_iter (int, default: 1000 ) –

    max iterations of the optimizer. Defaults to 1000.

  • force_constant (float, default: 1000.0 ) –

    force constant of the RDKit torsion constraint. Defaults to 1.0e3. Much stiffer constraints (e.g. 1.0e4) can make the RDKit minimizer stop early in higher-energy states.

Raises:

  • ValueError –

    for an unsupported calculator (including 'xTB', which has no constrained optimization; use an ASE xTB calculator instead) or when the force field cannot be set up.

Returns:

  • Conf ( Conf ) –

    optimized copy with E_tot(kcal/mol) (unconstrained energy) and Converged in its props.

torsion_drive(conf, calculator, torsion_angle_idx=None, simplify=True, interval=15.0, fmax=0.05, max_iter=1000, energy_decrease_thresh=0.001, use_converged_only=True)

Calculates potential energy profiles for each torsion angle with TorsionDrive.

TorsionDrive (https://doi.org/10.1063/5.0009232) scans a torsion angle on a periodic grid by wavefront propagation of constrained optimizations, so each grid point ends up with the lowest energy reachable from its neighbors.

Parameters:

  • conf (Conf) –

    reference conformer.

  • calculator (str | Callable) –

    'MMFF94' (= 'MMFF'), 'MMFF94s', 'UFF', or ASE calculator; or 'GAFF', 'GAFF2', 'Parsley', 'Sage', 'Rosemary' (see rdworks.openff); or an AIMNet2 model such as 'AIMNet2' (see rdworks.aimnet2); or a UMA model such as 'UMA' (see rdworks.uma).

  • torsion_angle_idx (int | None, default: None ) –

    key to the torsion indices to calculate. Defaults to None (all).

  • simplify (bool, default: True ) –

    whether to use fragment surrogate. Defaults to True.

  • interval (float, default: 15.0 ) –

    grid spacing of torsion angles in degree; 360 must be a multiple of it. Defaults to 15.0.

  • fmax (float, default: 0.05 ) –

    fmax of ASE optimizer. Defaults to 0.05.

  • max_iter (int, default: 1000 ) –

    max iterations of each constrained optimization. Defaults to 1000.

  • energy_decrease_thresh (float, default: 0.001 ) –

    minimum energy decrease (kcal/mol) for a grid point to be updated and propagated. Defaults to 1.0e-3.

  • use_converged_only (bool, default: True ) –

    whether to use only converged data. Defaults to True.

Returns:

  • Conf ( Conf ) –

    conf with conf.props['torsion'] set to a list of profile dicts, one per torsion, each with indices, angle, E_rel(kcal/mol), and torsion_angle_idx (plus frag and frag_indices if simplify).

torsion_drive_profile(conf, calculator, indices, simplify, interval, fmax, max_iter, energy_decrease_thresh, use_converged_only)

Calculate potential energy profile for one torsion angle by wavefront propagation.

Parameters:

  • conf (Conf) –

    reference conformer (not modified); its geometry seeds the scan.

  • calculator (str | Callable) –

    'MMFF94' (= 'MMFF'), 'MMFF94s', 'UFF', or ASE calculator; or 'GAFF', 'GAFF2', 'Parsley', 'Sage', 'Rosemary'; or an AIMNet2 model such as 'AIMNet2'; or a UMA model such as 'UMA'.

  • indices (tuple[int, ...]) –

    atom indices (i,j,k,l) for a torsion angle.

  • simplify (bool) –

    whether to use fragmentation.

  • interval (float) –

    grid spacing in degrees; 360 must be a multiple of it.

  • fmax (float) –

    convergence limit of the ASE optimizer.

  • max_iter (int) –

    max iterations of each constrained optimization.

  • energy_decrease_thresh (float) –

    a new result replaces a grid point only if it lowers the energy by more than this (kcal/mol).

  • use_converged_only (bool) –

    whether to discard non-converged optimizations.

Raises:

  • ValueError –

    if 360 is not a multiple of interval.

  • RuntimeError –

    if no grid point has a (converged) energy.

Returns:

  • dict[str, list] –

    dict[str, list]: A dictionary containing the torsion energy profile with indices, angle, and E_rel(kcal/mol) (plus frag and frag_indices if simplify). E_rel = E - min(E), where E is the constrained-optimized energy at each grid point.

rdworks.openff.openforcefield

Energies and geometry optimizations with Amber GAFF/GAFF2 and OpenFF force fields (OpenMM).

These functions follow Conf.singlepoint(), Conf.optimize(), and rdworks.torsion.wavefront.constrained_optimize() (same props, same return values), so they can be used for torsion scans and torsion drives.

Force fields (forcefield, case-insensitive), or any explicit name of the same kind: 'GAFF' -> 'gaff-1.81' (openmmforcefields + AmberTools) 'GAFF2' -> 'gaff-2.11' (openmmforcefields + AmberTools) 'Parsley' -> 'openff_unconstrained-1.3.1.offxml' (openff-toolkit) 'Sage' -> 'openff_unconstrained-2.3.0.offxml' (openff-toolkit) 'Rosemary' -> 'openff_unconstrained-3.0.0-rc1.offxml' (openff-toolkit, release candidate)

Partial charges (charge_method): 'nagl' -> OpenFF NAGL graph neural network AM1-BCC charges (openff-nagl; default, fast) 'am1bcc' -> AM1-BCC charges (needs AmberTools sqm or OpenEye) any other openff.toolkit.Molecule.assign_partial_charges() method, e.g. 'gasteiger'

All calculations are in the gas phase (no cutoff). OpenMM systems are cached per molecule (topology, atom order, and stereochemistry), force field, and charge method, so repeated calls on conformers of one molecule (e.g. a torsion scan) assign charges only once.

Install the optional dependencies with pip install rdworks[openff] (OpenFF force fields); GAFF/GAFF2 also need openmmforcefields and ambertools from conda-forge.

Attributes

EV_PER_A_TO_KJ_PER_MOL_NM = 964.8533212 module-attribute

FORCEFIELDS = {'gaff': 'gaff-1.81', 'gaff2': 'gaff-2.11', 'parsley': 'openff_unconstrained-1.3.1.offxml', 'sage': 'openff_unconstrained-2.3.0.offxml', 'rosemary': 'openff_unconstrained-3.0.0-rc1.offxml'} module-attribute

KCAL_TO_KJ = 4.184 module-attribute

NAGL_MODEL = 'openff-gnn-am1bcc-0.1.0-rc.1.pt' module-attribute

logger = logging.getLogger(__name__) module-attribute

Classes

Functions:

constrained_optimize(conf, forcefield, indices, angle, fmax=0.05, max_iter=1000, force_constant=1000.0, charge_method='nagl')

Optimize a copy of conf with the torsion angle indices held at angle.

Parameters:

  • conf (Conf) –

    starting conformer (not modified).

  • forcefield (str) –

    'GAFF', 'GAFF2', 'Parsley', 'Sage', 'Rosemary', or a full force field name (see resolve_forcefield()).

  • indices (tuple[int, ...]) –

    atom indices (i,j,k,l) of the torsion angle.

  • angle (float) –

    target torsion angle in degrees.

  • fmax (float, default: 0.05 ) –

    convergence limit of the max atomic force in eV/Angstrom. Defaults to 0.05.

  • max_iter (int, default: 1000 ) –

    max iterations of the minimizer. Defaults to 1000.

  • force_constant (float, default: 1000.0 ) –

    force constant of the harmonic torsion restraint in kcal/mol/rad^2. Defaults to 1.0e3.

  • charge_method (str, default: 'nagl' ) –

    partial charge method. Defaults to 'nagl'.

Returns:

  • Conf ( Conf ) –

    optimized copy with E_tot(kcal/mol) (energy without the restraint) and Converged in its props.

is_supported(calculator)

Whether calculator names a GAFF or OpenFF force field handled by this module.

Parameters:

  • calculator (str | Callable) –

    calculator passed to torsion scans (name or ASE calculator).

Returns:

  • bool ( bool ) –

    True for 'GAFF', 'GAFF2', 'Parsley', 'Sage', 'Rosemary', 'gaff-', or an OpenFF '.offxml' file name (case-insensitive short names).

optimize(conf, forcefield='Sage', fmax=0.05, max_iter=1000, charge_method='nagl')

Optimize 3D geometry.

Parameters:

  • conf (Conf) –

    conformer (with explicit hydrogens); its coordinates are updated.

  • forcefield (str, default: 'Sage' ) –

    'GAFF', 'GAFF2', 'Parsley', 'Sage', 'Rosemary', or a full force field name (see resolve_forcefield()). Defaults to 'Sage'.

  • fmax (float, default: 0.05 ) –

    convergence limit of the max atomic force in eV/Angstrom (same units as ASE). Defaults to 0.05.

  • max_iter (int, default: 1000 ) –

    max iterations of the minimizer. Defaults to 1000.

  • charge_method (str, default: 'nagl' ) –

    partial charge method. Defaults to 'nagl'.

Returns:

  • Conf ( Conf ) –

    conf with E_tot_init(kcal/mol), E_tot(kcal/mol), and Converged in its props.

resolve_forcefield(forcefield)

Returns the full force field name for a short name ('GAFF', 'GAFF2', 'Parsley', 'Sage', 'Rosemary').

Parameters:

  • forcefield (str) –

    short name, or a full name such as 'gaff-2.11' or 'openff_unconstrained-2.2.1.offxml'.

Raises:

  • ValueError –

    if forcefield is not a GAFF or OpenFF force field name.

Returns:

  • str ( str ) –

    full force field name.

singlepoint(conf, forcefield='Sage', charge_method='nagl')

Get potential energy and set E_tot(kcal/mol) in the conf.props.

Parameters:

  • conf (Conf) –

    conformer (with explicit hydrogens).

  • forcefield (str, default: 'Sage' ) –

    'GAFF', 'GAFF2', 'Parsley', 'Sage', 'Rosemary', or a full force field name (see resolve_forcefield()). Defaults to 'Sage'.

  • charge_method (str, default: 'nagl' ) –

    partial charge method. Defaults to 'nagl'.

Returns:

  • Conf ( Conf ) –

    conf with E_tot(kcal/mol) in its props.

rdworks.aimnet2.aimnet2

Energies and geometry optimizations with the AIMNet2 neural network potential.

AIMNet2: https://github.com/isayevlab/aimnetcentral (aimnet package). Energies come from aimnet.calculators.AIMNet2Calculator; (constrained) geometry optimizations run with TorchSim (torch-sim-atomistic) through aimnet.calculators.aimnet2torchsim.AIMNet2TorchSim.

These functions follow Conf.singlepoint(), Conf.optimize(), and rdworks.torsion.wavefront.constrained_optimize() (same props, same return values), so they can be used for torsion scans and torsion drives.

Models (model, case-insensitive): any AIMNet2 registry name or alias, for example 'AIMNet2' -> 'aimnet2-wb97m-d3_0' (wB97M-D3; default) 'AIMNet2-B973c' -> 'aimnet2-b973c-d3_0' (B97-3c) 'AIMNet2-2025' -> 'aimnet2-b973c-2025-d3_0' 'AIMNet2-NSE' -> 'aimnet2-nse_0' (open-shell; uses conf.spin as multiplicity) Model files are downloaded on first use and cached by aimnet.

Molecular charge (conf.charge) and, for NSE models, spin multiplicity (conf.spin) are passed to the model. Calculations are in the gas phase. AIMNet2 calculators are cached per model and device, so repeated calls (e.g. a torsion scan) load the model only once.

Install the optional dependencies with pip install rdworks[aimnet2].

Attributes

OPTIMIZERS = ('fire', 'lbfgs', 'bfgs', 'gradient_descent') module-attribute

logger = logging.getLogger(__name__) module-attribute

Classes

Functions:

constrained_optimize(conf, model, indices, angle, fmax=0.05, max_iter=1000, force_constant=1000.0, optimizer='fire', device=None)

Optimize a copy of conf with the torsion angle indices held at angle.

Parameters:

  • conf (Conf) –

    starting conformer (not modified).

  • model (str) –

    AIMNet2 model name or alias, e.g. 'AIMNet2'.

  • indices (tuple[int, ...]) –

    atom indices (i,j,k,l) of the torsion angle.

  • angle (float) –

    target torsion angle in degrees.

  • fmax (float, default: 0.05 ) –

    convergence limit of the max atomic force in eV/Angstrom. Defaults to 0.05.

  • max_iter (int, default: 1000 ) –

    max optimizer steps. Defaults to 1000.

  • force_constant (float, default: 1000.0 ) –

    force constant of the harmonic torsion restraint in kcal/mol/rad^2. Defaults to 1.0e3.

  • optimizer (str, default: 'fire' ) –

    TorchSim optimizer. Defaults to 'fire'.

  • device (str | None, default: None ) –

    'cpu', 'cuda', ... Defaults to None (CUDA if available).

Returns:

  • Conf ( Conf ) –

    optimized copy with E_tot(kcal/mol) (energy without the restraint) and Converged in its props.

is_supported(calculator)

Whether calculator names an AIMNet2 model handled by this module.

Parameters:

  • calculator (str | Callable) –

    calculator passed to torsion scans (name or ASE calculator).

Returns:

  • bool ( bool ) –

    True for strings starting with 'AIMNet2' (case-insensitive), e.g. 'AIMNet2', 'AIMNet2-B973c', or 'aimnet2-wb97m-d3_1'.

optimize(conf, model='AIMNet2', fmax=0.05, max_iter=1000, optimizer='fire', device=None)

Optimize 3D geometry with TorchSim.

Parameters:

  • conf (Conf) –

    conformer; its coordinates are updated.

  • model (str, default: 'AIMNet2' ) –

    AIMNet2 model name or alias. Defaults to 'AIMNet2'.

  • fmax (float, default: 0.05 ) –

    convergence limit of the max atomic force in eV/Angstrom (same units as ASE). Defaults to 0.05.

  • max_iter (int, default: 1000 ) –

    max optimizer steps. Defaults to 1000.

  • optimizer (str, default: 'fire' ) –

    TorchSim optimizer: 'fire', 'lbfgs', 'bfgs', or 'gradient_descent'. Defaults to 'fire'.

  • device (str | None, default: None ) –

    'cpu', 'cuda', ... Defaults to None (CUDA if available).

Returns:

  • Conf ( Conf ) –

    conf with E_tot_init(kcal/mol), E_tot(kcal/mol), and Converged in its props.

singlepoint(conf, model='AIMNet2', device=None)

Get potential energy and set E_tot(kcal/mol) in the conf.props.

Parameters:

  • conf (Conf) –

    conformer.

  • model (str, default: 'AIMNet2' ) –

    AIMNet2 model name or alias. Defaults to 'AIMNet2'.

  • device (str | None, default: None ) –

    'cpu', 'cuda', ... Defaults to None (CUDA if available).

Returns:

  • Conf ( Conf ) –

    conf with E_tot(kcal/mol) in its props.

rdworks.uma.uma

Energies and geometry optimizations with the UMA machine-learned interatomic potential.

UMA (Universal Model for Atoms): https://github.com/facebookresearch/fairchem (fairchem-core). Energies and forces come from fairchem.core.FAIRChemCalculator (an ASE calculator); (constrained) geometry optimizations run with ASE optimizers, and torsion angles are held with ase.constraints.FixInternals.

These functions follow Conf.singlepoint(), Conf.optimize(), and rdworks.torsion.wavefront.constrained_optimize() (same props, same return values), so they can be used for torsion scans and torsion drives.

Models (model, case-insensitive): 'UMA' -> 'uma-s-1p2p1-ft-d4rev' (default) any fairchem model name -> e.g. 'uma-s-1p2p1', 'uma-m-1p1', 'uma-s-1p2p1-ft-r2scan' Task (task): 'omol' (molecules; default), 'omat', 'oc20', 'odac', or 'omc'.

With the 'omol' task, the molecular charge (conf.charge) and spin multiplicity (conf.spin) are passed to the model. Calculations are in the gas phase. Calculators are cached per model, task, and device, so repeated calls (e.g. a torsion scan) load the model only once.

UMA checkpoints are gated on Hugging Face (https://huggingface.co/facebook/UMA): accept the license there and authenticate, e.g. with the HF_TOKEN environment variable or huggingface-cli login, before the first use. Install the optional dependencies with pip install rdworks[uma].

Attributes

DEFAULT_MODEL = 'uma-s-1p2p1-ft-d4rev' module-attribute

DEFAULT_TASK = 'omol' module-attribute

OPTIMIZERS = ('FIRE', 'LBFGS', 'BFGS') module-attribute

logger = logging.getLogger(__name__) module-attribute

Classes

Functions:

constrained_optimize(conf, model, indices, angle, fmax=0.05, max_iter=1000, optimizer='FIRE', task=DEFAULT_TASK, device=None)

Optimize a copy of conf with the torsion angle indices held at angle.

Parameters:

  • conf (Conf) –

    starting conformer (not modified).

  • model (str) –

    'UMA' (= 'uma-s-1p2p1-ft-d4rev') or a fairchem model name.

  • indices (tuple[int, ...]) –

    atom indices (i,j,k,l) of the torsion angle.

  • angle (float) –

    target torsion angle in degrees.

  • fmax (float, default: 0.05 ) –

    convergence limit of the max atomic force in eV/Angstrom. Defaults to 0.05.

  • max_iter (int, default: 1000 ) –

    max optimizer steps. Defaults to 1000.

  • optimizer (str, default: 'FIRE' ) –

    ASE optimizer: 'FIRE', 'LBFGS', or 'BFGS'. Defaults to 'FIRE'.

  • task (str, default: DEFAULT_TASK ) –

    UMA task. Defaults to 'omol'.

  • device (str | None, default: None ) –

    'cpu' or 'cuda'. Defaults to None (CUDA if available).

Returns:

  • Conf ( Conf ) –

    optimized copy with E_tot(kcal/mol) and Converged in its props. The torsion is held exactly by FixInternals, which adds no energy term.

is_supported(calculator)

Whether calculator names a UMA model handled by this module.

Parameters:

  • calculator (str | Callable) –

    calculator passed to torsion scans (name or ASE calculator).

Returns:

  • bool ( bool ) –

    True for strings starting with 'UMA' (case-insensitive), e.g. 'UMA' or 'uma-s-1p2p1-ft-d4rev'.

optimize(conf, model='UMA', fmax=0.05, max_iter=1000, optimizer='FIRE', task=DEFAULT_TASK, device=None)

Optimize 3D geometry with an ASE optimizer.

Parameters:

  • conf (Conf) –

    conformer; its coordinates are updated.

  • model (str, default: 'UMA' ) –

    'UMA' (= 'uma-s-1p2p1-ft-d4rev') or a fairchem model name. Defaults to 'UMA'.

  • fmax (float, default: 0.05 ) –

    convergence limit of the max atomic force in eV/Angstrom. Defaults to 0.05.

  • max_iter (int, default: 1000 ) –

    max optimizer steps. Defaults to 1000.

  • optimizer (str, default: 'FIRE' ) –

    ASE optimizer: 'FIRE', 'LBFGS', or 'BFGS'. Defaults to 'FIRE'.

  • task (str, default: DEFAULT_TASK ) –

    UMA task. Defaults to 'omol'.

  • device (str | None, default: None ) –

    'cpu' or 'cuda'. Defaults to None (CUDA if available).

Returns:

  • Conf ( Conf ) –

    conf with E_tot_init(kcal/mol), E_tot(kcal/mol), and Converged in its props.

resolve_model(model)

Returns the fairchem model name ('UMA' -> 'uma-s-1p2p1-ft-d4rev').

Raises:

  • ValueError –

    if model is not a UMA model name.

singlepoint(conf, model='UMA', task=DEFAULT_TASK, device=None)

Get potential energy and set E_tot(kcal/mol) in the conf.props.

Parameters:

  • conf (Conf) –

    conformer.

  • model (str, default: 'UMA' ) –

    'UMA' (= 'uma-s-1p2p1-ft-d4rev') or a fairchem model name. Defaults to 'UMA'.

  • task (str, default: DEFAULT_TASK ) –

    UMA task. Defaults to 'omol'.

  • device (str | None, default: None ) –

    'cpu' or 'cuda'. Defaults to None (CUDA if available).

Returns:

  • Conf ( Conf ) –

    conf with E_tot(kcal/mol) in its props.

rdworks.torsion.atom_indices

Rotatable-bond (dihedral a-b-c-d) detection.

Functions:

get_torsion_angle_atom_indices(rdmol, strict=True)

Determine dihedral angle atoms (a-b-c-d) and rotating group for each rotatable bond (b-c).

The bond b-c is split into two fragments. The smaller fragment (by heavy atom count) is the rotating group and must contain at least three heavy atoms. A rotatable bond is skipped when: - b or c has no neighbor other than H, F, Cl, Br, or I to define a or d - a-b or c-d is in a small ring (3 or 4 atoms) - a and d are in the same ring (macrocycle)

Parameters:

  • rdmol (Mol) –

    molecule.

  • strict (bool, default: True ) –

    whether to exclude amide/imide/ester/acid bonds. Defaults to True.

Returns:

  • list[tuple] –

    list[tuple[int, int, int, int, tuple[int, ...], tuple[int, ...]]]: [ (a, b, c, d, rot_atom_indices, fix_atom_indices), (a, b, c, d, rot_atom_indices, fix_atom_indices), ..., ]

rdworks.torsion.fragment

Torsion fragment creation around a rotatable bond.

Classes

Functions:

create_torsion_fragment(rdmol, torsion_indices, wbo_tolerance=0.03)

Create a close surrogate fragment that captures the PES of the intended torsion.

Fragmentation aims to preserve the local chemical environment around the targeted torsion while increasing calculation speed and avoiding potential complications. To avoid oversimplification and inaccurate approximation, two strategies are combined: - fragment candidates are generated by a set of reasonably empirical rules - further filtered by Wiberg bond order (WBO) calculated by semi-empirical QM. It has been shown that the Wiberg bond order (WBO) provides a fast and robust measure of whether a torsion profile has been disrupted by fragmentation. Any fragment that causes WBO difference larger than wbo_tolerance will be excluded. WBO filtering is used only if xTB is available.

Parameters:

  • rdmol (Mol) –

    molecule.

  • torsion_indices (tuple) –

    (i, j, k, l, atoms to be rotated, atoms to be fixed)

  • wbo_tolerance (float, default: 0.03 ) –

    maximum allowed WBO change at the j-k bond. Defaults to 0.03.

Returns:

  • Mol –

    (Chem.Mol: fragment molecule,

  • tuple[int, ...] –

    tuple[int, ...]: fragment atom indices of (i, j, k, l),

  • bool ( bool ) –

    True if fragmented,

  • bool ( bool ) –

    True if WBO filtering is used)

References

https://pubs.acs.org/doi/10.1021/acs.jcim.2c01153 https://www.biorxiv.org/content/10.1101/2020.08.27.270934v2

rdworks.torsion.plot

Plot data (torsion angle vs. relative energy) from torsion scan results.

Functions:

get_torsion_plot_data(torsion_profiles, idx=None)

Returns plot data (torsion angle vs. relative energy) from torsion scan results.

Parameters:

  • torsion_profiles (list[dict]) –

    torsion profiles, i.e. props['torsion'] set by torsion_scan() or torsion_drive().

  • idx (int, default: None ) –

    0-based torsion angle index. Defaults to None (all torsion angles).

Returns:

  • dict –

    {'idx': list, 'angle': list, 'E_rel(kcal/mol)': list}