1 from .ParticleCollection
import ParticleCollection
2 from .Vector3DReal
import Vector3DReal
8 def __init__(self, path, assertReadMode = False):
16 if os.path.exists(path):
17 self.
file = open(path,
"r")
21 elif os.path.exists(path +
".xz"):
23 self.
file = lzma.LZMAFile(path +
".xz",
"r")
29 raise RuntimeError(
"VTFSnapshotFile does not exist: " + path)
31 self.
file = open(path,
"w")
34 def isInReadMode(self):
35 return self.
mode ==
"r"
37 def isInWriteMode(self):
38 return self.
mode ==
"w"
40 def getStructureBlock(self):
43 def setStructureBlock(self, structureBlock):
46 def readStructureBlock(self):
52 for line
in self.
file:
55 if line.startswith(
"timestep"):
60 def writeStructureBlock(self):
66 def readTimestep(self):
69 for line
in self.
file:
72 if line.startswith(
"timestep"):
77 if len(parts)
not in [3, 6]:
78 message =
"Unexpected line, number " + str(self.
_lineNumber)
81 raise ValueError(message)
95 collection.setPositionsAndVelocities(positions, velocities)
99 def writeTimestep(self, particleCollection):
103 positions = particleCollection.getPositions()
104 velocities = particleCollection.getVelocities()
106 self.
file.write(
"timestep\n")
107 for position, velocity
in itertools.izip_longest(positions, velocities):
108 self.
file.write(str(position.getX().real) +
" ")
109 self.
file.write(str(position.getY().real) +
" ")
110 self.
file.write(str(position.getZ().real))
112 if velocity
is not None:
113 self.
file.write(
" " + str(velocity.getX().real))
114 self.
file.write(
" " + str(velocity.getY().real))
115 self.
file.write(
" " + str(velocity.getZ().real))
117 self.
file.write(
"\n")