Custom Forces and Integrators
Use this sub-skill when the task involves OpenMM Custom*Force classes, CustomIntegrator, force groups, global/per-element parameter updates, tabulated functions, expression parsing, or smoke-testing a hand-built custom System.
Route Tasks
- For selecting a custom force class, expression variables, parameters, exclusions, cutoffs, interaction groups, tabulated functions, or serialization behavior, read
references/custom-force-api.md. - For
CustomIntegratoralgorithms, constraints, random variables, force-group-specificf0/energy0expressions, MTS patterns, or aMD-style boosts, readreferences/custom-integrator-recipes.md. - For parse errors, undefined variables, parameter update mistakes, unit/count mismatches, nonbonded double counting, force-group queries, stochastic reproducibility, or serialization failures, read
references/troubleshooting.md. - For a quick installed OpenMM sanity check, run
scripts/custom_force_smoke.py; it builds a two-particleCustomBondForceon the Reference platform and asserts finite energy.
Core Workflow
- Choose the narrowest
Custom*Forceclass that matches the interaction geometry, then write the expression in OpenMM algebra syntax with class-specific variables. - Add all global, per-particle, per-bond, per-angle, per-torsion, donor/acceptor, group, or computed parameters before adding interaction records.
- Ensure every required element count matches the
Systembefore creating aContext; forCustomNonbondedForce, add one particle parameter record for every system particle. - Prefer
Context.setParameter()for frequently tuned globals; useset*Parameters()plusupdateParametersInContext()for changed per-element values; reserveContext.reinitialize()for topology/count/force-definition changes. - Assign force groups deliberately when querying energy pieces, excluding query-only forces from integration, or implementing MTS/custom algorithms.
- Validate on the
Referenceplatform with explicit positions, finite energy/force assertions, and XML serialization round trips when systems must be portable.
Boundaries
- Use
../force-fields-modeling/for ForceField XML authoring, template matching, residue modeling, and parameter file selection. - Use
../platforms-performance/for CUDA/OpenCL/HIP/CPU/Reference platform selection, precision, determinism, and performance tuning. - Use
../development-extensions/for implementing new platform kernels, C++ plugins, or new core OpenMM force classes.