3__author__ = "Patrick Louden (plouden@nd.edu)"
4__copyright__ = "Copyright (c) 2004-present The University of Notre Dame. All Rights Reserved."
13from argparse import RawDescriptionHelpFormatter
19def HBcount(hbqFileName, hbqPSAFileName, qS, qL, boxl_x, boxl_y, boxl_z, nSnapshots):
24 lthSum = 0.0 # low(q) to high(q) sum
25 htlSum = 0.0 # high(q) to low(q) sum
28 # first let's extract the Hydrogen Bond count from the .hbq file
29 hbqFile = open(hbqFileName, "r")
32 if "parameters:" in line:
33 nbins = float(line.split()[16][:-1])
34 deltaQ = float(line.split()[19])
35 elif "Hydrogen Bond count:" in line:
36 hbCount = float(line.split()[4])
38 # accumulate the matrix into a list for easy looping and summing
39 hbqList.append(line.split())
42 for i in range(0, len(hbqList[0])):
43 for j in range(0, len(hbqList[0])):
44 if ( (i*deltaQ) >= qS ) and ( (j*deltaQ) <= qL ):
45 htlSum = htlSum + float(hbqList[i][j])
46 elif ( (i*deltaQ) <= qL ) and ( (j*deltaQ) >= qS ):
47 lthSum = lthSum + float(hbqList[i][j])
49 totSum = htlSum + lthSum
50 normHBCount = (totSum * hbCount) / (boxl_x * boxl_y * boxl_z) / nSnapshots
52 hbqPSAFile = open(hbqPSAFileName, "w")
53 hbqPSAFile.write("qS = " + str(qS) + "\n")
54 hbqPSAFile.write("qL = " +str(qL) +"\n")
55 hbqPSAFile.write("boxl(x) = " + str(boxl_x) + "\n")
56 hbqPSAFile.write("boxl(y) = " + str(boxl_y) + "\n")
57 hbqPSAFile.write("boxl(z) = " + str(boxl_z) + "\n")
58 hbqPSAFile.write("nSnapshots = " + str(nSnapshots) + "\n")
59 hbqPSAFile.write("nbins = " + str(nbins) + "\n")
60 hbqPSAFile.write("deltaQ = " + str(deltaQ) + "\n")
61 hbqPSAFile.write("hbCount = " + str(hbCount) + "\n")
62 hbqPSAFile.write("htlSum = " + str(htlSum) + "\n")
63 hbqPSAFile.write("lthSum = " + str(lthSum) + "\n")
64 hbqPSAFile.write("The normalized per square Angstrom number of hydrogen bonds found is " + str(normHBCount) + "\n")
69 parser = argparse.ArgumentParser(
70 description='OpenMD tetrahedral hydrogen-bond matrix analyzer.',
71 #formatter_class=RawDescriptionHelpFormatter,
72 epilog="Example: hbtetAnalyzer.py -i sim.hbq -o sim.hbqPSA -qS 0.91 -qL 0.75 -x 56.5 -y 43.3")
73 parser.add_argument("-i", "--hbq-file=", action="store", dest="hbqFileName", help="use specified input (.hbq) file")
74 parser.add_argument("-o", "--hbqPAS-file=", action="store", dest="hbqPSAFileName", help="use specified output (.hbqPSA) file")
75 parser.add_argument("-qS", "--q(solid)=", action="store", type=float, dest="qS", help="the tetrahedral order parameter value at the solid surface")
76 parser.add_argument("-qL", "--q(liquid)=", action="store", type=float, dest="qL", help="the tetrahedral order parameter value at the liquid surface")
77 parser.add_argument("-x", "--boxl(x)=", action="store", type=float, dest="boxl_x", help="the x-dimension of the simulation box (Angstroms)")
78 parser.add_argument("-y", "--boxl(y)=", action="store", type=float, dest="boxl_y", help="the y-dimension of the simulation box (Angstroms)")
79 parser.add_argument("-z", "--boxl(z)=", action="store", type=float, dest="boxl_z", help="the z-dimension of the simulation box (Angstroms)")
80 parser.add_argument("-t", "--nSnapshots=", action="store", type=float, dest="nSnapshots", help="the number of snapshots used to accumulate the (.hbq) file")
82 if len(sys.argv) == 1:
85 args = parser.parse_args()
87 if (not args.hbqFileName):
88 parser.error("No input-file was specified")
90 if (not args.hbqPSAFileName):
91 parser.error("No output-file was specified")
95 parser.error("No q(solid) was specified")
99 parser.error("No q(liquid) was specified")
101 if (not args.boxl_x):
103 parser.error("No x-dimension of the box was specified")
105 if (not args.boxl_y):
107 parser.error("No y-dimension of the box was specified")
109 if (not args.boxl_z):
111 parser.error("No z-dimension of the box was specified")
113 if (not args.nSnapshots):
115 parser.error("No nSnapshots specified")
118 #Call functions here, pass appropriate variables.
119 HBcount(args.hbqFileName, args.hbqPSAFileName, args.qS, args.qL, args.boxl_x, args.boxl_y, args.boxl_z, args.nSnapshots)
121if __name__ == "__main__":