westpa 2022.10__cp312-cp312-macosx_10_9_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of westpa might be problematic. Click here for more details.

Files changed (150) hide show
  1. westpa/__init__.py +14 -0
  2. westpa/_version.py +21 -0
  3. westpa/analysis/__init__.py +5 -0
  4. westpa/analysis/core.py +746 -0
  5. westpa/analysis/statistics.py +27 -0
  6. westpa/analysis/trajectories.py +360 -0
  7. westpa/cli/__init__.py +0 -0
  8. westpa/cli/core/__init__.py +0 -0
  9. westpa/cli/core/w_fork.py +152 -0
  10. westpa/cli/core/w_init.py +230 -0
  11. westpa/cli/core/w_run.py +77 -0
  12. westpa/cli/core/w_states.py +212 -0
  13. westpa/cli/core/w_succ.py +99 -0
  14. westpa/cli/core/w_truncate.py +59 -0
  15. westpa/cli/tools/__init__.py +0 -0
  16. westpa/cli/tools/ploterr.py +506 -0
  17. westpa/cli/tools/plothist.py +706 -0
  18. westpa/cli/tools/w_assign.py +596 -0
  19. westpa/cli/tools/w_bins.py +166 -0
  20. westpa/cli/tools/w_crawl.py +119 -0
  21. westpa/cli/tools/w_direct.py +547 -0
  22. westpa/cli/tools/w_dumpsegs.py +94 -0
  23. westpa/cli/tools/w_eddist.py +506 -0
  24. westpa/cli/tools/w_fluxanl.py +378 -0
  25. westpa/cli/tools/w_ipa.py +833 -0
  26. westpa/cli/tools/w_kinavg.py +127 -0
  27. westpa/cli/tools/w_kinetics.py +96 -0
  28. westpa/cli/tools/w_multi_west.py +414 -0
  29. westpa/cli/tools/w_ntop.py +213 -0
  30. westpa/cli/tools/w_pdist.py +515 -0
  31. westpa/cli/tools/w_postanalysis_matrix.py +82 -0
  32. westpa/cli/tools/w_postanalysis_reweight.py +53 -0
  33. westpa/cli/tools/w_red.py +486 -0
  34. westpa/cli/tools/w_reweight.py +780 -0
  35. westpa/cli/tools/w_select.py +226 -0
  36. westpa/cli/tools/w_stateprobs.py +111 -0
  37. westpa/cli/tools/w_trace.py +599 -0
  38. westpa/core/__init__.py +0 -0
  39. westpa/core/_rc.py +673 -0
  40. westpa/core/binning/__init__.py +55 -0
  41. westpa/core/binning/_assign.cpython-312-darwin.so +0 -0
  42. westpa/core/binning/assign.py +449 -0
  43. westpa/core/binning/binless.py +96 -0
  44. westpa/core/binning/binless_driver.py +54 -0
  45. westpa/core/binning/binless_manager.py +190 -0
  46. westpa/core/binning/bins.py +47 -0
  47. westpa/core/binning/mab.py +427 -0
  48. westpa/core/binning/mab_driver.py +54 -0
  49. westpa/core/binning/mab_manager.py +198 -0
  50. westpa/core/data_manager.py +1694 -0
  51. westpa/core/extloader.py +74 -0
  52. westpa/core/h5io.py +995 -0
  53. westpa/core/kinetics/__init__.py +24 -0
  54. westpa/core/kinetics/_kinetics.cpython-312-darwin.so +0 -0
  55. westpa/core/kinetics/events.py +147 -0
  56. westpa/core/kinetics/matrates.py +156 -0
  57. westpa/core/kinetics/rate_averaging.py +266 -0
  58. westpa/core/progress.py +218 -0
  59. westpa/core/propagators/__init__.py +54 -0
  60. westpa/core/propagators/executable.py +715 -0
  61. westpa/core/reweight/__init__.py +14 -0
  62. westpa/core/reweight/_reweight.cpython-312-darwin.so +0 -0
  63. westpa/core/reweight/matrix.py +126 -0
  64. westpa/core/segment.py +119 -0
  65. westpa/core/sim_manager.py +830 -0
  66. westpa/core/states.py +359 -0
  67. westpa/core/systems.py +93 -0
  68. westpa/core/textio.py +74 -0
  69. westpa/core/trajectory.py +330 -0
  70. westpa/core/we_driver.py +908 -0
  71. westpa/core/wm_ops.py +43 -0
  72. westpa/core/yamlcfg.py +391 -0
  73. westpa/fasthist/__init__.py +34 -0
  74. westpa/fasthist/__main__.py +110 -0
  75. westpa/fasthist/_fasthist.cpython-312-darwin.so +0 -0
  76. westpa/mclib/__init__.py +264 -0
  77. westpa/mclib/__main__.py +28 -0
  78. westpa/mclib/_mclib.cpython-312-darwin.so +0 -0
  79. westpa/oldtools/__init__.py +4 -0
  80. westpa/oldtools/aframe/__init__.py +35 -0
  81. westpa/oldtools/aframe/atool.py +75 -0
  82. westpa/oldtools/aframe/base_mixin.py +26 -0
  83. westpa/oldtools/aframe/binning.py +178 -0
  84. westpa/oldtools/aframe/data_reader.py +560 -0
  85. westpa/oldtools/aframe/iter_range.py +200 -0
  86. westpa/oldtools/aframe/kinetics.py +117 -0
  87. westpa/oldtools/aframe/mcbs.py +146 -0
  88. westpa/oldtools/aframe/output.py +39 -0
  89. westpa/oldtools/aframe/plotting.py +90 -0
  90. westpa/oldtools/aframe/trajwalker.py +126 -0
  91. westpa/oldtools/aframe/transitions.py +469 -0
  92. westpa/oldtools/cmds/__init__.py +0 -0
  93. westpa/oldtools/cmds/w_ttimes.py +358 -0
  94. westpa/oldtools/files.py +34 -0
  95. westpa/oldtools/miscfn.py +23 -0
  96. westpa/oldtools/stats/__init__.py +4 -0
  97. westpa/oldtools/stats/accumulator.py +35 -0
  98. westpa/oldtools/stats/edfs.py +129 -0
  99. westpa/oldtools/stats/mcbs.py +89 -0
  100. westpa/tools/__init__.py +33 -0
  101. westpa/tools/binning.py +472 -0
  102. westpa/tools/core.py +340 -0
  103. westpa/tools/data_reader.py +159 -0
  104. westpa/tools/dtypes.py +31 -0
  105. westpa/tools/iter_range.py +198 -0
  106. westpa/tools/kinetics_tool.py +340 -0
  107. westpa/tools/plot.py +283 -0
  108. westpa/tools/progress.py +17 -0
  109. westpa/tools/selected_segs.py +154 -0
  110. westpa/tools/wipi.py +751 -0
  111. westpa/trajtree/__init__.py +4 -0
  112. westpa/trajtree/_trajtree.cpython-312-darwin.so +0 -0
  113. westpa/trajtree/trajtree.py +117 -0
  114. westpa/westext/__init__.py +0 -0
  115. westpa/westext/adaptvoronoi/__init__.py +3 -0
  116. westpa/westext/adaptvoronoi/adaptVor_driver.py +214 -0
  117. westpa/westext/hamsm_restarting/__init__.py +3 -0
  118. westpa/westext/hamsm_restarting/example_overrides.py +35 -0
  119. westpa/westext/hamsm_restarting/restart_driver.py +1165 -0
  120. westpa/westext/stringmethod/__init__.py +11 -0
  121. westpa/westext/stringmethod/fourier_fitting.py +69 -0
  122. westpa/westext/stringmethod/string_driver.py +253 -0
  123. westpa/westext/stringmethod/string_method.py +306 -0
  124. westpa/westext/weed/BinCluster.py +180 -0
  125. westpa/westext/weed/ProbAdjustEquil.py +100 -0
  126. westpa/westext/weed/UncertMath.py +247 -0
  127. westpa/westext/weed/__init__.py +10 -0
  128. westpa/westext/weed/weed_driver.py +182 -0
  129. westpa/westext/wess/ProbAdjust.py +101 -0
  130. westpa/westext/wess/__init__.py +6 -0
  131. westpa/westext/wess/wess_driver.py +207 -0
  132. westpa/work_managers/__init__.py +57 -0
  133. westpa/work_managers/core.py +396 -0
  134. westpa/work_managers/environment.py +134 -0
  135. westpa/work_managers/mpi.py +318 -0
  136. westpa/work_managers/processes.py +187 -0
  137. westpa/work_managers/serial.py +28 -0
  138. westpa/work_managers/threads.py +79 -0
  139. westpa/work_managers/zeromq/__init__.py +20 -0
  140. westpa/work_managers/zeromq/core.py +641 -0
  141. westpa/work_managers/zeromq/node.py +131 -0
  142. westpa/work_managers/zeromq/work_manager.py +526 -0
  143. westpa/work_managers/zeromq/worker.py +320 -0
  144. westpa-2022.10.dist-info/AUTHORS +22 -0
  145. westpa-2022.10.dist-info/LICENSE +21 -0
  146. westpa-2022.10.dist-info/METADATA +183 -0
  147. westpa-2022.10.dist-info/RECORD +150 -0
  148. westpa-2022.10.dist-info/WHEEL +5 -0
  149. westpa-2022.10.dist-info/entry_points.txt +29 -0
  150. westpa-2022.10.dist-info/top_level.txt +1 -0
