Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ if(SKBUILD)
message(STATUS "The project is built using scikit-build")
endif()

# it determines the size of the PATH up to librascal and
# is used to output relative path information in the code using __FILE__
string(LENGTH "${CMAKE_SOURCE_DIR}/" SOURCE_PATH_SIZE)
add_definitions("-DSOURCE_PATH_SIZE=${SOURCE_PATH_SIZE}")

add_subdirectory(src)

enable_testing()
Expand Down
6 changes: 5 additions & 1 deletion bindings/rascal/models/kernels.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
from .sparse_points import SparsePoints
import json

import logging

import numpy as np

LOGGER = logging.getLogger(__name__)


class Kernel(BaseIO):

Expand Down Expand Up @@ -109,7 +112,8 @@ def _set_data(self, data):
super()._set_data(data)

def _get_data(self):
return super()._get_data()
data = super()._get_data()
return data

def __call__(self, X, Y=None, grad=(False, False), compute_neg_stress=False):
"""
Expand Down
9 changes: 7 additions & 2 deletions bindings/rascal/models/krr.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,13 @@ def predict_stress(self, managers, KNM=None):

return -neg_stress

def get_weights(self):
return self.weights
@property
def weights(self):
return self._weights

@weights.setter
def weights(self, weights):
self._weights = weights.reshape(-1)

def _get_init_params(self):
init_params = dict(
Expand Down
113 changes: 47 additions & 66 deletions bindings/rascal/representations/spherical_covariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,70 +151,70 @@ def __init__(
cutoff_smooth_width,
max_radial,
max_angular,
gaussian_sigma_type,
gaussian_sigma_type="Constant",
gaussian_sigma_constant=0.3,
cutoff_function_type="ShiftedCosine",
normalize=True,
radial_basis="GTO",
optimization=None,
optimization_args=None,
soap_type="LambdaSpectrum",
inversion_symmetry=True,
radial_basis="GTO",
normalize=True,
covariant_lambda=0,
cutoff_function_parameters=dict(),
optimization=None,
optimization_args=None,
global_species=None,
cutoff_function_parameters=None,
):
"""Construct a SphericalExpansion representation

Required arguments are all the hyperparameters named in the
class documentation
"""
self.name = "sphericalcovariants"
self.hypers = dict()
self.update_hyperparameters(
optimization = check_optimization_for_spherical_representations(
optimization, optimization_args
)

if global_species is None:
global_species = []
elif isinstance(global_species, int):
global_species = list(global_species)
elif not (isinstance(global_species, list)):
raise ValueError(
"'global_species' should be None, an integer, an empty list or a list of atomic numbers"
)

if cutoff_function_parameters is None:
cutoff_function_parameters = dict()
elif not isinstance(cutoff_function_parameters, dict):
raise ValueError(
"'cutoff_function_parameters' should be None or a dictionary with 'rate', 'scale' and 'expontent'"
)

self.hypers = dict(
interaction_cutoff=interaction_cutoff,
cutoff_smooth_width=cutoff_smooth_width,
max_radial=max_radial,
max_angular=max_angular,
gaussian_sigma_type=gaussian_sigma_type,
gaussian_sigma_constant=gaussian_sigma_constant,
cutoff_function_type=cutoff_function_type,
soap_type=soap_type,
normalize=normalize,
inversion_symmetry=inversion_symmetry,
radial_basis=radial_basis,
normalize=normalize,
covariant_lambda=covariant_lambda,
)

self.cutoff_function_parameters = deepcopy(cutoff_function_parameters)

cutoff_function_parameters.update(
interaction_cutoff=interaction_cutoff,
cutoff_smooth_width=cutoff_smooth_width,
)
cutoff_function = cutoff_function_dict_switch(
cutoff_function_type, **cutoff_function_parameters
)

gaussian_density = dict(
type=gaussian_sigma_type,
gaussian_sigma=dict(value=gaussian_sigma_constant, unit="AA"),
)
optimization = check_optimization_for_spherical_representations(
optimization, optimization_args
)

radial_contribution = dict(type=radial_basis, optimization=optimization)
radial_contribution = dict(
type=radial_basis,
)

self.update_hyperparameters(
cutoff_function=cutoff_function,
gaussian_density=gaussian_density,
radial_contribution=radial_contribution,
optimization=optimization,
optimization_args=optimization_args,
global_species=global_species,
cutoff_function_parameters=cutoff_function_parameters,
)

self.nl_options = [
dict(name="centers", args=dict()),
dict(name="centers", args=[]),
dict(name="neighbourlist", args=dict(cutoff=interaction_cutoff)),
dict(name="centercontribution", args=dict()),
dict(name="strict", args=dict(cutoff=interaction_cutoff)),
]

self.rep_options = dict(name=self.name, args=[self.hypers])

self._representation = CalculatorFactory(self.rep_options)
Expand All @@ -232,18 +232,19 @@ def update_hyperparameters(self, **hypers):
"max_angular",
"gaussian_sigma_type",
"gaussian_sigma_constant",
"cutoff_function_type",
"soap_type",
"inversion_symmetry",
"covariant_lambda",
"cutoff_function",
"radial_basis",
"normalize",
"gaussian_density",
"radial_contribution",
"covariant_lambda",
"optimization",
"global_species",
"cutoff_function_parameters",
}

hypers_clean = {key: hypers[key] for key in hypers if key in allowed_keys}
self.hypers.update(hypers_clean)
return

def transform(self, frames):
"""Compute the representation.
Expand Down Expand Up @@ -353,27 +354,7 @@ def get_keys(self, species):
return keys

