Skip to content

Support full initialization of volumetric maps within Colvars - #737

Merged
giacomofiorin merged 27 commits into
masterfrom
internalize-gridforces
Sep 5, 2026
Merged

Support full initialization of volumetric maps within Colvars#737
giacomofiorin merged 27 commits into
masterfrom
internalize-gridforces

Conversation

@giacomofiorin

@giacomofiorin giacomofiorin commented Oct 23, 2024

Copy link
Copy Markdown
Member

Currently, volumetric map and Multi-Map variables (link) are implemented in NAMD in two ways:

  1. using MGridForce keywords, with atoms selected by MGridForceFile and scalable computation over multiple processors/nodes done by NAMD as implemented here (more efficient)
  2. using MGridForce keywords, but with atoms selected and processed internally by Colvars (more flexible)

In VMD the situation is similar, with MGridForce replaced by VMD commands and with the distinction that

This PR improves the use-case no. 2, i.e. when atoms are selected and processed directly by Colvars. It allows to specify the volumetric map's file name directly in the Colvars configuration, with the following advantages:

  • there is no need for an additional Tcl script to load the maps
  • the syntax is now identical to NAMD and VMD

One disadvantage of processing the atoms and the maps internally to Colvars is that NAMD's parallel communication cannot be used any more (use-case no. 1). However, in today's most GPU-based computations there are not many CPU tasks.

The documentation and the Colvars Dashboard template for mapTotal are updated accordingly. Additionally, there is now a template configuration for a Multi-Map variable as well (although using the generator script is still preferred)

@giacomofiorin
giacomofiorin force-pushed the internalize-gridforces branch from 10238ef to 6c2ac5b Compare October 23, 2024 16:04
@giacomofiorin giacomofiorin changed the title Support full initialization volumetric maps within Colvars Support full initialization of volumetric maps within Colvars Oct 23, 2024
@HanatoK

HanatoK commented Oct 25, 2024

Copy link
Copy Markdown
Member

It seems with this PR and NAMD's main branch, the interface volmap tests are still failed either in the CPU build or in the GPU build. Do I miss something?

@giacomofiorin

giacomofiorin commented Oct 25, 2024

Copy link
Copy Markdown
Member Author

It seems with this PR and NAMD's main branch, the interface volmap tests are still failed either in the CPU build or in the GPU build.

Correct, this PR tries to fix the issue of NAMD raising an error when gridForces are defined with GPU-resident, even if they are never meant to be used on the GPU. By making Colvars load them instead, the user's intent is much clearer.

The issue of NAMD main no longer supporting reduction via ComputeGlobal (on any hardware configuration) still remains unaddressed. (EDIT: Should be fixed soon as of April 2026, but performance with GPU-resident is not great)

@giacomofiorin
giacomofiorin force-pushed the internalize-gridforces branch 3 times, most recently from 42ed8ad to 4c45a16 Compare October 27, 2024 19:44
@jhenin

jhenin commented Nov 27, 2024

Copy link
Copy Markdown
Member

Is this ready for review?

@giacomofiorin
giacomofiorin marked this pull request as draft December 2, 2024 00:41
@giacomofiorin

Copy link
Copy Markdown
Member Author

@jhenin I have a few jobs that showed discontinuities upon restarting: likely a PBC issue. I converted it back to draft accordingly.

@giacomofiorin giacomofiorin self-assigned this Mar 4, 2025
@giacomofiorin
giacomofiorin force-pushed the internalize-gridforces branch 2 times, most recently from d191eb2 to 180446a Compare March 14, 2025 20:19
@giacomofiorin
giacomofiorin force-pushed the internalize-gridforces branch from 180446a to cec10ae Compare March 28, 2025 15:03
@giacomofiorin
giacomofiorin force-pushed the internalize-gridforces branch 2 times, most recently from ed017ad to 702b47b Compare April 16, 2026 21:33
@giacomofiorin

Copy link
Copy Markdown
Member Author

After rebasing onto master:

  • NAMD ARM volmap regtests fail, but this looks like another instance of single-precision math
  • VMD volmap tests segfault

@giacomofiorin
giacomofiorin force-pushed the internalize-gridforces branch from 702b47b to 3a068b1 Compare June 9, 2026 19:08
@giacomofiorin
giacomofiorin marked this pull request as ready for review June 11, 2026 20:29
@giacomofiorin
giacomofiorin requested review from HanatoK and jhenin June 11, 2026 20:29
@giacomofiorin

Copy link
Copy Markdown
Member Author

