2"""Pressure Correlation function
4Computes various correlation functions of the pressure
5that have been stored in a stat file.
10 -h, --help show this help
11 -f, --stat-file=... use specified stat file
12 -o, --output-file=... use specified output (.pcorr) file
14The script will compute: <(P(t)-<P>)*(P(0)-<P>)> / < (P(0) - <P>)^2 >
17 stat2pcorr -f ring5.stat -o ring5.pcorr
21__author__ = "Dan Gezelter (gezelter@nd.edu)"
22__version__ = "$Revision$"
25__copyright__ = "Copyright (c) 2004-present The University of Notre Dame. All Rights Reserved."
36def readStatFile(statFileName):
47 statFile = open(statFileName, 'r')
54 line = statFile.readline()
56 line = statFile.readline()
60 time.append(float(L[0]))
61 temperature.append(float(L[4]))
63 # OpenMD prints out pressure in units of atm.
65 pressure.append(float(L[5]))
66 volume.append(float(L[6]))
68 line = statFile.readline()
80 print("computing Averages")
92 # converts amu*fs^-2*Ang^-1 -> atm
93 pressureConvert = 1.63882576e8
95 for i in range(len(time)):
96 tempSum = tempSum + temperature[i]
97 pressSum = pressSum + pressure[i]
98 volSum = volSum + volume[i]
99 # in units of amu Ang^2 fs^-1
100 pvTerm = pressure[i]*volume[i] / pressureConvert
101 pvSum = pvSum + pvTerm
102 temp2Sum = temp2Sum + math.pow(temperature[i], 2)
103 press2Sum = press2Sum + math.pow(pressure[i], 2)
104 vol2Sum = vol2Sum + math.pow(volume[i], 2)
105 pv2Sum = pv2Sum + math.pow(pvTerm, 2)
107 tempAve = tempSum / float(len(time))
108 pressAve = pressSum / float(len(time))
109 volAve = volSum / float(len(time))
110 pvAve = pvSum / float(len(time))
112 tempSdev = math.sqrt(temp2Sum / float(len(time)) - math.pow(tempAve, 2))
113 pressSdev = math.sqrt(press2Sum / float(len(time)) - math.pow(pressAve, 2))
114 if (vol2Sum / float(len(time)) < math.pow(volAve, 2)):
117 volSdev = math.sqrt(vol2Sum / float(len(time)) - math.pow(volAve, 2))
118 pvSdev = math.sqrt(pv2Sum / float(len(time)) - math.pow(pvAve, 2))
120 print(" Average pressure = %f +/- %f (atm)" % (pressAve, pressSdev))
121 print(" Average volume = %f +/- %f (Angst^3)" % (volAve, volSdev))
122 print("Average temperature = %f +/- %f (K)" % (tempAve, tempSdev))
123 print(" Average PV product = %f +/- %f (amu Angst^2 fs^-1)" % (pvAve, pvSdev))
125def computeCorrelations(outputFileName):
127 # converts amu*fs^-2*Ang^-1 -> atm
128 pressureConvert = 1.63882576e8
130 # Boltzmann's constant amu*Ang^2*fs^-2/K
135 print("computing Pressure Correlation Function")
136 # i corresponds to dt
137 for i in range(len(time)):
138 # j is the starting time for the correlation
140 for j in range( len(time) - i ):
141 deltaP1 = pressure[j] - pressAve
142 deltaP2 = pressure[j+i] - pressAve
143 pp = pp + deltaP1*deltaP2
145 Pcorr.append(pp / float(len(time) - i))
147 outputFile = open(outputFileName, 'w')
148 for i in range(len(time)):
150 outputFile.write("%f\t%13e\n" % (time[i], Pcorr[i] / Pcorr[0]))
156 global haveStatFileName
157 global haveOutputFileName
159 haveStatFileName = False
160 haveOutputFileName = False
164 opts, args = getopt.getopt(argv, "hf:o:", ["help", "stat-file=", "output-file="])
165 except getopt.GetoptError:
168 for opt, arg in opts:
169 if opt in ("-h", "--help"):
172 elif opt in ("-f", "--stat-file"):
174 haveStatFileName = True
175 elif opt in ("-o", "--output-file"):
177 haveOutputFileName = True
178 if (not haveStatFileName):
180 print("No stat file was specified")
182 if (not haveOutputFileName):
184 print("No output file was specified")
187 readStatFile(statFileName);
189 computeCorrelations(outputFileName);
191if __name__ == "__main__":
192 if len(sys.argv) == 1: