source: util/src/PairCorrelationTIP3toResiduum.py.in@ e1a46d

Last change on this file since e1a46d 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.7 KB
Line 
1#!@PYTHON@
2#
3# calculates pair correlation for a given residuum in a PDB file and the TIP3 molecules
4
5import sys, string, re, math
6wrerr = sys.stderr.write
7wrout = sys.stdout.write
8
9# check for parameters
10if len(sys.argv) < 3:
11 wrerr("Usage: "+sys.argv[0]+" <prefix> <offset to xyz> <residuum regexp>\n")
12 sys.exit(1)
13
14bin_no=15
15offset=int(sys.argv[2])
16res=sys.argv[3]
17output = open(sys.argv[1]+".min_distance", "w")
18output2 = open(sys.argv[1]+".density", "w")
19output.write("# timestep\tminimum distance to atom in "+res+" molecule\n")
20output2.write("# timestep\t")
21for n in range(bin_no):
22 output2.write("[%d,%d]\t" % (n,n+1))
23output2.write("\n")
24
25timestep=0
26TYRMatch=re.compile(res)
27TIPMatch=re.compile('TIP3.*WTO')
28
29input = open((sys.argv[1]+".pov1.%04d.pdb" % (timestep)), "r")
30while input:
31 wrout("Scanning time step %d ... " % (timestep))
32 # parse the file
33 TYRs=[]
34 TIPs=[]
35 min=[]
36 bins=[]
37 for line in input:
38 if "#" in line:
39 continue
40 if "END" in line:
41 break
42 if "CONECT" in line:
43 break
44 if TYRMatch.search(line):
45 entries=line.split()
46 for n in range(3):
47 TYRs.append(float(entries[n+offset]))
48 if TIPMatch.search(line):
49 entries=line.split()
50 for n in range(3):
51 TIPs.append(float(entries[n+offset]))
52 input.close()
53
54 # reset arrays
55 center=[0.,0.,0.]
56 for j in range(len(TYRs)/3):
57 min.append(-1.)
58 for n in range(bin_no):
59 bins.append(0)
60 for n in range(3):
61 center[n]+=TYRs[j*3+n]
62 for n in range(3):
63 center[n]/=len(TYRs)/3
64 wrout(" atoms (%d,%d) ... center is at [%f,%f,%f] ... " % (len(TYRs)/3,len(TIPs)/3,center[0], center[1], center[2]))
65 # calculate distance
66 for i in range(len(TIPs)/3):
67 mindistance=-1.
68 for j in range(len(TYRs)/3):
69 # minimum distance
70 distance=0.
71 for n in range(3):
72 distance+=(TIPs[i*3+n]-TYRs[j*3+n])*(TIPs[i*3+n]-TYRs[j*3+n])
73 if (min[j]==-1) or (min[j]*min[j]>distance): # note down minimum distance
74 # radial density
75 min[j] = math.sqrt(distance)
76 if (mindistance == -1) or (mindistance > min[j]):
77 mindistance=min[j]
78# distance=0.
79# for n in range(3):
80# distance+=(TIPs[i*3+n]-center[n])*(TIPs[i*3+n]-center[n])
81 for n in range(bin_no):
82 if (n*n<mindistance) and ((n+1)*(n+1)>mindistance):
83 bins[n]+=1
84 # store values
85 wrout(" writing ... ")
86 output.write("%d\t" % (timestep))
87 for n in range(len(TYRs)/3):
88 output.write("%lg\t" % (min[n]))
89 output.write("\n")
90 output2.write("%d\t" % (timestep))
91 for n in range(bin_no):
92 output2.write("%d\t" % (bins[n]))
93 output2.write("\n")
94 wrout("done.\n")
95 # open next file
96 timestep+=1
97 input = open((sys.argv[1]+".pov1.%04d.pdb" % (timestep)), "r")
98
Note: See TracBrowser for help on using the repository browser.