2 @package MPCDAnalysis.LogicalEntityMeanSquareDisplacement
4 Analysis functionality for data on mean square displacement, as produced by
5 `OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement`.
10 Analysis class for data on mean square displacement, as produced by
11 `OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement`.
13 Unless specified otherwise, all times are measured in units of `measurement
15 `OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement`.
17 @see OpenMPCD::CUDA::MPCFluid::Instrumentation::LogicalEntityMeanSquareDisplacement
25 Throws if `rundir` is not a `str`, or a `list` of `str`.
27 Throws if the given `rundir` does not exist, or does not contain
28 a readable, valid data file.
30 Throws if `rundir` is an empty list.
33 The run directory, as a `string`. From this directory, the
34 file `logicalEntityMeanSquareDisplacement.data` will be read
35 as input. If this file does not exist,
36 `logicalEntityMeanSquareDisplacement.data.xz` will be read
38 Alternatively, this can be a list of strings, each element
39 of which specifies a directory that is treated as described
43 if isinstance(rundirs, str):
46 if not isinstance(rundirs, list):
48 for rundir
in rundirs:
49 if not isinstance(rundir, str):
61 for rundir
in rundirs:
62 if not isinstance(rundir, str):
65 filepath = rundir +
"/" +
"logicalEntityMeanSquareDisplacement.data"
66 filepathXZ = filepath +
".xz"
69 if not os.path.isfile(filepath)
and not os.path.isfile(filepathXZ):
74 self.
_config = Configuration(rundir)
77 "instrumentation." + \
78 "logicalEntityMeanSquareDisplacement." + \
79 "measurementArgumentCount"]
84 if not self.
_config.isEquivalent(Configuration(rundir)):
86 "Rundirs have incompatible configurations!")
88 if os.path.isfile(filepath):
89 with open(filepath,
"r")
as f:
91 elif os.path.isfile(filepathXZ):
93 f = lzma.LZMAFile(filepathXZ,
"r")
101 Returns, in units of `measurement time`, the maximum correlation time
102 that was configured to be measured, i.e. \f$ N_A \f$.
110 Returns an `OnTheFlyStatisticsDDDA` object that holds information on the
111 sample of measured mean square displacements for time difference
115 Throws if any of the arguments have invalid types.
117 Throws if any of the arguments have invalid values.
120 The time difference to return results for, measured in
121 This argument is to be of type `int`, positive, and at
122 most `getMaximumMeasurementTime()`.
125 if not isinstance(deltaT, int):
136 def fitToData(self, function = None, minTime = None, maxTime = None):
138 Fits the data to the given function, and returns the optimal function
142 A function object suitable to be used as the first argument
143 to `scipy.optimize.curve_fit`, or `None`, in which case a
144 function of the form \f$ y\left(x\right) = p_1 x^{p_2} \f$
145 with parameters \f$ p_1 \f$ and \f$ p_2 \f$ is used.
147 If not `None`, this value specifies the minimum value of the
148 measurement time that will be used for the fit.
150 If not `None`, this value specifies the maximum value of the
151 measurement time that will be used for the fit.
155 import scipy.optimize
164 for T
in range(minTime, maxTime):
168 values.append(msd.getSampleMean())
171 function =
lambda x, p1, p2: p1 * x ** p2
173 times = numpy.array(times)
174 values = numpy.array(values)
175 fit = scipy.optimize.curve_fit(function, times, values)
182 showEstimatedStandardDeviation = True,
185 Returns an `matplotlib.axes.Axes` object that plots the mean square
186 displacement against the diffusion time, in units of `measurement time`.
189 Throws if any of the arguments have invalid types.
191 Throws if any of the arguments have invalid values.
193 @param[in] showEstimatedStandardDeviation
194 Whether to show, for each data point, the estimated standard
197 A list of lines to plot, in addition to the data. Each
198 element of this list represents a line and is a list
199 containing, in this order:
200 - A list containing `x` and `y` coordinates for the
201 starting point of the line,
202 - Likewise for the ending point.
205 if not isinstance(showEstimatedStandardDeviation, bool):
207 if not isinstance(lines, list):
211 import matplotlib.figure
213 figure = matplotlib.figure.Figure()
214 axes = figure.add_subplot(1, 1, 1)
223 values.append(msd.getSampleMean())
224 if showEstimatedStandardDeviation:
226 msd.getOptimalStandardErrorOfTheMean())
228 if len(errorbars) == 0:
232 axes.errorbar(times, values, yerr = errorbars)
235 x = [line[0][0], line[1][0]]
236 y = [line[0][1], line[1][1]]
237 axes.errorbar(x, y, yerr =
None)
239 axes.set_xlabel(
r'Diffusion Time $ T $')
240 axes.set_ylabel(
r'$ C(0, T) $')
247 Parses the given file `f`.
249 If a file has been parsed already, this new file is treated as if it
250 was a continuation of previously parsed runs. Hence, this file's first
251 measurement is treated as if it followed the last file's last
255 The file to parse, of type `file` or `lzma.LZMAFile`.
263 deltaT = int(parts[1])
264 msd = float(parts[2])