1
1
2
+ from pymatgen import Structure
3
+ from pymatgen .analysis .magnetism import CollinearMagneticStructureAnalyzer
4
+
2
5
import numpy as np
3
6
4
7
def procure_response_dict (
5
- struct_final ,
8
+ struct_final , num_perturb_sites ,
6
9
incar_dict , outcar_dict ,
7
- inv_block_dict , response_dict ,
10
+ inv_block_dict , response_dict , perturb_dict ,
11
+ rkey , keys , ldaul_vals , analyzer_gs ,
8
12
):
13
+ """
14
+ Function to gather response data, in preparation for linear regression.
15
+ This data is organized into `response_dict`.
16
+ """
17
+
9
18
# perform magnetic ordering analysis
10
19
analyzer_output = CollinearMagneticStructureAnalyzer (
11
20
struct_final , threshold = 0.61 )
@@ -26,7 +35,6 @@ def procure_response_dict(
26
35
specie = struct_final [i ].specie
27
36
ldaul = ldaul_vals [i ]
28
37
29
- # if ldaul != -1 and rkey:
30
38
orbital = inv_block_dict [str (ldaul )]
31
39
perturb_dict .update (
32
40
{"site" + str (i ): {"specie" : str (specie ),
@@ -52,18 +60,23 @@ def procure_response_dict(
52
60
53
61
response_dict [rkey ]['magnetic order' ].append (magnet_order )
54
62
55
- # Function for fitting to response data. Returns: slope and associated error
56
63
def response_fit (x , y ):
64
+ """
65
+ Function for fitting to response data. Returns: slope and associated error
66
+ """
57
67
58
68
(p , pcov ) = np .polyfit (x , y , 1 , cov = True )
59
69
perr = np .sqrt (np .diag (pcov ))
60
70
61
71
return p , perr
62
72
63
- # Function for fitting to response data
64
- # - includes the "slope ~ zero" case for stepped data due to low precision
65
- # Returns: slope and associated error
66
73
def response_fit_stepped (x , y , tol = 1.0e-6 ):
74
+ """
75
+ Function for fitting to response data
76
+ - includes the "slope ~ zero" case for stepped data due to low precision
77
+ Returns: slope and associated error
78
+ """
79
+
67
80
is_stepped = False
68
81
step_id = - 1
69
82
@@ -96,8 +109,15 @@ def response_fit_stepped(x, y, tol=1.0e-6):
96
109
97
110
def obtain_response_matrices (
98
111
n_response , spin_polarized ,
99
- response_dict ,
112
+ response_dict , keys ,
100
113
):
114
+ """
115
+ Function to compute self-consistent (SCF) and non-self-consistent (NSCF)
116
+ linear response "chi" matrices; In addition to using linear regression
117
+ to compute slopes about zero potential, the uncertainty associated
118
+ with these values are also stored for subsequent error quantification.
119
+ Returns: chi_matrix_nscf, chi_matrix_scf, chi_nscf_err, chi_scf_err
120
+ """
101
121
102
122
# Matrices for self-consistent and non-self-consistent responses
103
123
# & associated element-wise errors
@@ -175,8 +195,11 @@ def obtain_response_matrices(
175
195
176
196
return chi_matrix_nscf , chi_matrix_scf , chi_nscf_err , chi_scf_err
177
197
178
- # Function to compute the element-wise error propagation in matrix inversion
179
198
def inverse_matrix_uncertainty (matrix , matrix_covar ):
199
+ """
200
+ Function to compute the element-wise error propagation in matrix inversion
201
+ """
202
+
180
203
m ,n = matrix .shape
181
204
if m != n :
182
205
logger .warning ("Matrix dimension error" )
@@ -232,10 +255,12 @@ def det_deriv(matrix,i,j):
232
255
233
256
return matrixinv , matrixinv_var , jacobians
234
257
235
- # Function to compute inverse of response matrix and associated
236
- # element-wise uncertainty for point-wise, atom-wise,
237
- # and full matrix inversion
238
258
def chi_inverse (chi , chi_err , method = "full" ):
259
+ """
260
+ Function to compute inverse of response matrix and associated
261
+ element-wise uncertainty for point-wise, atom-wise,
262
+ and full matrix inversion
263
+ """
239
264
240
265
n_response = len (chi )
241
266
@@ -267,10 +292,15 @@ def chi_inverse(chi, chi_err, method="full"):
267
292
268
293
return chi_block , chi_inv , chi_inv_var , chi_inv_jacobs
269
294
270
- def hubbard_hund_pointwise (
295
+ def compute_u_pointwise (
271
296
site_index ,
272
297
f_matrix , f_matrix_err ,
273
298
):
299
+ """
300
+ Function to compute Hubbard U value using point-wise (diagonal) inversion,
301
+ in addition to the associated uncertainty value
302
+ - based on the study by Linscott et. al.
303
+ """
274
304
275
305
i = site_index
276
306
@@ -281,10 +311,15 @@ def hubbard_hund_pointwise(
281
311
282
312
return uval , uval_err
283
313
284
- def hubbard_hund_simple_two_by_two (
314
+ def compute_uj_simple_two_by_two (
285
315
site_index ,
286
316
f_matrix , f_matrix_err ,
287
317
):
318
+ """
319
+ Function to compute Hubbard U and Hund J values using simple 2x2 formula,
320
+ in addition to the associated uncertainty values
321
+ - based on the study by Linscott et. al.
322
+ """
288
323
289
324
i = site_index
290
325
@@ -299,14 +334,19 @@ def hubbard_hund_simple_two_by_two(
299
334
jval = 0.25 * np .sum (jmat )
300
335
jval_err = 0.25 * np .sqrt (np .sum (jmat_err ** 2 ))
301
336
302
- return uval , uval_err , jmat , jmat_err
337
+ return uval , uval_err , jval , jval_err
303
338
304
- def hubbard_hund_scaled_two_by_two (
339
+ def compute_uj_scaled_two_by_two (
305
340
site_index ,
306
341
f_matrix , f_matrix_err ,
307
342
chi_matrix_scf , chi_scf_err , chi_matrix_nscf , chi_nscf_err ,
308
343
chi_scf_inv_jacobs , chi_nscf_inv_jacobs ,
309
344
):
345
+ """
346
+ Function to compute Hubbard U and Hund J values using scaled 2x2 formula,
347
+ in addition to the associated uncertainty values
348
+ - based on the study by Linscott et. al.
349
+ """
310
350
311
351
i = site_index
312
352
@@ -401,4 +441,4 @@ def fmat_deriv_nscf(kk,ll,k,l):
401
441
# compute std
402
442
jval_err = np .sqrt (jval_err )
403
443
404
- return uval , uval_err , jmat , jmat_err
444
+ return uval , uval_err , jval , jval_err
0 commit comments