Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 1, 2024
1 parent 88f5079 commit de96159
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 52 deletions.
18 changes: 9 additions & 9 deletions deepmd/dpmodel/atomic_model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,17 @@
from .base_atomic_model import (
BaseAtomicModel,
)
from .dp_atomic_model import (
DPAtomicModel,
)
from .energy_atomic_model import (
DPEnergyAtomicModel,
from .dipole_atomic_model import (
DPDipoleAtomicModel,
)
from .dos_atomic_model import (
DPDOSAtomicModel,
)
from .polar_atomic_model import (
DPPolarAtomicModel,
from .dp_atomic_model import (
DPAtomicModel,
)
from .dipole_atomic_model import (
DPDipoleAtomicModel,
from .energy_atomic_model import (
DPEnergyAtomicModel,
)
from .linear_atomic_model import (
DPZBLLinearEnergyAtomicModel,
Expand All @@ -42,6 +39,9 @@
from .pairtab_atomic_model import (
PairTabAtomicModel,
)
from .polar_atomic_model import (
DPPolarAtomicModel,
)

__all__ = [
"make_base_atomic_model",
Expand Down
1 change: 1 addition & 0 deletions deepmd/dpmodel/atomic_model/dipole_atomic_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: LGPL-3.0-or-later
import numpy as np

from deepmd.dpmodel.fitting.dipole_fitting import (
DipoleFitting,
)
Expand Down
5 changes: 2 additions & 3 deletions deepmd/dpmodel/atomic_model/energy_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

class DPEnergyAtomicModel(DPAtomicModel):
def __init__(self, descriptor, fitting, type_map, **kwargs):
assert (
isinstance(fitting, EnergyFittingNet)
or isinstance(fitting, InvarFitting)
assert isinstance(fitting, EnergyFittingNet) or isinstance(
fitting, InvarFitting
)
super().__init__(descriptor, fitting, type_map, **kwargs)
79 changes: 39 additions & 40 deletions deepmd/dpmodel/atomic_model/polar_atomic_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,42 @@ def __init__(self, descriptor, fitting, type_map, **kwargs):
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
"""
out_bias, out_std = self._fetch_out_stat(self.bias_keys)

if self.fitting_net.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 = np.zeros(ntypes,dtype=dtype)
for i in range(ntypes):
temp[i] = np.mean(np.diagonal(out_bias[kk][i].reshape(3, 3)))
modified_bias = temp[atype]

# (nframes, nloc, 1)
modified_bias = (
modified_bias[..., np.newaxis]
* (self.fitting_net.scale[atype])
)

eye = np.eye(3,dtype=dtype)
eye = np.tile(eye, (nframes, nloc, 1, 1))
# (nframes, nloc, 3, 3)
modified_bias = modified_bias[..., np.newaxis] * eye

# nf x nloc x odims, out_bias: ntypes x odims
ret[kk] = ret[kk] + modified_bias
return ret
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
"""
out_bias, out_std = self._fetch_out_stat(self.bias_keys)

if self.fitting_net.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 = np.zeros(ntypes, dtype=dtype)
for i in range(ntypes):
temp[i] = np.mean(np.diagonal(out_bias[kk][i].reshape(3, 3)))
modified_bias = temp[atype]

# (nframes, nloc, 1)
modified_bias = (
modified_bias[..., np.newaxis] * (self.fitting_net.scale[atype])
)

eye = np.eye(3, dtype=dtype)
eye = np.tile(eye, (nframes, nloc, 1, 1))
# (nframes, nloc, 3, 3)
modified_bias = modified_bias[..., np.newaxis] * eye

# nf x nloc x odims, out_bias: ntypes x odims
ret[kk] = ret[kk] + modified_bias
return ret
1 change: 1 addition & 0 deletions deepmd/dpmodel/model/dos_model.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# SPDX-License-Identifier: LGPL-3.0-or-later

0 comments on commit de96159

Please sign in to comment.