Skip to content

Commit 5a84796

Browse files
authored
Merge pull request #1177 from deepmodeling/devel
Merge recent development on devel into master
2 parents 2f6020b + 5843c02 commit 5a84796

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+25686
-11619
lines changed

.github/workflows/mirror_gitee.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ concurrency:
88

99
jobs:
1010
git-mirror:
11+
if: github.repository_owner == 'deepmodeling'
1112
runs-on: ubuntu-latest
1213
steps:
1314
- uses: wearerequired/git-mirror-action@v1
1415
env:
1516
SSH_PRIVATE_KEY: ${{ secrets.SYNC_GITEE_PRIVATE_KEY }}
1617
with:
17-
source-repo: "git@github.com:deepmodeling/deepmd-kit.git"
18+
source-repo: "https://github.com/deepmodeling/deepmd-kit.git"
1819
destination-repo: "[email protected]:deepmodeling/deepmd-kit.git"

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ API_CC
3030
doc/api_py/
3131
dp/
3232
build_lammps/
33+
.idea/
3334
build_tests/
3435
build_cc_tests

.readthedocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version: 2
2+
conda:
3+
environment: doc/environment.yml

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Please follow our [GitHub](https://github.com/deepmodeling/deepmd-kit) webpage t
6060

6161
DeePMD-kit offers multiple installation methods. It is recommend using easily methods like [offline packages](doc/install/easy-install.md#offline-packages), [conda](doc/install/easy-install.md#with-conda) and [docker](doc/install/easy-install.md#with-docker).
6262

63-
One may manually install DeePMD-kit by following the instuctions on [installing the Python interface](doc/install/install-from-source.md#install-the-python-interface) and [installing the C++ interface](doc/install/install-from-source.md#install-the-c-interface). The C++ interface is necessary when using DeePMD-kit with LAMMPS and i-PI.
63+
One may manually install DeePMD-kit by following the instuctions on [installing the Python interface](doc/install/install-from-source.md#install-the-python-interface) and [installing the C++ interface](doc/install/install-from-source.md#install-the-c-interface). The C++ interface is necessary when using DeePMD-kit with LAMMPS, i-PI or GROMACS.
6464

6565

6666
# Use DeePMD-kit
@@ -71,7 +71,7 @@ A quick-start on using DeePMD-kit can be found as follows:
7171
- [Training a model](doc/train/training.md)
7272
- [Freeze a model](doc/freeze/freeze.md)
7373
- [Test a model](doc/test/test.md)
74-
- [Running MD with LAMMPS](doc/third-party/lammps.md)
74+
- [Run MD with LAMMPS](doc/third-party/lammps.md)
7575

7676
A full [document](doc/train/train-input-auto.rst) on options in the training input script is available.
7777

@@ -82,6 +82,7 @@ A full [document](doc/train/train-input-auto.rst) on options in the training inp
8282
- [Install from source code](doc/install/install-from-source.md)
8383
- [Install LAMMPS](doc/install/install-lammps.md)
8484
- [Install i-PI](doc/install/install-ipi.md)
85+
- [Install GROMACS](doc/install/install-gromacs.md)
8586
- [Building conda packages](doc/install/build-conda.md)
8687
- [Data](doc/data/index.md)
8788
- [Data conversion](doc/data/data-conv.md)
@@ -113,10 +114,10 @@ A full [document](doc/train/train-input-auto.rst) on options in the training inp
113114
- [C++ interface](doc/inference/cxx.md)
114115
- [Integrate with third-party packages](doc/third-party/index.rst)
115116
- [Use deep potential with ASE](doc/third-party/ase.md)
116-
- [Running MD with LAMMPS](doc/third-party/lammps.md)
117+
- [Run MD with LAMMPS](doc/third-party/lammps.md)
117118
- [LAMMPS commands](doc/third-party/lammps-command.md)
118119
- [Run path-integral MD with i-PI](doc/third-party/ipi.md)
119-
120+
- [Run MD with GROMACS](doc/third-party/gromacs.md)
120121

121122
# Code structure
122123
The code is organized as follows:
@@ -135,6 +136,8 @@ The code is organized as follows:
135136

136137
* `source/lmp`: source code of Lammps module.
137138

139+
* `source/gmx`: source code of Gromacs plugin.
140+
138141
* `source/op`: tensorflow op implementation. working with library.
139142

140143

deepmd/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""Root of the deepmd package, exposes all public classes and submodules."""
22

3+
try:
4+
from importlib import metadata
5+
except ImportError: # for Python<3.8
6+
import importlib_metadata as metadata
37
import deepmd.utils.network as network
48

59
from . import cluster, descriptor, fit, loss, utils
@@ -14,6 +18,10 @@
1418
except ImportError:
1519
from .__about__ import __version__
1620

21+
# load third-party plugins
22+
for ep in metadata.entry_points().get('deepmd', []):
23+
ep.load()
24+
1725
__all__ = [
1826
"descriptor",
1927
"fit",

deepmd/common.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from deepmd.env import GLOBAL_TF_FLOAT_PRECISION, GLOBAL_NP_FLOAT_PRECISION
2424
from deepmd.utils.sess import run_sess
2525
from deepmd.utils.errors import GraphWithoutTensorError
26+
from deepmd.utils.path import DPPath
2627

2728
if TYPE_CHECKING:
2829
_DICT_VAL = TypeVar("_DICT_VAL")
@@ -429,9 +430,10 @@ def expand_sys_str(root_dir: Union[str, Path]) -> List[str]:
429430
List[str]
430431
list of string pointing to system directories
431432
"""
432-
matches = [str(d) for d in Path(root_dir).rglob("*") if (d / "type.raw").is_file()]
433-
if (Path(root_dir) / "type.raw").is_file():
434-
matches += [root_dir]
433+
root_dir = DPPath(root_dir)
434+
matches = [str(d) for d in root_dir.rglob("*") if (d / "type.raw").is_file()]
435+
if (root_dir / "type.raw").is_file():
436+
matches.append(str(root_dir))
435437
return matches
436438

437439

deepmd/descriptor/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
from .descriptor import Descriptor
12
from .hybrid import DescrptHybrid
23
from .se_a import DescrptSeA
34
from .se_r import DescrptSeR
4-
from .se_ar import DescrptSeAR
55
from .se_t import DescrptSeT
66
from .se_a_ebd import DescrptSeAEbd
77
from .se_a_ef import DescrptSeAEf

deepmd/descriptor/descriptor.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,64 @@
33

44
import numpy as np
55
from deepmd.env import tf
6+
from deepmd.utils import Plugin, PluginVariant
67

78

8-
class Descriptor(ABC):
9+
class Descriptor(PluginVariant):
910
r"""The abstract class for descriptors. All specific descriptors should
1011
be based on this class.
1112
1213
The descriptor :math:`\mathcal{D}` describes the environment of an atom,
1314
which should be a function of coordinates and types of its neighbour atoms.
1415
16+
Examples
17+
--------
18+
>>> descript = Descriptor(type="se_e2_a", rcut=6., rcut_smth=0.5, sel=[50])
19+
>>> type(descript)
20+
<class 'deepmd.descriptor.se_a.DescrptSeA'>
21+
1522
Notes
1623
-----
1724
Only methods and attributes defined in this class are generally public,
1825
that can be called by other classes.
1926
"""
2027

28+
__plugins = Plugin()
29+
30+
@staticmethod
31+
def register(key: str) -> "Descriptor":
32+
"""Regiester a descriptor plugin.
33+
34+
Parameters
35+
----------
36+
key : str
37+
the key of a descriptor
38+
39+
Returns
40+
-------
41+
Descriptor
42+
the regiestered descriptor
43+
44+
Examples
45+
--------
46+
>>> @Descriptor.register("some_descrpt")
47+
class SomeDescript(Descriptor):
48+
pass
49+
"""
50+
return Descriptor.__plugins.register(key)
51+
52+
def __new__(cls, *args, **kwargs):
53+
if cls is Descriptor:
54+
try:
55+
descrpt_type = kwargs['type']
56+
except KeyError:
57+
raise KeyError('the type of descriptor should be set by `type`')
58+
if descrpt_type in Descriptor.__plugins.plugins:
59+
cls = Descriptor.__plugins.plugins[descrpt_type]
60+
else:
61+
raise RuntimeError('Unknown descriptor type: ' + descrpt_type)
62+
return super().__new__(cls)
63+
2164
@abstractmethod
2265
def get_rcut(self) -> float:
2366
"""

deepmd/descriptor/hybrid.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
from .descriptor import Descriptor
1616
from .se_a import DescrptSeA
1717
from .se_r import DescrptSeR
18-
from .se_ar import DescrptSeAR
1918
from .se_t import DescrptSeT
2019
from .se_a_ebd import DescrptSeAEbd
2120
from .se_a_ef import DescrptSeAEf
2221
from .loc_frame import DescrptLocFrame
2322

23+
@Descriptor.register("hybrid")
2424
class DescrptHybrid (Descriptor):
2525
"""Concate a list of descriptors to form a new descriptor.
2626
@@ -37,11 +37,19 @@ def __init__ (self,
3737
"""
3838
if descrpt_list == [] or descrpt_list is None:
3939
raise RuntimeError('cannot build descriptor from an empty list of descriptors.')
40+
formatted_descript_list = []
41+
for ii in descrpt_list:
42+
if isinstance(ii, Descriptor):
43+
formatted_descript_list.append(ii)
44+
elif isinstance(ii, dict):
45+
formatted_descript_list.append(Descriptor(**ii))
46+
else:
47+
raise NotImplementedError
4048
# args = ClassArg()\
4149
# .add('list', list, must = True)
4250
# class_data = args.parse(jdata)
4351
# dict_list = class_data['list']
44-
self.descrpt_list = descrpt_list
52+
self.descrpt_list = formatted_descript_list
4553
self.numb_descrpt = len(self.descrpt_list)
4654
for ii in range(1, self.numb_descrpt):
4755
assert(self.descrpt_list[ii].get_ntypes() ==

deepmd/descriptor/se.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
from typing import Tuple, List
2+
3+
from deepmd.env import tf
4+
from deepmd.utils.graph import get_embedding_net_variables
5+
from .descriptor import Descriptor
6+
7+
8+
class DescrptSe (Descriptor):
9+
"""A base class for smooth version of descriptors.
10+
11+
Notes
12+
-----
13+
All of these descriptors have an environmental matrix and an
14+
embedding network (:meth:`deepmd.utils.network.embedding_net`), so
15+
they can share some similiar methods without defining them twice.
16+
17+
Attributes
18+
----------
19+
embedding_net_variables : dict
20+
initial embedding network variables
21+
descrpt_reshape : tf.Tensor
22+
the reshaped descriptor
23+
descrpt_deriv : tf.Tensor
24+
the descriptor derivative
25+
rij : tf.Tensor
26+
distances between two atoms
27+
nlist : tf.Tensor
28+
the neighbor list
29+
30+
"""
31+
def _identity_tensors(self, suffix : str = "") -> None:
32+
"""Identify tensors which are expected to be stored and restored.
33+
34+
Notes
35+
-----
36+
These tensors will be indentitied:
37+
self.descrpt_reshape : o_rmat
38+
self.descrpt_deriv : o_rmat_deriv
39+
self.rij : o_rij
40+
self.nlist : o_nlist
41+
Thus, this method should be called during building the descriptor and
42+
after these tensors are initialized.
43+
44+
Parameters
45+
----------
46+
suffix : str
47+
The suffix of the scope
48+
"""
49+
self.descrpt_reshape = tf.identity(self.descrpt_reshape, name = 'o_rmat' + suffix)
50+
self.descrpt_deriv = tf.identity(self.descrpt_deriv, name = 'o_rmat_deriv' + suffix)
51+
self.rij = tf.identity(self.rij, name = 'o_rij' + suffix)
52+
self.nlist = tf.identity(self.nlist, name = 'o_nlist' + suffix)
53+
54+
def get_tensor_names(self, suffix : str = "") -> Tuple[str]:
55+
"""Get names of tensors.
56+
57+
Parameters
58+
----------
59+
suffix : str
60+
The suffix of the scope
61+
62+
Returns
63+
-------
64+
Tuple[str]
65+
Names of tensors
66+
"""
67+
return (f'o_rmat{suffix}:0', f'o_rmat_deriv{suffix}:0', f'o_rij{suffix}:0', f'o_nlist{suffix}:0')
68+
69+
def pass_tensors_from_frz_model(self,
70+
descrpt_reshape : tf.Tensor,
71+
descrpt_deriv : tf.Tensor,
72+
rij : tf.Tensor,
73+
nlist : tf.Tensor
74+
):
75+
"""
76+
Pass the descrpt_reshape tensor as well as descrpt_deriv tensor from the frz graph_def
77+
78+
Parameters
79+
----------
80+
descrpt_reshape
81+
The passed descrpt_reshape tensor
82+
descrpt_deriv
83+
The passed descrpt_deriv tensor
84+
rij
85+
The passed rij tensor
86+
nlist
87+
The passed nlist tensor
88+
"""
89+
self.rij = rij
90+
self.nlist = nlist
91+
self.descrpt_deriv = descrpt_deriv
92+
self.descrpt_reshape = descrpt_reshape
93+
94+
def init_variables(self,
95+
model_file : str,
96+
suffix : str = "",
97+
) -> None:
98+
"""
99+
Init the embedding net variables with the given dict
100+
101+
Parameters
102+
----------
103+
model_file : str
104+
The input frozen model file
105+
suffix : str, optional
106+
The suffix of the scope
107+
"""
108+
self.embedding_net_variables = get_embedding_net_variables(model_file, suffix = suffix)

0 commit comments

Comments
 (0)