3 class PotentialEnergy(Base):
5 Class for analysis of potential energies.
13 The run to analyze, as an instance of `Run`.
21 Returns a `matplotlib.axes.Axes` object that contains a plot of the
22 potential energy, with the horizontal axis showing the simulation
23 time `t`, and the vertical axis showing the potential energy at that
27 import matplotlib.figure
29 figure = matplotlib.figure.Figure()
30 axes = figure.add_subplot(1, 1, 1)
35 _line, = axes.plot(data.keys(), data.values())
37 legendLabels.append(
"Potential Energy")
39 axes.legend(lines, legendLabels)
41 axes.set_title(
"Star Polymer Potential Energy")
42 axes.set_xlabel(
"Simulation Time t")
43 axes.set_ylabel(
"Potential Energy")
48 def _computeValueAsFunctionOfTime(self):
50 Takes the raw simulation output, and computes the potential energy as
51 a function of time. The result is returned as an
52 `collcections.OrderedDict`.
55 from collections
import OrderedDict
57 config = self.
getRun().getConfiguration()
63 timestep = config[
"mpc.timestep"]
64 time = timestep * config[
"mpc.warmupSteps"]
66 lastTimestepAnalyzed = -9e9
70 particles = snapshots.readTimestep()
74 lastTimestepAnalyzed = time
77 if particles.isEmpty():
80 starPolymers.setParticles(particles)
82 ret[time] = starPolymers.getPotentialEnergy()
87 def _getCacheFilename(self):
89 Returns the filename where cached data is (expected to be) saved to.
92 return "potentialEnergy.txt"
95 def _getCacheMetadata(self):
97 Returns the cache metadata.
104 "cacheVersion": cacheVersion,
110 def _getAnalysisTimestep(self):
112 Returns the timestep between to analysis points.