forked from njzjz/deepmd-kit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
116 changed files
with
3,114 additions
and
415 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
import numpy as np | ||
|
||
from deepmd.dpmodel.fitting.dipole_fitting import ( | ||
DipoleFitting, | ||
) | ||
|
||
from .dp_atomic_model import ( | ||
DPAtomicModel, | ||
) | ||
|
||
|
||
class DPDipoleAtomicModel(DPAtomicModel): | ||
def __init__(self, descriptor, fitting, type_map, **kwargs): | ||
if not isinstance(fitting, DipoleFitting): | ||
raise TypeError( | ||
"fitting must be an instance of DipoleFitting for DPDipoleAtomicModel" | ||
) | ||
super().__init__(descriptor, fitting, type_map, **kwargs) | ||
|
||
def apply_out_stat( | ||
self, | ||
ret: dict[str, np.ndarray], | ||
atype: np.ndarray, | ||
): | ||
# dipole not applying bias | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from deepmd.dpmodel.fitting.dos_fitting import ( | ||
DOSFittingNet, | ||
) | ||
|
||
from .dp_atomic_model import ( | ||
DPAtomicModel, | ||
) | ||
|
||
|
||
class DPDOSAtomicModel(DPAtomicModel): | ||
def __init__(self, descriptor, fitting, type_map, **kwargs): | ||
if not isinstance(fitting, DOSFittingNet): | ||
raise TypeError( | ||
"fitting must be an instance of DOSFittingNet for DPDOSAtomicModel" | ||
) | ||
super().__init__(descriptor, fitting, type_map, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
from deepmd.dpmodel.fitting.ener_fitting import ( | ||
EnergyFittingNet, | ||
InvarFitting, | ||
) | ||
|
||
from .dp_atomic_model import ( | ||
DPAtomicModel, | ||
) | ||
|
||
|
||
class DPEnergyAtomicModel(DPAtomicModel): | ||
def __init__(self, descriptor, fitting, type_map, **kwargs): | ||
if not ( | ||
isinstance(fitting, EnergyFittingNet) or isinstance(fitting, InvarFitting) | ||
): | ||
raise TypeError( | ||
"fitting must be an instance of EnergyFittingNet or InvarFitting for DPEnergyAtomicModel" | ||
) | ||
super().__init__(descriptor, fitting, type_map, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
import array_api_compat | ||
import numpy as np | ||
|
||
from deepmd.dpmodel.fitting.polarizability_fitting import ( | ||
PolarFitting, | ||
) | ||
|
||
from .dp_atomic_model import ( | ||
DPAtomicModel, | ||
) | ||
|
||
|
||
class DPPolarAtomicModel(DPAtomicModel): | ||
def __init__(self, descriptor, fitting, type_map, **kwargs): | ||
if not isinstance(fitting, PolarFitting): | ||
raise TypeError( | ||
"fitting must be an instance of PolarFitting for DPPolarAtomicModel" | ||
) | ||
super().__init__(descriptor, fitting, type_map, **kwargs) | ||
|
||
def apply_out_stat( | ||
self, | ||
ret: dict[str, np.ndarray], | ||
atype: np.ndarray, | ||
): | ||
"""Apply the stat to each atomic output. | ||
Parameters | ||
---------- | ||
ret | ||
The returned dict by the forward_atomic method | ||
atype | ||
The atom types. nf x nloc | ||
""" | ||
xp = array_api_compat.array_namespace(atype) | ||
out_bias, out_std = self._fetch_out_stat(self.bias_keys) | ||
|
||
if self.fitting.shift_diag: | ||
nframes, nloc = atype.shape | ||
dtype = out_bias[self.bias_keys[0]].dtype | ||
for kk in self.bias_keys: | ||
ntypes = out_bias[kk].shape[0] | ||
temp = xp.mean( | ||
xp.diagonal(out_bias[kk].reshape(ntypes, 3, 3), axis1=1, axis2=2), | ||
axis=1, | ||
) | ||
modified_bias = temp[atype] | ||
|
||
# (nframes, nloc, 1) | ||
modified_bias = ( | ||
modified_bias[..., xp.newaxis] * (self.fitting.scale[atype]) | ||
) | ||
|
||
eye = xp.eye(3, dtype=dtype) | ||
eye = xp.tile(eye, (nframes, nloc, 1, 1)) | ||
# (nframes, nloc, 3, 3) | ||
modified_bias = modified_bias[..., xp.newaxis] * eye | ||
|
||
# nf x nloc x odims, out_bias: ntypes x odims | ||
ret[kk] = ret[kk] + modified_bias | ||
return ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.