Skip to content

Commit 18f6f7c

Browse files
committed
Modified analyze_traj.py and analyze_EEXE.py by replacing 'configuration' with 'trajectory'.
1 parent 2faa215 commit 18f6f7c

File tree

3 files changed

+78
-78
lines changed

3 files changed

+78
-78
lines changed

docs/simulations.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,11 +248,9 @@ include parameters for data analysis here.
248248
Modules/functions not obeying the contract are unlikely to work.
249249

250250
- Multiple functions can be defined in the module, but the function for coordinate manipulation must have the same name as the module itself.
251-
- The function must only have two compulsory arguments, which are the two GRO files to be modified. The function must not depend on
252-
the order of the input GRO files.
251+
- The function must only have two compulsory arguments, which are the two GRO files to be modified. The function must not depend on the order of the input GRO files.
253252
- The function must return :code:`None` (i.e., no return value).
254-
- The function must save the modified GRO file as :code:`confout.gro`. Note that in the CLI :code:`run_EEXE`,
255-
:code:`confout.gro` generated as the simulation output will be automatically backed up to prevent overwriting.
253+
- The function must save the modified GRO file as :code:`confout.gro`. Note that in the CLI :code:`run_EEXE`, :code:`confout.gro` generated as the simulation output will be automatically backed up to prevent overwriting.
256254

257255
.. _doc_EEXE_parameters:
258256

ensemble_md/analysis/analyze_traj.py

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def extract_state_traj(dhdl):
4141

4242
def stitch_trajs(files, rep_trajs, shifts=None, dhdl=True, col_idx=-1, save=True):
4343
"""
44-
Stitches the state-space/CV-space trajectories for each configuration from DHDL files
44+
Stitches the state-space/CV-space trajectories for each starting configuration from DHDL files
4545
or PLUMED output files generated at different iterations.
4646
4747
Parameters
@@ -51,8 +51,8 @@ def stitch_trajs(files, rep_trajs, shifts=None, dhdl=True, col_idx=-1, save=True
5151
Specifically, :code:`files[i]` should be a list containing the files of interest from all iterations in
5252
replica :code:`i`.
5353
rep_trajs : list
54-
A list of lists that represents the replica space trajectories for each configuration. For example,
55-
:code:`rep_trajs[0] = [0, 2, 3, 0, 1, ...]` means that configuration 0 transitioned to replica 2, then
54+
A list of lists that represents the replica space trajectories for each starting configuration. For example,
55+
:code:`rep_trajs[0] = [0, 2, 3, 0, 1, ...]` means that starting configuration 0 transitioned to replica 2, then
5656
3, 0, 1, in iterations 1, 2, 3, 4, ..., respectively.
5757
shifts : list
5858
A list of values for shifting the state indices for each replica. The length of the list
@@ -73,21 +73,23 @@ def stitch_trajs(files, rep_trajs, shifts=None, dhdl=True, col_idx=-1, save=True
7373
Returns
7474
-------
7575
trajs : list
76-
A list that contains lists of state-space/CV-space trajectory (in global indices) for each configuration.
77-
For example, :code:`trajs[i]` is the state-space/CV-space trajectory of configuration :code:`i`.
76+
A list that contains lists of state-space/CV-space trajectory (in global indices) for each starting
77+
configuration. For example, :code:`trajs[i]` is the state-space/CV-space trajectory of starting
78+
configuration :code:`i`.
7879
"""
7980
n_configs = len(files) # number of starting configurations
8081
n_iter = len(files[0]) # number of iterations per replica
8182

82-
# First figure out which dhdl/plumed output files each configuration corresponds to
83-
# files_sorted[i] contains the dhdl/plumed output files for configuration i sorted based on iteration indices
83+
# First figure out which dhdl/plumed output files each starting configuration corresponds to
84+
# files_sorted[i] contains the dhdl/plumed output files for starting configuration i sorted
85+
# based on iteration indices
8486
files_sorted = [[] for i in range(n_configs)]
8587
for i in range(n_configs):
8688
for j in range(n_iter):
8789
files_sorted[i].append(files[rep_trajs[i][j]][j])
8890

