Esempio n. 1
0
    def __init__(self, filename, mode='r'):
        """Open *filename* for reading (default, ``mode="r"``), writing 
        (``mode="w"``), or appending (``mode="r+"`` or ``mode="a"``)."""

        if not isinstance(filename, str):
            raise TypeError("filename argument must be a string")
        if not isinstance(mode, str): 
            TypeError('mode argument must be string')
        if not mode in ('r', 'w', 'a', 'r+'): 
            ValueError("mode string must begin with one of 'r', 'w', 'r+', or "
                       "'a'")
        if mode == 'r' and not os.path.isfile(filename):
            raise IOError("[Errno 2] No such file or directory: '{0:s}'"
                          .format(filename))
        self._filename = filename
        if mode in ('a', 'r+'):
            self._file = open(filename, 'r+b')
            self._file.seek(0)
            mode = 'a'
        else:
            self._file = open(filename, mode+'b')
        self._mode = mode
        name = os.path.splitext(os.path.split(filename)[1])[0]
        TrajBase.__init__(self, name)
        self._bytes_per_frame = None
        self._first_byte = None
        self._dtype = np.float32
        
        self._timestep = 1
        self._first_ts = 0
        self._framefreq = 1
        self._n_fixed = 0
Esempio n. 2
0
 def link(self, *ag):
     
     if ag:
         TrajBase.link(self, *ag)
         for traj in self._trajectories:
             traj.link(*ag)
     else:
         return self._ag
Esempio n. 3
0
 def __init__(self, name):
     """Trajectory can be instantiated with a *name* or a filename. When
     name is a valid path to a trajectory file it will be opened for 
     reading."""
     
     TrajBase.__init__(self, name)
     self._trajectory = None
     self._trajectories = []
     self._filenames = set()
     self._n_files = 0
     self._cfi = 0 # current file index
     if os.path.isfile(name):
         self.addFile(name)
Esempio n. 4
0
 def __init__(self, name, **kwargs):
     """Trajectory can be instantiated with a *name* or a filename. When
     name is a valid path to a trajectory file it will be opened for 
     reading."""
     
     TrajBase.__init__(self, name)
     self._trajectory = None
     self._trajectories = []
     self._filenames = set()
     self._n_files = 0
     self._cfi = 0 # current file index
     assert 'mode' not in kwargs, 'mode is an invalid keyword argument'
     self._kwargs = kwargs
     if os.path.isfile(name):
         self.addFile(name)
Esempio n. 5
0
 def setAtoms(self, ag, setref=True):
     
     for traj in self._trajectories:
         traj.setAtoms(ag, setref)
     TrajBase.setAtoms(self, ag, setref)
Esempio n. 6
0
 def setAtoms(self, atoms):
     
     for traj in self._trajectories:
         traj.setAtoms(atoms)
     TrajBase.setAtoms(self, atoms)