libvmdmolfile.i 22.7 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
/* -*- C -*-  (not really, but good for syntax highlighting) */
/* SWIG interface for libvmdmolfile of VMD molfile_plugins
   Copyright (c) 2017 Berk Onat <b.onat@warwick.ac.uk>
   Published under the GNU GENERAL PUBLIC LICENSE Version 2 (or higher)

   swig -python -outdir MDAnalysis/coordinates/xdrfile src/xdrfile/libxdrfile2.i
*/
%define DOCSTRING
"
:Author:  Berk Onat <b.onat@warwick.ac.uk>
:Year:    2017
:Licence: GNU GENERAL PUBLIC LICENSE Version 2 (or higher)


The Gromacs XTC/TRR library :mod:`libxdrfile2`
==============================================

:mod:`libxdrfile2`, a derivative of the Gromacs_ `libxdrfile library`_, provides an
interface to some high-level functions for XTC/TRR trajectory handling.
Only functions required for reading and processing whole trajectories are exposed at
the moment; low-level routines to read individual numbers are not provided. In
addition, :mod:`libxdrfile2` exposes functions to allow fast frame indexing and XDR
file seeking.

The functions querying the numbers of atoms in a trajectory frame
(:func:`read_xtc_natoms` and :func:`read_trr_natoms`) open a file themselves and
only require the file name.

All other functions operate on a *XDRFILE* object, which is a special file
handle for xdr files.  Any xdr-based trajectory file (XTC or TRR format) always
has to be opened with :func:`xdrfile_open`. When done, close the trajectory
with :func:`xdrfile_close`.

The functions fill or read existing arrays of coordinates; they never allocate
these arrays themselves. Hence they need to be setup outside libxdrfile2 as
numpy arrays. The exception to these are the indexing ones functions that take
care of array allocation and transference to a garbage-collectable memory object.


.. _Gromacs: http://www.gromacs.org
.. _libxdrfile library: http://www.gromacs.org/Developer_Zone/Programming_Guide/XTC_Library

.. versionchanged:: 0.8.0
   :mod:`libxdrfile2` is now used instead of :mod:`libxdrfile`. :mod:`libxdrfile2` is
   based on :mod:`libxdrfile` but has xdr seeking and indexing capabilities.
   Unlike :mod:`libxdrfile` before it, :mod:`libxdrfile2` is distributed under the GNU
   GENERAL PUBLIC LICENSE, version 2 (or higher).


Example: Reading from a XTC
---------------------------

In the example we read coordinate frames from an existing XTC trajectory::

  import numpy as np
  from libxdrfile2 import xdrfile_open, xdrfile_close, read_xtc_natoms, read_xtc, DIM, exdrOK
  xtc = 'md.xtc'

  # get number of atoms
  natoms = read_xtc_natoms(xtc)

  # allocate coordinate array of the right size and type
  # (the type float32 is crucial to match the underlying C-code!!)
  x = np.zeros((natoms, DIM), dtype=np.float32)
  # allocate unit cell box
  box = np.zeros((DIM, DIM), dtype=np.float32)

  # open file
  XTC = xdrfile_open(xtc, 'r')

  # loop through file until return status signifies end or a problem
  # (it should become exdrENDOFFILE on the last iteration)
  status = exdrOK
  while status == exdrOK:
     status,step,time,prec = read_xtc(XTC, box, x)
     # do something with x
     centre = x.mean(axis=0)
     print 'Centre of geometry at %(time)g ps: %(centre)r' % vars()

  # finally close file
  xdrfile_close(XTC)

Note that only the *contents* of the coordinate and unitcell arrays *x* and
*box* change.


Functions and constants
-----------------------

The module defines a number of constants such as :data:`DIM` or the
`Status symbols`_.

.. data:: DIM

          The number of cartesian dimensions for which the underlying C-code
          was compiled; this is most certainly 3.


Status symbols
~~~~~~~~~~~~~~

A number of symbols are exported; they all start with the letters
``exdr``. Important ones are:

