From ff92b01e3e123668bfe02c03f71ff6de4d4d8e06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20M=C3=BCller?= Date: Sat, 23 Apr 2016 19:13:39 +0200 Subject: [PATCH] Reduce verbosity when reading tpr files. --- pygmx/tpxio.pyx | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/pygmx/tpxio.pyx b/pygmx/tpxio.pyx index 4f05066..0afcdf9 100644 --- a/pygmx/tpxio.pyx +++ b/pygmx/tpxio.pyx @@ -1,8 +1,8 @@ # cython: c_string_type=unicode, c_string_encoding=utf8 # Cython wrapper around tpxio.cpp -# from cython cimport view -# from array import array +from libc cimport stdio + import numpy as np cimport numpy as np @@ -88,6 +88,21 @@ cdef atom_charge(t_atom atom): cdef atom_mass(t_atom atom): return atom.m + +cdef open_tpx(const char* filename, t_inputrec *ir, matrix box, int *natoms, gmx_mtop_t *top): + #cdef stdio.FILE *old_stderr = stdio.stderr + #stdio.stderr = stdio.freopen('tmp', 'w', stdio.stderr) + cdef char buffer[stdio.BUFSIZ] + stdio.setbuf(stdio.stderr, buffer) + return_code = read_tpx(filename, ir, box, natoms, NULL, NULL, NULL, top) + + for i in range(stdio.BUFSIZ): + buffer[i] = 0 + stdio.fflush(stdio.stderr) + stdio.fseek(stdio.stderr, 0, stdio.SEEK_END) + stdio.setbuf(stdio.stderr, NULL) + return return_code + cdef class TPXReader: cdef: t_tpxheader header @@ -181,16 +196,11 @@ cdef class TPXReader: # cdef np.ndarray[real, ndim=2] coordinates = np.empty((self.n_atoms, 3), dtype=np.float32) # cdef np.ndarray[real, ndim=2] velocites = np.empty((self.n_atoms, 3), dtype=np.float32) # cdef np.ndarray[real, ndim=2] forces = np.empty((self.n_atoms, 3), dtype=np.float32) - - return_code = read_tpx( + open_tpx( filename, &self.input_record, self.box, &self.n_atoms, - NULL, NULL, NULL, - # coordinates.data, - # velocites.data, - # forces.data, &self.topology ) self.topology_name = self.topology.name[0]