예제 #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
파일: trajectory.py 프로젝트: proc0/ngl
 def __init__(self, file_name):
     self.file_name = str(file_name)
     self.xdr_fp = libxdrfile2.xdrfile_open(self.file_name, "rb")
     self.numatoms = self._read_natoms(self.file_name)
     self.update()
     # allocate coordinate array of the right size and type
     self.x = np.zeros((self.numatoms, libxdrfile2.DIM), dtype=np.float32)
     # allocate unit cell box
     self.box = np.zeros((libxdrfile2.DIM, libxdrfile2.DIM), dtype=np.float32)
예제 #3
0
def xtc_nframes(filename):
    """ 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)
    return nframes, natoms
예제 #4
0
 def __init__( self, file_name ):
     self.file_name = str( file_name )
     self.xdr_fp = libxdrfile2.xdrfile_open( self.file_name, 'rb' )
     self.numatoms = self._read_natoms( self.file_name )
     self.update()
     # allocate coordinate array of the right size and type
     self.x = np.zeros(
         ( self.numatoms, libxdrfile2.DIM ), dtype=np.float32
     )
     # allocate unit cell box
     self.box = np.zeros(
         ( libxdrfile2.DIM, libxdrfile2.DIM ), dtype=np.float32
     )
예제 #5
0
    def __init__(self, filename, **kwargs):
        raise NotImplementedError
        try:
            import xdrfile.libxdrfile2 as libxdr
        except ImportError:
            raise ImportError("libxdrfile2 library needed for xtc trajectories!")

        self.filename = filename
        self.velocities = False
        self.file = libxdr.xdrfile_open(filename, 'r')
        self.natoms = libxdr.read_xtc_natoms(self.filename)
        self.nframes, self.offsets = libxdr.read_xtc_numframes(self.filename)
        self.box = np.zeros((3,3),dtype=np.float32)
        self.config = np.zeros((self.natoms,3),dtype=np.float32)
예제 #6
0
    def __init__(self, filename, **kwargs):
        raise NotImplementedError
        try:
            import xdrfile.libxdrfile2 as libxdr
        except ImportError:
            raise ImportError(
                "libxdrfile2 library needed for xtc trajectories!")

        self.filename = filename
        self.velocities = False
        self.file = libxdr.xdrfile_open(filename, 'r')
        self.natoms = libxdr.read_xtc_natoms(self.filename)
        self.nframes, self.offsets = libxdr.read_xtc_numframes(self.filename)
        self.box = np.zeros((3, 3), dtype=np.float32)
        self.config = np.zeros((self.natoms, 3), dtype=np.float32)
예제 #7
0
파일: reader.py 프로젝트: greatlse/barnaba
 def set_xtc(self, xtcfile):
     if xtcfile != None:
         natoms = libxdrfile2.read_xtc_natoms(xtcfile)
         assert natoms == self.natoms
         self.xtc = libxdrfile2.xdrfile_open(xtcfile, "r")