Ejemplo n.º 1
0
def init():
    model = KIMModel(model_name="SW_StillingerWeber_1985_Si__MO_405512056662_006")

    # Cannot set them all by calling this function only once, because the assertion
    # depends on order
    model.set_opt_params(A=[[5.0]])
    model.set_opt_params(B=[["default"]])
    model.set_opt_params(sigma=[[2.0951, "fix"]])
    model.set_opt_params(gamma=[[1.5]])

    path = Path(__file__).parent.joinpath("configs_extxyz/Si_4")
    tset = Dataset(path)
    configs = tset.get_configs()

    calc = Calculator(model)
    calc.create(configs, use_energy=True, use_forces=True)

    loss = Loss(calc, residual_fn=residual_fn, nprocs=1)

    return loss
Ejemplo n.º 2
0
    def test_parameter(self):
        modelname = "SW_StillingerWeber_1985_Si__MO_405512056662_005"
        model = KIMModel(modelname)

        # parameters
        params = model.get_model_params()
        sigma = params["sigma"][0]
        A = params["A"][0]

        # optimizing parameters
        # B will not be optimized, only providing initial guess
        model.set_opt_params(sigma=[["default"]],
                             B=[["default", "fix"]],
                             A=[["default"]])

        calc = Calculator(model)

        x0 = calc.get_opt_params()
        assert x0[0] == sigma
        assert x0[1] == A
        assert len(x0) == 2
        assert model.get_num_opt_params() == 2

        x1 = [i + 0.1 for i in x0]
        calc.update_model_params(x1)

        assert params["sigma"][0] == sigma + 0.1
        assert params["A"][0] == A + 0.1
Ejemplo n.º 3
0
    def test_compute(self):
        test_file_path = Path(__file__).parents[1].joinpath("configs_extxyz")
        tset = Dataset(test_file_path.joinpath("Si_4"))
        configs = tset.get_configs()

        modelname = "SW_StillingerWeber_1985_Si__MO_405512056662_005"
        model = KIMModel(modelname)

        # calculator
        calc = Calculator(model)
        compute_arguments = calc.create(configs)

        for i, ca in enumerate(compute_arguments):
            calc.compute(ca)
            energy = calc.get_energy(ca)
            forces = calc.get_forces(ca)[:3]

            assert energy == pytest.approx(ref_energies[i], 1e-6)
            assert np.allclose(forces, ref_forces[i])
Ejemplo n.º 4
0
def get_avail_params(model_name):
    model = KIMModel(model_name)
    model.echo_model_params()
Ejemplo n.º 5
0
"""
Compute the root-mean-square error (RMSE) of a model prediction and reference values in
the dataset.
"""

from kliff.analyzers import EnergyForcesRMSE
from kliff.calculators import Calculator
from kliff.dataset import Dataset
from kliff.models import KIMModel
from kliff.utils import download_dataset

model = KIMModel(model_name="SW_StillingerWeber_1985_Si__MO_405512056662_005")

# load the trained model back
# model.load("kliff_model.yaml")

dataset_path = download_dataset(dataset_name="Si_training_set_4_configs")
tset = Dataset(dataset_path)
configs = tset.get_configs()

calc = Calculator(model)
calc.create(configs)

analyzer = EnergyForcesRMSE(calc)
analyzer.run(verbose=2, sort="energy")
Ejemplo n.º 6
0
# Let's first import the modules that will be used in this example.

from kliff.calculators import Calculator
from kliff.dataset import Dataset
from kliff.loss import Loss
from kliff.models import KIMModel
from kliff.utils import download_dataset

##########################################################################################
# Model
# -----
#
# We first create a KIM model for the SW potential, and print out all the available
# parameters that can be optimized (we call this ``model parameters``).

model = KIMModel(model_name="SW_StillingerWeber_1985_Si__MO_405512056662_006")
model.echo_model_params()


##########################################################################################
# The output is generated by the last line, and it tells us the ``name``, ``value``,
# ``size``, ``data type`` and a ``description`` of each parameter.
#
# .. note::
#    You can provide a ``path`` argument to the method ``echo_model_params(path)`` to
#    write the available parameters information to a file indicated by ``path``.
#
# .. note::
#    The available parameters information can also by obtained using the **kliff**
#    :ref:`cmdlntool`:
#    ``$ kliff model --echo-params SW_StillingerWeber_1985_Si__MO_405512056662_006``
Ejemplo n.º 7
0
See `A force-matching Stillinger-Weber potential for MoS2: Parameterization and Fisher
information theory based sensitivity analysis <https://doi.org/10.1063/1.5007842>`_
"""

from kliff.analyzers import Fisher
from kliff.calculators import Calculator
from kliff.dataset import Dataset
from kliff.models import KIMModel
from kliff.utils import download_dataset

##########################################################################################
# Select the parameters that will be used to compute the Fisher information. Only
# parameters specified below will be use, others will be kept fixed. The size of the
# Fisher information matrix will be equal to the total size of the parameters specified
# here.
model = KIMModel(model_name="SW_StillingerWeber_1985_Si__MO_405512056662_006")
model.set_opt_params(A=[["default"]],
                     B=[["default"]],
                     sigma=[["default"]],
                     gamma=[["default"]])

# dataset
dataset_path = download_dataset(dataset_name="Si_training_set_4_configs")
tset = Dataset(dataset_path)
configs = tset.get_configs()

# calculator
calc = Calculator(model)
calc.create(configs)

##########################################################################################