.. data:: exdrOK

          Success of xdr file read/write operation.

.. data:: exdrCLOSE

          xdr file is closed

.. data:: exdrENDOFFILE

          end of file was reached (response of :func:`read_xtc` and
          :func:`read_trr` after the last read frame)

.. data:: exdrFILENOTFOUND

          :func:`xdrfile_open` cannot find the requested file

Other symbols that are used internally are:

.. data:: exdrHEADER

          header

.. data:: exdrSTRING

          string

.. data:: exdrDOUBLE

          double precision floating point number

.. data:: exdrINT

          integer

.. data:: exdrFLOAT

          floating point number

.. data:: exdrUINT

          unsigned integer

.. data:: exdr3DX

          compressed 3D coordinates

.. data:: exdrMAGIC

          magic number

.. data:: exdrNOMEM

          not enough memory to allocate space for a XDR data structure.

Opening and closing of XDR files
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Two low-level functions are used to obtain a *XDRFILE* object (a file handle)
to access xdr files such as XTC or TRR trajectories.

.. function:: xdrfile_open(path, mode) -> XDRFILE

              Open *path* and returns a *XDRFILE* handle that is required by other
              functions.

              :Arguments:
		  *path*
		     file name
		  *mode*
		     'r' for reading and 'w' for writing
	      :Returns: *XDRFILE* handle

.. function:: xdrfile_close(XDRFILE) -> status

              Close the xdrfile pointed to by *XDRFILE*.

              .. Warning:: Closing an already closed file will lead to a
                           crash with a double-free pointer error.

XTC functions
~~~~~~~~~~~~~

The XTC trajectory format is a lossy compression format that only stores
coordinates. Compression level is determined by the *precision* argument to the
:func:`write_xtc` function. Coordinates (Gromacs_ uses nm natively) are
multiplied by *precision* and truncated to the integer part. A typical value is
1000.0, which gives an accuracy of 1/100 of an Angstroem.

The advantage of XTC over TRR is its significantly reduced size.


.. function:: read_xtc_natoms(fn) -> natoms

              Read the number of atoms *natoms* from a xtc file *fn*.

              :Arguments:
                *fn*
                   file name of an xtc file

              :Raises: :exc:`IOError` if the supplied filed is not a XTC
                       or if it is not readable.

.. function:: read_xtc_numframes(fn) -> (numframes, offsets)

              Read through the whole trajectory headers to obtain the total number of frames.
              The process is speeded up by reading frame headers for the amount of data in the frame,
              and then skipping directly to the next header. An array of frame offsets is also
              returned, which can later be used to seek direcly to arbitrary frames in the trajectory.

              :Arguments:
                *fn*
                   file name of an xtc file

              :Returns:
                a tuple containing:
                  *numframes*
                     an int with the total frame count in the trajectory
                  *offsets*
                     a numpy array of int64 recording the starting byte offset of each frame

              :Raises: :exc:`IOError` if the supplied filed is not a XTC
                       or if it is not readable.

.. function:: read_xtc(XDRFILE, box, x) -> (status, step, time, precision)

              Read the next frame from the opened xtc trajectory into *x*.

              :Arguments:
                *XDRFILE*
                   open *XDRFILE* object
                *box*
                   pre-allocated numpy ``array((DIM,DIM),dtype=numpy.float32)`` which
                   is filled with the unit cell box vectors
                *x*
                   pre-allocated numpy ``array((natoms, DIM),dtype=numpy.float32)``
                   which is updated with the coordinates from the frame

              :Returns:
                a tuple containing:
                  *status*
                     integer status (0 = exdrOK), see `Status symbols`_ for other
                     values)
                  *step*
                     simulation step
                  *time*
                     simulation time in ps
                  *precision*
                     precision of the lossy xtc format (typically 1000.0)

