# 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
# 
# class FileFormatError(Exception):
#     """Is raised when unexpected data is encountered while reading a file"""
#     pass


from builtins import range
from molmod.units import picosecond, amu, angstrom, atm, deg
from molmod.io.common import SlicedReader, FileFormatError
import numpy as np
            if len(words) != 4:
                raise FileFormatError("The atom header line must contain 4 words. (%i'th frame, %i'th step, %i'th atom)" % (self._counter, step, i+1))
            symbols.append(words[0])
            try:
                masses[i] = float(words[2])*self.mass_unit
                charges[i] = float(words[3])
            except ValueError:
                raise FileFormatError("The numbers in the atom header line could not be interpreted.")
            # the pos line
            pos_msg = "The position lines must consist of three floating point values. (%i'th frame, %i'th step, %i'th atom)" % (self._counter, step, i+1)
            pos[i] = read_three(pos_msg)
            if self.keytrj > 0:
                vel_msg = "The velocity lines must consist of three floating point values. (%i'th frame, %i'th step, %i'th atom)" % (self._counter, step, i+1)
                vel[i] = read_three(vel_msg)
            if self.keytrj > 1:
                frc_msg = "The force lines must consist of three floating point values. (%i'th frame, %i'th step, %i'th atom)" % (self._counter, step, i+1)
                frc[i] = read_three(frc_msg)
        pos *= self.pos_unit # convert to au
        if self.keytrj > 0:
            vel *= self.vel_unit # convert to au
        if self.keytrj > 1:
            frc *= self.frc_unit # convert to au
        return frame

    def _skip_frame(self):
        """Skip a single frame from the trajectory"""
        for i in range(self._frame_size):
            next(self._f)



# 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
# 
# class FileFormatError(Exception):
#     """Is raised when unexpected data is encountered while reading a file"""
#     pass


# Path: molmod/io/dlpoly.py
from builtins import range
from molmod.units import picosecond, amu, angstrom, atm, deg
from molmod.io.common import SlicedReader, FileFormatError
import numpy as np

            if len(words) != 4:
                raise FileFormatError("The atom header line must contain 4 words. (%i'th frame, %i'th step, %i'th atom)" % (self._counter, step, i+1))
            symbols.append(words[0])
            try:
                masses[i] = float(words[2])*self.mass_unit
                charges[i] = float(words[3])
            except ValueError:
                raise FileFormatError("The numbers in the atom header line could not be interpreted.")
            # the pos line
            pos_msg = "The position lines must consist of three floating point values. (%i'th frame, %i'th step, %i'th atom)" % (self._counter, step, i+1)
            pos[i] = read_three(pos_msg)
            if self.keytrj > 0:
                vel_msg = "The velocity lines must consist of three floating point values. (%i'th frame, %i'th step, %i'th atom)" % (self._counter, step, i+1)
                vel[i] = read_three(vel_msg)
            if self.keytrj > 1:
                frc_msg = "The force lines must consist of three floating point values. (%i'th frame, %i'th step, %i'th atom)" % (self._counter, step, i+1)
                frc[i] = read_three(frc_msg)
        pos *= self.pos_unit # convert to au
        if self.keytrj > 0:
            vel *= self.vel_unit # convert to au
        if self.keytrj > 1:
            frc *= self.frc_unit # convert to au
        return frame

    def _skip_frame(self):
        """Skip a single frame from the trajectory"""
        for i in range(self._frame_size):
            next(self._f)



class DLPolyOutputReader(SlicedReader):