Commit a8df200d authored by peastman's avatar peastman
Browse files

Merge pull request #722 from swails/fix_dcd

[WIP]Fix byte handling to work for both Py2 and Py3
parents 3a3a2aa1 c6b6b894
......@@ -73,7 +73,7 @@ class DCDFile(object):
header = struct.pack('<i4c9if', 84, b'C', b'O', b'R', b'D', 0, firstStep, interval, 0, 0, 0, 0, 0, 0, dt)
header += struct.pack('<13i', boxFlag, 0, 0, 0, 0, 0, 0, 0, 0, 24, 84, 164, 2)
header += struct.pack('<80s', b'Created by OpenMM')
header += struct.pack('<80s', b'Created '+bytes(time.asctime(time.localtime(time.time())), 'ascii'))
header += struct.pack('<80s', b'Created '+time.asctime(time.localtime(time.time())).encode('ascii'))
header += struct.pack('<4i', 164, 4, len(list(topology.atoms())), 4)
file.write(header)
......
......@@ -75,9 +75,13 @@ class PDBFile(object):
pdb = file
else:
inputfile = file
own_handle = False
if isinstance(file, str):
inputfile = open(file)
own_handle = True
pdb = PdbStructure(inputfile, load_all_models=True)
if own_handle:
inputfile.close()
PDBFile._loadNameReplacementTables()
# Build the topology
......
import unittest
import tempfile
from simtk.openmm import app
import simtk.openmm as mm
from simtk import unit
from random import random
import os
class TestDCDFile(unittest.TestCase):
def test_dcd(self):
""" Test the DCD file """
fname = tempfile.mktemp(suffix='.dcd')
pdbfile = app.PDBFile('systems/alanine-dipeptide-implicit.pdb')
natom = len(list(pdbfile.topology.atoms()))
with open(fname, 'wb') as f:
dcd = app.DCDFile(f, pdbfile.topology, 0.001)
for i in range(5):
dcd.writeModel([mm.Vec3(random(), random(), random()) for j in range(natom)]*unit.angstroms)
os.remove(fname)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment