Skip to content

feat: canonical identity-switch move - #74

Merged
dubbelda merged 1 commit into
iRASPA:mainfrom
ssharlin:feat/identity-switch-move
Aug 26, 2026
Merged

dubbelda merged 1 commit into
iRASPA:mainfrom
ssharlin:feat/identity-switch-move

Conversation

@ssharlin

Copy link
Copy Markdown
Contributor

Adds Move::Types::IdentitySwitchCBMC: a single-box, composition-conserving pair exchange. One
molecule of component A and one of component B swap identities in place.

It complements IdentityChangeCBMC (which converts a single molecule against an imposed fugacity
ratio). Because a pair is exchanged, N of every component is conserved, and no fugacities are needed:

acc = (W_grow_A * W_grow_B) / (W_retrace_A * W_retrace_B) * exp(-beta * (dU_Ewald + dU_pol + dU_pair))

It changes no equilibrium average; it exists to decorrelate dense mixtures where whole-molecule
insertion/deletion is inefficient.

Input: IdentitySwitches: [partner ids], IdentitySwitchProbability.

Notes for review:

  • During growth, both old molecules must be ignored, but the CBMC helper takes only one molecule
    id to skip. So the partner is briefly given the same id (and restored right after) so one skip
    covers both; the A–B interaction that this hides is added back explicitly as dU_pair.
  • The two-molecule Ewald difference relies on the per-moleculeId exclusion fix in fix: match Ewald exclusion pairs on moleculeId instead of per span #73 (merged);
    this branch is based on it.
  • Adding identitySwitches bumps the Component restart-file version to 2, read behind a
    versionNumber >= 2 guard, so older restart files still load.

Tests (tests/raspa3-tests/mc_identity_switch_drift.cpp):

  • identical_components_are_always_accepted — identical-type components ⇒ acceptance exactly 1,
    composition frozen.
  • charged_multisite_components_energy_drift — CO2 ↔ water with Ewald ⇒ zero drift incl.
    ewald_exclusion.

Single-box, composition-conserving pair exchange: one molecule of component A
and one of component B swap identities in place. Complements the semi-grand
IdentityChangeCBMC; conserves N of every component and needs no fugacities.

Input keys: IdentitySwitches, IdentitySwitchProbability.
Tests: tests/raspa3-tests/mc_identity_switch_drift.cpp
@ssharlin ssharlin changed the title feat: canonical identity-switch move (MCCCS-MN swatch) feat: canonical identity-switch move Aug 25, 2026
@ssharlin

Copy link
Copy Markdown
Contributor Author

The three red checks are all pre-existing CI issues that fail on main as well:

  • test-cpp: the configure step fails with "cmakeMinimumRequired" major version 4 must be less than 3. The runner's apt cmake (3.28 on ubuntu-24.04) is older than the cmake 4.3 that
    CMakePresets.json / CMakeLists.txt require, so it errors before compiling anything.
  • python-formatting: would reformat raspa/raspalib/atom.pyi; this PR doesn't touch this file.
  • cpp-formatting: flags ~480 files across the repo (foundationkit, mathkit, structurekit, most
    of mc_moves, …), i.e., it's failing repo-wide under the CI's clang-format. The two files this PR
    adds (identity_switch.{cpp,ixx}, mc_identity_switch_drift.cpp) are not flagged.

I verified locally with cmake 4.3 + clang: clean build, unit_tests_raspakit 379/379, and the two
new MC_IDENTITY_SWITCH_DRIFT tests pass.

@dubbelda
dubbelda merged commit 1088d17 into iRASPA:main Aug 26, 2026
0 of 3 checks passed
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