Skip to content

Secondary structure - #1644

Open
carlocamilloni wants to merge 4 commits into
masterfrom
secondary-structure
Open

carlocamilloni wants to merge 4 commits into
masterfrom
secondary-structure

Conversation

@carlocamilloni

Copy link
Copy Markdown
Member

Summary

[ALPHARMSD], [ANTIBETARMSD] and [PARABETARMSD] now compute the number of segments that are similar to a helix or a sheet with
a single action, on the CPU and (with USEGPU) on the GPU, instead of the chain of vector actions created by the shortcuts.
For large systems this is up to 16 times faster on 32 CPU cores and about 85 times faster on the GPU than master.
ANTIBETARMSD and PARABETARMSD also get new defaults: STRANDS_CUTOFF=1 (nm), and a D_MAX for the default switching function
(also for ALPHARMSD). These defaults change the results of inputs that do not set these keywords; how to get the previous
behaviour is explained below.

The branch is based on master. The GPU actions (*_SCALAR_ACC in the openaccPTM plugin) use only the device utilities that are already
on master and do not depend on the task manager, so this PR is independent of the openaccPTM-multigpu PR.

Secondary structure

Single actions

  • New actions ALPHARMSD_SCALAR, ANTIBETARMSD_SCALAR, PARABETARMSD_SCALAR (src/secondarystructure/SecondaryStructureCount.h/.cpp).
    They build the segments from the lengths of the chains (for the sheets, as pairs of strands, with the same rules as the shortcuts),
    compute the distance of each segment from the references, the lowest one (PARABETARMSD) and the switching function, and add the
    derivatives to the atoms in the same pass: there is no backward pass and no vector with an element per segment.
    With two references the derivatives are computed only for the lowest one, and only when the switching function is not constant.
  • The shortcuts still create the vectors of the expanded input with the same labels (label_rmsd, label_lt, label_cut, ...).
    They are computed only if another action uses them (e.g. a PRINT of the vector with LESS_THAN, or LOWEST); the value of the shortcut,
    or its lessthan component, comes from the single action. The results are the same as the sum of the vectors (checked in the
    regtests rt-alpha-scalar and rt-sheet-scalar, which print both).
  • With USEGPU and TYPE=DRMSD, the same calculation runs on the GPU (*_SCALAR_ACC in the openaccPTM plugin), with the same
    per-segment code (shared functions in SecondaryStructureCount.h). With USEGPU and the RMSD types the vectors are used, as before.
  • OpenMP with per-thread buffers cleared and summed in parallel; MPI splits the segments between the ranks.

New defaults (results change)

  • ANTIBETARMSD and PARABETARMSD use STRANDS_CUTOFF=1 (nm) by default: the segments whose strands (CA atoms of the central residues)
    are further apart do not contribute. The value is converted to the units of UNITS.
  • The default switching function (given by R_0, NN, MM, D_0) of the three variables has a D_MAX, where it is 1e-5
    (1.42 nm with the defaults), and is stretched to be zero there, as SwitchingFunction::set(nn,mm,r0,d0) does for the other actions
    that take these keywords. Each segment within the cutoff changes by at most 1e-5.
  • How large the change is: on the amyloid of rt33 (18 peptides) the number of antiparallel segments changes by about 1.2 (out of
    5-58) because of the cutoff; with 144 peptides by about 10 (out of 40-460). ALPHARMSD changes by about 1e-4.
  • The value of D_MAX is in the expanded input (SWITCH of the _lt and _SCALAR actions) and in the log of the _SCALAR action.

How to get the previous behaviour

