Skip to content

Commit 262933b

Browse files
committed
changed build_ua_vectors and _get_residue_axes to the three axis options
1 parent 097345c commit 262933b

1 file changed

Lines changed: 39 additions & 32 deletions

File tree

‎CodeEntropy/levels/nodes/covariance.py‎

Lines changed: 39 additions & 32 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 = bool(getattr(args, "axes", False))
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: bool,
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: Whether customised 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.
@@ -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: bool,
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: Whether customised 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: Type of axes that 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,7 @@ def _build_ua_vectors(
472472
"""
473473
force_vecs: list[np.ndarray] = []
474474
torque_vecs: list[np.ndarray] = []
475-
475+
print(f"The axes are: {axes}")
476476
for ua_i, bead in enumerate(bead_groups):
477477
if res_position == -1:
478478
residue = residue_group.residues[0]
@@ -481,10 +481,9 @@ def _build_ua_vectors(
481481
else:
482482
residue = residue_group
483483

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))
484+
ua_topology = None
485+
if axes == "topology":
486+
ua_topology = axes_topology.ua.get((mol_id, local_res_i, ua_i))
488487
if ua_topology is not None:
489488
trans_axes, rot_axes, center, moi = (
490489
axes_manager.get_UA_axes_from_topology(
@@ -495,14 +494,22 @@ def _build_ua_vectors(
495494
)
496495
)
497496
else:
498-
# we don't use the topology
497+
# custom local axes if no topology
499498
make_whole(residue_group)
500499
make_whole(bead)
501500
trans_axes, rot_axes, center, moi = axes_manager.get_UA_axes(
502501
residue_group, ua_i, res_position
503502
)
503+
elif axes == "local":
504+
# we don't use the topology
505+
make_whole(residue_group)
506+
make_whole(bead)
507+
trans_axes, rot_axes, center, moi = axes_manager.get_UA_axes(
508+
residue_group, ua_i, res_position
509+
)
504510

505511
else:
512+
print("principal axes? :(")
506513
# principal axes
507514
make_whole(residue.atoms)
508515
make_whole(bead)
@@ -542,7 +549,7 @@ def _build_residue_vectors(
542549
axes_manager: Any,
543550
axes_topology: Any | None,
544551
box: np.ndarray | None,
545-
customised_axes: bool,
552+
axes: str,
546553
force_partitioning: float,
547554
is_highest: bool,
548555
) -> tuple[list[np.ndarray], list[np.ndarray]]:
@@ -556,7 +563,7 @@ def _build_residue_vectors(
556563
axes_manager: Axes helper used to select axes, centres, and moments.
557564
axes_topology: Optional cached axes topology generated during static setup.
558565
box: Optional periodic box vector.
559-
customised_axes: Whether customised residue axes should be used.
566+
axes: Type of axes that should be used
560567
force_partitioning: Force partitioning factor for highest-level vectors.
561568
is_highest: Whether residue is the highest active level.
562569
@@ -579,7 +586,7 @@ def _build_residue_vectors(
579586
axes_manager=axes_manager,
580587
axes_topology=axes_topology,
581588
box=box,
582-
customised_axes=customised_axes,
589+
axes=axes,
583590
)
584591

585592
force_vecs.append(
@@ -616,7 +623,7 @@ def _get_residue_axes(
616623
axes_manager: Any,
617624
axes_topology: Any | None,
618625
box: np.ndarray | None,
619-
customised_axes: bool,
626+
axes: bool,
620627
) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
621628
"""Return axes, centre, and inertia data for a residue bead.
622629
@@ -631,25 +638,25 @@ def _get_residue_axes(
631638
axes_manager: Axes helper used to select axes, centres, and moments.
632639
axes_topology: Optional cached axes topology generated during static setup.
633640
box: Optional periodic box vector.
634-
customised_axes: Whether customised residue axes should be used.
641+
axes: Whether customised residue axes should be used.
635642
636643
Returns:
637644
A tuple of translation axes, rotation axes, centre, and moments of inertia.
638645
"""
639-
if customised_axes:
646+
if axes != "principal":
640647
res = mol.residues[local_res_i]
641648
residue_topology = None
642-
if axes_topology is not None:
649+
if axes == "topology":
643650
residue_topology = axes_topology.residue.get((mol_id, local_res_i))
644651

645-
if residue_topology is not None:
646-
return axes_manager.get_residue_axes_from_topology(
647-
u=u,
648-
mol=mol,
649-
residue_atoms=res.atoms,
650-
topology=residue_topology,
651-
box=box,
652-
)
652+
if residue_topology is not None:
653+
return axes_manager.get_residue_axes_from_topology(
654+
u=u,
655+
mol=mol,
656+
residue_atoms=res.atoms,
657+
topology=residue_topology,
658+
box=box,
659+
)
653660

654661
return axes_manager.get_residue_axes(
655662
mol, local_res_i, relative_res_i, residue=res.atoms

0 commit comments

Comments
 (0)