1 | #! @PYTHON@
|
---|
2 | #
|
---|
3 | # determines all distance between each atomic pair and prints minimum and respective ids
|
---|
4 |
|
---|
5 | import sys, string, re, math
|
---|
6 | wrerr = sys.stderr.write
|
---|
7 | wrout = sys.stdout.write
|
---|
8 | CELLLENGTH = 5
|
---|
9 |
|
---|
10 | # check for parameters
|
---|
11 | if len(sys.argv) < 3:
|
---|
12 | wrerr("Usage: "+sys.argv[0]+" <datafile> <Atom1> <Atom2>\n")
|
---|
13 | sys.exit(1)
|
---|
14 |
|
---|
15 | #Get box boundaries (open parameter file)
|
---|
16 | input = open(sys.argv[1], "r")
|
---|
17 | filetype=sys.argv[1].split(".")
|
---|
18 | line=input.readline()
|
---|
19 | line=input.readline()
|
---|
20 |
|
---|
21 | line=input.readline()
|
---|
22 | atoms=line.split()
|
---|
23 | max=[float(atoms[1]), float(atoms[2]), float(atoms[3])]
|
---|
24 | min=[float(atoms[1]), float(atoms[2]), float(atoms[3])]
|
---|
25 | Listatoms=[]
|
---|
26 | Center=[0, 0, 0]
|
---|
27 | n=0
|
---|
28 | for line in input:
|
---|
29 | if "#" in line:
|
---|
30 | continue
|
---|
31 | atom=line.split()
|
---|
32 | if (atom[0] == sys.argv[2]) or (atom[0] == sys.argv[3]):
|
---|
33 | Listatoms.append([str(atom[0]), float(atom[1]), float(atom[2]), float(atom[3])])
|
---|
34 | for i in range(3):
|
---|
35 | Center[i]+=float(atom[i+1])
|
---|
36 | if float(atom[i+1]) < min[i]:
|
---|
37 | min[i] = float(atom[i+1])
|
---|
38 | if float(atom[i+1]) > max[i]:
|
---|
39 | max[i] = float(atom[i+1])
|
---|
40 | print "Parsed "+str(len(Listatoms))+" atoms of type "+sys.argv[2]+" or "+sys.argv[3]+" parsed."
|
---|
41 | print "Found Box bounds [%f,%f]x[%f,%f]x[%f,%f]." % (min[0],max[0],min[1],max[1],min[2],max[2])
|
---|
42 |
|
---|
43 | # find radius of cell
|
---|
44 | RMAX=0
|
---|
45 | for i in range(3):
|
---|
46 | Center[i]=Center[i]/float(len(Listatoms))
|
---|
47 | if RMAX < (max[i]-min[i]):
|
---|
48 | RMAX=(max[i]-min[i])
|
---|
49 | RMAX=RMAX/2
|
---|
50 | R=(RMAX*RMAX)/4
|
---|
51 | print "Radius of set is "+str(RMAX)+" and of inner circle is "+str(math.sqrt(R))+"."
|
---|
52 |
|
---|
53 | # find reference set of points
|
---|
54 | cell=[]
|
---|
55 | for i in range(len(Listatoms)):
|
---|
56 | dist=0
|
---|
57 | for j in range(3):
|
---|
58 | dist+=(Listatoms[i][j+1]-Center[j])*(Listatoms[i][j+1]-Center[j])
|
---|
59 | if dist < R:
|
---|
60 | cell.append(i)
|
---|
61 | if len(cell) < 5:
|
---|
62 | print "WARNING: We have found only "+str(len(cell))+" reference points."
|
---|
63 |
|
---|
64 | # now, put each distance into bins
|
---|
65 | NumBins=len(Listatoms)
|
---|
66 | BinWidth=(RMAX*2)/float(NumBins)
|
---|
67 | Bins=[]
|
---|
68 | for i in range(NumBins+1):
|
---|
69 | Bins.append(0)
|
---|
70 | print "I have created "+str(NumBins)+" bins with width "+str(BinWidth)+"."
|
---|
71 | # for each reference point
|
---|
72 | for ref in range(len(cell)):
|
---|
73 | # for each other point in cluster
|
---|
74 | for other in range(len(Listatoms)):
|
---|
75 | if (cell[ref] != other):
|
---|
76 | dist=0
|
---|
77 | for j in range(3):
|
---|
78 | dist+=(Listatoms[other][j+1]-Listatoms[ cell[ref] ][j+1])*(Listatoms[other][j+1]-Listatoms[ cell[ref] ][j+1])
|
---|
79 | dist=math.sqrt(dist)
|
---|
80 | #print "Distance between "+str( cell[ref] )+" and "+str(other)+" is "+str(dist)+", putting into Bin "+str(math.floor(dist/BinWidth))+"."
|
---|
81 | Bins[int(math.floor(dist/BinWidth))]+=1
|
---|
82 |
|
---|
83 | output=open("histogramm_"+sys.argv[2]+"-"+sys.argv[3]+".csv","w")
|
---|
84 | output.write("# BinNr\tDistStart\tDistCenter\tCount\n")
|
---|
85 | for i in range(1,len(Bins)):
|
---|
86 | output.write("%d\t%lg\t%lg\t%lg\n" % (i,BinWidth*i, BinWidth*(i+1/2), Bins[i]/(4.*math.pi*BinWidth*float(i)*BinWidth*float(i))))
|
---|
87 |
|
---|