.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "flow_gallery/run_fd_vs_dfpt.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_flow_gallery_run_fd_vs_dfpt.py: FOO BAR ========================== Flow to compute with finite differences. Finite electric field calculation of AlP at clamped atomic positions Here the polarization of the cell is computed as a function of increasing external homogeneous electric field. berryopt 4 is used to trigger the finite field calculation, while the efield variable sets the strength (in atomic units) and direction of the field Based on tutorespfn/Input/tpolarization_6.abi .. GENERATED FROM PYTHON SOURCE LINES 18-171 .. image-sg:: /flow_gallery/images/sphx_glr_run_fd_vs_dfpt_001.png :alt: run fd vs dfpt :srcset: /flow_gallery/images/sphx_glr_run_fd_vs_dfpt_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Downloading repository from: https://github.com/PseudoDojo/ONCVPSP-PBE-PDv0.4/archive/refs/heads/master.zip ... Installing ONCVPSP-PBE-SR-PDv0.4 in: /home/runner/.abinit/pseudos/ONCVPSP-PBE-SR-PDv0.4 0.00iB [00:00, ?iB/s] 794kiB [00:00, 7.16MiB/s] 1.52MiB [00:00, 3.80MiB/s] 2.85MiB [00:00, 6.57MiB/s] 3.71MiB [00:00, 5.48MiB/s] 5.14MiB [00:00, 7.61MiB/s] 6.14MiB [00:00, 7.25MiB/s] 7.00MiB [00:01, 6.91MiB/s] 7.78MiB [00:01, 6.90MiB/s] 8.54MiB [00:01, 6.91MiB/s] 9.28MiB [00:01, 5.75MiB/s] 10.0MiB [00:01, 5.80MiB/s] 11.2MiB [00:01, 7.21MiB/s] 12.0MiB [00:01, 6.54MiB/s] 12.8MiB [00:02, 5.87MiB/s] 13.7MiB [00:02, 6.06MiB/s] 14.5MiB [00:02, 5.96MiB/s] 15.8MiB [00:02, 7.29MiB/s] 16.6MiB [00:02, 7.54MiB/s] 17.5MiB [00:02, 7.06MiB/s] 18.2MiB [00:02, 6.67MiB/s] 19.0MiB [00:02, 6.95MiB/s] 19.8MiB [00:03, 6.92MiB/s] 20.5MiB [00:03, 6.89MiB/s] 21.3MiB [00:03, 6.63MiB/s] 22.1MiB [00:03, 6.91MiB/s] 22.8MiB [00:03, 6.36MiB/s] 23.7MiB [00:03, 6.89MiB/s] 24.5MiB [00:03, 6.39MiB/s] 25.4MiB [00:03, 7.14MiB/s] 26.2MiB [00:03, 6.28MiB/s] 27.2MiB [00:04, 6.72MiB/s] 27.9MiB [00:04, 6.64MiB/s] 28.6MiB [00:04, 6.57MiB/s] 29.3MiB [00:04, 6.51MiB/s] 30.0MiB [00:04, 5.77MiB/s] 30.7MiB [00:04, 5.70MiB/s] 31.5MiB [00:04, 6.10MiB/s] 32.3MiB [00:04, 6.19MiB/s] 33.0MiB [00:05, 6.09MiB/s] 34.1MiB [00:05, 7.07MiB/s] 34.9MiB [00:05, 7.07MiB/s] 35.6MiB [00:05, 6.67MiB/s] 36.5MiB [00:05, 6.98MiB/s] 37.2MiB [00:05, 6.90MiB/s] 38.1MiB [00:05, 7.00MiB/s] 38.8MiB [00:05, 7.25MiB/s] 39.6MiB [00:06, 7.00MiB/s] 40.3MiB [00:06, 6.84MiB/s] 41.1MiB [00:06, 6.21MiB/s] 41.7MiB [00:06, 5.11MiB/s] 43.0MiB [00:06, 5.56MiB/s] 44.2MiB [00:06, 6.31MiB/s] 45.0MiB [00:06, 6.34MiB/s] 46.3MiB [00:07, 7.76MiB/s] 47.2MiB [00:07, 7.28MiB/s] 48.0MiB [00:07, 7.11MiB/s] 48.7MiB [00:07, 6.91MiB/s] 49.5MiB [00:07, 6.78MiB/s] 50.3MiB [00:07, 6.64MiB/s] 51.0MiB [00:07, 5.70MiB/s] 51.7MiB [00:07, 5.25MiB/s] 52.8MiB [00:08, 6.27MiB/s] 53.9MiB [00:08, 7.49MiB/s] 54.8MiB [00:08, 7.54MiB/s] 55.6MiB [00:08, 7.25MiB/s] 56.4MiB [00:08, 7.24MiB/s] 57.2MiB [00:08, 7.06MiB/s] 57.9MiB [00:08, 6.63MiB/s] 58.7MiB [00:08, 6.76MiB/s] 59.4MiB [00:09, 5.80MiB/s] 60.6MiB [00:09, 6.74MiB/s] 61.3MiB [00:09, 5.90MiB/s] 62.1MiB [00:09, 5.49MiB/s] 63.1MiB [00:09, 5.85MiB/s] 64.1MiB [00:09, 6.68MiB/s] 64.9MiB [00:09, 6.58MiB/s] 65.7MiB [00:10, 6.98MiB/s] 66.4MiB [00:10, 6.09MiB/s] 67.4MiB [00:10, 6.23MiB/s] 68.3MiB [00:10, 6.17MiB/s] 69.4MiB [00:10, 5.07MiB/s] 71.1MiB [00:10, 7.21MiB/s] 72.2MiB [00:10, 7.52MiB/s] 73.1MiB [00:11, 6.24MiB/s] 74.1MiB [00:11, 6.26MiB/s] 75.2MiB [00:11, 6.38MiB/s] 76.5MiB [00:11, 7.79MiB/s] 77.5MiB [00:11, 7.73MiB/s] 78.3MiB [00:11, 7.51MiB/s] 79.1MiB [00:12, 7.09MiB/s] 79.9MiB [00:12, 4.68MiB/s] 81.4MiB [00:12, 6.00MiB/s] 82.5MiB [00:12, 4.77MiB/s] 84.6MiB [00:12, 6.99MiB/s] 85.6MiB [00:13, 6.35MiB/s] 86.7MiB [00:13, 6.11MiB/s] 88.5MiB [00:13, 7.86MiB/s] 89.4MiB [00:13, 7.77MiB/s] 90.3MiB [00:13, 7.40MiB/s] 91.1MiB [00:13, 6.45MiB/s] 92.2MiB [00:14, 7.09MiB/s] 93.0MiB [00:14, 7.02MiB/s] 93.8MiB [00:14, 7.01MiB/s] 94.6MiB [00:14, 6.30MiB/s] 95.5MiB [00:14, 6.97MiB/s] 95.5MiB [00:14, 6.56MiB/s] Validating md5 checksums of ONCVPSP-PBE-SR-PDv0.4... Checksum test: OK Installation completed successfully in 16.10 [s] | .. code-block:: Python import sys import os import abipy.flowtk as flowtk from abipy.core.structure import Structure from abipy.abio.inputs import AbinitInput from abipy.flowtk.works import PhononWork from abipy.flowtk.dfpt_works import ElasticWork from abipy.flowtk.finitediff import FiniteEfieldWork, FiniteDisplWork, FiniteStrainWork, FiniteHfieldWork def build_flow(options): # Set working directory (default is the name of the script with '.py' removed and "run_" replaced by "flow_") if not options.workdir: options.workdir = os.path.basename(sys.argv[0]).replace(".py", "").replace("run_", "flow_") structure = Structure.from_abistring(""" # Definition of the unit cell acell 3*7.2728565836E+00 rprim 0.0000000000E+00 7.0710678119E-01 7.0710678119E-01 7.0710678119E-01 0.0000000000E+00 7.0710678119E-01 7.0710678119E-01 7.0710678119E-01 0.0000000000E+00 natom 2 # two atoms in the cell typat 1 2 # type 1 is Phosphorous, type 2 is Aluminum (order defined by znucl above and pseudos list) # Definition of the atom types and pseudopotentials ntypat 2 # two types of atoms znucl 15 13 # the atom types are Phosphorous and Aluminum #atomic positions, given in units of the cell vectors. Thus as the cell vectors #change due to strain the atoms will move as well. xred 1/4 1/4 1/4 0 0 0 """) # Get NC pseudos from pseudodojo. from abipy.flowtk.psrepos import get_oncvpsp_pseudos pseudos = get_oncvpsp_pseudos(xc_name="PBE", version="0.4", relativity_type="SR", accuracy="standard") #nband 4 # nband is restricted here to the number of filled bands only, no empty bands. The theory of # the Berrys phase polarization formula assumes filled bands only. Our pseudopotential choice # includes 5 valence electrons on P, 3 on Al, for 8 total in the primitive unit cell, hence # 4 filled bands. scf_input = AbinitInput(structure, pseudos) num_ele = scf_input.num_valence_electrons scf_input.set_vars( ecut=5, nband=4, tolvrs=1.0e-8, nstep=100, # Maximal number of SCF cycles ecutsm=0.5, dilatmx=1.05, paral_kgb=0, ) shiftk = [0.5, 0.5, 0.5, 0.5, 0.0, 0.0, 0.0, 0.5, 0.0, 0.0, 0.0, 0.5, ] scf_input.set_kmesh(ngkpt=[6, 6, 6], shiftk=shiftk) #scf_input.set_kmesh(ngkpt=[1, 1, 1], shiftk=[0, 0, 0]) # Initialize the flow. flow = flowtk.Flow(workdir=options.workdir, manager=options.manager) fd_accuracy = 2 # 3 points #fd_accuracy = 4 # 5 points relax_ions = True relax_ions_opts = None flow.register_work(FiniteEfieldWork.from_scf_input( scf_input, fd_accuracy=fd_accuracy, step_au=0.0001, relax_ions=relax_ions, relax_ions_opts=relax_ions_opts, )) #flow.register_work(FiniteDisplWork.from_scf_input( # scf_input, # fd_accuracy=fd_accuracy, # step_au=0.01, # extra_abivars=dict(berryopt=-1), # This to compute the polarization at E = 0 #)) flow.register_work(FiniteStrainWork.from_scf_input( scf_input, fd_accuracy=fd_accuracy, norm_step=0.005, shear_step=0.03, extra_abivars=dict(berryopt=-1), # This to compute the polarization at E = 0 relax_ions=relax_ions, relax_ions_opts=relax_ions_opts, )) #flow.register_work(FiniteHfieldWork.from_scf_input( # scf_input, # fd_accuracy=fd_accuracy, # step_au=0.01, # relax_ions=relax_ions, # relax_ions_opts=relax_ions_opts, #)) #flow.register_work(PhononWork.from_scf_input(scf_input, # qpoints=[0, 0, 0], # is_ngqpt=False, # with_becs=True, # with_quad=False, # with_flexoe=False, # with_dvdb=False, # tolerance=None, # ddk_tolerance=None #)) flow.register_work(ElasticWork.from_scf_input(scf_input, with_relaxed_ion=True, with_piezo=True, with_dde=False, tolerances=None )) return flow # This block generates the thumbnails in the AbiPy gallery. # You can safely REMOVE this part if you are using this script for production runs. if os.getenv("READTHEDOCS", False): __name__ = None import tempfile options = flowtk.build_flow_main_parser().parse_args(["-w", tempfile.mkdtemp()]) build_flow(options).graphviz_imshow() @flowtk.flow_main def main(options): """ This is our main function that will be invoked by the script. flow_main is a decorator implementing the command line interface. Command line args are stored in `options`. """ return build_flow(options) if __name__ == "__main__": sys.exit(main()) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 18.288 seconds) .. _sphx_glr_download_flow_gallery_run_fd_vs_dfpt.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: run_fd_vs_dfpt.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: run_fd_vs_dfpt.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: run_fd_vs_dfpt.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_