2"""A script that computes the system dipole correlation function
5 -h, --help show this help
6 -f, --stat-file =... use specified stat file
7 -o, --output-file =... use specified output (.spectrum) file
8 -p, --dipole_pos =... column number of x-component of dipole in the stat. file. Note: the count starts from 0
11 stat2dipolecorr -f stockmayer.stat -o stockmayer.spectrum -p 9
15__author__ = "Dan Gezelter (gezelter@nd.edu), Hemanta Bhattarai (hbhattar@nd.edu)"
16__copyright__ = "Copyright (c) 2004-present The University of Notre Dame. All Rights Reserved."
27def readStatFile(statFileName, dipole_pos):
33 statFile = open(statFileName, 'r')
36 line = statFile.readline()
38 line = statFile.readline()
42 time.append(float(L[0]))
43 dipX = float(L[dipole_pos])
44 dipY = float(L[dipole_pos + 1])
45 dipZ = float(L[dipole_pos + 2])
46 boxDipole.append([dipX, dipY, dipZ])
48 line = statFile.readline()
55 for index in range(len(L1)):
56 dotprod += L1[index] * L2[index]
59def compute_auto_correlation(outFile):
60 outSpectrum = open(outFile, 'w')
61 outSpectrum.write("# System dipole correlation function\n")
62 outSpectrum.write("# time <P(0).P(t)>\n");
69 for start in range(N-step):
70 local_auto_corr.append(dot(boxDipole[start], boxDipole[start + step]))
72 outSpectrum.write("%f\t%e\n"%(time[step], (sum(local_auto_corr)/count)))
83 global haveStatFileName
84 global haveOutputFileName
85 global haveDipoleColumn
87 haveStatFileName = False
88 haveOutputFileName = False
89 haveDipoleColumn = False
92 opts, args = getopt.getopt(argv, "hp:f:o:", ["help", "=", "stat-file=", "output-file="])
93 except getopt.GetoptError:
97 if opt in ("-h", "--help"):
100 elif opt in ("-p", "--dipole_pos="):
101 dipole_pos = int(arg)
102 haveDipoleColumn = True
103 elif opt in ("-f", "--stat-file"):
105 haveStatFileName = True
106 elif opt in ("-o", "--output-file"):
108 haveOutputFileName = True
109 if (not haveStatFileName):
111 print("No stat file was specified")
113 if (not haveOutputFileName):
115 print("No output file was specified")
117 if (not haveDipoleColumn):
119 print("Coulumn number of x-component of dipole not specified")
122 readStatFile(statFileName, dipole_pos)
123 compute_auto_correlation(outputFileName)
125if __name__ == "__main__":
126 if len(sys.argv) == 1: