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

run fd displ
Downloading repository from: https://github.com/PseudoDojo/ONCVPSP-LDA-PDv0.4/archive/refs/heads/master.zip ...
Installing ONCVPSP-LDA-SR-PDv0.4 in: /home/runner/.abinit/pseudos/ONCVPSP-LDA-SR-PDv0.4

0.00iB [00:00, ?iB/s]
786kiB [00:00, 6.12MiB/s]
1.46MiB [00:00, 6.25MiB/s]
2.16MiB [00:00, 5.66MiB/s]
3.26MiB [00:00, 6.71MiB/s]
4.06MiB [00:00, 6.68MiB/s]
4.92MiB [00:00, 7.06MiB/s]
5.65MiB [00:00, 5.71MiB/s]
6.33MiB [00:01, 5.91MiB/s]
7.40MiB [00:01, 6.94MiB/s]
8.18MiB [00:01, 7.06MiB/s]
8.96MiB [00:01, 6.77MiB/s]
10.1MiB [00:01, 7.75MiB/s]
12.1MiB [00:01, 9.39MiB/s]
13.9MiB [00:01, 11.1MiB/s]
16.2MiB [00:01, 11.0MiB/s]
18.0MiB [00:02, 11.9MiB/s]
20.2MiB [00:02, 14.3MiB/s]
21.8MiB [00:02, 11.7MiB/s]
23.1MiB [00:02, 9.74MiB/s]
24.2MiB [00:02, 7.61MiB/s]
25.6MiB [00:02, 8.61MiB/s]
26.6MiB [00:03, 8.64MiB/s]
27.6MiB [00:03, 8.66MiB/s]
29.6MiB [00:03, 9.06MiB/s]
31.4MiB [00:03, 10.5MiB/s]
33.5MiB [00:03, 11.6MiB/s]
34.7MiB [00:03, 11.3MiB/s]
35.9MiB [00:03, 11.1MiB/s]
38.3MiB [00:04, 13.2MiB/s]
39.7MiB [00:04, 9.87MiB/s]
41.2MiB [00:04, 10.6MiB/s]
42.4MiB [00:04, 10.0MiB/s]
43.7MiB [00:04, 10.3MiB/s]
45.9MiB [00:04, 12.6MiB/s]
47.3MiB [00:05, 9.67MiB/s]
49.2MiB [00:05, 11.6MiB/s]
50.5MiB [00:05, 11.4MiB/s]
51.8MiB [00:05, 11.3MiB/s]
53.2MiB [00:05, 11.0MiB/s]
54.5MiB [00:05, 11.0MiB/s]
55.7MiB [00:05, 9.24MiB/s]
56.7MiB [00:05, 8.13MiB/s]
58.1MiB [00:06, 9.01MiB/s]
59.9MiB [00:06, 10.7MiB/s]
62.1MiB [00:06, 10.7MiB/s]
64.0MiB [00:06, 11.9MiB/s]
66.6MiB [00:06, 12.9MiB/s]
67.9MiB [00:06, 12.2MiB/s]
69.2MiB [00:06, 11.7MiB/s]
71.0MiB [00:07, 12.3MiB/s]
72.3MiB [00:07, 11.7MiB/s]
73.4MiB [00:07, 11.4MiB/s]
75.6MiB [00:07, 13.9MiB/s]
77.1MiB [00:07, 11.0MiB/s]
78.3MiB [00:07, 8.14MiB/s]
79.3MiB [00:08, 8.25MiB/s]
80.3MiB [00:08, 8.38MiB/s]
81.2MiB [00:08, 7.78MiB/s]
82.0MiB [00:08, 7.70MiB/s]
84.3MiB [00:08, 9.03MiB/s]
86.0MiB [00:08, 10.6MiB/s]
88.1MiB [00:08, 11.6MiB/s]
90.1MiB [00:08, 12.8MiB/s]
91.5MiB [00:09, 10.6MiB/s]
92.6MiB [00:09, 9.26MiB/s]
93.6MiB [00:09, 8.86MiB/s]
94.5MiB [00:09, 7.88MiB/s]
95.4MiB [00:09, 7.09MiB/s]
96.2MiB [00:09, 6.47MiB/s]
97.2MiB [00:10, 6.43MiB/s]
98.2MiB [00:10, 6.29MiB/s]
99.3MiB [00:10, 6.55MiB/s]
100MiB [00:10, 6.53MiB/s]
101MiB [00:10, 6.29MiB/s]
103MiB [00:10, 8.39MiB/s]
105MiB [00:10, 9.85MiB/s]
107MiB [00:11, 11.2MiB/s]
109MiB [00:11, 13.6MiB/s]
110MiB [00:11, 12.8MiB/s]
112MiB [00:11, 12.4MiB/s]
113MiB [00:11, 13.1MiB/s]
115MiB [00:11, 11.8MiB/s]
116MiB [00:11, 9.79MiB/s]
117MiB [00:12, 8.82MiB/s]
118MiB [00:12, 8.94MiB/s]
120MiB [00:12, 10.3MiB/s]
122MiB [00:12, 11.7MiB/s]
124MiB [00:12, 11.7MiB/s]
126MiB [00:12, 12.6MiB/s]
128MiB [00:12, 14.4MiB/s]
130MiB [00:12, 13.5MiB/s]
131MiB [00:13, 13.2MiB/s]
132MiB [00:13, 10.5MiB/s]
134MiB [00:13, 11.8MiB/s]
136MiB [00:13, 12.8MiB/s]
138MiB [00:13, 12.3MiB/s]
139MiB [00:13, 12.0MiB/s]
141MiB [00:13, 13.8MiB/s]
142MiB [00:14, 10.4MiB/s]
143MiB [00:14, 9.14MiB/s]
144MiB [00:14, 8.90MiB/s]
146MiB [00:14, 8.02MiB/s]
146MiB [00:14, 7.97MiB/s]
147MiB [00:14, 6.35MiB/s]
149MiB [00:15, 7.14MiB/s]
149MiB [00:15, 7.28MiB/s]
150MiB [00:15, 6.88MiB/s]
151MiB [00:15, 7.16MiB/s]
152MiB [00:15, 6.79MiB/s]
152MiB [00:15, 6.46MiB/s]
153MiB [00:15, 7.25MiB/s]
154MiB [00:15, 5.83MiB/s]
155MiB [00:16, 6.38MiB/s]
156MiB [00:16, 7.15MiB/s]
157MiB [00:16, 7.05MiB/s]
158MiB [00:16, 6.80MiB/s]
158MiB [00:16, 6.81MiB/s]
159MiB [00:16, 6.95MiB/s]
160MiB [00:16, 6.99MiB/s]
161MiB [00:16, 5.26MiB/s]
162MiB [00:17, 6.22MiB/s]
163MiB [00:17, 5.71MiB/s]
164MiB [00:17, 5.89MiB/s]
165MiB [00:17, 7.69MiB/s]
166MiB [00:17, 7.60MiB/s]
167MiB [00:17, 6.33MiB/s]
167MiB [00:17, 6.07MiB/s]
168MiB [00:18, 6.16MiB/s]
169MiB [00:18, 6.02MiB/s]
170MiB [00:18, 9.29MiB/s]

Validating md5 checksums of ONCVPSP-LDA-SR-PDv0.4...
Checksum test: OK
Installation completed successfully in 20.47 [s]

import sys
import os
import abipy.flowtk as flowtk

from abipy.core.structure import Structure
from abipy.abio.inputs import AbinitInput
from abipy.flowtk.finitediff import FiniteDisplWork


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="LDA", version="0.4",
                                  relativity_type="SR", accuracy="standard")
    #nspinor = 1
    #nsppol, nspden = 1, 4
    #if nspinor == 1:
    #    nsppol, nspden  = 2, 2

    #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=50,         # 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)

    mask_iatom = [True, False]
    pert_cart_dirs = [[1, 0, 0],]

    mask_iatom = None
    pert_cart_dirs = None

    work = FiniteDisplWork.from_scf_input(
        scf_input,
        fd_accuracy=2,
        step_au=0.01,
        pert_cart_dirs=pert_cart_dirs,
        mask_iatom=mask_iatom,
        #extra_abivars=dict(berryopt=-1),  # This to compute the polarization at E = 0
    )

    # Add the work to the flow.
    flow.register_work(work)

    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())

Total running time of the script: (0 minutes 21.058 seconds)

Gallery generated by Sphinx-Gallery