diff --git a/package/MDAnalysis/lib/formats/xtc.c b/package/MDAnalysis/lib/formats/xtc.c index e568a5ca730..c204f998d12 100644 --- a/package/MDAnalysis/lib/formats/xtc.c +++ b/package/MDAnalysis/lib/formats/xtc.c @@ -1122,6 +1122,29 @@ static void __Pyx_ExceptionReset(PyObject *type, PyObject *value, PyObject *tb); static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); + +#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ + __Pyx_GetItemInt_Generic(o, to_py_func(i)))) +#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, + int is_list, int wraparound, int boundscheck); + static void __Pyx_RaiseBufferIndexError(int axis); static CYTHON_INLINE int __Pyx_GetBufferAndValidate(Py_buffer* buf, PyObject* obj, @@ -1153,29 +1176,6 @@ static CYTHON_INLINE int __pyx_sub_acquisition_count_locked( static CYTHON_INLINE void __Pyx_INC_MEMVIEW(__Pyx_memviewslice *, int, int); static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *, int, int); -#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ - (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ - __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ - (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ - __Pyx_GetItemInt_Generic(o, to_py_func(i)))) -#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ - (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ - __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ - (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, - int wraparound, int boundscheck); -#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ - (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ - __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ - (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, - int wraparound, int boundscheck); -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, - int is_list, int wraparound, int boundscheck); - -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); - #if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { PyObject *value; @@ -1343,9 +1343,6 @@ static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); -static PyObject *__pyx_memview_get_nn___pyx_t_3lib_7formats_3xtc_DTYPE_T(const char *itemp); -static int __pyx_memview_set_nn___pyx_t_3lib_7formats_3xtc_DTYPE_T(const char *itemp, PyObject *obj); - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); #if CYTHON_CCOMPLEX @@ -1666,7 +1663,6 @@ static char __pyx_k_name_2[] = "__name__"; static char __pyx_k_struct[] = "struct"; static char __pyx_k_unpack[] = "unpack"; static char __pyx_k_IOError[] = "IOError"; -static char __pyx_k_asarray[] = "asarray"; static char __pyx_k_exc_val[] = "exc_val"; static char __pyx_k_float32[] = "float32"; static char __pyx_k_fortran[] = "fortran"; @@ -1778,7 +1774,6 @@ static PyObject *__pyx_kp_s_XTC_read_error; static PyObject *__pyx_kp_s_XTC_write_error; static PyObject *__pyx_n_s_allclose; static PyObject *__pyx_n_s_allocate_buffer; -static PyObject *__pyx_n_s_asarray; static PyObject *__pyx_n_s_ascontiguousarray; static PyObject *__pyx_n_s_atol; static PyObject *__pyx_n_s_base; @@ -4157,8 +4152,8 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_22read(struct __pyx_obj_3l int __pyx_v_step; float __pyx_v_time; float __pyx_v_prec; - __Pyx_memviewslice __pyx_v_xyz = { 0, 0, { 0 }, { 0 }, { 0 } }; - __Pyx_memviewslice __pyx_v_box = { 0, 0, { 0 }, { 0 }, { 0 } }; + PyArrayObject *__pyx_v_xyz = 0; + PyArrayObject *__pyx_v_box = 0; PyObject *__pyx_r = NULL; __Pyx_RefNannyDeclarations int __pyx_t_1; @@ -4167,14 +4162,7 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_22read(struct __pyx_obj_3l PyObject *__pyx_t_4 = NULL; PyObject *__pyx_t_5 = NULL; PyObject *__pyx_t_6 = NULL; - __Pyx_memviewslice __pyx_t_7 = { 0, 0, { 0 }, { 0 }, { 0 } }; - Py_ssize_t __pyx_t_8; - Py_ssize_t __pyx_t_9; - int __pyx_t_10; - Py_ssize_t __pyx_t_11; - Py_ssize_t __pyx_t_12; - PyObject *__pyx_t_13 = NULL; - PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_7 = NULL; int __pyx_lineno = 0; const char *__pyx_filename = NULL; int __pyx_clineno = 0; @@ -4308,8 +4296,8 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_22read(struct __pyx_obj_3l /* "lib/formats/xtc.pyx":218 * cdef float time, prec * - * cdef DTYPE_T[:, ::1] xyz = np.empty((self.n_atoms, DIMS), dtype=DTYPE) # <<<<<<<<<<<<<< - * cdef DTYPE_T[:, ::1] box = np.empty((DIMS, DIMS), dtype=DTYPE) + * cdef np.ndarray xyz = np.empty((self.n_atoms, DIMS), dtype=DTYPE) # <<<<<<<<<<<<<< + * cdef np.ndarray box = np.empty((DIMS, DIMS), dtype=DTYPE) * */ __pyx_t_4 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -4345,17 +4333,14 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_22read(struct __pyx_obj_3l __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_d_dc_nn___pyx_t_3lib_7formats_3xtc_DTYPE_T(__pyx_t_4); - if (unlikely(!__pyx_t_7.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_xyz = __pyx_t_7; - __pyx_t_7.memview = NULL; - __pyx_t_7.data = NULL; + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 218; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_xyz = ((PyArrayObject *)__pyx_t_4); + __pyx_t_4 = 0; /* "lib/formats/xtc.pyx":219 * - * cdef DTYPE_T[:, ::1] xyz = np.empty((self.n_atoms, DIMS), dtype=DTYPE) - * cdef DTYPE_T[:, ::1] box = np.empty((DIMS, DIMS), dtype=DTYPE) # <<<<<<<<<<<<<< + * cdef np.ndarray xyz = np.empty((self.n_atoms, DIMS), dtype=DTYPE) + * cdef np.ndarray box = np.empty((DIMS, DIMS), dtype=DTYPE) # <<<<<<<<<<<<<< * * return_code = xdrlib.read_xtc(self.xfp, self.n_atoms, &step, */ @@ -4392,71 +4377,22 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_22read(struct __pyx_obj_3l __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_7 = __Pyx_PyObject_to_MemoryviewSlice_d_dc_nn___pyx_t_3lib_7formats_3xtc_DTYPE_T(__pyx_t_4); - if (unlikely(!__pyx_t_7.memview)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; - __pyx_v_box = __pyx_t_7; - __pyx_t_7.memview = NULL; - __pyx_t_7.data = NULL; - - /* "lib/formats/xtc.pyx":222 - * - * return_code = xdrlib.read_xtc(self.xfp, self.n_atoms, &step, - * &time, &box[0, 0], # <<<<<<<<<<<<<< - * &xyz[0, 0], &prec) - * if return_code != xdrlib.EOK and return_code != xdrlib.EENDOFFILE: - */ - __pyx_t_8 = 0; - __pyx_t_9 = 0; - __pyx_t_10 = -1; - if (__pyx_t_8 < 0) { - __pyx_t_8 += __pyx_v_box.shape[0]; - if (unlikely(__pyx_t_8 < 0)) __pyx_t_10 = 0; - } else if (unlikely(__pyx_t_8 >= __pyx_v_box.shape[0])) __pyx_t_10 = 0; - if (__pyx_t_9 < 0) { - __pyx_t_9 += __pyx_v_box.shape[1]; - if (unlikely(__pyx_t_9 < 0)) __pyx_t_10 = 1; - } else if (unlikely(__pyx_t_9 >= __pyx_v_box.shape[1])) __pyx_t_10 = 1; - if (unlikely(__pyx_t_10 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_10); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 222; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } - - /* "lib/formats/xtc.pyx":223 - * return_code = xdrlib.read_xtc(self.xfp, self.n_atoms, &step, - * &time, &box[0, 0], - * &xyz[0, 0], &prec) # <<<<<<<<<<<<<< - * if return_code != xdrlib.EOK and return_code != xdrlib.EENDOFFILE: - * raise RuntimeError('XTC Read Error occured: {}'.format(return_code)) - */ - __pyx_t_11 = 0; - __pyx_t_12 = 0; - __pyx_t_10 = -1; - if (__pyx_t_11 < 0) { - __pyx_t_11 += __pyx_v_xyz.shape[0]; - if (unlikely(__pyx_t_11 < 0)) __pyx_t_10 = 0; - } else if (unlikely(__pyx_t_11 >= __pyx_v_xyz.shape[0])) __pyx_t_10 = 0; - if (__pyx_t_12 < 0) { - __pyx_t_12 += __pyx_v_xyz.shape[1]; - if (unlikely(__pyx_t_12 < 0)) __pyx_t_10 = 1; - } else if (unlikely(__pyx_t_12 >= __pyx_v_xyz.shape[1])) __pyx_t_10 = 1; - if (unlikely(__pyx_t_10 != -1)) { - __Pyx_RaiseBufferIndexError(__pyx_t_10); - {__pyx_filename = __pyx_f[0]; __pyx_lineno = 223; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - } + if (!(likely(((__pyx_t_4) == Py_None) || likely(__Pyx_TypeTest(__pyx_t_4, __pyx_ptype_5numpy_ndarray))))) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 219; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_v_box = ((PyArrayObject *)__pyx_t_4); + __pyx_t_4 = 0; /* "lib/formats/xtc.pyx":221 - * cdef DTYPE_T[:, ::1] box = np.empty((DIMS, DIMS), dtype=DTYPE) + * cdef np.ndarray box = np.empty((DIMS, DIMS), dtype=DTYPE) * * return_code = xdrlib.read_xtc(self.xfp, self.n_atoms, &step, # <<<<<<<<<<<<<< - * &time, &box[0, 0], - * &xyz[0, 0], &prec) + * &time, box.data, + * xyz.data, &prec) */ - __pyx_v_return_code = read_xtc(__pyx_v_self->xfp, __pyx_v_self->n_atoms, ((int *)(&__pyx_v_step)), (&__pyx_v_time), ((float (*)[3])(&(*((__pyx_t_3lib_7formats_3xtc_DTYPE_T *) ( /* dim=1 */ ((char *) (((__pyx_t_3lib_7formats_3xtc_DTYPE_T *) ( /* dim=0 */ (__pyx_v_box.data + __pyx_t_8 * __pyx_v_box.strides[0]) )) + __pyx_t_9)) ))))), ((rvec *)(&(*((__pyx_t_3lib_7formats_3xtc_DTYPE_T *) ( /* dim=1 */ ((char *) (((__pyx_t_3lib_7formats_3xtc_DTYPE_T *) ( /* dim=0 */ (__pyx_v_xyz.data + __pyx_t_11 * __pyx_v_xyz.strides[0]) )) + __pyx_t_12)) ))))), ((float *)(&__pyx_v_prec))); + __pyx_v_return_code = read_xtc(__pyx_v_self->xfp, __pyx_v_self->n_atoms, ((int *)(&__pyx_v_step)), (&__pyx_v_time), ((float (*)[3])__pyx_v_box->data), ((rvec *)__pyx_v_xyz->data), ((float *)(&__pyx_v_prec))); /* "lib/formats/xtc.pyx":224 - * &time, &box[0, 0], - * &xyz[0, 0], &prec) + * &time, box.data, + * xyz.data, &prec) * if return_code != xdrlib.EOK and return_code != xdrlib.EENDOFFILE: # <<<<<<<<<<<<<< * raise RuntimeError('XTC Read Error occured: {}'.format(return_code)) * @@ -4473,7 +4409,7 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_22read(struct __pyx_obj_3l if (__pyx_t_3) { /* "lib/formats/xtc.pyx":225 - * &xyz[0, 0], &prec) + * xyz.data, &prec) * if return_code != xdrlib.EOK and return_code != xdrlib.EENDOFFILE: * raise RuntimeError('XTC Read Error occured: {}'.format(return_code)) # <<<<<<<<<<<<<< * @@ -4498,15 +4434,15 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_22read(struct __pyx_obj_3l __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; __Pyx_GOTREF(__pyx_t_4); } else { - __pyx_t_13 = PyTuple_New(1+1); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_13, 0, __pyx_t_6); __pyx_t_6 = NULL; + __pyx_t_7 = PyTuple_New(1+1); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_6); PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_t_6); __pyx_t_6 = NULL; __Pyx_GIVEREF(__pyx_t_5); - PyTuple_SET_ITEM(__pyx_t_13, 0+1, __pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_7, 0+1, __pyx_t_5); __pyx_t_5 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_13, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; } __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} @@ -4522,8 +4458,8 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_22read(struct __pyx_obj_3l {__pyx_filename = __pyx_f[0]; __pyx_lineno = 225; __pyx_clineno = __LINE__; goto __pyx_L1_error;} /* "lib/formats/xtc.pyx":224 - * &time, &box[0, 0], - * &xyz[0, 0], &prec) + * &time, box.data, + * xyz.data, &prec) * if return_code != xdrlib.EOK and return_code != xdrlib.EENDOFFILE: # <<<<<<<<<<<<<< * raise RuntimeError('XTC Read Error occured: {}'.format(return_code)) * @@ -4583,7 +4519,7 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_22read(struct __pyx_obj_3l * if return_code == xdrlib.EOK: * self.current_frame += 1 # <<<<<<<<<<<<<< * # TODO:(max) this is perfect to return a named tuple! - * return np.asarray(xyz), np.asarray(box), step, time, prec + * return xyz, box, step, time, prec */ __pyx_v_self->current_frame = (__pyx_v_self->current_frame + 1); @@ -4599,100 +4535,34 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_22read(struct __pyx_obj_3l /* "lib/formats/xtc.pyx":234 * self.current_frame += 1 * # TODO:(max) this is perfect to return a named tuple! - * return np.asarray(xyz), np.asarray(box), step, time, prec # <<<<<<<<<<<<<< + * return xyz, box, step, time, prec # <<<<<<<<<<<<<< * * def write(self, xyz, box, int step, float time, float prec=1000.0): */ __Pyx_XDECREF(__pyx_r); - __pyx_t_2 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_asarray); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __pyx_memoryview_fromslice(__pyx_v_xyz, 2, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_3lib_7formats_3xtc_DTYPE_T, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_3lib_7formats_3xtc_DTYPE_T, 0);; if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __pyx_t_5 = NULL; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_13))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_13); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_13, function); - } - } - if (!__pyx_t_5) { - __pyx_t_4 = __Pyx_PyObject_CallOneArg(__pyx_t_13, __pyx_t_2); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __Pyx_GOTREF(__pyx_t_4); - } else { - __pyx_t_6 = PyTuple_New(1+1); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_6, 0+1, __pyx_t_2); - __pyx_t_2 = 0; - __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_6, NULL); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_4); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - } - __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; - __pyx_t_6 = __Pyx_GetModuleGlobalName(__pyx_n_s_np); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_2 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_asarray); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_2); - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __pyx_t_6 = __pyx_memoryview_fromslice(__pyx_v_box, 2, (PyObject *(*)(char *)) __pyx_memview_get_nn___pyx_t_3lib_7formats_3xtc_DTYPE_T, (int (*)(char *, PyObject *)) __pyx_memview_set_nn___pyx_t_3lib_7formats_3xtc_DTYPE_T, 0);; if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); - __pyx_t_5 = NULL; - if (CYTHON_COMPILING_IN_CPYTHON && unlikely(PyMethod_Check(__pyx_t_2))) { - __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_2); - if (likely(__pyx_t_5)) { - PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); - __Pyx_INCREF(__pyx_t_5); - __Pyx_INCREF(function); - __Pyx_DECREF_SET(__pyx_t_2, function); - } - } - if (!__pyx_t_5) { - __pyx_t_13 = __Pyx_PyObject_CallOneArg(__pyx_t_2, __pyx_t_6); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; - __Pyx_GOTREF(__pyx_t_13); - } else { - __pyx_t_14 = PyTuple_New(1+1); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __Pyx_GIVEREF(__pyx_t_5); PyTuple_SET_ITEM(__pyx_t_14, 0, __pyx_t_5); __pyx_t_5 = NULL; - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_14, 0+1, __pyx_t_6); - __pyx_t_6 = 0; - __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_2, __pyx_t_14, NULL); if (unlikely(!__pyx_t_13)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_13); - __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; - } - __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; - __pyx_t_2 = __Pyx_PyInt_From_int(__pyx_v_step); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_step); if (unlikely(!__pyx_t_4)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_2 = PyFloat_FromDouble(__pyx_v_time); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_2); - __pyx_t_14 = PyFloat_FromDouble(__pyx_v_time); if (unlikely(!__pyx_t_14)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_14); - __pyx_t_6 = PyFloat_FromDouble(__pyx_v_prec); if (unlikely(!__pyx_t_6)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} - __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = PyFloat_FromDouble(__pyx_v_prec); if (unlikely(!__pyx_t_7)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} + __Pyx_GOTREF(__pyx_t_7); __pyx_t_5 = PyTuple_New(5); if (unlikely(!__pyx_t_5)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 234; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(((PyObject *)__pyx_v_xyz)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_xyz)); + PyTuple_SET_ITEM(__pyx_t_5, 0, ((PyObject *)__pyx_v_xyz)); + __Pyx_INCREF(((PyObject *)__pyx_v_box)); + __Pyx_GIVEREF(((PyObject *)__pyx_v_box)); + PyTuple_SET_ITEM(__pyx_t_5, 1, ((PyObject *)__pyx_v_box)); __Pyx_GIVEREF(__pyx_t_4); - PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_4); - __Pyx_GIVEREF(__pyx_t_13); - PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_13); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_4); __Pyx_GIVEREF(__pyx_t_2); - PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_t_2); - __Pyx_GIVEREF(__pyx_t_14); - PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_14); - __Pyx_GIVEREF(__pyx_t_6); - PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_2); + __Pyx_GIVEREF(__pyx_t_7); + PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_t_7); __pyx_t_4 = 0; - __pyx_t_13 = 0; __pyx_t_2 = 0; - __pyx_t_14 = 0; - __pyx_t_6 = 0; + __pyx_t_7 = 0; __pyx_r = __pyx_t_5; __pyx_t_5 = 0; goto __pyx_L0; @@ -4711,21 +4581,19 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_22read(struct __pyx_obj_3l __Pyx_XDECREF(__pyx_t_4); __Pyx_XDECREF(__pyx_t_5); __Pyx_XDECREF(__pyx_t_6); - __PYX_XDEC_MEMVIEW(&__pyx_t_7, 1); - __Pyx_XDECREF(__pyx_t_13); - __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_7); __Pyx_AddTraceback("lib.formats.xtc.XTCFile.read", __pyx_clineno, __pyx_lineno, __pyx_filename); __pyx_r = NULL; __pyx_L0:; - __PYX_XDEC_MEMVIEW(&__pyx_v_xyz, 1); - __PYX_XDEC_MEMVIEW(&__pyx_v_box, 1); + __Pyx_XDECREF((PyObject *)__pyx_v_xyz); + __Pyx_XDECREF((PyObject *)__pyx_v_box); __Pyx_XGIVEREF(__pyx_r); __Pyx_RefNannyFinishContext(); return __pyx_r; } /* "lib/formats/xtc.pyx":236 - * return np.asarray(xyz), np.asarray(box), step, time, prec + * return xyz, box, step, time, prec * * def write(self, xyz, box, int step, float time, float prec=1000.0): # <<<<<<<<<<<<<< * """write one frame into XTC file @@ -5369,7 +5237,7 @@ static PyObject *__pyx_pf_3lib_7formats_3xtc_7XTCFile_24write(struct __pyx_obj_3 __pyx_v_self->current_frame = (__pyx_v_self->current_frame + 1); /* "lib/formats/xtc.pyx":236 - * return np.asarray(xyz), np.asarray(box), step, time, prec + * return xyz, box, step, time, prec * * def write(self, xyz, box, int step, float time, float prec=1000.0): # <<<<<<<<<<<<<< * """write one frame into XTC file @@ -20031,7 +19899,6 @@ static __Pyx_StringTabEntry __pyx_string_tab[] = { {&__pyx_kp_s_XTC_write_error, __pyx_k_XTC_write_error, sizeof(__pyx_k_XTC_write_error), 0, 0, 1, 0}, {&__pyx_n_s_allclose, __pyx_k_allclose, sizeof(__pyx_k_allclose), 0, 0, 1, 1}, {&__pyx_n_s_allocate_buffer, __pyx_k_allocate_buffer, sizeof(__pyx_k_allocate_buffer), 0, 0, 1, 1}, - {&__pyx_n_s_asarray, __pyx_k_asarray, sizeof(__pyx_k_asarray), 0, 0, 1, 1}, {&__pyx_n_s_ascontiguousarray, __pyx_k_ascontiguousarray, sizeof(__pyx_k_ascontiguousarray), 0, 0, 1, 1}, {&__pyx_n_s_atol, __pyx_k_atol, sizeof(__pyx_k_atol), 0, 0, 1, 1}, {&__pyx_n_s_base, __pyx_k_base, sizeof(__pyx_k_base), 0, 0, 1, 1}, @@ -21543,6 +21410,99 @@ static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) return -1; } +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + if (likely(PyObject_TypeCheck(obj, type))) + return 1; + PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", + Py_TYPE(obj)->tp_name, type->tp_name); + return 0; +} + +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (!j) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_COMPILING_IN_CPYTHON + if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o); + if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_COMPILING_IN_CPYTHON + if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_COMPILING_IN_CPYTHON + if (is_list || PyList_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { + PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; + if (likely(m && m->sq_item)) { + if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { + Py_ssize_t l = m->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (PyErr_ExceptionMatches(PyExc_OverflowError)) + PyErr_Clear(); + else + return NULL; + } + } + return m->sq_item(o, i); + } + } +#else + if (is_list || PySequence_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + static void __Pyx_RaiseBufferIndexError(int axis) { PyErr_Format(PyExc_IndexError, "Out of bounds on buffer access (axis %d)", axis); @@ -22231,99 +22191,6 @@ static CYTHON_INLINE void __Pyx_XDEC_MEMVIEW(__Pyx_memviewslice *memslice, } } -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { - PyObject *r; - if (!j) return NULL; - r = PyObject_GetItem(o, j); - Py_DECREF(j); - return r; -} -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_COMPILING_IN_CPYTHON - if (wraparound & unlikely(i < 0)) i += PyList_GET_SIZE(o); - if ((!boundscheck) || likely((0 <= i) & (i < PyList_GET_SIZE(o)))) { - PyObject *r = PyList_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_COMPILING_IN_CPYTHON - if (wraparound & unlikely(i < 0)) i += PyTuple_GET_SIZE(o); - if ((!boundscheck) || likely((0 <= i) & (i < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, i); - Py_INCREF(r); - return r; - } - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -#else - return PySequence_GetItem(o, i); -#endif -} -static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, - CYTHON_NCP_UNUSED int wraparound, - CYTHON_NCP_UNUSED int boundscheck) { -#if CYTHON_COMPILING_IN_CPYTHON - if (is_list || PyList_CheckExact(o)) { - Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); - if ((!boundscheck) || (likely((n >= 0) & (n < PyList_GET_SIZE(o))))) { - PyObject *r = PyList_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } - else if (PyTuple_CheckExact(o)) { - Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); - if ((!boundscheck) || likely((n >= 0) & (n < PyTuple_GET_SIZE(o)))) { - PyObject *r = PyTuple_GET_ITEM(o, n); - Py_INCREF(r); - return r; - } - } else { - PySequenceMethods *m = Py_TYPE(o)->tp_as_sequence; - if (likely(m && m->sq_item)) { - if (wraparound && unlikely(i < 0) && likely(m->sq_length)) { - Py_ssize_t l = m->sq_length(o); - if (likely(l >= 0)) { - i += l; - } else { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) - PyErr_Clear(); - else - return NULL; - } - } - return m->sq_item(o, i); - } - } -#else - if (is_list || PySequence_Check(o)) { - return PySequence_GetItem(o, i); - } -#endif - return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); -} - -static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { - if (unlikely(!type)) { - PyErr_SetString(PyExc_SystemError, "Missing type object"); - return 0; - } - if (likely(PyObject_TypeCheck(obj, type))) - return 1; - PyErr_Format(PyExc_TypeError, "Cannot convert %.200s to %.200s", - Py_TYPE(obj)->tp_name, type->tp_name); - return 0; -} - static CYTHON_INLINE void __Pyx_RaiseTooManyValuesError(Py_ssize_t expected) { PyErr_Format(PyExc_ValueError, "too many values to unpack (expected %" CYTHON_FORMAT_SSIZE_T "d)", expected); @@ -23063,17 +22930,6 @@ static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { } } -static PyObject *__pyx_memview_get_nn___pyx_t_3lib_7formats_3xtc_DTYPE_T(const char *itemp) { - return (PyObject *) PyFloat_FromDouble(*(__pyx_t_3lib_7formats_3xtc_DTYPE_T *) itemp); -} -static int __pyx_memview_set_nn___pyx_t_3lib_7formats_3xtc_DTYPE_T(const char *itemp, PyObject *obj) { - __pyx_t_3lib_7formats_3xtc_DTYPE_T value = __pyx_PyFloat_AsFloat(obj); - if ((value == (npy_float32)-1) && PyErr_Occurred()) - return 0; - *(__pyx_t_3lib_7formats_3xtc_DTYPE_T *) itemp = value; - return 1; -} - static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { const long neg_one = (long) -1, const_zero = (long) 0; const int is_unsigned = neg_one > const_zero; diff --git a/package/MDAnalysis/lib/formats/xtc.pyx b/package/MDAnalysis/lib/formats/xtc.pyx index d965ae8da4f..d48bbe13c8d 100644 --- a/package/MDAnalysis/lib/formats/xtc.pyx +++ b/package/MDAnalysis/lib/formats/xtc.pyx @@ -215,12 +215,12 @@ cdef class XTCFile: cdef int step cdef float time, prec - cdef DTYPE_T[:, ::1] xyz = np.empty((self.n_atoms, DIMS), dtype=DTYPE) - cdef DTYPE_T[:, ::1] box = np.empty((DIMS, DIMS), dtype=DTYPE) + cdef np.ndarray xyz = np.empty((self.n_atoms, DIMS), dtype=DTYPE) + cdef np.ndarray box = np.empty((DIMS, DIMS), dtype=DTYPE) return_code = xdrlib.read_xtc(self.xfp, self.n_atoms, &step, - &time, &box[0, 0], - &xyz[0, 0], &prec) + &time, box.data, + xyz.data, &prec) if return_code != xdrlib.EOK and return_code != xdrlib.EENDOFFILE: raise RuntimeError('XTC Read Error occured: {}'.format(return_code)) @@ -231,7 +231,7 @@ cdef class XTCFile: if return_code == xdrlib.EOK: self.current_frame += 1 # TODO:(max) this is perfect to return a named tuple! - return np.asarray(xyz), np.asarray(box), step, time, prec + return xyz, box, step, time, prec def write(self, xyz, box, int step, float time, float prec=1000.0): """write one frame into XTC file