source: util/src/ShiftPeriodic.py.in@ 59b70a

Last change on this file since 59b70a was c03ca6, checked in by Frederik Heber <heber@…>, 16 years ago

ShiftPeriodic.py fixed for xyz files.

  • Property mode set to 100755
File size: 1.5 KB
Line 
1#!@PYTHON@
2#
3# Shifts atoms in a given coordination file periodically
4
5import sys, string, re, math
6wrerr = sys.stderr.write
7wrout = sys.stdout.write
8
9if (len(sys.argv) < 10):
10 print "Usage: "+sys.argv[0]+" <xyzfile> <element offset> <xyzoffset> <box x> <box y> <box z> <shift x> <shift y> <shift z>"
11 print "Output goes to STDOUT."
12 sys.exit(1)
13
14# get parameters
15elementoffset=int(sys.argv[2])
16xyzoffset=int(sys.argv[3])
17box=[float(sys.argv[4]), float(sys.argv[5]),float(sys.argv[6])]
18shift=[float(sys.argv[7]),float(sys.argv[8]),float(sys.argv[9])]
19
20# parse the file and obtain maxid
21wrerr("Parsing the coordinate file "+sys.argv[1]+".\n")
22file = open(sys.argv[1], "r")
23#wrout(file.readline())
24#wrout(file.readline())
25atoms = {}
26maxid=-1
27nr=0
28for line in file:
29 # simpy print everything else
30 if not ("END" in line or "CONECT" in line or "MASTER" in line or "#" in line):
31 nr+=1
32file.close()
33file = open(sys.argv[1], "r")
34wrout("%d\n\tShifted by $shift from PDB file.\n" % (nr))
35for line in file:
36 # simpy print everything else
37 if not ("END" in line or "CONECT" in line or "MASTER" in line or "#" in line):
38 fields=line.split()
39 for i in range(3):
40 value=float(fields[i+xyzoffset])+shift[i]
41 while value > box[i]:
42 value = value - box[i]
43 while value < 0:
44 value = value + box[i]
45 fields[i+xyzoffset] = str(value)
46 wrout("%s\t%lg\t%lg\t%lg" % (fields[elementoffset], float(fields[0+xyzoffset]), float(fields[1+xyzoffset]), float(fields[2+xyzoffset])))
47 wrout("\n")
48
49sys.exit(0)
Note: See TracBrowser for help on using the repository browser.