From a3badfdab83152ee4948a394d1c39467b83ff2fc Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 12 Aug 2021 16:45:37 -0400 Subject: [PATCH 1/5] rename for cherry-pick --- {deepmd => source/train}/calculator.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {deepmd => source/train}/calculator.py (100%) diff --git a/deepmd/calculator.py b/source/train/calculator.py similarity index 100% rename from deepmd/calculator.py rename to source/train/calculator.py From afec13f7d39f4e93b905863704bc064d938b10b4 Mon Sep 17 00:00:00 2001 From: hsulab Date: Fri, 29 Jan 2021 22:49:07 +0000 Subject: [PATCH 2/5] fix an error in stress by ase interface (cherry picked from commit a24971f699cc71d577c19f0bf590b9b87194a97a) --- source/train/calculator.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/source/train/calculator.py b/source/train/calculator.py index 7ca7943d7a..3cf6be2049 100644 --- a/source/train/calculator.py +++ b/source/train/calculator.py @@ -4,7 +4,9 @@ from pathlib import Path from deepmd import DeepPotential -from ase.calculators.calculator import Calculator, all_changes +from ase.calculators.calculator import ( + Calculator, all_changes, PropertyNotImplementedError +) if TYPE_CHECKING: from ase import Atoms @@ -51,7 +53,7 @@ class DP(Calculator): """ name = "DP" - implemented_properties = ["energy", "forces", "stress"] + implemented_properties = ["energy", "forces", "virial", "stress"] def __init__( self, @@ -72,7 +74,7 @@ def __init__( def calculate( self, atoms: Optional["Atoms"] = None, - properties: List[str] = ["energy", "forces", "stress"], + properties: List[str] = ["energy", "forces", "virial"], system_changes: List[str] = all_changes, ): """Run calculation with deepmd model. @@ -98,6 +100,17 @@ def calculate( symbols = self.atoms.get_chemical_symbols() atype = [self.type_dict[k] for k in symbols] e, f, v = self.dp.eval(coords=coord, cells=cell, atom_types=atype) - self.results["energy"] = e[0] - self.results["forces"] = f[0] - self.results["stress"] = v[0] + self.results['energy'] = e[0][0] + self.results['forces'] = f[0] + self.results['virial'] = v[0].reshape(3,3) + + # convert virial into stress for lattice relaxation + if "stress" in properties: + if sum(atoms.get_pbc()) > 0: + # the usual convention (tensile stress is positive) + # stress = -virial / volume + stress = -0.5*(v[0].copy()+v[0].copy().T) / atoms.get_volume() + # Voigt notation + self.results['stress'] = stress.flat[[0,4,8,5,2,1]] + else: + raise PropertyNotImplementedError From 92f453a44bfc32dce581b8debc7a7bec8eb5356c Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 12 Aug 2021 16:48:51 -0400 Subject: [PATCH 3/5] move back --- {source/train => deepmd}/calculator.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {source/train => deepmd}/calculator.py (100%) diff --git a/source/train/calculator.py b/deepmd/calculator.py similarity index 100% rename from source/train/calculator.py rename to deepmd/calculator.py From 0b02cceaa3912a18c833b73844539db729f3dd5c Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 12 Aug 2021 18:38:25 -0400 Subject: [PATCH 4/5] fix lint error --- deepmd/calculator.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deepmd/calculator.py b/deepmd/calculator.py index 3cf6be2049..615881f850 100644 --- a/deepmd/calculator.py +++ b/deepmd/calculator.py @@ -1,13 +1,14 @@ """ASE calculator interface module.""" -from typing import TYPE_CHECKING, Dict, List, Optional, Union from pathlib import Path +from typing import TYPE_CHECKING, Dict, List, Optional, Union -from deepmd import DeepPotential from ase.calculators.calculator import ( Calculator, all_changes, PropertyNotImplementedError ) +from deepmd import DeepPotential + if TYPE_CHECKING: from ase import Atoms From e8ccd40fe5ed16dd875ff050e7ad68394dc6e6f9 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Thu, 12 Aug 2021 18:39:43 -0400 Subject: [PATCH 5/5] fix lint warnings --- deepmd/calculator.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deepmd/calculator.py b/deepmd/calculator.py index 615881f850..25dc7fd5ee 100644 --- a/deepmd/calculator.py +++ b/deepmd/calculator.py @@ -103,15 +103,15 @@ def calculate( e, f, v = self.dp.eval(coords=coord, cells=cell, atom_types=atype) self.results['energy'] = e[0][0] self.results['forces'] = f[0] - self.results['virial'] = v[0].reshape(3,3) + self.results['virial'] = v[0].reshape(3, 3) # convert virial into stress for lattice relaxation if "stress" in properties: if sum(atoms.get_pbc()) > 0: # the usual convention (tensile stress is positive) # stress = -virial / volume - stress = -0.5*(v[0].copy()+v[0].copy().T) / atoms.get_volume() - # Voigt notation - self.results['stress'] = stress.flat[[0,4,8,5,2,1]] + stress = -0.5 * (v[0].copy() + v[0].copy().T) / atoms.get_volume() + # Voigt notation + self.results['stress'] = stress.flat[[0, 4, 8, 5, 2, 1]] else: raise PropertyNotImplementedError