OpenMPCD
Asphericity.py
1 from .Base import Base
2 
3 class Asphericity(Base):
4  """
5  Class for analysis of asphericities.
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(Asphericity, self).__init__(run)
17 
18 
20  """
21  Returns a `matplotlib.axes.Axes` object that contains a plot of the
22  asphericity, with the horizontal axis showing the simulation
23  time `t`, and the vertical axis showing the asphericity at that
24  point in time.
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  _line, = axes.plot(data.keys(), data.values())
36  lines.append(_line)
37  legendLabels.append("Asphericity")
38 
39  axes.legend(lines, legendLabels)
40 
41  axes.set_title("Star Polymer Asphericity")
42  axes.set_xlabel("Simulation Time t")
43  axes.set_ylabel("Asphericity")
44 
45  return axes
46 
47 
48  def _computeValueAsFunctionOfTime(self):
49  """
50  Takes the raw simulation output, and computes the asphericity as
51  a function of time. The result is returned as an
52  `collcections.OrderedDict`.
53  """
54 
55  from collections import OrderedDict
56 
57  config = self.getRun().getConfiguration()
58  snapshots = self._getSnapshots()
59  starPolymers = self._getStarPolymers()
60 
61  ret = OrderedDict()
62  timestep = config["mpc.timestep"]
63  time = timestep * config["mpc.warmupSteps"]
64 
65  while True:
66  time += timestep
67 
68  particles = snapshots.readTimestep()
69  particles.setUniformMass(starPolymers.getParticleMass())
70 
71  if particles.isEmpty():
72  break
73 
74  particles.shiftToCenterOfMassFrame()
75  starPolymers.setParticles(particles)
76 
77  ret[time] = particles.getAsphericity()
78 
79  return ret
80 
81 
82  def _getCacheFilename(self):
83  """
84  Returns the filename where cached data is (expected to be) saved to.
85  """
86 
87  return "asphericity.txt"
MPCDAnalysis.StarPolymersAnalysis.Base.Base.getRun
def getRun(self)
Definition: Base.py:44
MPCDAnalysis.StarPolymersAnalysis.Asphericity.Asphericity.getMPLAxesForValueAsFunctionOfTime
def getMPLAxesForValueAsFunctionOfTime(self)
Definition: Asphericity.py:28
MPCDAnalysis.StarPolymersAnalysis.Base.Base._getSnapshots
def _getSnapshots(self)
Definition: Base.py:112
MPCDAnalysis.StarPolymersAnalysis.Asphericity.Asphericity.__init__
def __init__(self, run)
Definition: Asphericity.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