Skip to content

Commit 19603db

Browse files
committed
updated tests.utils.make_Universe
ALlow setting of additional TopologyAttrs in extras. Either just add the TopolAttr (as before, as a list) or use a dict with names/values.
1 parent cb2803a commit 19603db

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

basicrta/tests/utils.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Tuple
1+
from typing import Tuple, Union, Dict, Any
22
from contextlib import contextmanager
33
import os
44

@@ -34,7 +34,7 @@ def work_in(dirname):
3434

3535

3636
def make_Universe(
37-
extras: Tuple[str] = tuple(),
37+
extras: Union[Tuple[str], Dict[str, Any]] = tuple(),
3838
size: Tuple[int, int, int] = (125, 25, 5),
3939
n_frames: int = 0,
4040
velocities: bool = False,
@@ -51,10 +51,12 @@ def make_Universe(
5151
5252
Parameters
5353
----------
54-
extras : tuple of strings, optional
55-
extra attributes to add to Universe:
56-
u = make_Universe(('masses', 'charges'))
57-
Creates a lightweight Universe with only masses and charges.
54+
extras : tuple of strings or dict, optional
55+
extra attributes to add to Universe. Can be:
56+
- tuple of strings: u = make_Universe(('masses', 'charges'))
57+
Creates a lightweight Universe with default values for these attributes.
58+
- dict with values: u = make_Universe({'resnames': ['TRP', 'VAL'], 'resids': [313, 314]})
59+
Creates a Universe with specific values for these attributes.
5860
size : tuple of int, optional
5961
number of elements of the Universe (n_atoms, n_residues, n_segments)
6062
n_frames : int
@@ -86,10 +88,18 @@ def make_Universe(
8688
velocities=velocities,
8789
forces=forces,
8890
)
91+
92+
# Handle topology attributes
8993
if extras is None:
9094
extras = []
91-
for ex in extras:
92-
u.add_TopologyAttr(ex)
95+
elif isinstance(extras, dict):
96+
# Dict format: {'resnames': ['TRP', 'VAL'], 'resids': [313, 314]}
97+
for attr_name, attr_values in extras.items():
98+
u.add_TopologyAttr(attr_name, attr_values)
99+
else:
100+
# Tuple/list format: ('masses', 'charges') - uses default values
101+
for ex in extras:
102+
u.add_TopologyAttr(ex)
93103

94104
if trajectory:
95105
pos = np.arange(3 * n_atoms * n_frames).reshape(n_frames, n_atoms, 3)

0 commit comments

Comments
 (0)