westpa 2022.12__cp312-cp312-macosx_10_13_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 (149) 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 +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 +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 +376 -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 +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_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 +455 -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 +506 -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 +719 -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 +835 -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 +910 -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/_fasthist.cpython-312-darwin.so +0 -0
  75. westpa/mclib/__init__.py +271 -0
  76. westpa/mclib/__main__.py +28 -0
  77. westpa/mclib/_mclib.cpython-312-darwin.so +0 -0
  78. westpa/oldtools/__init__.py +4 -0
  79. westpa/oldtools/aframe/__init__.py +35 -0
  80. westpa/oldtools/aframe/atool.py +75 -0
  81. westpa/oldtools/aframe/base_mixin.py +26 -0
  82. westpa/oldtools/aframe/binning.py +178 -0
  83. westpa/oldtools/aframe/data_reader.py +560 -0
  84. westpa/oldtools/aframe/iter_range.py +200 -0
  85. westpa/oldtools/aframe/kinetics.py +117 -0
  86. westpa/oldtools/aframe/mcbs.py +153 -0
  87. westpa/oldtools/aframe/output.py +39 -0
  88. westpa/oldtools/aframe/plotting.py +90 -0
  89. westpa/oldtools/aframe/trajwalker.py +126 -0
  90. westpa/oldtools/aframe/transitions.py +469 -0
  91. westpa/oldtools/cmds/__init__.py +0 -0
  92. westpa/oldtools/cmds/w_ttimes.py +361 -0
  93. westpa/oldtools/files.py +34 -0
  94. westpa/oldtools/miscfn.py +23 -0
  95. westpa/oldtools/stats/__init__.py +4 -0
  96. westpa/oldtools/stats/accumulator.py +35 -0
  97. westpa/oldtools/stats/edfs.py +129 -0
  98. westpa/oldtools/stats/mcbs.py +96 -0
  99. westpa/tools/__init__.py +33 -0
  100. westpa/tools/binning.py +472 -0
  101. westpa/tools/core.py +340 -0
  102. westpa/tools/data_reader.py +159 -0
  103. westpa/tools/dtypes.py +31 -0
  104. westpa/tools/iter_range.py +198 -0
  105. westpa/tools/kinetics_tool.py +340 -0
  106. westpa/tools/plot.py +283 -0
  107. westpa/tools/progress.py +17 -0
  108. westpa/tools/selected_segs.py +154 -0
  109. westpa/tools/wipi.py +751 -0
  110. westpa/trajtree/__init__.py +4 -0
  111. westpa/trajtree/_trajtree.cpython-312-darwin.so +0 -0
  112. westpa/trajtree/trajtree.py +117 -0
  113. westpa/westext/__init__.py +0 -0
  114. westpa/westext/adaptvoronoi/__init__.py +3 -0
  115. westpa/westext/adaptvoronoi/adaptVor_driver.py +214 -0
  116. westpa/westext/hamsm_restarting/__init__.py +3 -0
  117. westpa/westext/hamsm_restarting/example_overrides.py +35 -0
  118. westpa/westext/hamsm_restarting/restart_driver.py +1165 -0
  119. westpa/westext/stringmethod/__init__.py +11 -0
  120. westpa/westext/stringmethod/fourier_fitting.py +69 -0
  121. westpa/westext/stringmethod/string_driver.py +253 -0
  122. westpa/westext/stringmethod/string_method.py +306 -0
  123. westpa/westext/weed/BinCluster.py +180 -0
  124. westpa/westext/weed/ProbAdjustEquil.py +100 -0
  125. westpa/westext/weed/UncertMath.py +247 -0
  126. westpa/westext/weed/__init__.py +10 -0
  127. westpa/westext/weed/weed_driver.py +192 -0
  128. westpa/westext/wess/ProbAdjust.py +101 -0
  129. westpa/westext/wess/__init__.py +6 -0
  130. westpa/westext/wess/wess_driver.py +217 -0
  131. westpa/work_managers/__init__.py +57 -0
  132. westpa/work_managers/core.py +396 -0
  133. westpa/work_managers/environment.py +134 -0
  134. westpa/work_managers/mpi.py +318 -0
  135. westpa/work_managers/processes.py +187 -0
  136. westpa/work_managers/serial.py +28 -0
  137. westpa/work_managers/threads.py +79 -0
  138. westpa/work_managers/zeromq/__init__.py +20 -0
  139. westpa/work_managers/zeromq/core.py +641 -0
  140. westpa/work_managers/zeromq/node.py +131 -0
  141. westpa/work_managers/zeromq/work_manager.py +526 -0
  142. westpa/work_managers/zeromq/worker.py +320 -0
  143. westpa-2022.12.dist-info/AUTHORS +22 -0
  144. westpa-2022.12.dist-info/LICENSE +21 -0
  145. westpa-2022.12.dist-info/METADATA +193 -0
  146. westpa-2022.12.dist-info/RECORD +149 -0
  147. westpa-2022.12.dist-info/WHEEL +6 -0
  148. westpa-2022.12.dist-info/entry_points.txt +29 -0
  149. westpa-2022.12.dist-info/top_level.txt +1 -0
