OpenMPCD
GyrationTensor.py
1 from .Base import Base
2 
3 class GyrationTensor(Base):
4  """
5  Class for analysis of gyration tensors.
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(GyrationTensor, self).__init__(run)
17 
18  def _computeValueAsFunctionOfTime(self):
19  """
20  Takes the raw simulation output, and computes the gyration tensor as
21  a function of time. The result is returned as an
22  `collcections.OrderedDict`, where each value is a list containing, in
23  this order, the `xx`, `xy`, `xz`, `yy`, `yz`, and `zz` components of the
24  gyration tensor, followed by the smallest eigenvalue and the `x`, `y`,
25  and `z` components of the associated eigenvector, followed by the
26  second-to-largest eigenvalue and its eigenvector, followed by the
27  largest eigenvalue and its eigenvector.
28  """
29 
30  from collections import OrderedDict
31 
32  config = self.getRun().getConfiguration()
33  snapshots = self._getSnapshots()
34  starPolymers = self._getStarPolymers()
35 
36  ret = OrderedDict()
37  timestep = config["mpc.timestep"]
38  time = timestep * config["mpc.warmupSteps"]
39 
40  while True:
41  time += timestep
42 
43  particles = snapshots.readTimestep()
44  particles.setUniformMass(starPolymers.getParticleMass())
45 
46  if particles.isEmpty():
47  break
48 
49  particles.shiftToCenterOfMassFrame()
50  starPolymers.setParticles(particles)
51 
52  S = particles.getGyrationTensor()
53  values = [S[0][0], S[0][1], S[0][2], S[1][1], S[1][2], S[2][2]]
54 
55  eigensystem = particles.getGyrationTensorEigensystem()
56  for eigenvalue, eigenvector in eigensystem:
57  values += [eigenvalue]
58  values += [eigenvector[i] for i in range(0, 3)]
59 
60 
61  ret[time] = values
62 
63  return ret
64 
65 
66  def _getCacheFilename(self):
67  """
68  Returns the filename where cached data is (expected to be) saved to.
69  """
70 
71  return "gyrationTensor.txt"
72 
73 
74  def _getCacheMetadata(self):
75  """
76  Returns the cache metadata.
77  """
78 
79  cacheVersion = 2
80 
81  metadata = {"cacheVersion": cacheVersion}
82  return metadata
83 
84 
85  def _getCacheValueInterpreter(self):
86  """
87  Returns what is to be used as the `valueInterpreter` argument to
88  `Cache.getDataOrderedDict`.
89  """
90 
91  def valueInterpreter(string):
92  import ast
93  return ast.literal_eval(string)
94 
95  return valueInterpreter
MPCDAnalysis.StarPolymersAnalysis.Base.Base.getRun
def getRun(self)
Definition: Base.py:44
MPCDAnalysis.StarPolymersAnalysis.GyrationTensor.GyrationTensor.__init__
def __init__(self, run)
Definition: GyrationTensor.py:16
MPCDAnalysis.StarPolymersAnalysis.Base.Base._getSnapshots
def _getSnapshots(self)
Definition: Base.py:112
MPCDAnalysis.StarPolymersAnalysis.Base.Base._getStarPolymers
def _getStarPolymers(self)
Definition: Base.py:123