OpenMPCD
MagneticClusterCount.py
1 from .Base import Base
2 
3 class MagneticClusterCount(Base):
4  """
5  Class for analysis of the number of magnetic clusters in a star polymer.
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(MagneticClusterCount, self).__init__(run)
17 
18 
20  """
21  Returns a `matplotlib.axes.Axes` object that contains a plot of the
22  number of magnetic clusters, with the horizontal axis showing the
23  simulation time `t`, and the vertical axis showing the cluster count.
24  """
25 
26  import matplotlib.figure
27 
28  figure = matplotlib.figure.Figure()
29  axes = figure.add_subplot(1, 1, 1)
30  lines = []
31  legendLabels = []
32 
33  data = self.getValueAsFunctionOfTime()
34  _line, = axes.plot(data.keys(), data.values())
35  lines.append(_line)
36  legendLabels.append("Magnetic Cluster Count")
37 
38  axes.legend(lines, legendLabels)
39 
40  axes.set_title("Magnetic Cluster Count")
41  axes.set_xlabel("Simulation Time t")
42  axes.set_ylabel("Magnetic Cluster Count")
43 
44  return axes
45 
46 
47  def _computeValueAsFunctionOfTime(self):
48  """
49  Takes the raw simulation output, and computes the magnetic cluster count
50  as a function of time. The result is returned as an
51  `collcections.OrderedDict`.
52  """
53 
54  from collections import OrderedDict
55 
56  config = self.getRun().getConfiguration()
57  snapshots = self._getSnapshots()
58  starPolymers = self._getStarPolymers()
59 
60  ret = OrderedDict()
61  timestep = config["mpc.timestep"]
62  time = timestep * config["mpc.warmupSteps"]
63 
64  lastTimestepAnalyzed = -9e9
65  while True:
66  time += timestep
67 
68  particles = snapshots.readTimestep()
69 
70  if time - lastTimestepAnalyzed < self._getAnalysisTimestep():
71  continue
72  lastTimestepAnalyzed = time
73 
74 
75  if particles.isEmpty():
76  break
77 
78  starPolymers.setParticles(particles)
79 
80  ret[time] = \
81  starPolymers.getMagneticClusterCount(
83 
84  return ret
85 
86 
87  def _getCacheFilename(self):
88  """
89  Returns the filename where cached data is (expected to be) saved to.
90  """
91 
92  return "magneticClusterCount.txt"
93 
94 
95  def _getCacheMetadata(self):
96  """
97  Returns the cache metadata.
98  """
99 
100  cacheVersion = 1
101 
102  metadata = \
103  {
104  "cacheVersion": cacheVersion,
105  "magneticClusterMaxDistance":
107  "analysisTimestep": self._getAnalysisTimestep()
108  }
109  return metadata
110 
111 
112  def _getMagneticClusterMaxDistance(self):
113  """
114  Returns the maximum distance that two particles may be apart and still
115  be considered to be part of the same magnetic cluster.
116  """
117 
118  return 2.5
119 
120 
121  def _getAnalysisTimestep(self):
122  """
123  Returns the timestep between to analysis points.
124  """
125 
126  return 100
MPCDAnalysis.StarPolymersAnalysis.Base.Base.getRun
def getRun(self)
Definition: Base.py:44
MPCDAnalysis.StarPolymersAnalysis.MagneticClusterCount.MagneticClusterCount._getAnalysisTimestep
def _getAnalysisTimestep(self)
Definition: MagneticClusterCount.py:132
MPCDAnalysis.StarPolymersAnalysis.MagneticClusterCount.MagneticClusterCount._getMagneticClusterMaxDistance
def _getMagneticClusterMaxDistance(self)
Definition: MagneticClusterCount.py:123
MPCDAnalysis.StarPolymersAnalysis.MagneticClusterCount.MagneticClusterCount.__init__
def __init__(self, run)
Definition: MagneticClusterCount.py:16
MPCDAnalysis.StarPolymersAnalysis.Base.Base._getSnapshots
def _getSnapshots(self)
Definition: Base.py:112
MPCDAnalysis.StarPolymersAnalysis.MagneticClusterCount.MagneticClusterCount.getMPLAxesForValueAsFunctionOfTime
def getMPLAxesForValueAsFunctionOfTime(self)
Definition: MagneticClusterCount.py:27
MPCDAnalysis.StarPolymersAnalysis.Base.Base.getValueAsFunctionOfTime
def getValueAsFunctionOfTime(self)
Definition: Base.py:56
MPCDAnalysis.StarPolymersAnalysis.Base.Base._getStarPolymers
def _getStarPolymers(self)
Definition: Base.py:123