From c3e9292dc97586ef497d36bf682f2ca7c3438d28 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 21 Mar 2021 20:34:25 -0400 Subject: [PATCH 1/5] fix bugs of ase calculator and add tests --- source/tests/test_deeppot_a.py | 14 ++++++++++++++ source/train/calculator.py | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/source/tests/test_deeppot_a.py b/source/tests/test_deeppot_a.py index 8541cb8fa3..6f8c800d16 100644 --- a/source/tests/test_deeppot_a.py +++ b/source/tests/test_deeppot_a.py @@ -324,4 +324,18 @@ def test_1frame_atm(self): for ii in range(nframes, 9): self.assertAlmostEqual(vv.reshape([-1])[ii], expected_sv.reshape([-1])[ii], places = default_places) + def test_ase(self): + from ase import Atoms + from deepmd.calculator import DP + water = Atoms('OHHOHH', + positions=self.coords.reshape((-1,3)), + cell=self.box.reshpae((3,3)), + calculator=self.dp) + ee = water.get_potential_energy() + ff = water.get_forces() + for ii in range(ff.size): + self.assertAlmostEqual(ff.reshape([-1])[ii], self.expected_f.reshape([-1])[ii], places = default_places) + expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis = 1) + for ii in range(nframes): + self.assertAlmostEqual(ee.reshape([-1])[ii], expected_se.reshape([-1])[ii], places = default_places) diff --git a/source/train/calculator.py b/source/train/calculator.py index e9c8e63c7d..b70305a26c 100644 --- a/source/train/calculator.py +++ b/source/train/calculator.py @@ -62,7 +62,7 @@ def __init__( **kwargs ) -> None: Calculator.__init__(self, label=label, **kwargs) - self.dp = DeepPot(str(Path(model).resolve())) + self.dp = DeepPotential(str(Path(model).resolve())) if type_dict: self.type_dict = type_dict else: From 373349c231da586b3830e8df5938f79645df2dc6 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 21 Mar 2021 20:37:06 -0400 Subject: [PATCH 2/5] add ase to tests --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index cf83e4955f..729d62650d 100644 --- a/setup.py +++ b/setup.py @@ -104,7 +104,7 @@ cmake_source_dir="source", cmake_minimum_required_version="3.0", extras_require={ - "test": ["dpdata>=0.1.9", "pytest", "pytest-cov", "pytest-sugar"], + "test": ["dpdata>=0.1.9", "ase", "pytest", "pytest-cov", "pytest-sugar"], "docs": ["sphinx", "recommonmark", "sphinx_rtd_theme"], **extras_require, }, From c5eef2f8182b0e858059b467989e541afc1abeb6 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 21 Mar 2021 21:03:56 -0400 Subject: [PATCH 3/5] fix typo --- source/tests/test_deeppot_a.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/tests/test_deeppot_a.py b/source/tests/test_deeppot_a.py index 6f8c800d16..ed24fa5875 100644 --- a/source/tests/test_deeppot_a.py +++ b/source/tests/test_deeppot_a.py @@ -329,7 +329,7 @@ def test_ase(self): from deepmd.calculator import DP water = Atoms('OHHOHH', positions=self.coords.reshape((-1,3)), - cell=self.box.reshpae((3,3)), + cell=self.box.reshape((3,3)), calculator=self.dp) ee = water.get_potential_energy() ff = water.get_forces() From d5354fdd383ecb8e8589fbb4762407232b05641c Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 21 Mar 2021 21:19:57 -0400 Subject: [PATCH 4/5] fix bug --- source/tests/test_deeppot_a.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/tests/test_deeppot_a.py b/source/tests/test_deeppot_a.py index ed24fa5875..f4e73682f3 100644 --- a/source/tests/test_deeppot_a.py +++ b/source/tests/test_deeppot_a.py @@ -330,9 +330,10 @@ def test_ase(self): water = Atoms('OHHOHH', positions=self.coords.reshape((-1,3)), cell=self.box.reshape((3,3)), - calculator=self.dp) + calculator=DP("deeppot.pb")) ee = water.get_potential_energy() ff = water.get_forces() + nframes = 1 for ii in range(ff.size): self.assertAlmostEqual(ff.reshape([-1])[ii], self.expected_f.reshape([-1])[ii], places = default_places) expected_se = np.sum(self.expected_e.reshape([nframes, -1]), axis = 1) From c7475d731347c2e9921a9f5afbf8d327b3b8bdbf Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Mon, 22 Mar 2021 23:30:25 -0400 Subject: [PATCH 5/5] import Path for runtime --- source/train/calculator.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/train/calculator.py b/source/train/calculator.py index b70305a26c..7ca7943d7a 100644 --- a/source/train/calculator.py +++ b/source/train/calculator.py @@ -1,13 +1,12 @@ """ASE calculator interface module.""" from typing import TYPE_CHECKING, Dict, List, Optional, Union +from pathlib import Path from deepmd import DeepPotential from ase.calculators.calculator import Calculator, all_changes if TYPE_CHECKING: - from pathlib import Path - from ase import Atoms __all__ = ["DP"]