Changeset c03ca6


Ignore:
Timestamp:
Sep 28, 2009, 6:35:27 PM (16 years ago)
Author:
Frederik Heber <heber@…>
Children:
6f1551
Parents:
f2dfc5
Message:

ShiftPeriodic.py fixed for xyz files.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • util/src/ShiftPeriodic.py.in

    rf2dfc5 rc03ca6  
    77wrout = sys.stdout.write
    88
    9 if (len(sys.argv) < 9):
    10   print "Usage: "+sys.argv[0]+" <file> <offset> <box x> <box y> <box z> <shift x> <shift y> <shift z>"
     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>"
    1111  print "Output goes to STDOUT."
    1212  sys.exit(1)
    1313
    1414# get parameters
    15 offset=int(sys.argv[2])
    16 box=[float(sys.argv[3]), float(sys.argv[4]),float(sys.argv[5])]
    17 shift=[float(sys.argv[6]),float(sys.argv[7]),float(sys.argv[8])]
     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])]
    1819
    1920# parse the file and obtain maxid
    20 print "Parsing the PDB file "+sys.argv[1]+"."
     21wrerr("Parsing the coordinate file "+sys.argv[1]+".\n")
    2122file = open(sys.argv[1], "r")
     23#wrout(file.readline())
     24#wrout(file.readline())
    2225atoms = {}
    2326maxid=-1
     27nr=0
    2428for line in file:
    2529  # simpy print everything else
    26   if "END" in line or "CONECT" in line or "MASTER" in line or "#" in line:
    27     print line
    28   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):
    2938    fields=line.split()
    3039    for i in range(3):
    31       value=float(fields[i+offset])+shift[i]
     40      value=float(fields[i+xyzoffset])+shift[i]
    3241      while value > box[i]:
    3342        value = value - box[i]
    3443      while value < 0:
    3544        value = value + box[i]
    36       fields[i+offset] = str(value)
    37     for j in range(len(fields)):
    38       wrout("%s " % (fields[j]))
     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])))
    3947    wrout("\n")
    4048
Note: See TracChangeset for help on using the changeset viewer.