1- from typing import Tuple
1+ from typing import Tuple , Union , Dict , Any
22from contextlib import contextmanager
33import os
44
@@ -34,7 +34,7 @@ def work_in(dirname):
3434
3535
3636def 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