Skip to content

[RFC v2] Refactor the reading of atom groups - #999

Open
HanatoK wants to merge 5 commits into
masterfrom
HanatoK/refactor_atom_groups
Open

HanatoK wants to merge 5 commits into
masterfrom
HanatoK/refactor_atom_groups

Conversation

@HanatoK

@HanatoK HanatoK commented Nov 12, 2026

Copy link
Copy Markdown
Member

Summary

This PR implements the idea discussed in #938 (comment), and also refactors the update of lattice (boundary condition) so that boundaries_ is updated only once in the GPU code path. This PR also lays the foundation of reusing atom groups.

Related issue(s)

N/A

Affected engine(s)

All.

Author(s)

@HanatoK

Licensing

By submitting this pull request, I agree that my contribution will be included in Colvars repository and redistributed under the GNU Lesser General Public License (LGPL) version 3.

Note: NAMD, VMD and TinkerHP follow more restrictive licenses, e.g. the UIUC license. However, the terms of the LGPLv3 remain in effect for the copies of the Colvars code distributed alongside those packages.

Artificial Intelligence (AI)

No AI is used so far.

Further information / links

Supersede #953

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical lifecycle and calculation-order bugs can dereference deleted objects, use stale coordinates and gradients, and apply stale forces from inactive components.

6 open issues
What changed in this PR

This PR moves atom-group preparation from individual components into the Colvars module, laying groundwork for group reuse. It also centralizes boundary-condition updates so the GPU path refreshes the lattice once per calculation.

Changes:

  • Add a reference-counted atom-group registry and module-level preparation and force-processing loops.
  • Move fitting-gradient, total-force, and gradient-debugging stages into module scheduling.
  • Replace component-held boundary conditions with proxy reads and an explicit update hook.
File Description
src/​colvars_system.h Exposes boundary fields and comments out unsupported-boundary handling.
src/​colvarproxy_system.h Adds a boundary-update hook and const-reference accessor.
src/​colvarmodule.h Declares atom-group registration and tracking state.
src/​colvarmodule.cpp Centralizes group preparation, gradient stages, and GPU force submission.
src/​colvarcomp.h Removes component-level preparation and fitting-gradient APIs.
src/​colvarcomp.cpp Registers component groups and removes relocated processing.
src/​colvarcomp_distances.cpp Reads boundary conditions locally for distance calculations.
src/​colvarcomp_coordnums.cpp Reads boundary conditions locally for CPU and GPU coordination calculations.
src/​colvarcomp_angles.cpp Reads boundary conditions locally for angle calculations.
src/​colvar.h Declares a separate component-gradient debugging method.
src/​colvar.cpp Removes relocated stages and separates gradient debugging.
namd/​cudaglobalmaster/​colvarproxy_cudaglobalmaster.C Implements explicit, synchronized lattice updates for NAMD.

Review effort: Balanced

Comment thread src/colvarcomp.cpp
Comment on lines +397 to +399
for (size_t i = 0; i < atom_groups.size(); i++) {
cvmodule->unregister_atom_group_from_cvc(atom_groups[i]);
}
Comment thread src/colvarmodule.cpp
Comment on lines +969 to +971
for (auto cvi = variables_active()->begin(); cvi != variables_active()->end(); cvi++) {
if (!(*cvi)->is_enabled(colvardeps::f_cv_total_force_current_step)) {
error_code |= (*cvi)->calc_cvc_total_force(0, (*cvi)->num_cvcs());
Comment thread src/colvarmodule.cpp
Comment on lines +1014 to +1016
it->first->reset_atoms_data();
it->first->read_positions();
it->first->calc_required_properties();
Comment thread src/colvarmodule.cpp
}
error_code |= proxy->update_system_boundaries();
decrease_depth();
error_code |= calc_colvars();
Comment thread src/colvarmodule.cpp
Comment on lines +1045 to +1046
if ((*cvi)->is_enabled(colvardeps::f_cv_total_force_current_step)) {
error_code |= (*cvi)->calc_cvc_total_force(0, (*cvi)->num_cvcs());
Comment thread src/colvarmodule.cpp
Comment on lines +1355 to 1357
for (auto ag = registered_atom_groups.begin(); ag != registered_atom_groups.end(); ++ag) {
error_code |= ag->first->get_gpu_atom_group()->add_force_to_proxy_gpu(ag->first);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants