source: util/src/ShiftPeriodic.py.in@ e34098

Last change on this file since e34098 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
RevLine 
[e1a46d]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
[c03ca6]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>"
[e1a46d]11 print "Output goes to STDOUT."
12 sys.exit(1)
13
14# get parameters
[c03ca6]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])]
[e1a46d]19
20# parse the file and obtain maxid
[c03ca6]21wrerr("Parsing the coordinate file "+sys.argv[1]+".\n")
[e1a46d]22file = open(sys.argv[1], "r")
[c03ca6]23#wrout(file.readline())
24#wrout(file.readline())
[e1a46d]25atoms = {}
26maxid=-1
[c03ca6]27nr=0
[e1a46d]28for line in file:
29 # simpy print everything else
[c03ca6]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):
[e1a46d]38 fields=line.split()
39 for i in range(3):
[c03ca6]40 value=float(fields[i+xyzoffset])+shift[i]
[e1a46d]41 while value > box[i]:
42 value = value - box[i]
43 while value < 0:
44 value = value + box[i]
[c03ca6]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])))
[e1a46d]47 wrout("\n")
48
49sys.exit(0)
Note: See TracBrowser for help on using the repository browser.