From 9bad8e731e7dfb647552683fff8b0c08a000ca94 Mon Sep 17 00:00:00 2001 From: Max Linke Date: Sun, 28 Aug 2016 19:08:42 +0200 Subject: [PATCH] read DCD Header and fixes other issue I set by accident --- package/MDAnalysis/lib/formats/libdcd.pyx | 51 +++++++---------------- 1 file changed, 14 insertions(+), 37 deletions(-) diff --git a/package/MDAnalysis/lib/formats/libdcd.pyx b/package/MDAnalysis/lib/formats/libdcd.pyx index d9da15afccb..fec875a9ac6 100644 --- a/package/MDAnalysis/lib/formats/libdcd.pyx +++ b/package/MDAnalysis/lib/formats/libdcd.pyx @@ -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', @@ -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'): @@ -134,10 +110,11 @@ cdef class DCDFile: if not self.is_open: raise RuntimeError("No file open") - ok = read_dcdheader(self.fd, &self.natoms, &self.nsets, - &self.istart, &self.nsavc, self.delta, - self.nfixed, self.freeind, self.fixedcoords, - self.reverse, *self.reverse, - self.remarks, &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)