{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Effective quasi-harmonic potential\n\nThis example shows how to fit the effective quasi-harmonic potential\nas a function of volume and temperature.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nfrom ase.build import bulk\nfrom tensorpotential.calculator import grace_fm\n\nfrom directupsampling.calculators.emt import EMT\nfrom directupsampling.effqh.effqh import EffQH\nfrom directupsampling.plot_tools import plot\nfrom directupsampling.sampling import GridSampler" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make the initial ASE Atoms object.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "atoms = bulk(\"Al\", \"fcc\", cubic=True) * 3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Make two calculators.\nThe first one is a light-weight calculator to sample MD trajectories.\nThe second one is an accurate calculator to compute forces on atoms.\nThe accurate calculator is typically a DFT calculator.\nIn this example, we intead use a GRACE foundation model.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "atoms.calc = EMT()\ncalc_dft = grace_fm(\"GRACE-1L-OMAT\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define a volume-temperature grid using a GridSampler.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "temperature = 20.0 # in K\ngrid_fqh = [(v, temperature) for v in np.linspace(15.0, 18.0, 7)]\neffqh_sampler = GridSampler(atoms, grid_fqh)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run MD calculations.\nFor a relatively light-weight calculator, we can run directly ``calculate_with``.\nFor a DFT calculator, it may be more convenient to first make input files using\n``write_folders``, run DFT calculations in these folders, and then collect\nthe results using ``read_folders``.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "effqh_sampler.sample_snapshots(30)\nsnapshots_for_effqh = effqh_sampler.calculate_with(calc_dft)\n# effqh_sampler.write_folders(\n# root_path=\"./calcs\",\n# joblist_file=\"./jobList\",\n# calc=std_dft,\n# )\n# Run DFT calculations in the folders.\n# snapshots_for_effqh = GridSampler.read_folders(\"./calcs\").snapshot_container" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Fit the effective harmonic potential as a function of volume and temperature.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "effqh = EffQH(atoms, fit_order=3)\neffqh.fit_snapshots(snapshots_for_effqh, method=\"least-squares\")\neffqh.write_fc_fit(\"effqh_force_constants_fit.hdf5\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Check the quasi-harmonic frequencies.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plot(effqh.exact_phonons).show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.13" } }, "nbformat": 4, "nbformat_minor": 0 }