Skip to content

Commit

Permalink
read DCD Header
Browse files Browse the repository at this point in the history
and fixes other issue I set by accident
  • Loading branch information
kain88-de committed Aug 28, 2016
1 parent 8b4f9d7 commit 9bad8e7
Showing 1 changed file with 14 additions and 37 deletions.
51 changes: 14 additions & 37 deletions package/MDAnalysis/lib/formats/libdcd.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,16 @@
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#

# This is not tested but should serve as an example how to enable windows
# support in the future
IF UNAME_SYSNAME == "Windows":
cdef extern from 'windows.h':
ctypedef HANDLE fio_fd
ELSE:
from libc.stdio cimport SEEK_SET, SEEK_CUR, SEEK_END, FILE
ctypedef FILE * fio_fd;
_whence_vals = {"FIO_SEEK_SET": SEEK_SET,
"FIO_SEEK_CUR": SEEK_CUR,
"FIO_SEEK_END": SEEK_END}
from libc.stdio cimport SEEK_SET, SEEK_CUR, SEEK_END
ctypedef int fio_fd;
_whence_vals = {"FIO_SEEK_SET": SEEK_SET,
"FIO_SEEK_CUR": SEEK_CUR,
"FIO_SEEK_END": SEEK_END}

cdef enum:
FIO_READ = 0x01
FIO_WRITE = 0x02

cdef enum:
DCD_ERRORS = {
0: 'No Problem',
-1: 'Normal EOF',
Expand All @@ -55,40 +48,23 @@ cdef extern from 'include/readdcd.h':
int *nsavc, double *delta, int *nfixed, int **freeind,
float **fixedcoords, int *reverse, int *charmm,
char **remarks, int *len_remarks)
int read_dcdstep(fio_fd fd, int natoms, float *x, float *y, float *z,
float *unitcell, int nfixed, int first, int *freeind,
float *fixedcoords, int reverse, int charmm)
int read_dcdsubset(fio_fd fd, int natoms, int lowerb, int upperb, float *x,
float *y, float *z, float *unitcell, int nfixed,
int first, int *freeind, float *fixedcoords, int reverse,
int charmm)
int skip_dcdstep(fio_fd fd, int natoms, int nfixed, int charmm, int numstep)
void close_dcd_read(int *freeind, float *fixedcoords)
int write_dcdheader(fio_fd fd, const char *remarks, int natoms,
int istart, int nsavc, double delta, int with_unitcell,
int charmm)
int write_dcdstep(fio_fd fd, int curstep, int curframe,
int natoms, const float *x, const float *y, const float *z,
const double *unitcell, int charmm)
int skip_dcdstep(fio_fd fd, int natoms, int nfixed, int charmm, int numsteps)


cdef class DCDFile:
cdef fio_fd fp
cdef readonly fname
cdef int is_open

cdef int natoms
cdef int nsets
cdef int istart
cdef int nsavc
cdef double delta
cdef int nfixed
cdef int **freeind
cdef float **fixedcords
cdef int *freeind
cdef float *fixedcoords
cdef int reverse
cdef int charmm
cdef char **remarks
cdef char *remarks
cdef int len_remarks

def __cinit__(self, fname, mode='r'):
Expand Down Expand Up @@ -134,10 +110,11 @@ cdef class DCDFile:
if not self.is_open:
raise RuntimeError("No file open")

ok = read_dcdheader(self.fd, <int*>&self.natoms, <int*>&self.nsets,
<int*>&self.istart, <int*>&self.nsavc, self.delta,
<int*>self.nfixed, self.freeind, self.fixedcoords,
<int*>self.reverse, <int>*self.reverse,
self.remarks, <int*>&self.len_remarks)
ok = read_dcdheader(self.fp, &self.natoms, &self.nsets, &self.istart,
&self.nsavc, &self.delta, &self.nfixed, &self.freeind,
&self.fixedcoords, &self.reverse,
&self.charmm, &self.remarks, &self.len_remarks)
if ok != 0:
raise IOError("Reading DCD header failed: {}".format(DCD_ERRORS[ok]))

print(self.natoms)

0 comments on commit 9bad8e7

Please sign in to comment.