.. function:: write_xtc(XDRFILE, step, time, box, x, prec) -> status

              Write the next frame *x* to the opened xtc trajectory.

              :Arguments:
                *XDRFILE*
                   open *XDRFILE* object (writable)
                *step*
                   simulation step
                *time*
                   time step in ps
                *box*
                   numpy ``array((DIM,DIM),dtype=numpy.float32)`` which contains
                   the unit cell box vectors
                *x*
                   numpy ``array((natoms, DIM),dtype=nump.float32)``
                   which contains the coordinates from the frame
                *precision*
                   precision of the lossy xtc format (typically 1000.0)

              :Returns: *status*, integer status (0 = OK), see the ``libxdrfile2.exdr*``
                        constants under `Status symbols`_ for other values)

TRR functions
~~~~~~~~~~~~~

TRR is the Gromacs_ native full-feature trajectory storage format. It can contain position
coordinates, velocities and forces, and the lambda value for free energy perturbation
calculations. Velocities and forces are optional in the sense that they can be all zero.

.. function:: read_trr_natoms(fn) -> natoms

              Read the number of atoms *natoms* from a trr file *fn*.

              :Arguments:
                *fn*
                   file name of a trr file

              :Raises: :exc:`IOError` if the supplied filed is not a TRR
                       or if it is not readable.

.. function:: read_trr_numframes(fn) -> (numframes, offsets)

              Read through the whole trajectory headers to obtain the total number of frames.
              The process is speeded up by reading frame headers for the amount of data in the frame,
              and then skipping directly to the next header. An array of frame offsets is also
              returned, which can later be used to seek direcly to arbitrary frames in the trajectory.

              :Arguments:
                *fn*
                   file name of an xtc file

              :Returns:
                a tuple containing:
                  *numframes*
                     an int with the total frame count in the trajectory
                  *offsets*
                     a numpy array of int64 recording the starting byte offset of each frame

              :Raises: :exc:`IOError` if the supplied filed is not a TRR or if it is not readable.

.. function:: read_trr(XDRFILE, box, x, v, f) -> (status, step, time, lambda)

              Read the next frame from the opened trr trajectory into *x*, *v*, and *f*.

              :Arguments:
                *XDRFILE*
                   open *XDRFILE* object
                *box*
                   pre-allocated numpy ``array((DIM,DIM),dtype=numpy.float32)`` which
                   is filled with the unit cell box vectors
                *x*
                   pre-allocated numpy ``array((natoms, DIM),dtype=nump.float32)``
                   which is updated with the **coordinates** from the frame
                *v*
                   pre-allocated numpy ``array((natoms, DIM),dtype=nump.float32)``
                   which is updated with the **velocities** from the frame
                *f*
                   pre-allocated numpy ``array((natoms, DIM),dtype=nump.float32)``
                   which is updated with the **forces** from the frame

              :Returns:
                a tuple containing:
                  *status*
                     integer status (0 = exdrOK), see the ``libxdrfile2.exdr*`` constants
                     under `Status symbols`_ for other values)
                  *step*
                     simulation step
                  *time*
                     simulation time in ps
                  *lambda*
                     current lambda value (only interesting for free energy perturbation)
                  *has_x*
                     boolean indicating whether coordinates were read from the TRR
                  *has_v*
                     boolean indicating whether velocities were read from the TRR
                  *has_f*
                     boolean indicating whether forces were read from the TRR

.. function:: write_trr(XDRFILE, step, time, lambda, box, x, v, f) -> status

              Write the next frame to the opened trr trajectory.

              :Arguments:
                *XDRFILE*
                   open *XDRFILE* object (writable)
                *step*
                   simulation step
                *time*
                   time step in ps
                *lambda*
                   free energy lambda value (typically 0.0)
                *box*
                   numpy ``array((DIM,DIM),dtype=numpy.float32)`` which contains
                   the unit cell box vectors
                *x*
                   numpy ``array((natoms, DIM),dtype=nump.float32)``
                   which contains the **coordinates** from the frame
                *v*
                   numpy ``array((natoms, DIM),dtype=nump.float32)``
                   which contains the **velocities** from the frame
                *f*
                   numpy ``array((natoms, DIM),dtype=nump.float32)``
                   which contains the **forces** from the frame

              .. versionchanged:: 0.8.0
                   either one of *x*, *v*, or *f* can now be set as a natom,0-DIM
                   numpy ``array((natom, 0),dtype=nump.float32)``. This will cause the
                   corresponding property to be skipped when writing to file.

              :Returns: *status*, integer status (0 = OK), see the ``libxdrfile2.exdr*``
                        constants under `Status symbols`_ for other values)

