westpa 2022.13__cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.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.
Files changed (162) 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 +749 -0
  5. westpa/analysis/statistics.py +27 -0
  6. westpa/analysis/trajectories.py +369 -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 +68 -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 +597 -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 +557 -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 +376 -0
  25. westpa/cli/tools/w_ipa.py +832 -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 +491 -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_timings.py +113 -0
  38. westpa/cli/tools/w_trace.py +599 -0
  39. westpa/core/__init__.py +0 -0
  40. westpa/core/_rc.py +673 -0
  41. westpa/core/binning/__init__.py +55 -0
  42. westpa/core/binning/_assign.c +36018 -0
  43. westpa/core/binning/_assign.cpython-312-aarch64-linux-gnu.so +0 -0
  44. westpa/core/binning/_assign.pyx +370 -0
  45. westpa/core/binning/assign.py +454 -0
  46. westpa/core/binning/binless.py +96 -0
  47. westpa/core/binning/binless_driver.py +54 -0
  48. westpa/core/binning/binless_manager.py +189 -0
  49. westpa/core/binning/bins.py +47 -0
  50. westpa/core/binning/mab.py +506 -0
  51. westpa/core/binning/mab_driver.py +54 -0
  52. westpa/core/binning/mab_manager.py +197 -0
  53. westpa/core/data_manager.py +1761 -0
  54. westpa/core/extloader.py +74 -0
  55. westpa/core/h5io.py +1079 -0
  56. westpa/core/kinetics/__init__.py +24 -0
  57. westpa/core/kinetics/_kinetics.c +45174 -0
  58. westpa/core/kinetics/_kinetics.cpython-312-aarch64-linux-gnu.so +0 -0
  59. westpa/core/kinetics/_kinetics.pyx +815 -0
  60. westpa/core/kinetics/events.py +147 -0
  61. westpa/core/kinetics/matrates.py +156 -0
  62. westpa/core/kinetics/rate_averaging.py +266 -0
  63. westpa/core/progress.py +218 -0
  64. westpa/core/propagators/__init__.py +54 -0
  65. westpa/core/propagators/executable.py +592 -0
  66. westpa/core/propagators/loaders.py +196 -0
  67. westpa/core/reweight/__init__.py +14 -0
  68. westpa/core/reweight/_reweight.c +36899 -0
  69. westpa/core/reweight/_reweight.cpython-312-aarch64-linux-gnu.so +0 -0
  70. westpa/core/reweight/_reweight.pyx +439 -0
  71. westpa/core/reweight/matrix.py +126 -0
  72. westpa/core/segment.py +119 -0
  73. westpa/core/sim_manager.py +839 -0
  74. westpa/core/states.py +359 -0
  75. westpa/core/systems.py +93 -0
  76. westpa/core/textio.py +74 -0
  77. westpa/core/trajectory.py +603 -0
  78. westpa/core/we_driver.py +910 -0
  79. westpa/core/wm_ops.py +43 -0
  80. westpa/core/yamlcfg.py +298 -0
  81. westpa/fasthist/__init__.py +34 -0
  82. westpa/fasthist/_fasthist.c +38755 -0
  83. westpa/fasthist/_fasthist.cpython-312-aarch64-linux-gnu.so +0 -0
  84. westpa/fasthist/_fasthist.pyx +222 -0
  85. westpa/mclib/__init__.py +271 -0
  86. westpa/mclib/__main__.py +28 -0
  87. westpa/mclib/_mclib.c +34610 -0
  88. westpa/mclib/_mclib.cpython-312-aarch64-linux-gnu.so +0 -0
  89. westpa/mclib/_mclib.pyx +226 -0
  90. westpa/oldtools/__init__.py +4 -0
  91. westpa/oldtools/aframe/__init__.py +35 -0
  92. westpa/oldtools/aframe/atool.py +75 -0
  93. westpa/oldtools/aframe/base_mixin.py +26 -0
  94. westpa/oldtools/aframe/binning.py +178 -0
  95. westpa/oldtools/aframe/data_reader.py +560 -0
  96. westpa/oldtools/aframe/iter_range.py +200 -0
  97. westpa/oldtools/aframe/kinetics.py +117 -0
  98. westpa/oldtools/aframe/mcbs.py +153 -0
  99. westpa/oldtools/aframe/output.py +39 -0
  100. westpa/oldtools/aframe/plotting.py +88 -0
  101. westpa/oldtools/aframe/trajwalker.py +126 -0
  102. westpa/oldtools/aframe/transitions.py +469 -0
  103. westpa/oldtools/cmds/__init__.py +0 -0
  104. westpa/oldtools/cmds/w_ttimes.py +361 -0
  105. westpa/oldtools/files.py +34 -0
  106. westpa/oldtools/miscfn.py +23 -0
  107. westpa/oldtools/stats/__init__.py +4 -0
  108. westpa/oldtools/stats/accumulator.py +35 -0
  109. westpa/oldtools/stats/edfs.py +129 -0
  110. westpa/oldtools/stats/mcbs.py +96 -0
  111. westpa/tools/__init__.py +33 -0
  112. westpa/tools/binning.py +472 -0
  113. westpa/tools/core.py +340 -0
  114. westpa/tools/data_reader.py +159 -0
  115. westpa/tools/dtypes.py +31 -0
  116. westpa/tools/iter_range.py +198 -0
  117. westpa/tools/kinetics_tool.py +343 -0
  118. westpa/tools/plot.py +283 -0
  119. westpa/tools/progress.py +17 -0
  120. westpa/tools/selected_segs.py +154 -0
  121. westpa/tools/wipi.py +751 -0
  122. westpa/trajtree/__init__.py +4 -0
  123. westpa/trajtree/_trajtree.c +17829 -0
  124. westpa/trajtree/_trajtree.cpython-312-aarch64-linux-gnu.so +0 -0
  125. westpa/trajtree/_trajtree.pyx +130 -0
  126. westpa/trajtree/trajtree.py +117 -0
  127. westpa/westext/__init__.py +0 -0
  128. westpa/westext/adaptvoronoi/__init__.py +3 -0
  129. westpa/westext/adaptvoronoi/adaptVor_driver.py +214 -0
  130. westpa/westext/hamsm_restarting/__init__.py +3 -0
  131. westpa/westext/hamsm_restarting/example_overrides.py +35 -0
  132. westpa/westext/hamsm_restarting/restart_driver.py +1165 -0
  133. westpa/westext/stringmethod/__init__.py +11 -0
  134. westpa/westext/stringmethod/fourier_fitting.py +69 -0
  135. westpa/westext/stringmethod/string_driver.py +253 -0
  136. westpa/westext/stringmethod/string_method.py +306 -0
  137. westpa/westext/weed/BinCluster.py +180 -0
  138. westpa/westext/weed/ProbAdjustEquil.py +100 -0
  139. westpa/westext/weed/UncertMath.py +247 -0
  140. westpa/westext/weed/__init__.py +10 -0
  141. westpa/westext/weed/weed_driver.py +192 -0
  142. westpa/westext/wess/ProbAdjust.py +101 -0
  143. westpa/westext/wess/__init__.py +6 -0
  144. westpa/westext/wess/wess_driver.py +217 -0
  145. westpa/work_managers/__init__.py +57 -0
  146. westpa/work_managers/core.py +396 -0
  147. westpa/work_managers/environment.py +134 -0
  148. westpa/work_managers/mpi.py +318 -0
  149. westpa/work_managers/processes.py +201 -0
  150. westpa/work_managers/serial.py +28 -0
  151. westpa/work_managers/threads.py +79 -0
  152. westpa/work_managers/zeromq/__init__.py +20 -0
  153. westpa/work_managers/zeromq/core.py +635 -0
  154. westpa/work_managers/zeromq/node.py +131 -0
  155. westpa/work_managers/zeromq/work_manager.py +526 -0
  156. westpa/work_managers/zeromq/worker.py +320 -0
  157. westpa-2022.13.dist-info/METADATA +179 -0
  158. westpa-2022.13.dist-info/RECORD +162 -0
  159. westpa-2022.13.dist-info/WHEEL +7 -0
  160. westpa-2022.13.dist-info/entry_points.txt +30 -0
  161. westpa-2022.13.dist-info/licenses/LICENSE +21 -0
  162. westpa-2022.13.dist-info/top_level.txt +1 -0