v2.10 / master input equivalent input with this PR
b: ANTIBETARMSD RESIDUES=all (all pairs, function without D_MAX), using b b: ANTIBETARMSD RESIDUES=all STRANDS_CUTOFF=0 LESS_THAN={RATIONAL R_0=0.08 NN=8 MM=12}, using b.lessthan
b: ANTIBETARMSD RESIDUES=all STRANDS_CUTOFF=1 R_0=0.1 b: ANTIBETARMSD RESIDUES=all LESS_THAN={RATIONAL R_0=0.1 NN=8 MM=12}, using b.lessthan
a: ALPHARMSD RESIDUES=all R_0=0.1 a: ALPHARMSD RESIDUES=all LESS_THAN={RATIONAL R_0=0.1 NN=8 MM=12}, using a.lessthan
  • STRANDS_CUTOFF=0 uses all the pairs of strands.
  • Giving the switching function with LESS_THAN (with the R_0, D_0, NN, MM used before) gives the function without D_MAX;
    with LESS_THAN the number of segments is the lessthan component (the value of the action is then the vector of the distances).
    R_0 in LESS_THAN is in the length units of UNITS (0.8 with UNITS LENGTH=A).
  • This is listed in CHANGES ("Changes that can change your results") and in the migration guide (developer-doc/Migration211.md).
  • Checked against the build before the change of defaults with explicit STRANDS_CUTOFF=1 and LESS_THAN={... D_MAX=...}:
    identical values and forces, for the sheets and the helix.

Exact skipping of the distant pairs

When the switching function is zero beyond a finite distance (the new default, or D_MAX in LESS_THAN), the single action also
skips the pairs of strands that are so far apart that their segment certainly has a distance from every reference larger than
D_MAX. The bound uses the distance between the central CA atoms and the radii of the two strands (DRMSD: the distances between
the strands in the reference; RMSD: the radii of gyration). The result does not change (equal, to the last digit, to the sum of
the vectors, which compute every pair), and STRANDS_CUTOFF=0 becomes cheap: ANTIBETARMSD on 144 peptides (370800 pairs) takes
2.4 ms per step on 32 cores (63 ms on master, with every pair computed).

Documentation

  • New sections "Strands cutoff" and "How the number of segments is computed" in ANTIBETARMSD and PARABETARMSD, and the latter in ALPHARMSD.
  • The stretching and D_MAX are explained in the three shortcuts and in the LESS_THAN and R_0 keywords; the LESS_THAN examples give D_MAX.
  • The plugin README has a "Secondary structure" section with the GPU timings.

Performance with respect to master

Leonardo Booster node (32-core Intel Xeon + one A100), nvc++ 24.5, plumed benchmark with a RESTRAINT on the variables (so the forces
are computed), average time per step in ms without the slowest step. GPU runs use 8 CPU threads. Systems: the amyloid of
regtest/secondarystructure/rt33 (18 peptides of 8 residues, 2520 atoms: amy1) and the same replicated 2x2x2 (144 peptides, 20160 atoms: amy2).

  • alpha: ALPHARMSD (54 / 432 segments);
  • ss: ALPHARMSD + ANTIBETARMSD + PARABETARMSD with STRANDS_CUTOFF=1, DRMSD (about 5500 / 370800 pairs of strands for each sheet);
  • nocut: ANTIBETARMSD with all the pairs (master: no STRANDS_CUTOFF; this PR: STRANDS_CUTOFF=0).