89-
# Then, stitch the trajectories for each configuration
90-
trajs = [[] for i in range(n_configs)] # for each configuration
91+
# Then, stitch the trajectories for each starting configuration
92+
trajs = [[] for i in range(n_configs)] # for each starting configuration
9193
for i in range(n_configs):
9294
for j in range(n_iter):
9395
if j == 0:
@@ -118,8 +120,8 @@ def stitch_trajs(files, rep_trajs, shifts=None, dhdl=True, col_idx=-1, save=True
118120
def stitch_trajs_for_sim(files, shifts=None, dhdl=True, col_idx=-1, save=True):
119121
"""
120122
Stitches the state-space/CV-space trajectories in the same replica/simulation folder.
121-
That is, the output trajectory is contributed by multiple different configurations to
122-
a certain alchemical range.
123+
That is, the output time series is contributed by multiple different trajectories (initiated by
124+
different starting configurations) to a certain alchemical range.
123125
124126
Parameters
125127
----------
@@ -204,12 +206,12 @@ def traj2transmtx(traj, N, normalize=True):
204206

205207
def plot_rep_trajs(trajs, fig_name, dt=None, stride=None):
206208
"""
207-
Plots the time series of replicas visited by each configuration in a single plot.
209+
Plots the time series of replicas visited by each trajectory in a single plot.
208210
209211
Parameters
210212
----------
211213
trajs : list
212-
A list of arrays that represent the replica space trajectories of all configurations.
214+
A list of arrays that represent the all replica space trajectories.
213215
fig_name : str
214216
The file name of the png file to be saved (with the extension).
215217
dt : float or None, optional
@@ -243,9 +245,9 @@ def plot_rep_trajs(trajs, fig_name, dt=None, stride=None):
243245
ax = fig.add_subplot(111)
244246
for i in range(n_sim):
245247
if len(trajs[0]) >= 100: # don't show the markers
246-
plt.plot(x[::stride], trajs[i][::stride], color=colors[i], label=f'Configuration {i}')
248+
plt.plot(x[::stride], trajs[i][::stride], color=colors[i], label=f'Trajectory {i}')
247249
else:
248-
plt.plot(x[::stride], trajs[i][::stride], color=colors[i], label=f'Configuration {i}', marker='o')
250+
plt.plot(x[::stride], trajs[i][::stride], color=colors[i], label=f'Trajectory {i}', marker='o')
249251

250252
if dt is None:
251253
plt.xlabel('MC moves')
@@ -259,14 +261,14 @@ def plot_rep_trajs(trajs, fig_name, dt=None, stride=None):
259261
plt.savefig(f'{fig_name}', dpi=600)
260262

261263

262-
def plot_state_trajs(trajs, state_ranges, fig_name, dt=None, stride=1, title_prefix='Configuration'):
264+
def plot_state_trajs(trajs, state_ranges, fig_name, dt=None, stride=1, title_prefix='Trajectory'):
263265
"""
264-
Plots the time series of states visited by each configuration in a subplot.
266+
Plots the time series of states visited by each trajectory in a subplot.
265267
266268
Parameters
267269
----------
268270
trajs : list
269-
A list of arrays that represent the state space trajectories of all configurations.
271+
A list of arrays that represent the state space trajectories of all continuous trajectories.
270272
state_ranges : list
271273
A list of lists of state indices. (Like the attribute :code:`state_ranges` in :code:`EnsemblEXE`.)
272274
fig_name : str
@@ -281,7 +283,7 @@ def plot_state_trajs(trajs, state_ranges, fig_name, dt=None, stride=1, title_pre
281283
plotting more than 10 million frames can take a lot of memory.
282284
title_prefix : str
283285
The prefix shared by the titles of the subplots. For example, if :code:`title_prefix` is
284-
set to "Configuration", then the titles of the subplots will be "Configuration 0", "Configuration 1", ..., etc.
286+
set to "Trajectory", then the titles of the subplots will be "Trajectory 0", "Trajectory 1", ..., etc.
285287
"""
286288
n_sim = len(trajs)
287289
cmap = plt.cm.ocean # other good options are CMRmap, gnuplot, terrain, turbo, brg, etc.
@@ -351,14 +353,14 @@ def plot_state_trajs(trajs, state_ranges, fig_name, dt=None, stride=1, title_pre
351353
plt.savefig(f'{fig_name}', dpi=600)
352354

353355

354-
def plot_state_hist(trajs, state_ranges, fig_name, stack=True, figsize=None, prefix='Configuration', subplots=False, save_hist=True): # noqa: E501
356+
def plot_state_hist(trajs, state_ranges, fig_name, stack=True, figsize=None, prefix='Trajectory', subplots=False, save_hist=True): # noqa: E501
355357
"""
356-
Plots the histograms of the state index for each configuration.
358+
Plots the histograms of the state index for each trajectory.
357359
358360
Parameters
359361
----------
360362
trajs : list
361-
A list of arrays that represent the state space trajectories of all configurations.
363+
A list of arrays that represent the state space trajectories of all continuous trajectories.
362364
state_ranges : list
363365
A list of lists of state indices. (Like the attribute :code:`state_ranges` in :obj:`.EnsembleEXE`.)
364366
fig_name : str
@@ -370,8 +372,8 @@ def plot_state_hist(trajs, state_ranges, fig_name, stack=True, figsize=None, pre
370372
default is :code:`(6.4, 4.8)` for cases having less than 30 states and :code:`(10, 4.8)` otherwise.
371373
prefix : str
372374
The prefix shared by the titles of the subplots, or the labels shown in the same plot.
373-
For example, if :code:`prefix` is set to "Configuration", then the titles/labels of the
374-
will be "Configuration 0", "Configuration 1", ..., etc.
375+
For example, if :code:`prefix` is set to "Trajectory", then the titles/labels of the
376+
will be "Trajectory 0", "Trajectory 1", ..., etc.
375377
subplots : bool
376378
Whether to plot the histogram in multiple subplots, with the title of
377379
each based on the value of :code:`prefix`.
@@ -381,7 +383,7 @@ def plot_state_hist(trajs, state_ranges, fig_name, stack=True, figsize=None, pre
381383
Returns
382384
-------
383385
hist_data : list
384-
The histogram data of the state index for each configuration.
386+
The histogram data of the state index for each trajectory.
385387
"""
386388
n_configs = len(trajs)
387389
n_states = max(max(state_ranges)) + 1
@@ -480,15 +482,15 @@ def plot_state_hist(trajs, state_ranges, fig_name, stack=True, figsize=None, pre
480482

481483
def plot_transit_time(trajs, N, fig_prefix=None, dt=None, folder='.'):
482484
"""
483-
Caclulcates and plots the average transit times for each configuration, including the time
485+
Caclulcates and plots the average transit times for each trajectory, including the time
484486
it takes from states 0 to k, from k to 0 and from 0 to k back to 0 (i.e. round-trip time).
485487
If there are more than 100 round-trips, 3 histograms corresponding to t_0k, t_k0 and t_roundtrip
486488
will be generated.
487489
488490
Parameters
489491
----------
490492
trajs : list
491-
A list of arrays that represent the state space trajectories of all configurations.
493+
A list of arrays that represent the state space trajectories of all continuous trajectories.
492494
N : int
493495
The total number of states in the whole alchemical range.
494496
fig_prefix : str
@@ -501,11 +503,11 @@ def plot_transit_time(trajs, N, fig_prefix=None, dt=None, folder='.'):
501503
Returns
502504
-------
503505
t_0k_list : list
504-
A list of transit time from states 0 to k for each configuration.
506+
A list of transit time from states 0 to k for each trajectory.
505507
t_k0_list : list
506-
A list of transit time from states k to 0 for each configuration.
508+
A list of transit time from states k to 0 for each trajectory.
507509
t_roundtrip_list : list
508-
A list of round-trip times for each configuration.
510+
A list of round-trip times for each trajectory.
509511
units : str
510512
The units of the times.
511513
"""
@@ -520,7 +522,7 @@ def plot_transit_time(trajs, N, fig_prefix=None, dt=None, folder='.'):
520522
else:
521523
units = 'ps'
522524

523-
# The lists below are for storing data corresponding to different configurations.
525+
# The lists below are for storing data corresponding to different trajectories.
524526
t_0k_list, t_k0_list, t_roundtrip_list = [], [], []
525527
t_0k_avg, t_k0_avg, t_roundtrip_avg = [], [], []
526528

@@ -608,8 +610,8 @@ def plot_transit_time(trajs, N, fig_prefix=None, dt=None, folder='.'):
608610
marker = ''
609611

610612
plt.figure()
611-
for i in range(len(t_list)): # t_list[i] is the list for configuration i
612-
plt.plot(np.arange(len(t_list[i])) + 1, t_list[i], label=f'Configuration {i}', marker=marker)
613+
for i in range(len(t_list)): # t_list[i] is the list for trajectory i
614+
plt.plot(np.arange(len(t_list[i])) + 1, t_list[i], label=f'Trajectory {i}', marker=marker)
613615

614616
if max(max((t_list))) >= 10000:
615617
plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
@@ -628,7 +630,7 @@ def plot_transit_time(trajs, N, fig_prefix=None, dt=None, folder='.'):
628630

629631
plt.figure()
630632
for i in range(len(t_list)):
631-
plt.hist(t_list[i], bins=int(len(t_list[i]) / 20), label=f'Configuration {i}')
633+
plt.hist(t_list[i], bins=int(len(t_list[i]) / 20), label=f'Trajectory {i}')
632634
if max(counts) >= 10000:
633635
plt.ticklabel_format(style='sci', axis='y', scilimits=(0, 0))
634636
plt.xlabel(f'{y_labels[t]}')
@@ -748,7 +750,7 @@ def get_swaps(EEXE_log='run_EEXE_log.txt'):
748750
# Note that proposed_swaps and accepted_swaps are initialized in the same way
749751
proposed_swaps = [{i: 0 for i in state_list[j]} for j in range(n_sim)] # Key: global state index; Value: The number of accepted swaps # noqa: E501
750752
accepted_swaps = [{i: 0 for i in state_list[j]} for j in range(n_sim)] # Key: global state index; Value: The number of accepted swaps # noqa: E501
751-
state_trajs = [[] for i in range(n_sim)] # the state-space trajectory for each REPLICA (not configuration)
753+
state_trajs = [[] for i in range(n_sim)] # the state-space trajectory for each REPLICA (not trajectory)
752754
for line in lines:
753755
if 'Simulation' in line and 'Global state' in line:
754756
rep = int(line.split(':')[0].split()[-1])

0 commit comments

Comments
 (0)