Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion deepmd/entrypoints/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ def test(

# create data class
tmap = dp.get_type_map() if dp.model_type == "ener" else None
data = DeepmdData(system, set_prefix, shuffle_test=shuffle_test, type_map=tmap)
data = DeepmdData(
system,
set_prefix,
shuffle_test=shuffle_test,
type_map=tmap,
sort_atoms=False,
)

if dp.model_type == "ener":
err = test_ener(
Expand Down
10 changes: 9 additions & 1 deletion deepmd/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class DeepmdData:
Data modifier that has the method `modify_data`
trn_all_set
Use all sets as training dataset. Otherwise, if the number of sets is more than 1, the last set is left for test.
sort_atoms : bool
Sort atoms by atom types. Required to enable when the data is directly feeded to
descriptors except mixed types.
"""

def __init__(
Expand All @@ -53,6 +56,7 @@ def __init__(
optional_type_map: bool = True,
modifier=None,
trn_all_set: bool = False,
sort_atoms: bool = True,
):
"""Constructor."""
root = DPPath(sys_path)
Expand Down Expand Up @@ -102,6 +106,7 @@ def __init__(
if type_map is None and self.type_map is None and self.mixed_type:
raise RuntimeError("mixed_type format must have type_map!")
# make idx map
self.sort_atoms = sort_atoms
self.idx_map = self._make_idx_map(self.atom_type)
# train dirs
self.test_dir = self.dirs[-1]
Expand Down Expand Up @@ -586,7 +591,10 @@ def _load_type_mix(self, set_name: DPPath):
def _make_idx_map(self, atom_type):
natoms = atom_type.shape[0]
idx = np.arange(natoms)
idx_map = np.lexsort((idx, atom_type))
if self.sort_atoms:
idx_map = np.lexsort((idx, atom_type))
else:
idx_map = idx
return idx_map

def _load_type_map(self, sys_path: DPPath):
Expand Down
7 changes: 6 additions & 1 deletion deepmd/utils/data_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(
trn_all_set=False,
sys_probs=None,
auto_prob_style="prob_sys_size",
sort_atoms: bool = True,
):
"""Constructor.

Expand Down Expand Up @@ -84,7 +85,10 @@ def __init__(
the list of systems is devided into blocks. A block is specified by `stt_idx:end_idx:weight`,
where `stt_idx` is the starting index of the system, `end_idx` is then ending (not including) index of the system,
the probabilities of the systems in this block sums up to `weight`, and the relatively probabilities within this block is proportional
to the number of batches in the system.
to the number of batches in the system.
sort_atoms : bool
Sort atoms by atom types. Required to enable when the data is directly feeded to
descriptors except mixed types.
"""
# init data
self.rcut = rcut
Expand All @@ -101,6 +105,7 @@ def __init__(
optional_type_map=optional_type_map,
modifier=modifier,
trn_all_set=trn_all_set,
sort_atoms=sort_atoms,
)
)
# check mix_type format
Expand Down
4 changes: 1 addition & 3 deletions source/tests/test_dp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,16 +180,14 @@ def test_1frame(self):
detail_file=detail_file,
atomic=False,
)
# TODO: see #2721
idx_map = np.lexsort((np.arange(len(self.atype)), self.atype))
pred_e = np.loadtxt(detail_file + ".e.out", ndmin=2)[0, 1]
pred_f = np.loadtxt(detail_file + ".f.out", ndmin=2)[:, 3:6]
pred_v = np.loadtxt(detail_file + ".v.out", ndmin=2)[:, 9:18]
pred_e_peratom = np.loadtxt(detail_file + ".e_peratom.out", ndmin=2)[0, 1]
pred_v_peratom = np.loadtxt(detail_file + ".v_peratom.out", ndmin=2)[:, 9:18]
self.assertAlmostEqual(pred_e, np.sum(self.expected_e), places=default_places)
np.testing.assert_almost_equal(
pred_f, self.expected_f.reshape(-1, 3)[idx_map], decimal=default_places
pred_f, self.expected_f.reshape(-1, 3), decimal=default_places
)
np.testing.assert_almost_equal(
pred_v,
Expand Down