deepmodeling / deepmodeling/deepmd-kit
[Feature Request] Add cutoff-based compact evaluation to LAMMPS pair_style deepmd for DPRc
- Dominant language
- Python
- Stars
- 2k
- Forks
- 649
- Avg merge
- 6d 18h
- Merged PRs (30d)
- 15
Description
## Summary
Add an optional cutoff-based compact-evaluation mode to the LAMMPS `pair_style deepmd` integration for standard Deep Potential Range Correction (DPRc) QM/MM simulations.
The mode should always include a user-defined QM/core group, dynamically include nearby MM molecules within a DPRc environment cutoff, run the model only on that compact subsystem, and scatter the resulting energy, virial, forces, atomic outputs, and model-deviation data back to the full LAMMPS system.
This request is for standard DPRc. It does not require residue-index `aparam` support and does not target the experimental `pairwise_dprc` model.
## Motivation
A standard DPRc model can already be evaluated by the current `pair_style deepmd` on a full QM/MM system:
- QM and MM atoms use different model types.
- Descriptor `exclude_types` removes MM-MM interactions and separates the QM-QM and QM-MM cutoffs.
- MM atomic energy biases are set to zero.
- `pair_style hybrid/overlay` can combine the DPRc correction with the low-level QM/MM Hamiltonian and classical MM interactions.
We verified the full-system path with a current DeePMD-kit checkout and a current LAMMPS checkout using:
- xTB QM/MM plus `pair_style hybrid/overlay ... deepmd`;
- one and four DeepMD models;
- `model_devi.out`;
- serial and two MPI ranks;
- implicit TIP4P electrostatics;
- orthogonal and triclinic periodic cells; and
- COLVARS restraints.
The missing capability is compact evaluation.
The current LAMMPS integration constructs coordinates and types for every mapped local and ghost atom, then calls the DeepMD model with the LAMMPS neighbor list. The neighbor list limits interaction edges to the model cutoff, but all mapped solvent atoms still enter the model input as nodes/atomic centers. Static `NULL` type mappings cannot express a spatially changing QM environment.
For a representative solvated DPRc system, the full LAMMPS system contains 16 QM atoms and 2,974 water molecules, or about 8,938 physical atoms after converting TIP4P virtual sites to implicit sites. The corresponding Amber DPRc correction clusters contain only about 226-285 physical atoms. Full-system inference is therefore expected to add substantial avoidable cost, even though distant MM atoms have zero physical DPRc contribution.
## Required semantics
Given a fixed LAMMPS group containing the QM/core atoms and an explicit environment cutoff:
1. Always include every atom in the QM/core group.
2. Select an MM molecule if any of its physical atoms is within the environment cutoff of any QM/core atom.
3. Include all physical atoms of each selected MM molecule, so water and other residues are never truncated.
4. Respect periodic minimum-image geometry, including restricted triclinic cells.
5. Build compact coordinate, type, ownership, ghost, and neighbor-list mappings for the selected subsystem.
6. Evaluate the DeepMD model only on that compact subsystem.
7. Scatter forces and per-atom outputs back to the original LAMMPS atom indices; excluded atoms receive no DeepMD contribution.
8. Accumulate the compact-system energy and virial into the normal LAMMPS pair contribution.
9. Apply the same selection to every model used for model deviation.
10. Preserve the existing full-system behavior when the new option is absent.
This is more than reducing the neighbor cutoff: cutoff-based neighbor edges already exist. The feature must remove inactive MM atoms from the model node/center list and backend input.
## Tentative user interface
The exact keyword names are open for discussion. One possible interface is:
```lammps
group qm id ...
pair_style hybrid/overlay \
... \
deepmd graph.000.pb graph.001.pb graph.002.pb graph.003.pb \
center_group qm environment_cutoff 6.0 include_molecule yes \
out_file model_devi.out out_freq 100
```
Suggested meanings:
- `center_group qm`: atoms that are always included and define the center of the environment selection.
- `environment_cutoff 6.0`: MM selection cutoff in current LAMMPS distance units. This is explicit because the largest model cutoff may be the QM-QM cutoff rather than the shorter QM-MM correction cutoff.
- `include_molecule yes`: promote an atom-level cutoff hit to the complete LAMMPS molecule ID.
If topology policy should remain outside the pair style, an equally acceptable design is a generic per-atom selection interface, for example `atom_selection_from_compute ID`, plus a separate LAMMPS compute that performs the core-group, cutoff, and whole-molecule selection. The important pair-style capability is compacting a dynamic selected subsystem and mapping its outputs correctly.
No new `aparam` implementation is needed for this proposal.
## Proposed implementation plan
### Phase 1: document and protect the existing full-system DPRc path
- Add a small standard-DPRc LAMMPS example using `hybrid/overlay`.
- Add regression coverage for duplicate LAMMPS-type-to-model-type mappings used to preserve different classical LJ types.
- Cover one model, multiple models, model deviation, `NULL` types, MPI, and triclinic boxes where applicable.
- Document that the correction model must be trained as the high-level minus the same low-level Hamiltonian used during MD.
### Phase 2: compact selected-subsystem evaluation in `pair_style deepmd`
- Parse the selected core group and environment cutoff, or accept a generic per-atom selection source.
- Rebuild selection when coordinates or the relevant neighbor list change.
- Synchronize selected status and molecule membership across MPI ownership boundaries.
- Compact owned and ghost atoms while retaining forward and reverse mappings to LAMMPS atom indices and global tags.
- Filter and remap the external neighbor list to the compact indices.
- Invalidate any DeepMD neighbor-list cache when the compact mapping changes.
- Scatter forces, atomic energies, atomic virials, and other per-atom model outputs to the full LAMMPS arrays.
- Correctly handle MPI ranks with no selected owned atoms.
- Keep the no-selection code path unchanged.
### Phase 3: model deviation and accelerator parity
- Apply an identical compact mapping to all ensemble models.
- Define and document model-deviation statistics over selected atoms only.
- Define atomic model-deviation output for excluded atoms while retaining stable LAMMPS atom identity.
- Add the same semantics to `pair_style deepmd/kk`, or explicitly diagnose it as unsupported until implemented.
- Benchmark CPU and GPU inference using both the full system and compact DPRc cluster.
### Phase 4: DPRc QM/MM integration example
- Add an integration example that overlays a low-level QM/MM or mock correction provider, classical MM terms, and the compact DPRc pair contribution.
- Demonstrate multiple model deviation and a changing solvent environment.
- Document requirements for molecule IDs, the selection cutoff, periodic imaging, and hybrid/overlay coefficients.
The xTB QM/MM implementation itself can remain in LAMMPS; the DeepMD feature should be generic and should not depend on xTB-specific code.
## Acceptance criteria
A first complete implementation should satisfy the following:
- Compact and full-system evaluation of the same standard DPRc model agree in energy, virial, and selected-atom forces within numerical tolerance.
- Instrumentation or a test hook confirms that distant unselected MM atoms are not passed to the model backend.
- A complete MM molecule is included when only one of its atoms crosses the selection cutoff.
- Selection is correct when the QM region or a selected molecule crosses an orthogonal or triclinic periodic boundary.
- Serial and multi-rank MPI results agree, including domain decomposition with empty selected subdomains.
- Four-model deviation uses the same selected atom mapping for all models.
- `hybrid/overlay` leaves the low-level QM/MM and classical MM contributions unchanged.
- Existing inputs without the new keywords produce unchanged results.
- Tests cover atoms and molecules entering and leaving the environment selection.
## Non-goals
This issue does not propose:
- new residue-index `aparam` support;
- support for the experimental `pairwise_dprc` model;
- automatic removal of QM bonded terms, QM-QM LJ, or duplicated classical electrostatics;
- Amber-to-LAMMPS topology or TIP4P virtual-site conversion;
- DP-GEN workflow changes; or
- automatic generation or retraining of DPRc correction models.
I am willing to work on the implementation as staged pull requests after agreement on the public interface and the division of responsibility between the pair style and a possible selection compute.
## References
- DPRc documentation: https://docs.deepmodeling.com/projects/deepmd/en/latest/model/dprc.html
- DPRc paper: https://doi.org/10.1021/acs.jctc.1c00201
- DeePMD-kit LAMMPS command documentation: https://docs.deepmodeling.com/projects/deepmd/en/latest/third-party/lammps-command.html
Coding agent: Codex
Codex version: codex-cli 0.144.6
Model: gpt-5.6-sol
Reasoning effort: xhigh
Contributor guide
Assessment
This issue has not been assessed yet.