source: util/src/CalculateXRayFromPDBstep.py.in@ a3ffb44

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

All of my python script put into ESPACK and adapted with @PYTHON@ and so on.

  • Property mode set to 100755
File size: 2.2 KB
Line 
1#!@PYTHON@
2#
3# calculates xray spectra for each time step with coordinates from PDB
4
5import sys, os
6
7exec_prefix="@prefix@"
8DATABASE=exec_prefix+"/bin/elements.db" # contains atomic numbers
9XRAY="/media/WORK/tmp/CODICE/XR_Intensity"
10PYXPLOT="/home/heber/build/pyxplot/pyxplot"
11NAME="ettringite_6Gpa"
12
13# get command line parameters
14if (len(sys.argv)) < 5:
15 print "Usage: "+sys.argv[0]+" <dir> <prefix> <offsetElement> <offsetXYZ> [start from step]"
16 sys.exit(1)
17else:
18 dir=sys.argv[1]
19 prefix=sys.argv[2]
20 offsetElement=int(sys.argv[3])
21 offsetXYZ=int(sys.argv[4])
22
23# generate hash map: element -> atomic number
24atomic={}
25input = open(DATABASE,"r")
26for line in input:
27 if "#" in line:
28 continue
29 entries=line.split()
30 element=entries[1].upper()
31 number=int(entries[5])
32 print "Putting "+element+" -> "+str(number)+" into hash map."
33 atomic[element]=number
34input.close()
35
36# parse each PDB
37if (len(sys.argv))>=5:
38 step=int(sys.argv[5])
39else:
40 step=0
41file=dir+"/"+prefix+("%04d" % (step))+".pdb"
42while 1:
43 try:
44 input=open(file, "r")
45 except IOError:
46 print file+" is not found, breaking."
47 break
48 print "Current step is "+str(step)+"."
49 # recode pdb to "Symbol atomicnumber X Y Z" structure
50 output = open(NAME,"w")
51 n=0
52 for line in input:
53 if "#" in line or "CONECT" in line or "MASTER" in line or "AUTHOR" in line or "COMPND" in line:
54 continue
55 if "END" in line:
56 break
57 entries=line.split()
58 try:
59 element=entries[offsetElement]
60 except IndexError:
61 print "Could not read element nr."+str(offsetElement)+" in line: "+line+"."
62 continue
63 number=atomic.get(element.upper(), None)
64 if number != None:
65 output.write("%s\t%d\t%s\t%s\t%s\n" % (element, int(number), entries[offsetXYZ], entries[offsetXYZ+1], entries[offsetXYZ+2]))
66 n=n+1
67 else:
68 print "WARNING: atomic number for element "+element+" is not known."
69 output.close()
70 # call Xray
71 outputname=dir+"/xray_intensity"+("%04d" % (step))
72 os.system(XRAY+' '+str(n)+' >'+outputname+'.csv')
73 # make plotfile and move eps into place
74 os.system('/bin/cp -f '+outputname+'.csv C3S_xray_spectrum.csv')
75 os.system(PYXPLOT+' xray_spectrum.pyx')
76 os.system('/bin/mv C3S_xray_spectrum.eps '+outputname+'.eps')
77 # next file
78 step+=1
79 file=dir+"/"+prefix+("%04d" % (step))+".pdb"
80
81sys.exit(1)
Note: See TracBrowser for help on using the repository browser.