Fitting an fcp to force constantsΒΆ

If there already exist force constants which can be reasonably spanned by a cluster space there exists functionality to fit an ForceConstantPotential directly:

from hiphive.utilities import extract_parameters
parameters = extract_parameters(fcs, cs)

Now a ForceConstantPotential can be created using the ClusterSpace and the parameters:

fcp = ForceConstantPotential(cs, parameters)

A worked out example can be found in
tests/integration/fcs_sensing.py

import numpy as np

from ase.build import bulk
from hiphive import ClusterSpace, ForceConstantPotential
from hiphive.utilities import extract_parameters

tol = 1e-12

cutoffs = [7, 5]
prim = bulk('Al')
dim = 6

ideal = prim.repeat(dim)

cs = ClusterSpace(prim, cutoffs)
parameters = np.random.random(cs.n_dofs)
fcp = ForceConstantPotential(cs, parameters)
fcs = fcp.get_force_constants(ideal)
fitted_parameters = extract_parameters(fcs, cs)

assert np.linalg.norm(fitted_parameters - parameters) < tol