def _get_init_params(self):
gaussian_density = self.hypers["gaussian_density"]
cutoff_function = self.hypers["cutoff_function"]
radial_contribution = self.hypers["radial_contribution"]

init_params = dict(
interaction_cutoff=cutoff_function["cutoff"]["value"],
cutoff_smooth_width=cutoff_function["smooth_width"]["value"],
max_radial=self.hypers["max_radial"],
max_angular=self.hypers["max_angular"],
soap_type=self.hypers["soap_type"],
inversion_symmetry=self.hypers["inversion_symmetry"],
normalize=self.hypers["normalize"],
gaussian_sigma_type=gaussian_density["type"],
gaussian_sigma_constant=gaussian_density["gaussian_sigma"]["value"],
lam=self.hypers["covariant_lambda"],
cutoff_function_type=cutoff_function["type"],
radial_basis=radial_contribution["type"],
optimization=radial_contribution["optimization"],
cutoff_function_parameters=self.cutoff_function_parameters,
)
return init_params
return self.hypers

def _set_data(self, data):
super()._set_data(data)
Expand Down
98 changes: 38 additions & 60 deletions bindings/rascal/representations/spherical_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,16 @@ def __init__(
cutoff_smooth_width,
max_radial,
max_angular,
gaussian_sigma_type,
gaussian_sigma_type="Constant",
gaussian_sigma_constant=0.3,
cutoff_function_type="ShiftedCosine",
radial_basis="GTO",
compute_gradients=False,
expansion_by_species_method="environment wise",
optimization=None,
optimization_args=None,
expansion_by_species_method="environment wise",
global_species=None,
compute_gradients=False,
cutoff_function_parameters=dict(),
cutoff_function_parameters=None,
):
"""Construct a SphericalExpansion representation

Expand All @@ -188,56 +188,52 @@ class documentation
"""

self.name = "sphericalexpansion"
self.hypers = dict()

optimization = check_optimization_for_spherical_representations(
optimization, optimization_args
)

if global_species is None:
global_species = []
elif not isinstance(global_species, list):
elif isinstance(global_species, int):
global_species = list(global_species)

