Skip to content

Commit 3fc4957

Browse files
author
root
committed
fix ut
1 parent cb3b34a commit 3fc4957

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

dpgen/data/gen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def stru_ele(supercell_stru, stru_out, eles, natoms, jdata, path_work):
145145
dpks_descriptor_name = os.path.basename(jdata["dpks_descriptor"])
146146
supercell_stru["atom_masses"] = jdata["atom_masses"]
147147
supercell_stru["atom_names"] = eles
148+
supercell_stru["atom_types"] = np.array(supercell_stru["types"])
148149
stru_text = make_abacus_scf_stru(
149150
supercell_stru,
150151
pp_file_names,

dpgen/data/tools/create_random_disturb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def create_disturbs_abacus_dev(
192192
stru = get_abacus_STRU(fin)
193193
natoms = sum(stru["atom_numbs"])
194194
cell0 = stru["cells"]
195+
stru["masses"] = stru["atom_masses"] # in dpdata, it is masses that should be used.
195196

196197
# creat nfile ofmt files.
197198
for fid in range(1, nfile + 1):

dpgen/generator/lib/abacus_scf.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,24 @@ def make_abacus_scf_stru(
212212
type_map=None,
213213
pporb="", # pull all pp orb dpks files to pporb folder
214214
):
215+
sys_data_copy = copy.deepcopy(sys_data)
215216
# re-construct the path of files by pporb + file name
216217
fp_pp_files = [os.path.join(pporb, i) for i in fp_pp_files]
217218
if fp_orb_files is not None:
218219
fp_orb_files = [os.path.join(pporb, i) for i in fp_orb_files]
219220
if fp_dpks_descriptor is not None:
220221
fp_dpks_descriptor = os.path.join(pporb, fp_dpks_descriptor)
221222

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)
223233

224234
return c
225235

@@ -236,13 +246,32 @@ def get_abacus_input_parameters(INPUT):
236246
return input_parameters
237247

238248

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+
"""
242268
data = get_frame_from_stru(STRU)
243269
data["atom_masses"] = data.pop("masses")
244270
data["cells"] = data.pop("cells")[0]
245271
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
246275
if "orb_files" not in data:
247276
data["orb_files"] = None
248277
if "dpks_descriptor" not in data:
@@ -260,7 +289,16 @@ def make_supercell_abacus(from_struct, super_cell):
260289
# )
261290
for idx_atm in from_struct["atom_types"]:
262291
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+
264302
to_atom_num = (
265303
sum(from_struct["atom_numbs"]) * super_cell[0] * super_cell[1] * super_cell[2]
266304
)

tests/data/test_gen_bulk_abacus.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def test(self):
7676
def testSTRU(self):
7777
jdata = self.jdata
7878
jdata["from_poscar_path"] = "./Cu.STRU"
79+
jdata["potcars"] = ["abacus.in/Cu_ONCV_PBE-1.0.upf"]
7980
make_super_cell_STRU(jdata)
8081
make_abacus_relax(jdata, {"fp_resources": {}})
8182
make_scale_ABACUS(jdata)

0 commit comments

Comments
 (0)