Representing FCs from external sources as a FCPΒΆ

There exist several codes that allow one to compute force constants and hiphive provides functionality to import some of these formats, including phonopy, phono3py, and (ShengBTE). It can be convenient to represent these force constants as ForceConstantPotential objects, for example in order to enforce rotational sum rules.

Firstly these force constants have to be imported as a ForceConstants object. Secondly, one has to construct the ClusterSpace on which the force constants will be projected. Then one can obtain the parameters as follows:

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

Now a ForceConstantPotential can be created by combining the ClusterSpace and the parameters in the usual manner:

fcp = ForceConstantPotential(cs, parameters)

A minimal example can be found in

import numpy as np

from 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