def __init__(self, outfilename, **kwargs): self.filename = outfilename # the filename has been parsed to be either b(g)zipped or not self.outfile = util.anyopen(self.filename, 'r') # note that, like for xtc and trr files, _numatoms and _numframes are used quasi-private variables # to prevent the properties being recalculated # this is because there is no indexing so the way it measures the number of frames is to read the whole file! self._numatoms = None self._numframes = None self._runtyp = None self.ts = Timestep(0) # need for properties initial calculations self.fixed = 0 self.skip = 1 self.periodic = False self.delta = kwargs.pop("delta", 1.0) # there is no time, so let delta be 1 # update runtyp property self.runtyp if not self.runtyp in ['optimize', 'surface']: raise AttributeError('Wrong RUNTYP= '+self.runtyp) self.skip_timestep = 1 self.ts = Timestep(self.numatoms) # update numframes property self.numframes # Read in the first timestep self._read_next_timestep()
def __init__(self, filename, numatoms=None, start=0, step=1, convert_units=None, multiframe=None): """Create a new PDBWriter :Arguments: *filename* name of output file *start* starting timestep *step* skip between subsequent timesteps *convert_units* units are converted to the MDAnalysis base format; ``None`` selects the value of :data:`MDAnalysis.core.flags` ['convert_lengths'] """ self.filename = filename if convert_units is None: convert_units = core.flags['convert_lengths'] self.convert_units = convert_units # convert length and time to base units self.frames_written = 0 if start < 0: raise ValueError("'Start' must be a positive value") self.start = start self.step = step self.file = util.anyopen(self.filename, 'w') # open file on init
def __init__(self, *args, **kwargs): """Initialize the XYZ trajectory writer :Arguments: *filename* file name of trajectory file. If it ends with "gz" then the file will be gzip-compressed; if it ends with "bz2" it will be bzip2 compressed. :Keywords: *atoms* Provide atom names: This can be a list of names or an :class:`AtomGroup`. If none is provided, atoms will be called 'X' in the output. These atom names will be used when a trajectory is written from raw :class:`Timestep` objects which do not contain atom information. If you write a :class:`AtomGroup` with :meth:`XYZWriter.write` then atom information is taken at each step and *atoms* is ignored. *remark* single line of text ("molecule name") """ # numatoms is ignored ... self.filename = args[0] # convert length and time to base units on the fly? convert_units = kwargs.pop('convert_units', None) self.convert_units = convert_units if convert_units is not None else MDAnalysis.core.flags[ 'convert_lengths'] self.atomnames = self._get_atomnames(kwargs.pop('atoms', "X")) self.remark = kwargs.pop( 'remark', "Written by {0} (release {1})".format(self.__class__.__name__, MDAnalysis.__version__)) self.xyz = util.anyopen(self.filename, 'w') # can also be gz, bz2
def __init__(self, *args, **kwargs): """Initialize the XYZ trajectory writer :Arguments: *filename* file name of trajectory file. If it ends with "gz" then the file will be gzip-compressed; if it ends with "bz2" it will be bzip2 compressed. :Keywords: *atoms* Provide atom names: This can be a list of names or an :class:`AtomGroup`. If none is provided, atoms will be called 'X' in the output. These atom names will be used when a trajectory is written from raw :class:`Timestep` objects which do not contain atom information. If you write a :class:`AtomGroup` with :meth:`XYZWriter.write` then atom information is taken at each step and *atoms* is ignored. *remark* single line of text ("molecule name") """ # numatoms is ignored ... self.filename = args[0] # convert length and time to base units on the fly? convert_units = kwargs.pop('convert_units', None) self.convert_units = convert_units if convert_units is not None else MDAnalysis.core.flags['convert_lengths'] self.atomnames = self._get_atomnames(kwargs.pop('atoms', "X")) self.remark = kwargs.pop('remark', "Written by {0} (release {1})".format(self.__class__.__name__, MDAnalysis.__version__)) self.xyz = util.anyopen(self.filename, 'w') # can also be gz, bz2
def __init__(self, filename, **kwargs): self.filename = filename # the filename has been parsed to be either be foo.xyz or foo.xyz.bz2 by coordinates::core.py # so the last file extension will tell us if it is bzipped or not root, ext = os.path.splitext(self.filename) self.xyzfile = util.anyopen(self.filename, "r") self.compression = ext[1:] if ext[1:] != "xyz" else None # note that, like for xtc and trr files, __numatoms and __numframes are used quasi-private variables # to prevent the properties being recalculated # this is because there is no indexing so the way it measures the number of frames is to read the whole file! self.__numatoms = None self.__numframes = None self.fixed = 0 self.skip = 1 self.periodic = False self.delta = kwargs.pop( "delta", 1.0 ) # can set delta manually, default is 1ps (taken from TRJReader) self.skip_timestep = 1 self.ts = self._Timestep( self.numatoms ) # numatoms has sideeffects: read trajectory... (FRAGILE) # Read in the first timestep (FRAGILE); # FIXME: Positions on frame 0 (whatever that means) instead of 1 (as all other readers do). # Haven't quite figured out where to start with all the self._reopen() etc. # (Also cannot just use seek() or reset() because that would break with urllib2.urlopen() streams) self._read_next_timestep()
def __init__(self, outfilename, **kwargs): self.filename = outfilename # the filename has been parsed to be either b(g)zipped or not self.outfile = util.anyopen(self.filename, 'r') # note that, like for xtc and trr files, _numatoms and _numframes are used quasi-private variables # to prevent the properties being recalculated # this is because there is no indexing so the way it measures the number of frames is to read the whole file! self._numatoms = None self._numframes = None self._runtyp = None self.ts = Timestep(0) # need for properties initial calculations self.fixed = 0 self.skip = 1 self.periodic = False self.delta = kwargs.pop("delta", 1.0) # there is no time, so let delta be 1 # update runtyp property self.runtyp if not self.runtyp in ['optimize', 'surface']: raise AttributeError('Wrong RUNTYP= ' + self.runtyp) self.skip_timestep = 1 self.ts = Timestep(self.numatoms) # update numframes property self.numframes # Read in the first timestep self._read_next_timestep()
def __init__(self, filename, **kwargs): self.filename = filename # the filename has been parsed to be either be foo.xyz or foo.xyz.bz2 by coordinates::core.py # so the last file extension will tell us if it is bzipped or not root, ext = os.path.splitext(self.filename) self.xyzfile = util.anyopen(self.filename, "r") self.compression = ext[1:] if ext[1:] != "xyz" else None # note that, like for xtc and trr files, __numatoms and __numframes are used quasi-private variables # to prevent the properties being recalculated # this is because there is no indexing so the way it measures the number of frames is to read the whole file! self.__numatoms = None self.__numframes = None self.fixed = 0 self.skip = 1 self.periodic = False self.delta = kwargs.pop("delta", 1.0) # can set delta manually, default is 1ps (taken from TRJReader) self.skip_timestep = 1 self.ts = self._Timestep(self.numatoms) # numatoms has sideeffects: read trajectory... (FRAGILE) # Read in the first timestep (FRAGILE); # FIXME: Positions on frame 0 (whatever that means) instead of 1 (as all other readers do). # Haven't quite figured out where to start with all the self._reopen() etc. # (Also cannot just use seek() or reset() because that would break with urllib2.urlopen() streams) self._read_next_timestep()
def __init__(self, trzfilename, numatoms=None, convert_units=None, **kwargs): """Creates a TRZ Reader :Arguments: *trzfilename* name of input file *numatoms* number of atoms in trajectory, must taken from topology file! *convert_units* converts units to MDAnalysis defaults """ if numatoms is None: raise ValueError('TRZReader requires the numatoms keyword') if convert_units is None: convert_units = MDAnalysis.core.flags['convert_lengths'] self.convert_units = convert_units self.filename = trzfilename self.trzfile = util.anyopen(self.filename, 'rb') self.__numatoms = numatoms self.fixed = False self.periodic = True self.skip = 1 self.__numframes = None self.__delta = None self.__dt = None self.__skip_timestep = None self._read_trz_header() self.ts = Timestep(self.numatoms, has_force=self.has_force) # structured dtype of a single trajectory frame readarg = str(numatoms) + 'f4' frame_contents = [('p1', 'i4'), ('nframe', 'i4'), ('ntrj', 'i4'), ('natoms', 'i4'), ('treal', 'f8'), ('p2', '2i4'), ('box', '9f8'), ('p3', '2i4'), ('pressure', 'f8'), ('ptensor', '6f8'), ('p4', '3i4'), ('etot', 'f8'), ('ptot', 'f8'), ('ek', 'f8'), ('T', 'f8'), ('p5', '6i4'), ('rx', readarg), ('pad2', '2i4'), ('ry', readarg), ('pad3', '2i4'), ('rz', readarg), ('pad4', '2i4'), ('vx', readarg), ('pad5', '2i4'), ('vy', readarg), ('pad6', '2i4'), ('vz', readarg)] if not self.has_force: frame_contents += [('pad7', 'i4')] else: frame_contents += [ ('pad7', '2i4'), ('fx', readarg), ('pad8', '2i4'), ('fy', readarg), ('pad9', '2i4'), ('fz', readarg), ('pad10', 'i4') ] self._dtype = numpy.dtype(frame_contents) self._read_next_timestep()
def __init__(self, filename, numatoms, title='TRZ', convert_units=None): """Create a TRZWriter :Arguments: *filename* name of output file *numatoms* number of atoms in trajectory :Keywords: *title* title of the trajectory *convert_units* units are converted to the MDAnalysis base format; ``None`` selects the value of :data:`MDAnalysis.core.flags` ['convert_lengths']. (see :ref:`flags-label`) """ self.filename = filename if numatoms is None: raise ValueError("TRZWriter requires the numatoms keyword") if numatoms == 0: raise ValueError("TRZWriter: no atoms in output trajectory") self.numatoms = numatoms if convert_units is None: convert_units = MDAnalysis.core.flags['convert_lengths'] self.convert_units = convert_units self.trzfile = util.anyopen(self.filename, 'wb') self._writeheader(title) floatsize = str(numatoms) + 'f4' self.frameDtype = numpy.dtype([('p1a', 'i4'), ('nframe', 'i4'), ('ntrj', 'i4'), ('natoms', 'i4'), ('treal', 'f8'), ('p1b', 'i4'), ('p2a', 'i4'), ('box', '9f8'), ('p2b', 'i4'), ('p3a', 'i4'), ('pressure', 'f8'), ('ptensor', '6f8'), ('p3b', 'i4'), ('p4a', 'i4'), ('six', 'i4'), ('etot', 'f8'), ('ptot', 'f8'), ('ek', 'f8'), ('T', 'f8'), ('blanks', '2f8'), ('p4b', 'i4'), ('p5a', 'i4'), ('rx', floatsize), ('p5b', 'i4'), ('p6a', 'i4'), ('ry', floatsize), ('p6b', 'i4'), ('p7a', 'i4'), ('rz', floatsize), ('p7b', 'i4'), ('p8a', 'i4'), ('vx', floatsize), ('p8b', 'i4'), ('p9a', 'i4'), ('vy', floatsize), ('p9b', 'i4'), ('p10a', 'i4'), ('vz', floatsize), ('p10b', 'i4')])
def open_trajectory(self): if self.xyzfile is not None: raise IOError(errno.EALREADY, 'XYZ file already opened', self.filename) self.xyzfile = util.anyopen(self.filename, "r") # reset ts ts = self.ts ts.status = 1 ts.frame = 0 ts.step = 0 ts.time = 0 return self.xyzfile
def open_trajectory(self): """Open the trajectory for reading and load first frame.""" self.trjfile = util.anyopen(self.filename, 'r') self.header = self.trjfile.readline() # ignore first line if len(self.header.rstrip()) > 80: # Chimera uses this check raise OSError("Header of AMBER formatted trajectory has more than 80 chars. " "This is probably not a AMBER trajectory.") # reset ts ts = self.ts ts.status = 1 ts.frame = 0 ts.step = 0 ts.time = 0 return self.trjfile
def open_trajectory(self): """Open the trajectory file""" if not self.trzfile is None: raise IOError(errno.EALREADY, 'TRZ file already opened', self.filename) if not os.path.exists(self.filename): raise IOError(errno.ENOENT, 'TRZ file not found', self.filename) self.trzfile = util.anyopen(self.filename, 'rb') #Reset ts ts = self.ts ts.status = 1 ts.frame = 0 ts.step = 0 ts.time = 0 return self.trzfile
def open_trajectory(self): if not self.outfile is None: raise IOError(errno.EALREADY, 'GMS file already opened', self.filename) if not os.path.exists(self.filename): # must check; otherwise might segmentation fault raise IOError(errno.ENOENT, 'GMS file not found', self.filename) self.outfile = util.anyopen(self.filename, 'r') # reset ts ts = self.ts ts.status = 1 ts.frame = 0 ts.step = 0 ts.time = 0 return self.outfile
def __init__(self, filename, numatoms, title='TRZ', convert_units=None): """Create a TRZWriter :Arguments: *filename* name of output file *numatoms* number of atoms in trajectory :Keywords: *title* title of the trajectory *convert_units* units are converted to the MDAnalysis base format; ``None`` selects the value of :data:`MDAnalysis.core.flags` ['convert_lengths']. (see :ref:`flags-label`) """ self.filename = filename if numatoms is None: raise ValueError("TRZWriter requires the numatoms keyword") if numatoms == 0: raise ValueError("TRZWriter: no atoms in output trajectory") self.numatoms = numatoms if convert_units is None: convert_units = MDAnalysis.core.flags['convert_lengths'] self.convert_units = convert_units self.trzfile = util.anyopen(self.filename, 'wb') self._writeheader(title) floatsize = str(numatoms) + 'f4' self.frameDtype = numpy.dtype([ ('p1a', 'i4'), ('nframe', 'i4'), ('ntrj', 'i4'), ('natoms', 'i4'), ('treal', 'f8'), ('p1b', 'i4'), ('p2a', 'i4'), ('box', '9f8'), ('p2b', 'i4'), ('p3a', 'i4'), ('pressure', 'f8'), ('ptensor', '6f8'), ('p3b', 'i4'), ('p4a', 'i4'), ('six', 'i4'), ('etot', 'f8'), ('ptot', 'f8'), ('ek', 'f8'), ('T', 'f8'), ('blanks', '2f8'), ('p4b', 'i4'), ('p5a', 'i4'), ('rx', floatsize), ('p5b', 'i4'), ('p6a', 'i4'), ('ry', floatsize), ('p6b', 'i4'), ('p7a', 'i4'), ('rz', floatsize), ('p7b', 'i4'), ('p8a', 'i4'), ('vx', floatsize), ('p8b', 'i4'), ('p9a', 'i4'), ('vy', floatsize), ('p9b', 'i4'), ('p10a', 'i4'), ('vz', floatsize), ('p10b', 'i4')])
def __init__(self, trzfilename, numatoms=None, convert_units=None, **kwargs): """Creates a TRZ Reader :Arguments: *trzfilename* name of input file *numatoms* number of atoms in trajectory, must taken from topology file! *convert_units* converts units to MDAnalysis defaults """ if numatoms is None: raise ValueError('TRZReader requires the numatoms keyword') if convert_units is None: convert_units = MDAnalysis.core.flags['convert_lengths'] self.convert_units = convert_units self.filename = trzfilename self.trzfile = util.anyopen(self.filename, 'rb') self.__numatoms = numatoms self.fixed = False self.periodic = True self.skip = 1 self.__numframes = None self.__delta = None self.__dt = None self.__skip_timestep = None self._read_trz_header() self.ts = Timestep(self.numatoms, has_force=self.has_force) # structured dtype of a single trajectory frame readarg = str(numatoms) + 'f4' frame_contents = [ ('p1', 'i4'), ('nframe', 'i4'), ('ntrj', 'i4'), ('natoms', 'i4'), ('treal', 'f8'), ('p2', '2i4'), ('box', '9f8'), ('p3', '2i4'), ('pressure', 'f8'), ('ptensor', '6f8'), ('p4', '3i4'), ('etot', 'f8'), ('ptot', 'f8'), ('ek', 'f8'), ('T', 'f8'), ('p5', '6i4'), ('rx', readarg), ('pad2', '2i4'), ('ry', readarg), ('pad3', '2i4'), ('rz', readarg), ('pad4', '2i4'), ('vx', readarg), ('pad5', '2i4'), ('vy', readarg), ('pad6', '2i4'), ('vz', readarg)] if not self.has_force: frame_contents += [('pad7', 'i4')] else: frame_contents += [ ('pad7', '2i4'), ('fx', readarg), ('pad8', '2i4'), ('fy', readarg), ('pad9', '2i4'), ('fz', readarg), ('pad10', 'i4')] self._dtype = numpy.dtype(frame_contents) self._read_next_timestep()
def __init__(self, filename, **kwargs): self.filename = util.filename(filename, ext='pdbqt') self.pdb = util.anyopen(self.filename, 'w')