[e1a46d] | 1 | #!@PYTHON@
|
---|
| 2 | #
|
---|
| 3 | # This code calculates the pair correlation between the water molecules and the center of gravity of the cluster (defined by the Si and Ca atoms)
|
---|
| 4 |
|
---|
| 5 | import sys, string, re, math
|
---|
| 6 | wrerr = sys.stderr.write
|
---|
| 7 | wrout = sys.stdout.write
|
---|
| 8 |
|
---|
| 9 | if (len(sys.argv) < 2):
|
---|
| 10 | print "Usage: "+sys.argv[0]+" <pdb> <dbond>"
|
---|
| 11 | sys.exit(1)
|
---|
| 12 |
|
---|
| 13 | # parse the pdb file and obtain maxid
|
---|
| 14 | print "Parsing the PDB file "+sys.argv[1]+"."
|
---|
| 15 | pdbfile = open(sys.argv[1], "r")
|
---|
| 16 | atoms = {}
|
---|
| 17 | maxid=-1
|
---|
| 18 | for line in pdbfile:
|
---|
| 19 | if "END" in line or "CONECT" in line or "MASTER" in line:
|
---|
| 20 | continue
|
---|
| 21 | fields = line.split()
|
---|
| 22 | if maxid < int(fields[1]):
|
---|
| 23 | maxid=int(fields[1])
|
---|
| 24 | # id, element, x, y, z and ten neighbour ids
|
---|
| 25 | last = fields[10].split('0')
|
---|
| 26 | atoms[fields[1]] = [int(fields[1]), last[3], float(fields[5]), float(fields[6]), float(fields[7]), -1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
|
---|
| 27 |
|
---|
| 28 | print "The biggest Id found was %d" % (maxid)
|
---|
| 29 |
|
---|
| 30 | # Parsing the dbond file
|
---|
| 31 | print "Parsing the DBOND file "+sys.argv[2]+"."
|
---|
| 32 | dbondfile = open(sys.argv[2], "r")
|
---|
| 33 | test = dbondfile.readline() # skip the first two lines
|
---|
| 34 | test = dbondfile.readline()
|
---|
| 35 | for line in dbondfile:
|
---|
| 36 | fields = line.split()
|
---|
| 37 | ids = [int(fields[0]), int(fields[1])]
|
---|
| 38 | set = [0,0]
|
---|
| 39 | if str(ids[0]) in atoms and str(ids[1]) in atoms:
|
---|
| 40 | for i in range(5,15):
|
---|
| 41 | for j in range(2):
|
---|
| 42 | if set[j] == 0 and (atoms[ str(ids[j]) ])[i] == -1:
|
---|
| 43 | (atoms[ str(ids[j]) ])[i] = ids [ (j+1) %2 ]
|
---|
| 44 | set[j] = 1
|
---|
| 45 | if set[0] == 1 and set[1] == 1:
|
---|
| 46 | break
|
---|
| 47 | if set[0] == 0 or set[1] == 0:
|
---|
| 48 | print "ERROR: Either id already had ten neighbours, increase number in code!"
|
---|
| 49 | sys.exit(1)
|
---|
| 50 | else:
|
---|
| 51 | print "ERROR: Either %d or %d are not listed in the PDB file!" % (ids[0], ids[1])
|
---|
| 52 | sys.exit(1)
|
---|
| 53 |
|
---|
| 54 | # go through all Si and Ca and calculate CoG
|
---|
| 55 | CoG = [ 0, 0, 0]
|
---|
| 56 | nr=0
|
---|
| 57 | for atom in atoms:
|
---|
| 58 | #print atoms[atom]
|
---|
| 59 | if "Si" in atoms[atom][1] or "Ca" in atoms[atom][1]:
|
---|
| 60 | for i in range(3):
|
---|
| 61 | CoG[i] += atoms[atom][2+i]
|
---|
| 62 | nr = nr + 1
|
---|
| 63 | for i in range(3):
|
---|
| 64 | CoG[i] /= nr
|
---|
| 65 | print "The Center of Gravity is at %g,%g,%g." % (CoG[0], CoG[1], CoG[2])
|
---|
| 66 |
|
---|
| 67 | # initialize the bin array
|
---|
| 68 | NrBins=100
|
---|
| 69 | BinWidth=0.5
|
---|
| 70 | bins = []
|
---|
| 71 | for i in range(NrBins):
|
---|
| 72 | bins.append(0)
|
---|
| 73 |
|
---|
| 74 | # go through every atom
|
---|
| 75 | nrwaters = 0
|
---|
| 76 | nrothers = 0
|
---|
| 77 | for atom in atoms:
|
---|
| 78 | if "O" in atoms[atom][1]:
|
---|
| 79 | water = 1
|
---|
| 80 | for i in range(5,15):
|
---|
| 81 | if atoms[atom][i] == -1:
|
---|
| 82 | break
|
---|
| 83 | if str(atoms[atom][i]) in atoms:
|
---|
| 84 | if "Si" in atoms[ str(atoms[atom][i]) ][1]:
|
---|
| 85 | water = 0
|
---|
| 86 | break
|
---|
| 87 | else:
|
---|
| 88 | print "ERROR: key %d is not in list!" % (atoms[atom][i])
|
---|
| 89 | sys.exit(1)
|
---|
| 90 | if water == 1:
|
---|
| 91 | dist = 0
|
---|
| 92 | for i in range(3):
|
---|
| 93 | dist += (CoG[i] - atoms[atom][2+i])*(CoG[i] - atoms[atom][2+i])
|
---|
| 94 | dist = int(math.sqrt(dist)/BinWidth)
|
---|
| 95 | if dist < NrBins:
|
---|
| 96 | bins[dist] = bins[dist] + 1
|
---|
| 97 | nrwaters = nrwaters+1
|
---|
| 98 | else:
|
---|
| 99 | nrothers = nrothers + 1
|
---|
| 100 |
|
---|
| 101 | print "There were %d water molecules and %d oxygens connected to silica." % (nrwaters, nrothers)
|
---|
| 102 |
|
---|
| 103 | #print "The Bins are as follows:"
|
---|
| 104 | output = open("histo_pair_correlation.dat", "w")
|
---|
| 105 | output.write("#Distance [A]\tnumber in bin\n")
|
---|
| 106 | for i in range(NrBins):
|
---|
| 107 | #print "%g\t%d" % (i*BinWidth, bins[i])
|
---|
| 108 | output.write("%g\t%g\n" % (i*BinWidth, bins[i]))
|
---|
| 109 | output.close()
|
---|
| 110 |
|
---|
| 111 | print "finished."
|
---|