@@ -0,0 +1,557 @@
1
+ import logging
2
+
3
+ import numpy as np
4
+
5
+ from westpa.core.data_manager import weight_dtype
6
+ from westpa.tools import WESTMasterCommand, WESTParallelTool
7
+
8
+ from westpa.core import h5io
9
+ from westpa.core.kinetics import sequence_macro_flux_to_rate, WKinetics
10
+
11
+ from westpa.tools.kinetics_tool import WESTKineticsBase, AverageCommands
12
+
13
+ from westpa.mclib import mcbs_ci_correl, _1D_simple_eval_block, _2D_simple_eval_block
14
+
15
+
16
+ # From w_stateprobs
17
+ from westpa.core.binning import accumulate_state_populations_from_labeled
18
+
19
+ log = logging.getLogger('w_direct')
20
+
21
+
22
+ # This block is responsible for submitting a set of calculations to be bootstrapped over for a particular type of calculation.
23
+ # A property which wishes to be calculated should adhere to this format.
24
+ def _rate_eval_block(iblock, start, stop, nstates, data_input, name, mcbs_alpha, mcbs_nsets, mcbs_acalpha, do_correl, mcbs_enable):
25
+ # Our rate estimator is a little more complex, so we've defined a custom evaluation block for it,
26
+ # instead of just using the block evalutors that we've imported.
27
+ results = []
28
+ for istate in range(nstates):
29
+ for jstate in range(nstates):
30
+ if istate == jstate:
31
+ continue
32
+ kwargs = {'istate': istate, 'jstate': jstate}
33
+ # Why are we sending in the total population dataset, instead of a sliced one?
34
+ # It's a requirement of our estimator; we need to pull from any given i to j state in order to properly normalize
35
+ # and avoid i to j rate constants which are affected by a third state k.
36
+ # That is, we need the populations for both i and j, and it's easier to just send in the entire dataset.
37
+ dataset = {'dataset': data_input['dataset'][:, istate, jstate], 'pops': data_input['pops']}
38
+ ci_res = mcbs_ci_correl(
39
+ dataset,
40
+ estimator=sequence_macro_flux_to_rate,
41
+ alpha=mcbs_alpha,
42
+ n_sets=mcbs_nsets,
43
+ autocorrel_alpha=mcbs_acalpha,
44
+ subsample=np.mean,
45
+ do_correl=do_correl,
46
+ mcbs_enable=mcbs_enable,
47
+ estimator_kwargs=kwargs,
48
+ )
49
+ results.append((name, iblock, istate, jstate, (start, stop) + ci_res))
50
+
51
+ return results
52
+
53
+
54
+ # The old w_kinetics
55
+ class DKinetics(WESTKineticsBase, WKinetics):
56
+ subcommand = 'init'
57
+ default_kinetics_file = 'direct.h5'
58
+ default_output_file = 'direct.h5'
59
+ help_text = 'calculate state-to-state kinetics by tracing trajectories'
60
+ description = '''\
61
+ Calculate state-to-state rates and transition event durations by tracing
62
+ trajectories.
63
+
64
+ A bin assignment file (usually "assign.h5") including trajectory labeling
65
+ is required (see "w_assign --help" for information on generating this file).
66
+
67
+ This subcommand for w_direct is used as input for all other w_direct
68
+ subcommands, which will convert the flux data in the output file into
69
+ average rates/fluxes/populations with confidence intervals.
70
+
71
+ -----------------------------------------------------------------------------
72
+ Output format
73
+ -----------------------------------------------------------------------------
74
+
75
+ The output file (-o/--output, by default "direct.h5") contains the
76
+ following datasets:
77
+
78
+ ``/conditional_fluxes`` [iteration][state][state]
79
+ *(Floating-point)* Macrostate-to-macrostate fluxes. These are **not**
80
+ normalized by the population of the initial macrostate.
81
+
82
+ ``/conditional_arrivals`` [iteration][stateA][stateB]
83
+ *(Integer)* Number of trajectories arriving at state *stateB* in a given
84
+ iteration, given that they departed from *stateA*.
85
+
86
+ ``/total_fluxes`` [iteration][state]
87
+ *(Floating-point)* Total flux into a given macrostate.
88
+
89
+ ``/arrivals`` [iteration][state]
90
+ *(Integer)* Number of trajectories arriving at a given state in a given
91
+ iteration, regardless of where they originated.
92
+
93
+ ``/duration_count`` [iteration]
94
+ *(Integer)* The number of event durations recorded in each iteration.
95
+
96
+ ``/durations`` [iteration][event duration]
97
+ *(Structured -- see below)* Event durations for transition events ending
98
+ during a given iteration. These are stored as follows:
99
+
100
+ istate
101
+ *(Integer)* Initial state of transition event.
102
+ fstate
103
+ *(Integer)* Final state of transition event.
104
+ duration
105
+ *(Floating-point)* Duration of transition, in units of tau.
106
+ weight
107
+ *(Floating-point)* Weight of trajectory at end of transition, **not**
108
+ normalized by initial state population.
109
+
110
+ Because state-to-state fluxes stored in this file are not normalized by
111
+ initial macrostate population, they cannot be used as rates without further
112
+ processing. The ``w_direct kinetics`` command is used to perform this normalization
113
+ while taking statistical fluctuation and correlation into account. See
114
+ ``w_direct kinetics --help`` for more information. Target fluxes (total flux
115
+ into a given state) require no such normalization.
116
+
117
+ -----------------------------------------------------------------------------
118
+ Command-line options
119
+ -----------------------------------------------------------------------------
120
+ '''
121
+
122
+ def __init__(self, parent):
123
+ super().__init__(parent)
124
+
125
+ def open_files(self):
126
+ self.output_file = h5io.WESTPAH5File(self.output_filename, 'a', creating_program=True)
127
+ h5io.stamp_creator_data(self.output_file)
128
+ self.assignments_file = h5io.WESTPAH5File(self.assignments_filename, 'r') # , driver='core', backing_store=False)
129
+ if not self.iter_range.check_data_iter_range_least(self.assignments_file):
130
+ raise ValueError('assignments data do not span the requested iterations')
131
+
132
+ def go(self):
133
+ pi = self.progress.indicator
134
+ with pi:
135
+ self.w_kinetics()
136
+
137
+
138
+ # The old w_kinavg
139
+ class DKinAvg(AverageCommands):
140
+ subcommand = 'kinetics'
141
+ help_text = 'Generates rate and flux values from a WESTPA simulation via tracing.'
142
+ default_kinetics_file = 'direct.h5'
143
+ description = '''\
144
+ Calculate average rates/fluxes and associated errors from weighted ensemble
145
+ data. Bin assignments (usually "assign.h5") and kinetics data (usually
146
+ "direct.h5") data files must have been previously generated (see
147
+ "w_assign --help" and "w_direct init --help" for information on
148
+ generating these files).
149
+
150
+ The evolution of all datasets may be calculated, with or without confidence
151
+ intervals.
152
+
153
+ -----------------------------------------------------------------------------
154
+ Output format
155
+ -----------------------------------------------------------------------------
156
+
157
+ The output file (-o/--output, usually "direct.h5") contains the following
158
+ dataset:
159
+
160
+ /avg_rates [state,state]
161
+ (Structured -- see below) State-to-state rates based on entire window of
162
+ iterations selected.
163
+
164
+ /avg_total_fluxes [state]
165
+ (Structured -- see below) Total fluxes into each state based on entire
166
+ window of iterations selected.
167
+
168
+ /avg_conditional_fluxes [state,state]
169
+ (Structured -- see below) State-to-state fluxes based on entire window of
170
+ iterations selected.
171
+
172
+ If --evolution-mode is specified, then the following additional datasets are
173
+ available:
174
+
175
+ /rate_evolution [window][state][state]
176
+ (Structured -- see below). State-to-state rates based on windows of
177
+ iterations of varying width. If --evolution-mode=cumulative, then
178
+ these windows all begin at the iteration specified with
179
+ --start-iter and grow in length by --step-iter for each successive
180
+ element. If --evolution-mode=blocked, then these windows are all of
181
+ width --step-iter (excluding the last, which may be shorter), the first
182
+ of which begins at iteration --start-iter.
183
+
184
+ /target_flux_evolution [window,state]
185
+ (Structured -- see below). Total flux into a given macro state based on
186
+ windows of iterations of varying width, as in /rate_evolution.
187
+
188
+ /conditional_flux_evolution [window,state,state]
189
+ (Structured -- see below). State-to-state fluxes based on windows of
190
+ varying width, as in /rate_evolution.
191
+
192
+ The structure of these datasets is as follows:
193
+
194
+ iter_start
195
+ (Integer) Iteration at which the averaging window begins (inclusive).
196
+
197
+ iter_stop
198
+ (Integer) Iteration at which the averaging window ends (exclusive).
199
+
200
+ expected
201
+ (Floating-point) Expected (mean) value of the observable as evaluated within
202
+ this window, in units of inverse tau.
203
+
204
+ ci_lbound
205
+ (Floating-point) Lower bound of the confidence interval of the observable
206
+ within this window, in units of inverse tau.
207
+
208
+ ci_ubound
209
+ (Floating-point) Upper bound of the confidence interval of the observable
210
+ within this window, in units of inverse tau.
211
+
212
+ stderr
213
+ (Floating-point) The standard error of the mean of the observable
214
+ within this window, in units of inverse tau.
215
+
216
+ corr_len
217
+ (Integer) Correlation length of the observable within this window, in units
218
+ of tau.
219
+
220
+ Each of these datasets is also stamped with a number of attributes:
221
+
222
+ mcbs_alpha
223
+ (Floating-point) Alpha value of confidence intervals. (For example,
224
+ *alpha=0.05* corresponds to a 95% confidence interval.)
225
+
226
+ mcbs_nsets
227
+ (Integer) Number of bootstrap data sets used in generating confidence
228
+ intervals.
229
+
230
+ mcbs_acalpha
231
+ (Floating-point) Alpha value for determining correlation lengths.
232
+
233
+
234
+ -----------------------------------------------------------------------------
235
+ Command-line options
236
+ -----------------------------------------------------------------------------
237
+ '''
238
+
239
+ def w_kinavg(self):
240
+ pi = self.progress.indicator
241
+ # pi = None
242
+
243
+ # We're initializing the various datasets...
244
+ self.open_files()
245
+ self.open_assignments()
246
+ # Obviously, this is for the conditional and total fluxes. This is really all we need to sort for this.
247
+ cond_fluxes = h5io.IterBlockedDataset(self.kinetics_file['conditional_fluxes'])
248
+ cond_fluxes.cache_data()
249
+ total_fluxes = h5io.IterBlockedDataset(self.kinetics_file['total_fluxes'])
250
+
251
+ # This is necessary for both color and state populations...
252
+ # ... but we also need this for the kinetics calculations.
253
+ pops = h5io.IterBlockedDataset(self.assignments_file['labeled_populations'])
254
+ pops.cache_data()
255
+ pops.data = pops.data.sum(axis=2)
256
+
257
+ submit_kwargs = dict(
258
+ pi=pi, nstates=self.nstates, start_iter=self.start_iter, stop_iter=self.stop_iter, step_iter=self.step_iter
259
+ )
260
+
261
+ # Calculate averages for the simulation, then report, if necessary.
262
+
263
+ submit_kwargs['dataset'] = {'dataset': cond_fluxes, 'pops': pops}
264
+ avg_rates = self.run_calculation(
265
+ eval_block=_rate_eval_block, name='Rate Evolution', dim=2, do_averages=True, **submit_kwargs
266
+ )
267
+ self.output_file.replace_dataset('avg_rates', data=avg_rates[1])
268
+
269
+ submit_kwargs['dataset'] = {'dataset': cond_fluxes}
270
+ avg_conditional_fluxes = self.run_calculation(
271
+ eval_block=_2D_simple_eval_block, name='Conditional Flux Evolution', dim=2, do_averages=True, **submit_kwargs
272
+ )
273
+ self.output_file.replace_dataset('avg_conditional_fluxes', data=avg_conditional_fluxes[1])
274
+
275
+ submit_kwargs['dataset'] = {'dataset': total_fluxes}
276
+ avg_total_fluxes = self.run_calculation(
277
+ eval_block=_1D_simple_eval_block, name='Target Flux Evolution', dim=1, do_averages=True, **submit_kwargs
278
+ )
279
+ self.output_file.replace_dataset('avg_total_fluxes', data=avg_total_fluxes[1])
280
+
281
+ # Now, print them!
282
+
283
+ # We've returned an average, but it still exists in a timeslice format. So we need to return the 'last' value.
284
+ if self.display_averages:
285
+ self.print_averages(avg_total_fluxes[1], '\nfluxes into macrostates:', dim=1)
286
+ self.print_averages(avg_conditional_fluxes[1], '\nfluxes from state to state:', dim=2)
287
+ self.print_averages(avg_rates[1], '\nrates from state to state:', dim=2)
288
+
289
+ # Do a bootstrap evolution.
290
+ submit_kwargs['dataset'] = {'dataset': cond_fluxes, 'pops': pops}
291
+ rate_evol = self.run_calculation(eval_block=_rate_eval_block, name='Rate Evolution', dim=2, **submit_kwargs)
292
+ self.output_file.replace_dataset('rate_evolution', data=rate_evol, shuffle=True, compression=9)
293
+
294
+ submit_kwargs['dataset'] = {'dataset': cond_fluxes}
295
+ rate_evol = self.run_calculation(
296
+ eval_block=_2D_simple_eval_block, name='Conditional Flux Evolution', dim=2, **submit_kwargs
297
+ )
298
+ self.output_file.replace_dataset('conditional_flux_evolution', data=rate_evol, shuffle=True, compression=9)
299
+
300
+ submit_kwargs['dataset'] = {'dataset': total_fluxes}
301
+ rate_evol = self.run_calculation(eval_block=_1D_simple_eval_block, name='Target Flux Evolution', dim=1, **submit_kwargs)
302
+ self.output_file.replace_dataset('target_flux_evolution', data=rate_evol, shuffle=True, compression=9)
303
+
304
+ def go(self):
305
+ # Have class inherit user-provided self.output_filename as self.kinetics_filename
306
+ self.kinetics_filename = self.output_filename
307
+
308
+ pi = self.progress.indicator
309
+ with pi:
310
+ self.w_kinavg()
311
+
312
+
313
+ # The old w_stateprobs
314
+ class DStateProbs(AverageCommands):
315
+ subcommand = 'probs'
316
+ help_text = 'Calculates color and state probabilities via tracing.'
317
+ default_kinetics_file = 'direct.h5'
318
+ description = '''\
319
+ Calculate average populations and associated errors in state populations from
320
+ weighted ensemble data. Bin assignments, including macrostate definitions,
321
+ are required. (See "w_assign --help" for more information).
322
+
323
+ -----------------------------------------------------------------------------
324
+ Output format
325
+ -----------------------------------------------------------------------------
326
+
327
+ The output file (-o/--output, usually "direct.h5") contains the following
328
+ dataset:
329
+
330
+ /avg_state_probs [state]
331
+ (Structured -- see below) Population of each state across entire
332
+ range specified.
333
+
334
+ /avg_color_probs [state]
335
+ (Structured -- see below) Population of each ensemble across entire
336
+ range specified.
337
+
338
+ If --evolution-mode is specified, then the following additional datasets are
339
+ available:
340
+
341
+ /state_pop_evolution [window][state]
342
+ (Structured -- see below). State populations based on windows of
343
+ iterations of varying width. If --evolution-mode=cumulative, then
344
+ these windows all begin at the iteration specified with
345
+ --start-iter and grow in length by --step-iter for each successive
346
+ element. If --evolution-mode=blocked, then these windows are all of
347
+ width --step-iter (excluding the last, which may be shorter), the first
348
+ of which begins at iteration --start-iter.
349
+
350
+ /color_prob_evolution [window][state]
351
+ (Structured -- see below). Ensemble populations based on windows of
352
+ iterations of varying width. If --evolution-mode=cumulative, then
353
+ these windows all begin at the iteration specified with
354
+ --start-iter and grow in length by --step-iter for each successive
355
+ element. If --evolution-mode=blocked, then these windows are all of
356
+ width --step-iter (excluding the last, which may be shorter), the first
357
+ of which begins at iteration --start-iter.
358
+
359
+ The structure of these datasets is as follows:
360
+
361
+ iter_start
362
+ (Integer) Iteration at which the averaging window begins (inclusive).
363
+
364
+ iter_stop
365
+ (Integer) Iteration at which the averaging window ends (exclusive).
366
+
367
+ expected
368
+ (Floating-point) Expected (mean) value of the observable as evaluated within
369
+ this window, in units of inverse tau.
370
+
371
+ ci_lbound
372
+ (Floating-point) Lower bound of the confidence interval of the observable
373
+ within this window, in units of inverse tau.
374
+
375
+ ci_ubound
376
+ (Floating-point) Upper bound of the confidence interval of the observable
377
+ within this window, in units of inverse tau.
378
+
379
+ stderr
380
+ (Floating-point) The standard error of the mean of the observable
381
+ within this window, in units of inverse tau.
382
+
383
+ corr_len
384
+ (Integer) Correlation length of the observable within this window, in units
385
+ of tau.
386
+
387
+ Each of these datasets is also stamped with a number of attributes:
388
+
389
+ mcbs_alpha
390
+ (Floating-point) Alpha value of confidence intervals. (For example,
391
+ *alpha=0.05* corresponds to a 95% confidence interval.)
392
+
393
+ mcbs_nsets
394
+ (Integer) Number of bootstrap data sets used in generating confidence
395
+ intervals.
396
+
397
+ mcbs_acalpha
398
+ (Floating-point) Alpha value for determining correlation lengths.
399
+
400
+
401
+ -----------------------------------------------------------------------------
402
+ Command-line options
403
+ -----------------------------------------------------------------------------
404
+ '''
405
+
406
+ def calculate_state_populations(self, pops):
407
+ # ... but then this is how the state populations are done.
408
+ # This was taken, more or less, from the old w_stateprobs
409
+ iter_count = self.stop_iter - self.start_iter
410
+ all_state_pops = np.empty((iter_count, self.nstates + 1), weight_dtype)
411
+ iter_state_pops = np.empty((self.nstates + 1,), weight_dtype)
412
+ avg_state_pops = np.zeros((self.nstates + 1,), weight_dtype)
413
+ pops.cache_data(max_size='available')
414
+ state_map = self.assignments_file['state_map'][...]
415
+ try:
416
+ for iiter, n_iter in enumerate(range(self.start_iter, self.stop_iter)):
417
+ iter_state_pops.fill(0)
418
+ labeled_pops = pops.iter_entry(n_iter)
419
+ accumulate_state_populations_from_labeled(labeled_pops, state_map, iter_state_pops, check_state_map=False)
420
+ all_state_pops[iiter] = iter_state_pops
421
+ avg_state_pops += iter_state_pops
422
+ del labeled_pops
423
+ finally:
424
+ pops.drop_cache()
425
+
426
+ state_pops = h5io.IterBlockedDataset.empty_like(pops)
427
+ state_pops.data = all_state_pops
428
+ return state_pops
429
+
430
+ def w_stateprobs(self):
431
+ pi = self.progress.indicator
432
+
433
+ self.open_files()
434
+ self.open_assignments()
435
+ # So far, we definitely need this boilerplate...
436
+ # pi.new_operation('Reading data')
437
+
438
+ # This is necessary for both color and state populations...
439
+ pops = h5io.IterBlockedDataset(self.assignments_file['labeled_populations'])
440
+
441
+ state_pops = self.calculate_state_populations(pops)
442
+
443
+ # This now sorts it for the color populations
444
+ pops.cache_data()
445
+ pops.data = pops.data.sum(axis=2)
446
+
447
+ submit_kwargs = dict(
448
+ pi=pi,
449
+ nstates=self.nstates,
450
+ start_iter=self.start_iter,
451
+ stop_iter=self.stop_iter,
452
+ step_iter=self.step_iter,
453
+ eval_block=_1D_simple_eval_block,
454
+ )
455
+
456
+ # Calculate and print averages
457
+ submit_kwargs['dataset'] = {'dataset': pops}
458
+ color_evol_avg = self.run_calculation(name='Color Probability Evolution', dim=1, do_averages=True, **submit_kwargs)
459
+ self.output_file.replace_dataset('avg_color_probs', data=color_evol_avg[1], shuffle=True, compression=9)
460
+
461
+ submit_kwargs['dataset'] = {'dataset': state_pops}
462
+ state_evol_avg = self.run_calculation(name='State Probability Evolution', dim=1, do_averages=True, **submit_kwargs)
463
+ self.output_file.replace_dataset(name='avg_state_probs', data=state_evol_avg[1], shuffle=True, compression=9)
464
+
465
+ # Print!
466
+ if self.display_averages:
467
+ self.print_averages(color_evol_avg[1], '\naverage color probabilities:', dim=1)
468
+ self.print_averages(state_evol_avg[1], '\naverage state probabilities:', dim=1)
469
+
470
+ # Now, do a bootstrap evolution
471
+ submit_kwargs['dataset'] = {'dataset': pops}
472
+ pop_evol = self.run_calculation(name='Color Probability Evolution', dim=1, **submit_kwargs)
473
+ self.output_file.replace_dataset('color_prob_evolution', data=pop_evol, shuffle=True, compression=9)
474
+
475
+ submit_kwargs['dataset'] = {'dataset': state_pops}
476
+ pop_evol = self.run_calculation(name='State Probability Evolution', dim=1, **submit_kwargs)
477
+ self.output_file.replace_dataset(name='state_pop_evolution', data=pop_evol, shuffle=True, compression=9)
478
+
479
+ def go(self):
480
+ # Have class inherit user-provided self.output_filename as self.kinetics_filename
481
+ self.kinetics_filename = self.output_filename
482
+
483
+ pi = self.progress.indicator
484
+ with pi:
485
+ self.w_stateprobs()
486
+
487
+
488
+ # Just a convenience class to run everything.
489
+ class DAll(DStateProbs, DKinAvg, DKinetics):
490
+ subcommand = 'all'
491
+ help_text = 'Runs the full suite, including the tracing of events.'
492
+ default_kinetics_file = 'direct.h5'
493
+ description = '''\
494
+ A convenience function to run init/kinetics/probs. Bin assignments,
495
+ including macrostate definitions, are required. (See
496
+ "w_assign --help" for more information).
497
+
498
+ For more information on the individual subcommands this subs in for, run
499
+ w_direct {init/kinetics/probs} --help.
500
+
501
+ -----------------------------------------------------------------------------
502
+ Command-line options
503
+ -----------------------------------------------------------------------------
504
+ '''
505
+
506
+ def go(self):
507
+ # Have class inherit user-provided self.output_filename as self.kinetics_filename
508
+ self.kinetics_filename = self.output_filename
509
+
510
+ pi = self.progress.indicator
511
+ with pi:
512
+ self.w_kinetics()
513
+ self.w_kinavg()
514
+ self.w_stateprobs()
515
+
516
+
517
+ # Just a convenience class to average the observables.
518
+ class DAverage(DStateProbs, DKinAvg):
519
+ subcommand = 'average'
520
+ help_text = 'Averages and returns fluxes, rates, and color/state populations.'
521
+ default_kinetics_file = 'direct.h5'
522
+ description = '''\
523
+ A convenience function to run kinetics/probs. Bin assignments,
524
+ including macrostate definitions, are required. (See
525
+ "w_assign --help" for more information).
526
+
527
+ For more information on the individual subcommands this subs in for, run
528
+ w_direct {kinetics/probs} --help.
529
+
530
+ -----------------------------------------------------------------------------
531
+ Command-line options
532
+ -----------------------------------------------------------------------------
533
+ '''
534
+
535
+ def go(self):
536
+ # Have class inherit user-provided self.output_filename as self.kinetics_filename
537
+ self.kinetics_filename = self.output_filename
538
+
539
+ pi = self.progress.indicator
540
+ with pi:
541
+ self.w_kinavg()
542
+ self.w_stateprobs()
543
+
544
+
545
+ class WDirect(WESTMasterCommand, WESTParallelTool):
546
+ prog = 'w_direct'
547
+ # subcommands = [AvgTraceSubcommand,AvgMatrixSubcommand]
548
+ subcommands = [DKinetics, DAverage, DKinAvg, DStateProbs, DAll]
549
+ subparsers_title = 'direct kinetics analysis schemes'
550
+
551
+
552
+ def entry_point():
553
+ WDirect().main()
554
+
555
+
556
+ if __name__ == '__main__':
557
+ entry_point()
@@ -0,0 +1,94 @@
1
+ import logging
2
+ import sys
3
+
4
+ from warnings import warn
5
+ from westpa.tools import WESTTool, WESTDataReader
6
+ from westpa.core.segment import Segment
7
+
8
+ log = logging.getLogger('w_dumpsegs')
9
+
10
+
11
+ class WDumpSegs(WESTTool):
12
+ prog = 'w_dumpsegs'
13
+ description = '''\
14
+ Dump segment data as text. This is very inefficient, so this tool should be used
15
+ as a last resort (use hdfview/h5ls to look at data, and access HDF5 directly for
16
+ significant analysis tasks).
17
+ '''
18
+
19
+ def __init__(self):
20
+ super().__init__()
21
+ self.data_reader = WESTDataReader()
22
+ self.n_iter = None
23
+ self.output_file = None
24
+ self.print_pcoords = False
25
+
26
+ def add_args(self, parser):
27
+ self.data_reader.add_args(parser)
28
+
29
+ parser.add_argument(
30
+ '-p',
31
+ '--print-pcoords',
32
+ dest='print_pcoords',
33
+ action='store_true',
34
+ help='print initial and final progress coordinates for each segment',
35
+ )
36
+ parser.add_argument(
37
+ '-i', '--iteration', dest='n_iter', type=int, help='Use data from iteration N_ITER (default: last complete iteration)'
38
+ )
39
+ parser.add_argument(
40
+ '-o', '--output', dest='output_file', help='Store output in OUTPUT_FILE (default: write to standard output).'
41
+ )
42
+
43
+ def process_args(self, args):
44
+ self.data_reader.process_args(args)
45
+ self.data_reader.open()
46
+ self.n_iter = args.n_iter or self.data_reader.current_iteration - 1
47
+ self.output_file = open(args.output_file, 'wt') if args.output_file else sys.stdout
48
+ self.print_pcoords = args.print_pcoords
49
+
50
+ def go(self):
51
+ segments = self.data_reader.get_segments(self.n_iter)
52
+
53
+ max_seg_id_len = len(str(max(segment.seg_id for segment in segments)))
54
+ max_status_name_len = max(list(map(len, iter(Segment.status_names.values()))))
55
+ max_endpoint_type_len = max(list(map(len, iter(Segment.endpoint_type_names.values()))))
56
+ max_n_parents_len = len(str(max(len(segment.wtg_parent_ids) for segment in segments)))
57
+
58
+ report_line = (
59
+ '{segment.n_iter:d} {segment.seg_id:{max_seg_id_len}d} {segment.weight:20.14g}'
60
+ + ' {status_name:{max_status_name_len}s} ({segment.status})'
61
+ + ' {segment.walltime:<12.6g} {segment.cputime:<12.6g}'
62
+ + ' {endpoint_type_name:{max_endpoint_type_len}s} ({segment.endpoint_type})'
63
+ + ' {n_parents:{max_n_parents_len}d} {segment.parent_id:{max_seg_id_len}d} {parents_str}'
64
+ + '\n'
65
+ )
66
+ pcoord_lines = ' pcoord[0] = {init_pcoord}\n pcoord[-1] = {final_pcoord}' + '\n'
67
+ for _seg_id, segment in enumerate(segments):
68
+ parents_str = '[' + ', '.join(map(str, sorted(segment.wtg_parent_ids))) + ']'
69
+ init_pcoord_str = '[' + ', '.join('{pcval:<12.6g}'.format(pcval=float(pce)) for pce in segment.pcoord[0]) + ']'
70
+ final_pcoord_str = '[' + ', '.join('{pcval:<12.6g}'.format(pcval=float(pce)) for pce in segment.pcoord[-1]) + ']'
71
+ self.output_file.write(
72
+ report_line.format(
73
+ segment=segment,
74
+ status_name=segment.status_names[segment.status],
75
+ endpoint_type_name=segment.endpoint_type_names[segment.endpoint_type],
76
+ parents_str=parents_str,
77
+ n_parents=len(segment.wtg_parent_ids),
78
+ max_seg_id_len=max_seg_id_len,
79
+ max_status_name_len=max_status_name_len,
80
+ max_endpoint_type_len=max_endpoint_type_len,
81
+ max_n_parents_len=max_n_parents_len,
82
+ )
83
+ )
84
+ if self.print_pcoords:
85
+ self.output_file.write(pcoord_lines.format(init_pcoord=init_pcoord_str, final_pcoord=final_pcoord_str))
86
+
87
+
88
+ def entry_point():
89
+ warn('w_dumpsegs is being deprecated.')
90
+ WDumpSegs().main()
91
+
92
+
93
+ if __name__ == '__main__':
94
+ entry_point()