.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials/make_effqh.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_tutorials_make_effqh.py: Effective quasi-harmonic potential ================================== This example shows how to fit the effective quasi-harmonic potential as a function of volume and temperature. .. GENERATED FROM PYTHON SOURCE LINES 8-18 .. code-block:: Python import numpy as np from ase.build import bulk from tensorpotential.calculator import grace_fm from directupsampling.calculators.emt import EMT from directupsampling.effqh.effqh import EffQH from directupsampling.plot_tools import plot from directupsampling.sampling import GridSampler .. rst-class:: sphx-glr-script-out .. code-block:: none [tensorpotential] Info: Environment variable TF_USE_LEGACY_KERAS is automatically set to '1'. WARNING:tensorflow:UserWarning: enabling the new type promotion must happen at the beginning of the program. Please ensure no TF APIs have been used yet. WARNING:tensorflow:UserWarning: enabling the new type promotion must happen at the beginning of the program. Please ensure no TF APIs have been used yet. WARNING:tensorflow:UserWarning: enabling the new type promotion must happen at the beginning of the program. Please ensure no TF APIs have been used yet. WARNING:tensorflow:UserWarning: enabling the new type promotion must happen at the beginning of the program. Please ensure no TF APIs have been used yet. WARNING:tensorflow:UserWarning: enabling the new type promotion must happen at the beginning of the program. Please ensure no TF APIs have been used yet. .. GENERATED FROM PYTHON SOURCE LINES 19-20 Make the initial ASE Atoms object. .. GENERATED FROM PYTHON SOURCE LINES 20-22 .. code-block:: Python atoms = bulk("Al", "fcc", cubic=True) * 3 .. GENERATED FROM PYTHON SOURCE LINES 23-28 Make two calculators. The first one is a light-weight calculator to sample MD trajectories. The second one is an accurate calculator to compute forces on atoms. The accurate calculator is typically a DFT calculator. In this example, we intead use a GRACE foundation model. .. GENERATED FROM PYTHON SOURCE LINES 28-31 .. code-block:: Python atoms.calc = EMT() calc_dft = grace_fm("GRACE-1L-OMAT") .. rst-class:: sphx-glr-script-out .. code-block:: none Using cached GRACE model from /root/.cache/grace/GRACE-1L-OMAT Model license: Academic Software License .. GENERATED FROM PYTHON SOURCE LINES 32-33 Define a volume-temperature grid using a GridSampler. .. GENERATED FROM PYTHON SOURCE LINES 33-37 .. code-block:: Python temperature = 20.0 # in K grid_fqh = [(v, temperature) for v in np.linspace(15.0, 18.0, 7)] effqh_sampler = GridSampler(atoms, grid_fqh) .. GENERATED FROM PYTHON SOURCE LINES 38-43 Run MD calculations. For a relatively light-weight calculator, we can run directly ``calculate_with``. For a DFT calculator, it may be more convenient to first make input files using ``write_folders``, run DFT calculations in these folders, and then collect the results using ``read_folders``. .. GENERATED FROM PYTHON SOURCE LINES 43-53 .. code-block:: Python effqh_sampler.sample_snapshots(30) snapshots_for_effqh = effqh_sampler.calculate_with(calc_dft) # effqh_sampler.write_folders( # root_path="./calcs", # joblist_file="./jobList", # calc=std_dft, # ) # Run DFT calculations in the folders. # snapshots_for_effqh = GridSampler.read_folders("./calcs").snapshot_container .. rst-class:: sphx-glr-script-out .. code-block:: none /usr/local/lib/python3.12/site-packages/ase/md/velocitydistribution.py:147: FutureWarning: `communicator` has been deprecated since ASE 3.26.0 and will be removed in ASE 3.27.0. Use `comm` instead. warnings.warn(msg, FutureWarning) /usr/local/lib/python3.12/site-packages/ase/md/velocitydistribution.py:154: FutureWarning: `comm=="serial"` has been deprecated since ASE 3.26.0 and will be removed in ASE 3.27.0. Use `comm=DummyMPI()` instead. warnings.warn(msg, FutureWarning) .. GENERATED FROM PYTHON SOURCE LINES 54-55 Fit the effective harmonic potential as a function of volume and temperature. .. GENERATED FROM PYTHON SOURCE LINES 55-58 .. code-block:: Python effqh = EffQH(atoms, fit_order=3) effqh.fit_snapshots(snapshots_for_effqh, method="least-squares") effqh.write_fc_fit("effqh_force_constants_fit.hdf5") .. GENERATED FROM PYTHON SOURCE LINES 59-60 Check the quasi-harmonic frequencies. .. GENERATED FROM PYTHON SOURCE LINES 60-61 .. code-block:: Python plot(effqh.exact_phonons).show() .. image-sg:: /tutorials/images/sphx_glr_make_effqh_001.png :alt: make effqh :srcset: /tutorials/images/sphx_glr_make_effqh_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (5 minutes 44.360 seconds) .. _sphx_glr_download_tutorials_make_effqh.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: make_effqh.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: make_effqh.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: make_effqh.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_