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