"
%enddef

%module(docstring=DOCSTRING) libvmdmolfile


%{
/* Python SWIG interface to molfile_plugin of VMD version 1.9.3
   Copyright (c) 2017 Berk Onat <b.onat@warwick.ac.uk>
   Published under the GNU LESSER GENERAL PUBLIC LICENSE Version 3 (or higher)
 */
#define SWIG_FILE_WITH_INIT
#include <stdio.h>
#include "molfile_plugin.h"
%}

%include "numpy.i"

%init %{
import_array();
%}


/* 

   I am only wrapping 'high level' functions and modify call
   signatures so that one does not need anything like pointers from
   python.
*/


/* status codes */
enum { exdrOK, exdrHEADER, exdrSTRING, exdrDOUBLE,
       exdrINT, exdrFLOAT, exdrUINT, exdr3DX, exdrCLOSE, exdrMAGIC,
       exdrNOMEM, exdrENDOFFILE, exdrFILENOTFOUND, exdrNR };

/* These com from stdio.h, for file seeking. Gives all the flexibility to _fseek(). */
enum { SEEK_SET, SEEK_CUR, SEEK_END };

/* open/close xdr files */
%feature("autodoc", "0") xdrfile_open;
extern XDRFILE* xdrfile_open(const char *path, const char *mode);

%feature("autodoc", "0") xdrfile_close;
extern int xdrfile_close(XDRFILE *fp);


/* from xdrfile_xtc.c */
/* This function returns the number of atoms in the xtc file in *natoms
     extern int read_xtc_natoms(char *fn,int *natoms);
   ... but the wrapped function returns natoms as the python return value
*/
%feature("autodoc", "0") my_read_xtc_natoms;
%rename (read_xtc_natoms) my_read_xtc_natoms;
%exception my_read_xtc_natoms {
  $action
  if (PyErr_Occurred()) SWIG_fail;
}
%inline %{
  int my_read_xtc_natoms(char *fn) {
    int natoms;
    int status;
    status = read_xtc_natoms(fn, &natoms);
    if (status != exdrOK) {
      PyErr_Format(PyExc_IOError, "[%d] Error reading natoms from xtc '%s'", status, fn);
      return 0;
    }
    return natoms;
  }
%}

%feature("autodoc", "0") my_read_xtc_numframes;
%rename (read_xtc_numframes) my_read_xtc_numframes;
%exception my_read_xtc_numframes {
  $action
  if (PyErr_Occurred()) SWIG_fail;
}
%inline %{
PyObject * my_read_xtc_numframes(char *fn) {
    int numframes, status;
    int64_t *offsets[1];
    PyObject *npoffsets = NULL;
    status = read_xtc_numframes(fn, &numframes, offsets);
    if (status != exdrOK) {
      PyErr_Format(PyExc_IOError, "[%d] Error reading numframes by seeking through xtc '%s'", status, fn);
      return 0;
    }
    npy_intp nfrms[1] = { numframes };
    npoffsets = PyArray_SimpleNewFromData(1, nfrms, NPY_INT64, *offsets);
    if (npoffsets==NULL)
    {
      free(*offsets);
      Py_XDECREF(npoffsets);
      PyErr_Format(PyExc_IOError, "Error copying frame index into Python.");
      return 0;
    }
    /* From http://web.archive.org/web/20130304224839/http://blog.enthought.com/python/numpy/simplified-creation-of-numpy-arrays-from-pre-allocated-memory/ */
    PyArray_BASE(npoffsets) = PyCObject_FromVoidPtr(*offsets, free);
    PyObject *tuple = PyTuple_New(2);
    PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong((long)numframes));
    PyTuple_SET_ITEM(tuple, 1, npoffsets);
    return tuple;
  }
