Use MMFFBatchedForcefield when you need per-molecule settings or atom-specific constraints. Unlike the top-level functions, this class allows you to pass sequences (lists) for scalar arguments to apply different settings to each molecule in the batch.
Supported per-molecule arguments:
properties: RDKit MMFFMolProperties objects (or None for defaults).nonBondedThreshold: Non-bonded cutoff distance.ignoreInterfragInteractions: Boolean to omit non-bonded terms between fragments.
Constraints:
Constraints are added via a per-molecule view ff[i]. Constraints applied to molecule i affect all its conformers. Use the relative=True flag on distance, angle, or torsion constraints to use offsets from the current geometry instead of absolute values.
from rdkit.Chem import AllChem
from nvmolkit.batchedForcefield import MMFFBatchedForcefield
# Setup per-molecule properties
props_b = AllChem.MMFFGetMoleculeProperties(mols[1])
props_c = AllChem.MMFFGetMoleculeProperties(mols[2])
props_c.SetMMFFVariant("MMFF94s")
props_c.SetMMFFDielectricConstant(4.0)
props_c.SetMMFFDielectricModel(2) # 1 = constant, 2 = distance-dependent
# Initialize batched forcefield with per-molecule lists
ff = MMFFBatchedForcefield(
mols,
properties=[None, props_b, props_c],
nonBondedThreshold=[100.0, 25.0, 25.0],
ignoreInterfragInteractions=[True, False, True],
)
# Add constraints to specific molecules
ff[0].add_distance_constraint(idx1=0, idx2=2, relative=True, min_len=-0.2, max_len=0.5, force_constant=20.0)
ff[0].add_position_constraint(idx=0, max_displ=0.1, force_constant=50.0)
ff[1].add_angle_constraint(idx1=0, idx2=1, idx3=2, relative=False, min_angle_deg=100.0, max_angle_deg=120.0, force_constant=25.0)
ff[2].add_torsion_constraint(idx1=0, idx2=1, idx3=2, idx4=3, relative=False, min_dihedral_deg=-10.0, max_dihedral_deg=10.0, force_constant=8.0)
# Run minimization
energies, converged = ff.minimize(maxIters=200, forceTol=1e-4)