Skip to content

Commit 51f7661

Browse files
precommit
1 parent 864a7ee commit 51f7661

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

emmet-core/emmet/core/phonon.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,24 @@ def to_pmg(self) -> PhononDosObject:
5050
return PhononDosObject(frequencies=self.frequencies, densities=self.densities)
5151

5252
@requires(pa is not None, "`pip install pyarrow` to use this functionality.")
53-
def to_arrow(self, col_prefix : str | None = None) -> ArrowTable:
53+
def to_arrow(self, col_prefix: str | None = None) -> ArrowTable:
5454
"""Convert PhononDOS to a pyarrow Table."""
5555
col_prefix = col_prefix or ""
56-
return pa.Table.from_pydict({f"{col_prefix}{k}": [getattr(self,k)] for k in ("frequencies","densities")})
56+
return pa.Table.from_pydict(
57+
{
58+
f"{col_prefix}{k}": [getattr(self, k)]
59+
for k in ("frequencies", "densities")
60+
}
61+
)
5762

5863
@classmethod
5964
@requires(pa is not None, "`pip install pyarrow` to use this functionality.")
60-
def from_arrow(cls, table: ArrowTable, col_prefix : str | None = None) -> Self:
65+
def from_arrow(cls, table: ArrowTable, col_prefix: str | None = None) -> Self:
6166
"""Create a PhononDOS from a pyarrow Table."""
6267
col_prefix = col_prefix or ""
63-
return cls(**{k: table[f"{col_prefix}{k}"].to_pylist()[0] for k in cls.model_fields})
68+
return cls(
69+
**{k: table[f"{col_prefix}{k}"].to_pylist()[0] for k in cls.model_fields}
70+
)
6471

6572

6673
class PhononBS(BaseModel):
@@ -142,7 +149,7 @@ def to_pmg(self) -> PhononBandStructureSymmLine:
142149
)
143150

144151
@requires(pa is not None, "`pip install pyarrow` to use this functionality.")
145-
def to_arrow(self, col_prefix : str | None = None) -> ArrowTable:
152+
def to_arrow(self, col_prefix: str | None = None) -> ArrowTable:
146153
"""Convert a PhononBS to an arrow table."""
147154
config = self.model_dump()
148155
if structure := config.pop("structure", None):
@@ -166,13 +173,15 @@ def to_arrow(self, col_prefix : str | None = None) -> ArrowTable:
166173
]
167174

168175
col_prefix = col_prefix or ""
169-
return pa.Table.from_pydict({f"{col_prefix}{k}": [v] for k, v in config.items()})
176+
return pa.Table.from_pydict(
177+
{f"{col_prefix}{k}": [v] for k, v in config.items()}
178+
)
170179

171180
@classmethod
172181
@requires(pa is not None, "`pip install pyarrow` to use this functionality.")
173-
def from_arrow(cls, table: ArrowTable, col_prefix : str | None = None) -> Self:
182+
def from_arrow(cls, table: ArrowTable, col_prefix: str | None = None) -> Self:
174183
"""Create a PhononBS from an arrow table."""
175-
col_prefix= col_prefix or ""
184+
col_prefix = col_prefix or ""
176185
config: dict[str, Any] = {}
177186
for k in (
178187
"structure",
@@ -197,7 +206,9 @@ def from_arrow(cls, table: ArrowTable, col_prefix : str | None = None) -> Self:
197206
config["eigendisplacements"] = (
198207
table[f"{col_prefix}eigendisplacements_real"].to_numpy()[0]
199208
+ 1.0j * table[f"{col_prefix}eigendisplacements_imag"].to_numpy()[0]
200-
).reshape(tuple(table[f"{col_prefix}eigendisplacements_shape"].to_pylist()[0]))
209+
).reshape(
210+
tuple(table[f"{col_prefix}eigendisplacements_shape"].to_pylist()[0])
211+
)
201212
elif k == "qpoint_labels":
202213
config["labels_dict"] = dict(
203214
zip(v, table[f"{col_prefix}qpoint_labelled_points"].to_pylist()[0])
@@ -377,15 +388,16 @@ def objects_to_arrow(self) -> ArrowTable:
377388
if self.phonon_bandstructure:
378389
bst = self.phonon_bandstructure.to_arrow(col_prefix="bs_")
379390
for k in bst.column_names:
380-
table = table.append_column(k,bst[k])
381-
391+
table = table.append_column(k, bst[k])
392+
382393
if self.phonon_dos:
383394
dost = self.phonon_dos.to_arrow(col_prefix="dos_")
384-
395+
385396
for k in dost.column_names:
386-
table = table.append_column(k,dost[k])
397+
table = table.append_column(k, dost[k])
387398
return table
388-
399+
400+
389401
class PhononComputationalSettings(BaseModel):
390402
"""Collection to store computational settings for the phonon computation."""
391403

0 commit comments

Comments
 (0)