# Path: molmod/units.py
# def parse_unit(expression):
# 
# Path: molmod/io/common.py
# class SlicedReader(object):
#     """Base class for readers that can read a slice of all the frames"""
# 
#     def __init__(self, f, sub=slice(None)):
#         """
#            Argument:
#             | ``f``  --  a filename or a file-like object
# 
#            Optional argument:
#             | ``sub``  --  a slice indicating which frames to read/skip
# 
#         """
#         if isinstance(f, basestring):
#             self._auto_close = True
#             self._f = open(f)
#         else:
#             self._auto_close = False
#             self._f = f
#         self._sub = sub
#         self._counter = 0
# 
#     def __del__(self):
#         """Clean up the open file"""
#         if self._auto_close:
#             self._f.close()
# 
#     def _read_frame(self):
#         """Read a single frame from the trajectory"""
#         raise NotImplementedError
# 
#     def _skip_frame(self):
#         """Skip a single frame from the trajectory"""
#         raise NotImplementedError
# 
#     def __iter__(self):
#         return self
# 
#     def __next__(self):
#         """Get the next frame from the file, taking into account the slice
# 
#            This method is part of the iterator protocol.
#         """
#         # skip frames as requested
#         while not slice_match(self._sub, self._counter):
#             self._skip_frame()
#             self._counter += 1
# 
#         result = self._read_frame()
#         self._counter += 1
#         return result


from builtins import range
from molmod.units import picosecond, nanometer
from molmod.io.common import SlicedReader
import numpy as np
        num_atoms = int(self._get_line())
        if self.num_atoms is not None and self.num_atoms != num_atoms:
            raise ValueError("The number of atoms must be the same over the entire file.")
        # Read the atom lines
        pos = np.zeros((num_atoms, 3), np.float32)
        vel = np.zeros((num_atoms, 3), np.float32)
        for i in range(num_atoms):
            words = self._get_line()[22:].split()
            pos[i, 0] = float(words[0])
            pos[i, 1] = float(words[1])
            pos[i, 2] = float(words[2])
            vel[i, 0] = float(words[3])
            vel[i, 1] = float(words[4])
            vel[i, 2] = float(words[5])
        pos *= nanometer
        vel *= nanometer/picosecond
        # Read the cell line
        cell = np.zeros((3, 3), np.float32)
        words = self._get_line().split()
        if len(words) >= 3:
            cell[0, 0] = float(words[0])
            cell[1, 1] = float(words[1])
            cell[2, 2] = float(words[2])
        if len(words) == 9:
            cell[1, 0] = float(words[3])
            cell[2, 0] = float(words[4])
            cell[0, 1] = float(words[5])
            cell[2, 1] = float(words[6])
            cell[0, 2] = float(words[7])
            cell[1, 2] = float(words[8])

# Path: molmod/units.py
# def parse_unit(expression):
# 
# Path: molmod/io/common.py
# class SlicedReader(object):
#     """Base class for readers that can read a slice of all the frames"""
# 
#     def __init__(self, f, sub=slice(None)):
#         """
#            Argument:
#             | ``f``  --  a filename or a file-like object
# 
#            Optional argument:
#             | ``sub``  --  a slice indicating which frames to read/skip
# 
#         """
#         if isinstance(f, basestring):
#             self._auto_close = True
#             self._f = open(f)
#         else:
#             self._auto_close = False
#             self._f = f
#         self._sub = sub
#         self._counter = 0
# 
#     def __del__(self):
#         """Clean up the open file"""
#         if self._auto_close:
#             self._f.close()
# 
#     def _read_frame(self):
#         """Read a single frame from the trajectory"""
#         raise NotImplementedError
# 
#     def _skip_frame(self):
#         """Skip a single frame from the trajectory"""
#         raise NotImplementedError
# 
#     def __iter__(self):
#         return self
# 
#     def __next__(self):
#         """Get the next frame from the file, taking into account the slice
# 
#            This method is part of the iterator protocol.
#         """
#         # skip frames as requested
#         while not slice_match(self._sub, self._counter):
#             self._skip_frame()
#             self._counter += 1
# 
#         result = self._read_frame()
#         self._counter += 1
#         return result


# Path: molmod/io/gromacs.py
from builtins import range
from molmod.units import picosecond, nanometer
from molmod.io.common import SlicedReader
import numpy as np

        num_atoms = int(self._get_line())
        if self.num_atoms is not None and self.num_atoms != num_atoms:
            raise ValueError("The number of atoms must be the same over the entire file.")
        # Read the atom lines
        pos = np.zeros((num_atoms, 3), np.float32)
        vel = np.zeros((num_atoms, 3), np.float32)
        for i in range(num_atoms):
            words = self._get_line()[22:].split()
            pos[i, 0] = float(words[0])
            pos[i, 1] = float(words[1])
            pos[i, 2] = float(words[2])
            vel[i, 0] = float(words[3])
            vel[i, 1] = float(words[4])
            vel[i, 2] = float(words[5])
        pos *= nanometer
        vel *= nanometer/picosecond
        # Read the cell line
        cell = np.zeros((3, 3), np.float32)
        words = self._get_line().split()
        if len(words) >= 3:
            cell[0, 0] = float(words[0])
            cell[1, 1] = float(words[1])
            cell[2, 2] = float(words[2])
        if len(words) == 9:
            cell[1, 0] = float(words[3])
            cell[2, 0] = float(words[4])
            cell[0, 1] = float(words[5])
            cell[2, 1] = float(words[6])
            cell[0, 2] = float(words[7])
            cell[1, 2] = float(words[8])

        cell *= nanometer