-
Notifications
You must be signed in to change notification settings - Fork 2
/
CHECKFIT-energy-vs-displacement.py
executable file
·179 lines (142 loc) · 5.22 KB
/
CHECKFIT-energy-vs-displacement.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/usr/bin/python
# -*- coding: utf-8 -*-
#_______________________________________________________________________________
from sys import stdin
from math import sqrt
from math import factorial
import numpy
import sys
import os
#-------------------------------------------------------------------------------
def fit(order,x,y,npoints,nderiv):
import math
b = 99999999
if (npoints > order):
b = numpy.polyfit(x,y,order)[order-nderiv]
b = math.factorial(nderiv)*b
return b
def printderiv(etam,bb,nfit,output_file):
print >> output_file, '%12.8f'%(etam),
for j in range(0,nfit):
if (bb[j] != 99999999):
print >> output_file, '%14.6f'%(bb[j]),
print >> output_file
return
def printnice(etam,bb,nfit,nderiv,orderstep,displpoints):
invcm2hz = 33.356409
print
print "#############################################\n"
print " Fit data------------------------------------\n"
print " Maximum value of the displacement ==>", '%5.3f'%(etam)
print " Number of displacement values used ==>", '%5i'%(displpoints),"\n"
print " Fit results for the derivative of order", '%4i'%(nderiv),"\n"
for j in range(0,nfit):
order=nderiv+j*orderstep
if (bb[j] != 99999999):
print " Polynomial of order", '%2i'%(order), " ==> ",
print '%8.2f'%(bb[j]), "[cm-1]"
print
for j in range(0,nfit):
order=nderiv+j*orderstep
if (bb[j] != 99999999):
print " Polynomial of order", '%2i'%(order), " ==> ",
print '%8.4f'%(bb[j]/invcm2hz), " [THz]"
print
return
def sortdispl(s,e):
ss=[]
ee=[]
ww=[]
for i in range(len(s)): ww.append(s[i])
ww.sort()
for i in range(len(s)):
ss.append(s[s.index(ww[i])])
ee.append(e[s.index(ww[i])])
return ss, ee
#-------------------------------------------------------------------------------
if (str(os.path.exists('INFO-diamond-phonon'))=='False'):
sys.exit("ERROR: file INFO-diamond-phonon not found!\n")
if (str(os.path.exists('energy-vs-displacement'))=='False'):
sys.exit("ERROR: file energy-vs-displacement not found!\n")
input_info = open('INFO-diamond-phonon',"r")
line = input_info.readline()
lattice_parameter = float(input_info.readline().strip().split()[5])
input_info.close()
#-------------------------------------------------------------------------------
maximum_displ = input("\nEnter maximum displacement for the interpolation >>>> ")
order_of_derivative = input("\nEnter the order of derivative >>>> ")
if (order_of_derivative < 0):
sys.exit("ERROR: Order of derivative must be positive!\n")
amass = input("\nEnter atomic mass in [amu] >>>> ")
#-------------------------------------------------------------------------------
orderstep = 1
factor = 2./3.
if (os.path.exists('X-phonon-calculation')):
factor = 1./4.
print "_____________________________________________"
print " X-phonon-calculation"
if (os.path.exists('quantum-espresso')):
factor=factor*0.5
amu = 1.66053886
invcm2hz = 33.356409
bohr_radius = 0.529177
pi = 3.1415926535897931
joule2hartree = 4.3597482
invcm2joule = 5.03411721428
joule2rydberg = joule2hartree/2.
unitconv=invcm2hz/lattice_parameter/bohr_radius
unitconv=unitconv**2
unitconv=unitconv*factor*joule2hartree/amass/amu*10**5
#-------------------------------------------------------------------------------
energy = []
displ = []
#-------------------------------------------------------------------------------
input_energy = open('energy-vs-displacement',"r")
while True:
line = input_energy.readline()
line = line.strip()
if len(line) == 0: break
eta,ene = line.split()
if (abs(float(eta)) <= maximum_displ):
energy.append(float(ene))
displ.append(float(eta))
#-------------------------------------------------------------------------------
displ,energy=sortdispl(displ,energy)
#-------------------------------------------------------------------------------
orderlist=[]
for i in range(0,6):
dumorder=order_of_derivative+orderstep*i
orderlist.append(dumorder)
#-------------------------------------------------------------------------------
output_file = open('check-energy-derivatives',"w")
nmax=len(displ)
while (len(displ) > order_of_derivative and len(displ) > 1):
bb = []
n=len(displ)
etam=max(displ)
emin=min(displ)
etam=max(abs(etam),abs(emin))
for order in orderlist:
cc=fit(order,displ,energy,n,order_of_derivative)
if (cc != 99999999):
if (cc >= 0): freq=sqrt( cc*unitconv)/2./pi
if (cc < 0): freq=-sqrt(-cc*unitconv)/2./pi
bb.append(freq)
else:
bb.append(cc)
if (n == nmax):
printnice(etam,bb,6,order_of_derivative,orderstep,nmax)
printderiv(etam,bb,6,output_file)
if (abs(displ[0]+etam) < 1.e-7):
displ.pop(0)
energy.pop(0)
if (abs(displ[len(displ)-1]-etam) < 1.e-7):
displ.pop()
energy.pop()
output_file.close()
output_file = open('order-of-derivative',"w")
print >> output_file, order_of_derivative
output_file.close()
print "#############################################\n"
os.system("export PDEFAULT=true; PLOT-checkderiv.py")
os.system("unset PDEFAULT")