@@ -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 ,
0 commit comments