Skip to content

Commit

Permalink
Save unitcell when writing trr
Browse files Browse the repository at this point in the history
  • Loading branch information
kain88-de committed Nov 2, 2015
1 parent 39591e8 commit 7aa664d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions package/MDAnalysis/coordinates/TRR.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from . import base
from ..lib.formats.trr import TRRFile
from ..core.AtomGroup import Universe, AtomGroup
from ..lib.mdamath import triclinic_box
from ..lib.mdamath import triclinic_box, triclinic_vectors


class TRRReader(base.Reader):
Expand Down Expand Up @@ -43,12 +43,10 @@ def __init__(self, filename, convert_units=True, sub=None, **kwargs):
self.ts.time = time_1
self.ts.dt = time_2 - time_1
self.ts.dimensions = triclinic_box(*box)
self.box = box
self.ts._unitcell = self.ts.dimensions

if self.convert_units:
self.convert_pos_from_native(self.ts._pos)
self.convert_pos_from_native(self.ts._unitcell[:3])
self.convert_pos_from_native(self.ts.dimensions[:3])
self.convert_velocities_from_native(self.ts.velocities)
self.convert_forces_from_native(self.ts.forces)

Expand Down Expand Up @@ -113,8 +111,7 @@ class TRRWriter(base.Writer):
units = {'time': 'ps', 'length': 'nm', 'velocity': 'nm/ps',
'force': 'kJ/(mol*nm)'}

def __init__(self, filename, convert_units=True, n_atoms=0,
**kwargs):
def __init__(self, filename, convert_units=True, n_atoms=0, **kwargs):
self._convert_units = convert_units
self.trr = TRRFile(filename, 'w')
self.n_atoms = n_atoms
Expand Down Expand Up @@ -152,8 +149,11 @@ def write_next_timestep(self, ts):
forces = np.empty((self.n_atoms, 3), dtype=np.float32)
time = ts.time
step = ts.frame
box = np.eye(3)
print(velo.shape)

if self._convert_units:
dimensions = self.convert_dimensions_to_unitcell(ts)

box = triclinic_vectors(dimensions)

# TODO: write dummy for
self.trr.write(xyz, velo, forces, box, step, time, 1)

0 comments on commit 7aa664d

Please sign in to comment.