Skip to content

Commit

Permalink
added dcd, discover and vasp converter unit tests and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiCheng45 committed Jan 22, 2024
1 parent 211370b commit e79f176
Show file tree
Hide file tree
Showing 10 changed files with 35,776 additions and 18 deletions.
2 changes: 1 addition & 1 deletion MDANSE/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ recursive-include Extensions/qhull_lib *.h *c *.pxd
recursive-include Extensions/xtc *.h *c *.pxd
recursive-include Src/MDANSE/Chemistry *.json
recursive-include Src/MDANSE/Framework *.json
recursive-include Tests *.pdb *.mdt *.config *.lammps
recursive-include Tests/Data/*

recursive-include Doc *

Expand Down
10 changes: 5 additions & 5 deletions MDANSE/Src/MDANSE/Framework/Converters/DCD.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def read_header(self):
# Read a block
data = self.next_record()

if data[:4] != "CORD":
if data[:4] != b"CORD":
raise DCDFileError("Unrecognized DCD format")

temp = struct.unpack(self.byteOrder + "20i", data[4:])
Expand Down Expand Up @@ -198,22 +198,22 @@ def read_header(self):
# Read a block
data = self.next_record()

nLines = struct.unpack(self.byteOrder + b"I", data[0:4])[0]
nLines = struct.unpack(self.byteOrder.encode() + b"I", data[0:4])[0]

self["title"] = []
for i in range(nLines):
temp = struct.unpack(
self.byteOrder + "80c", data[4 + 80 * i : 4 + 80 * (i + 1)]
)
self["title"].append("".join(temp).strip())
self["title"].append(b"".join(temp).strip())

self["title"] = "\n".join(self["title"])
self["title"] = b"\n".join(self["title"])

# Read a block
data = self.next_record()

# Read the number of atoms.
self["natoms"] = struct.unpack(self.byteOrder + b"I", data)[0]
self["natoms"] = struct.unpack(self.byteOrder.encode() + b"I", data)[0]

def read_step(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion MDANSE/Src/MDANSE/Framework/Converters/Discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def run_step(self, index):

conf = self._trajectory.chemical_system.configuration
if conf.is_periodic:
conf.unit_cell = cell
conf.unit_cell = UnitCell(cell)

movableAtoms = self._hisfile["movable_atoms"]

Expand Down
8 changes: 4 additions & 4 deletions MDANSE/Src/MDANSE/Framework/Converters/VASP.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ def __init__(self, filename):
while True:
self._headerSize = self["instance"].tell()
line = self["instance"].readline().strip()
if not line or line.lower().startswith("direct"):
if not line or line.lower().startswith(b"direct"):
self._frameHeaderSize = self["instance"].tell() - self._headerSize
break
header.append(line)
header.append(line.decode())

self["scale_factor"] = float(header[0])

Expand All @@ -74,7 +74,7 @@ def __init__(self, filename):
while True:
self._frameSize = self["instance"].tell()
line = self["instance"].readline().strip()
if not line or line.lower().startswith("direct"):
if not line or line.lower().startswith(b"direct"):
break
nAtoms += 1

Expand Down Expand Up @@ -207,7 +207,7 @@ def initialize(self):
self._xdatcarFile = XDATCARFile(self.configuration["xdatcar_file"]["filename"])

# The number of steps of the analysis.
self.numberOfSteps = self._xdatcarFile["n_frames"]
self.numberOfSteps = int(self._xdatcarFile["n_frames"])

self._chemicalSystem = ChemicalSystem()

Expand Down
Loading

0 comments on commit e79f176

Please sign in to comment.