openmm
openmm
¶
OpenMM molecular mechanics backend.
Provides a full-featured MM engine using OpenMM for energy, minimization,
Hessian, and frequency calculations. Supports both harmonic and MM3
functional forms with runtime parameter updates via :class:_OpenMMState.
OpenMMBackend
¶
Molecular mechanics backend powered by OpenMM.
Supports both harmonic (AMBER-style) and MM3 functional forms. A prepared
session holds a reusable :class:_OpenMMState so parameter updates during
an optimization loop do not rebuild the OpenMM system.
Initialize the OpenMM backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
platform_name
|
str | None
|
OpenMM platform to use (e.g. |
None
|
precision
|
str | None
|
Floating-point precision for GPU platforms
( |
None
|
Raises:
| Type | Description |
|---|---|
BackendUnavailableError
|
If OpenMM is not installed. |
BackendConfigurationError
|
If precision is invalid. |
Source code in q2mm/backends/mm/openmm.py
info
property
¶
info: BackendInfo
Immutable capability declaration for this backend.
The platform name is baked into the provenance/name, so this is built
per instance. Both HARMONIC and MM3 forms use CustomForce objects
with global parameters, so analytical parameter gradients are
available; batched energy and Hessian-parameter Jacobians are not.
prepare
¶
prepare(request: PreparationRequest) -> PreparedOpenMM
Build a prepared session for one training case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
PreparationRequest
|
Preparation request carrying the molecule and base force field. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
PreparedOpenMM |
PreparedOpenMM
|
A per-case session owning a reusable
:class: |
Raises:
| Type | Description |
|---|---|
PreparationError
|
If no force field is supplied, its functional form is unsupported, or the OpenMM system cannot be built. |
Source code in q2mm/backends/mm/openmm.py
PreparedOpenMM
¶
PreparedOpenMM(*, backend: OpenMMBackend, info: BackendInfo, case_id: str, molecule: Molecule, force_field: ForceField, layout: Any, state: _OpenMMState)
Bases: AbstractPreparedBackend
Prepared OpenMM session for a single training case.
Owns the molecule, base force field, parameter layout, and one reusable
private :class:_OpenMMState. Energy, Hessian, and frequency evaluations
update the state's global parameters in place (reusing native state), while
minimization and analytical parameter gradients build a throwaway state so
they never mutate the reusable energy/Hessian state.
Source code in q2mm/backends/mm/openmm.py
detect_best_platform
¶
Return the name of the fastest available OpenMM platform.
If the OPENMM_DEFAULT_PLATFORM environment variable is set, its
value is returned directly (no validation against installed
platforms). This allows test harnesses to force CPU-only execution.
Otherwise, platform preference order: CUDA > OpenCL > CPU > Reference.
Logs a warning when CUDA is unavailable and the function falls back to OpenCL on a system with an NVIDIA GPU — OpenCL on modern NVIDIA GPUs gives very poor utilisation (~14%). The warning is suppressed on non-NVIDIA systems where OpenCL may be the intended backend.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Name of the best available platform. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If OpenMM is not installed. |