2020It also includes various functions to retrieve or ensure important parameters from
2121MDConfig/MDEngine combinations, such as nstout_from_mdconfig and ensure_mdconfig_options.
2222"""
23+ import logging
24+
2325from .mdengine import MDEngine
2426from .mdconfig import MDConfig
2527from .trajectory .trajectory import Trajectory
2830from .gromacs import mdconfig as gmx_config
2931
3032
31- async def get_all_traj_parts (folder : str , deffnm : str , engine : MDEngine ) -> list [Trajectory ]:
33+ logger = logging .getLogger (__name__ )
34+
35+
36+ async def get_all_traj_parts (folder : str , deffnm : str , engine : MDEngine | type [MDEngine ],
37+ ) -> list [Trajectory ]:
3238 """
3339 List all trajectories in folder by given engine class with given deffnm.
3440
@@ -37,10 +43,12 @@ async def get_all_traj_parts(folder: str, deffnm: str, engine: MDEngine) -> list
3743 folder : str
3844 Absolute or relative path to a folder.
3945 deffnm : str
40- deffnm used by the engines simulation run from which we want the trajs.
41- engine : MDEngine
42- The engine that produced the trajectories
43- (or one from the same class and with similar init args)
46+ deffnm used by the engines simulation run from which we want the trajectories.
47+ engine : MDEngine | type[MDEngine]
48+ The engine that produced the trajectories (or one from the same class
49+ and with similar init args). Note that it is also possible to pass an
50+ uninitialized engine class, but then the default trajectory output type
51+ will be returned.
4452
4553 Returns
4654 -------
@@ -52,7 +60,17 @@ async def get_all_traj_parts(folder: str, deffnm: str, engine: MDEngine) -> list
5260 ValueError
5361 Raised when the engine class is unknown.
5462 """
55- if isinstance (engine , (gmx_engine .GmxEngine , gmx_engine .SlurmGmxEngine )):
63+ # test for uninitialized engine classes, we warn but return the default traj type
64+ if isinstance (engine , type ) and issubclass (engine , MDEngine ):
65+ logger .warning ("Engine %s is not initialized, i.e. it is an engine class. "
66+ "Returning the default output trajectory type for this "
67+ "engine class." , engine )
68+ if (
69+ isinstance (engine , (gmx_engine .GmxEngine , gmx_engine .SlurmGmxEngine ))
70+ or (isinstance (engine , type ) # check that it is a type otherwise issubclass might not work
71+ and issubclass (engine , (gmx_engine .GmxEngine , gmx_engine .SlurmGmxEngine ))
72+ )
73+ ):
5674 return await gmx_utils .get_all_traj_parts (folder = folder , deffnm = deffnm ,
5775 traj_type = engine .output_traj_type ,
5876 )
@@ -61,6 +79,7 @@ async def get_all_traj_parts(folder: str, deffnm: str, engine: MDEngine) -> list
6179
6280
6381async def get_all_file_parts (folder : str , deffnm : str , file_ending : str ,
82+ engine : MDEngine | type [MDEngine ],
6483 ) -> list [str ]:
6584 """
6685 Find and return all files with given ending produced by a `MDEngine`.
@@ -75,16 +94,24 @@ async def get_all_file_parts(folder: str, deffnm: str, file_ending: str,
7594 deffnm (prefix of filenames) used in the simulation.
7695 file_ending : str
7796 File ending of the requested filetype (with or without preceding ".").
97+ engine : MDEngine | type[MDEngine]
98+ The engine or engine class that produced the file parts.
7899
79100 Returns
80101 -------
81102 list[str]
82103 Ordered list of filepaths for files with given ending.
83104 """
84- # TODO: we just use the function from the gromacs engines for now, i.e. we
85- # assume that the filename scheme will be the same for other engines
86- return await gmx_utils .get_all_file_parts (folder = folder , deffnm = deffnm ,
87- file_ending = file_ending )
105+ if (
106+ isinstance (engine , (gmx_engine .GmxEngine , gmx_engine .SlurmGmxEngine ))
107+ or (isinstance (engine , type ) # check that it is a type otherwise issubclass might not work
108+ and issubclass (engine , (gmx_engine .GmxEngine , gmx_engine .SlurmGmxEngine ))
109+ )
110+ ):
111+ return await gmx_utils .get_all_file_parts (folder = folder , deffnm = deffnm ,
112+ file_ending = file_ending )
113+ raise ValueError (f"Engine { engine } is not a known MDEngine (class)."
114+ + " Maybe someone just forgot to add the function?" )
88115
89116
90117def nstout_from_mdconfig (mdconfig : MDConfig , output_traj_type : str ) -> int :
0 commit comments