self.update_hyperparameters(
elif not (isinstance(global_species, list)):
raise ValueError(
"'global_species' should be None, an integer, an empty list or a list of atomic numbers"
)

if cutoff_function_parameters is None:
cutoff_function_parameters = dict()
elif not isinstance(cutoff_function_parameters, dict):
raise ValueError(
"'cutoff_function_parameters' should be None or a dictionary with 'rate', 'scale' and 'expontent'"
)

self.hypers = dict(
interaction_cutoff=interaction_cutoff,
cutoff_smooth_width=cutoff_smooth_width,
max_radial=max_radial,
max_angular=max_angular,
gaussian_sigma_type=gaussian_sigma_type,
gaussian_sigma_constant=gaussian_sigma_constant,
cutoff_function_type=cutoff_function_type,
radial_basis=radial_basis,
compute_gradients=compute_gradients,
expansion_by_species_method=expansion_by_species_method,
optimization=optimization,
optimization_args=optimization_args,
global_species=global_species,
compute_gradients=compute_gradients,
)
self.cutoff_function_parameters = deepcopy(cutoff_function_parameters)
cutoff_function_parameters.update(
interaction_cutoff=interaction_cutoff,
cutoff_smooth_width=cutoff_smooth_width,
)
cutoff_function = cutoff_function_dict_switch(
cutoff_function_type, **cutoff_function_parameters
)

gaussian_density = dict(
type=gaussian_sigma_type,
gaussian_sigma=dict(value=gaussian_sigma_constant, unit="A"),
)
optimization = check_optimization_for_spherical_representations(
optimization, optimization_args
)

radial_contribution = dict(type=radial_basis, optimization=optimization)

self.update_hyperparameters(
cutoff_function=cutoff_function,
gaussian_density=gaussian_density,
radial_contribution=radial_contribution,
cutoff_function_parameters=cutoff_function_parameters,
)

self.nl_options = [
dict(name="centers", args=dict()),
dict(name="centers", args=[]),
dict(name="neighbourlist", args=dict(cutoff=interaction_cutoff)),
dict(name="centercontribution", args=dict()),
dict(name="strict", args=dict(cutoff=interaction_cutoff)),
]

self.rep_options = dict(name=self.name, args=[self.hypers])

n_features = self.get_num_coefficients()

self._representation = CalculatorFactory(self.rep_options)

def update_hyperparameters(self, **hypers):
Expand All @@ -253,13 +249,14 @@ def update_hyperparameters(self, **hypers):
"max_angular",
"gaussian_sigma_type",
"gaussian_sigma_constant",
"gaussian_density",
"cutoff_function",
"radial_contribution",
"cutoff_function_type",
"radial_basis",
"compute_gradients",
"optimization",
"cutoff_function_parameters",
"expansion_by_species_method",
"global_species",
"compute_gradients",
}
hypers_clean = {key: hypers[key] for key in hypers if key in allowed_keys}
self.hypers.update(hypers_clean)
Expand Down Expand Up @@ -305,26 +302,7 @@ def get_keys(self, species):
return keys

def _get_init_params(self):
gaussian_density = self.hypers["gaussian_density"]
cutoff_function = self.hypers["cutoff_function"]
radial_contribution = self.hypers["radial_contribution"]

init_params = dict(
interaction_cutoff=cutoff_function["cutoff"]["value"],
cutoff_smooth_width=cutoff_function["smooth_width"]["value"],
max_radial=self.hypers["max_radial"],
max_angular=self.hypers["max_angular"],
expansion_by_species_method=self.hypers["expansion_by_species_method"],
global_species=self.hypers["global_species"],
compute_gradients=self.hypers["compute_gradients"],
gaussian_sigma_type=gaussian_density["type"],
gaussian_sigma_constant=gaussian_density["gaussian_sigma"]["value"],
cutoff_function_type=cutoff_function["type"],
radial_basis=radial_contribution["type"],
optimization=radial_contribution["optimization"],
cutoff_function_parameters=self.cutoff_function_parameters,
)
return init_params
return self.hypers

def _set_data(self, data):
super()._set_data(data)
Expand Down
Loading