예제 #1
0
def xtc_coords(filename,idxs=None):
    """ Get the coordinates """

    try:
        import xdrfile.libxdrfile2 as libxdr
    except ImportError:
        raise ImportError("libxdrfile2 library needed for xtc trajectories!")

    file = libxdr.xdrfile_open(filename, "r")
    natoms = libxdr.read_xtc_natoms(filename)
    nframes, offsets = libxdr.read_xtc_numframes(filename)
    box = np.zeros((3,3),dtype=np.float32)
    config = np.zeros((natoms,3),dtype=np.float32)

    if idxs is not None:
        # Seek to read frames specified by idxs.
        nframes = len(idxs)
        coords = np.zeros((nframes,3,natoms),dtype="float")
        for i in xrange(nframes):
            libxdr.xdr_seek(file,offsets[idxs[i]],0)
            status,step,timestmp,prec = libxdr.read_xtc(file, box, config)
            coords[i,:,:] = config.astype("float").T
    else:
        coords = np.zeros((nframes,3,natoms),dtype=np.float32)
        status = libxdr.exdrOK
        i = 0
        while status == libxdr.exdrOK:
            status,step,timestmp,prec = libxdr.read_xtc(file, box, config)
            coords[i,:,:] = config.astype("float").T
            i += 1

    libxdr.xdrfile_close(file)

    return coords
예제 #2
0
파일: reader.py 프로젝트: greatlse/barnaba
    def read(self):

        assert self.model != None, "# Model uninitialized. call parse before read!"

        # read pdb
        if self.xtc == None:
            data = []
            for line in self.fh:
                at = line[0:6].strip()
                if at == "ATOM" or at == "HETATM":
                    vv = [float(line[30:38]), float(line[38:46]), float(line[46:54])]
                    data.append(vv)
                if at == "ENDMDL":
                    self.model.set_coords(np.array(data))
                    self.time += 1
                    # return step
                    return self.time
            self.fh.close()
            return -1

        # read xtc
        else:
            coords = np.zeros((self.natoms, 3), dtype=np.float32)
            box = np.zeros((3, 3), dtype=np.float32)

            status, step, time, prec = libxdrfile2.read_xtc(self.xtc, box, coords)
            self.model.set_coords(10.0 * coords)
            if status:
                libxdrfile2.xdrfile_close(self.xtc)
                return -1
            else:
                return time
예제 #3
0
 def next(self):
     status = libxdr.read_xtc(self.file, self.box, self.config)[0]
     return np.array(self.config, copy=True, dtype=np.float64), status
예제 #4
0
파일: trajectory.py 프로젝트: proc0/ngl
 def _read(self, fp, box, x):
     status, step, ftime, prec = libxdrfile2.read_xtc(fp, box, x)
     return status, step, ftime
예제 #5
0
 def _read( self, fp, box, x ):
     status, step, ftime, prec = libxdrfile2.read_xtc( fp, box, x )
     return status, step, ftime
예제 #6
0
 def next(self):
     status = libxdr.read_xtc(self.file, self.box, self.config)[0]
     return np.array(self.config,copy=True,dtype=np.float64), status