%}


/* This function returns the number of atoms in the trr file in *natoms
     extern int read_trr_natoms(char *fn,int *natoms);
 ... but the wrapped function returns natoms as the python return value
*/
%feature("autodoc", "0") my_read_trr_natoms;
%rename (read_trr_natoms) my_read_trr_natoms;
%exception my_read_trr_natoms {
  $action
  if (PyErr_Occurred()) SWIG_fail;
}
%inline %{
  int my_read_trr_natoms(char *fn) {
    int natoms;
    int status;
    status = read_trr_natoms(fn, &natoms);
    if (status != exdrOK) {
      PyErr_Format(PyExc_IOError, "[%d] Error reading natoms from trr '%s'", status, fn);
      return 0;
    }
    return natoms;
  }
%}


%feature("autodoc", "0") my_read_trr_numframes;
%rename (read_trr_numframes) my_read_trr_numframes;
%exception my_read_trr_numframes {
  $action
  if (PyErr_Occurred()) SWIG_fail;
}
%inline %{
PyObject * my_read_trr_numframes(char *fn) {
    int numframes, status;
    int64_t *offsets[1];
    PyObject *npoffsets = NULL;
    status = read_trr_numframes(fn, &numframes, offsets);
    if (status != exdrOK) {
      PyErr_Format(PyExc_IOError, "[%d] Error reading numframes by seeking through trr '%s'", status, fn);
      return 0;
    }
    npy_intp nfrms[1] = { numframes };
    npoffsets = PyArray_SimpleNewFromData(1, nfrms, NPY_INT64, *offsets);
    if (npoffsets==NULL)
    {
      free(*offsets);
      Py_XDECREF(npoffsets);
      PyErr_Format(PyExc_IOError, "Error copying frame index into Python.");
      return 0;
    }
    /* From http://web.archive.org/web/20130304224839/http://blog.enthought.com/python/numpy/simplified-creation-of-numpy-arrays-from-pre-allocated-memory/ */
    PyArray_BASE(npoffsets) = PyCObject_FromVoidPtr(*offsets, free);
    PyObject *tuple = PyTuple_New(2);
    PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong((long)numframes));
    PyTuple_SET_ITEM(tuple, 1, npoffsets);
    return tuple;
  }
%}



#define DIM 3
typedef float matrix[DIM][DIM];
typedef float rvec[DIM];


/* Reading from xdr files */

%apply (float INPLACE_ARRAY2[ANY][ANY]) {(matrix box)}
%apply (int DIM1, int DIM2, float* INPLACE_ARRAY2) {(int natoms,  int _DIM,  float *x),
                                                    (int vnatoms, int v_DIM, float *v),
                                                    (int fnatoms, int f_DIM, float *f)}

/* Read one frame of an open xtc file */
/*
extern int read_xtc(XDRFILE *xd,int natoms,int *step,float *time,
 		    matrix box,rvec *x,float *prec);
*/
%feature("autodoc", "read_xtc(XDRFILE, box, x) -> (status, step, time, precision)") my_read_xtc;
%rename (read_xtc) my_read_xtc;
%inline %{
PyObject * my_read_xtc(XDRFILE *xd, matrix box, int natoms, int _DIM, float *x) {
  /* _DIM = 3 always, need to reorder for numpy.i SWIG */
  int status, step;
  float time, prec;
  PyObject *tuple = PyTuple_New(4);
  status = read_xtc(xd, natoms, &step, &time, box, (rvec *)x, &prec);
  PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong((long)status));
  PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong((long)step));
  PyTuple_SET_ITEM(tuple, 2, PyFloat_FromDouble((double)time));
  PyTuple_SET_ITEM(tuple, 3, PyFloat_FromDouble((double)prec));
  return tuple; // return  (status, step, time, prec)
}
%}