case master CPU 8 thr PR CPU 8 thr master CPU 32 thr PR CPU 32 thr master GPU PR GPU
alpha-amy1 0.09 0.06 0.09 0.06 0.75 0.29
alpha-amy2 0.61 0.43 0.95 0.51 1.05 0.50
ss-amy1 2.31 0.84 1.98 0.48 4.58 1.13
ss-amy2 117.6 12.5 100.0 6.1 152 1.80
nocut-amy1 3.20 0.31 1.05 0.17 1.26 0.34
nocut-amy2 213.9 4.9 63.4 2.4 48.2 0.58
  • ss-amy2: 16 times faster on 32 cores, 9 times on 8 cores, 85 times on the GPU. On master the GPU was slower than the CPU for all the
    cases but nocut-amy2; now it is 3.4 times faster than 32 cores (7 times faster than 8 cores) on the large system.
  • On master the time of ss-amy2 on the CPU was dominated by the vectors of STRANDS_CUTOFF over the 370800 pairs (about 85 ms) and did not
    scale with the threads.
  • For a single protein (ss-amy1, alpha) the CPU remains faster than the GPU: the GPU time is the cost of starting the kernels and of the
    transfers (about 0.3 ms per step for ALPHARMSD).
  • The nocut rows compare the same calculation of all the pairs, but this PR uses the function with D_MAX (needed for the skipping).
  • The master columns were measured with master plus a change that also passed USEGPU to the DISTANCE and LESS_THAN of the shortcuts
    (not part of this PR; it gave no measurable difference on the GPU and does not touch the CPU path). The PR columns were measured with
    this work on top of openaccPTM-multigpu; the *_SCALAR_ACC kernels do not use its task manager.
  • One CPU core (cloud VM): ALPHARMSD 0.32 -> 0.18 ms (54 segments) and 2.35 -> 1.42 ms (432 segments); ss-amy2 298 -> 35 ms.

Validation

  • Single actions equal to the sum of the vectors of the expanded input (values to 1e-10, forces within 1e-9), for DRMSD,
    OPTIMAL and OPTIMAL-FAST, with and without NOPBC, STYLE all/inter/intra, LESS_THAN, one and two references; --debug-forces;
    MPI (rt33-mpi, and 2 ranks on the GPU); 1 to 4 threads, also with fewer OpenMP threads than requested and without OpenMP (CI).
  • GPU: plugin regtests on Leonardo (nvc++), including the new rt-GPU-sheet-scalar (references from the CPU); compute-sanitizer
    memcheck and racecheck clean.
  • New regtests: secondarystructure/rt-alpha-scalar, secondarystructure/rt-sheet-scalar, targetGPU/rt-GPU-sheet-scalar.
    The references of the regtests that use the defaults were updated; only the columns of the three variables change.

Related

The openaccPTM-multigpu PR also keeps the data of the actions of the task manager on the GPU between the steps instead of copying it
at every call. That speeds up the vector chain of these shortcuts on the GPU (ss-amy2 152 -> 118 ms) and the other GPU actions with large
inputs, but it is not needed by this PR. The two PRs merge without conflicts, in either order.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_016vwxtV46v5FLckcMEcJrbt

…ngle actions, on the CPU and on the GPU

ALPHARMSD, ANTIBETARMSD and PARABETARMSD compute the number of segments
that are similar to a helix or a sheet with ALPHARMSD_SCALAR,
ANTIBETARMSD_SCALAR and PARABETARMSD_SCALAR (SecondaryStructureCount),
instead of the sum of the chain of vector actions. The segments are built
from the lengths of the chains (for the sheets as pairs of strands, with the
rules of the shortcuts, see getSheetPairs), the pairs further apart than
STRANDS_CUTOFF cost one distance, and the derivatives are added to the atoms
while the segments are computed: there is no backward pass and no vector
with an element per segment. With two references the derivatives are
computed only for the lowest one and only when the switching function is
not constant. OpenMP with per-thread buffers, MPI split of the segments.

The shortcuts keep the vectors of the expanded input with the same labels:
they are computed only when another action uses them. The results are the
same as the sums of the vectors (regtests rt-sheet-scalar, rt-alpha-scalar).

With USEGPU and TYPE=DRMSD the openaccPTM plugin computes the same with
*_SCALAR_ACC: a kernel lists the pairs within STRANDS_CUTOFF, one GPU thread
per segment computes it with the same functions as the CPU
(SecondaryStructureCount.h) and adds the derivatives with atomics, a last
kernel sums the values and the virial (regtest rt-GPU-sheet-scalar). With
USEGPU and the RMSD types the vectors are used as before.

