diff --git a/dpdata/cp2k/output.py b/dpdata/cp2k/output.py index 230c3defb..ed3ab5af3 100644 --- a/dpdata/cp2k/output.py +++ b/dpdata/cp2k/output.py @@ -494,7 +494,7 @@ def get_frames(fname): atom_types = [] atom_numbs = [] # preserve the atom_name order - atom_names = atom_symbol_list[np.sort(symbol_idx)] + atom_names = atom_symbol_list[np.sort(symbol_idx, kind="stable")] for jj in atom_symbol_list: for idx, ii in enumerate(atom_names): if jj == ii: diff --git a/dpdata/lammps/dump.py b/dpdata/lammps/dump.py index cdc28bdcd..017f75a34 100644 --- a/dpdata/lammps/dump.py +++ b/dpdata/lammps/dump.py @@ -215,7 +215,9 @@ def system_data(lines, type_map=None, type_idx_zero=True, unwrap=False): system["cells"].append(cell) atype = get_atype(array_lines[ii], type_idx_zero=type_idx_zero) # map atom type; a[as[a][as[as[b]]]] = b[as[b][as^{-1}[b]]] = b[id] - idx = np.argsort(atype)[np.argsort(np.argsort(system["atom_types"]))] + idx = np.argsort(atype, kind="stable")[ + np.argsort(np.argsort(system["atom_types"], kind="stable"), kind="stable") + ] system["coords"].append( safe_get_posi(array_lines[ii], cell, np.array(orig), unwrap)[idx] ) diff --git a/dpdata/md/rdf.py b/dpdata/md/rdf.py index 219543eb3..d5409a0ce 100644 --- a/dpdata/md/rdf.py +++ b/dpdata/md/rdf.py @@ -57,7 +57,7 @@ def compute_rdf(box, posis, atype, sel_type=[None, None], max_r=5, nbins=100): def _compute_rdf_1frame(box, posis, atype, sel_type=[None, None], max_r=5, nbins=100): - all_types = list(set(list(np.sort(atype)))) + all_types = list(set(list(np.sort(atype, kind="stable")))) if sel_type[0] is None: sel_type[0] = all_types if sel_type[1] is None: diff --git a/dpdata/qe/scf.py b/dpdata/qe/scf.py index 659b18458..4457572d0 100755 --- a/dpdata/qe/scf.py +++ b/dpdata/qe/scf.py @@ -87,7 +87,7 @@ def get_coords(lines, cell): atom_types = [] atom_numbs = [] # preserve the atom_name order - atom_names = atom_symbol_list[np.sort(symbol_idx)] + atom_names = atom_symbol_list[np.sort(symbol_idx, kind="stable")] for jj in atom_symbol_list: for idx, ii in enumerate(atom_names): if jj == ii: diff --git a/dpdata/system.py b/dpdata/system.py index 743f3d057..e33ce47e9 100644 --- a/dpdata/system.py +++ b/dpdata/system.py @@ -624,7 +624,7 @@ def sort_atom_types(self) -> np.ndarray: idx : np.ndarray new atom index in the Axis.NATOMS """ - idx = np.argsort(self.data["atom_types"]) + idx = np.argsort(self.data["atom_types"], kind="stable") for tt in self.DTYPES: if tt.name not in self.data: # skip optional data @@ -767,7 +767,7 @@ def replicate(self, ncopy): np.array(np.copy(data["atom_numbs"])) * np.prod(ncopy) ) tmp.data["atom_types"] = np.sort( - np.tile(np.copy(data["atom_types"]), np.prod(ncopy)) + np.tile(np.copy(data["atom_types"]), np.prod(ncopy)), kind="stable" ) tmp.data["cells"] = np.copy(data["cells"]) for ii in range(3): diff --git a/dpdata/utils.py b/dpdata/utils.py index 55cf41ef5..da7261790 100644 --- a/dpdata/utils.py +++ b/dpdata/utils.py @@ -63,14 +63,16 @@ def sort_atom_names(data, type_map=None): # a[as[a]] == b[as[b]] as == argsort # as[as[b]] == as^{-1}[b] # a[as[a][as[as[b]]]] = b[as[b][as^{-1}[b]]] = b[id] - idx = np.argsort(data["atom_names"])[np.argsort(np.argsort(type_map))] + idx = np.argsort(data["atom_names"], kind="stable")[ + np.argsort(np.argsort(type_map, kind="stable"), kind="stable") + ] else: # index that will sort an array by alphabetical order - idx = np.argsort(data["atom_names"]) + idx = np.argsort(data["atom_names"], kind="stable") # sort atom_names, atom_numbs, atom_types by idx data["atom_names"] = list(np.array(data["atom_names"])[idx]) data["atom_numbs"] = list(np.array(data["atom_numbs"])[idx]) - data["atom_types"] = np.argsort(idx)[data["atom_types"]] + data["atom_types"] = np.argsort(idx, kind="stable")[data["atom_types"]] return data diff --git a/tests/poscars/POSCAR.P42nmc.replace b/tests/poscars/POSCAR.P42nmc.replace index e785d1286..5dd05d848 100644 --- a/tests/poscars/POSCAR.P42nmc.replace +++ b/tests/poscars/POSCAR.P42nmc.replace @@ -6,99 +6,99 @@ Hf24 O64 Zr8 Hf O Zr 24 64 8 Cartesian - 0.0000000000 0.0000000000 0.0000000000 - 7.5009600000 7.5009600000 5.0819200000 - 7.5009600000 7.5009600000 0.0000000000 - 7.5009600000 2.5003200000 10.1638400000 - 2.5003200000 7.5009600000 5.0819200000 - 2.5003200000 7.5009600000 10.1638400000 - 2.5003200000 2.5003200000 5.0819200000 - 2.5003200000 2.5003200000 10.1638400000 - 5.0006400000 2.5003200000 7.6228800000 - 10.0012800000 7.5009600000 2.5409600000 - 0.0000000000 2.5003200000 7.6228800000 - 0.0000000000 2.5003200000 2.5409600000 - 7.5009600000 5.0006400000 7.6228800000 - 7.5009600000 5.0006400000 2.5409600000 - 10.0012800000 7.5009600000 7.6228800000 - 7.5009600000 0.0000000000 2.5409600000 - 0.0000000000 0.0000000000 5.0819200000 - 0.0000000000 5.0006400000 5.0819200000 - 7.5009600000 0.0000000000 7.6228800000 - 5.0006400000 0.0000000000 5.0819200000 - 2.5003200000 0.0000000000 2.5409600000 - 5.0006400000 0.0000000000 10.1638400000 - 2.5003200000 0.0000000000 7.6228800000 - 2.5003200000 5.0006400000 7.6228800000 - 1.2501600000 8.7511200000 1.0558196992 - 1.2501600000 8.7511200000 3.5967796992 - 1.2501600000 3.7504800000 8.6786996992 - 1.2501600000 3.7504800000 3.5967796992 - 6.2508000000 8.7511200000 6.1377396992 - 6.2508000000 8.7511200000 1.0558196992 - 6.2508000000 3.7504800000 6.1377396992 - 8.7511200000 1.2501600000 8.6786996992 - 6.2508000000 3.7504800000 1.0558196992 - 1.2501600000 3.7504800000 1.0558196992 - 1.2501600000 8.7511200000 8.6786996992 - 8.7511200000 6.2508000000 3.5967796992 - 8.7511200000 6.2508000000 8.6786996992 - 1.2501600000 8.7511200000 6.1377396992 - 1.2501600000 3.7504800000 6.1377396992 - 6.2508000000 3.7504800000 3.5967796992 - 6.2508000000 6.2508000000 1.4851403008 - 6.2508000000 8.7511200000 3.5967796992 - 6.2508000000 1.2501600000 9.1080203008 - 6.2508000000 1.2501600000 4.0261003008 - 1.2501600000 6.2508000000 9.1080203008 - 1.2501600000 6.2508000000 4.0261003008 - 1.2501600000 1.2501600000 9.1080203008 - 1.2501600000 1.2501600000 4.0261003008 - 6.2508000000 6.2508000000 6.5670603008 - 8.7511200000 1.2501600000 3.5967796992 - 6.2508000000 1.2501600000 6.5670603008 - 6.2508000000 1.2501600000 1.4851403008 - 1.2501600000 6.2508000000 6.5670603008 - 1.2501600000 6.2508000000 1.4851403008 - 1.2501600000 1.2501600000 6.5670603008 - 1.2501600000 1.2501600000 1.4851403008 - 6.2508000000 8.7511200000 8.6786996992 - 6.2508000000 3.7504800000 8.6786996992 - 3.7504800000 6.2508000000 8.6786996992 - 8.7511200000 8.7511200000 9.1080203008 - 3.7504800000 1.2501600000 8.6786996992 - 3.7504800000 3.7504800000 1.4851403008 - 3.7504800000 3.7504800000 6.5670603008 - 3.7504800000 8.7511200000 1.4851403008 - 3.7504800000 8.7511200000 6.5670603008 - 8.7511200000 3.7504800000 1.4851403008 - 8.7511200000 3.7504800000 6.5670603008 - 8.7511200000 8.7511200000 1.4851403008 - 8.7511200000 8.7511200000 6.5670603008 - 3.7504800000 6.2508000000 3.5967796992 - 3.7504800000 3.7504800000 9.1080203008 - 3.7504800000 8.7511200000 4.0261003008 - 3.7504800000 8.7511200000 9.1080203008 - 3.7504800000 3.7504800000 4.0261003008 - 8.7511200000 3.7504800000 9.1080203008 - 3.7504800000 1.2501600000 3.5967796992 - 8.7511200000 3.7504800000 4.0261003008 - 8.7511200000 6.2508000000 1.0558196992 - 8.7511200000 1.2501600000 6.1377396992 - 8.7511200000 1.2501600000 1.0558196992 - 8.7511200000 6.2508000000 6.1377396992 - 3.7504800000 6.2508000000 1.0558196992 - 3.7504800000 1.2501600000 6.1377396992 - 3.7504800000 1.2501600000 1.0558196992 - 6.2508000000 6.2508000000 4.0261003008 - 8.7511200000 8.7511200000 4.0261003008 - 3.7504800000 6.2508000000 6.1377396992 - 6.2508000000 6.2508000000 9.1080203008 - 7.5009600000 2.5003200000 5.0819200000 - 5.0006400000 7.5009600000 7.6228800000 - 5.0006400000 7.5009600000 2.5409600000 - 5.0006400000 2.5003200000 2.5409600000 - 2.5003200000 5.0006400000 2.5409600000 - 5.0006400000 5.0006400000 5.0819200000 - 5.0006400000 5.0006400000 10.1638400000 - 0.0000000000 5.0006400000 10.1638400000 +0.000000 0.000000 0.000000 +0.000000 0.000000 5.081920 +0.000000 5.000640 5.081920 +5.000640 0.000000 10.163840 +5.000640 0.000000 5.081920 +2.500320 0.000000 2.540960 +2.500320 0.000000 7.622880 +2.500320 5.000640 7.622880 +7.500960 0.000000 2.540960 +7.500960 0.000000 7.622880 +7.500960 5.000640 2.540960 +7.500960 5.000640 7.622880 +0.000000 2.500320 2.540960 +0.000000 2.500320 7.622880 +10.001280 7.500960 2.540960 +10.001280 7.500960 7.622880 +5.000640 2.500320 7.622880 +2.500320 2.500320 10.163840 +2.500320 2.500320 5.081920 +2.500320 7.500960 10.163840 +2.500320 7.500960 5.081920 +7.500960 2.500320 10.163840 +7.500960 7.500960 0.000000 +7.500960 7.500960 5.081920 +3.750480 3.750480 1.485140 +3.750480 3.750480 6.567060 +3.750480 8.751120 1.485140 +3.750480 8.751120 6.567060 +8.751120 3.750480 1.485140 +8.751120 3.750480 6.567060 +8.751120 8.751120 1.485140 +8.751120 8.751120 6.567060 +3.750480 3.750480 4.026100 +3.750480 3.750480 9.108020 +3.750480 8.751120 4.026100 +3.750480 8.751120 9.108020 +8.751120 3.750480 4.026100 +8.751120 3.750480 9.108020 +8.751120 8.751120 4.026100 +8.751120 8.751120 9.108020 +3.750480 1.250160 1.055820 +3.750480 1.250160 6.137740 +3.750480 6.250800 1.055820 +3.750480 6.250800 6.137740 +8.751120 1.250160 1.055820 +8.751120 1.250160 6.137740 +8.751120 6.250800 1.055820 +8.751120 6.250800 6.137740 +3.750480 1.250160 3.596780 +3.750480 1.250160 8.678700 +3.750480 6.250800 3.596780 +3.750480 6.250800 8.678700 +8.751120 1.250160 3.596780 +8.751120 1.250160 8.678700 +8.751120 6.250800 3.596780 +8.751120 6.250800 8.678700 +1.250160 3.750480 1.055820 +1.250160 3.750480 6.137740 +1.250160 8.751120 1.055820 +1.250160 8.751120 6.137740 +6.250800 3.750480 1.055820 +6.250800 3.750480 6.137740 +6.250800 8.751120 1.055820 +6.250800 8.751120 6.137740 +1.250160 3.750480 3.596780 +1.250160 3.750480 8.678700 +1.250160 8.751120 3.596780 +1.250160 8.751120 8.678700 +6.250800 3.750480 3.596780 +6.250800 3.750480 8.678700 +6.250800 8.751120 3.596780 +6.250800 8.751120 8.678700 +1.250160 1.250160 1.485140 +1.250160 1.250160 6.567060 +1.250160 6.250800 1.485140 +1.250160 6.250800 6.567060 +6.250800 1.250160 1.485140 +6.250800 1.250160 6.567060 +6.250800 6.250800 1.485140 +6.250800 6.250800 6.567060 +1.250160 1.250160 4.026100 +1.250160 1.250160 9.108020 +1.250160 6.250800 4.026100 +1.250160 6.250800 9.108020 +6.250800 1.250160 4.026100 +6.250800 1.250160 9.108020 +6.250800 6.250800 4.026100 +6.250800 6.250800 9.108020 +0.000000 5.000640 10.163840 +5.000640 5.000640 10.163840 +5.000640 5.000640 5.081920 +2.500320 5.000640 2.540960 +5.000640 2.500320 2.540960 +5.000640 7.500960 2.540960 +5.000640 7.500960 7.622880 +7.500960 2.500320 5.081920