Skip to content

Commit 62f638a

Browse files
authored
Merge pull request #489 from CCPBioSim/426-axis-argument
Change customised_axes arg to str axes arg
2 parents c455df8 + 36a4380 commit 62f638a

79 files changed

Lines changed: 589 additions & 418 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CodeEntropy/config/argparse.py‎

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,18 @@ class ArgSpec:
151151
default=True,
152152
help="Use combined force-torque matrix for residue-level vibrational entropies",
153153
),
154-
"customised_axes": ArgSpec(
155-
type=bool,
156-
default=True,
157-
help="Use bonded axes to rotate forces for united-atom vibrational entropies",
154+
"axes": ArgSpec(
155+
type=str,
156+
default="local",
157+
help="Axes to be used for residue and UA level rotations. If set to principal, "
158+
"principal axes of residue are used for residue rotation and UA translation "
159+
"and principal axes of UA are used for UA rotation. If set to topology, "
160+
"axes are determined using the cached topology indices rather than repeating "
161+
"MDAnalysis selections each frame. Residue level rotation and UA translation "
162+
"use principal axes of the residue. UA rotation uses bond-derived axes. If set "
163+
"to local, local level-specific custom axes are used. Residue rotation and UA "
164+
"translation use local internal coordinate-derived axes. "
165+
"UA rotation uses bond-derived axes.",
158166
),
159167
"search_type": ArgSpec(
160168
type=str,
@@ -506,6 +514,18 @@ def validate_inputs(self, u: Any, args: argparse.Namespace) -> None:
506514
self._check_input_temperature(args)
507515
self._check_input_force_partitioning(args)
508516
self._check_parallel_frame_options(args)
517+
self._check_input_axes(args)
518+
519+
@staticmethod
520+
def _check_input_axes(args: argparse.Namespace) -> None:
521+
"""Check that the axes option is one of the supported values."""
522+
valid = ("principal", "topology", "local")
523+
axes = str(args.axes).strip().lower()
524+
if axes not in valid:
525+
raise ValueError(
526+
f"Invalid 'axes': {args.axes!r}. Must be one of {', '.join(valid)}."
527+
)
528+
args.axes = axes
509529

510530
@staticmethod
511531
def _check_input_start(u: Any, args: argparse.Namespace) -> None:

‎CodeEntropy/levels/nodes/axes_topology.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class BuildAxesTopologyNode:
8282
def run(self, shared_data: dict[str, Any]) -> dict[str, Any]:
8383
"""Build cached axes topology and write it into shared data.
8484
85-
The cache is only populated when ``args.customised_axes`` is true. When
85+
The cache is only populated when ``args.axes`` is equal to ``topology``. When
8686
customised axes are disabled, an empty cache is still written so later
8787
stages can read ``shared_data["axes_topology"]`` safely.
8888
@@ -97,7 +97,7 @@ def run(self, shared_data: dict[str, Any]) -> dict[str, Any]:
9797
args = shared_data["args"]
9898
topology = AxesTopology()
9999

100-
if not bool(getattr(args, "customised_axes", False)):
100+
if args.axes != "topology":
101101
shared_data["axes_topology"] = topology
102102
return {"axes_topology": topology}
103103

‎CodeEntropy/levels/nodes/covariance.py‎

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def run(self, ctx: FrameCtx) -> dict[str, Any]:
8383

8484
fp = float(args.force_partitioning)
8585
combined = bool(getattr(args, "combined_forcetorque", False))
86-
customised_axes = bool(getattr(args, "customised_axes", False))
86+
axes = args.axes
8787

8888
box = self._try_get_box(u)
8989
fragments = u.atoms.fragments
@@ -114,7 +114,7 @@ def run(self, ctx: FrameCtx) -> dict[str, Any]:
114114
axes_topology=axes_topology,
115115
box=box,
116116
force_partitioning=fp,
117-
customised_axes=customised_axes,
117+
axes=axes,
118118
is_highest=("united_atom" == level_list[-1]),
119119
out_force=out_force,
120120
out_torque=out_torque,
@@ -131,7 +131,7 @@ def run(self, ctx: FrameCtx) -> dict[str, Any]:
131131
axes_manager=axes_manager,
132132
axes_topology=axes_topology,
133133
box=box,
134-
customised_axes=customised_axes,
134+
axes=axes,
135135
force_partitioning=fp,
136136
is_highest=("residue" == level_list[-1]),
137137
out_force=out_force,
@@ -178,7 +178,7 @@ def _process_united_atom(
178178
axes_topology: Any | None,
179179
box: np.ndarray | None,
180180
force_partitioning: float,
181-
customised_axes: bool,
181+
axes: str,
182182
is_highest: bool,
183183
out_force: dict[str, dict[Any, Matrix]],
184184
out_torque: dict[str, dict[Any, Matrix]],
@@ -205,7 +205,7 @@ def _process_united_atom(
205205
axes_topology: Optional cached axes topology generated during static setup.
206206
box: Optional periodic box vector.
207207
force_partitioning: Force partitioning factor for highest-level vectors.
208-
customised_axes: Whether customised UA axes should be used.
208+
axes: Which UA axes should be used.
209209
is_highest: Whether united atom is the highest active level.
210210
out_force: Frame-local force second-moment accumulator, mutated in place.
211211
out_torque: Frame-local torque second-moment accumulator, mutated in place.
@@ -237,7 +237,7 @@ def _process_united_atom(
237237

238238
else:
239239
res_position = None
240-
residue_group = res
240+
residue_group = res.atoms
241241
bead_key = (mol_id, "united_atom", local_res_i)
242242
bead_idx_list = beads.get(bead_key, [])
243243
if not bead_idx_list:
@@ -257,7 +257,7 @@ def _process_united_atom(
257257
axes_topology=axes_topology,
258258
box=box,
259259
force_partitioning=force_partitioning,
260-
customised_axes=customised_axes,
260+
axes=axes,
261261
is_highest=is_highest,
262262
res_position=res_position,
263263
)
@@ -281,7 +281,7 @@ def _process_residue(
281281
axes_manager: Any,
282282
axes_topology: Any | None,
283283
box: np.ndarray | None,
284-
customised_axes: bool,
284+
axes: str,
285285
force_partitioning: float,
286286
is_highest: bool,
287287
out_force: dict[str, dict[Any, Matrix]],
@@ -301,7 +301,7 @@ def _process_residue(
301301
axes_manager: Axes helper used to build translation and rotation axes.
302302
axes_topology: Optional cached axes topology generated during static setup.
303303
box: Optional periodic box vector.
304-
customised_axes: Whether customised residue axes should be used.
304+
axes: Which residue axes should be used.
305305
force_partitioning: Force partitioning factor for highest-level vectors.
306306
is_highest: Whether residue is the highest active level.
307307
out_force: Frame-local force second-moment accumulator, mutated in place.
@@ -327,7 +327,7 @@ def _process_residue(
327327
axes_manager=axes_manager,
328328
axes_topology=axes_topology,
329329
box=box,
330-
customised_axes=customised_axes,
330+
axes=axes,
331331
force_partitioning=force_partitioning,
332332
is_highest=is_highest,
333333
)
@@ -447,7 +447,7 @@ def _build_ua_vectors(
447447
axes_topology: Any | None,
448448
box: np.ndarray | None,
449449
force_partitioning: float,
450-
customised_axes: bool,
450+
axes: str,
451451
is_highest: bool,
452452
res_position: int,
453453
) -> tuple[list[np.ndarray], list[np.ndarray]]:
@@ -463,7 +463,7 @@ def _build_ua_vectors(
463463
axes_topology: Optional cached axes topology generated during static setup.
464464
box: Optional periodic box vector.
465465
force_partitioning: Force partitioning factor for highest-level vectors.
466-
customised_axes: Whether customised UA axes should be used.
466+
axes: Which UA axes should be used.
467467
is_highest: Whether UA is the highest active level.
468468
res_position: Where the residue is in the residue group
469469
@@ -472,7 +472,6 @@ def _build_ua_vectors(
472472
"""
473473
force_vecs: list[np.ndarray] = []
474474
torque_vecs: list[np.ndarray] = []
475-
476475
for ua_i, bead in enumerate(bead_groups):
477476
if res_position == -1:
478477
residue = residue_group.residues[0]
@@ -481,10 +480,9 @@ def _build_ua_vectors(
481480
else:
482481
residue = residue_group
483482

484-
if customised_axes:
485-
ua_topology = None
486-
if axes_topology is not None:
487-
ua_topology = axes_topology.ua.get((mol_id, local_res_i, ua_i))
483+
ua_topology = None
484+
if axes == "topology":
485+
ua_topology = axes_topology.ua.get((mol_id, local_res_i, ua_i))
488486
if ua_topology is not None:
489487
trans_axes, rot_axes, center, moi = (
490488
axes_manager.get_UA_axes_from_topology(
@@ -495,21 +493,31 @@ def _build_ua_vectors(
495493
)
496494
)
497495
else:
498-
# we don't use the topology
496+
# custom local axes if no topology
499497
make_whole(residue_group)
500498
make_whole(bead)
501499
trans_axes, rot_axes, center, moi = axes_manager.get_UA_axes(
502500
residue_group, ua_i, res_position
503501
)
502+
elif axes == "local":
503+
# we don't use the topology
504+
make_whole(residue_group)
505+
make_whole(bead)
506+
trans_axes, rot_axes, center, moi = axes_manager.get_UA_axes(
507+
residue_group, ua_i, res_position
508+
)
504509

505-
else:
510+
elif axes == "principal":
506511
# principal axes
507512
make_whole(residue.atoms)
508513
make_whole(bead)
509514
trans_axes = axes_manager.get_principal_axes_from_group(residue.atoms)
510515
rot_axes, moi = axes_manager.get_molecule_axes(bead)
511516
center = bead.center_of_mass(unwrap=True)
512517

518+
else:
519+
raise ValueError(f"Unknown axes option: {axes!r}")
520+
513521
force_vecs.append(
514522
self._ft.get_weighted_forces(
515523
bead=bead,
@@ -542,7 +550,7 @@ def _build_residue_vectors(
542550
axes_manager: Any,
543551
axes_topology: Any | None,
544552
box: np.ndarray | None,
545-
customised_axes: bool,
553+
axes: str,
546554
force_partitioning: float,
547555
is_highest: bool,
548556
) -> tuple[list[np.ndarray], list[np.ndarray]]:
@@ -556,7 +564,7 @@ def _build_residue_vectors(
556564
axes_manager: Axes helper used to select axes, centres, and moments.
557565
axes_topology: Optional cached axes topology generated during static setup.
558566
box: Optional periodic box vector.
559-
customised_axes: Whether customised residue axes should be used.
567+
axes: Which residue axes that should be used.
560568
force_partitioning: Force partitioning factor for highest-level vectors.
561569
is_highest: Whether residue is the highest active level.
562570
@@ -578,7 +586,7 @@ def _build_residue_vectors(
578586
relative_res_i=relative_res_i,
579587
axes_manager=axes_manager,
580588
axes_topology=axes_topology,
581-
customised_axes=customised_axes,
589+
axes=axes,
582590
)
583591

584592
force_vecs.append(
@@ -614,7 +622,7 @@ def _get_residue_axes(
614622
relative_res_i: int,
615623
axes_manager: Any,
616624
axes_topology: Any | None,
617-
customised_axes: bool,
625+
axes: str,
618626
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
619627
"""Return axes, centre, and inertia data for a residue bead.
620628
@@ -628,38 +636,43 @@ def _get_residue_axes(
628636
might differ from residue index of first residue in topology.
629637
axes_manager: Axes helper used to select axes, centres, and moments.
630638
axes_topology: Optional cached axes topology generated during static setup.
631-
customised_axes: Whether customised residue axes should be used.
639+
axes: Which residue axes should be used.
632640
633641
Returns:
634642
A tuple of translation axes, rotation axes, centre, and moments of inertia.
635643
"""
636-
if customised_axes:
644+
if axes == "topology" or axes == "local":
637645
res = mol.residues[local_res_i]
638646
residue_topology = None
639-
if axes_topology is not None:
647+
if axes == "topology" and axes_topology is not None:
648+
# can use the cached axes topology
640649
residue_topology = axes_topology.residue.get((mol_id, local_res_i))
641650

642651
if residue_topology is not None:
643652
return axes_manager.get_residue_axes_from_topology(
644653
u=u, mol=mol, residue_atoms=res.atoms, topology=residue_topology
645654
)
646-
655+
# no topology or local axes argument
647656
return axes_manager.get_residue_axes(
648657
mol, local_res_i, relative_res_i, residue=res.atoms
649658
)
650659

660+
if axes != "principal":
661+
raise ValueError(f"Unknown axes option: {axes!r}")
662+
651663
make_whole(mol.atoms)
652664
make_whole(bead)
653665

654-
trans_axes = axes_manager.get_principal_axes_from_group(mol.atoms)
655-
rot_axes, moi = axes_manager.get_molecule_axes(bead)
656-
center = bead.center_of_mass(unwrap=True)
657-
return (
658-
np.asarray(trans_axes),
659-
np.asarray(rot_axes),
660-
np.asarray(center),
661-
np.asarray(moi),
662-
)
666+
if axes == "principal":
667+
trans_axes = axes_manager.get_principal_axes_from_group(mol.atoms)
668+
rot_axes, moi = axes_manager.get_molecule_axes(bead)
669+
center = bead.center_of_mass(unwrap=True)
670+
return (
671+
np.asarray(trans_axes),
672+
np.asarray(rot_axes),
673+
np.asarray(center),
674+
np.asarray(moi),
675+
)
663676

664677
def _get_polymer_axes(
665678
self,

‎docs/source/getting_started.rst‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,14 @@ The ``top_traj_file`` argument is required; other arguments have default values.
212212
2019 paper.
213213
- ``True``
214214
- ``bool``
215-
* - ``--customised_axes``
216-
- Use custom bonded axes to get COM, MOI and PA that match the 2019 paper.
217-
- ``True``
218-
- ``bool``
215+
* - ``--axes``
216+
- Axes used for residue and united-atom rotations. One of ``principal``
217+
(principal axes of the residue/UA), ``topology`` (bonded axes using cached
218+
topology indices, matching the 2019 paper) or ``local`` (local internal
219+
coordinate-derived axes for residues and UA translation, bonded axes for UA
220+
rotation).
221+
- ``local``
222+
- ``str``
219223
* - ``--search_type``
220224
- Method for finding neighbouring molecules.
221225
- ``RAD``

‎tests/regression/baselines/benzaldehyde/axes_off.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"groups": {
33
"0": {
44
"components": {
5-
"united_atom:Transvibrational": 0.06950663196232491,
6-
"united_atom:Rovibrational": 35.19655714759134,
7-
"residue:FTmat-Transvibrational": 86.64136384477892,
8-
"residue:FTmat-Rovibrational": 62.24303760058521,
5+
"united_atom:Transvibrational": 0.06950663196232494,
6+
"united_atom:Rovibrational": 35.19655714759137,
7+
"residue:FTmat-Transvibrational": 86.64136384477902,
8+
"residue:FTmat-Rovibrational": 62.24303760058522,
99
"united_atom:Conformational": 0.0,
1010
"residue:Conformational": 0.0,
1111
"residue:Orientational": 20.481571492615355
1212
},
13-
"total": 204.63203671753317
13+
"total": 204.63203671753328
1414
}
1515
}
1616
}

‎tests/regression/baselines/benzaldehyde/combined_forcetorque_false.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"groups": {
33
"0": {
44
"components": {
5-
"united_atom:Transvibrational": 0.06817494136874551,
6-
"united_atom:Rovibrational": 49.686697381523466,
7-
"residue:Transvibrational": 69.24977659775257,
5+
"united_atom:Transvibrational": 0.06950663196232494,
6+
"united_atom:Rovibrational": 49.686697381523565,
7+
"residue:Transvibrational": 69.24977659775254,
88
"residue:Rovibrational": 69.73922011617867,
99
"united_atom:Conformational": 0.0,
1010
"residue:Conformational": 0.0,
1111
"residue:Orientational": 20.481571492615355
1212
},
13-
"total": 209.22544052943883
13+
"total": 209.22677222003247
1414
}
1515
}
1616
}

‎tests/regression/baselines/benzaldehyde/default.json‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
"groups": {
33
"0": {
44
"components": {
5-
"united_atom:Transvibrational": 24.921822103314035,
6-
"united_atom:Rovibrational": 27.950376507672594,
7-
"residue:FTmat-Transvibrational": 71.231562004914,
5+
"united_atom:Transvibrational": 24.94016991205995,
6+
"united_atom:Rovibrational": 27.950376507672583,
7+
"residue:FTmat-Transvibrational": 71.23156200491398,
88
"residue:FTmat-Rovibrational": 60.43602521189648,
99
"united_atom:Conformational": 7.522643899702263,
1010
"residue:Conformational": 0.0,
1111
"residue:Orientational": 59.43920971558428
1212
},
13-
"total": 251.50163944308366
13+
"total": 251.51998725182955
1414
}
1515
}
1616
}

0 commit comments

Comments
 (0)