OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
hbtetAnalyzer
1#!@Python3_EXECUTABLE@
2
3__author__ = "Patrick Louden (plouden@nd.edu)"
4__copyright__ = "Copyright (c) 2004-present The University of Notre Dame. All Rights Reserved."
5__license__ = "OpenMD"
6
7import sys
8import os
9import datetime
10import argparse
11import textwrap
12import numpy as np
13from argparse import RawDescriptionHelpFormatter
14
15
16def usage():
17 print(__doc__)
18
19def HBcount(hbqFileName, hbqPSAFileName, qS, qL, boxl_x, boxl_y, boxl_z, nSnapshots):
20 hbCount = 0.0
21 nbins = 0.0
22 deltaQ = 0.0
23 hbqList = []
24 lthSum = 0.0 # low(q) to high(q) sum
25 htlSum = 0.0 # high(q) to low(q) sum
26 totSum = 0.0
27
28 # first let's extract the Hydrogen Bond count from the .hbq file
29 hbqFile = open(hbqFileName, "r")
30 for line in hbqFile:
31 if "#" in line:
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])
37 else:
38 # accumulate the matrix into a list for easy looping and summing
39 hbqList.append(line.split())
40
41
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])
48
49 totSum = htlSum + lthSum
50 normHBCount = (totSum * hbCount) / (boxl_x * boxl_y * boxl_z) / nSnapshots
51
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")
65
66
67
68def main(argv):
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")
81
82 if len(sys.argv) == 1:
83 parser.print_help()
84 sys.exit(2)
85 args = parser.parse_args()
86
87 if (not args.hbqFileName):
88 parser.error("No input-file was specified")
89
90 if (not args.hbqPSAFileName):
91 parser.error("No output-file was specified")
92
93 if (not args.qS):
94 parser.print_help()
95 parser.error("No q(solid) was specified")
96
97 if (not args.qL):
98 parser.print_help()
99 parser.error("No q(liquid) was specified")
100
101 if (not args.boxl_x):
102 parser.print_help()
103 parser.error("No x-dimension of the box was specified")
104
105 if (not args.boxl_y):
106 parser.print_help()
107 parser.error("No y-dimension of the box was specified")
108
109 if (not args.boxl_z):
110 parser.print_help()
111 parser.error("No z-dimension of the box was specified")
112
113 if (not args.nSnapshots):
114 parser.print_help()
115 parser.error("No nSnapshots specified")
116
117
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)
120
121if __name__ == "__main__":
122 main(sys.argv[1:])