@@ -212,14 +212,24 @@ def make_abacus_scf_stru(
212
212
type_map = None ,
213
213
pporb = "" , # pull all pp orb dpks files to pporb folder
214
214
):
215
+ sys_data_copy = copy .deepcopy (sys_data )
215
216
# re-construct the path of files by pporb + file name
216
217
fp_pp_files = [os .path .join (pporb , i ) for i in fp_pp_files ]
217
218
if fp_orb_files is not None :
218
219
fp_orb_files = [os .path .join (pporb , i ) for i in fp_orb_files ]
219
220
if fp_dpks_descriptor is not None :
220
221
fp_dpks_descriptor = os .path .join (pporb , fp_dpks_descriptor )
221
222
222
- c = make_unlabeled_stru (sys_data , 0 , pp_files = fp_pp_files , numerical_orbital = fp_orb_files , numerical_descriptor = fp_dpks_descriptor )
223
+ # we need to make sure that the shape of cells and coords are the same
224
+ # and if they are 2D, we need to convert them to 3D
225
+ cells = np .array (sys_data ["cells" ])
226
+ coords = np .array (sys_data ["coords" ])
227
+ assert len (cells .shape ) == len (coords .shape ), "cells and coords should have the same shape."
228
+
229
+ if len (cells .shape ) == 2 :
230
+ sys_data_copy ["cells" ] = np .array ([cells ])
231
+ sys_data_copy ["coords" ] = np .array ([coords ])
232
+ c = make_unlabeled_stru (sys_data_copy , 0 , pp_file = fp_pp_files , numerical_orbital = fp_orb_files , numerical_descriptor = fp_dpks_descriptor )
223
233
224
234
return c
225
235
@@ -236,13 +246,32 @@ def get_abacus_input_parameters(INPUT):
236
246
return input_parameters
237
247
238
248
239
- def get_abacus_STRU (STRU , INPUT = None , n_ele = None ):
240
- # read in geometry from STRU file. n_ele is the number of elements.
241
- # Either n_ele or INPUT should be provided.
249
+ def get_abacus_STRU (STRU ):
250
+ """Read STRU file and return a dictionary containing the structure information.
251
+
252
+ Args:
253
+ STRU (str): The path of STRU file.
254
+
255
+ Returns:
256
+ dict: A dictionary containing the structure information.
257
+ {
258
+ "atom_names": list of str,
259
+ "atom_numbs": list of int,
260
+ "atom_masses": list of float,
261
+ "coords": np.ndarray,
262
+ "cells": np.ndarray,
263
+ "pp_files": list of str,
264
+ "orb_files": list of str,
265
+ "dpks_descriptor": str,
266
+ }
267
+ """
242
268
data = get_frame_from_stru (STRU )
243
269
data ["atom_masses" ] = data .pop ("masses" )
244
270
data ["cells" ] = data .pop ("cells" )[0 ]
245
271
data ["coords" ] = data .pop ("coords" )[0 ]
272
+ assert "pp_files" in data , "pp_files should be provided in STRU file."
273
+ if None in data ["pp_files" ]:
274
+ data ["pp_files" ] = None
246
275
if "orb_files" not in data :
247
276
data ["orb_files" ] = None
248
277
if "dpks_descriptor" not in data :
@@ -260,7 +289,16 @@ def make_supercell_abacus(from_struct, super_cell):
260
289
# )
261
290
for idx_atm in from_struct ["atom_types" ]:
262
291
new_types += [idx_atm ] * super_cell [0 ] * super_cell [1 ] * super_cell [2 ]
263
- to_struct ["atom_types" ] = new_types
292
+ to_struct ["atom_types" ] = np .array (new_types )
293
+
294
+ # expand move, spins
295
+ for ikey in ["move" , "spins" ]:
296
+ if ikey in from_struct :
297
+ new_list = []
298
+ for ia in range (sum (from_struct ["atom_numbs" ])):
299
+ new_list += [from_struct [ikey ][0 ][ia ]] * super_cell [0 ] * super_cell [1 ] * super_cell [2 ]
300
+ to_struct [ikey ] = np .array ([new_list ])
301
+
264
302
to_atom_num = (
265
303
sum (from_struct ["atom_numbs" ]) * super_cell [0 ] * super_cell [1 ] * super_cell [2 ]
266
304
)
0 commit comments