@@ -0,0 +1,486 @@
1
+ from h5py import File as H5File
2
+ import numpy as np
3
+ from westpa import rc
4
+ from westpa.tools import WESTParallelTool
5
+
6
+
7
+ class DurationCorrector(object):
8
+ @staticmethod
9
+ def from_kinetics_file(directh5, istate, fstate, dtau, n_iters=None):
10
+ iter_slice = slice(n_iters)
11
+
12
+ if isinstance(directh5, H5File):
13
+ dataset = directh5['durations'][iter_slice]
14
+ else:
15
+ with H5File(directh5, 'r') as directh5:
16
+ dataset = directh5['durations'][iter_slice]
17
+
18
+ torf = np.logical_and(dataset['istate'] == istate, dataset['fstate'] == fstate)
19
+ torf = np.logical_and(torf, dataset['weight'] > 0)
20
+
21
+ durations = dataset['duration']
22
+ weights = dataset['weight']
23
+
24
+ weights[~torf] = 0.0 # mask off irrelevant flux
25
+
26
+ return DurationCorrector(durations, weights, dtau)
27
+
28
+ def __init__(self, durations, weights, dtau, maxduration=None):
29
+ self.weights = np.array(weights)
30
+ self.durations = np.array(durations)
31
+ self.dtau = dtau
32
+ self._f_tilde = None
33
+ self._f_int1 = None
34
+
35
+ if maxduration is None:
36
+ self.maxduration = self.durations.shape[0]
37
+ else:
38
+ self.maxduration = maxduration
39
+
40
+ if dtau is None:
41
+ all_durations = []
42
+ all_durations.extend(durations)
43
+ all_durations.extend(np.arange(maxduration))
44
+ uniq_durations = np.unique(all_durations) # unique sorts automatically
45
+ self.dtau = np.min(np.diff(uniq_durations))
46
+
47
+ self._build_map()
48
+
49
+ @property
50
+ def event_duration_histogram(self):
51
+ return self._f_tilde
52
+
53
+ @property
54
+ def cumulative_event_duration_histogram(self):
55
+ return self._f_int1
56
+
57
+ def _build_map(self):
58
+ weights = self.weights
59
+ durations = self.durations
60
+ maxduration = self.maxduration
61
+ dtau = self.dtau
62
+
63
+ taugrid = np.arange(0, maxduration, dtau, dtype=float)
64
+ f_map = np.zeros(weights.shape, dtype=int) - 1
65
+ for i, tau in enumerate(taugrid):
66
+ matches = np.logical_and(durations >= tau, durations < tau + dtau)
67
+ f_map[matches] = i
68
+
69
+ self.taugrid = taugrid
70
+ self.f_map = f_map
71
+
72
+ def correction(self, iters, freqs=None):
73
+ r"""
74
+ Return the correction factor
75
+
76
+ __ __ -1
77
+ | t=theta tau=t |
78
+ | |\ |\ |
79
+ | | | ~ |
80
+ | | | f(tau) dtau dt | * maxduration
81
+ | \| \| |
82
+ | t=0 tau=0 |
83
+ |_ _|
84
+
85
+ where
86
+ ~` ^
87
+ f(tau) is proportional to f(tau)/(theta-tau), and is normalized to
88
+ ^
89
+ integrate to 1, and f(tau) is sum of the weights of walkers with
90
+ duration time tau.
91
+
92
+ ---------
93
+ Arguments
94
+ ---------
95
+ maxduration: the maximum duration time that could have been observed in
96
+ the simulation, which is usually equal to the length of the
97
+ simulation. This should be in units of tau.
98
+ """
99
+
100
+ if iters is None:
101
+ iters = np.arange(len(self.weights))
102
+
103
+ if freqs is None:
104
+ freqs = np.ones(len(iters), dtype=float)
105
+
106
+ maxduration = np.max(iters) + 1
107
+
108
+ f_map = self.f_map[iters]
109
+ weights = self.weights[iters]
110
+ taugrid = self.taugrid # [self.taugrid < maxduration]
111
+
112
+ weights *= freqs[:, None]
113
+
114
+ dtau = self.dtau
115
+
116
+ f_tilde = np.zeros(len(taugrid), dtype=float)
117
+ for i, tau in enumerate(taugrid):
118
+ if tau < maxduration:
119
+ f_tilde[i] = weights[f_map == i].sum() / (maxduration - tau + 1)
120
+
121
+ if f_tilde.sum() != 0:
122
+ f_tilde /= f_tilde.sum() * dtau
123
+
124
+ self._f_tilde = f_tilde
125
+ # now integrate f_tilde twice
126
+ # integral1[t/dtau] gives the integral of f_tilde(tau) dtau from 0 to t
127
+ self._f_int1 = integral1 = np.zeros(f_tilde.shape)
128
+
129
+ for i, tau in enumerate(taugrid):
130
+ if i > 0 and tau < maxduration:
131
+ integral1[i] = np.trapz(f_tilde[: i + 1], taugrid[: i + 1])
132
+
133
+ integral2 = np.trapz(integral1, taugrid)
134
+
135
+ if integral2 == 0:
136
+ return 0.0
137
+ return maxduration / integral2
138
+
139
+
140
+ def get_raw_rates(directh5, istate, fstate, n_iters=None):
141
+ rate_evol = directh5['rate_evolution'][slice(n_iters), istate, fstate]
142
+ avg = rate_evol['expected']
143
+
144
+ return avg
145
+
146
+
147
+ def calc_avg_rate(directh5_path, istate, fstate, **kwargs):
148
+ """
149
+ Return the raw or RED-corrected rate constant with the confidence interval.
150
+
151
+ ---------
152
+ Arguments
153
+ ---------
154
+ dt: timestep (ps)
155
+ nstiter: duration of each iteration (number of steps)
156
+ ntpr: report inteval (number of steps)
157
+
158
+ """
159
+
160
+ n_iters = kwargs.pop("n_iters", None)
161
+
162
+ ntpr = kwargs.pop("report_interval", 20)
163
+ nstiter = kwargs.pop("n_steps_iter", 1000)
164
+ callback = kwargs.pop("callback", None)
165
+
166
+ red = kwargs.pop("red", False)
167
+
168
+ if len(kwargs) > 0:
169
+ raise ValueError("unparsed kwargs")
170
+
171
+ dtau = float(ntpr) / nstiter
172
+ dc = None
173
+
174
+ with H5File(directh5_path, 'r') as directh5:
175
+ if n_iters is None:
176
+ n_iters = directh5['rate_evolution'].shape[0]
177
+
178
+ rate_evol = directh5['rate_evolution'][n_iters - 1, istate, fstate]
179
+ rate = rate_evol['expected']
180
+
181
+ if red:
182
+ dc = DurationCorrector.from_kinetics_file(directh5, istate, fstate, dtau, n_iters)
183
+
184
+ if callback is not None:
185
+ kw = {"correction": dc}
186
+ callback(**kw)
187
+
188
+ iters = np.arange(n_iters)
189
+
190
+ correction = dc.correction(iters) if dc else 1.0
191
+
192
+ rate *= correction
193
+
194
+ return rate
195
+
196
+
197
+ def calc_rates(directh5_path, istate, fstate, **kwargs):
198
+ """
199
+ Return the raw and RED-corrected rate constants vs. iterations.
200
+ This code is faster than calling calc_rate() iteratively
201
+
202
+ ---------
203
+ Arguments
204
+ ---------
205
+ dt: timestep (ps)
206
+ nstiter: duration of each iteration (number of steps)
207
+ ntpr: report inteval (number of steps)
208
+
209
+ """
210
+
211
+ n_iters = kwargs.pop("n_iters", None)
212
+
213
+ ntpr = kwargs.pop("report_interval", 20)
214
+ nstiter = kwargs.pop("n_steps_iter", 1000)
215
+ callback = kwargs.pop("callback", None)
216
+
217
+ red = kwargs.pop("red", False)
218
+
219
+ if len(kwargs) > 0:
220
+ raise ValueError("unparsed kwargs")
221
+
222
+ dtau = float(ntpr) / nstiter
223
+ dc = None
224
+
225
+ with H5File(directh5_path, 'r') as directh5:
226
+ rate_evol, cilb, ciub = get_raw_rates(directh5, istate, fstate, n_iters)
227
+ if n_iters is None:
228
+ n_iters = len(rate_evol)
229
+ if red:
230
+ dc = DurationCorrector.from_kinetics_file(directh5, istate, fstate, dtau, n_iters)
231
+
232
+ if callback is not None:
233
+ kw = {"correction": dc}
234
+ callback(**kw)
235
+
236
+ raw_rates = np.zeros(n_iters)
237
+
238
+ rates = np.zeros(n_iters)
239
+
240
+ for i in range(n_iters):
241
+ i_iter = i + 1
242
+ print("\riter %d/%d (%3.0f%%)" % (i_iter, n_iters, i_iter * 100.0 / n_iters), end="")
243
+
244
+ r = rate_evol[i]
245
+
246
+ iters = np.arange(i_iter)
247
+
248
+ correction = dc.correction(iters) if dc else 1.0
249
+
250
+ raw_rates[i] = r
251
+ rates[i] = raw_rates[i] * correction
252
+
253
+ print("\n")
254
+
255
+ return rates
256
+
257
+
258
+ class RateCalculator:
259
+ def __init__(self, directh5, istate, fstate, assignh5=None, **kwargs):
260
+ n_iters = kwargs.pop("n_iters", None)
261
+ ntpr = kwargs.pop("report_interval", 20)
262
+ nstiter = kwargs.pop("n_steps_iter", 1000)
263
+
264
+ if len(kwargs) > 0:
265
+ for k in kwargs:
266
+ print(k)
267
+ raise ValueError("unparsed kwargs")
268
+
269
+ dtau = float(ntpr) / nstiter
270
+
271
+ with H5File(directh5, 'r') as f:
272
+ state_labels = {}
273
+ for i, raw_label in enumerate(f['state_labels']):
274
+ label = raw_label.decode() if isinstance(raw_label, bytes) else raw_label
275
+ state_labels[label] = i
276
+ if istate not in state_labels:
277
+ raise ValueError(f"istate not found: {istate}, available options are {list(state_labels.keys())}")
278
+ if fstate not in state_labels:
279
+ raise ValueError(f"istate not found: {fstate}, available options are {list(state_labels.keys())}")
280
+ istate = state_labels[istate]
281
+ fstate = state_labels[fstate]
282
+ cond_fluxes = f['conditional_fluxes'][slice(n_iters), istate, fstate]
283
+
284
+ if assignh5 is not None:
285
+ with H5File(assignh5, 'r') as f:
286
+ pops = f['labeled_populations'][slice(n_iters)]
287
+ pops = pops.sum(axis=2)
288
+ else:
289
+ pops = None
290
+
291
+ self._dc = None
292
+ self._pops = pops
293
+ self._cond_fluxes = cond_fluxes
294
+ self._dtau = dtau
295
+ self._directh5 = directh5
296
+ self._assignh5 = assignh5
297
+ self._istate = istate
298
+ self._fstate = fstate
299
+
300
+ @property
301
+ def conditional_fluxes(self):
302
+ return self._cond_fluxes
303
+
304
+ @property
305
+ def populations(self):
306
+ return self._pops
307
+
308
+ @property
309
+ def tau(self):
310
+ return self._tau
311
+
312
+ @property
313
+ def dtau(self):
314
+ return self._dtau
315
+
316
+ @property
317
+ def istate(self):
318
+ return self._istate
319
+
320
+ @property
321
+ def fstate(self):
322
+ return self._fstate
323
+
324
+ @property
325
+ def n_iters(self):
326
+ return len(self.conditional_fluxes)
327
+
328
+ def _get_corrector(self):
329
+ if self._dc is None:
330
+ with H5File(self._directh5, 'r') as f:
331
+ self._dc = DurationCorrector.from_kinetics_file(f, self.istate, self.fstate, self.dtau, self.n_iters)
332
+
333
+ return self._dc
334
+
335
+ def calc_rate(self, i_iter=None, red=False, **kwargs):
336
+ if i_iter is None:
337
+ i_iter = self.n_iters
338
+
339
+ dc = self._get_corrector() if red else None
340
+ found = False
341
+ with H5File(self._directh5, 'r') as f:
342
+ for i in range(f['rate_evolution'].shape[0]):
343
+ rate_evol = f['rate_evolution'][i, self.istate, self.fstate]
344
+ start = rate_evol['iter_start']
345
+ stop = rate_evol['iter_stop']
346
+
347
+ if i_iter >= start and i_iter < stop:
348
+ rate = rate_evol['expected']
349
+ found = True
350
+ break
351
+
352
+ if not found:
353
+ self.log.error("Can't find rate evolution data for iteration %d!" % i_iter)
354
+
355
+ if dc:
356
+ iters = np.arange(i_iter)
357
+ correction = dc.correction(iters)
358
+ rate *= correction
359
+
360
+ return rate
361
+
362
+ def calc_rates(self, n_iters=None, **kwargs):
363
+ if n_iters is None:
364
+ n_iters = self.n_iters
365
+
366
+ rates = np.zeros(n_iters)
367
+
368
+ for i in range(n_iters):
369
+ i_iter = i + 1
370
+ print("\riter %d/%d (%3.0f%%)" % (i_iter, n_iters, i_iter * 100.0 / n_iters), end="")
371
+
372
+ r = self.calc_rate(i_iter, **kwargs)
373
+
374
+ rates[i] = r
375
+
376
+ print("\n")
377
+
378
+ return rates
379
+
380
+
381
+ class WRed(WESTParallelTool):
382
+ prog = 'w_red'
383
+ description = '''\
384
+ Apply the RED scheme to estimate steady-state WE fluxes from
385
+ shorter trajectories.
386
+
387
+ -----------------------------------------------------------------------------
388
+ Source data
389
+ -----------------------------------------------------------------------------
390
+
391
+ Source data is provided as a w_ipa "scheme" which is typically defined
392
+ in the west.cfg file. For instance, if a user wishes to estimate RED
393
+ fluxes for a scheme named "DEFAULT" that argument would be provided
394
+ to w_red and WRed would estimate RED fluxes based off of the data
395
+ contained in the assign.h5 and direct.h5 files in ANALYSIS/DEFAULT.
396
+
397
+ '''
398
+
399
+ def __init__(self):
400
+ super().__init__()
401
+
402
+ def go(self):
403
+ try:
404
+ rc.config['west']['analysis']['red']
405
+ except Exception:
406
+ raise ValueError('No RED parameters are specified in west.cfg.')
407
+ try:
408
+ rc.config['west']['analysis']['red']['scheme']
409
+ except Exception:
410
+ raise ValueError('No scheme specified for RED calculation in west.cfg.')
411
+ try:
412
+ rc.config['west']['analysis']['red']['istate_label']
413
+ except Exception:
414
+ raise ValueError('No intial state label specified for RED calculation in west.cfg.')
415
+ try:
416
+ rc.config['west']['analysis']['red']['fstate_label']
417
+ except Exception:
418
+ raise ValueError('No final state label specified for RED calculation in west.cfg.')
419
+ try:
420
+ rc.config['west']['analysis']['red']['nstiter']
421
+ except Exception:
422
+ raise ValueError('Time step not specified in west.cfg.')
423
+ try:
424
+ rc.config['west']['analysis']['red']['nstrep']
425
+ except Exception:
426
+ raise ValueError('Time step not specified in west.cfg.')
427
+
428
+ if rc.config['west']['analysis']['kinetics']['evolution'] == "cumulative":
429
+ pass
430
+ else:
431
+ print("Only RED estimates with cumulative averaging are supported at this time.")
432
+ exit()
433
+
434
+ config = rc.config
435
+ adir = config.get(['west', 'analysis', 'directory'])
436
+ name = config.get(['west', 'analysis', 'red', 'scheme'])
437
+ istate = config.get(['west', 'analysis', 'red', 'istate_label'])
438
+ fstate = config.get(['west', 'analysis', 'red', 'fstate_label'])
439
+ n_steps_per_iter = config.get(['west', 'analysis', 'red', 'nstiter'])
440
+ n_steps_per_report = config.get(['west', 'analysis', 'red', 'nstrep'])
441
+
442
+ directh5path = '%s/%s/direct.h5' % (adir, name)
443
+ assignh5path = '%s/%s/assign.h5' % (adir, name)
444
+
445
+ print('\nConfig successfully read from west.cfg:')
446
+ print('--------------------------------------')
447
+ print('scheme: %s' % name)
448
+ print('states: %s -> %s' % (istate, fstate))
449
+ print('nstiter: %s' % n_steps_per_iter)
450
+ print('nstrep: %s' % n_steps_per_report)
451
+ print('--------------------------------------')
452
+ print('\nEstimating RED fluxes...')
453
+ rater = RateCalculator(
454
+ directh5path,
455
+ istate,
456
+ fstate,
457
+ n_steps_iter=n_steps_per_iter,
458
+ report_interval=n_steps_per_report,
459
+ assignh5=assignh5path,
460
+ )
461
+
462
+ rates = rater.calc_rates(red=True, callback=None)
463
+
464
+ with H5File(directh5path, "r+") as dest_file:
465
+ try:
466
+ dest_file.create_dataset('red_flux_evolution', data=rates)
467
+ print('saved RED fluxes to red_flux_evolution in ANALYSIS/%s/direct.h5' % name)
468
+ except Exception:
469
+ warning = input('Dataset already exists! Overwrite? (y/n)')
470
+ if warning == "y":
471
+ dest_file['red_flux_evolution'][...] = rates
472
+ print('saved RED fluxes to red_flux_evolution in ANALYSIS/%s/direct.h5' % name)
473
+ elif warning == "n":
474
+ np.save('ANALYSIS/%s/red.npy' % name, rates)
475
+ print('saved RED fluxes to red_flux_evolution.npy in ANALYSIS/%s' % name)
476
+ else:
477
+ print('red rates not saved. Exiting...')
478
+ exit
479
+
480
+
481
+ def entry_point():
482
+ WRed().main()
483
+
484
+
485
+ if __name__ == '__main__':
486
+ entry_point()