1+ from functools import partial
2+ from collections import namedtuple
3+ import numpy as np
4+
15from paths_cli .compiling .tools import mdtraj_parse_atomlist
26from paths_cli .wizard .plugin_classes import (
37 LoadFromOPS , WizardObjectPlugin , WrapCategory
48)
59from paths_cli .wizard .core import get_object
610import paths_cli .wizard .engines
711
8- from functools import partial
9- from collections import namedtuple
10- import numpy as np
11-
1212from paths_cli .wizard .parameters import (
1313 FromWizardPrerequisite
1414)
2727 "You should specify atom indices enclosed in double brackets, e.g. "
2828 "[{list_range_natoms}]"
2929)
30+ _MDTrajParams = namedtuple ("_MDTrajParams" , ['period' , 'n_atoms' ,
31+ 'kwarg_name' , 'cv_user_str' ])
32+ _MDTRAJ_INTRO = "We'll make a CV that measures the {user_str}."
33+
3034
3135# TODO: implement so the following can be the help string:
3236# _ATOM_INDICES_HELP_STR = (
5660
5761@get_object
5862def _get_atom_indices (wizard , topology , n_atoms , cv_user_str ):
63+ """Parameter loader for atom_indices parameters in MDTraj.
64+
65+ Parameters
66+ ----------
67+ wizard : :class:`.Wizard`
68+ wizard for user interaction
69+ topology :
70+ topology (reserved for future use)
71+ n_atoms : int
72+ number of atoms to define this CV (i.e., 2 for a distance; 3 for an
73+ angle; 4 for a dihedral)
74+ cv_user_str : str
75+ user-facing name for the CV being created
76+
77+ Returns
78+ -------
79+ :class`np.ndarray` :
80+ array of indices for the MDTraj function
81+ """
5982 helper = Helper (_ATOM_INDICES_HELP_STR .format (
6083 list_range_natoms = list (range (n_atoms ))
6184 ))
@@ -67,14 +90,14 @@ def _get_atom_indices(wizard, topology, n_atoms, cv_user_str):
6790 except Exception as e :
6891 wizard .exception (f"Sorry, I didn't understand '{ atoms_str } '." , e )
6992 helper ("?" )
70- return
93+ return None
7194
7295 return arr
7396
74- _MDTrajParams = namedtuple ("_MDTrajParams" , ['period' , 'n_atoms' ,
75- 'kwarg_name' , 'cv_user_str' ])
7697
7798def _mdtraj_cv_builder (wizard , prereqs , func_name ):
99+ """General function to handle building MDTraj CVs.
100+ """
78101 from openpathsampling .experimental .storage .collective_variables import \
79102 MDTrajFunctionCV
80103 dct = TOPOLOGY_CV_PREREQ (wizard )
@@ -108,9 +131,9 @@ def _mdtraj_cv_builder(wizard, prereqs, func_name):
108131 return MDTrajFunctionCV (func , topology , period_min = period_min ,
109132 period_max = period_max , ** kwargs )
110133
111- _MDTRAJ_INTRO = "We'll make a CV that measures the {user_str}."
112134
113135def _mdtraj_summary (wizard , context , result ):
136+ """Standard summary of MDTraj CVs: function, atom, topology"""
114137 cv = result
115138 func = cv .func
116139 topology = cv .topology
@@ -121,6 +144,7 @@ def _mdtraj_summary(wizard, context, result):
121144 f" Topology: { repr (topology .mdtraj )} " )
122145 return [summary ]
123146
147+
124148if HAS_MDTRAJ :
125149 MDTRAJ_DISTANCE = WizardObjectPlugin (
126150 name = 'Distance' ,
@@ -152,10 +176,24 @@ def _mdtraj_summary(wizard, context, result):
152176 "four atoms" ),
153177 summary = _mdtraj_summary ,
154178 )
155-
156179 # TODO: add RMSD -- need to figure out how to select a frame
157180
181+
158182def coordinate (wizard , prereqs = None ):
183+ """Builder for coordinate CV.
184+
185+ Parameters
186+ ----------
187+ wizard : :class:`.Wizard`
188+ wizard for user interaction
189+ prereqs :
190+ prerequisites (unused in this method)
191+
192+ Return
193+ ------
194+ CoordinateFunctionCV :
195+ the OpenPathSampling CV for this selecting this coordinate
196+ """
159197 # TODO: atom_index should be from wizard.ask_custom_eval
160198 from openpathsampling .experimental .storage .collective_variables import \
161199 CoordinateFunctionCV
@@ -174,12 +212,13 @@ def coordinate(wizard, prereqs=None):
174212 f"atom { atom_index } ?" )
175213 try :
176214 coord = {'x' : 0 , 'y' : 1 , 'z' : 2 }[xyz ]
177- except KeyError as e :
215+ except KeyError :
178216 wizard .bad_input ("Please select one of 'x', 'y', or 'z'" )
179217
180218 cv = CoordinateFunctionCV (lambda snap : snap .xyz [atom_index ][coord ])
181219 return cv
182220
221+
183222COORDINATE_CV = WizardObjectPlugin (
184223 name = "Coordinate" ,
185224 category = "cv" ,
@@ -202,6 +241,7 @@ def coordinate(wizard, prereqs=None):
202241 "you can also create your own and load it from a file." )
203242)
204243
244+
205245if __name__ == "__main__" : # no-cov
206246 from paths_cli .wizard .run_module import run_category
207247 run_category ('cv' )
0 commit comments