diff --git a/CHANGELOG.md b/CHANGELOG.md index 85be722..7f8d8fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,34 @@ All notable changes to fes-ml are listed here. +## Unreleased + +### Changed + +- `EMLEPotential` no longer uses Sire. It is one openmm-torch `TorchForce` (TorchScript), replayed + from a CUDA graph on CUDA devices, so no Python runs at each step. The ML charges are scaled by + 1 - lambda in the NonbondedForce, and the force adds lambda * E_EMLE. lambda = 0 is now the MM + System with PME. See the new guide page, "EMLE embedding". +- With periodic boundary conditions, EMLE sums the ML-MM electrostatics over all periodic images + with PME by default (`electrostatics="pme"`). +- `EMLEPotential` keeps lambda in the global parameter `lambda_emle` (or `lambda_interpolate` + when it takes lambda from `MLInterpolation`). Windows with EMLE can share one Context. +- EMLE energies change, because the scheme is new. + +### Upgrading + +- The `emle` extra no longer needs Sire. PME needs an emle-engine with `electrostatics="pme"`. +- The `EMLEPotential` options `backend`, `torch_model`, `neighbour_list_frequency`, + `lambda_interpolate`, `interpolate_steps` and `dispersion_mode` raise an error. New options: + `electrostatics`, `pme_cutoff`, `pme_tolerance`, `switch_width`, `cuda_graph` and `dense_aev`. +- `EMLEPotential` and `ChargeScaling` on the same atoms raise an error. +- The OpenFF strategy no longer takes `emle_plus`. + +### Removed + +- The strategy inputs `mols`, `parm7`, `mm_charges`, `openmm_charges`, `top_file` and `crd_file`, + which only EMLE used, and the lambda "levers" of `AlchemicalState` and `SharedContext`. + ## 0.4.0 (2026-12-04) This release adds protocol files, one output file per window, MBAR analysis and provenance diff --git a/README.md b/README.md index ba2db71..dfc6848 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,8 @@ fes-ml-analyse benzene_water_window_*.h5 --decorrelate More in the user guide: [λ schedules and modifications](https://michellab.github.io/fes-ml/guide/schedules/), [running simulations](https://michellab.github.io/fes-ml/guide/running/) (one window per job, restarts), -[Sire and OpenFF strategies, EMLE](https://michellab.github.io/fes-ml/guide/strategies/), +[Sire and OpenFF strategies](https://michellab.github.io/fes-ml/guide/strategies/), +[EMLE embedding](https://michellab.github.io/fes-ml/guide/emle/), [alchemical groups](https://michellab.github.io/fes-ml/guide/groups/), [writing a modification](https://michellab.github.io/fes-ml/guide/extending/), [logging](https://michellab.github.io/fes-ml/guide/logging/). diff --git a/docs/guide/emle.md b/docs/guide/emle.md new file mode 100644 index 0000000..595c5ff --- /dev/null +++ b/docs/guide/emle.md @@ -0,0 +1,76 @@ +# EMLE embedding + +`EMLEPotential` gives the ML region an electrostatic embedding with +[EMLE](https://github.com/chemle/emle-engine): the MM charges polarise the ML region (static and +induced terms). It runs inside OpenMM as one openmm-torch `TorchForce`, with no Sire and no Python +at each step. + +## The energy + +``` +E(λ) = E_MM[ML charges (1 − λ) q] + λ E_EMLE +``` + +- The MM charges of the ML atoms are scaled by `1 − λ` with parameter offsets in the + NonbondedForce. So the MM electrostatics between the ML and MM atoms go from full at λ = 0 to + none at λ = 1, through OpenMM's own PME. +- `E_EMLE` is the EMLE embedding energy of the ML atoms in the field of the MM charges. +- The ML-ML pairs move to a separate force, as with `MLInterpolation`, so they do not change + with λ. + +At λ = 0 the System is the MM System; at λ = 1 the ML-MM electrostatics are EMLE. In between, the +energy is linear in λ, except for the interaction of the ML region with its own periodic images in +the MM term, which goes as (1 − λ)². + +With periodic boundary conditions, EMLE sums the electrostatics over all periodic images with PME +(`electrostatics="pme"`, the default). `electrostatics="cutoff"` uses a cutoff and a smooth switch +instead. Without periodic boundary conditions, EMLE uses all MM atoms. + +λ is the OpenMM global parameter `lambda_emle` (`lambda_emle_` for a named group). Without +its own λ, `EMLEPotential` uses the λ of the `MLInterpolation` of its group (`lambda_interpolate`). +So windows can share one Context. + +```python +schedule = {"MLInterpolation": [1.0, 0.5, 0.0], "EMLEPotential": [1.0, 0.5, 0.0]} +modifications_kwargs = {"MLPotential": {"name": "ani2x"}} +``` + +## Options + +| Option | Default | Meaning | +|---|---|---| +| `method` | `"electrostatic"` | EMLE method: `"electrostatic"`, `"mechanical"` or `"nonpol"` | +| `model` | `None` | EMLE model file; `None` is the default model of emle-engine | +| `alpha_mode` | `"fixed"` | how emle-engine computes the polarisabilities | +| `qm_charge` | sum of the MM charges | total charge of the ML region | +| `electrostatics` | `"pme"` if periodic | `"pme"` or `"cutoff"` | +| `pme_cutoff` | `"10A"` | real-space cutoff of PME; shorter than half the box width minus the size of the ML region | +| `pme_tolerance` | `2e-5` | Ewald error tolerance, as in OpenMM | +| `cutoff` | `"12A"` | cutoff with `electrostatics="cutoff"` | +| `switch_width` | `0.2` | part of the cutoff over which the switch goes from 1 to 0 | +| `device` | CUDA if available | device of the EMLE model | +| `cuda_graph` | `True` | replay the force from a CUDA graph (openmm-torch's `useCUDAGraphs`) | +| `dense_aev` | `True` | emle-engine's dense features, which a CUDA graph can capture (cost grows with the cube of the number of ML atoms) | +| `forceGroup` | `0` | force group of the EMLE force | + +`EMLEPotential` and `ChargeScaling` cannot both scale the charges of the same atoms. + +## Speed + +Ethanol in 1000 waters (3009 atoms), 1 fs steps, one RTX 4090, EMLE with a CUDA graph: about +1.3 ms per step with PME, against 0.1 ms for MM alone. Without the CUDA graph, a step is 6 to 8 +times slower. In float32 on CUDA, two evaluations at the same positions differ by up to about +4e-3 kJ/mol. + +## Installation + +The `emle` extra installs emle-engine and openmm-torch. PME needs an emle-engine with +`electrostatics="pme"`. + +## Changes from fes-ml 0.4 + +Earlier versions ran EMLE through Sire and a Python `EMLECalculator`, with a cutoff, so λ = 0 was +not the PME MM System and the ML region lost the electrostatics beyond the cutoff. The options +`backend`, `torch_model`, `neighbour_list_frequency`, `lambda_interpolate`, `interpolate_steps` and +`dispersion_mode` are gone: the ML energy comes from `MLPotential` or `MLInterpolation`, and λ +comes from the schedule. diff --git a/docs/guide/extending.md b/docs/guide/extending.md index 59f0282..46276d2 100644 --- a/docs/guide/extending.md +++ b/docs/guide/extending.md @@ -55,9 +55,8 @@ options in `modifications_kwargs["MassScaling"]`. [groups and dependencies](groups.md). - If `apply` needs data that only the creation strategy has, declare it: `inputs = ("topology",)`. The strategy then passes it as a keyword argument, computed once per - group. Both strategies provide `topology` (OpenMM), `mols` (Sire), `parm7` and `mm_charges`; the - OpenFF strategy also provides `positions`, `topology_off`, `original_offxml`, `openmm_charges`, - and `top_file`/`crd_file` when EMLE needs them. + group. Both strategies provide `topology` (OpenMM); the OpenFF strategy also provides + `positions`, `topology_off` and `original_offxml`. - To let a Context change your λ without rebuilding the System, keep λ in an OpenMM global parameter named by `self.lambda_parameter` and set the class attribute `LAMBDA_PARAMETER` (for example `"lambda_mass"`); named groups get the suffix `_` automatically. diff --git a/docs/guide/schedules.md b/docs/guide/schedules.md index bd7348b..42f5994 100644 --- a/docs/guide/schedules.md +++ b/docs/guide/schedules.md @@ -24,7 +24,7 @@ values outside [0, 1] give a warning. `None` in a window leaves that modificatio | `ChargeScaling` | full charges | zero charges (intermolecular electrostatics only) | — | | `MLInterpolation` | ML potential for the alchemical region | MM potential | `ml` extra | | `MLCorrection` | MM + (ML − MM) Δ-learning correction | MM | `ml` extra | -| `EMLEPotential` | electrostatic embedding | mechanical embedding | `emle` extra | +| `EMLEPotential` | EMLE electrostatic embedding | MM electrostatics | `emle` extra | | `CustomLJ` | optimised LJ parameters (from an offxml) | original LJ parameters | `openff` extra | | `ChargeTransfer` | short-ranged charge-transfer term on | off | `openff` extra | @@ -51,7 +51,7 @@ The options of each modification are the keyword arguments of its `apply` method ## λ as OpenMM global parameters -`LJSoftCore`, `ChargeScaling`, `ChargeTransfer`, `MLInterpolation` and `MLCorrection` keep λ in an OpenMM global +`LJSoftCore`, `ChargeScaling`, `ChargeTransfer`, `MLInterpolation`, `MLCorrection` and `EMLEPotential` keep λ in an OpenMM global parameter, so an existing Context can be moved to another λ with `context.setParameter(...)`: | Modification | Parameter | @@ -60,9 +60,10 @@ parameter, so an existing Context can be moved to another λ with `context.setPa | `ChargeScaling` | `lambda_electrostatics` (NonbondedForce parameter offsets) | | `ChargeTransfer` | `lambda_charge_transfer` | | `MLInterpolation`, `MLCorrection` | `lambda_interpolate` | +| `EMLEPotential` | `lambda_emle` (or `lambda_interpolate`, without its own λ) | For a named [group](groups.md), the name gets the suffix `_`, for example -`lambda_sterics_ligand`. `CustomLJ` and `EMLEPotential` build their λ into the System. +`lambda_sterics_ligand`. `CustomLJ` builds its λ into the System. `{"ChargeScaling": {"use_global_parameter": False}}` writes the scaled charges into the System instead. The two forms agree exactly on the Reference platform. On CUDA, OpenMM's PME takes a diff --git a/docs/guide/strategies.md b/docs/guide/strategies.md index e803b5e..d58b0a1 100644 --- a/docs/guide/strategies.md +++ b/docs/guide/strategies.md @@ -43,15 +43,13 @@ Results can depend on the Sire version that built the system, so record it with ### EMLE -Options of the [`EMLECalculator`](https://github.com/chemle/emle-engine) go to the -`EMLEPotential` modification: +`EMLEPotential` works with both strategies and does not need Sire; see [EMLE embedding](emle.md): ```python -modifications_kwargs = {"EMLEPotential": {"method": "electrostatic", "backend": "torchani", "device": "cpu"}} +modifications_kwargs = {"EMLEPotential": {"method": "electrostatic", "cutoff": "12A"}} ``` -The strategy provides the files and charges EMLE needs. The old `emle_kwargs` argument still works -but is deprecated. +The old `emle_kwargs` argument still works but is deprecated. ## OpenFF diff --git a/docs/index.md b/docs/index.md index 3903fcc..c6f68f6 100644 --- a/docs/index.md +++ b/docs/index.md @@ -44,7 +44,8 @@ fes-ml-analyse benzene_water_window_*.h5 --decorrelate - [Installation](installation.md): which extras you need. - [λ schedules and modifications](guide/schedules.md): what each modification does. - [Running simulations](guide/running.md): minimisation, equilibration, production, restarts. -- [Creation strategies](guide/strategies.md): Sire or OpenFF, dynamics options and EMLE. +- [EMLE embedding](guide/emle.md): electrostatic embedding of the ML region, without Sire. +- [Creation strategies](guide/strategies.md): Sire or OpenFF, and dynamics options. - [Alchemical groups and dependencies](guide/groups.md): several regions in one schedule, and how the modifications are ordered. - [Writing a modification](guide/extending.md): add your own. diff --git a/docs/installation.md b/docs/installation.md index 6711782..9c9cc97 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -8,7 +8,7 @@ system builders and potentials are optional extras, so you install only what you | `sire` | the Sire creation strategy (Amber files) | `sire` | | `openff` | the OpenFF creation strategy (the default), `CustomLJ`, `ChargeTransfer` | `openff-toolkit`, `openff-interchange` | | `ml` | `MLPotential`, `MLInterpolation`, `MLCorrection` | `openmm-ml`, `openmm-torch`, `torch`, `torchani` | -| `emle` | `EMLEPotential` (electrostatic embedding) | `emle-engine`, `sire` | +| `emle` | `EMLEPotential` (electrostatic embedding) | `emle-engine`, `openmm-torch` | | `analysis` | MBAR | `pymbar` | | `viz` | plots | `matplotlib` | | `dev` | tests, linting, type checks | `pytest`, `ruff`, `mypy`, `pre-commit` | diff --git a/environment.yaml b/environment.yaml index 0838462..be71505 100644 --- a/environment.yaml +++ b/environment.yaml @@ -16,7 +16,7 @@ dependencies: # OpenMM 8.5 is built against NumPy 2, which mace-torch (pip) installs (#17) - openmm>=8.5 - coloredlogs - # Sire strategy, EMLE + # Sire strategy - sire # OpenFF strategy, CustomLJ, ChargeTransfer - openff-toolkit @@ -24,7 +24,7 @@ dependencies: - ambertools # packmol-memgen (ambertools) imports pkg_resources, which setuptools 82 removes - setuptools<82 - # ML modifications + # ML modifications and EMLE - openmm-torch - openmm-ml - pytorch=*=*cuda* @@ -34,6 +34,6 @@ dependencies: - pymbar - pip - pip: - # Pinned: the default branch moves (2026-12-03) - - git+https://github.com/chemle/emle-engine.git@85bb26207bff651fda4c765b16516a11ae1625db + # Pinned: PME for EMLE (electrostatics="pme") is in chemle/emle-engine pull request 133, not merged yet + - git+https://github.com/JMorado/emle-engine.git@17af21f2263672551c4e59be21a04651cca5e0ca - mace-torch diff --git a/examples/ml_mm_emle/ml_mm_emle.py b/examples/ml_mm_emle/ml_mm_emle.py index fafc10a..4263a4d 100755 --- a/examples/ml_mm_emle/ml_mm_emle.py +++ b/examples/ml_mm_emle/ml_mm_emle.py @@ -8,9 +8,9 @@ The alchemical schedule consists of a single stage: 1. ML Interpolation: Gradually transitions from MM to ML representation of the solute in solution (MLInterpolation: 1.0 -> 0.0, where 1.0 is ML and 0.0 is MM) -2. EMLE Potential: Gradually transitions from mechanical embedding to electrostatic embedding (EMLE) - representation of the solute in solution - (EMLEPotential: 1.0 -> 0.0, where 1.0 is electrostatic embedding and 0.0 is mechanical embedding) +2. EMLE Potential: Gradually transitions from MM electrostatics to the EMLE electrostatic embedding + of the solute in solution + (EMLEPotential: 1.0 -> 0.0, where 1.0 is EMLE embedding and 0.0 is MM electrostatics) Usage: python ml_mm_emle.py