@@ -31,7 +31,10 @@ def reorient_axis(self) -> None:
31
31
32
32
class ChargeDensity (PGrid , ChargeABC ):
33
33
def __init__ (
34
- self , grid_data : np .ndarray , structure : Structure , normalization : str = "vasp" ,
34
+ self ,
35
+ grid_data : np .ndarray ,
36
+ structure : Structure ,
37
+ normalization : str = "vasp" ,
35
38
):
36
39
"""
37
40
Class that contains functions to featurize volumetic data with periodic
@@ -86,10 +89,14 @@ def renormalized_data(self) -> np.ndarray:
86
89
if self .normalization [0 ].lower () == "v" :
87
90
return self .grid_data * self .structure .volume
88
91
else :
89
- raise NotImplementedError ("Charge density normalization scheme not implemented" )
92
+ raise NotImplementedError (
93
+ "Charge density normalization scheme not implemented"
94
+ )
90
95
91
96
@classmethod
92
- def from_pmg_volumetric_data (cls , vdata : VolumetricData , data_key = "total" ) -> "ChargeDensity" :
97
+ def from_pmg_volumetric_data (
98
+ cls , vdata : VolumetricData , data_key = "total"
99
+ ) -> "ChargeDensity" :
93
100
"""
94
101
Read a single key from the data field of a VolumetricData object
95
102
Args:
@@ -99,10 +106,16 @@ def from_pmg_volumetric_data(cls, vdata: VolumetricData, data_key="total") -> "C
99
106
Returns:
100
107
ChargeDensity object
101
108
"""
102
- return cls (grid_data = vdata .data [data_key ], structure = vdata .structure , normalization = "vasp" ,)
109
+ return cls (
110
+ grid_data = vdata .data [data_key ],
111
+ structure = vdata .structure ,
112
+ normalization = "vasp" ,
113
+ )
103
114
104
115
@classmethod
105
- def from_rho (cls , rho : np .ndarray , structure : Structure , normalization : str = "vasp" ):
116
+ def from_rho (
117
+ cls , rho : np .ndarray , structure : Structure , normalization : str = "vasp"
118
+ ):
106
119
new_obj = cls (grid_data = rho , structure = structure , normalization = "none" )
107
120
new_obj .normalization = normalization
108
121
return new_obj
@@ -112,10 +125,10 @@ def reorient_axis(self) -> None:
112
125
Change the orientation of the lattice vector so that:
113
126
a points along the x-axis, b is in the xy-plane, c is in the positive-z halve of space
114
127
"""
115
- args = self . structure . lattice . abc + self . structure . lattice . angles # type: Tuple[float, float, float, float, float, float]
116
- self .structure .lattice = Lattice . from_parameters (
117
- * args , vesta = True
118
- )
128
+ args = (
129
+ self .structure .lattice . abc + self . structure . lattice . angles
130
+ ) # type: Tuple[float, float, float, float, float, float]
131
+ self . structure . lattice = Lattice . from_parameters ( * args , vesta = True )
119
132
120
133
# def get_data_in_cube(self, s: float, ngrid: int) -> np.ndarray:
121
134
# """
@@ -157,7 +170,9 @@ def get_transformed_obj(
157
170
158
171
"""
159
172
new_structure = self .structure .copy ()
160
- new_structure .translate_sites (list (range (len (new_structure ))), - np .array (frac_shift ))
173
+ new_structure .translate_sites (
174
+ list (range (len (new_structure ))), - np .array (frac_shift )
175
+ )
161
176
new_structure = new_structure * sc_mat
162
177
163
178
# determine the output grid
@@ -169,7 +184,9 @@ def get_transformed_obj(
169
184
else :
170
185
grid_out = grid_out
171
186
172
- new_rho = self .get_transformed_data (sc_mat , frac_shift , grid_out = grid_out , up_sample = up_sample )
187
+ new_rho = self .get_transformed_data (
188
+ sc_mat , frac_shift , grid_out = grid_out , up_sample = up_sample
189
+ )
173
190
return ChargeDensity .from_rho (new_rho , new_structure , self .normalization )
174
191
175
192
def get_reshaped_cell (
@@ -179,7 +196,9 @@ def get_reshaped_cell(
179
196
grid_out : Union [List , int ] = int (1e9 ),
180
197
up_sample : int = 1 ,
181
198
) -> "ChargeDensity" :
182
- return self .get_transformed_obj (sc_mat = sc_mat , frac_shift = frac_shift , grid_out = grid_out , up_sample = up_sample )
199
+ return self .get_transformed_obj (
200
+ sc_mat = sc_mat , frac_shift = frac_shift , grid_out = grid_out , up_sample = up_sample
201
+ )
183
202
184
203
#
185
204
# _, new_rho = get_sc_interp(self.rho, sc_mat, grid_sizes=grid_out)
@@ -209,11 +228,15 @@ def __init__(self, chargeden_dict: Dict, aug_charge: Dict = None):
209
228
) # get one key in the dictionary to make writing the subsequent code easier
210
229
211
230
@classmethod
212
- def from_pmg_volumetric_data (cls , vdata : VolumetricData , data_keys = ("total" , "diff" )):
231
+ def from_pmg_volumetric_data (
232
+ cls , vdata : VolumetricData , data_keys = ("total" , "diff" )
233
+ ):
213
234
chargeden_dict = {}
214
235
data_aug = getattr (vdata , "data_aug" , None )
215
236
for k in data_keys :
216
- chargeden_dict [k ] = ChargeDensity .from_pmg_volumetric_data (vdata , data_key = k )
237
+ chargeden_dict [k ] = ChargeDensity .from_pmg_volumetric_data (
238
+ vdata , data_key = k
239
+ )
217
240
return cls (chargeden_dict , aug_charge = data_aug )
218
241
219
242
@property
@@ -242,7 +265,8 @@ def get_reshaped_cell(
242
265
for k , v in self .chargeden_dict .items ():
243
266
new_spin_charge [k ] = v .get_reshaped_cell (sc_mat , frac_shift , grid_out )
244
267
factor = int (
245
- new_spin_charge [self ._tmp_key ].structure .num_sites / self .chargeden_dict [self ._tmp_key ].structure .num_sites
268
+ new_spin_charge [self ._tmp_key ].structure .num_sites
269
+ / self .chargeden_dict [self ._tmp_key ].structure .num_sites
246
270
)
247
271
new_aug = {}
248
272
if self .aug_charge is not None :
@@ -279,14 +303,18 @@ def multiply_aug(data_aug: List[str], factor: int) -> List[str]:
279
303
if cur_block :
280
304
for j in range (factor ):
281
305
cnt += 1
282
- cur_block [0 ] = f"augmentation occupancies{ cnt :>4} { cur_block [0 ].split ()[- 1 ]:>4} \n "
306
+ cur_block [
307
+ 0
308
+ ] = f"augmentation occupancies{ cnt :>4} { cur_block [0 ].split ()[- 1 ]:>4} \n "
283
309
res .extend (cur_block )
284
310
cur_block = [ll ]
285
311
else :
286
312
cur_block .append (ll )
287
313
else :
288
314
for j in range (factor ):
289
315
cnt += 1
290
- cur_block [0 ] = f"augmentation occupancies{ cnt :>4} { cur_block [0 ].split ()[- 1 ]:>4} \n "
316
+ cur_block [
317
+ 0
318
+ ] = f"augmentation occupancies{ cnt :>4} { cur_block [0 ].split ()[- 1 ]:>4} \n "
291
319
res .extend (cur_block )
292
320
return res
0 commit comments