Skip to content

Fix issue #554 - #555

Merged
lohedges merged 6 commits into
develfrom
fix_554
Dec 2, 2026
Merged

lohedges merged 6 commits into
develfrom
fix_554

Conversation

@lohedges

@lohedges lohedges commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Closes #554.

The QM/MM cutoff and charge switching were applied per MM atom, using each atom's own distance to the nearest QM atom. A neutral molecule straddling the switching region therefore had a net effective charge, and the (correct) chain-rule forces for this energy pulled atoms with one sign of charge inwards and the other outwards. With a charged QM region this is strong: for chorismate (q = −2) in water, shell waters rotate their hydrogens towards the QM region and the net MM charge within the cutoff grows from +2.4 e to +44.6 e over 1 ps.

The cutoff and switching are now applied by MM residue, using the distance from each residue's centroid to the nearest QM atom. Whole residues are included or excluded, all of a residue's charges are scaled by the same switching value, and the switching force −(Σⱼ dE/dqⱼ q⁰ⱼ) ds/dr is shared equally over the residue's atoms, with the opposite force on the nearest QM atom. Neutral residues therefore remain neutral.

  • The selection and switching forces are in a shared header (qmgroups.h), used by both PyQMEngine and TorchQMEngine, replacing their duplicated per-atom code. Groups are made whole about their first atom before taking their centroid.
  • The engines and forces have getGroups/setGroups, set from the residues in sire.qm.create_engine and sire.qm.emle. Atoms outside residues form their own groups, and forces streamed by older versions fall back to per-atom groups.
  • The GPU-resident engine passes the residue of each MM atom to callbacks that accept an mm_groups argument, and emle_callback forwards it to emle.models.preprocess, with a warning if the installed emle-engine doesn't support it (Add optional group-based cutoff and switching to preprocess chemle/emle-engine#122). As on the host, each link's MM1 and MM2 atoms and virtual charges form their own group.
  • The Torch engine now reads dE/dq once per step rather than per MM atom.

For ANI2x-EMLE on alanine dipeptide in water, the initial energy changes by −15.4 kJ/mol (only waters in the switching region contribute differently), the host and GPU-resident routes agree to 3×10⁻⁴ kJ/mol, and performance is unchanged.

Tests check that residues are included whole with a single switching factor and zero net switched charge, compare the switching forces on a water in the switching region and on all QM atoms with finite differences of the energy for a charged QM region, and check the groups passed to GPU-resident callbacks.

Checklist

  • I confirm that I have merged the latest version of devel into this branch before issuing this pull request (e.g. by running git pull origin devel): [y]
  • I confirm that I have added a changelog entry to the changelog (we will add a link to this PR as part of the review): [y]
  • I confirm that I have permission to release this code under the MIT license (the Python API) or the LGPLv3+ license (everything else), as described in the LICENSE file: [y]

@lohedges lohedges added the bug Something isn't working label Dec 1, 2026
@lohedges
lohedges merged commit 695b28e into devel Dec 2, 2026
5 checks passed
@lohedges
lohedges deleted the fix_554 branch December 2, 2026 07:02

This branch was previously deployed

1 inactive deployment
sire-build — 1fb27ee8 Deployed Dec 1, 2026 by lohedges via build (3.13, linux) #485
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Per-atom switching of MM charges gives spurious forces on molecules in the switching region

1 participant