westpa 2022.10__cp312-cp312-macosx_11_0_arm64.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.
- westpa/__init__.py +14 -0
- westpa/_version.py +21 -0
- westpa/analysis/__init__.py +5 -0
- westpa/analysis/core.py +746 -0
- westpa/analysis/statistics.py +27 -0
- westpa/analysis/trajectories.py +360 -0
- westpa/cli/__init__.py +0 -0
- westpa/cli/core/__init__.py +0 -0
- westpa/cli/core/w_fork.py +152 -0
- westpa/cli/core/w_init.py +230 -0
- westpa/cli/core/w_run.py +77 -0
- westpa/cli/core/w_states.py +212 -0
- westpa/cli/core/w_succ.py +99 -0
- westpa/cli/core/w_truncate.py +59 -0
- westpa/cli/tools/__init__.py +0 -0
- westpa/cli/tools/ploterr.py +506 -0
- westpa/cli/tools/plothist.py +706 -0
- westpa/cli/tools/w_assign.py +596 -0
- westpa/cli/tools/w_bins.py +166 -0
- westpa/cli/tools/w_crawl.py +119 -0
- westpa/cli/tools/w_direct.py +547 -0
- westpa/cli/tools/w_dumpsegs.py +94 -0
- westpa/cli/tools/w_eddist.py +506 -0
- westpa/cli/tools/w_fluxanl.py +378 -0
- westpa/cli/tools/w_ipa.py +833 -0
- westpa/cli/tools/w_kinavg.py +127 -0
- westpa/cli/tools/w_kinetics.py +96 -0
- westpa/cli/tools/w_multi_west.py +414 -0
- westpa/cli/tools/w_ntop.py +213 -0
- westpa/cli/tools/w_pdist.py +515 -0
- westpa/cli/tools/w_postanalysis_matrix.py +82 -0
- westpa/cli/tools/w_postanalysis_reweight.py +53 -0
- westpa/cli/tools/w_red.py +486 -0
- westpa/cli/tools/w_reweight.py +780 -0
- westpa/cli/tools/w_select.py +226 -0
- westpa/cli/tools/w_stateprobs.py +111 -0
- westpa/cli/tools/w_trace.py +599 -0
- westpa/core/__init__.py +0 -0
- westpa/core/_rc.py +673 -0
- westpa/core/binning/__init__.py +55 -0
- westpa/core/binning/_assign.cpython-312-darwin.so +0 -0
- westpa/core/binning/assign.py +449 -0
- westpa/core/binning/binless.py +96 -0
- westpa/core/binning/binless_driver.py +54 -0
- westpa/core/binning/binless_manager.py +190 -0
- westpa/core/binning/bins.py +47 -0
- westpa/core/binning/mab.py +427 -0
- westpa/core/binning/mab_driver.py +54 -0
- westpa/core/binning/mab_manager.py +198 -0
- westpa/core/data_manager.py +1694 -0
- westpa/core/extloader.py +74 -0
- westpa/core/h5io.py +995 -0
- westpa/core/kinetics/__init__.py +24 -0
- westpa/core/kinetics/_kinetics.cpython-312-darwin.so +0 -0
- westpa/core/kinetics/events.py +147 -0
- westpa/core/kinetics/matrates.py +156 -0
- westpa/core/kinetics/rate_averaging.py +266 -0
- westpa/core/progress.py +218 -0
- westpa/core/propagators/__init__.py +54 -0
- westpa/core/propagators/executable.py +715 -0
- westpa/core/reweight/__init__.py +14 -0
- westpa/core/reweight/_reweight.cpython-312-darwin.so +0 -0
- westpa/core/reweight/matrix.py +126 -0
- westpa/core/segment.py +119 -0
- westpa/core/sim_manager.py +830 -0
- westpa/core/states.py +359 -0
- westpa/core/systems.py +93 -0
- westpa/core/textio.py +74 -0
- westpa/core/trajectory.py +330 -0
- westpa/core/we_driver.py +908 -0
- westpa/core/wm_ops.py +43 -0
- westpa/core/yamlcfg.py +391 -0
- westpa/fasthist/__init__.py +34 -0
- westpa/fasthist/__main__.py +110 -0
- westpa/fasthist/_fasthist.cpython-312-darwin.so +0 -0
- westpa/mclib/__init__.py +264 -0
- westpa/mclib/__main__.py +28 -0
- westpa/mclib/_mclib.cpython-312-darwin.so +0 -0
- westpa/oldtools/__init__.py +4 -0
- westpa/oldtools/aframe/__init__.py +35 -0
- westpa/oldtools/aframe/atool.py +75 -0
- westpa/oldtools/aframe/base_mixin.py +26 -0
- westpa/oldtools/aframe/binning.py +178 -0
- westpa/oldtools/aframe/data_reader.py +560 -0
- westpa/oldtools/aframe/iter_range.py +200 -0
- westpa/oldtools/aframe/kinetics.py +117 -0
- westpa/oldtools/aframe/mcbs.py +146 -0
- westpa/oldtools/aframe/output.py +39 -0
- westpa/oldtools/aframe/plotting.py +90 -0
- westpa/oldtools/aframe/trajwalker.py +126 -0
- westpa/oldtools/aframe/transitions.py +469 -0
- westpa/oldtools/cmds/__init__.py +0 -0
- westpa/oldtools/cmds/w_ttimes.py +358 -0
- westpa/oldtools/files.py +34 -0
- westpa/oldtools/miscfn.py +23 -0
- westpa/oldtools/stats/__init__.py +4 -0
- westpa/oldtools/stats/accumulator.py +35 -0
- westpa/oldtools/stats/edfs.py +129 -0
- westpa/oldtools/stats/mcbs.py +89 -0
- westpa/tools/__init__.py +33 -0
- westpa/tools/binning.py +472 -0
- westpa/tools/core.py +340 -0
- westpa/tools/data_reader.py +159 -0
- westpa/tools/dtypes.py +31 -0
- westpa/tools/iter_range.py +198 -0
- westpa/tools/kinetics_tool.py +340 -0
- westpa/tools/plot.py +283 -0
- westpa/tools/progress.py +17 -0
- westpa/tools/selected_segs.py +154 -0
- westpa/tools/wipi.py +751 -0
- westpa/trajtree/__init__.py +4 -0
- westpa/trajtree/_trajtree.cpython-312-darwin.so +0 -0
- westpa/trajtree/trajtree.py +117 -0
- westpa/westext/__init__.py +0 -0
- westpa/westext/adaptvoronoi/__init__.py +3 -0
- westpa/westext/adaptvoronoi/adaptVor_driver.py +214 -0
- westpa/westext/hamsm_restarting/__init__.py +3 -0
- westpa/westext/hamsm_restarting/example_overrides.py +35 -0
- westpa/westext/hamsm_restarting/restart_driver.py +1165 -0
- westpa/westext/stringmethod/__init__.py +11 -0
- westpa/westext/stringmethod/fourier_fitting.py +69 -0
- westpa/westext/stringmethod/string_driver.py +253 -0
- westpa/westext/stringmethod/string_method.py +306 -0
- westpa/westext/weed/BinCluster.py +180 -0
- westpa/westext/weed/ProbAdjustEquil.py +100 -0
- westpa/westext/weed/UncertMath.py +247 -0
- westpa/westext/weed/__init__.py +10 -0
- westpa/westext/weed/weed_driver.py +182 -0
- westpa/westext/wess/ProbAdjust.py +101 -0
- westpa/westext/wess/__init__.py +6 -0
- westpa/westext/wess/wess_driver.py +207 -0
- westpa/work_managers/__init__.py +57 -0
- westpa/work_managers/core.py +396 -0
- westpa/work_managers/environment.py +134 -0
- westpa/work_managers/mpi.py +318 -0
- westpa/work_managers/processes.py +187 -0
- westpa/work_managers/serial.py +28 -0
- westpa/work_managers/threads.py +79 -0
- westpa/work_managers/zeromq/__init__.py +20 -0
- westpa/work_managers/zeromq/core.py +641 -0
- westpa/work_managers/zeromq/node.py +131 -0
- westpa/work_managers/zeromq/work_manager.py +526 -0
- westpa/work_managers/zeromq/worker.py +320 -0
- westpa-2022.10.dist-info/AUTHORS +22 -0
- westpa-2022.10.dist-info/LICENSE +21 -0
- westpa-2022.10.dist-info/METADATA +183 -0
- westpa-2022.10.dist-info/RECORD +150 -0
- westpa-2022.10.dist-info/WHEEL +5 -0
- westpa-2022.10.dist-info/entry_points.txt +29 -0
- westpa-2022.10.dist-info/top_level.txt +1 -0
westpa/core/states.py
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
|
|
3
|
+
from westpa.core.segment import Segment
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BasisState:
|
|
7
|
+
'''Describes an basis (micro)state. These basis states are used to generate
|
|
8
|
+
initial states for new trajectories, either at the beginning of the simulation
|
|
9
|
+
(i.e. at w_init) or due to recycling.
|
|
10
|
+
|
|
11
|
+
:ivar state_id: Integer identifier of this state, usually set by the
|
|
12
|
+
data manager.
|
|
13
|
+
:ivar label: A descriptive label for this microstate (may be empty)
|
|
14
|
+
:ivar probability: Probability of this state to be selected when creating a
|
|
15
|
+
new trajectory.
|
|
16
|
+
:ivar pcoord: The representative progress coordinate of this state.
|
|
17
|
+
|
|
18
|
+
:ivar auxref: A user-provided (string) reference for locating data associated
|
|
19
|
+
with this state (usually a filesystem path).
|
|
20
|
+
'''
|
|
21
|
+
|
|
22
|
+
def __init__(self, label, probability, pcoord=None, auxref=None, state_id=None):
|
|
23
|
+
self.label = str(label, encoding="UTF-8") if type(label) is bytes else label
|
|
24
|
+
self.probability = probability
|
|
25
|
+
self.pcoord = np.atleast_1d(pcoord)
|
|
26
|
+
self.auxref = auxref
|
|
27
|
+
self.state_id = state_id
|
|
28
|
+
self.data = {}
|
|
29
|
+
|
|
30
|
+
def __repr__(self):
|
|
31
|
+
return '{} state_id={self.state_id!r} label={self.label!r} prob={self.probability!r} pcoord={self.pcoord!r}>'.format(
|
|
32
|
+
object.__repr__(self)[:-1], self=self
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def states_to_file(cls, states, fileobj):
|
|
37
|
+
'''Write a file defining basis states, which may then be read by `states_from_file()`.'''
|
|
38
|
+
|
|
39
|
+
if isinstance(fileobj, str):
|
|
40
|
+
fileobj = open(fileobj, 'wt')
|
|
41
|
+
|
|
42
|
+
max_label_len = max(8, max(len(state.label or '') for state in states))
|
|
43
|
+
max_auxref_len = max(8, max(len(state.auxref or '') for state in states))
|
|
44
|
+
fmt = (
|
|
45
|
+
'{state.label:<{max_label_len}s} {state.probability:12.7g} {auxref_str:<{max_auxref_len}s}'
|
|
46
|
+
' # state_id={state_id_str:s} pcoord={pcoord_str}\n'
|
|
47
|
+
)
|
|
48
|
+
fileobj.write(
|
|
49
|
+
'# {:{max_label_len}s} {:>12s} {:{max_auxref_len}s}\n'.format(
|
|
50
|
+
'Label', 'Probability', 'Auxref', max_label_len=max_label_len - 2, max_auxref_len=max_auxref_len
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
for state in states:
|
|
54
|
+
state_id_str = str(state.state_id) if state.state_id is not None else 'None'
|
|
55
|
+
pcoord_str = str(list(state.pcoord))
|
|
56
|
+
auxref_str = 'None' if state.auxref == b'' or state.auxref == "b''" else str(state.auxref)
|
|
57
|
+
fileobj.write(
|
|
58
|
+
fmt.format(
|
|
59
|
+
state=state,
|
|
60
|
+
pcoord_str=pcoord_str,
|
|
61
|
+
auxref_str=auxref_str,
|
|
62
|
+
state_id_str=state_id_str,
|
|
63
|
+
max_label_len=max_label_len,
|
|
64
|
+
max_auxref_len=max_auxref_len,
|
|
65
|
+
)
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
@classmethod
|
|
69
|
+
def states_from_file(cls, statefile):
|
|
70
|
+
'''Read a file defining basis states. Each line defines a state, and contains a label, the probability,
|
|
71
|
+
and optionally a data reference, separated by whitespace, as in::
|
|
72
|
+
|
|
73
|
+
unbound 1.0
|
|
74
|
+
|
|
75
|
+
or::
|
|
76
|
+
|
|
77
|
+
unbound_0 0.6 state0.pdb
|
|
78
|
+
unbound_1 0.4 state1.pdb
|
|
79
|
+
|
|
80
|
+
'''
|
|
81
|
+
states = []
|
|
82
|
+
lineno = 0
|
|
83
|
+
|
|
84
|
+
try:
|
|
85
|
+
open_statefile = open(statefile, 'rt')
|
|
86
|
+
except TypeError:
|
|
87
|
+
open_statefile = statefile
|
|
88
|
+
|
|
89
|
+
for line in open_statefile:
|
|
90
|
+
lineno += 1
|
|
91
|
+
|
|
92
|
+
# remove comment portion
|
|
93
|
+
line = line.partition('#')[0].strip()
|
|
94
|
+
if not line:
|
|
95
|
+
continue
|
|
96
|
+
|
|
97
|
+
fields = line.split()
|
|
98
|
+
label = fields[0]
|
|
99
|
+
try:
|
|
100
|
+
probability = float(fields[1])
|
|
101
|
+
except ValueError:
|
|
102
|
+
raise ValueError('invalid probability ({!r}) {} line {:d}'.format(fields[1], statefile, lineno))
|
|
103
|
+
|
|
104
|
+
try:
|
|
105
|
+
auxref = fields[2].strip()
|
|
106
|
+
except IndexError:
|
|
107
|
+
auxref = None
|
|
108
|
+
|
|
109
|
+
states.append(cls(state_id=None, probability=probability, label=label, auxref=auxref))
|
|
110
|
+
|
|
111
|
+
try:
|
|
112
|
+
open_statefile.close()
|
|
113
|
+
except Exception:
|
|
114
|
+
pass
|
|
115
|
+
|
|
116
|
+
return states
|
|
117
|
+
|
|
118
|
+
def as_numpy_record(self):
|
|
119
|
+
'''Return the data for this state as a numpy record array.'''
|
|
120
|
+
|
|
121
|
+
from westpa.core.data_manager import vstr_dtype, weight_dtype, seg_id_dtype
|
|
122
|
+
|
|
123
|
+
bstate_dtype = np.dtype(
|
|
124
|
+
[
|
|
125
|
+
('state_id', seg_id_dtype),
|
|
126
|
+
('probability', weight_dtype),
|
|
127
|
+
('pcoord', self.pcoord.dtype, (len(self.pcoord),)),
|
|
128
|
+
('label', vstr_dtype),
|
|
129
|
+
('auxref', vstr_dtype),
|
|
130
|
+
]
|
|
131
|
+
)
|
|
132
|
+
bstaterec = np.array(
|
|
133
|
+
[(self.state_id, self.probability, self.pcoord, self.label or '', self.auxref or '')], dtype=bstate_dtype
|
|
134
|
+
)[0]
|
|
135
|
+
return bstaterec
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
class InitialState:
|
|
139
|
+
'''Describes an initial state for a new trajectory. These are generally constructed by
|
|
140
|
+
appropriate modification of a basis state.
|
|
141
|
+
|
|
142
|
+
:ivar state_id: Integer identifier of this state, usually set by the
|
|
143
|
+
data manager.
|
|
144
|
+
:ivar basis_state_id: Identifier of the basis state from which this state was
|
|
145
|
+
generated, or None.
|
|
146
|
+
:ivar basis_state: The `BasisState` from which this state was generated, or None.
|
|
147
|
+
:ivar iter_created: Iteration in which this state was generated (0 for
|
|
148
|
+
simulation initialization).
|
|
149
|
+
:ivar iter_used: Iteration in which this state was used to initiate a
|
|
150
|
+
trajectory (None for unused).
|
|
151
|
+
:ivar istate_type: Integer describing the type of this initial state
|
|
152
|
+
(ISTATE_TYPE_BASIS for direct use of a basis state,
|
|
153
|
+
ISTATE_TYPE_GENERATED for a state generated from a basis state,
|
|
154
|
+
ISTATE_TYPE_RESTART for a state corresponding to the endpoint
|
|
155
|
+
of a segment in another simulation, or
|
|
156
|
+
ISTATE_TYPE_START for a state generated from a start state).
|
|
157
|
+
:ivar istate_status: Integer describing whether this initial state has been properly
|
|
158
|
+
prepared.
|
|
159
|
+
:ivar pcoord: The representative progress coordinate of this state.
|
|
160
|
+
'''
|
|
161
|
+
|
|
162
|
+
ISTATE_TYPE_UNSET = 0
|
|
163
|
+
ISTATE_TYPE_BASIS = 1
|
|
164
|
+
ISTATE_TYPE_GENERATED = 2
|
|
165
|
+
ISTATE_TYPE_RESTART = 3
|
|
166
|
+
ISTATE_TYPE_START = 4
|
|
167
|
+
|
|
168
|
+
ISTATE_UNUSED = 0
|
|
169
|
+
|
|
170
|
+
ISTATE_STATUS_PENDING = 0
|
|
171
|
+
ISTATE_STATUS_PREPARED = 1
|
|
172
|
+
ISTATE_STATUS_FAILED = 2
|
|
173
|
+
|
|
174
|
+
istate_types = {}
|
|
175
|
+
istate_type_names = {}
|
|
176
|
+
|
|
177
|
+
istate_statuses = {}
|
|
178
|
+
istate_status_names = {}
|
|
179
|
+
|
|
180
|
+
def __init__(
|
|
181
|
+
self,
|
|
182
|
+
state_id,
|
|
183
|
+
basis_state_id,
|
|
184
|
+
iter_created,
|
|
185
|
+
iter_used=None,
|
|
186
|
+
istate_type=None,
|
|
187
|
+
istate_status=None,
|
|
188
|
+
pcoord=None,
|
|
189
|
+
basis_state=None,
|
|
190
|
+
basis_auxref=None,
|
|
191
|
+
):
|
|
192
|
+
self.state_id = state_id
|
|
193
|
+
self.basis_state_id = basis_state_id
|
|
194
|
+
self.basis_state = basis_state
|
|
195
|
+
self.istate_type = istate_type
|
|
196
|
+
self.istate_status = istate_status
|
|
197
|
+
self.iter_created = iter_created
|
|
198
|
+
self.iter_used = iter_used
|
|
199
|
+
self.pcoord = np.atleast_1d(pcoord)
|
|
200
|
+
self.basis_auxref = basis_auxref
|
|
201
|
+
self.data = {}
|
|
202
|
+
|
|
203
|
+
def __repr__(self):
|
|
204
|
+
return '{} state_id={self.state_id!r} istate_type={self.istate_type!r} basis_state_id={self.basis_state_id!r} iter_created={self.iter_created!r} pcoord={self.pcoord!r}>'.format(
|
|
205
|
+
object.__repr__(self)[:-1], self=self
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
def as_numpy_record(self):
|
|
209
|
+
from westpa.core.data_manager import seg_id_dtype, istate_type_dtype, istate_status_dtype, vstr_dtype
|
|
210
|
+
|
|
211
|
+
istate_dtype = np.dtype(
|
|
212
|
+
[
|
|
213
|
+
('state_id', seg_id_dtype),
|
|
214
|
+
('basis_state_id', seg_id_dtype),
|
|
215
|
+
('iter_created', np.uint),
|
|
216
|
+
('iter_used', np.uint),
|
|
217
|
+
('istate_type', istate_type_dtype),
|
|
218
|
+
('istate_status', istate_status_dtype),
|
|
219
|
+
('basis_auxref', vstr_dtype),
|
|
220
|
+
('pcoord', self.pcoord.dtype, (len(self.pcoord),)),
|
|
221
|
+
]
|
|
222
|
+
)
|
|
223
|
+
return np.array(
|
|
224
|
+
[
|
|
225
|
+
(
|
|
226
|
+
self.state_id,
|
|
227
|
+
self.basis_state_id or 0,
|
|
228
|
+
self.iter_created or 0,
|
|
229
|
+
self.iter_used or 0,
|
|
230
|
+
self.istate_type or 0,
|
|
231
|
+
self.istate_status or 0,
|
|
232
|
+
self.basis_auxref or '',
|
|
233
|
+
self.pcoord,
|
|
234
|
+
)
|
|
235
|
+
],
|
|
236
|
+
dtype=istate_dtype,
|
|
237
|
+
)[0]
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
InitialState.istate_statuses.update(
|
|
241
|
+
{_attr: getattr(InitialState, _attr) for _attr in dir(InitialState) if _attr.startswith('ISTATE_STATUS_')}
|
|
242
|
+
)
|
|
243
|
+
InitialState.istate_types.update(
|
|
244
|
+
{_attr: getattr(InitialState, _attr) for _attr in dir(InitialState) if _attr.startswith('ISTATE_TYPE_')}
|
|
245
|
+
)
|
|
246
|
+
InitialState.istate_status_names.update({istate_status: name for name, istate_status in InitialState.istate_statuses.items()})
|
|
247
|
+
InitialState.istate_type_names.update({istate_type: name for name, istate_type in InitialState.istate_types.items()})
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
class TargetState:
|
|
251
|
+
'''Describes a target state.
|
|
252
|
+
|
|
253
|
+
:ivar state_id: Integer identifier of this state, usually set by the
|
|
254
|
+
data manager.
|
|
255
|
+
:ivar label: A descriptive label for this microstate (may be empty)
|
|
256
|
+
:ivar pcoord: The representative progress coordinate of this state.
|
|
257
|
+
|
|
258
|
+
'''
|
|
259
|
+
|
|
260
|
+
def __init__(self, label, pcoord, state_id=None):
|
|
261
|
+
self.label = label
|
|
262
|
+
self.pcoord = np.atleast_1d(pcoord)
|
|
263
|
+
self.state_id = state_id
|
|
264
|
+
|
|
265
|
+
def __repr__(self):
|
|
266
|
+
return '{} state_id={self.state_id!r} label={self.label!r} pcoord={self.pcoord!r}>'.format(
|
|
267
|
+
object.__repr__(self)[:-1], self=self
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
@classmethod
|
|
271
|
+
def states_to_file(cls, states, fileobj):
|
|
272
|
+
'''Write a file defining basis states, which may then be read by `states_from_file()`.'''
|
|
273
|
+
|
|
274
|
+
if isinstance(fileobj, str):
|
|
275
|
+
fileobj = open(fileobj, 'wt')
|
|
276
|
+
|
|
277
|
+
max_label_len = max(8, max(len(state.label or '') for state in states))
|
|
278
|
+
|
|
279
|
+
fileobj.write('# {:{max_label_len}s} {:s}\n'.format('Label', 'Pcoord', max_label_len=max_label_len - 2))
|
|
280
|
+
for state in states:
|
|
281
|
+
pcoord_str = ' '.join(str(field) for field in state.pcoord)
|
|
282
|
+
fileobj.write('{:{max_label_len}s} {:s}\n'.format(state.label, pcoord_str, max_label_len=max_label_len))
|
|
283
|
+
|
|
284
|
+
@classmethod
|
|
285
|
+
def states_from_file(cls, statefile, dtype):
|
|
286
|
+
'''Read a file defining target states. Each line defines a state, and contains a label followed
|
|
287
|
+
by a representative progress coordinate value, separated by whitespace, as in::
|
|
288
|
+
|
|
289
|
+
bound 0.02
|
|
290
|
+
|
|
291
|
+
for a single target and one-dimensional progress coordinates or::
|
|
292
|
+
|
|
293
|
+
bound 2.7 0.0
|
|
294
|
+
drift 100 50.0
|
|
295
|
+
|
|
296
|
+
for two targets and a two-dimensional progress coordinate.
|
|
297
|
+
'''
|
|
298
|
+
|
|
299
|
+
labels = []
|
|
300
|
+
pcoord_values = []
|
|
301
|
+
|
|
302
|
+
try:
|
|
303
|
+
open_statefile = open(statefile, 'r')
|
|
304
|
+
except TypeError:
|
|
305
|
+
open_statefile = statefile
|
|
306
|
+
|
|
307
|
+
for line in open_statefile:
|
|
308
|
+
line = line.partition('#')[0].strip()
|
|
309
|
+
if not line:
|
|
310
|
+
continue
|
|
311
|
+
|
|
312
|
+
fields = line.split()
|
|
313
|
+
labels.append(fields[0])
|
|
314
|
+
pcoord_values.append(np.array(list(map(dtype, fields[1:])), dtype=dtype))
|
|
315
|
+
|
|
316
|
+
try:
|
|
317
|
+
open_statefile.close()
|
|
318
|
+
except Exception:
|
|
319
|
+
pass
|
|
320
|
+
|
|
321
|
+
return [cls(label=label, pcoord=pcoord) for label, pcoord in zip(labels, pcoord_values)]
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def pare_basis_initial_states(basis_states, initial_states, segments=None):
|
|
325
|
+
'''Given iterables of basis and initial states (and optionally segments that use them),
|
|
326
|
+
return minimal sets (as in __builtins__.set) of states needed to describe the history of the given
|
|
327
|
+
segments an initial states.'''
|
|
328
|
+
|
|
329
|
+
bstatemap = {state.state_id: state for state in basis_states}
|
|
330
|
+
istatemap = {state.state_id: state for state in initial_states}
|
|
331
|
+
|
|
332
|
+
if segments is not None:
|
|
333
|
+
segments = list(segments)
|
|
334
|
+
return_istates = set(
|
|
335
|
+
istatemap[segment.initial_state_id] for segment in segments if segment.initpoint_type == Segment.SEG_INITPOINT_NEWTRAJ
|
|
336
|
+
)
|
|
337
|
+
else:
|
|
338
|
+
return_istates = set(initial_states)
|
|
339
|
+
|
|
340
|
+
return_bstates = set(
|
|
341
|
+
bstatemap[istate.basis_state_id]
|
|
342
|
+
for istate in return_istates
|
|
343
|
+
if istate.istate_type != InitialState.ISTATE_TYPE_RESTART and istate.istate_type != InitialState.ISTATE_TYPE_START
|
|
344
|
+
)
|
|
345
|
+
|
|
346
|
+
return return_bstates, return_istates
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
def return_state_type(state_obj):
|
|
350
|
+
'''Convinience function for returning the state ID and type of the state_obj pointer'''
|
|
351
|
+
|
|
352
|
+
if isinstance(state_obj, Segment):
|
|
353
|
+
return type(state_obj).__name__, state_obj.seg_id
|
|
354
|
+
elif isinstance(state_obj, InitialState):
|
|
355
|
+
return type(state_obj).__name__, state_obj.state_id
|
|
356
|
+
elif isinstance(state_obj, BasisState):
|
|
357
|
+
return type(state_obj).__name__, state_obj.state_id
|
|
358
|
+
else:
|
|
359
|
+
return 'Unknown', float('inf')
|
westpa/core/systems.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
import numpy as np
|
|
4
|
+
|
|
5
|
+
import westpa
|
|
6
|
+
from westpa.core.binning import NopMapper
|
|
7
|
+
|
|
8
|
+
log = logging.getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class WESTSystem:
|
|
12
|
+
'''A description of the system being simulated, including the dimensionality and
|
|
13
|
+
data type of the progress coordinate, the number of progress coordinate entries
|
|
14
|
+
expected from each segment, and binning. To construct a simulation, the user must
|
|
15
|
+
subclass WESTSystem and set several instance variables.
|
|
16
|
+
|
|
17
|
+
At a minimum, the user must subclass ``WESTSystem`` and override
|
|
18
|
+
:method:`initialize` to set the data type and dimensionality of progress
|
|
19
|
+
coordinate data and define a bin mapper.
|
|
20
|
+
|
|
21
|
+
:ivar pcoord_ndim: The number of dimensions in the progress coordinate.
|
|
22
|
+
Defaults to 1 (i.e. a one-dimensional progress
|
|
23
|
+
coordinate).
|
|
24
|
+
:ivar pcoord_dtype: The data type of the progress coordinate, which must be
|
|
25
|
+
callable (e.g. ``np.float32`` and ``long`` will work,
|
|
26
|
+
but ``'<f4'`` and ``'<i8'`` will not). Defaults to
|
|
27
|
+
``np.float64``.
|
|
28
|
+
:ivar pcoord_len: The length of the progress coordinate time series
|
|
29
|
+
generated by each segment, including *both* the initial
|
|
30
|
+
and final values. Defaults to 2 (i.e. only the initial
|
|
31
|
+
and final progress coordinate values for a segment are
|
|
32
|
+
returned from propagation).
|
|
33
|
+
:ivar bin_mapper: A bin mapper describing the progress coordinate space.
|
|
34
|
+
:ivar bin_target_counts: A vector of target counts, one per bin.
|
|
35
|
+
'''
|
|
36
|
+
|
|
37
|
+
def __init__(self, rc=None):
|
|
38
|
+
self.rc = rc or westpa.rc
|
|
39
|
+
|
|
40
|
+
# Number of dimentions in progress coordinate data
|
|
41
|
+
self.pcoord_ndim = 1
|
|
42
|
+
|
|
43
|
+
# Length of progress coordinate data for each segment
|
|
44
|
+
self.pcoord_len = 2
|
|
45
|
+
|
|
46
|
+
# Data type of progress coordinate
|
|
47
|
+
self.pcoord_dtype = np.float32
|
|
48
|
+
|
|
49
|
+
# Mapper
|
|
50
|
+
self.bin_mapper = NopMapper()
|
|
51
|
+
self._bin_target_counts = None
|
|
52
|
+
|
|
53
|
+
self.bin_target_counts = [1]
|
|
54
|
+
|
|
55
|
+
@property
|
|
56
|
+
def bin_target_counts(self):
|
|
57
|
+
return self._bin_target_counts
|
|
58
|
+
|
|
59
|
+
@bin_target_counts.setter
|
|
60
|
+
def bin_target_counts(self, target_counts):
|
|
61
|
+
maxcount = max(target_counts)
|
|
62
|
+
self._bin_target_counts = np.array(target_counts, dtype=np.min_scalar_type(maxcount))
|
|
63
|
+
|
|
64
|
+
def initialize(self):
|
|
65
|
+
'''Prepare this system object for use in simulation or analysis,
|
|
66
|
+
creating a bin space, setting replicas per bin, and so on. This
|
|
67
|
+
function is called whenever a WEST tool creates an instance of the
|
|
68
|
+
system driver.
|
|
69
|
+
'''
|
|
70
|
+
pass
|
|
71
|
+
|
|
72
|
+
def prepare_run(self):
|
|
73
|
+
'''Prepare this system for use in a simulation run. Called by w_run in
|
|
74
|
+
all worker processes.'''
|
|
75
|
+
pass
|
|
76
|
+
|
|
77
|
+
def finalize_run(self):
|
|
78
|
+
'''A hook for system-specific processing for the end of a simulation run
|
|
79
|
+
(as defined by such things as maximum wallclock time, rather than perhaps
|
|
80
|
+
more scientifically-significant definitions of "the end of a simulation run")'''
|
|
81
|
+
pass
|
|
82
|
+
|
|
83
|
+
def new_pcoord_array(self, pcoord_len=None):
|
|
84
|
+
'''Return an appropriately-sized and -typed pcoord array for a timepoint, segment,
|
|
85
|
+
or number of segments. If ``pcoord_len`` is not specified (or None), then
|
|
86
|
+
a length appropriate for a segment is returned.'''
|
|
87
|
+
|
|
88
|
+
if pcoord_len is None:
|
|
89
|
+
pcoord_len = self.pcoord_len
|
|
90
|
+
return np.zeros((pcoord_len, self.pcoord_ndim), self.pcoord_dtype)
|
|
91
|
+
|
|
92
|
+
def new_region_set(self):
|
|
93
|
+
raise NotImplementedError('This method has been removed.')
|
westpa/core/textio.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'''Miscellaneous routines to help with input and output of WEST-related data in text format'''
|
|
2
|
+
|
|
3
|
+
import getpass
|
|
4
|
+
import socket
|
|
5
|
+
import sys
|
|
6
|
+
import time
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class NumericTextOutputFormatter:
|
|
10
|
+
comment_string = '# '
|
|
11
|
+
emit_header = True
|
|
12
|
+
|
|
13
|
+
def __init__(self, output_file, mode='wt', emit_header=None):
|
|
14
|
+
if hasattr(output_file, 'write'):
|
|
15
|
+
self._file = output_file
|
|
16
|
+
else:
|
|
17
|
+
self._file = open(output_file, mode)
|
|
18
|
+
|
|
19
|
+
self._header_written = False
|
|
20
|
+
self._header_lines = []
|
|
21
|
+
|
|
22
|
+
self.write_header('created by program: {}'.format(sys.argv[0] or 'unknown program'))
|
|
23
|
+
self.write_header('created by user: {}'.format(getpass.getuser()))
|
|
24
|
+
self.write_header('created on host: {}'.format(socket.gethostname()))
|
|
25
|
+
self.write_header('created at: {}'.format(time.strftime('%c', time.localtime(time.time()))))
|
|
26
|
+
|
|
27
|
+
if emit_header is not None:
|
|
28
|
+
self.emit_header = emit_header
|
|
29
|
+
else:
|
|
30
|
+
self.emit_header = self.__class__.emit_header
|
|
31
|
+
|
|
32
|
+
def __getattr__(self, attr):
|
|
33
|
+
return getattr(self._file, attr)
|
|
34
|
+
|
|
35
|
+
def close(self):
|
|
36
|
+
if not self._header_written:
|
|
37
|
+
self._write_header()
|
|
38
|
+
self._file.close()
|
|
39
|
+
|
|
40
|
+
def write(self, str):
|
|
41
|
+
if not self._header_written:
|
|
42
|
+
self._write_header()
|
|
43
|
+
self._file.write(str)
|
|
44
|
+
|
|
45
|
+
def writelines(self, sequence):
|
|
46
|
+
if not self._header_written:
|
|
47
|
+
self._write_header()
|
|
48
|
+
self._file.writelines(sequence)
|
|
49
|
+
|
|
50
|
+
def write_comment(self, line):
|
|
51
|
+
'''Writes a line beginning with the comment string'''
|
|
52
|
+
self._file.write('{}{}\n'.format(self.comment_string, line))
|
|
53
|
+
|
|
54
|
+
def write_header(self, line):
|
|
55
|
+
'''Appends a line to those written when the file header is written. The
|
|
56
|
+
appropriate comment string will be prepended, so ``line`` should not include
|
|
57
|
+
a comment character.'''
|
|
58
|
+
if self._header_written:
|
|
59
|
+
raise EnvironmentError('cannot append header lines after header has been written')
|
|
60
|
+
else:
|
|
61
|
+
self._header_lines.append(line)
|
|
62
|
+
|
|
63
|
+
def __enter__(self):
|
|
64
|
+
return self
|
|
65
|
+
|
|
66
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
|
67
|
+
self._file.close()
|
|
68
|
+
return False
|
|
69
|
+
|
|
70
|
+
def _write_header(self):
|
|
71
|
+
if self.emit_header and not self._header_written:
|
|
72
|
+
for line in self._header_lines:
|
|
73
|
+
self.write_comment(line)
|
|
74
|
+
self._header_written = True
|