All tests pass now, minus the small numerical deviations in AMD64 due to the use of the NAMD GridForces code, which uses single-precision math. I disabled those.

@giacomofiorin
giacomofiorin force-pushed the internalize-gridforces branch 2 times, most recently from 5ece717 to 9ba4988 Compare July 23, 2026 18:23
Here, the main test is that numatoms (computed internally by Colvars) is equal to numatoms_ref (computed by NAMD)
Also remove a few heap allocations
Allow different deformation amplitude between leaflets, small fixes

Fix reading input from --deformation-map-mask option

Issue identified by @1004parky, mask map was initialized to 1 in all cases.

Silence NumPy warnings

Small fixes

Fix handling of PDB files in generated VMD input

Make single-map CVs optional

Allow customizing selection for COM and orientation restraints

Make generated NAMD and VMD scripts more uniform

Unify writing of Colvars input between NAMD and VMD

Add support for mapFile keyword
@giacomofiorin
giacomofiorin force-pushed the internalize-gridforces branch from 9ba4988 to 7985f08 Compare August 26, 2026 21:19

@HanatoK HanatoK left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me overall.

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.

Pull request overview

Adds Colvars-managed volumetric-map loading through mapFile for NAMD and VMD, with supporting Multi-Map generation, documentation, templates, and tests.

Changes:

  • Separates engine-managed and internally computed map APIs.
  • Adds internal DX loading and Multi-Map generator support.
  • Updates documentation, templates, fixtures, and golden outputs.

Reviewed changes

Copilot reviewed 42 out of 44 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
vmd/tests/interface/005_multiple_maps/AutoDiff/test.colvars.traj Updates VMD trajectory baseline.
vmd/tests/interface/005_multiple_maps/AutoDiff/test.colvars.out Updates VMD log baseline.
vmd/tests/interface/004_map_total_internal/AutoDiff/test.colvars.traj Updates internal-map trajectory baseline.
vmd/tests/interface/004_map_total_internal/AutoDiff/test.colvars.out Updates internal-map log baseline.
vmd/src/colvarproxy_vmd.h Declares internal-map APIs.
vmd/src/colvarproxy_vmd.C Implements VMD DX loading and indexed computation.
vmd/cv_dashboard/templates/component.colvars Adds mapFile and Multi-Map templates.
src/colvarproxy_volmaps.h Separates engine and internal map interfaces.
src/colvarproxy_volmaps.cpp Implements shared map bookkeeping.
src/colvarcomp_volmaps.cpp Adds mapFile parsing and execution paths.
namd/tests/library/Common/origin.pdb Adds density-generation origin fixture.
namd/tests/library/Common/make_densities.tcl Expands and recenters generated maps.
namd/tests/interface/007_map_total_internal/test.in Exercises NAMD mapFile loading.
namd/tests/interface/007_map_total_internal/skip_test.sh Skips the test on AArch64.
namd/tests/interface/007_map_total_internal/namd-version.txt Updates recorded runtime version.
namd/tests/interface/007_map_total_internal/AutoDiff/test.restart.colvars.traj Updates restart trajectory baseline.
namd/tests/interface/007_map_total_internal/AutoDiff/test.restart.colvars.state.stripped Updates restart-state baseline.
namd/tests/interface/007_map_total_internal/AutoDiff/test.restart.colvars.out Updates restart log baseline.
namd/tests/interface/007_map_total_internal/AutoDiff/test.colvars.traj Updates trajectory baseline.
namd/tests/interface/007_map_total_internal/AutoDiff/test.colvars.state.stripped Updates state baseline.
namd/tests/interface/007_map_total_internal/AutoDiff/test.colvars.out Updates log baseline.
namd/tests/interface/006_multiple_maps/namd-version.txt Updates recorded runtime version.
namd/tests/interface/006_multiple_maps/AutoDiff/test.restart.colvars.traj Updates restart trajectory baseline.
namd/tests/interface/006_multiple_maps/AutoDiff/test.restart.colvars.state.stripped Updates restart-state baseline.
namd/tests/interface/006_multiple_maps/AutoDiff/test.restart.colvars.out Updates restart log baseline.
namd/tests/interface/006_multiple_maps/AutoDiff/test.colvars.traj Updates Multi-Map trajectory baseline.
namd/tests/interface/006_multiple_maps/AutoDiff/test.colvars.state.stripped Updates Multi-Map state baseline.
namd/tests/interface/006_multiple_maps/AutoDiff/test.colvars.out Updates Multi-Map log baseline.
namd/tests/interface/005_map_total_cvc/skip_test.sh Skips the test on AArch64.
namd/tests/interface/005_map_total_cvc/namd-version.txt Updates recorded runtime version.
namd/tests/interface/005_map_total_cvc/AutoDiff/test.restart.colvars.traj Updates restart trajectory baseline.
namd/tests/interface/005_map_total_cvc/AutoDiff/test.restart.colvars.state.stripped Updates restart-state baseline.
namd/tests/interface/005_map_total_cvc/AutoDiff/test.restart.colvars.out Updates restart log baseline.
namd/tests/interface/005_map_total_cvc/AutoDiff/test.colvars.traj Updates trajectory baseline.
namd/tests/interface/005_map_total_cvc/AutoDiff/test.colvars.state.stripped Updates state baseline.
namd/tests/interface/005_map_total_cvc/AutoDiff/test.colvars.out Updates log baseline.
namd/src/GlobalMaster.C.patch Initializes grid-object iterator state.
namd/src/colvarproxy_namd.h Declares NAMD internal-map storage and APIs.
namd/src/colvarproxy_namd.C Implements NAMD map loading and engine integration.
doc/colvars-refman-main.tex Documents mapFile and Multi-Map usage.
devel-tools/compile-vmd.sh Enables VMD debug symbols.
colvartools/gen_multimap.py Adds internal loading and generator options.
Suppressed comments (5)

