This is the release 1.0 version
[gromacs/libxdrfile.git] / src / python / sample.py
blob56b5d4fbf241d354de3193e9e3f17e824c0e8d5a
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 import sys
34 #you have to compile with --enable-shared
35 #and have libxdrfile.so in the LD_LIBRARY_PATH
37 if len(sys.argv)!=2:
38 print "Missing file argument\nUsage: sample.py FILE"
39 sys.exit()
42 x=xdrfile(sys.argv[1])
43 for f in x: #iterates frames
44 print "%8s %8s %8s %8s Step: %8d "%("Atom","X","Y","Z",f.step) #print header
45 for i,a in enumerate(f.x): #iterate atoms
46 print "%8d %8.1f %8.1f %8.1f"%(i+1,a[0],a[1],a[2]) #print atom number, x, y, z