Skip to content

Commit f91bf62

Browse files
committed
lint
1 parent 9a10dcf commit f91bf62

File tree

2 files changed

+46
-18
lines changed

2 files changed

+46
-18
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repos:
77
- id: trailing-whitespace
88
- id: flake8
99
- repo: https://github.com/pre-commit/mirrors-mypy
10-
rev: v0.761
10+
rev: v0.812
1111
hooks:
1212
- id: mypy
1313
- repo: https://github.com/kynan/nbstripout

src/pyrho/core/chargeDensity.py

+45-17
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ def reorient_axis(self) -> None:
3131

3232
class ChargeDensity(PGrid, ChargeABC):
3333
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",
3538
):
3639
"""
3740
Class that contains functions to featurize volumetic data with periodic
@@ -86,10 +89,14 @@ def renormalized_data(self) -> np.ndarray:
8689
if self.normalization[0].lower() == "v":
8790
return self.grid_data * self.structure.volume
8891
else:
89-
raise NotImplementedError("Charge density normalization scheme not implemented")
92+
raise NotImplementedError(
93+
"Charge density normalization scheme not implemented"
94+
)
9095

9196
@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":
93100
"""
94101
Read a single key from the data field of a VolumetricData object
95102
Args:
@@ -99,10 +106,16 @@ def from_pmg_volumetric_data(cls, vdata: VolumetricData, data_key="total") -> "C
99106
Returns:
100107
ChargeDensity object
101108
"""
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+
)
103114

104115
@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+
):
106119
new_obj = cls(grid_data=rho, structure=structure, normalization="none")
107120
new_obj.normalization = normalization
108121
return new_obj
@@ -112,10 +125,10 @@ def reorient_axis(self) -> None:
112125
Change the orientation of the lattice vector so that:
113126
a points along the x-axis, b is in the xy-plane, c is in the positive-z halve of space
114127
"""
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)
119132

120133
# def get_data_in_cube(self, s: float, ngrid: int) -> np.ndarray:
121134
# """
@@ -157,7 +170,9 @@ def get_transformed_obj(
157170
158171
"""
159172
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+
)
161176
new_structure = new_structure * sc_mat
162177

163178
# determine the output grid
@@ -169,7 +184,9 @@ def get_transformed_obj(
169184
else:
170185
grid_out = grid_out
171186

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+
)
173190
return ChargeDensity.from_rho(new_rho, new_structure, self.normalization)
174191

175192
def get_reshaped_cell(
@@ -179,7 +196,9 @@ def get_reshaped_cell(
179196
grid_out: Union[List, int] = int(1e9),
180197
up_sample: int = 1,
181198
) -> "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+
)
183202

184203
#
185204
# _, 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):
209228
) # get one key in the dictionary to make writing the subsequent code easier
210229

211230
@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+
):
213234
chargeden_dict = {}
214235
data_aug = getattr(vdata, "data_aug", None)
215236
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+
)
217240
return cls(chargeden_dict, aug_charge=data_aug)
218241

219242
@property
@@ -242,7 +265,8 @@ def get_reshaped_cell(
242265
for k, v in self.chargeden_dict.items():
243266
new_spin_charge[k] = v.get_reshaped_cell(sc_mat, frac_shift, grid_out)
244267
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
246270
)
247271
new_aug = {}
248272
if self.aug_charge is not None:
@@ -279,14 +303,18 @@ def multiply_aug(data_aug: List[str], factor: int) -> List[str]:
279303
if cur_block:
280304
for j in range(factor):
281305
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"
283309
res.extend(cur_block)
284310
cur_block = [ll]
285311
else:
286312
cur_block.append(ll)
287313
else:
288314
for j in range(factor):
289315
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"
291319
res.extend(cur_block)
292320
return res

0 commit comments

Comments
 (0)