def addFile(self, filename): """Add a file to the trajectory instance. Currently only DCD files are supported.""" if not isinstance(filename, str): raise ValueError('filename must be a string') if os.path.abspath(filename) in self._filenames: raise IOError('{0:s} is already added to the trajectory' .format(filename)) traj = openTrajFile(filename) n_atoms = self._n_atoms if n_atoms != 0 and n_atoms != traj.numAtoms(): raise IOError('{0:s} must have same number of atoms as previously ' 'loaded files'.format(traj.getTitle())) if self._n_files == 0: self._trajectory = traj self._title = traj.getTitle() if n_atoms == 0: self._n_atoms = traj.numAtoms() self._coords = traj._coords self._trajectories.append(traj) self._n_csets += traj.numFrames() self._n_files += 1 if self._ag is not None: traj.setAtoms(self._ag)
def addFile(self, filename, **kwargs): """Add a file to the trajectory instance. Currently only DCD files are supported.""" if not isinstance(filename, str): raise ValueError('filename must be a string') if os.path.abspath(filename) in self._filenames: raise IOError( '{0} is already added to the trajectory'.format(filename)) assert 'mode' not in kwargs, 'mode is an invalid keyword argument' traj = openTrajFile(filename, **(kwargs or self._kwargs)) n_atoms = self._n_atoms if n_atoms != 0 and n_atoms != traj.numAtoms(): raise IOError('{0} must have same number of atoms as ' 'previously loaded files'.format(traj.getTitle())) if self._n_files == 0: self._trajectory = traj self._title = traj.getTitle() if n_atoms == 0: self._n_atoms = traj.numAtoms() self._coords = traj._coords self._trajectories.append(traj) self._n_csets += traj.numFrames() self._n_files += 1 if self._ag is not None: traj.setAtoms(self._ag)