OpenMD 3.0
Molecular Dynamics in the Open
Loading...
Searching...
No Matches
funcflExtractor
1#!@Python3_EXECUTABLE@
2"""Funcfl Extractor
3
4Opens an DYNAMO86 EAM funcfl file, parses the data and writes out
5separate files for F[rho], rho(r), and Z(r)
6
7Usage: funcflExtractor
8
9Options:
10 -h, --help show this help
11 -f, --funcfl=... use specified funcfl file for the data
12 -o, --output-base=... use specified name for the base of the output files
13
14Example:
15 funcflExtractor -f Au.u3.funcfl -o Au_u3
16
17"""
18
19__author__ = "Dan Gezelter (gezelter@nd.edu)"
20__copyright__ = "Copyright (c) 2004-present The University of Notre Dame. All Rights Reserved."
21__license__ = "OpenMD"
22
23import sys
24import getopt
25import string
26
27z = []
28rho = []
29fRho = []
30
31def usage():
32 print(__doc__)
33
34def readFuncflFile(funcflFileName):
35
36 eamFile = open(funcflFileName, 'r')
37 lines = eamFile.readlines()
38 eamFile.close()
39
40 lineNo = 0
41 tokensFound = 0
42
43 for l in lines:
44 lineNo = lineNo +1
45 if (lineNo == 3):
46 L = string.split(l)
47 nrho = int(L[0])
48 drho = float(L[1])
49 nR = int(L[2])
50 dR = float(L[3])
51 rcut = float(L[4])
52 if (lineNo > 3):
53 L = string.split(l)
54 for i in range(0, 5):
55 tokensFound = tokensFound + 1
56 if (tokensFound <= nrho):
57 fRho.append(float(L[i]))
58 elif (tokensFound <= nrho+nR):
59 z.append(float(L[i]))
60 else:
61 rho.append(float(L[i]))
62
63 eamFile.close()
64 return (nrho, drho, nR, dR, rcut)
65
66def writeFiles(outputBaseName, nrho, drho, nR, dR, rcut):
67
68 fFile = open(outputBaseName + ".F.dat", 'w')
69 zFile = open(outputBaseName + ".Z.dat", 'w')
70 rhoFile = open(outputBaseName + ".rho.dat", 'w')
71
72 for i in range(0, nR):
73 r = i*dR
74 zFile.write( "%f\t%f\n" % (r, z[i]))
75 rhoFile.write( "%f\t%f\n" % (r, rho[i]))
76
77
78 for i in range(0, nrho):
79 rhoVal = i * drho
80 fFile.write("%f\t%f\n" % (rhoVal, fRho[i]))
81
82 fFile.close()
83 zFile.close()
84 rhoFile.close()
85
86
87def main(argv):
88 global haveFuncflFileName
89 global haveOutputBaseName
90
91 haveFuncflFileName = False
92 haveOutputBaseName = False
93
94 try:
95 opts, args = getopt.getopt(argv, "hf:o:", ["help", "funcfl=", "output-base="])
96 except getopt.GetoptError:
97 usage()
98 sys.exit(2)
99 for opt, arg in opts:
100 if opt in ("-h", "--help"):
101 usage()
102 sys.exit()
103 elif opt in ("-f", "--funcfl"):
104 funcflFileName = arg
105 haveFuncflFileName = True
106 elif opt in ("-o", "--output-base"):
107 outputBaseName = arg
108 haveOutputBaseName = True
109 if (not haveFuncflFileName):
110 usage()
111 print("No funcfl file was specified")
112 sys.exit()
113 if (not haveOutputBaseName):
114 usage()
115 print("No output base name was specified")
116 sys.exit()
117
118 (nrho, drho, nR, dR, rcut) = readFuncflFile(funcflFileName)
119 writeFiles(outputBaseName, nrho, drho, nR, dR, rcut)
120
121if __name__ == "__main__":
122 if len(sys.argv) == 1:
123 usage()
124 sys.exit()
125 main(sys.argv[1:])
126
127