from xdrfile import * from math import * #you have to compile with --enable-shared #and have libxdrfile.so in the LD_LIBRARY_PATH #it expect the test.xtc file generated by xdrfile_c_test DIM=3 fn="test.xtc" x=xdrfile(fn) natoms1 = 173 step1 = 1993 prec1 = 1000 time1 = 1097.23 box1=[[(i+1)*3.7 + (j+1) for j in range(DIM)] for i in range(DIM)] toler = 1e-3 for k,f in enumerate(x): if f.natoms.value != natoms1: print "natoms != natoms1",f.natoms.value,natoms1 if f.step.value != step1+k: print "incorrect step",f.step.value,step1+k,k if fabs(f.time.value-time1-k) > toler: print "incorrect time",f.time.value,time1+k if fabs(f.prec.value-prec1) > toler: print "incorrect precision",f.prec.value,prec1 for i in range(DIM): for j in range(DIM): if fabs(f.box[i][j] - box1[i][j]) > toler: print "box incorrect",f.box[i][j],box1[i][j] for i in range(f.natoms.value): for j in range(DIM): target = (i+1)*3.7 + (j+1) if f.x[i][j] - target > toler : print "x incorrect" print "OK"