144 peptides, the three variables: 298 -> 41 ms per step on one core,
100 -> 7.8 ms on 32 cores, 152 -> 2.3 ms on one A100.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016vwxtV46v5FLckcMEcJrbt
…pairs whose switching function is zero

Behaviour change, listed in CHANGES and in the migration guide:
- ANTIBETARMSD and PARABETARMSD use STRANDS_CUTOFF=1 (nm, converted with
  UNITS) by default; STRANDS_CUTOFF=0 uses all the pairs of strands.
- With R_0, NN, MM and D_0 (no LESS_THAN) the switching function of
  ALPHARMSD, ANTIBETARMSD and PARABETARMSD gets the D_MAX that
  SwitchingFunction::set(nn,mm,r0,d0) uses for the other actions (where the
  function is 1e-5) and is stretched to zero there. LESS_THAN={RATIONAL
  R_0=0.08 NN=8 MM=12} gives the previous function (the number of segments
  is then the lessthan component).
Checked against the previous build with explicit STRANDS_CUTOFF=1 and
LESS_THAN={... D_MAX=...}: identical values and forces.

When the switching function is zero beyond a finite distance, the single
action (CPU and GPU) also skips the pairs of strands whose central CA atoms
are further apart than a distance computed from the references plus the
radii of the two strands: a lower bound of the distance of the segment from
every reference is then above D_MAX (DRMSD: the distances between the
strands; RMSD: the radii of gyration). The result does not change (equal to
the sum of the vectors, which compute every pair): ANTIBETARMSD with
STRANDS_CUTOFF=0 on 144 peptides 930 -> 160 ms per step on one core.
D_MAX is written in the log of the single action.

Documentation: "Strands cutoff" section, D_MAX in the LESS_THAN examples and
in the keywords. Regtest references updated (only the columns of the three
variables change); rt-sheet-scalar and rt-GPU-sheet-scalar have pairs with
STRANDS_CUTOFF=0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016vwxtV46v5FLckcMEcJrbt
…parallel

The derivative buffers of the nt threads (3 natoms+9 each) were cleared
and summed by one thread, so that 32 threads were slower than 8 for
ALPHARMSD on 432 segments (0.91 vs 0.47 ms). The buffers are now cleared
with a loop over the nt buffers and summed with a loop over the
derivatives, both shared between the threads (correct also when fewer than
nt threads run, same order of the sums), and the radii of the strands are
computed in the same parallel region: 0.51 ms on 32 threads; the three
variables on 144 peptides 7.5 -> 6.1 ms. Timings in CHANGES and README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016vwxtV46v5FLckcMEcJrbt
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.29429% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.98%. Comparing base (422109d) to head (2dcd4e8).

Files with missing lines Patch % Lines
src/secondarystructure/SecondaryStructureBase.h 84.21% 9 Missing ⚠️
src/secondarystructure/SecondaryStructureCount.cpp 95.20% 7 Missing ⚠️
src/secondarystructure/AlphaRMSD.cpp 92.30% 1 Missing ⚠️
src/secondarystructure/AntibetaRMSD.cpp 96.29% 1 Missing ⚠️
src/secondarystructure/ParabetaRMSD.cpp 96.29% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1644      +/-   ##
==========================================
+ Coverage   88.96%   88.98%   +0.01%     
==========================================
  Files         652      655       +3     
  Lines       81934    82131     +197     
==========================================
+ Hits        72890    73081     +191     
- Misses       9044     9050       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

…CUTOFF=0

They were measured with the default STRANDS_CUTOFF (1 nm): the inputs of
the benchmark did not set STRANDS_CUTOFF=0. With STRANDS_CUTOFF=0 the exact
skipping of the pairs whose switching function is zero leaves about 10
times more segments than the cutoff: ANTIBETARMSD on 144 peptides takes
160 ms per step on one core, 13 ms with the default cutoff.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016vwxtV46v5FLckcMEcJrbt

This branch has not been deployed

No deployments
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.

2 participants