11import random
2+ import os
23from functools import partial
34import textwrap
45
1011)
1112from paths_cli .wizard .tools import yes_no , a_an
1213from paths_cli .parsing .core import custom_eval
14+ from paths_cli .wizard .errors import FILE_LOADING_ERROR_MSG
1315from paths_cli .wizard .joke import name_joke
1416
1517import shutil
@@ -41,6 +43,15 @@ def __init__(self, steps):
4143
4244 self .console = Console ()
4345 self .default = {}
46+ self ._patched = False # if we've done the monkey-patching
47+
48+ def _patch (self ):
49+ import openpathsampling as paths
50+ from openpathsampling .experimental .storage import monkey_patch_all
51+ if not self ._patched :
52+ paths = monkey_patch_all (paths )
53+ paths .InterfaceSet .simstore = True
54+ self ._patched = True
4455
4556 def debug (content ):
4657 self .console .print (content )
@@ -86,7 +97,7 @@ def ask_enumerate(self, question, options):
8697 self .say (opt_string , preface = " " * 3 )
8798 result = None
8899 while result is None :
89- choice = self .ask ("Please select a number. " ,
100+ choice = self .ask ("Please select a number: " ,
90101 options = [str (i + 1 )
91102 for i in range (len (options ))])
92103 try :
@@ -127,7 +138,8 @@ def obj_selector(self, store_name, text_name, create_func):
127138 return obj
128139
129140 def exception (self , msg , exception ):
130- self .bad_input (msg + "\n Here's the error I got:\n " + str (exception ))
141+ self .bad_input (f"{ msg } \n Here's the error I got:\n "
142+ f"{ exception .__class__ .__name__ } : { exception } " )
131143
132144 def _req_do_another (self , req ):
133145 store , min_ , max_ = req
@@ -164,6 +176,7 @@ def register(self, obj, obj_type, store_name):
164176 return obj
165177
166178 def save_to_file (self ):
179+ from openpathsampling .experimental .storage import Storage
167180 filename = None
168181 while filename is None :
169182 filename = self .ask ("Where would you like to save your setup "
@@ -175,9 +188,9 @@ def save_to_file(self):
175188 continue
176189
177190 if os .path .exists (filename ):
178- overwrite = self .ask ("{filename} exists. Overwrite it?" ,
191+ overwrite = self .ask (f "{ filename } exists. Overwrite it?" ,
179192 options = ["[Y]es" , "[N]o" ])
180- overwrite = yes_no [ overwrite ]
193+ overwrite = yes_no ( overwrite )
181194 if not overwrite :
182195 filename = None
183196 continue
@@ -189,8 +202,27 @@ def save_to_file(self):
189202 else :
190203 self ._do_storage (storage )
191204
205+ def _storage_description_line (self , store_name ):
206+ store = getattr (self , store_name )
207+ if len (store ) == 1 :
208+ store_name = store_name [:- 1 ] # chop the 's'
209+
210+ line = f"* { len (store )} { store_name } : " + str (list (store .keys ()))
211+ return line
212+
192213 def _do_storage (self , storage ):
193- pass
214+ store_names = ['engines' , 'cvs' , 'states' , 'networks' , 'schemes' ]
215+ lines = [self ._storage_description_line (store_name )
216+ for store_name in store_names ]
217+ statement = ("I'm going to store the following items:\n \n "
218+ + "\n " .join (lines ))
219+ self .say (statement )
220+ for store_name in store_names :
221+ store = getattr (self , store_name )
222+ for obj in store .values ():
223+ storage .save (obj )
224+
225+ self .say ("Success! Everthing has been stored in your file." )
194226
195227 def _ask_do_another (self , obj_type ):
196228 do_another = None
@@ -206,6 +238,7 @@ def _ask_do_another(self, obj_type):
206238 return do_another
207239
208240 def run_wizard (self ):
241+ self ._patch () # try to hide the slowness of our first import
209242 for step in self .steps :
210243 req = step .store_name , step .minimum , step .maximum
211244 do_another = True
@@ -220,6 +253,8 @@ def run_wizard(self):
220253 else :
221254 do_another = False
222255
256+ self .save_to_file ()
257+
223258from collections import namedtuple
224259WizardStep = namedtuple ('WizardStep' , ['func' , 'display_name' , 'store_name' ,
225260 'minimum' , 'maximum' ])
@@ -229,6 +264,7 @@ def run_wizard(self):
229264 store_name = "engines" ,
230265 minimum = 1 ,
231266 maximum = 1 )
267+
232268CVS_STEP = WizardStep (func = cvs ,
233269 display_name = "CV" ,
234270 store_name = 'cvs' ,
0 commit comments