kups.mcmc.moves
¶
Monte Carlo moves for molecular simulations.
This module provides Monte Carlo move proposals for grand canonical (GCMC) and canonical (NVT) ensemble simulations. Moves include particle translations, rotations, molecular insertions/deletions, and grand canonical exchange moves.
Key Components:
- MonteCarloMove: Base class for MC move proposals
- ParticleTranslationMove: Single particle displacement
- GroupTranslationMove: Rigid body translation of molecular groups
- GroupRotationMove: Rigid body rotation of molecular groups
- ReinsertionMove: Random reinsertion with rotation
- ExchangeMove: GCMC insertion/deletion of molecules All moves operate on indexed particle data and support batched parallel systems. Moves generate proposals compatible with MCMCPropagator.
BatchedPositions = Table[ParticleId, HasPositionsGroupSystem]
¶
Type alias for particle positions with group and system indexing.
ExchangeChanges
¶
Combined particle and group changes for a GCMC exchange move.
Each field pairs an Index of target slot ids with a Buffered
holding the new data and an occupation mask. For insertions the
occupation is True (slots become occupied); for deletions it is
False (slots are freed).
Attributes:
| Name | Type | Description |
|---|---|---|
particles |
WithIndices[ParticleId, Buffered[ParticleId, ExchangeParticleData]]
|
Target particle slots and buffered particle data. |
groups |
WithIndices[GroupId, Buffered[GroupId, ExchangeGroupData]]
|
Target group slots and buffered group data. |
Source code in src/kups/mcmc/moves.py
ExchangeGroupData
¶
ExchangeMove
¶
Bases: MonteCarloMove[State, ExchangeChanges]
Grand canonical Monte Carlo (GCMC) insertion/deletion move. Satisfies ChangesFn.
Randomly proposes either insertion or deletion of a molecular group
with 50% probability each via propose_mixed.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
View[State, Buffered[ParticleId, HasPositionsGroupSystem]]
|
Lens to buffered particle positions. |
groups |
View[State, Buffered[GroupId, HasMotifAndSystemIndex]]
|
Lens to buffered molecular groups. |
motifs |
View[State, Table[MotifParticleId, IsMotifData]]
|
Lens to molecular templates available for insertion. |
unitcell |
View[State, Table[SystemId, UnitCell]]
|
Lens to unit cell parameters. |
capacity |
View[State, Capacity[int]]
|
Lens to capacity constraints. |
Source code in src/kups/mcmc/moves.py
ExchangeParticleData
¶
Per-particle payload for GCMC exchange moves (no identity info).
The motif field indexes into the motif template
(Indexed[MotifParticleId, MotifParticles]) so the patch function
can look up masses, charges, labels, etc.
Attributes:
| Name | Type | Description |
|---|---|---|
new_positions |
Array
|
Proposed coordinates, shape |
group |
Index[GroupId]
|
Group assignment for each particle. |
system |
Index[SystemId]
|
System assignment for each particle. |
motif |
Index[MotifParticleId]
|
Motif-template index for each particle. |
Source code in src/kups/mcmc/moves.py
GroupRotationMove
¶
Bases: MonteCarloMove[State, ParticlePositionChanges]
Rigid body rotation of molecular groups. Satisfies ChangesFn.
Attributes:
| Name | Type | Description |
|---|---|---|
particles |
View[State, BatchedPositions]
|
Lens to particle positions. |
groups |
View[State, Table[GroupId, HasSystemIndex]]
|
Lens to groups eligible for moves. |
systems |
View[State, Table[SystemId, HasUnitCell]]
|
Lens to indexed systems with unit cell data. |
step_width |
View[State, Table[SystemId, Array]]
|
Lens to rotation magnitude (0=no rotation, 1=full). |
capacity |
View[State, Capacity[int]]
|
Lens to capacity constraints. |
Source code in src/kups/mcmc/moves.py
GroupTranslationMove
¶
Bases: MonteCarloMove[State, ParticlePositionChanges]
Rigid body translation of molecular groups. Satisfies ChangesFn.
Attributes:
| Name | Type | Description |
|---|---|---|
particles |
View[State, BatchedPositions]
|
Lens to particle positions. |
groups |
View[State, Table[GroupId, HasSystemIndex]]
|
Lens to groups eligible for moves. |
systems |
View[State, Table[SystemId, HasUnitCell]]
|
Lens to indexed systems with unit cells. |
step_width |
View[State, Table[SystemId, Array]]
|
Lens to maximum translation magnitude. |
capacity |
View[State, Capacity[int]]
|
Lens to capacity constraints. |
distribution |
SymmetricTranslationDistribution
|
Symmetric distribution for displacements (default: normal). |
Source code in src/kups/mcmc/moves.py
HasGroupSystemIndex
¶
Bases: HasGroupIndex, HasSystemIndex, Protocol
Combined group and system index for particles.
Source code in src/kups/mcmc/moves.py
HasPositionsGroupSystem
¶
Bases: HasPositions, HasGroupIndex, HasSystemIndex, Protocol
Combined positions, group and system index for particles.
Source code in src/kups/mcmc/moves.py
IsDisplacementState
¶
Bases: IsTranslationState, IsRotationState, IsReinsertionState, Protocol
State protocol for the combined translation/rotation/reinsertion move.
Source code in src/kups/mcmc/moves.py
IsExchangeState
¶
Bases: IsMCMCMoveState, Protocol
State protocol for particle exchange (grand canonical) MCMC moves.
Source code in src/kups/mcmc/moves.py
IsGCMCState
¶
Bases: IsDisplacementState, Protocol
State protocol for the combined displacement + exchange move.
Source code in src/kups/mcmc/moves.py
IsMCMCMoveState
¶
Bases: Protocol
Base state protocol for MCMC moves with particles, groups, systems, and capacity.
Source code in src/kups/mcmc/moves.py
IsMotifData
¶
Bases: Protocol
Motif template data: positions indexed by motif assignment.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
Array
|
Template particle positions, shape |
motif |
Index[MotifId]
|
Per-particle motif assignment. |
Source code in src/kups/mcmc/moves.py
IsReinsertionState
¶
Bases: IsMCMCMoveState, Protocol
State protocol for particle reinsertion MCMC moves.
Source code in src/kups/mcmc/moves.py
IsRotationState
¶
Bases: IsMCMCMoveState, Protocol
State protocol for group rotation MCMC moves.
Source code in src/kups/mcmc/moves.py
IsTranslationState
¶
Bases: IsMCMCMoveState, Protocol
State protocol for group translation MCMC moves.
Source code in src/kups/mcmc/moves.py
MonteCarloMove
¶
Bases: ChangesFn[State, Changes], ABC
Base class for Monte Carlo move proposals that satisfy ChangesFn.
Source code in src/kups/mcmc/moves.py
ParticlePositionChanges
¶
Description of particle position updates.
Attributes:
| Name | Type | Description |
|---|---|---|
particle_ids |
Index[ParticleId]
|
Indices of particles to update |
new_positions |
Array
|
New position coordinates for specified particles |
Source code in src/kups/mcmc/moves.py
ParticleTranslationMove
¶
Bases: MonteCarloMove[State, ParticlePositionChanges]
Single particle translation move. Satisfies ChangesFn.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
View[State, BatchedPositions]
|
Lens to particle positions in state. |
systems |
View[State, Table[SystemId, HasUnitCell]]
|
Lens to indexed systems with unit cells. |
step_width |
View[State, Table[SystemId, Array]]
|
Lens to maximum displacement magnitude (tunable). |
distribution |
SymmetricTranslationDistribution
|
Symmetric distribution for displacements (default: normal). |
Source code in src/kups/mcmc/moves.py
ReinsertionMove
¶
Bases: MonteCarloMove[State, ParticlePositionChanges]
Random reinsertion of molecular groups. Satisfies ChangesFn.
Attributes:
| Name | Type | Description |
|---|---|---|
positions |
View[State, BatchedPositions]
|
Lens to particle positions. |
groups |
View[State, Table[GroupId, HasSystemIndex]]
|
Lens to groups eligible for moves. |
systems |
View[State, Table[SystemId, HasUnitCell]]
|
Lens to indexed systems with unit cell data. |
capacity |
View[State, Capacity[int]]
|
Lens to capacity constraints. |
Source code in src/kups/mcmc/moves.py
SymmetricTranslationDistribution
¶
Bases: Protocol
Protocol for symmetric translation distributions.
Source code in src/kups/mcmc/moves.py
SystemIndex
¶
delete_random_motif(key, motifs, particles, groups, capacity)
¶
Generate a GCMC deletion move removing a random molecular group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
JAX PRNG key. |
required |
motifs
|
Table[MotifParticleId, IsMotifData]
|
Indexed molecular templates (for metadata consistency). |
required |
particles
|
Buffered[ParticleId, HasPositionsGroupSystem]
|
Current buffered particle positions. |
required |
groups
|
Buffered[GroupId, HasMotifAndSystemIndex]
|
Current buffered group metadata. |
required |
capacity
|
Capacity[int]
|
Capacity constraints for state arrays. |
required |
Returns:
| Type | Description |
|---|---|
ExchangeChanges
|
Exchange changes describing the deletion. |
Source code in src/kups/mcmc/moves.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | |
exchange_changes_from_position_changes(changes, particles, groups, n_sys)
¶
Convert a ParticlePositionChanges into ExchangeChanges.
Produces the same shape as insert_random_motif / delete_random_motif
(one group entry per system) so that jax.lax.select_n can mix them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
changes
|
ParticlePositionChanges
|
Proposed particle position changes. |
required |
particles
|
Buffered[ParticleId, IsExchangeParticles]
|
Current buffered particle positions. |
required |
groups
|
Buffered[GroupId, HasMotifAndSystemIndex]
|
Current buffered group metadata. |
required |
n_sys
|
int
|
Number of systems (determines group output size). |
required |
Source code in src/kups/mcmc/moves.py
insert_random_motif(key, motifs, particles, groups, unitcell, capacity)
¶
Generate a GCMC insertion move for random molecular motifs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
JAX PRNG key. |
required |
motifs
|
Table[MotifParticleId, IsMotifData]
|
Indexed molecular templates for insertion. |
required |
particles
|
Buffered[ParticleId, HasPositionsGroupSystem]
|
Current buffered particle positions. |
required |
groups
|
Buffered[GroupId, HasMotifAndSystemIndex]
|
Current buffered group metadata. |
required |
unitcell
|
Table[SystemId, UnitCell]
|
Per-system unit cell parameters. |
required |
capacity
|
Capacity[int]
|
Capacity constraints for state arrays. |
required |
Returns:
| Type | Description |
|---|---|
ExchangeChanges
|
Exchange changes describing the insertion. |
Source code in src/kups/mcmc/moves.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 | |
make_displacement_mcmc_propagator(state, patch_fn, probability_fn, *, translation_weight=1.0, rotation_weight=1.0, reinsertion_weight=1.0)
¶
Build an MCMC propagator that randomly picks translation, rotation, or reinsertion.
Only the scheduler corresponding to the selected move is updated each step.
Source code in src/kups/mcmc/moves.py
983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 | |
make_exchange_mcmc_propagator(state, patch_fn, probability_fn)
¶
Build an MCMC propagator for grand-canonical insertion/deletion moves.
Source code in src/kups/mcmc/moves.py
make_gcmc_mcmc_propagator(state, patch_fn, probability_fn, *, translation_weight=1.0, rotation_weight=1.0, reinsertion_weight=1.0, exchange_weight=3.0)
¶
Build an MCMC propagator combining displacement and exchange moves.
Randomly picks translation, rotation, reinsertion, or exchange (insert/delete)
at each step. Displacement proposals are lifted to ExchangeChanges via
exchange_changes_from_position_changes so all four branches share the
same Changes type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
Lens[State, IsGCMCState]
|
Lens into the sub-state satisfying |
required |
patch_fn
|
PatchFn[State, ExchangeChanges, Move]
|
Converts exchange changes to a state patch. |
required |
probability_fn
|
LogProbabilityRatioFn[State, Move]
|
Log probability ratio for acceptance/rejection. |
required |
translation_weight
|
float
|
Unnormalized selection weight for translation moves. |
1.0
|
rotation_weight
|
float
|
Unnormalized selection weight for rotation moves. |
1.0
|
reinsertion_weight
|
float
|
Unnormalized selection weight for reinsertion moves. |
1.0
|
exchange_weight
|
float
|
Unnormalized selection weight for exchange (insert/delete) moves. |
3.0
|
Returns:
| Type | Description |
|---|---|
Propagator[State]
|
Configured MCMCPropagator with adaptive step-width scheduling for |
Propagator[State]
|
all four move types. |
Source code in src/kups/mcmc/moves.py
1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 | |
make_group_rotation_mcmc_propagator(state, patch_fn, probability_fn)
¶
Build an MCMC propagator for rigid-body group rotation moves.
Source code in src/kups/mcmc/moves.py
make_group_translation_mcmc_propagator(state, patch_fn, probability_fn)
¶
Build an MCMC propagator for random group translation moves.
Source code in src/kups/mcmc/moves.py
make_reinsertion_mcmc_propagator(state, patch_fn, probability_fn)
¶
Build an MCMC propagator for random group reinsertion moves.
Source code in src/kups/mcmc/moves.py
propose_group_rotation(key, particles, groups, systems, step_width, capacity)
¶
Propose a random rigid-body rotation of one group per system.
Source code in src/kups/mcmc/moves.py
propose_group_translation(key, particles, groups, systems, step_width, capacity, distribution=jax.random.normal)
¶
Propose a random rigid-body translation of one group per system.
Source code in src/kups/mcmc/moves.py
propose_particle_translation(key, particles, systems, step_width, distribution=jax.random.normal)
¶
Propose a random single-particle translation (one particle per system).
Source code in src/kups/mcmc/moves.py
propose_reinsertion(key, particles, groups, systems, capacity)
¶
Propose a random reinsertion (new position + rotation) of one group per system.
Source code in src/kups/mcmc/moves.py
random_rotate_groups(key, particles, systems, step_width)
¶
Rotate molecular groups around their centers of mass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
JAX PRNG key. |
required |
particles
|
Table[ParticleId, HasPositionsGroupSystem]
|
Indexed particles with positions, group, and system indices. |
required |
systems
|
Table[SystemId, HasUnitCell]
|
Indexed systems with unit cell data. |
required |
step_width
|
Array
|
Rotation step size (0=no rotation, 1=full random rotation). |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Rotated particle positions with center of mass preserved. |
Source code in src/kups/mcmc/moves.py
random_select_groups(key, groups, particles, capacity)
¶
Randomly select one molecular group per simulation system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Array
|
JAX PRNG key. |
required |
groups
|
Table[GroupId, HasSystemIndex]
|
Indexed groups with system assignment. |
required |
particles
|
Table[ParticleId, HasGroupSystemIndex]
|
Indexed particle data with group and system indices. |
required |
capacity
|
Capacity[int]
|
Capacity constraints for array operations. |
required |
Returns:
| Type | Description |
|---|---|
Index[ParticleId]
|
Index of particle IDs belonging to the selected groups. |
Source code in src/kups/mcmc/moves.py
translate_groups(translations, particles, systems)
¶
Apply rigid body translations to particles with periodic wrapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
translations
|
Table[SystemId, Array]
|
Per-system translation vectors, shape |
required |
particles
|
Table[ParticleId, HasPositionsAndSystemIndex]
|
Indexed particles with positions and system index. |
required |
systems
|
Table[SystemId, HasUnitCell]
|
Indexed systems with unit cell data. |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Translated and wrapped particle positions. |