%feature("autodoc", "read_trr(XDRFILE, box, x, v, f) -> (status, step, time, lambda)") my_read_trr;
%rename (read_trr) my_read_trr;
%inline %{
PyObject * my_read_trr(XDRFILE *xd, matrix box,
		int natoms,  int _DIM,  float *x,
		int vnatoms, int v_DIM, float *v,
		int fnatoms, int f_DIM, float *f) {
  /* _DIM = 3 always, need to reorder for numpy.i SWIG */
  int status, step, has_prop=0;
  float time, lmbda;
  PyObject *tuple = PyTuple_New(7);
  status = read_trr(xd, natoms, &step, &time, &lmbda, box, (rvec *)x, (rvec *)v, (rvec *)f, &has_prop);
  PyTuple_SET_ITEM(tuple, 0, PyInt_FromLong((long)status));
  PyTuple_SET_ITEM(tuple, 1, PyInt_FromLong((long)step));
  PyTuple_SET_ITEM(tuple, 2, PyFloat_FromDouble((double)time));
  PyTuple_SET_ITEM(tuple, 3, PyFloat_FromDouble((double)lmbda));
  PyTuple_SET_ITEM(tuple, 4, PyBool_FromLong((long)(has_prop & HASX)));
  PyTuple_SET_ITEM(tuple, 5, PyBool_FromLong((long)(has_prop & HASV)));
  PyTuple_SET_ITEM(tuple, 6, PyBool_FromLong((long)(has_prop & HASF)));
  return tuple; // return  (status, step, time, lmbda, has_x, has_v, has_f)
}
%}

%clear (matrix box);
%clear (int natoms,  int _DIM,  float *x);
%clear (int vnatoms, int v_DIM, float *v);
%clear (int fnatoms, int f_DIM, float *f);


/* Writing of xdr files */

%apply (float IN_ARRAY2[ANY][ANY]) {(matrix box)}
%apply (int DIM1, int DIM2, float* IN_ARRAY2) {(int natoms,  int _DIM,  float *x),
                                               (int vnatoms, int v_DIM, float *v),
                                               (int fnatoms, int f_DIM, float *f)}

/* Write a frame to xtc file */
/*
extern int write_xtc(XDRFILE *xd, int natoms,int step,float time,
		     matrix box,rvec *x,float prec);
*/
%feature("autodoc", "write_xtc(XDRFILE, step, time, box, x, prec) -> status") my_write_xtc;
%rename (write_xtc) my_write_xtc;
%inline %{
int my_write_xtc(XDRFILE *xd, int step, float time,
                 matrix box, int natoms, int _DIM, float *x, float prec) {
  /* _DIM = 3 always, need to reorder for numpy.i SWIG */
  return write_xtc(xd, natoms, step, time, box, (rvec *)x, prec);
}
%}

%feature("autodoc", "write_trr(XDRFILE, step, time, lambda, box, x, v, f) -> status") my_write_trr;
%rename (write_trr) my_write_trr;
%inline %{
int my_write_trr(XDRFILE *xd, int step, float time, float lmbda, matrix box,
                 int natoms,  int _DIM,  float *x,
                 int vnatoms, int v_DIM, float *v,
                 int fnatoms, int f_DIM, float *f) {
  /* Preparing for the case of empty arrays - NULL pointers tell the library to skip this property. */
  if (_DIM == 0) x = NULL;
  if (v_DIM == 0) v = NULL;
  if (f_DIM == 0) f = NULL;
  return write_trr(xd, natoms, step, time, lmbda, box, (rvec *)x, (rvec *)v, (rvec *)f);
}
%}

%feature("autodoc", "0") xdr_seek;
extern int xdr_seek(XDRFILE *xd, long long pos, int whence);

%feature("autodoc", "0") xdr_tell;
extern long long xdr_tell(XDRFILE *xd);

%clear (matrix box);
%clear (int natoms,  int _DIM,  float *x);
%clear (int vnatoms, int v_DIM, float *v);
%clear (int fnatoms, int f_DIM, float *f);