forked from deepmodeling/deepmd-kit
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_descriptor_dpa1.py
38 lines (31 loc) · 1.06 KB
/
test_descriptor_dpa1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# SPDX-License-Identifier: LGPL-3.0-or-later
import unittest
import numpy as np
from deepmd.dpmodel.descriptor import (
DescrptDPA1,
)
from ...seed import (
GLOBAL_SEED,
)
from .case_single_frame_with_nlist import (
TestCaseSingleFrameWithNlist,
)
class TestDescrptDPA1(unittest.TestCase, TestCaseSingleFrameWithNlist):
def setUp(self):
TestCaseSingleFrameWithNlist.setUp(self)
def test_self_consistency(
self,
):
rng = np.random.default_rng(GLOBAL_SEED)
nf, nloc, nnei = self.nlist.shape
davg = rng.normal(size=(self.nt, nnei, 4))
dstd = rng.normal(size=(self.nt, nnei, 4))
dstd = 0.1 + np.abs(dstd)
em0 = DescrptDPA1(self.rcut, self.rcut_smth, self.sel, ntypes=2)
em0.davg = davg
em0.dstd = dstd
em1 = DescrptDPA1.deserialize(em0.serialize())
mm0 = em0.call(self.coord_ext, self.atype_ext, self.nlist)
mm1 = em1.call(self.coord_ext, self.atype_ext, self.nlist)
for ii in [0, 1, 4]:
np.testing.assert_allclose(mm0[ii], mm1[ii])