-
Notifications
You must be signed in to change notification settings - Fork 648
Expand file tree
/
Copy pathdeep_density.py
More file actions
121 lines (108 loc) · 3.52 KB
/
Copy pathdeep_density.py
File metadata and controls
121 lines (108 loc) · 3.52 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# SPDX-License-Identifier: LGPL-3.0-or-later
from typing import (
Any,
)
import numpy as np
from deepmd.dpmodel.output_def import (
FittingOutputDef,
ModelOutputDef,
OutputVariableDef,
)
from .deep_eval import (
DeepEval,
)
class DeepDensity(DeepEval):
"""Charge density evaluated on grid points.
Parameters
----------
model_file : Path
The name of the frozen model file.
*args : list
Positional arguments.
auto_batch_size : bool or int or AutoBatchSize, default: True
If True, automatic batch size will be used. If int, it will be used
as the initial batch size.
neighbor_list : ase.neighborlist.NewPrimitiveNeighborList, optional
The ASE neighbor list class to produce the neighbor list. If None, the
neighbor list will be built natively in the model.
**kwargs : dict
Keyword arguments.
"""
@property
def output_def(self) -> ModelOutputDef:
"""Get the output definition of this model.
The density is predicted on grid points rather than on atoms, but it
is declared with the same per-site output definition as the fitting
net of the model.
"""
return ModelOutputDef(
FittingOutputDef(
[
OutputVariableDef(
"density",
[1],
reducible=True,
r_differentiable=True,
c_differentiable=True,
),
]
)
)
def eval(
self,
coords: np.ndarray,
cells: np.ndarray | None,
atom_types: list[int] | np.ndarray,
grid: np.ndarray,
fparam: np.ndarray | None = None,
aparam: np.ndarray | None = None,
mixed_type: bool = False,
**kwargs: dict[str, Any],
) -> np.ndarray:
"""Evaluate the density on grid points.
Parameters
----------
coords : np.ndarray
The coordinates of the atoms, in shape (nframes, natoms, 3).
cells : np.ndarray
The cell vectors of the system, in shape (nframes, 9). If the system
is not periodic, set it to None.
atom_types : list[int] or np.ndarray
The types of the atoms. If mixed_type is False, the shape is (natoms,);
otherwise, the shape is (nframes, natoms).
grid : np.ndarray
The coordinates of the grid points, in shape (nframes, ngrid, 3).
fparam : np.ndarray, optional
The frame parameters, by default None.
aparam : np.ndarray, optional
The atomic parameters, by default None.
mixed_type : bool, optional
Whether the atom_types is mixed type, by default False.
**kwargs : dict[str, Any]
Keyword arguments.
Returns
-------
density
The density on the grid points, in shape (nframes, ngrid).
"""
(
coords,
cells,
atom_types,
fparam,
aparam,
nframes,
natoms,
) = self._standard_input(coords, cells, atom_types, fparam, aparam, mixed_type)
results = self.deep_eval.eval(
coords,
cells,
atom_types,
False,
fparam=fparam,
aparam=aparam,
grid=np.array(grid),
**kwargs,
)
return results["density"].reshape(nframes, -1)
__all__ = ["DeepDensity"]