mirror of https://github.com/lammps/lammps.git
Implement alternate and recommended way to set properties of abstract base class
See: https://github.com/lammps/lammps/security/code-scanning/476
This commit is contained in:
parent
7238a29cb7
commit
3e9dca3017
|
@ -4,12 +4,13 @@ import pickle
|
|||
class MLIAPUnified(ABC):
|
||||
"""Abstract base class for MLIAPUnified."""
|
||||
|
||||
def __init__(self):
|
||||
self.interface = None
|
||||
self.element_types = None
|
||||
self.ndescriptors = None
|
||||
self.nparams = None
|
||||
self.rcutfac = None
|
||||
def __init__(self, interface = None, element_types = None,
|
||||
ndescriptors = None, nparams = None, rcutfac = None):
|
||||
self.interface = interface
|
||||
self.element_types = element_types
|
||||
self.ndescriptors = ndescriptors
|
||||
self.nparams = nparams
|
||||
self.rcutfac = rcutfac
|
||||
|
||||
@abstractmethod
|
||||
def compute_gradients(self, data):
|
||||
|
|
|
@ -6,16 +6,13 @@ class MLIAPUnifiedLJ(MLIAPUnified):
|
|||
"""Test implementation for MLIAPUnified."""
|
||||
|
||||
def __init__(self, element_types, epsilon=1.0, sigma=1.0, rcutfac=1.25):
|
||||
super().__init__()
|
||||
self.element_types = element_types
|
||||
self.ndescriptors = 1
|
||||
self.nparams = 3
|
||||
# ARGS: interface, element_types, ndescriptors, nparams, rcutfac
|
||||
super().__init__(None, element_types, 1, 3, rcutfac)
|
||||
# Mimicking the LJ pair-style:
|
||||
# pair_style lj/cut 2.5
|
||||
# pair_coeff * * 1 1
|
||||
self.epsilon = epsilon
|
||||
self.sigma = sigma
|
||||
self.rcutfac = rcutfac
|
||||
|
||||
def compute_gradients(self, data):
|
||||
"""Test compute_gradients."""
|
||||
|
|
Loading…
Reference in New Issue