
.. 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

    2022-04-28 11:07:49.718 | INFO     | kliff.dataset.dataset:_read:397 - 4 configurations read from /Users/mjwen/Applications/kliff/examples/Si_training_set_4_configs
    #================================================================================
    # Available parameters to optimize.
    # Parameters in `original` space.
    # Model: LJ6-12
    #================================================================================

    name: epsilon
    value: [1.]
    size: 1

    name: sigma
    value: [2.]
    size: 1

    name: cutoff
    value: [5.]
    size: 1


    #================================================================================
    # Model parameters that are optimized.
    # Note that the parameters are in the transformed space if 
    # `params_transform` is provided when instantiating the model.
    #================================================================================

    sigma 1
      2.0000000000000000e+00 

    epsilon 1
      1.0000000000000000e+00 


    2022-04-28 11:07:49.726 | INFO     | kliff.calculators.calculator:create:107 - Create calculator for 4 configurations.
    2022-04-28 11:07:49.726 | INFO     | kliff.loss:minimize:290 - Start minimization using method: L-BFGS-B.
    2022-04-28 11:07:49.727 | INFO     | kliff.loss:_scipy_optimize:404 - Running in serial mode.
    2022-04-28 11:07:53.172 | INFO     | kliff.loss:minimize:292 - Finish minimization using method: L-BFGS-B.
    #================================================================================
    # Model parameters that are optimized.
    # Note that the parameters are in the transformed space if 
    # `params_transform` is provided when instantiating the model.
    #================================================================================

    sigma 1
      2.0629043239028659e+00 

    epsilon 1
      1.5614870430532530e+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  5.538 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>`_
