source: util/src/CalculatePairCorrelation.py.in@ 59b70a

Last change on this file since 59b70a 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.8 KB
Line 
1#! @PYTHON@
2#
3# determines all distance between each atomic pair and prints minimum and respective ids
4
5import sys, string, re, math
6wrerr = sys.stderr.write
7wrout = sys.stdout.write
8CELLLENGTH = 5
9
10# check for parameters
11if 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)
16input = open(sys.argv[1], "r")
17filetype=sys.argv[1].split(".")
18line=input.readline()
19line=input.readline()
20
21line=input.readline()
22atoms=line.split()
23max=[float(atoms[1]), float(atoms[2]), float(atoms[3])]
24min=[float(atoms[1]), float(atoms[2]), float(atoms[3])]
25Listatoms=[]
26Center=[0, 0, 0]
27n=0
28for 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])
40print "Parsed "+str(len(Listatoms))+" atoms of type "+sys.argv[2]+" or "+sys.argv[3]+" parsed."
41print "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
44RMAX=0
45for 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])
49RMAX=RMAX/2
50R=(RMAX*RMAX)/4
51print "Radius of set is "+str(RMAX)+" and of inner circle is "+str(math.sqrt(R))+"."
52
53# find reference set of points
54cell=[]
55for 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)
61if len(cell) < 5:
62 print "WARNING: We have found only "+str(len(cell))+" reference points."
63
64# now, put each distance into bins
65NumBins=len(Listatoms)
66BinWidth=(RMAX*2)/float(NumBins)
67Bins=[]
68for i in range(NumBins+1):
69 Bins.append(0)
70print "I have created "+str(NumBins)+" bins with width "+str(BinWidth)+"."
71# for each reference point
72for 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
83output=open("histogramm_"+sys.argv[2]+"-"+sys.argv[3]+".csv","w")
84output.write("# BinNr\tDistStart\tDistCenter\tCount\n")
85for 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
Note: See TracBrowser for help on using the repository browser.