# 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


import numpy as np
from molmod.units import picosecond, angstrom, kcalmol
from molmod.io.common import SlicedReader
         >>> for frame in foo:
         ...    print frame.time
    """
    def __init__(self, f, sub=slice(None)):
        """
           Arguments:
            | ``f``  --  a filename or a file-like object
            | ``sub``  --  an optional slice object to select a subset of time
                           frames

           The number of atoms is read immediately and is available as
           ``self.num_atoms``.
        """
        SlicedReader.__init__(self, f, sub)
        self._secfile = SectionFile(self._f)
        self._read_header()

    def _read_header(self):
        """Read the number of atoms from the first section"""
        self.num_atoms = int(self._secfile.get_next("FilNum")[0].split()[4])

    def _read_frame(self):
        """Read a single frame from the trajectory"""
        self._secfile.get_next("Frame Number")
        frame = ATRJFrame()
        # Read the time and energy
        energy_lines = self._secfile.get_next("Time/Energy")
        energy_words = energy_lines[0].split()
        frame.time = float(energy_words[0])*picosecond
        frame.step = int(energy_words[1])

# 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/atrj.py
import numpy as np
from molmod.units import picosecond, angstrom, kcalmol
from molmod.io.common import SlicedReader

         >>> for frame in foo:
         ...    print frame.time
    """
    def __init__(self, f, sub=slice(None)):
        """
           Arguments:
            | ``f``  --  a filename or a file-like object
            | ``sub``  --  an optional slice object to select a subset of time
                           frames

           The number of atoms is read immediately and is available as
           ``self.num_atoms``.
        """
        SlicedReader.__init__(self, f, sub)
        self._secfile = SectionFile(self._f)
        self._read_header()

    def _read_header(self):
        """Read the number of atoms from the first section"""
        self.num_atoms = int(self._secfile.get_next("FilNum")[0].split()[4])

    def _read_frame(self):
        """Read a single frame from the trajectory"""
        self._secfile.get_next("Frame Number")
        frame = ATRJFrame()
        # Read the time and energy
        energy_lines = self._secfile.get_next("Time/Energy")
        energy_words = energy_lines[0].split()
        frame.time = float(energy_words[0])*picosecond
        frame.step = int(energy_words[1])

        frame.total_energy = float(energy_words[2])*kcalmol