
.. DO NOT EDIT.
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
.. "auto_examples/example_lennard_jones.py"
.. LINE NUMBERS ARE GIVEN BELOW.

.. only:: html

    .. note::
        :class: sphx-glr-download-link-note

        Click :ref:`here <sphx_glr_download_auto_examples_example_lennard_jones.py>`
        to download the full example code

.. rst-class:: sphx-glr-example-title

.. _sphx_glr_auto_examples_example_lennard_jones.py:


.. _tut_lj:

Train a Lennard-Jones potential
===============================

In this tutorial, we train a Lennard-Jones potential that is build in KLIFF (i.e. not
models archived on OpenKIM_). From a user's perspective, a KLIFF built-in model is not
different from a KIM model.

Compare this with :ref:`tut_kim_sw`.

.. _OpenKIM: https://openkim.org

.. GENERATED FROM PYTHON SOURCE LINES 15-45




.. rst-class:: sphx-glr-script-out

 Out:

 .. code-block:: none

    4 configurations read from /Users/mjwen/Applications/kliff/examples/Si_training_set_4_configs
    #================================================================================
    # Available parameters to optimize.
    # Model: LJ6-12
    #================================================================================

    name: epsilon
    value: [1.0]
    size: 1

    name: sigma
    value: [2.0]
    size: 1

    name: cutoff
    value: [5.0]
    size: 1

    #================================================================================
    # Model parameters that are optimized.
    #================================================================================

    sigma 1
      2.0000000000000000e+00 

    epsilon 1
      1.0000000000000000e+00 

    Start minimization using method: L-BFGS-B.
    Running in serial mode.

    Finish minimization using method: L-BFGS-B.
    #================================================================================
    # Model parameters that are optimized.
    #================================================================================

    sigma 1
      2.0629054250507624e+00 

    epsilon 1
      1.5614851569433212e+00 







|

.. code-block:: default

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

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

    # calculator
    model = LennardJones()
    model.echo_model_params()

    # fitting parameters
    model.set_opt_params(sigma=[["default"]], epsilon=[["default"]])
    model.echo_opt_params()

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

    # loss
    loss = Loss(calc, nprocs=1)
    result = loss.minimize(method="L-BFGS-B", options={"disp": True, "maxiter": 10})


    # print optimized parameters
    model.echo_opt_params()
    model.save("kliff_model.yaml")


.. rst-class:: sphx-glr-timing

   **Total running time of the script:** ( 0 minutes  4.353 seconds)


.. _sphx_glr_download_auto_examples_example_lennard_jones.py:


.. only :: html

 .. container:: sphx-glr-footer
    :class: sphx-glr-footer-example



  .. container:: sphx-glr-download sphx-glr-download-python

     :download:`Download Python source code: example_lennard_jones.py <example_lennard_jones.py>`



  .. container:: sphx-glr-download sphx-glr-download-jupyter

     :download:`Download Jupyter notebook: example_lennard_jones.ipynb <example_lennard_jones.ipynb>`


.. only:: html

 .. rst-class:: sphx-glr-signature

    `Gallery generated by Sphinx-Gallery <https://sphinx-gallery.github.io>`_
