Skip to content
Snippets Groups Projects
Commit 831490c2 authored by Michele Nottoli's avatar Michele Nottoli
Browse files

Work in progress.

parent 55c3f32b
Branches
Tags
1 merge request!4Options
...@@ -3,10 +3,27 @@ ...@@ -3,10 +3,27 @@
import numpy as np import numpy as np
from scipy.spatial.distance import pdist from scipy.spatial.distance import pdist
def distance(coords: np.ndarray) -> np.ndarray: class Distance():
"""Compute the distance matric as a descriptor."""
return pdist(coords, metric="euclidean")
def coulomb(coords: np.ndarray) -> np.ndarray: """Distance matrix descriptors."""
"""Compute the Coulomb matrix as a descriptor."""
return 1.0/distance(coords) def __init__(self, **kwargs):
self.set_options(**kwargs)
def set_options(self, kwargs):
"""Given an option dictionary set the valid options and
raise an error if there are invalid ones."""
if len(kwargs) > 0:
raise ValueError("Invalid arguments given to the descriptor class.")
def compute(self, coords: np.ndarray) -> np.ndarray:
"""Compute the distance matric as a descriptor."""
return pdist(coords, metric="euclidean")
class Coulomb(Distance):
"""Coulomb matrix descriptors."""
def compute(self, coords: np.ndarray) -> np.ndarray:
"""Compute the Coulomb matrix as a descriptor."""
return 1.0/super().compute(coords)
...@@ -14,24 +14,56 @@ class Extrapolator: ...@@ -14,24 +14,56 @@ class Extrapolator:
it requires the number of electrons, the number of basis functions it requires the number of electrons, the number of basis functions
and the number of atoms of the molecule. The number of previous and the number of atoms of the molecule. The number of previous
steps used by the extrapolator is an optional argument with default steps used by the extrapolator is an optional argument with default
value of 10.""" value of 6."""
def __init__(self, nelectrons: int, nbasis: int, natoms: int, def _update_docstring(self):
nsteps: int = 6, **kwargs): options_str = "\n".join(f" - '{key}': {value}" for key, value in self.supported_options.items())
self.__doc__ = self.__doc__.format(options=options_str)
def __init__(self, nelectrons: int, nbasis: int, natoms: int, **kwargs):
self.supported_options = {
"verbose": False,
"nsteps": 6
}
self._update_docstring()
self.nelectrons = nelectrons self.nelectrons = nelectrons
self.nbasis = nbasis self.nbasis = nbasis
self.natoms = natoms self.natoms = natoms
self.nsteps = nsteps
self.gammas = CircularBuffer(self.nsteps, (self.nelectrons//2, self.nbasis)) self.gammas = CircularBuffer(self.options["nsteps"], (self.nelectrons//2, self.nbasis))
self.overlaps = CircularBuffer(self.nsteps, (self.nbasis, self.nbasis)) self.overlaps = CircularBuffer(self.options["nsteps"], (self.nbasis, self.nbasis))
self.descriptors = CircularBuffer(self.nsteps, self.descriptors = CircularBuffer(self.options["nsteps"],
((self.natoms - 1)*self.natoms//2, )) ((self.natoms - 1)*self.natoms//2, ))
self.tangent: Optional[np.ndarray] = None self.tangent: Optional[np.ndarray] = None
self._set_options(**kwargs) self.set_options(**kwargs)
def set_options(self, **kwargs):
"""Given an arbitrary amount of keyword arguments, parse them if
specified, set default values if not specified and raise an error
if invalid arguments are passed."""
self.options = {}
descriptor_options = {}
fitting_options = {}
for key, value in kwargs.items():
if key in self.supported_options:
self.options[key] = value
elif key.startswith("descriptor_"):
descriptor_options[key[11:]] = value
elif key.startswith("fitting_"):
fitting_options[key[8:]] = value
else:
raise ValueError(f"Unsupported option: {key}")
for option, default_value in self.supported_options.items():
if not hasattr(self.options, option):
setattr(self.options, option, default_value)
def load_data(self, coords: np.ndarray, coeff: np.ndarray, def load_data(self, coords: np.ndarray, coeff: np.ndarray,
overlap: np.ndarray): overlap: np.ndarray):
...@@ -73,13 +105,6 @@ class Extrapolator: ...@@ -73,13 +105,6 @@ class Extrapolator:
return c_guess @ c_guess.T return c_guess @ c_guess.T
def _set_options(self, **kwargs):
"""Parse additional options from the additional keyword arguments."""
self.options = {}
if "verbose" in kwargs:
self.options["verbose"] = kwargs["verbose"]
else:
self.options["verbose"] = False
def _get_tangent(self) -> np.ndarray: def _get_tangent(self) -> np.ndarray:
"""Get the tangent point.""" """Get the tangent point."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment