Add ENERGY_ONLY bit to eflag parameter for force computation#4914
Merged
Conversation
this adds a new bit flag ENERGY_ONLY to the eflag variable and adds code to force computing styles to convert this into an eflag_only variable that is zero or non-zero based on eflag
for fixes and computes calling force styles' compute() method and only use the global energy add ENERGY_ONLY bit to eflag.
…is set also improve comments
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends LAMMPS’ energy/virial flag plumbing by introducing an ENERGY_ONLY bit, intended for call sites that only need the global potential energy (and no virial/per-atom tallies), and propagates this through core force components and several fixes/computes that frequently evaluate energies.
Changes:
- Add
ENERGY_ONLYto the energy flag enum and thread a correspondingeflag_onlystate throughPair,KSpace,Bond,Angle,Dihedral,Improper, andFixEV setup logic. - Update multiple MC/FEP/DIELECTRIC/EXTRA-FIX call sites to request
ENERGY_GLOBAL | ENERGY_ONLYand to useVIRIAL_NONEinstead of literal0. - Minor formatting/indentation cleanups in several headers.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/force.h | Adds ENERGY_ONLY bit to energy flags; reformats related enums. |
| src/pair.h | Tracks eflag_only in the Pair class state. |
| src/pair.cpp | Masks eflag_either, computes eflag_only, and clears it in ev_unset(). |
| src/kspace.h | Tracks eflag_only in KSpace and resets it in ev_init() fast-path. |
| src/kspace.cpp | Masks eflag_either and computes eflag_only in KSpace::ev_setup(). |
| src/bond.h | Adds eflag_only to bond EV flag state and reset chain. |
| src/bond.cpp | Masks eflag_either and computes eflag_only in Bond::ev_setup(). |
| src/angle.h | Adds eflag_only to angle EV flag state and reset chain. |
| src/angle.cpp | Masks eflag_either and computes eflag_only in Angle::ev_setup(). |
| src/dihedral.h | Adds eflag_only to dihedral EV flag state and reset chain. |
| src/dihedral.cpp | Masks eflag_either and computes eflag_only in Dihedral::ev_setup(). |
| src/improper.h | Adds eflag_only to improper EV flag state and reset chain. |
| src/improper.cpp | Masks eflag_either and computes eflag_only in Improper::ev_setup(). |
| src/fix.h | Adds eflag_only to fix EV flag state and reset chain; minor whitespace tweak. |
| src/fix.cpp | Computes eflag_only in Fix::ev_setup() and documents ENERGY_ONLY. |
| src/MC/fix_widom.cpp | Requests global-energy-only evaluation via `ENERGY_GLOBAL |
| src/MC/fix_gcmc.cpp | Requests global-energy-only evaluation via `ENERGY_GLOBAL |
| src/MC/fix_sgcmc.cpp | Requests global-energy-only evaluation via `ENERGY_GLOBAL |
| src/MC/fix_neighbor_swap.cpp | Requests global-energy-only evaluation via `ENERGY_GLOBAL |
| src/MC/fix_mol_swap.cpp | Requests global-energy-only evaluation via `ENERGY_GLOBAL |
| src/MC/fix_atom_swap.cpp | Requests global-energy-only evaluation via `ENERGY_GLOBAL |
| src/MC/fix_charge_regulation.cpp | Requests global-energy-only evaluation via `ENERGY_GLOBAL |
| src/FEP/compute_fep.cpp | Switches compute to request global-energy-only evaluation via `ENERGY_GLOBAL |
| src/FEP/compute_fep_ta.cpp | Switches compute to request global-energy-only evaluation via `ENERGY_GLOBAL |
| src/EXTRA-FIX/fix_numdiff.cpp | Uses `ENERGY_GLOBAL |
| src/EXTRA-FIX/fix_numdiff_virial.cpp | Uses `ENERGY_GLOBAL |
| src/DIELECTRIC/fix_polarize_bem_icc.cpp | Requests global-energy-only evaluation via `ENERGY_GLOBAL |
| src/DIELECTRIC/fix_polarize_bem_gmres.cpp | Requests global-energy-only evaluation via `ENERGY_GLOBAL |
You can also share your feedback on Copilot code review. Take the survey.
akohlmey
marked this pull request as ready for review
March 12, 2026 17:15
ndtrung81
approved these changes
Mar 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This adds a new bit, ENERGY_ONLY, to the eflag variable which indicates that only the (global) energy is required. This can be used by force styles to skip over steps only required for computing forces and may result in significant savings for computations like MC fixes when they need to do a full energy computation.
Related Issue(s)
This addresses the feature request and thus closes #4847
Author(s)
Axel Kohlmeyer, Temple U
Licensing
By submitting this pull request, I agree, that my contribution will be included in LAMMPS and redistributed under either the GNU General Public License version 2 (GPL v2) or the GNU Lesser General Public License version 2.1 (LGPL v2.1).
Artificial Intelligence (AI) Tools Usage
By submitting this pull request, I confirm that I did NOT use any AI tools to generate
all or parts of the code and modifications in this pull request.
Backward Compatibility
Yes.
Implementation Notes
Rather than using "magic" numbers we now use the symbolic constants to set eflag and vflag to make the desired intent more obvious.
Post Submission Checklist