-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathclass0_functions3.py
92 lines (84 loc) · 3.54 KB
/
class0_functions3.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
import numpy as np
import os
import sys
sys.path.append(os.environ['SCRIPT'])
def read_interpolate_2D_data(x1,x2,y,findx1,findx2):
# x1 and x2 are coming as either a meshgrid or unique items
# (findx1, findx2) is the data point to find y
# y is either bandgap, dielectric constant
# x1 should look like array([[0. , 0.05, 0.1 ],[0. , 0.05, 0.1 ]])
# x2 should look like array([[0.32, 0.32, 0.32], [0.34, 0.34, 0.34]])
# y(ind2,ind1): x1 will take the index on the right (smallest change), x2 will take the left one
x1=np.unique(x1)
x2=np.unique(x2)
findx1=float(findx1)
findx2=float(findx2)
assert y.shape == (len(x2),len(x1))
# np.where(x1==findx1) returns (array([1]),), so [0][0] will give the value inside
ind1=np.where(x1==findx1)[0][0]
ind2=np.where(x2==findx2)[0][0]
findy=y[ind2,ind1]
return findy
def get_2D_electronic_eps(dict_find):
# find the value 'find1' of 'name1' e.g. the value find1=0.32 of 'AEXX'
# input a dictionary of values {name1:find1, name2:find2}
sys.path.append(os.environ['WORK'])
from ELECTRONIC_EPS import x,y,xname
# need to change this
xname=xname.split('_')
x1=x[0]
x2=x[1]
findy=read_interpolate_2D_data(x1,x2,y,dict_find[xname[0]], dict_find[xname[1]])
return findy
def write_INFO( #direc,
dictionary: dict={},
direc='.',
incarname: str='SAVEINFO'):
''' write an INCAR-like file: SAVEINFO
Parameters
----------
dictionary: dict
keywords are self-defined
like {title=title,legend=legend}
direc: str or pathlib.Path
directory to write in SAVEINFO
incarname: str
a string like SAVEINFO, stores the information
Other possible keywords:
# CENTER=position of defect center
# NLINE= the vim line to find defect (or its neighbors)
# FREYCORR = freysoldt correction
# EPS= dielectric constant
# EPS_ELEC = electronic dielectric constant
'''
from pathlib import Path
direc = Path(direc)
with open(str(direc / incarname), 'w') as f:
for key in dictionary.keys():
f.write('%s%s=%s \n' % ( '', key, str(dictionary[key])) )
def read_interpolate_1D_data(x1,x2,y,findx1,findx2):
# x1,x2,y are 1D data. The same index correspond to the same calculation.
# E.g. x1(aexx)=[0,1,0,1], x2(hfscreen)=[0.1,0.1,0.2,0.2], y(bandgap)=related values
# find the index when x1=findx1 and x2=findx2
findind=np.where((x1==findx1)*(x2==findx2))[0] # np.where gives (array([9]),)
assert len(findind)==1 ,'must be one found value' # findind will be array([9])
findy=y[findind[0]] # use findind[0]=9 to give the index number
return findy
def reorder_x_y_data(x,y,data):
# x,y,data should come as the 1-d arrays
# make x,y a meshgrid
# make data the correct format
uniquex=np.unique(x) # unique will sort the values automatically
uniquey=np.unique(y)
# generate a meshgrid
xx,yy=np.meshgrid(uniquex,uniquey) # shape is (len(uniquey),len(uniquex))
data_xx_yy=np.zeros(xx.shape)
for i in range(len(uniquey)):
for j in range(len(uniquex)):
#read_interpolate_1D_data(x1,x2,y,findx1,findx2)
data_xx_yy[i,j]= read_interpolate_1D_data(x,y,data,xx[i,j],yy[i,j])
# get data[i,j] to match with meshgrid xx,yy
return xx,yy,data_xx_yy
#def calc_deltamiu(enthalpyf_ele, ele, dict_elementformula): # formation enthalpy = num_Be * deltamiu_Be + num_O * deltamiu_O
# num_ele = dict_elementformula[ele] # number of element atoms
# return enthalpyf_ele / num_ele