.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/plot_convergence.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_gallery_plot_convergence.py: Plot convergence ================ This example shows how to plot the convergence of scalar quantities wrt to one independent variable. For instance, the convergence of the energy per atom with the cutoff energy ecut. .. GENERATED FROM PYTHON SOURCE LINES 13-16 Let's assume we have the total energy per atom and the pressure in GPa as a function of ecut stored in three python lists: .. GENERATED FROM PYTHON SOURCE LINES 16-29 .. code-block:: Python ecut_list = [35., 40., 45., 50., 55., 60., 65.] energy_per_atom_ev = [ -444.29611271, -444.3113239, -444.3124781, -444.31251066, -444.31254606, -444.31256315, -444.31258609, ] pressure_gpa = [ -17.56316746, -16.00634717, -15.80295881, -15.79975677, -15.79858973, -15.79811464, -15.79929941, ] .. GENERATED FROM PYTHON SOURCE LINES 30-33 To plot energy vs ecut with a convergence window of 1e-3 centered around our best estimate i.e. the value obtained with the highest ecut, use the high-level API `from_xy_label_vals`: .. GENERATED FROM PYTHON SOURCE LINES 33-42 .. code-block:: Python from abipy.tools.plotting import ConvergenceAnalyzer ca = ConvergenceAnalyzer.from_xy_label_vals("ecut (Ha)", ecut_list, "E/natom (eV)", energy_per_atom_ev, tols=1e-3) print(ca) ca.plot() .. image-sg:: /gallery/images/sphx_glr_plot_convergence_001.png :alt: x: 41.1 for $\Delta$: 0.001 :srcset: /gallery/images/sphx_glr_plot_convergence_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Number of points for x-axis: 7 ykey: E/natom (eV) ytol ix xx ykey 0 0.001 2 41.135808 E/natom (eV) .. GENERATED FROM PYTHON SOURCE LINES 43-46 To analyze the convergence of two or more quantities, use the low-level API that expects two dictionaries mapping the y-label used in the plot to (1) the list of values and (2) the associated absolute tolerance as in: .. GENERATED FROM PYTHON SOURCE LINES 46-62 .. code-block:: Python yvals_dict = { "E/natom (eV)": energy_per_atom_ev, "P (GPa)": pressure_gpa, } ytols_dict = { "E/natom (eV)": 1e-3, "P (GPa)": 1e-1, } ca = ConvergenceAnalyzer("ecut (Ha)", ecut_list, yvals_dict, ytols_dict) #print(ca) #ca.plot() .. GENERATED FROM PYTHON SOURCE LINES 63-64 To specify multiple convergence criteria, replace scalars with tuples as in: .. GENERATED FROM PYTHON SOURCE LINES 64-75 .. code-block:: Python ytols_dict = { "E/natom (eV)": (1e-3, 1e-4), "P (GPa)": (1e-1, 1e-2), } ca = ConvergenceAnalyzer("ecut (Ha)", ecut_list, yvals_dict, ytols_dict) #print(ca) ca.plot() .. image-sg:: /gallery/images/sphx_glr_plot_convergence_002.png :alt: x: 41.1 for $\Delta$: 0.001, x: 46.2 for $\Delta$: 0.0001, x: 42.6 for $\Delta$: 0.1, x: 44.8 for $\Delta$: 0.01 :srcset: /gallery/images/sphx_glr_plot_convergence_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 76-79 Finally, if you have a (xlsf or csv) file with columns named e.g.: `ecut`, `energy_per_atom`, `pressure` and you want to plot the results with ConvergenceAnalyzer, use the `from_file` method with a `ytols_dict` whose keys define the columns in tabular data: .. GENERATED FROM PYTHON SOURCE LINES 79-93 .. code-block:: Python ytols_dict = { "ecut": (1e-3, 1e-4), "pressure": (1e-1, 1e-2), } #ca = ConvergenceAnalyzer.from_file(filepath, ytols_dict) # To change the x/y-labels in the plot, use: #ca.set_label("ecut", "ecut (Ha)") #ca.set_label("energy_per_atom", "E/natom (eV)") #ca.set_label("pressure", "P (GPa)") #print(ca) #ca.plot() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.775 seconds) .. _sphx_glr_download_gallery_plot_convergence.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_convergence.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_convergence.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_convergence.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_