This is the release 1.0 version
[gromacs/libxdrfile.git] / src / python / xdrfile_test.py
blobd4c6025b23a637d5afa2fa084d40a436bd9692c3
1 #!/usr/bin/python
2 # -*- mode: python; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
3 #
4 # $Id$
5 #
6 # Copyright (c) Erik Lindahl, David van der Spoel 2003-2007.
7 # Coordinate compression (c) by Frans van Hoesel.
8 # Python wrapper (c) by Roland Schulz
9 #
10 # IN contrast to the rest of Gromacs, XDRFILE is distributed under the
11 # BSD license, so you can use it any way you wish, including closed source:
13 # Permission is hereby granted, free of charge, to any person obtaining a
14 # copy of this software and associated documentation files (the "Software"),
15 # to deal in the Software without restriction, including without limitation
16 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 # and/or sell copies of the Software, and to permit persons to whom the
18 # Software is furnished to do so, subject to the following conditions:
20 # The above copyright notice and this permission notice shall be included in
21 # all copies or substantial portions of the Software.
23 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 # DEALINGS IN THE SOFTWARE.
31 from xdrfile import *
32 from math import *
34 #you have to compile with --enable-shared
35 #and have libxdrfile.so in the LD_LIBRARY_PATH
36 #it expect the test.xtc/test.trr file generated by xdrfile_c_test
38 DIM=3
39 natoms1 = 173
40 step1 = 1993
41 prec1 = 1000
42 time1 = 1097.23
43 lam1 = 0.4
44 box1=[[(i+1)*3.7 + (j+1) for j in range(DIM)] for i in range(DIM)]
45 toler = 1e-3
47 def test(fn):
48 x=xdrfile(fn)
49 if x.natoms != natoms1: print "natoms != natoms1",x.natoms,natoms1
50 for k,f in enumerate(x):
51 if f.step != step1+k: print "incorrect step",f.step,step1+k,k
52 if fabs(f.time-time1-k) > toler: print "incorrect time",f.time,time1+k
53 if not x.mode&mTrr and fabs(f.prec-prec1) > toler: print "incorrect precision",f.prec,prec1
54 if x.mode&mTrr and fabs(f.lam-lam1) > toler: print "incorrect lambda",f.lam,lam1
55 for i in range(DIM):
56 for j in range(DIM):
57 if fabs(f.box[i][j] - box1[i][j]) > toler: print "box incorrect",f.box[i][j],box1[i][j]
58 for i in range(x.natoms):
59 for j in range(DIM):
60 target = (i+1)*3.7 + (j+1)
61 if f.x[i][j] - target > toler : print "x incorrect"
62 print fn,"OK"
64 test("../test.trr")
65 test("../test.xtc")