@@ -0,0 +1,330 @@
1
+ import numpy as np
2
+ import os
3
+
4
+ from mdtraj import Trajectory, load as load_traj, FormatRegistry, formats as mdformats
5
+ from mdtraj.core.trajectory import _TOPOLOGY_EXTS, _get_extension as get_extension
6
+
7
+ FormatRegistry.loaders['.rst'] = mdformats.amberrst.load_restrt
8
+ FormatRegistry.fileobjects['.rst'] = mdformats.AmberRestartFile
9
+
10
+ TRAJECTORY_EXTS = list(FormatRegistry.loaders.keys())
11
+ TOPOLOGY_EXTS = list(_TOPOLOGY_EXTS)
12
+ for ext in [".h5", ".hdf5", ".lh5"]:
13
+ TOPOLOGY_EXTS.remove(ext)
14
+
15
+
16
+ class WESTTrajectory(Trajectory):
17
+ '''A subclass of ``mdtraj.Trajectory`` that contains the trajectory of atom coordinates with
18
+ pointers denoting the iteration number and segment index of each frame.'''
19
+
20
+ def __init__(
21
+ self,
22
+ coordinates,
23
+ topology=None,
24
+ time=None,
25
+ iter_labels=None,
26
+ seg_labels=None,
27
+ pcoords=None,
28
+ parent_ids=None,
29
+ unitcell_lengths=None,
30
+ unitcell_angles=None,
31
+ ):
32
+ if isinstance(coordinates, Trajectory):
33
+ xyz = coordinates.xyz
34
+ topology = coordinates.topology if topology is None else topology
35
+ time = coordinates.time if time is None else time
36
+ unitcell_lengths = coordinates.unitcell_lengths if unitcell_lengths is None else unitcell_lengths
37
+ unitcell_angles = coordinates.unitcell_angles if unitcell_angles is None else unitcell_angles
38
+ else:
39
+ xyz = coordinates
40
+
41
+ super(WESTTrajectory, self).__init__(xyz, topology, time, unitcell_lengths, unitcell_angles)
42
+ self._shape = None
43
+ self.iter_labels = iter_labels
44
+ self.seg_labels = seg_labels
45
+ self.pcoords = pcoords
46
+ self.parent_ids = parent_ids
47
+
48
+ def _string_summary_basic(self):
49
+ """Basic summary of WESTTrajectory in string form."""
50
+ unitcell_str = 'and unitcells' if self._have_unitcell else 'without unitcells'
51
+ value = "%s with %d frames, %d atoms, %d residues, %s" % (
52
+ self.__class__.__name__,
53
+ self.n_frames,
54
+ self.n_atoms,
55
+ self.n_residues,
56
+ unitcell_str,
57
+ )
58
+ return value
59
+
60
+ def _check_labels(self, value):
61
+ if value is None:
62
+ value = 0
63
+ elif isinstance(value, list):
64
+ value = np.array(value)
65
+
66
+ if np.isscalar(value):
67
+ value = np.array([value] * self.n_frames, dtype=int)
68
+ elif value.shape != (self.n_frames,):
69
+ raise ValueError('Wrong shape. Got %s, should be %s' % (value.shape, (self.n_frames,)))
70
+
71
+ return value
72
+
73
+ def _check_pcoords(self, value):
74
+ if value is None:
75
+ value = 0.0
76
+ elif isinstance(value, list):
77
+ value = np.array(value)
78
+
79
+ if np.isscalar(value):
80
+ value = np.array([(value,)] * self.n_frames, dtype=float)
81
+
82
+ if value.ndim == 1:
83
+ value = np.tile(value, (self.n_frames, 1))
84
+ elif value.ndim != 2:
85
+ raise ValueError('pcoords must be a 2-D array')
86
+
87
+ elif value.shape[0] != self.n_frames:
88
+ raise ValueError('Wrong length. Got %s, should be %s' % (value.shape[0], self.n_frames))
89
+
90
+ return value
91
+
92
+ def iter_label_values(self):
93
+ visited_ids = []
94
+
95
+ for i in self.iter_labels:
96
+ if i in visited_ids:
97
+ continue
98
+ visited_ids.append(i)
99
+ yield i
100
+
101
+ def seg_label_values(self, iteration=None):
102
+ seg_labels = self.seg_labels[self.iter_labels == iteration]
103
+ visited_ids = []
104
+
105
+ for j in seg_labels:
106
+ if j in visited_ids:
107
+ continue
108
+ visited_ids.append(j)
109
+ yield j
110
+
111
+ @property
112
+ def label_values(self):
113
+ for i in self.iter_label_values():
114
+ for j in self.seg_label_values(i):
115
+ yield i, j
116
+
117
+ def _iter_blocks(self):
118
+ for i, j in self.label_values:
119
+ IandJ = np.logical_and(self.iter_labels == i, self.seg_labels == j)
120
+ yield i, j, IandJ
121
+
122
+ @property
123
+ def iter_labels(self):
124
+ """Iteration index corresponding to each frame
125
+
126
+ Returns
127
+ -------
128
+ time : np.ndarray, shape=(n_frames,)
129
+ The iteration index corresponding to each frame
130
+ """
131
+ return self._iters
132
+
133
+ @iter_labels.setter
134
+ def iter_labels(self, value):
135
+ "Set the iteration index corresponding to each frame"
136
+
137
+ self._iters = self._check_labels(value)
138
+ self._shape = None
139
+
140
+ @property
141
+ def seg_labels(self):
142
+ """Segment index corresponding to each frame
143
+
144
+ Returns
145
+ -------
146
+ time : np.ndarray, shape=(n_frames,)
147
+ The segment index corresponding to each frame
148
+ """
149
+ return self._segs
150
+
151
+ @seg_labels.setter
152
+ def seg_labels(self, value):
153
+ "Set the segment index corresponding to each frame"
154
+
155
+ self._segs = self._check_labels(value)
156
+ self._shape = None
157
+
158
+ @property
159
+ def pcoords(self):
160
+ return self._pcoords
161
+
162
+ @pcoords.setter
163
+ def pcoords(self, value):
164
+ self._pcoords = self._check_pcoords(value)
165
+
166
+ @property
167
+ def parent_ids(self):
168
+ return self._parent_ids
169
+
170
+ @parent_ids.setter
171
+ def parent_ids(self, value):
172
+ self._parent_ids = self._check_labels(value)
173
+
174
+ def join(self, other, check_topology=True, discard_overlapping_frames=False):
175
+ """Join two ``Trajectory``s. This overrides ``mdtraj.Trajectory.join``
176
+ so that it also handles WESTPA pointers.
177
+ ``mdtraj.Trajectory.join``'s documentation for more details.
178
+ """
179
+ if isinstance(other, Trajectory):
180
+ other = [other]
181
+
182
+ new_traj = super(WESTTrajectory, self).join(
183
+ other, check_topology=check_topology, discard_overlapping_frames=discard_overlapping_frames
184
+ )
185
+
186
+ trajectories = [self] + other
187
+ if discard_overlapping_frames:
188
+ for i in range(len(trajectories) - 1):
189
+ x0 = trajectories[i].xyz[-1]
190
+ x1 = trajectories[i + 1].xyz[0]
191
+
192
+ if np.all(np.abs(x1 - x0) < 2e-3):
193
+ trajectories[i] = trajectories[i][:-1]
194
+
195
+ iter_labels = []
196
+ seg_labels = []
197
+ parent_ids = []
198
+ pshape = self.pcoords.shape
199
+ pcoords = []
200
+
201
+ for t in trajectories:
202
+ if hasattr(t, "iter_labels"):
203
+ iters = t.iter_labels
204
+ else:
205
+ iters = np.zeros(len(t)) - 1 # default iter label: -1
206
+
207
+ iter_labels.append(iters)
208
+
209
+ if hasattr(t, "seg_labels"):
210
+ segs = t.seg_labels
211
+ else:
212
+ segs = np.zeros(len(t)) - 1 # default seg label: -1
213
+
214
+ seg_labels.append(segs)
215
+
216
+ if hasattr(t, "parent_ids"):
217
+ pids = t.parent_ids
218
+ else:
219
+ pids = np.zeros(len(t)) - 1 # default parent_id: -1
220
+
221
+ parent_ids.append(pids)
222
+
223
+ if hasattr(t, "pcoords"):
224
+ p = t.pcoords
225
+ else:
226
+ p = np.zeros((len(t), pshape[-1]), dtype=float) # default pcoord: 0.0
227
+
228
+ pcoords.append(p)
229
+
230
+ iter_labels = np.concatenate(iter_labels)
231
+ seg_labels = np.concatenate(seg_labels)
232
+ parent_ids = np.concatenate(parent_ids)
233
+ pcoords = np.concatenate(pcoords)
234
+
235
+ new_westpa_traj = WESTTrajectory(
236
+ new_traj, iter_labels=iter_labels, seg_labels=seg_labels, pcoords=pcoords, parent_ids=parent_ids
237
+ )
238
+
239
+ return new_westpa_traj
240
+
241
+ def slice(self, key, copy=True):
242
+ """Slice the ``Trajectory``. This overrides ``mdtraj.Trajectory.slice``
243
+ so that it also handles WESTPA pointers. Please see
244
+ ``mdtraj.Trajectory.slice``'s documentation for more details.
245
+ """
246
+
247
+ if isinstance(key, tuple):
248
+ if self._shape is None:
249
+ uniq_iters = np.unique(self.iter_labels)
250
+ max_iter = uniq_iters.max()
251
+ max_seg = self.seg_labels.max()
252
+ max_n_trajs = 0
253
+ for _, _, block in self._iter_blocks():
254
+ n_trajs = block.sum()
255
+ if n_trajs > max_n_trajs:
256
+ max_n_trajs = n_trajs
257
+
258
+ self._shape = (max_iter, max_seg, max_n_trajs)
259
+ else:
260
+ max_iter, max_seg, max_n_trajs = self._shape
261
+
262
+ M = np.full((max_iter + 1, max_seg + 1, max_n_trajs), -1, dtype=int)
263
+ all_traj_indices = np.arange(self.n_frames, dtype=int)
264
+ for i, j, block in self._iter_blocks():
265
+ traj_indices = all_traj_indices[block]
266
+
267
+ for k, traj_idx in enumerate(traj_indices):
268
+ M[i, j, k] = traj_idx
269
+
270
+ selected_indices = M[key].flatten()
271
+ if np.isscalar(selected_indices):
272
+ selected_indices = np.array([selected_indices])
273
+ key = selected_indices[selected_indices != -1]
274
+
275
+ iters = self.iter_labels[key]
276
+ segs = self.seg_labels[key]
277
+ pcoords = self.pcoords[key, :]
278
+ parent_ids = self.parent_ids[key]
279
+
280
+ traj = super(WESTTrajectory, self).slice(key, copy)
281
+ traj.iter_labels = iters
282
+ traj.seg_labels = segs
283
+ traj.pcoords = pcoords
284
+ traj.parent_ids = parent_ids
285
+
286
+ return traj
287
+
288
+
289
+ def load_trajectory(folder):
290
+ '''Load trajectory from ``folder`` using ``mdtraj`` and return a ``mdtraj.Trajectory``
291
+ object. The folder should contain a trajectory and a topology file (with a recognizable
292
+ extension) that is supported by ``mdtraj``. The topology file is optional if the
293
+ trajectory file contains topology data (e.g., HDF5 format).
294
+ '''
295
+ traj_file = top_file = None
296
+ file_list = [f_name for f_name in os.listdir(folder) if not f_name.startswith('.')]
297
+
298
+ for filename in file_list:
299
+ filepath = os.path.join(folder, filename)
300
+ if not os.path.isfile(filepath):
301
+ continue
302
+
303
+ ext = get_extension(filename).lower()
304
+ # Catching trajectory formats that can be topology and trajectories at the same time.
305
+ # Only activates when there is a single file.
306
+ if len(file_list) < 2 and ext in TOPOLOGY_EXTS and ext in TRAJECTORY_EXTS:
307
+ top_file = filename
308
+ traj_file = filename
309
+
310
+ # Assuming topology file is copied first.
311
+ if ext in TOPOLOGY_EXTS and top_file is None:
312
+ top_file = filename
313
+ elif ext in TRAJECTORY_EXTS and traj_file is None:
314
+ traj_file = filename
315
+
316
+ if top_file is not None and traj_file is not None:
317
+ break
318
+
319
+ if traj_file is None:
320
+ raise ValueError('trajectory file not found')
321
+
322
+ traj_file = os.path.join(folder, traj_file)
323
+
324
+ kwargs = {}
325
+ if top_file is not None:
326
+ top_file = os.path.join(folder, top_file)
327
+ kwargs['top'] = top_file
328
+
329
+ traj = load_traj(traj_file, **kwargs)
330
+ return traj