-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.py
178 lines (117 loc) · 4.34 KB
/
gen.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
175
176
177
178
import numpy as np
# general note, everything has been converted to 0-indexed
def readpara():
with open('paras') as f:
ifoffdiag, ifoffsite, numdop, ctype, offscale = f.readline().split()
para = {
'ifoffdiag': int(ifoffdiag),
'ifoffsite': int(ifoffsite),
'numdop': int(numdop),
'ctype': ctype,
'offscale': float(offscale)
}
dops = []
for _ in range(para['numdop']):
dops += [[float(val) for val in f.readline().split()]]
para['dops'] = dops
para['CONST'] = 13.605692 * 2.0 * 0.5291772
para['latcon'] = 5.431
return para
def readlattice(para):
def testoutput():
dop = searchdict[(0.0, 0.0, 0.0)]
print('dopant site: {}'.format(dop))
print('dopant NN: {}'.format(NN[dop]))
with open('lattice.dat') as f:
# hardcoded, the 2nd entry on the first line denotes the total # of sites
# Then the first 13 lines are discarded
size = int(f.readline().split()[1])
# discard lines
for _ in range(12):
f.readline()
# read site
site = []
for _ in range(size):
site += [[ float(val) for val in f.readline().split()]]
site = np.array(site)[:, :3]
searchdict = { tuple(s) : i for i, s in enumerate(site)}
# read NN
NN = [[0] for _ in range(size) ]
for s in range( size):
# 0-indexed
NN[s] = [int(val) - 1 for val in f.readline().split()]
f.readline()
f.readline()
f.readline()
#np.savetxt('NN', NN, fmt='%i')
testoutput()
para['size'] = size
return site, NN, searchdict
def onsite_gen(sites, NN, searchdict, para):
size = para['size']
dops = para['dops']
const = para['CONST']
latcon = para['latcon']
ctype = para['ctype']
ifoffdiag = para['ifoffdiag']
offscale = para['offscale']
with open('diagcorr') as f:
epsilon = float(f.readline())
# 17 = 1 + 4 + 3 * 4, up to second nearest neighbors
cccdiag = []
for _ in range(17):
cccdiag += [[float(val) for val in f.readline().split()]]
if ifoffdiag:
with open('offdiagcorr') as f:
cccoff = []
for _ in range(17):
cccoff += [[float(val) for val in f.readline().split()]]
cccdiag = np.array(cccdiag)
cccoff = np.array(cccoff)
cccoff *= offscale
diag = np.zeros((size, 10))
offdiag = [ [0] for _ in range(size)]
# current no offsite
offsite = [ [0] for _ in range(size)]
corrchart = [ 0 for _ in range(size)]
for dop in dops:
# sets up the NN sequence to add correction terms
dopid = searchdict[tuple(dop)]
if ctype == 'dop':
dopNN = [dopid]
elif ctype == '1NN':
dopNN = [dopid] + NN[dopid]
elif ctype == '2NN':
dopNN = [dopid] + NN[dopid]
for NNid in NN[dopid]:
for rNNid in NN[NNid]:
if rNNid != dopid:
dopNN += [rNNid]
print(dopNN)
for i, site in enumerate(sites):
if i not in dopNN:
# Coulomb corrections
r = np.linalg.norm(site - dop) * latcon
diag[i] += [ const / (epsilon * r)] * 10
else:
diag[i] += cccdiag[dopNN.index(i)]
if ifoffdiag:
if len(offdiag[i]) == 1:
offdiag[i] = cccoff[dopNN.index(i)]
else:
offdiag[i] += cccoff[dopNN.index(i)]
corrchart[i] = 1
# default set offsite to 0
offsite[i] = np.zeros(400)
np.savetxt('diagonal.dat', diag)
with open('offdiag.dat', 'w') as f:
for site in range(size):
f.write( ' '.join([str(num) for num in offdiag[site]]) + '\n')
with open('offsite.dat', 'w') as f:
for site in range(size):
f.write( ' '.join([str(num) for num in offsite[site]]) + '\n')
np.savetxt('corrchart.dat', corrchart, fmt='%i')
if __name__ == '__main__':
para = readpara()
sites, NN, searchdict = readlattice(para)
onsite_gen(sites, NN, searchdict, para)