OpenMPCD
EckartAngularVelocityVector.py
1 from .Base import Base
2 
3 class EckartAngularVelocityVector(Base):
4  """
5  Class for analysis of Eckart-frame angular velocity vectors, as defined in
6  `MPCDAnalysis.EckartSystem`.
7  """
8 
9  def __init__(self, run):
10  """
11  The constructor.
12 
13  @param[in] run
14  The run to analyze, as an instance of `Run`.
15  """
16 
17  super(EckartAngularVelocityVector, self).__init__(run)
18 
19 
21  """
22  Returns a `matplotlib.axes.Axes` object that contains a plot of the
23  Eckart angular velocities of star polymer, with the horizontal axis
24  showing the simulation time `t`, and the Cartesian components of the
25  Eckart angular velocity vector, in radians per time unit.
26  """
27 
28  import matplotlib.figure
29 
30  figure = matplotlib.figure.Figure()
31  axes = figure.add_subplot(1, 1, 1)
32  lines = []
33  legendLabels = []
34 
35  data = self.getValueAsFunctionOfTime()
36  frequencies = [[], [], []]
37  for datum in data.values():
38  for i in [0, 1, 2]:
39  frequencies[i].append(datum[i])
40 
41  _line, = axes.plot(data.keys(), frequencies[0])
42  lines.append(_line)
43  legendLabels.append("Eckart Angular Velocity: x Component")
44 
45  _line, = axes.plot(data.keys(), frequencies[1])
46  lines.append(_line)
47  legendLabels.append("Eckart Angular Velocity: y Component")
48 
49  _line, = axes.plot(data.keys(), frequencies[2])
50  lines.append(_line)
51  legendLabels.append("Eckart Angular Velocity: z Component")
52 
53  axes.legend(lines, legendLabels)
54 
55  axes.set_title("Star Polymer Eckart Angular Velocity")
56  axes.set_xlabel("Simulation Time t")
57  axes.set_ylabel("Eckart Angular Velocity [rad/T]")
58 
59  return axes
60 
61 
62  def _computeValueAsFunctionOfTime(self):
63  """
64  Takes the raw simulation output, and computes the Eckart angular
65  velocity vector as a function of time. The result is returned as an
66  `collcections.OrderedDict`.
67  """
68 
69  from collections import OrderedDict
70 
71 
72  config = self.getRun().getConfiguration()
73  snapshots = self._getSnapshots()
74  starPolymers = self._getStarPolymers()
75 
76  ret = OrderedDict()
77  timestep = config["mpc.timestep"]
78  time = timestep * config["mpc.warmupSteps"]
79 
80  eckartSystem = None
81  while True:
82  time += timestep
83 
84  particles = snapshots.readTimestep()
85  particles.setUniformMass(starPolymers.getParticleMass())
86 
87  if particles.isEmpty():
88  break
89 
90  if eckartSystem is None:
91  from MPCDAnalysis.EckartSystem import EckartSystem
92  eckartSystem = EckartSystem(particles)
93 
94  ret[time] = eckartSystem.getEckartAngularVelocityVector(particles)
95 
96  return ret
97 
98 
99  def _getCacheFilename(self):
100  """
101  Returns the filename where cached data is (expected to be) saved to.
102  """
103 
104  return "eckartAngularVelocityVectors.txt"
105 
106 
107  def _getCacheValueInterpreter(self):
108  """
109  Returns what is to be used as the `valueInterpreter` argument to
110  `Cache.getDataOrderedDict`.
111  """
112 
113  def valueInterpreter(string):
114  import ast
115  return ast.literal_eval(string)
116 
117  return valueInterpreter
MPCDAnalysis.StarPolymersAnalysis.EckartAngularVelocityVector.EckartAngularVelocityVector.getMPLAxesForValueAsFunctionOfTime
def getMPLAxesForValueAsFunctionOfTime(self)
Definition: EckartAngularVelocityVector.py:29
MPCDAnalysis.StarPolymersAnalysis.Base.Base.getRun
def getRun(self)
Definition: Base.py:44
MPCDAnalysis.StarPolymersAnalysis.EckartAngularVelocityVector.EckartAngularVelocityVector.__init__
def __init__(self, run)
Definition: EckartAngularVelocityVector.py:17
MPCDAnalysis.EckartSystem
Definition: EckartSystem.py:1
MPCDAnalysis.StarPolymersAnalysis.Base.Base._getSnapshots
def _getSnapshots(self)
Definition: Base.py:112
MPCDAnalysis.StarPolymersAnalysis.Base.Base.getValueAsFunctionOfTime
def getValueAsFunctionOfTime(self)
Definition: Base.py:56
MPCDAnalysis.StarPolymersAnalysis.Base.Base._getStarPolymers
def _getStarPolymers(self)
Definition: Base.py:123