@@ -50,17 +50,24 @@ def to_pmg(self) -> PhononDosObject:
50
50
return PhononDosObject (frequencies = self .frequencies , densities = self .densities )
51
51
52
52
@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 :
54
54
"""Convert PhononDOS to a pyarrow Table."""
55
55
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
+ )
57
62
58
63
@classmethod
59
64
@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 :
61
66
"""Create a PhononDOS from a pyarrow Table."""
62
67
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
+ )
64
71
65
72
66
73
class PhononBS (BaseModel ):
@@ -142,7 +149,7 @@ def to_pmg(self) -> PhononBandStructureSymmLine:
142
149
)
143
150
144
151
@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 :
146
153
"""Convert a PhononBS to an arrow table."""
147
154
config = self .model_dump ()
148
155
if structure := config .pop ("structure" , None ):
@@ -166,13 +173,15 @@ def to_arrow(self, col_prefix : str | None = None) -> ArrowTable:
166
173
]
167
174
168
175
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
+ )
170
179
171
180
@classmethod
172
181
@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 :
174
183
"""Create a PhononBS from an arrow table."""
175
- col_prefix = col_prefix or ""
184
+ col_prefix = col_prefix or ""
176
185
config : dict [str , Any ] = {}
177
186
for k in (
178
187
"structure" ,
@@ -197,7 +206,9 @@ def from_arrow(cls, table: ArrowTable, col_prefix : str | None = None) -> Self:
197
206
config ["eigendisplacements" ] = (
198
207
table [f"{ col_prefix } eigendisplacements_real" ].to_numpy ()[0 ]
199
208
+ 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
+ )
201
212
elif k == "qpoint_labels" :
202
213
config ["labels_dict" ] = dict (
203
214
zip (v , table [f"{ col_prefix } qpoint_labelled_points" ].to_pylist ()[0 ])
@@ -377,15 +388,16 @@ def objects_to_arrow(self) -> ArrowTable:
377
388
if self .phonon_bandstructure :
378
389
bst = self .phonon_bandstructure .to_arrow (col_prefix = "bs_" )
379
390
for k in bst .column_names :
380
- table = table .append_column (k ,bst [k ])
381
-
391
+ table = table .append_column (k , bst [k ])
392
+
382
393
if self .phonon_dos :
383
394
dost = self .phonon_dos .to_arrow (col_prefix = "dos_" )
384
-
395
+
385
396
for k in dost .column_names :
386
- table = table .append_column (k ,dost [k ])
397
+ table = table .append_column (k , dost [k ])
387
398
return table
388
-
399
+
400
+
389
401
class PhononComputationalSettings (BaseModel ):
390
402
"""Collection to store computational settings for the phonon computation."""
391
403
0 commit comments