colvartools/gen_multimap.py:1030

  • Changing this default to False makes the if args.use_pdb_weights is None auto-enable branch in check_prep_args() unreachable. Consequently, supplying --input-pdb-files no longer enables PDB weights by default, contrary to the option's help and prior behavior.
    group.add_argument('--use-pdb-weights',
                       action='store_true',
                       help='When true, multiply the occupancy and temperature '
                       'PDB columns to define the weights of each atom within '
                       'each map; when false, all weights are equal to 1. '
                       'Defaults to True if --input-pdb-files is used.',
                       default=False)

colvartools/gen_multimap.py:1190

  • This assignment discards a mask loaded through --deformation-map-mask whenever --mask-by-amplitude is also set. Both option descriptions explicitly allow combining masking functions, so the amplitude mask must be multiplied into the existing mask as before.
        args.deformation_map_mask = \
            get_mask_from_deformation(deformation_map=args.deformation_map,
                                      threshold=mask_threshold,
                                      tolerance=0.2*mask_threshold)

colvartools/gen_multimap.py:1384

  • For a 2D workflow with multiple input selections (for example upper and lower leaflets), this fallback chooses only the first PDB file. The previous implementation built averaged distanceZ components for every unique selection, so generated scripts now restrain one leaflet instead of the system COM. Preserve all input selections when no explicit --com-restraint-pdb-file is supplied.
        com_pdb_file = ori_pdb_file = args.com_restraint_pdb_file
        if com_pdb_file is None:
            com_pdb_file = ori_pdb_file = pdb_files[0]

colvartools/gen_multimap.py:1036

  • The help says this option has no effect in VMD, but write_vmd_script() uses it to suppress mol addfile and generate mapFile components. Users therefore cannot rely on the documented behavior; describe that internal loading applies to both NAMD and VMD.
                       help="When true, Colvars will load the maps internally using "
                       "\"mapFile\" and the atoms are processed diretly by Colvars "
                       "instead of NAMD; "
                       "this option has no effect in VMD",

doc/colvars-refman-main.tex:4090

  • This second link has the same visible-keyword error: weights require an atoms group, not mapName. As written, the public reference directs users to configure an incompatible map identifier.
    This option requires defining using the \refkey{mapName}{colvar|mapTotal|atoms} keyword to select atoms, and the number of weights must match the number of atoms.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread namd/src/colvarproxy_namd.C
Comment thread namd/src/colvarproxy_namd.C
Comment thread namd/src/colvarproxy_namd.h
Comment thread vmd/src/colvarproxy_vmd.C
Comment thread colvartools/gen_multimap.py
Comment thread doc/colvars-refman-main.tex
Comment thread doc/colvars-refman-main.tex Outdated
Comment thread doc/colvars-refman-main.tex Outdated
giacomofiorin and others added 4 commits September 1, 2026 17:35
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@giacomofiorin
giacomofiorin merged commit 5900934 into master Sep 5, 2026
18 checks passed
@giacomofiorin
giacomofiorin deleted the internalize-gridforces branch September 5, 2026 17:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants