2 @package MPCDAnalysis.NormalModeAutocorrelation
4 Analysis functionality for data on normal mode autocorrelations, as produced by
5 `OpenMPCD::CUDA::MPCFluid::Instrumentation::NormalModeAutocorrelation`.
10 Analysis class for data on normal mode autocorrelation, as produced by
11 `OpenMPCD::CUDA::MPCFluid::Instrumentation::NormalModeAutocorrelation`.
13 Unless specified otherwise, all times are measured in units of `measurement
15 `OpenMPCD::CUDA::MPCFluid::Instrumentation::NormalModeAutocorrelation`.
17 @see OpenMPCD::CUDA::MPCFluid::Instrumentation::NormalModeAutocorrelation
25 Throws if `rundirs` is not a `string`, or a `list` of `string`s.
27 Throws if the given `rundir` does not exist, or does not contain
28 a readable, valid `normalModeAutocorrelations.data` file.
31 The run directory, as a `string`. From this directory, the
32 file `normalModeAutocorrelations.data` will be read as input.
33 Alternatively, this may be a `list` of `string` instances,
34 each of which will be treated as described above.
37 if isinstance(rundirs, str):
40 if not isinstance(rundirs, list):
42 for rundir
in rundirs:
43 if not isinstance(rundir, str):
56 for rundir
in rundirs:
57 filepath = rundir +
"/" +
"normalModeAutocorrelations.data"
59 if not os.path.isfile(filepath):
62 config = Configuration(rundir)
67 "instrumentation.normalModeAutocorrelation." + \
68 "autocorrelationArgumentCount"]
71 self.
_config.getDifferencesAsFlatDictionary(config)
77 for ignoredKey
in ignoredKeys:
78 if ignoredKey
in differences:
79 del differences[ignoredKey]
81 if len(differences) != 0:
82 msg =
"Incompatible rundirs given."
83 msg +=
" Differences:\n"
84 msg += str(differences)
87 with open(filepath,
"r")
as f:
93 Returns the number of normal modes.
103 Returns, in units of `measurement time`, the maximum correlation time
104 that was configured to be measured, i.e. \f$ N_A - 1 \f$.
112 Returns an `OnTheFlyStatisticsDDDA` object that holds information on the
113 sample of measured autocorrelations for normal mode index `mode` and
114 correlation time `correlationTime`.
117 Throws if any of the arguments have invalid types.
119 Throws if any of the arguments have invalid values.
122 The normal mode index, as an `int` in the range
123 `[0, getNormalModeCount())`.
124 @param[in] correlationTime
125 The correlation time to return results for, measured in
126 This argument is to be of type `int`, non-negative, and at
127 most `getMaximumMeasurementTime()`.
130 if not isinstance(mode, int):
135 if not isinstance(correlationTime, int):
137 if correlationTime < 0:
150 stat = OnTheFlyStatisticsDDDA()
154 if correlationTime >= len(measurement):
157 stat.addDatum(measurement[correlationTime])
163 def getMPLAxes(self, mode, showEstimatedStandardDeviation = True):
165 Returns an `matplotlib.axes.Axes` object that plots the normal mode
166 autocorrelation of mode index `mode` against the correlation time, in
167 units of `measurement time`.
170 Throws if any of the arguments have invalid types.
172 Throws if any of the arguments have invalid values.
175 The normal mode index, as an `int` in the range
176 `[0, getNormalModeCount())`.
177 @param[in] showEstimatedStandardDeviation
178 Whether to show, for each data point, the estimated standard
182 if not isinstance(mode, int):
186 if not isinstance(showEstimatedStandardDeviation, bool):
190 import matplotlib.figure
192 figure = matplotlib.figure.Figure()
193 axes = figure.add_subplot(1, 1, 1)
202 values.append(autocorrelation.getSampleMean())
203 if showEstimatedStandardDeviation:
205 autocorrelation.getOptimalStandardErrorOfTheMean())
207 if len(errorbars) == 0:
211 axes.errorbar(times, values, yerr = errorbars)
213 axes.set_xlabel(
r'Correlation Time $ T $')
214 axes.set_ylabel(
r'$ C(0, T, n=' + str(mode) +
') $')
221 Parses the given file `f`.
223 If a file has been parsed already, this new file is treated as if it
224 was a continuation of previously parsed runs. Hence, this file's first
225 measurement is treated as if it followed the last file's last
229 The file to parse, of type `file`.
232 assert isinstance(f, file)
251 mt0 = int(parts[0]) + starting_mt0
255 autocorrelation = float(parts[2 + mode])