Skip to content

Commit f45c8cd

Browse files
committed
fix(axes): build topology cache and validate axes option
1 parent 672291e commit f45c8cd

3 files changed

Lines changed: 20 additions & 2 deletions

File tree

‎CodeEntropy/config/argparse.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,18 @@ def validate_inputs(self, u: Any, args: argparse.Namespace) -> None:
514514
self._check_input_temperature(args)
515515
self._check_input_force_partitioning(args)
516516
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
517529

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

‎CodeEntropy/levels/nodes/axes_topology.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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 str(getattr(args, "axes", "topology")):
100+
if args.axes != "topology":
101101
shared_data["axes_topology"] = topology
102102
return {"axes_topology": topology}
103103

‎CodeEntropy/levels/nodes/covariance.py‎

Lines changed: 7 additions & 1 deletion
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-
axes = str(getattr(args, "axes", False))
86+
axes = args.axes
8787

8888
box = self._try_get_box(u)
8989
fragments = u.atoms.fragments
@@ -517,6 +517,9 @@ def _build_ua_vectors(
517517
rot_axes, moi = axes_manager.get_molecule_axes(bead)
518518
center = bead.center_of_mass(unwrap=True)
519519

520+
else:
521+
raise ValueError(f"Unknown axes option: {axes!r}")
522+
520523
force_vecs.append(
521524
self._ft.get_weighted_forces(
522525
bead=bead,
@@ -657,6 +660,9 @@ def _get_residue_axes(
657660
mol, local_res_i, relative_res_i, residue=res.atoms
658661
)
659662

663+
if axes != "principal":
664+
raise ValueError(f"Unknown axes option: {axes!r}")
665+
660666
make_whole(mol.atoms)
661667
make_whole(bead)
662668

0 commit comments

Comments
 (0)