PK RWk k run_ldaus.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow for LDA+U calculations\n\nThis example shows how to compute the LDA+U band structure of NiO\nwith PAW for several values of U-J.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\nfrom abipy.flowtk.abiobjects import LdauParams\n\n\ndef make_scf_nscf_dos_inputs(structure, pseudos, luj_params, paral_kgb=1):\n # Input file taken from tldau_2.in\n multi = abilab.MultiDataset(structure, pseudos=pseudos, ndtset=3)\n\n # Global variables\n global_vars = dict(\n #\n ecut=12,\n pawecutdg=30,\n nband=40,\n occopt=7,\n tsmear=0.015,\n nstep=50,\n paral_kgb=paral_kgb,\n #\n # Spin\n nsppol=1,\n nspden=2,\n nspinor=1,\n spinat=[0, 0, 1,\n 0, 0, -1,\n 0, 0, 0,\n 0, 0, 0],\n # Kpoint Grid\n # The k point grid is not symmetric, but the calculations being\n # for the ground-state, this is not a problem.\n )\n\n multi.set_vars(global_vars)\n multi.set_vars(luj_params.to_abivars())\n\n # GS run.\n multi[0].set_vars(\n iscf=17,\n toldfe=1.0e-8,\n ngkpt=[2, 2, 2],\n chksymbreak=0,\n )\n\n # Band structure run.\n multi[1].set_kpath(ndivsm=6)\n multi[1].set_vars(tolwfr=1e-10)\n\n # DOS calculation.\n multi[2].set_vars(\n iscf=-3, # NSCF calculation\n ngkpt=structure.calc_ngkpt(nksmall=8),\n shiftk=[0.0, 0.0, 0.0],\n nshiftk=1,\n tolwfr=1.e-8,\n #pawprtdos=1,\n )\n\n # Generate two input files for the GS and the NSCF run\n scf_input, nscf_input, dos_input = multi.split_datasets()\n\n return scf_input, nscf_input, dos_input\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n # Create the work for the band structure calculation.\n structure = abidata.structure_from_ucell(\"NiO\")\n pseudos = abidata.pseudos(\"28ni.paw\", \"8o.2.paw\")\n\n # The code below set up the parameters for the LDA+U calculation in NiO.\n #usepawu 1\n #lpawu 2 -1\n #upawu 8.0 0.0 eV\n #jpawu 0.8 0.0 eV\n usepawu = 1\n u_values = [5.0, 8.0]\n\n for u in u_values:\n # Apply U-J on Ni only.\n luj_params = LdauParams(usepawu, structure)\n luj_params.luj_for_symbol(\"Ni\", l=2, u=u, j=0.1*u, unit=\"eV\")\n\n scf_input, nscf_input, dos_input = make_scf_nscf_dos_inputs(structure, pseudos, luj_params)\n\n work = flowtk.BandStructureWork(scf_input, nscf_input, dos_inputs=dos_input)\n flow.register_work(work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_ldaus.py -s\n\nthen use:\n\n abirun.py flow_ldaus/ ebands\n\nto analyze all GSR files produced by flow.\n\n.. code-block:: bash\n\n KS electronic bands:\n nsppol nspinor nspden nkpt nband nelect fermie formula natom \\\n w0_t0 1 1 2 3 40 48.0 6.084 Ni2 O2 4\n w0_t1 1 1 2 129 40 48.0 6.084 Ni2 O2 4\n w0_t2 1 1 2 213 40 48.0 6.169 Ni2 O2 4\n w1_t0 1 1 2 3 40 48.0 6.855 Ni2 O2 4\n w1_t1 1 1 2 129 40 48.0 6.855 Ni2 O2 4\n w1_t2 1 1 2 213 40 48.0 6.432 Ni2 O2 4\n\n angle0 angle1 angle2 a b c volume abispg_num \\\n w0_t0 60.0 60.0 60.0 2.964 2.964 5.927 36.809 166\n w0_t1 60.0 60.0 60.0 2.964 2.964 5.927 36.809 166\n w0_t2 60.0 60.0 60.0 2.964 2.964 5.927 36.809 166\n w1_t0 60.0 60.0 60.0 2.964 2.964 5.927 36.809 166\n w1_t1 60.0 60.0 60.0 2.964 2.964 5.927 36.809 166\n w1_t2 60.0 60.0 60.0 2.964 2.964 5.927 36.809 166\n\n scheme occopt tsmear_ev bandwidth_spin0 fundgap_spin0 \\\n w0_t0 gaussian 7 0.408 99.343 3.324\n w0_t1 gaussian 7 0.408 99.680 3.049\n w0_t2 gaussian 7 0.408 99.838 2.560\n w1_t0 gaussian 7 0.408 99.318 4.626\n w1_t1 gaussian 7 0.408 99.628 3.352\n w1_t2 gaussian 7 0.408 99.826 3.155\n\n dirgap_spin0 task_class ncfile node_id \\\n w0_t0 3.351 ScfTask flow_ldaus/w0/t0/outdata/out_GSR.nc 241313\n w0_t1 3.352 NscfTask flow_ldaus/w0/t1/outdata/out_GSR.nc 241314\n w0_t2 3.041 NscfTask flow_ldaus/w0/t2/outdata/out_GSR.nc 241315\n w1_t0 4.626 ScfTask flow_ldaus/w1/t0/outdata/out_GSR.nc 241317\n w1_t1 3.928 NscfTask flow_ldaus/w1/t1/outdata/out_GSR.nc 241318\n w1_t2 3.983 NscfTask flow_ldaus/w1/t2/outdata/out_GSR.nc 241319\n\n status\n w0_t0 Completed\n w0_t1 Completed\n w0_t2 Completed\n w1_t0 Completed\n w1_t1 Completed\n w1_t2 Completed\n\nThe second task in each work (w*_t1) is a NSCF run along the high symmetry path.\nand we can compare the results of these two task by specifying the node identifiers:\n\n abirun.py flow_ldaus/ ebands -p --nids=241314,241318\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R' run_raman_optic.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Raman Flow with independent-particle approximation (optic)\n\nThis script shows how to perform a Raman calculation with excitonic effects\nincluded with the BSE formalism.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport numpy as np\n\nimport abipy.abilab as abilab\nimport abipy.data as abidata\nimport abipy.flowtk as flowtk\n\n\ndef build_flow(options):\n # Get the unperturbed structure.\n pseudos = abidata.pseudos(\"14si.pspnc\")\n base_structure = abidata.structure_from_ucell(\"Si\")\n\n ngkpt = [6, 6, 6]\n\n etas = [-.001, 0, +.001]\n ph_displ = np.reshape(np.zeros(3*len(base_structure)), (-1,3))\n ph_displ[0,:] = [+1, 0, 0]\n ph_displ[1,:] = [-1, 0, 0]\n\n # Build new structures by displacing atoms according to the phonon displacement\n # ph_displ (in cartesian coordinates). The Displacement is normalized so that\n # the maximum atomic diplacement is 1 Angstrom and then multiplied by eta.\n modifier = abilab.StructureModifier(base_structure)\n\n displaced_structures = modifier.displace(ph_displ, etas, frac_coords=False)\n\n # Initialize flow. Each workflow in the flow defines a complete BSE calculation for given eta.\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n # Generate the different shifts to average\n ndiv = 1\n shift1D = np.arange(1, 2*ndiv+1, 2) / (2 * ndiv)\n all_shifts = [[x, y, z] for x in shift1D for y in shift1D for z in shift1D]\n\n for structure, eta in zip(displaced_structures, etas):\n for ishift,shift in enumerate(all_shifts):\n flow.register_work(raman_work(structure, pseudos, ngkpt, shift),\n workdir=\"eta_\" + str(eta) + \"shift_\" + str(ishift))\n\n return flow\n\n\ndef raman_work(structure, pseudos, ngkpt, shiftk):\n # Generate 3 different input files for computing optical properties with Optic.\n\n global_vars = dict(\n istwfk=\"*1\",\n paral_kgb=0,\n ecut=8,\n nstep=200,\n diemac=12,\n ixc=7,\n chksymbreak=0,\n #accesswff=3\n )\n\n multi = abilab.MultiDataset(structure, pseudos=pseudos, ndtset=5)\n multi.set_vars(global_vars)\n multi.set_kmesh(ngkpt=ngkpt, shiftk=shiftk)\n\n # GS run\n multi[0].set_vars(\n tolvrs=1e-8,\n nband=20,\n nbdbuf=2,\n )\n\n # Note kptopt 2 in NSCF and DDK\n # In principle kptopt 2 is needed only in DDK.\n # one could do a first NSCF run with kptopt 1, reread with kptopt 2 and enter DDK...\n\n # NSCF run\n multi[1].set_vars(\n iscf=-2,\n nband=40,\n nbdbuf=5,\n kptopt=2,\n tolwfr=1.e-12,\n )\n\n # DDK along 3 directions\n # Third dataset : ddk response function along axis 1\n # Fourth dataset : ddk response function along axis 2\n # Fifth dataset : ddk response function along axis 3\n for idir in range(3):\n rfdir = 3 * [0]\n rfdir[idir] = 1\n\n multi[2 + idir].set_vars(\n iscf=-3,\n nband=40,\n nbdbuf=5,\n nstep=1,\n nline=0,\n prtwf=3,\n kptopt=2,\n nqpt=1,\n qpt=[0.0, 0.0, 0.0],\n rfdir=rfdir,\n rfelfd=2,\n tolwfr=1.e-12,\n )\n\n scf_inp, nscf_inp, ddk1, ddk2, ddk3 = multi.split_datasets()\n ddk_inputs = [ddk1, ddk2, ddk3]\n\n work = flowtk.Work()\n scf_t = work.register_scf_task(scf_inp)\n nscf_t = work.register_nscf_task(nscf_inp, deps={scf_t: \"DEN\"})\n\n ddk_nodes = []\n for inp in ddk_inputs:\n ddk_t = work.register_ddk_task(inp, deps={nscf_t: \"WFK\"})\n ddk_nodes.append(ddk_t)\n\n optic_input = abilab.OpticInput(\n broadening=0.002, # Value of the smearing factor, in Hartree\n domega=0.0003, # Frequency mesh.\n maxomega=0.3,\n scissor=0.000, # Scissor shift if needed, in Hartree\n tolerance=0.002, # Tolerance on closeness of singularities (in Hartree)\n num_lin_comp=6, # Number of components of linear optic tensor to be computed\n lin_comp=(11, 12, 13, 22, 23, 33), # Linear coefficients to be computed (x=1, y=2, z=3)\n num_nonlin_comp=0 # Number of components of nonlinear optic tensor to be computed\n #nonlin_comp=(123, 222),\n )\n\n optic_t = flowtk.OpticTask(optic_input, nscf_node=nscf_t, ddk_nodes=ddk_nodes)\n work.register(optic_t)\n\n return work\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK Rwim run_sic_relax.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Relaxation Flow\n\nThis example shows how to build a very simple Flow for the structural relaxation of SiC.\nOne could use a similar logic to perform multiple relaxations with different input parameters...\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\n\nimport abipy.abilab as abilab\nimport abipy.data as data\nimport abipy.flowtk as flowtk\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n pseudos = data.pseudos(\"14si.pspnc\", \"6c.pspnc\")\n structure = data.structure_from_ucell(\"SiC\")\n\n # Initialize the input\n relax_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n\n # Set variables\n relax_inp.set_vars(\n ecut=20,\n paral_kgb=1,\n iomode=3,\n # Relaxation part\n ionmov=2,\n optcell=1,\n strfact=100,\n ecutsm=0.5, # Important!\n dilatmx=1.15, # Important!\n toldff=1e-6,\n tolmxf=1e-5,\n ntime=100,\n )\n\n # K-points sampling\n shiftk = [\n [0.5,0.5,0.5],\n [0.5,0.0,0.0],\n [0.0,0.5,0.0],\n [0.0,0.0,0.5]\n ]\n relax_inp.set_kmesh(ngkpt=[4, 4, 4], shiftk=shiftk)\n\n # Initialize the flow\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n # Register the task.\n flow.register_relax_task(relax_inp)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_sic_relax.py -s\n\nthen use:\n\n abirun.py flow_sic_relax structures\n\nto compare the input and output structures of the tasks:\n\n.. code-block:: bash\n\n Lattice parameters:\n formula natom angle0 angle1 angle2 a b c volume \\\n w0_t0_in Si1 C1 2 60.0 60.0 60.0 3.065 3.065 3.065 20.351\n w0_t0_out Si1 C1 2 60.0 60.0 60.0 3.065 3.065 3.065 20.355\n\n abispg_num P [GPa] Max|F| eV/ang task_class status\n w0_t0_in None NaN NaN RelaxTask Completed\n w0_t0_out None -0.001 0.0 RelaxTask Completed\n\n Use `--verbose` to print atoms.\n\nAs you can see, the pressure at the end of the RelaxTask is very small (forces are zero by symmetry):\n\nTo visualize the evolution of the lattice parameters during the structura relaxation use:\n\n abiopen.py flow_sic_relax/w0/t0/outdata/out_HIST.nc\n\nand then inside the ipython terminal, type:\n\n.. code-block:: ipython\n\n In [1]: %matplotlib\n In [2]: abifile.plot()\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R?M run_phonons_with_quad.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Dynamical quadrupoles\n\nThis example shows how to compute the dynamical matrix of GaP on user-defined q-mesh\nincluding Born effective charges, the macroscopic dielectric matric and the dynamical quadrupoles Q*.\nThe final results (out_DDB, out_DVDB) will be produced automatically at the end of the run\nand saved in ``flow_phonons_with_quad/outdata/``.\n\nThe Q* tensor may be needed to improve the accuracy of the Fourier interpolation of the phonon frequencies,\nespecially in the long-wavelength limit |q| --> 0.\n\nThis example is based on \nNote that only selected features are compatible with dynamical quadrupoles.\nPlease consult \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.abilab as abilab\nimport abipy.data as abidata\n\nfrom abipy import flowtk\n\n\ndef build_flow(options):\n \"\"\"\n Create a `Flow` for phonon calculations including\n eps_inf, Born effective charges and dynamical quadrupoles\n \"\"\"\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n pseudos = abidata.pseudos(\"31-Ga.LDA.fhi\", \"15-P.LDA.fhi\")\n\n # Initialize the structure from an abinit string\n # Other approaches (e.g. from cif files) are available as well.\n structure = abilab.Structure.from_abistring(\"\"\"\n acell 1.0 1.0 1.0\n rprim 0.0 5.023016083002 5.023016083002\n 5.023016083002 0.0 5.023016083002\n 5.023016083002 5.023016083002 0.0\n\n # Definition of the atom types and positions\n # ******************************************\n ntypat 2\n znucl 31 15\n natom 2\n typat 1 2\n xred\n 0.0000000 0.0000000 0.0000000\n 0.2500000 0.2500000 0.2500000\n\"\"\")\n\n # Build input for GS calculation\n scf_input = abilab.AbinitInput(structure, pseudos=pseudos)\n\n # We use parameters similar to the ones in https://docs.abinit.org/tests/tutorespfn/Input/tlw_4.abi\n scf_input.set_vars(\n nband=4,\n ecut=5.0,\n ngkpt=[4, 4, 4],\n shiftk=[\n [0.5, 0.5, 0.5],\n [0.5, 0.0, 0.0],\n [0.0, 0.5, 0.0],\n [0.0, 0.0, 0.5],\n ],\n diemac=12.0,\n nstep=100,\n tolvrs=1.0e-10,\n #tolvrs=1.0e-18, # This is the value used in tlw_4.abi\n # but it is not always possible to reach this precision in more complex systems.\n #useylm=1,\n #ixc=7\n #iomode=3,\n #paral_kgb=1,\n )\n\n # At the time of writing, Q* calculations are implemented only for\n # NC LDA scalar-relativistic pseudos without non-linear core correction.\n # This section shows how to use the Pseudo API to perform this kind of check\n # before runnnig the calculation.\n for pseudo in scf_input.pseudos:\n # print(pseudo)\n if not pseudo.isnc:\n raise RuntimeError(\"Only NC pseudos are compatible with Q*\")\n if pseudo.has_nlcc:\n raise RuntimeError(\"NLCC is not compatible with Q*\")\n if pseudo.xc.type != \"LDA\":\n raise RuntimeError(\"Only LDA is compatible with Q*\")\n\n # Initialize the flow\n flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)\n\n # Compute phonons on the ddb_ngqpt q-mesh.\n # Include Born effective charges and dynamical quadrupoles via `with_quad=True`.\n #\n ddb_ngqpt = [1, 1, 1]\n #ddb_ngqpt = [4, 4, 4]\n ph_work = flowtk.PhononWork.from_scf_input(scf_input, qpoints=ddb_ngqpt,\n is_ngqpt=True, with_becs=True, with_quad=True)\n\n # Add the phonon work to the flow\n flow.register_work(ph_work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RdD0 run_gruneisen_abinit.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Gruneisen parameters with DFPT phonons and finite difference\n\nThis script compute the Gr\u00fcneisen parameters (derivative of frequencies wrt Volume)\nusing finite differences and the phonons obtained with the DFPT part of Abinit.\nThe Anaddb input file needed to compute Gr\u00fcneisen parameters will be generated\nin the outdata directory of the flow.\n\nIt is necessary to run three DFPT phonon calculations.\nOne is calculated at the equilibrium volume and the remaining two are calculated\nat the slightly larger volume and smaller volume than the equilibrium volume.\nThe unitcells at these volumes have to be fully relaxed under the constraint of each volume.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.abilab as abilab\nimport abipy.data as abidata\nfrom abipy import flowtk\n\n\ndef build_flow(options):\n \"\"\"\n Create a `Flow` for Gr\u00fcneisen calculations:\n Three relaxations at fixed volume followed by phonon calculation on a q-mesh.\n \"\"\"\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n flow = flowtk.Flow(workdir=options.workdir)\n\n # This function constructs the input files for the phonon calculation:\n # GS input + the input files for the phonon calculation.\n pseudos = abidata.pseudos(\"14si.pspnc\")\n structure = abidata.structure_from_ucell(\"Si\")\n\n gs_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n\n # Global variables used both for the GS and the DFPT run.\n gs_inp.set_vars(\n nband=4,\n ecut=2.0,\n ngkpt=[4, 4, 4],\n nshiftk=4,\n shiftk=[0.0, 0.0, 0.5, # This gives the usual fcc Monkhorst-Pack grid\n 0.0, 0.5, 0.0,\n 0.5, 0.0, 0.0,\n 0.5, 0.5, 0.5],\n diemac=12.0,\n #iomode=3,\n tolvrs=1.0e-18,\n )\n\n # NB: k-mesh in gs_inp and ngqpt q-mesh must be commensurate.\n from abipy.flowtk.gruneisen import GruneisenWork\n voldelta = gs_inp.structure.volume * 0.02\n work = GruneisenWork.from_gs_input(gs_inp, voldelta, ngqpt=[2, 2, 2], with_becs=False)\n flow.register_work(work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).plot_networkx(tight_layout=True)\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RM"= run_relax_vs_kpts_tsmear.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Relaxation of GaN with different K-meshes\n\nIn this example, we employ the relaxation algorithms implemented in Abinit (``ionmov`` and ``optcell``)\nto find the equilibrium configuration of GaN (atomic positions and lattice vectors).\nThe relaxation is done with different k-meshes to monitor the convergence of the results.\nYou will observe a change of the equilibrium parameters with respect to the k-point mesh.\n\nNote the we are using pseudopotentials generated with the GGA which tends to\noverestimate the lattice parameters and ecut is way too low.\nIf you replace GGA with LDA, you will observe that LDA tends to underestimate the parameters.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\n\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\nimport abipy.data as abidata\n\n\ndef relax_input(tsmear, nksmall):\n \"\"\"\n Crystalline aluminum: optimization of the lattice parameter\n at fixed number of k points and broadening. Similar to tbase4_1.in with minor\n \"\"\"\n #structure = abilab.Structure.fcc()\n inp = abilab.AbinitInput(structure=abidata.ucells.structure_from_ucell(\"Al\"),\n pseudos=abidata.pseudos(\"13al.981214.fhi\"))\n\n # Define k-point sampling.\n # nshiftk and shift are automatically selected from the lattice and the number of divisions\n # for the smallest direction. nksmall 2 e.g. will automatically select\n # ngkpt 2 2 2\n # nshiftk 4\n # shiftk\n # 0.5 0.5 0.5\n # 0.5 0.0 0.0\n # 0.0 0.5 0.0\n # 0.0 0.0 0.5\n inp.set_autokmesh(nksmall=nksmall)\n\n inp.set_vars(\n ecut=6,\n occopt=4,\n tsmear=tsmear,\n toldfe=1e-6,\n nstep=10,\n optcell=1, # Optimization of the lattice parameters\n ionmov=2,\n ntime=10,\n dilatmx=1.05,\n ecutsm=0.5,\n ixc=1,\n )\n\n return inp\n\n\ndef build_flow(options):\n \"\"\"\n Build and return a flow performing structural relaxations with different k-point samplings.\n \"\"\"\n # Set working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Let generate multiple inputs for different (tsmear, nksmall)\n # Product computes the Cartesian product of input iterables.\n # It's equivalent to nested for-loops\n tsmear_list = (0.01, 0.02, 0.03, 0.04)\n nksmall_list = (2, 4, 6)\n\n from itertools import product\n inputs = [relax_input(tsmear, nksmall) for tsmear, nksmall in product(tsmear_list, nksmall_list)]\n\n # Build flow form inputs.\n # As the calculations are independent, we can use Flow.from_inputs\n # Note the Flow.from_inputs is a simplified interface that, by default, builds tasks\n # for Ground-state calculation (GsTask).\n # Here we are performing a structural relaxation so we have to specify the task class explicitly.\n # AbiPy will use this piece of information to handle the restart of the RelaxTask that differs\n # from the one provided by GsTask.\n\n return flowtk.Flow.from_inputs(options.workdir, inputs=inputs, task_class=flowtk.RelaxTask)\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_relax_vs_kpts_tsmear.py -s\n\n then use:\n\n abirun.py flow_relax_vs_kpts_tsmear hist -p\n\n to print (and plot) the structural relaxation for all the tasks:\n\n .. image:: https://github.com/abinit/abipy_assets/blob/master/run_relax_vs_kpts_tsmear_hist.png?raw=true\n :alt: Commbiplot of the HIST files for the different (nkpt, tsmear) params\n\n To analyze the convergence of the relaxed lattice parameters, use:\n\n .. code-block:: bash\n\n\tabirun.py flow_relax_vs_kpts_tsmear robot GSR\n\n to create a GSR robot for all the tasks in the flow and open an ipyton shell.\n\n Then, inside ipython, type:\n\n .. code-block:: ipython\n\n\t In [1]: %matplotlib\n\t In [2]: df = robot.get_dataframe()\n\t # Let's do some math with pandas to retrieve the Abinit acell from the a lattice parameter given in Ang.\n\t In [3]: import math\n\t In [4]: from abipy import abilab\n\t In [5]: df[\"acell\"] = df[\"a\"] * math.sqrt(2) * abilab.units.ang_to_bohr\n\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# In [7]: df[\"acell\"]\n# Out[7]:\n# flow_relax_vs_kpts_tsmear/w0/t0/outdata/out_GSR.nc 7.558770\n# flow_relax_vs_kpts_tsmear/w0/t1/outdata/out_GSR.nc 7.505486\n# flow_relax_vs_kpts_tsmear/w0/t2/outdata/out_GSR.nc 7.496158\n# flow_relax_vs_kpts_tsmear/w0/t3/outdata/out_GSR.nc 7.558770\n# flow_relax_vs_kpts_tsmear/w0/t4/outdata/out_GSR.nc 7.505643\n# flow_relax_vs_kpts_tsmear/w0/t5/outdata/out_GSR.nc 7.495546\n# flow_relax_vs_kpts_tsmear/w0/t6/outdata/out_GSR.nc 7.558770\n# flow_relax_vs_kpts_tsmear/w0/t7/outdata/out_GSR.nc 7.501756\n# flow_relax_vs_kpts_tsmear/w0/t8/outdata/out_GSR.nc 7.496770\n# flow_relax_vs_kpts_tsmear/w0/t9/outdata/out_GSR.nc 7.558771\n# flow_relax_vs_kpts_tsmear/w0/t10/outdata/out_GSR.nc 7.504096\n# flow_relax_vs_kpts_tsmear/w0/t11/outdata/out_GSR.nc 7.499134\n# Name: acell, dtype: float64\n#\n# # to plot the optimized acell vs nkpt for the different values of tsmear, use:\n#\t In [6]: robot.plot_xy_with_hue(df, \"nkpt\", \"acell\", hue=\"tsmear\")\n#\n# .. image:: https://github.com/abinit/abipy_assets/blob/master/run_relax_vs_kpts_tsmear.png?raw=true\n# :alt: optimized acell as function of nkpt and tsmear"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK Ruሳ " run_mgb2_phonons_nkpt_tsmear.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow to analyze the convergence of phonons in metals wrt ngkpt and tsmear\n\nThis examples shows how to build a Flow to compute the\nphonon band structure in a metallic system (MgB2) with different\nk-point samplings and values of the electronic smearing tsmear\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\nimport sys\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nfrom abipy import flowtk\n\n\ndef make_scf_input(structure, ngkpt, tsmear, pseudos, paral_kgb=0):\n \"\"\"Build and return Ground-state input for MgB2 given ngkpt and tsmear.\"\"\"\n\n scf_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n\n # Global variables\n scf_inp.set_vars(\n ecut=10,\n nband=8,\n occopt=4, # Marzari smearing\n tsmear=tsmear,\n paral_kgb=paral_kgb,\n iomode=3,\n )\n\n # Dataset 1 (GS run)\n scf_inp.set_kmesh(ngkpt=ngkpt, shiftk=structure.calc_shiftk())\n scf_inp.set_vars(tolvrs=1e-10)\n\n return scf_inp\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n structure = abidata.structure_from_ucell(\"MgB2\")\n\n # Get pseudos from a table.\n table = abilab.PseudoTable(abidata.pseudos(\"12mg.pspnc\", \"5b.pspnc\"))\n pseudos = table.get_pseudos_for_structure(structure)\n\n flow = flowtk.Flow(workdir=options.workdir)\n\n # Build work of GS task. Each gs_task uses different (ngkpt, tsmear) values\n # and represent the starting point of the phonon works.\n scf_work = flowtk.Work()\n ngkpt_list = [[4, 4, 4], [8, 8, 8]] #, [12, 12, 12]]\n tsmear_list = [0.01, 0.02] # , 0.04]\n for ngkpt in ngkpt_list:\n for tsmear in tsmear_list:\n scf_input = make_scf_input(structure, ngkpt, tsmear, pseudos)\n scf_work.register_scf_task(scf_input)\n flow.register_work(scf_work)\n\n # This call uses the information reported in the GS task to\n # compute all the independent atomic perturbations corresponding to a [2, 2, 2] q-mesh.\n # For each GS task, construct a phonon work that will inherit (ngkpt, tsmear) from scf_task.\n for scf_task in scf_work:\n ph_work = flowtk.PhononWork.from_scf_task(scf_task, qpoints=[2, 2, 2], is_ngqpt=True)\n flow.register_work(ph_work)\n\n return flow.allocate(use_smartio=True)\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_mgb2_phonons_nkpt_tsmear.py -s\n\n then use:\n\n .. code-block:: shell\n\n\tabicomp.py ddb flow_mgb2_phonons_nkpt_tsmear/w*/outdata/*_DDB -ipy\n\n to build a robot from the output DDB files and start the ipython shell.\n\n then, inside the ipython shell, use:\n\n .. code-block:: ipython\n\n In [1]: %matplotlib\n In [2]: r = robot.anaget_phonon_plotters(nqsmall=0)\n In [3]: r.phbands_plotter.gridplot_with_hue(\"tsmear\")\n\n to compute the phonon bands with Anaddb and plot the results grouped by \"tsmear\".\n\n .. image:: https://github.com/abinit/abipy_assets/blob/master/run_mgb2_phonons_nkpt_tsmear.png?raw=true\n :alt: Convergence of phonon dispersion of MgB2 wrt k-point sampling and electronic smearing.\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R;Y run_phfrozen_ebands.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow for e-Bands with frozen phonon\n\nElectronic band structure of silicon in a distorted geometry (frozen phonon at q=0)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport numpy as np\nimport abipy.data as data\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef make_scf_nscf_inputs(structure, paral_kgb=1):\n multi = abilab.MultiDataset(structure, pseudos=data.pseudos(\"14si.pspnc\"), ndtset=2)\n\n # Global variables\n global_vars = dict(\n ecut=6,\n nband=8,\n timopt=-1,\n paral_kgb=0,\n #nstep=4, # This is not enough to converge. Used to test the automatic restart.\n nstep=10,\n iomode=3,\n )\n\n multi.set_vars(global_vars)\n\n # Dataset 1 (GS run)\n multi[0].set_kmesh(ngkpt=[8,8,8], shiftk=[0,0,0])\n multi[0].set_vars(tolvrs=1e-6)\n\n # Dataset 2 (NSCF run)\n kptbounds = [\n [0.5, 0.0, 0.0], # L point\n [0.0, 0.0, 0.0], # Gamma point\n [0.0, 0.5, 0.5], # X point\n ]\n\n multi[1].set_kpath(ndivsm=6, kptbounds=kptbounds)\n multi[1].set_vars(tolwfr=1e-12)\n\n # Generate two input files for the GS and the NSCF run\n scf_input, nscf_input = multi.split_datasets()\n\n return scf_input, nscf_input\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # build the structures\n base_structure = abilab.Structure.from_file(data.cif_file(\"si.cif\"))\n modifier = abilab.StructureModifier(base_structure)\n\n etas = [-0.1, 0, +0.1]\n ph_displ = np.reshape(np.zeros(3*len(base_structure)), (-1,3))\n ph_displ[0,:] = [+1, 0, 0]\n ph_displ[1,:] = [-1, 0, 0]\n\n displaced_structures = modifier.displace(ph_displ, etas, frac_coords=False)\n\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n for structure in displaced_structures:\n # Create the work for the band structure calculation.\n scf_input, nscf_input = make_scf_nscf_inputs(structure)\n\n work = flowtk.BandStructureWork(scf_input, nscf_input)\n flow.register_work(work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_phfrozen_ebands -s\n\nthen use:\n\n abirun.py flow_phfrozen_ebands/ structures -v\n\nto analyze the input/output structures including the atomic positions:\n\n.. code-block:: bash\n\n Lattice parameters:\n formula natom angle0 angle1 angle2 a b c volume \\\n w0_t0_in Si2 2 60.0 60.0 60.0 3.867 3.867 3.867 40.888\n w0_t0_out Si2 2 60.0 60.0 60.0 3.867 3.867 3.867 40.888\n w0_t1_in Si2 2 60.0 60.0 60.0 3.867 3.867 3.867 40.888\n w1_t0_in Si2 2 60.0 60.0 60.0 3.867 3.867 3.867 40.888\n w1_t0_out Si2 2 60.0 60.0 60.0 3.867 3.867 3.867 40.888\n w1_t1_in Si2 2 60.0 60.0 60.0 3.867 3.867 3.867 40.888\n w2_t0_in Si2 2 60.0 60.0 60.0 3.867 3.867 3.867 40.888\n w2_t0_out Si2 2 60.0 60.0 60.0 3.867 3.867 3.867 40.888\n w2_t1_in Si2 2 60.0 60.0 60.0 3.867 3.867 3.867 40.888\n\n abispg_num P [GPa] Max|F| eV/ang task_class status\n w0_t0_in None NaN NaN ScfTask Completed\n w0_t0_out 12 -3.638 3.180e+00 ScfTask Completed\n w0_t1_in None NaN NaN NscfTask Completed\n w1_t0_in None NaN NaN ScfTask Completed\n w1_t0_out 227 -5.212 7.430e-27 ScfTask Completed\n w1_t1_in None NaN NaN NscfTask Completed\n w2_t0_in None NaN NaN ScfTask Completed\n w2_t0_out 12 -4.192 2.095e+00 ScfTask Completed\n w2_t1_in None NaN NaN NscfTask Completed\n\n Atomic positions (columns give the site index):\n 0 \\\n w0_t0_in (Si, +0.970139 +0.000000 +0.014930)\n w0_t0_out (Si, +0.970139 +0.000000 +0.014930)\n w0_t1_in (Si, +0.970139 +0.000000 +0.014930)\n w1_t0_in (Si, +0.000000 +0.000000 +0.000000)\n w1_t0_out (Si, +0.000000 +0.000000 +0.000000)\n w1_t1_in (Si, +0.000000 +0.000000 +0.000000)\n w2_t0_in (Si, +0.029861 +0.000000 +0.985070)\n w2_t0_out (Si, +0.029861 +0.000000 +0.985070)\n w2_t1_in (Si, +0.029861 +0.000000 +0.985070)\n\n 1 status\n w0_t0_in (Si, +0.279861 +0.250000 +0.235070) Completed\n w0_t0_out (Si, +0.279861 +0.250000 +0.235070) Completed\n w0_t1_in (Si, +0.279861 +0.250000 +0.235070) Completed\n w1_t0_in (Si, +0.250000 +0.250000 +0.250000) Completed\n w1_t0_out (Si, +0.250000 +0.250000 +0.250000) Completed\n w1_t1_in (Si, +0.250000 +0.250000 +0.250000) Completed\n w2_t0_in (Si, +0.220139 +0.250000 +0.264930) Completed\n w2_t0_out (Si, +0.220139 +0.250000 +0.264930) Completed\n w2_t1_in (Si, +0.220139 +0.250000 +0.264930) Completed\n\n Finally, we can plot the electronic bands with the command:\n\n abirun.py flow_phfrozen_ebands ebands -p -t NscfTask\n\n to select only the band structures produced by the NscfTask.\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R
run_effmass_finitediff.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Effective masses with finite difference\n\nFlow to compute effective masses with finite difference method.\nDerivatives are computed along lines in k-space.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef make_scf_input(nspinor=1, usepaw=0):\n \"\"\"Returns GS input file for Silicon\"\"\"\n if nspinor == 1:\n pseudos = abidata.pseudos(\"14si.pspnc\") if usepaw == 0 else abidata.pseudos(\"Si.GGA_PBE-JTH-paw.xml\")\n else:\n pseudos = abidata.pseudos(\"Si_r.psp8\") if usepaw == 0 else abidata.pseudos(\"Si.GGA_PBE-JTH-paw.xml\")\n\n structure = dict(\n ntypat=1,\n natom=2,\n typat=[1, 1],\n znucl=14,\n #acell=3 * [10.26310667319252], # https://docs.abinit.org/tests/v7/Input/t82.in\n acell=3 * [10.2073557], # 5.4015 Ang\n rprim=[[0.0, 0.5, 0.5],\n [0.5, 0.0, 0.5],\n [0.5, 0.5, 0.0]],\n xred=[ [0.0 , 0.0 , 0.0],\n [0.25, 0.25, 0.25]],\n )\n\n # Build input\n scf_input = abilab.AbinitInput(structure=structure, pseudos=pseudos)\n\n # Set variables\n scf_input.set_vars(\n ecut=12,\n nband=8 if nspinor == 1 else 16,\n nspinor=nspinor,\n tolvrs=1e-8,\n )\n\n if scf_input.ispaw:\n scf_input.set_vars(pawecutdg=2 * scf_input[\"ecut\"])\n\n scf_input.set_kmesh(ngkpt=[8, 8, 8], shiftk=[0, 0, 0])\n\n return scf_input\n\n\ndef build_flow(options):\n # Set working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Get the SCF input (here NC with SOC)\n scf_input = make_scf_input(nspinor=2, usepaw=0)\n\n # Build the flow with different steps.\n from abipy.flowtk.effmass_works import EffMassLineWork\n flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)\n\n # Multiple calculations with different step for finite difference.\n for i, step in enumerate((0.01, 0.005)):\n if i == 0: den_node = None\n work = EffMassLineWork.from_scf_input(scf_input, k0_list=(0, 0, 0),\n step=step, npts=10,\n red_dirs=[[1, 0, 0], [1, 1, 0]],\n cart_dirs=[[1, 0, 0], [1, 1, 1], [1, 1, 0]],\n den_node=den_node)\n # Will start from the DEN file produced in the first iteration.\n if i == 0: den_node = work[0]\n flow.register_work(work)\n\n return flow\n\n\n# This block generates the thumbnails in the Abipy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_effmass_finitediff -s\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RaPS run_nonlinear.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Nnon-linear optical properties with DFPT\n\nFlow to compute non-linear optical properties with DFPT (static limit).\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.flowtk as flowtk\nimport abipy.data as abidata\n\nfrom abipy import abilab\n\n# NB: This flow requires abinit >= \"8.5.2\"\n\n\ndef make_scf_input(ecut=10, ngkpt=(8, 8, 8)):\n \"\"\"\n This function constructs an `AbinitInput` for performing a\n GS-SCF calculation in crystalline AlAs.\n\n Args:\n ecut: cutoff energy in Ha.\n ngkpt: 3 integers specifying the k-mesh for the electrons.\n\n Return:\n `AbinitInput` object\n \"\"\"\n # Initialize the AlAs structure from an internal database. Use the pseudos shipped with AbiPy.\n gs_inp = abilab.AbinitInput(structure=abidata.structure_from_ucell(\"AlAs\"),\n pseudos=abidata.pseudos(\"13al.981214.fhi\", \"33as.pspnc\"))\n\n # Set the value of the Abinit variables needed for GS runs.\n gs_inp.set_vars(\n nband=4,\n ecut=ecut,\n ngkpt=ngkpt,\n nshiftk=1,\n shiftk=[0.0, 0.0, 0.0],\n ixc=7,\n nstep=500,\n iscf=7,\n diemac=5.0,\n toldfe=1.0e-22,\n nbdbuf=0,\n kptopt=1,\n )\n\n #gs_inp.set_mnemonics(True)\n return gs_inp\n\n\ndef build_flow(options):\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n scf_input = make_scf_input(ecut=10, ngkpt=(6, 6, 6))\n return flowtk.NonLinearCoeffFlow.from_scf_input(options.workdir, scf_input)\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R|- run_from_files.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Starting a Flow from external files\n\nThis example shows how to build a flow for Nscf calculations\nin which the dependency is given by an external density file.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef make_scf_nscf_inputs(paral_kgb=1):\n \"\"\"Returns two input files: GS run and NSCF on a high symmetry k-mesh.\"\"\"\n multi = abilab.MultiDataset(structure=abidata.cif_file(\"si.cif\"),\n pseudos=abidata.pseudos(\"14si.pspnc\"), ndtset=2)\n\n # Global variables\n ecut = 6\n global_vars = dict(\n ecut=ecut,\n nband=8,\n nstep=15,\n paral_kgb=paral_kgb,\n )\n\n if multi.ispaw:\n global_vars.update(pawecutdg=2*ecut)\n\n multi.set_vars(global_vars)\n\n # Dataset 1 (GS run)\n multi[0].set_kmesh(ngkpt=[8, 8, 8], shiftk=[0, 0, 0])\n multi[0].set_vars(tolvrs=1e-6)\n\n # Dataset 2 (NSCF run)\n kptbounds = [\n [0.5, 0.0, 0.0], # L point\n [0.0, 0.0, 0.0], # Gamma point\n [0.0, 0.5, 0.5], # X point\n ]\n\n multi[1].set_kpath(ndivsm=6, kptbounds=kptbounds)\n multi[1].set_vars(tolwfr=1e-12)\n\n # Generate two input files for the GS and the NSCF run\n scf_input, nscf_input = multi.split_datasets()\n\n return scf_input, nscf_input\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Get the SCF and the NSCF input.\n scf_input, nscf_input = make_scf_nscf_inputs()\n\n # Build the flow.\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n # Create a Work, all tasks in work will start from the DEN file.\n # Note that the file must exist when the work is created\n # Use the standard approach based on tasks and works if\n # there's a node who needs a file produced in the future.\n work = flowtk.Work()\n den_filepath = abidata.ref_file(\"si_DEN.nc\")\n work.register_nscf_task(nscf_input, deps={den_filepath: \"DEN\"})\n flow.register_work(work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R܂ run_phonons.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow for phonons with DFPT\n\nThis example shows how to compute the phonon band structure of AlAs with AbiPy flows.\nSymmetries are taken into account: only q-points in the IBZ are generated and\nfor each q-point only the independent atomic perturbations are computed.\nThe final results (out_DDB, out_DVDB) will be produced automatically at the end of the run\nand saved in ``flow_phonons/outdata/``.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.abilab as abilab\nimport abipy.data as abidata\n\nfrom abipy import flowtk\n\n\ndef make_scf_input(paral_kgb=0):\n \"\"\"\n This function constructs the input file for the GS calculation:\n \"\"\"\n # Crystalline AlAs: computation of the second derivative of the total energy\n structure = abidata.structure_from_ucell(\"AlAs\")\n pseudos = abidata.pseudos(\"13al.981214.fhi\", \"33as.pspnc\")\n gs_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n\n gs_inp.set_vars(\n nband=4,\n ecut=2.0,\n ngkpt=[4, 4, 4],\n nshiftk=4,\n shiftk=[0.0, 0.0, 0.5, # This gives the usual fcc Monkhorst-Pack grid\n 0.0, 0.5, 0.0,\n 0.5, 0.0, 0.0,\n 0.5, 0.5, 0.5],\n #shiftk=[0, 0, 0],\n paral_kgb=paral_kgb,\n tolvrs=1.0e-10,\n ixc=1,\n diemac=9.0,\n #iomode=3,\n )\n\n return gs_inp\n\n\ndef build_flow(options):\n \"\"\"\n Create a `Flow` for phonon calculations. The flow has two works.\n\n The first work contains a single GS task that produces the WFK file used in DFPT\n Then we have multiple Works that are generated automatically\n in order to compute the dynamical matrix on a [4, 4, 4] mesh.\n Symmetries are taken into account: only q-points in the IBZ are generated and\n for each q-point only the independent atomic perturbations are computed.\n \"\"\"\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Build input for GS calculation\n scf_input = make_scf_input()\n\n # Create flow to compute all the independent atomic perturbations\n # corresponding to a [4, 4, 4] q-mesh.\n # Electric field and Born effective charges are also computed.\n flow = flowtk.PhononFlow.from_scf_input(options.workdir, scf_input,\n ph_ngqpt=(4, 4, 4), with_becs=True)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_phonons.py -s\n\nthen use:\n\n abirun.py flow_phonons history\n\nto get the list of actions perfomed by AbiPy to complete the flow.\nNote how the ``PhononWork`` has merged all the partial DDB files produced by the PhononTasks\n\n.. code-block:: bash\n\n ===================================================================================================================================\n ====================================== ===============================\n ===================================================================================================================================\n [Thu Dec 7 22:55:02 2017] Finalized set to True\n [Thu Dec 7 22:55:02 2017] Will call mrgddb to merge [ .... ]\n\nNow open the final DDB file with:\n\n abiopen.py flow_phonons/outdata/out_DDB\n\nand invoke anaddb to compute the phonon band structure and the phonon DOS with:\n\n.. code-block:: ipython\n\n In [1]: phbst_file, phdos_file = abifile.anaget_phbst_and_phdos_files()\n In [2]: %matplotlib\n In [3]: phbst_file.plot_phbands()\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R;Y Y run_gaas_ebands_soc.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Band structure with/without SOC\n\nThis example shows how to compute the band structure of GaAs with and without spin-orbit term.\nWe essentially build two BandStructureWork inside a loop over nspinor in [1, 2]\nnspinor = 1 corresponds to a standard collinear calculation for non-magnetic systems while\nnspinor = 2 gives us the non-collinear case with spinor wavefunctions required for the treatment of SOC.\nSome of the variables in the input files must be changed depending on the value of nspinor.\n\nWe use relativistic NC pseudos made of two terms: scalar pseudo + SOC term.\nThe SOC term can be deactivated with the input variable `so_psp`.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef build_flow(options):\n # Set working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n structure = abidata.structure_from_ucell(\"GaAs\")\n pseudos = abidata.pseudos(\"Ga-low_r.psp8\", \"As_r.psp8\")\n num_electrons = structure.num_valence_electrons(pseudos)\n #print(\"num_electrons:\", num_electrons)\n\n # Usa same shifts in all tasks.\n ngkpt = [4, 4, 4]\n shiftk = [\n [0.5, 0.5, 0.5],\n [0.5, 0.0, 0.0],\n [0.0, 0.5, 0.0],\n [0.0, 0.0, 0.5],\n ]\n\n # NSCF run on k-path with large number of bands\n kptbounds = [\n [0.5, 0.0, 0.0], # L point\n [0.0, 0.0, 0.0], # Gamma point\n [0.0, 0.5, 0.5], # X point\n ]\n\n # Initialize the flow.\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n for nspinor in [1, 2]:\n # Multi will contain two datasets (GS + NSCF) for the given nspinor.\n multi = abilab.MultiDataset(structure=structure, pseudos=pseudos, ndtset=2)\n\n # Global variables.\n multi.set_vars(\n ecut=20,\n nspinor=nspinor,\n nspden=1 if nspinor == 1 else 4,\n so_psp=\"*0\" if nspinor == 1 else \"*1\", # Important!\n #paral_kgb=1,\n )\n\n nband_occ = num_electrons // 2 if nspinor == 1 else num_electrons\n #print(nband_occ)\n\n # Dataset 1 (GS run)\n multi[0].set_vars(tolvrs=1e-8, nband=nband_occ + 4)\n multi[0].set_kmesh(ngkpt=ngkpt, shiftk=shiftk, kptopt=1 if nspinor == 1 else 4)\n\n multi[1].set_vars(iscf=-2, nband=nband_occ + 4, tolwfr=1.e-12)\n multi[1].set_kpath(ndivsm=10, kptbounds=kptbounds)\n\n # Get the SCF and the NSCF input.\n scf_input, nscf_input = multi.split_datasets()\n\n flow.register_work(flowtk.BandStructureWork(scf_input, nscf_input))\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_gaas_ebands_soc.py -s\n\nthen use:\n\n abirun.py flow_si_ebands ebands --plot -t NscfTask\n\nto analyze (and plot) the electronic bands produced by the NsfTasks of the Flow.\n\n\n\nAlternatively, one can start a GSR robot for the NscfTask with:\n\n abirun.py flow_gaas_ebands_soc/ robot GSR -t NscfTask\n\nand then plot the two band structure on the same figure with:\n\n.. code-block:: ipython\n\n In [1]: %matplotlib\n In [2]: robot.combiplot_ebands()\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RQb run_relax.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Relaxation Flow\n\nThis script shows how to perform a structural relaxation in two steps:\n\n 1) Relaxation of atomic positions with unit cell parameters fixed.\n 2) Full relaxation (atoms + cell) with the initial configuration read from step 1)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef make_ion_ioncell_inputs(paral_kgb=0):\n\n structure = abilab.Structure.from_file(abidata.cif_file(\"si.cif\"))\n\n # Perturb the structure (random perturbation of 0.1 Angstrom)\n # then compress the volume to trigger dilatmx.\n structure.perturb(distance=0.1)\n structure.scale_lattice(structure.volume * 0.6)\n\n global_vars = dict(\n ecut=4,\n ngkpt=[4, 4, 4],\n shiftk=[0, 0, 0],\n nshiftk=1,\n chksymbreak=0,\n paral_kgb=paral_kgb,\n iomode=3,\n #prtwf=0,\n )\n\n multi = abilab.MultiDataset(structure, pseudos=abidata.pseudos(\"14si.pspnc\"), ndtset=2)\n\n # Global variables\n multi.set_vars(global_vars)\n\n # Dataset 1 (Atom Relaxation)\n multi[0].set_vars(\n optcell=0,\n ionmov=2,\n tolrff=0.02,\n tolmxf=5.0e-5,\n #ntime=50,\n ntime=3, #To test the restart\n #dilatmx=1.1, # FIXME: abinit crashes if I don't use this\n )\n\n # Dataset 2 (Atom + Cell Relaxation)\n multi[1].set_vars(\n optcell=1,\n ionmov=2,\n ecutsm=0.5,\n dilatmx=1.02,\n tolrff=0.02,\n tolmxf=5.0e-5,\n strfact=100,\n #ntime=50,\n ntime=3, # To test the restart\n )\n\n #print(multi)\n\n ion_inp, ioncell_inp = multi.split_datasets()\n return ion_inp, ioncell_inp\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Create the flow\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n # Create a relaxation work and add it to the flow.\n ion_inp, ioncell_inp = make_ion_ioncell_inputs()\n\n relax_work = flowtk.RelaxWork(ion_inp, ioncell_inp)\n flow.register_work(relax_work)\n\n #bands_work = flowtk.BandStructureWork(scf_input, nscf_input)\n bands_work = flowtk.Work()\n deps = {relax_work[-1]: \"@structure\"}\n deps = {relax_work[-1]: [\"DEN\", \"@structure\"]} # --> This is not possible because the file ext is changed!\n #deps = {relax_work[-1]: [\"WFK\", \"@structure\"]} # --> This triggers an infamous bug in abinit\n\n bands_work.register_relax_task(ioncell_inp, deps=deps)\n flow.register_work(bands_work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RM{ run_screening.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Screening computation with different parameters\n\nThis examples shows how to compute the SCR file with different number of bands\nand different values of ecuteps in order to prepare further GW convergence studies.\nEach screening calculation is automatically parallelized over q-points and the\npartial SCR files are then merged with the mrgscr utility.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport numpy as np\n\nimport abipy.abilab as abilab\nimport abipy.data as abidata\nimport abipy.flowtk as flowtk\n\n\ndef build_flow(options):\n\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n\n # Initialize structure from string and a minimalistic variables:\n # natom, acell, rprimd and xred_symbols.\n\n structure = abilab.Structure.from_abistring(\"\"\"\nnatom 2\nacell 3*10.26 # Experimental lattice constants\nrprim 0.0 0.5 0.5 # FCC primitive vectors (to be scaled by acell)\n 0.5 0.0 0.5\n 0.5 0.5 0.0\n\nxred_symbols\n 0.0 0.0 0.0 Si\n 0.25 0.25 0.25 Si\n\"\"\")\n\n # Build the SCF input.\n scf_inp = abilab.AbinitInput(structure=structure, pseudos=abidata.pseudos(\"14si.pspnc\"))\n\n #nscf_nband_list = np.arange(2, 8, 2)\n nscf_nband_list = [25]\n max_nscf_nband = max(nscf_nband_list)\n\n #ecuteps_list = np.arange(2, 8, 2)\n ecuteps_list = [2]\n max_ecuteps = max(ecuteps_list)\n\n print(\"Number of valence electrons in the unit cell:\", scf_inp.num_valence_electrons)\n\n scf_inp.set_vars(\n ecut=4,\n nband=8,\n ngkpt=[4, 4, 4],\n shiftk=[0, 0, 0],\n tolvrs=1e-8,\n timopt=-1, # TODO: Add abirun.py option to extract timing data.\n #paral_kgb=1,\n #iomode=3,\n )\n\n #ebands_inp = scf_inp.make_ebands_input(ndivsm=15)\n\n # Build NSCF input on a k-mesh including empty states.\n nscf_inp = scf_inp.new_with_vars(\n nband=max_nscf_nband,\n #nbdbuf=10\n tolwfr=1e-20, # Too high. Should be ~1e-20\n iscf=-2\n )\n\n flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)\n\n # Band structure work to produce the WFK file with a NSCF run + empty states.\n bands_work = flowtk.BandStructureWork(scf_inp, nscf_inp) # dos_inputs=[nscf_inp])\n flow.register_work(bands_work)\n\n for ecuteps in ecuteps_list:\n for nscf_nband in nscf_nband_list:\n\n scr_inp = nscf_inp.new_with_vars(\n optdriver=3,\n ecuteps=ecuteps,\n nband=nscf_nband,\n )\n\n # Compute SCR file by splitting all the q-points.\n scr_work = flowtk.ScreeningWork.from_nscf_task(bands_work.nscf_task, scr_inp)\n\n # IMPORTANT:\n # If you alredy have a WFK file and you want to skip the SCF + NSCF part\n # build the scr_work using `from_wkf_filepath` instead of `from_nscf_task` e.g.:\n\n #scr_work = ScreeningWork.from_wfk_file(wfk_filepath, scr_inp)\n\n flow.register_work(scr_work)\n\n # This part is optional:\n # 1) set_readme sets the string that will be used to generate a human readable README.md file\n # 2) set_abipy_meta_json can be used to defined metadata that will be written to abipy_meta.json.\n scr_work.set_readme(f\"SCR computation with ecuteps={ecuteps} and nband={nscf_nband}\")\n scr_work.set_abipy_meta_json(dict(ecuteps=ecuteps, nband=nscf_nband))\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK Rlqz run_optic.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Optic Flow\n\nThis example shows how to create a flow to compute optical spectra with Optic\n(independent particle approximation, no local field effects) and perform\na convergence study with respect to the k-point sampling.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef build_flow(options, paral_kgb=0):\n \"\"\"\n Build flow for the calculation of optical properties with optic + band structure\n along high-symmetry k-path. DDK are computed with 3 k-meshes of increasing density\n to monitor the convergece of the spectra.\n \"\"\"\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n multi = abilab.MultiDataset(structure=abidata.structure_from_ucell(\"GaAs\"),\n pseudos=abidata.pseudos(\"31ga.pspnc\", \"33as.pspnc\"), ndtset=2)\n\n # Usa same shifts in all tasks.\n shiftk = [[0.5, 0.5, 0.5],\n [0.5, 0.0, 0.0],\n [0.0, 0.5, 0.0],\n [0.0, 0.0, 0.5]]\n\n # Global variables.\n multi.set_vars(ecut=2, paral_kgb=paral_kgb)\n\n # Dataset 1 (GS run)\n multi[0].set_vars(tolvrs=1e-8, nband=4)\n multi[0].set_kmesh(ngkpt=[4, 4, 4], shiftk=shiftk)\n\n # NSCF run on k-path with large number of bands\n multi[1].set_vars(iscf=-2, nband=20, tolwfr=1.e-9)\n multi[1].set_kpath(ndivsm=10)\n\n # Initialize the flow.\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n # GS to get the density + NSCF along the path.\n scf_inp, nscf_inp = multi.split_datasets()\n bands_work = flowtk.BandStructureWork(scf_inp, nscf_inp)\n flow.register_work(bands_work)\n\n # Build OpticInput used to compute optical properties.\n optic_input = abilab.OpticInput(\n broadening=0.002, # Value of the smearing factor, in Hartree\n domega=0.0003, # Frequency mesh.\n maxomega=0.3,\n scissor=0.000, # Scissor shift if needed, in Hartree\n tolerance=0.002, # Tolerance on closeness of singularities (in Hartree)\n num_lin_comp=2, # Number of components of linear optic tensor to be computed\n lin_comp=(11, 33), # Linear coefficients to be computed (x=1, y=2, z=3)\n num_nonlin_comp=2, # Number of components of nonlinear optic tensor to be computed\n nonlin_comp=(123, 222), # Non-linear coefficients to be computed\n )\n\n # ddk_nband is fixed here, in principle it depends on nelect and the frequency range in chi(w).\n ddk_nband = 20\n\n # Perform converge study wrt ngkpt (shiftk is constant).\n ngkpt_convergence = [[4, 4, 4], [8, 8, 8], [16, 16, 16]]\n\n from abipy.flowtk.dfpt_works import NscfDdksWork\n for ddk_ngkpt in ngkpt_convergence:\n # Build work for NSCF from DEN produced by the first GS task + 3 DDKs.\n # All tasks use more bands and a denser k-mesh defined by ddk_ngkpt.\n ddks_work = NscfDdksWork.from_scf_task(bands_work[0], ddk_ngkpt, shiftk, ddk_nband)\n flow.register_work(ddks_work)\n\n # Build optic task to compute chi with this value of ddk_ngkpt.\n optic_task = flowtk.OpticTask(optic_input, nscf_node=ddks_work.task_with_ks_energies,\n ddk_nodes=ddks_work.ddk_tasks, use_ddknc=False)\n ddks_work.register_task(optic_task)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_optic.py -s\n\nthen use:\n\n abirun.py flow_optic robot optic\n\nto create a robot for OPTIC.nc files. Then inside the ipytho shell type:\n\n.. code-block:: ipython\n\n In [1]: %matplotlib\n In [2]: robot.plot_linopt_convergence()\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R4} " run_becs_and_epsilon_vs_kpts.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow for Born effective charges and dielectric tensors with DFPT\n\nThis example shows how to compute the Born effective charges and\nthe dielectric tensors (e0, einf) of AlAs with AbiPy flows.\nWe perform multiple calculations by varying the number of k-points\nin order to analyze the convergence of the results wrt nkpt\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.abilab as abilab\nimport abipy.data as abidata\n\nfrom abipy import flowtk\n\n\ndef make_scf_input(ngkpt, paral_kgb=0):\n \"\"\"\n This function constructs the input file for the GS calculation for a given IBZ sampling.\n \"\"\"\n # Crystalline AlAs: computation of the second derivative of the total energy\n structure = abidata.structure_from_ucell(\"AlAs\")\n pseudos = abidata.pseudos(\"13al.981214.fhi\", \"33as.pspnc\")\n gs_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n\n gs_inp.set_vars(\n nband=4,\n ecut=2.0,\n ngkpt=ngkpt,\n nshiftk=4,\n shiftk=[0.0, 0.0, 0.5, # This gives the usual fcc Monkhorst-Pack grid\n 0.0, 0.5, 0.0,\n 0.5, 0.0, 0.0,\n 0.5, 0.5, 0.5],\n #shiftk=[0, 0, 0],\n paral_kgb=paral_kgb,\n tolvrs=1.0e-10,\n ixc=1,\n diemac=9.0,\n #iomode=3,\n )\n\n return gs_inp\n\n\ndef build_flow(options):\n \"\"\"\n Create a `Flow` for phonon calculations. The flow has two works.\n\n The first work contains a single GS task that produces the WFK file used in DFPT\n Then we have multiple Works that are generated automatically\n in order to compute the dynamical matrix on a [4, 4, 4] mesh.\n Symmetries are taken into account: only q-points in the IBZ are generated and\n for each q-point only the independent atomic perturbations are computed.\n \"\"\"\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n flow = flowtk.Flow(workdir=options.workdir)\n\n for ngkpt in [(2, 2, 2), (4, 4, 4), (8, 8, 8)]:\n # Build input for GS calculation with different k-meshes\n scf_input = make_scf_input(ngkpt=ngkpt)\n flow.register_scf_task(scf_input, append=True)\n\n for scf_task in flow[0]:\n bec_work = flowtk.BecWork.from_scf_task(scf_task)\n flow.register_work(bec_work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_becs_and_epsilon_vs_kpts.py -s\n\nUse:\n\n abirun.py flow_becs_and_epsilon_vs_kpts/ listext DDB\n\nto list all the DDB files produced by the flow.\n\nNow use abicomp.py to create a DdbRobot to analyze the DDB files produced by the 3 Works:\n\n abicomp.py ddb flow_becs_and_epsilon_vs_kpts/w*/outdata/out_DDB\n\nthe inside the ipython terminal use the anacompare methods to analyze the results. e.g.\n\n.. code-block:: ipython\n\n In [1]: r = robot.anacompare_epsinf()\n In [2]: r.df\n Out[2]:\n xx yy zz yz xz xy formula chneut \\\n 0 13.584082 13.584082 13.584082 0.0 0.0 0.0 Al1 As1 1\n 0 9.268425 9.268425 9.268425 0.0 0.0 0.0 Al1 As1 1\n 0 8.873178 8.873178 8.873178 0.0 0.0 0.0 Al1 As1 1\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK Rlz run_flexoelectric.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flexoelectric Tensor\n\nThis example shows how to compute the dynamical matrix of GaP on user-defined q-mesh\nincluding Born effective charges, the macroscopic dielectric matric and the dynamical quadrupoles Q*.\nThe final results (out_DDB, out_DVDB) will be produced automatically at the end of the run\nand saved in ``flow_phonons_with_quad/outdata/``.\n\nThe Q* tensor may be needed to improve the accuracy of the Fourier interpolation of the phonon frequencies,\nespecially in the long-wavelength limit |q| --> 0.\nThis example is based on \nNote that only selected features are compatible with dynamical quadrupoles.\nPlease consult \n\nhttps://docs.abinit.org/tests/tutorespfn/Input/tlw_1.abi\n# Linear response function and long-wave magnitudes calculation\n# for a 5% distorted 2 atom Silicon cell\n# (M. Royo, 7.11.2019)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.abilab as abilab\nimport abipy.data as abidata\n\nfrom abipy import flowtk\n\n\ndef build_flow(options):\n \"\"\"\n Create a `Flow` for phonon calculations including\n eps_inf, Born effective charges and dynamical quadrupoles\n \"\"\"\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n pseudos = abidata.pseudos(\"14si.fhi\")\n\n # Initialize the structure from an abinit string\n # Other approaches (e.g. from cif files) are available as well.\n structure = abilab.Structure.from_abistring(\"\"\"\n#Definition of the unit cell\n#***************************\nacell 10.102 10.6 9.4\nrprim 0.0000000000 0.5000000000 0.500000000\n 0.5000000000 0.0000000000 0.500000000\n 0.5000000000 0.5000000000 0.000000000\n\n\n#Definition of the atom types and positions\n#******************************************\nntypat 1\nznucl 14\nnatom 2\ntypat 2*1\nxred\n 0.0500000 -0.0500000 0.0000000\n 0.2000000 0.3000000 0.2000000\n\"\"\")\n # Build input for GS calculation\n scf_input = abilab.AbinitInput(structure, pseudos=pseudos)\n\n # We use parameters similar to the ones in https://docs.abinit.org/tests/tutorespfn/Input/tlw_4.abi\n scf_input.set_vars(\n nband=4,\n ecut=4.0,\n ngkpt=[4, 4, 4],\n shiftk=[\n [0.5, 0.5, 0.5],\n [0.5, 0.0, 0.0],\n [0.0, 0.5, 0.0],\n [0.0, 0.0, 0.5],\n ],\n diemac=13.0,\n nstep=100,\n #tolvrs=1.0e-10,\n tolvrs=1.0e-18, # This is the value used in tlw_4.abi\n # but it is not always possible to reach this precision in more complex systems.\n useylm=1,\n ixc=7\n #iomode=3,\n #paral_kgb=1,\n )\n\n # At the time of writing, Flexoelectric calculations are implemented only for\n # NC LDA scalar-relativistic pseudos without non-linear core corrections.\n # This section shows how to use the Pseudo API to perform this kind of check\n # before runnnig the calculation.\n for pseudo in scf_input.pseudos:\n # print(pseudo)\n if not pseudo.isnc:\n raise RuntimeError(\"Only NC pseudos are compatible with Q*\")\n if pseudo.has_nlcc:\n raise RuntimeError(\"NLCC is not compatible with Q*\")\n if pseudo.xc.type != \"LDA\":\n raise RuntimeError(\"Only LDA is compatible with Q*\")\n\n # Initialize the flow\n flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)\n\n # Compute phonons on the ddb_ngqpt q-mesh.\n # Include Born effective charges and dynamical quadrupoles via `with_quad=True`.\n #\n ddb_ngqpt = [1, 1, 1]\n #ddb_ngqpt = [4, 4, 4]\n ph_work = flowtk.PhononWork.from_scf_input(scf_input, qpoints=ddb_ngqpt,\n is_ngqpt=True, with_becs=True, with_flexoe=True)\n\n # Add the phonon work to the flow\n flow.register_work(ph_work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ݄R@} } run_si_ebands.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Band structure Flow\n\nFlow to compute the band structure of silicon.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef make_scf_nscf_inputs(paral_kgb=0, usepaw=0):\n \"\"\"Returns two input files: GS run and NSCF on a high symmetry k-mesh.\"\"\"\n pseudos = abidata.pseudos(\"14si.pspnc\") if usepaw == 0 else abidata.pseudos(\"Si.GGA_PBE-JTH-paw.xml\")\n\n # Get structure from cif file.\n multi = abilab.MultiDataset(structure=abidata.cif_file(\"si.cif\"), pseudos=pseudos, ndtset=2)\n\n # Global variables\n ecut = 6\n multi.set_vars(\n ecut=ecut,\n nband=8,\n paral_kgb=paral_kgb,\n iomode=3,\n timopt=-1,\n )\n\n if multi.ispaw:\n multi.set_vars(pawecutdg=2 * ecut)\n\n # Dataset 1 (GS run)\n multi[0].set_kmesh(ngkpt=[8, 8, 8], shiftk=[0, 0, 0])\n multi[0].set_vars(tolvrs=1e-6)\n\n # Dataset 2 (NSCF run)\n kptbounds = [\n [0.5, 0.0, 0.0], # L point\n [0.0, 0.0, 0.0], # Gamma point\n [0.0, 0.5, 0.5], # X point\n ]\n\n multi[1].set_kpath(ndivsm=6, kptbounds=kptbounds)\n multi[1].set_vars(tolwfr=1e-12)\n\n # Generate two input files for the GS and the NSCF run\n scf_input, nscf_input = multi.split_datasets()\n return scf_input, nscf_input\n\n\ndef build_flow(options):\n # Set working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Get the SCF and the NSCF input.\n scf_input, nscf_input = make_scf_nscf_inputs()\n\n # Build the flow.\n return flowtk.bandstructure_flow(options.workdir, scf_input, nscf_input, manager=options.manager)\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_si_ebands.py -s\n\nthen use:\n\n abirun.py flow_si_ebands ebands --plot\n\nto analyze (and plot) the electronic bands produced by the Flow.\n\n.. code-block:: bash\n\n KS electronic bands:\n nsppol nspinor nspden nkpt nband nelect fermie formula natom \\\n w0_t0 1 1 1 29 8 8.0 5.598 Si2 2\n w0_t1 1 1 1 14 8 8.0 5.598 Si2 2\n\n angle0 angle1 angle2 a b c volume abispg_num scheme \\\n w0_t0 60.0 60.0 60.0 3.867 3.867 3.867 40.888 227 none\n w0_t1 60.0 60.0 60.0 3.867 3.867 3.867 40.888 227 none\n\n occopt tsmear_ev bandwidth_spin0 fundgap_spin0 dirgap_spin0 \\\n w0_t0 1 0.272 11.856 0.562 2.532\n w0_t1 1 0.272 11.856 0.524 2.532\n\n task_class ncfile status\n w0_t0 ScfTask flow_si_ebands/w0/t0/outdata/out_GSR.nc Completed\n w0_t1 NscfTask flow_si_ebands/w0/t1/outdata/out_GSR.nc Completed\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RZM9 9 run_relax_and_ebands.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow for Relaxation + Bands\n\nThis script shows how to perform a structural relaxation and a band structure calculation\n\nWARNING: The API could change!\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef make_ion_ioncell_inputs(paral_kgb=0):\n pseudos = abidata.pseudos(\"14si.pspnc\")\n structure = abilab.Structure.from_file(abidata.cif_file(\"si.cif\"))\n\n # Perturb the structure (random perturbation of 0.1 Angstrom)\n # then compress the volume to trigger dilatmx.\n #structure.perturb(distance=0.1)\n #structure.scale_lattice(structure.volume * 0.6)\n\n global_vars = dict(\n ecut=28,\n ngkpt=[4,4,4],\n shiftk=[0,0,0],\n nshiftk=1,\n chksymbreak=0,\n paral_kgb=paral_kgb,\n #prtwf=0,\n )\n\n multi = abilab.MultiDataset(structure, pseudos=pseudos, ndtset=2)\n\n # Global variables\n multi.set_vars(global_vars)\n\n # Dataset 1 (Atom Relaxation)\n multi[0].set_vars(\n optcell=0,\n ionmov=2,\n tolrff=0.02,\n tolmxf=5.0e-5,\n ntime=50,\n #ntime=3, #To test the restart\n #dilatmx=1.1, # FIXME: abinit crashes if I don't use this\n )\n\n # Dataset 2 (Atom + Cell Relaxation)\n multi[1].set_vars(\n optcell=1,\n ionmov=2,\n ecutsm=0.5,\n dilatmx=1.02,\n tolrff=0.02,\n tolmxf=5.0e-5,\n strfact=100,\n ntime=50,\n #ntime=3, # To test the restart\n )\n\n ion_inp, ioncell_inp = multi.split_datasets()\n return ion_inp, ioncell_inp\n\n\ndef make_scf_nscf_inputs(paral_kgb=1):\n \"\"\"Returns two input files: GS run and NSCF on a high symmetry k-mesh.\"\"\"\n pseudos = abidata.pseudos(\"14si.pspnc\")\n #pseudos = data.pseudos(\"Si.GGA_PBE-JTH-paw.xml\")\n\n multi = abilab.MultiDataset(structure=abidata.cif_file(\"si.cif\"), pseudos=pseudos, ndtset=2)\n\n # Global variables\n ecut = 28\n global_vars = dict(ecut=ecut,\n nband=8,\n timopt=-1,\n istwfk=\"*1\",\n nstep=15,\n paral_kgb=paral_kgb,\n )\n\n if multi.ispaw:\n global_vars.update(pawecutdg=2*ecut)\n\n multi.set_vars(global_vars)\n\n # Dataset 1 (GS run)\n multi[0].set_kmesh(ngkpt=[8,8,8], shiftk=[0,0,0])\n multi[0].set_vars(tolvrs=1e-6)\n\n # Dataset 2 (NSCF run)\n kptbounds = [\n [0.5, 0.0, 0.0], # L point\n [0.0, 0.0, 0.0], # Gamma point\n [0.0, 0.5, 0.5], # X point\n ]\n\n multi[1].set_kpath(ndivsm=6, kptbounds=kptbounds)\n multi[1].set_vars(tolwfr=1e-12)\n\n # Generate two input files for the GS and the NSCF run\n scf_input, nscf_input = multi.split_datasets()\n return scf_input, nscf_input\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Create the flow\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n paral_kgb = 1\n #paral_kgb = 0 # This one is OK\n\n # Create a relaxation work and add it to the flow.\n ion_inp, ioncell_inp = make_ion_ioncell_inputs(paral_kgb=paral_kgb)\n\n relax_work = flowtk.RelaxWork(ion_inp, ioncell_inp)\n flow.register_work(relax_work)\n\n scf_inp, nscf_inp = make_scf_nscf_inputs(paral_kgb=paral_kgb)\n\n bands_work = flowtk.BandStructureWork(scf_inp, nscf_inp)\n\n # The scf task in bands work restarts from the DEN file of the last task in relax_work\n if paral_kgb == 0:\n # cg works fine if we restart from the WFK\n bands_work.scf_task.add_deps({relax_work[-1]: \"WFK\"})\n else:\n # --> This triggers an infamous bug in abinit\n bands_work.scf_task.add_deps({relax_work[-1]: \"WFK\"})\n\n # --> This is ok if we used fourier_interp to change the FFT mesh.\n #bands_work.scf_task.add_deps({relax_work[-1]: \"DEN\"})\n\n # All task in bands_work will fetch the relaxed structure from the last task in relax_work\n for task in bands_work:\n task.add_deps({relax_work[-1]: \"@structure\"})\n\n flow.register_work(bands_work)\n flow.allocate()\n flow.use_smartio()\n flow.set_garbage_collector()\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R,0 0 run_effmass_dfpt.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Effective masses with DFPT\n\nFlow to compute effective masses with DFPT.\nTwo options are available:\n\n - EffMassDFPTWork --> Run DFPT calculation directly assuming the location\n of the band edges is already known.\n - EffMassAutoDFPTWork --> Run NSCF calculation to find band edges, then use DFPT.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef make_scf_input(usepaw=0, nspinor=1):\n \"\"\"Returns input for GS-SCF calculation.\"\"\"\n if nspinor == 1:\n pseudos = abidata.pseudos(\"14si.pspnc\") if usepaw == 0 else abidata.pseudos(\"Si.GGA_PBE-JTH-paw.xml\")\n else:\n pseudos = abidata.pseudos(\"Si_r.psp8\") if usepaw == 0 else abidata.pseudos(\"Si.GGA_PBE-JTH-paw.xml\")\n\n # See https://docs.abinit.org/tests/v7/Input/t82.in\n structure = dict(\n ntypat=1,\n natom=2,\n typat=[1, 1],\n znucl=14,\n #acell=3 * [10.26310667319252],\n acell=3 * [10.2073557], # 5.4015 Ang\n rprim=[[0.0, 0.5, 0.5],\n [0.5, 0.0, 0.5],\n [0.5, 0.5, 0.0]],\n xred=[[0.0 , 0.0 , 0.0],\n [0.25, 0.25, 0.25]],\n )\n\n scf_input = abilab.AbinitInput(structure=structure, pseudos=pseudos)\n\n # Global variables\n nband = 8 if nspinor == 1 else 16\n scf_input.set_vars(\n ecut=8,\n nband=nband,\n nspinor=nspinor,\n nstep=100,\n tolvrs=1e-8,\n )\n\n if scf_input.ispaw:\n scf_input.set_vars(pawecutdg=2 * scf_input[\"ecut\"])\n\n # Set k-mesh\n scf_input.set_kmesh(ngkpt=[8, 8, 8], shiftk=[0, 0, 0])\n\n return scf_input\n\n\ndef build_flow(options):\n # Set working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Get the SCF input (without SOC)\n scf_input = make_scf_input(nspinor=1, usepaw=1)\n\n # Build the flow.\n from abipy.flowtk.effmass_works import EffMassDFPTWork, EffMassAutoDFPTWork\n flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)\n\n # Compute effective masses for each k in k0_list.\n # effmass_bands_f90 defines the band range for each k in k0_list\n # Here we are interested in the effective masses at the Gamma point for the valence bands\n effmass_bands_f90 = [1, 4] if scf_input[\"nspinor\"] == 1 else [1, 8]\n work = EffMassDFPTWork.from_scf_input(scf_input, k0_list=(0, 0, 0),\n effmass_bands_f90=effmass_bands_f90)\n flow.register_work(work)\n\n # or use this Work to detect band edges automatically but increase ndivsm and decrease tolwfr!\n # you may want to use a negative value of ndivsm (e.g. -20) to use the pymatgen density_line\n # convention. This is useful to avoid problems with high-symmetry\n # k-paths containing very small segments.\n # In this case, indeed, ndivsm > 0 (Abinit variable) can easily generate thousands of k-points.\n work = EffMassAutoDFPTWork.from_scf_input(scf_input, ndivsm=-5, tolwfr=1e-12)\n flow.register_work(work)\n\n return flow\n\n\n# This block generates the thumbnails in the Abipy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_effmass_dfpt -s\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R.Ɇ$ run_phonons_wkq.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Phonons with WFQ files (q-mesh denser than k-mesh)\n\nThis example shows how to use WFQ files to compute phonons on a q-mesh\nthat is not necessarily commensurate with the k-mesh used for electrons.\nSymmetries are taken into account: only q-points in the IBZ are generated.\nMoreover WFQ files are computed only if k + q does not belong to the initial mesh and,\nfor each q-point, only the independent atomic perturbations are computed.\nThe final results (out_DDB, out_DVDB) will be produced automatically at the end of the run\nand saved in the ``outdata/`` of the work.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.abilab as abilab\nimport abipy.data as abidata\n\nfrom abipy import flowtk\n\n\ndef make_scf_input(paral_kgb=0):\n \"\"\"\n This function constructs the input file for the GS calculation:\n \"\"\"\n # Crystalline AlAs: computation of the second derivative of the total energy\n structure = abidata.structure_from_ucell(\"AlAs\")\n pseudos = abidata.pseudos(\"13al.981214.fhi\", \"33as.pspnc\")\n gs_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n\n gs_inp.set_vars(\n nband=4,\n ecut=2.0,\n ngkpt=[2, 2, 2],\n nshiftk=1,\n shiftk=[0, 0, 0],\n #nshiftk=4,\n #shiftk=[0.0, 0.0, 0.5, # This gives the usual fcc Monkhorst-Pack grid\n # 0.0, 0.5, 0.0,\n # 0.5, 0.0, 0.0,\n # 0.5, 0.5, 0.5],\n paral_kgb=paral_kgb,\n tolvrs=1.0e-10,\n diemac=9.0,\n )\n\n return gs_inp\n\n\ndef build_flow(options):\n \"\"\"\n Create a `Flow` for phonon calculations. The flow has two works.\n \"\"\"\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n flow = flowtk.Flow(workdir=options.workdir)\n\n # Build input for GS calculation and create first work with 1 ScfTask.\n scf_input = make_scf_input()\n work = flow.register_scf_task(scf_input)\n scf_task = work[0]\n\n # Create work for phonon calculation with WFQ files with a [4, 4, 4] q-mesh.\n # Electric field and Born effective charges are also computed.\n wfkq_work = flowtk.PhononWfkqWork.from_scf_task(scf_task, ngqpt=[4, 4, 4], with_becs=True)\n flow.register_work(wfkq_work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_phonons_wfq.py -s\n\nthen use:\n\n abirun.py flow_phonons_wkq history\n\nto get the list of actions perfomed by AbiPy to complete the flow.\nNote how the ``PhononWfkqWork`` has merged all the partial DDB/DVDB files\nand removed the WFQ files at runtime to optimize the disk space.\n\n.. code-block:: bash\n\n =========================================================================================================================\n ============================= =============================\n =========================================================================================================================\n [Tue Sep 18 00:04:18 2018] Removing WFQ: flow_phonons_wkq/w1/t5/outdata/out_WFQ\n [Tue Sep 18 00:04:54 2018] Removing WFQ: flow_phonons_wkq/w1/t14/outdata/out_WFQ\n\nNow open the final DDB file with:\n\n abiopen.py flow_phonons_wkq/w1/outdata/out_DDB\n\nand invoke anaddb to compute the phonon band structure and the phonon DOS with:\n\n.. code-block:: ipython\n\n In [1]: phbst_file, phdos_file = abifile.anaget_phbst_and_phdos_files()\n In [2]: %matplotlib\n In [3]: phbst_file.plot_phbands()\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R$2 run_eph_pot.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow to compute e-ph scattering potentials\n\nThis example shows how to compute e-ph scattering potentials\nalong a q-path, merge the POT files in the DVDB file and use the\nDVDB and the DDB file to analyze the average over the unit cell of the\nperiodic part as a function of q\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.abilab as abilab\nimport abipy.data as abidata\n\nfrom abipy import flowtk\n\n\ndef make_scf_input(ngkpt):\n \"\"\"\n This function constructs the input file for the GS calculation:\n \"\"\"\n structure = dict(\n angdeg=3*[60.0],\n acell=3*[7.1992351952],\n natom=2,\n ntypat=2,\n typat=[1, 2],\n znucl=[31, 15],\n xred=[\n 0.0000000000, 0.0000000000, 0.0000000000,\n 0.2500000000, 0.2500000000, 0.2500000000,\n ])\n\n pseudos = abidata.pseudos(\"Ga.oncvpsp\", \"P.psp8\")\n gs_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n\n gs_inp.set_vars(\n nband=8,\n ecut=20.0, # Too low\n ngkpt=ngkpt,\n nshiftk=1,\n shiftk=[0, 0, 0],\n tolvrs=1.0e-8,\n nstep=150,\n paral_kgb=0,\n )\n\n return gs_inp\n\n\ndef build_flow(options):\n \"\"\"\n Create a `Flow` for phonon calculations. The flow has two works.\n\n The first work contains a single GS task that produces the WFK file used in DFPT\n Then we have multiple Works that are generated automatically\n in order to compute the dynamical matrix on a [2, 2, 2] mesh.\n Symmetries are taken into account: only q-points in the IBZ are generated and\n for each q-point only the independent atomic perturbations are computed.\n \"\"\"\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Use 2x2x2 both for k-mesh and q-mesh\n # Build input for GS calculation\n scf_input = make_scf_input(ngkpt=(2, 2, 2))\n\n # Create flow to compute all the independent atomic perturbations\n # corresponding to a [4, 4, 4] q-mesh.\n # Electric field and Born effective charges are also computed.\n from abipy.flowtk.eph_flows import EphPotFlow\n ngqpt = [2, 2, 2]\n\n qpath_list = [\n +0.10000, +0.10000, +0.10000, # L -> G\n +0.00000, +0.00000, +0.00000, # $\\Gamma$\n +0.10000, +0.00000, +0.10000, # G -> X\n\n #+0.50000, +0.50000, +0.50000, # L\n #+0.00000, +0.00000, +0.00000, # $\\Gamma$\n #+0.50000, +0.00000, +0.50000, # X\n #+0.50000, +0.25000, +0.75000, # W\n #+0.37500, +0.37500, +0.75000, # K\n #+0.00000, +0.00000, +0.00000, # $\\Gamma$\n #+0.50000, +0.25000, +0.75000, # W\n #+0.62500 +0.25000 +0.62500 # U\n #+0.50000 +0.25000 +0.75000 # W\n #+0.50000 +0.50000 +0.50000 # L\n #+0.37500 +0.37500 +0.75000 # K\n #+0.62500 +0.25000 +0.62500 # U\n #+0.50000 +0.00000 +0.50000 # X\n ]\n\n # Use small ndivsm to reduce computing time.\n flow = EphPotFlow.from_scf_input(options.workdir, scf_input,\n ngqpt, qpath_list, ndivsm=2, ddk_tolerance={\"tolwfr\": 1e-12},\n with_becs=True)\n\n return flow\n\n\n# This block generates the thumbnails in the Abipy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R.*' run_frohlich_zpr.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Estimate the ZPR at the band edges with the generalized Frohlich model\n\nFlow to estimate the zero-point renormalization at the band edges\nusing the generalized Frohlich model. The flow uses DFPT to compute\nthe effective masses at the band edges (automatically detected by performing a NSCF run with a k-path),\nBECS, eps_inf and phonon frequencies at Gamma\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef make_scf_input(usepaw=0):\n \"\"\"Returns the GS input file\"\"\"\n # Here we use parameters similar to https://docs.abinit.org/tests/v8/Input/t57.in\n pseudos = abidata.pseudos(\"Ca.psp8\", \"O.psp8\")\n\n structure = dict(\n acell=3 * [9.136],\n xred=[\n 0.0000000000, 0.0000000000, 0.0000000000,\n 0.5000000000, 0.5000000000, 0.5000000000],\n rprim=[\n 0 , 0.5, 0.5,\n 0.5, 0 , 0.5,\n 0.5, 0.5, 0],\n typat=[1, 2],\n natom=2,\n ntypat=2,\n znucl=[20, 8],\n )\n\n scf_input = abilab.AbinitInput(structure=structure, pseudos=pseudos)\n\n scf_input.set_vars(\n nband=12,\n nbdbuf=2,\n diemac=6,\n ecut=30, # Underconverged ecut.\n #ecut=15,\n nstep=100,\n tolvrs=1e-16,\n kptrlatt=[-2, 2, 2, # In cartesian coordinates, this grid is simple cubic\n 2, -2, 2,\n 2, 2, -2],\n )\n\n return scf_input\n\n\ndef build_flow(options):\n # Set working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Build the SCF input.\n scf_input = make_scf_input()\n\n # Build the flow.\n from abipy.flowtk.effmass_works import FrohlichZPRFlow\n flow = FrohlichZPRFlow.from_scf_input(options.workdir, scf_input, ndivsm=4, tolwfr=1e-16,\n manager=options.manager)\n\n return flow\n\n\n# This block generates the thumbnails in the Abipy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_frohlich_zpr -s\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R$ run_frohlich_zpr_from_ddb.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Estimate the ZPR of band edges with generalized Frohlich model\n\nFlow to estimate the zero-point renormalization at the band edges\nusing the generalized Frohlich model. The flow uses DFPT to compute\nthe effective masses at the band edges (automatically detected by performing a NSCF run with a k-path),\nand uses an external DDB file providing BECS, eps_inf and phonon frequencies at Gamma.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef build_flow(options):\n\n # Set working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Get structure from DDB file.\n ddb_path = abidata.ref_file(\"refs/mgo_v8t57/mgo_zpr_t57o_DS3_DDB\")\n with abilab.abiopen(ddb_path) as ddb:\n structure = ddb.structure\n\n # Build SCF input using structure from DDB file.\n pseudos = abidata.pseudos(\"Ca.psp8\", \"O.psp8\")\n scf_input = abilab.AbinitInput(structure=structure, pseudos=pseudos)\n\n # Set other input variables. These quantities are system-depedent.\n # Here we use parameters similar to https://docs.abinit.org/tests/v8/Input/t57.in\n scf_input.set_vars(\n nband=12,\n nbdbuf=2,\n diemac=6,\n ecut=30, # Underconverged ecut.\n #ecut=15,\n nstep=100,\n tolvrs=1e-16,\n kptrlatt=[-2, 2, 2, # In cartesian coordinates, this grid is simple cubic\n 2, -2, 2,\n 2, 2, -2],\n )\n\n # Build the flow to detect band edges, compute effective masses and finally obtain an estimate for the ZPR\n # BECS/phonons/eps_inf are taken from ddb_node.\n from abipy.flowtk.effmass_works import FrohlichZPRFlow\n flow = FrohlichZPRFlow.from_scf_input(options.workdir, scf_input, ddb_node=ddb_path, ndivsm=2, tolwfr=1e-14,\n manager=options.manager)\n return flow\n\n\n# This block generates the thumbnails in the Abipy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_frohlich_zpr_from_ddb.py -s\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R6
run_gkq.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow to compute e-ph matrix elements along a q-path\n\nThis example shows how to compute the e-ph matrix elements in AlAs along a q-path with AbiPy flows.\nThe final results are stored in the GKQ.nc file (one file for q-point) in the outdata of each task.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.abilab as abilab\nimport abipy.data as abidata\n\nfrom abipy import flowtk\n\n\ndef make_scf_input(ngkpt):\n \"\"\"\n This function constructs the input file for the GS calculation:\n \"\"\"\n structure = abidata.structure_from_ucell(\"AlAs\")\n pseudos = abidata.pseudos(\"13al.981214.fhi\", \"33as.pspnc\")\n gs_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n\n gs_inp.set_vars(\n nband=6,\n ecut=6.0,\n ngkpt=ngkpt,\n nshiftk=1,\n shiftk=[0, 0, 0],\n tolvrs=1.0e-10,\n )\n\n return gs_inp\n\n\ndef build_flow(options):\n \"\"\"\n Create a `Flow` for the computation of e-ph matrix elements\n \"\"\"\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Use 2x2x2 both for k-mesh.\n # Build input for GS calculation\n scf_input = make_scf_input(ngkpt=(2, 2, 2))\n\n # corresponding to a [2, 2, 2] q-mesh.\n ngqpt = (2, 2, 2)\n\n # Create flow to compute all the independent atomic perturbations\n # Use ndivsm = 0 to pass an explicit list of q-points.\n # If ndivsm > 0, qpath_list is interpreted as a list of boundaries for the q-path\n qpath_list = [[0.0, 0.0, 0.0], [0.01, 0, 0], [0.1, 0, 0],\n [0.24, 0, 0], [0.3, 0, 0], [0.45, 0, 0], [0.5, 0.0, 0.0]]\n\n from abipy.flowtk.eph_flows import GkqPathFlow\n flow = GkqPathFlow.from_scf_input(options.workdir, scf_input,\n ngqpt, qpath_list, ndivsm=0, with_becs=True,\n ddk_tolerance={\"tolwfr\": 1e-8})\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_gkq.py -s\n\nthen use:\n\n abirun.py flow_phonons history\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK Rt]ZT T run_mgb2_edoses.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow for convergence studies of e-DOS wrt ngkpt\n\nThis examples shows how to build a Flow to compute the\nband structure and the electron DOS of MgB2 with different k-point samplings.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\nimport sys\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nfrom abipy import flowtk\n\n\ndef make_scf_nscf_inputs(structure, pseudos, paral_kgb=1):\n \"\"\"return GS, NSCF (band structure), and DOSes input.\"\"\"\n\n multi = abilab.MultiDataset(structure, pseudos=pseudos, ndtset=5)\n\n # Global variables\n multi.set_vars(\n ecut=10,\n nband=11,\n timopt=-1,\n occopt=4, # Marzari smearing\n tsmear=0.03,\n paral_kgb=paral_kgb,\n )\n\n # Dataset 1 (GS run)\n multi[0].set_kmesh(ngkpt=[8, 8, 8], shiftk=structure.calc_shiftk())\n multi[0].set_vars(tolvrs=1e-6)\n\n # Dataset 2 (NSCF Band Structure)\n multi[1].set_kpath(ndivsm=6)\n multi[1].set_vars(tolwfr=1e-12)\n\n # Dos calculations with increasing k-point sampling.\n for i, nksmall in enumerate([4, 8, 16]):\n multi[i+2].set_vars(\n iscf=-3, # NSCF calculation\n ngkpt=structure.calc_ngkpt(nksmall),\n shiftk=[0.0, 0.0, 0.0],\n tolwfr=1.0e-10,\n )\n\n # return GS, NSCF (band structure), DOSes input.\n return multi.split_datasets()\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n structure = abidata.structure_from_ucell(\"MgB2\")\n\n # Get pseudos from a table.\n table = abilab.PseudoTable(abidata.pseudos(\"12mg.pspnc\", \"5b.pspnc\"))\n pseudos = table.get_pseudos_for_structure(structure)\n\n nval = structure.num_valence_electrons(pseudos)\n #print(nval)\n\n inputs = make_scf_nscf_inputs(structure, pseudos)\n scf_input, nscf_input, dos_inputs = inputs[0], inputs[1], inputs[2:]\n\n return flowtk.bandstructure_flow(options.workdir, scf_input, nscf_input,\n dos_inputs=dos_inputs, manager=options.manager)\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_mgb2_edoses.py -s\n\nthen use:\n\n abirun.py flow_mgb2_edoes ebands\n\nto get info about the electronic properties:\n\n.. code-block:: shell\n\n KS electronic bands:\n nsppol nspinor nspden nkpt nband nelect fermie formula natom \\\n w0_t0 1 1 1 40 11 8.0 7.615 Mg1 B2 3\n w0_t1 1 1 1 97 11 8.0 7.615 Mg1 B2 3\n w0_t2 1 1 1 15 11 8.0 7.701 Mg1 B2 3\n w0_t3 1 1 1 80 11 8.0 7.629 Mg1 B2 3\n w0_t4 1 1 1 432 11 8.0 7.626 Mg1 B2 3\n\n angle0 angle1 angle2 a b c volume abispg_num \\\n w0_t0 90.0 90.0 120.0 3.086 3.086 3.523 29.056 191\n w0_t1 90.0 90.0 120.0 3.086 3.086 3.523 29.056 191\n w0_t2 90.0 90.0 120.0 3.086 3.086 3.523 29.056 191\n w0_t3 90.0 90.0 120.0 3.086 3.086 3.523 29.056 191\n w0_t4 90.0 90.0 120.0 3.086 3.086 3.523 29.056 191\n\n scheme occopt tsmear_ev \\\n w0_t0 cold smearing of N. Marzari with minimization ... 4 0.816\n w0_t1 cold smearing of N. Marzari with minimization ... 4 0.816\n w0_t2 cold smearing of N. Marzari with minimization ... 4 0.816\n w0_t3 cold smearing of N. Marzari with minimization ... 4 0.816\n w0_t4 cold smearing of N. Marzari with minimization ... 4 0.816\n\n bandwidth_spin0 fundgap_spin0 dirgap_spin0 task_class \\\n w0_t0 12.452 0.031 0.609 ScfTask\n w0_t1 12.441 0.077 0.399 NscfTask\n w0_t2 12.368 0.415 1.680 NscfTask\n w0_t3 12.510 0.069 0.390 NscfTask\n w0_t4 12.506 0.033 0.283 NscfTask\n\n ncfile node_id status\n w0_t0 flow_mgb2_edoses/w0/t0/outdata/out_GSR.nc 241032 Completed\n w0_t1 flow_mgb2_edoses/w0/t1/outdata/out_GSR.nc 241033 Completed\n w0_t2 flow_mgb2_edoses/w0/t2/outdata/out_GSR.nc 241034 Completed\n w0_t3 flow_mgb2_edoses/w0/t3/outdata/out_GSR.nc 241035 Completed\n w0_t4 flow_mgb2_edoses/w0/t4/outdata/out_GSR.nc 241036 Completed\n\nOur main goal is to analyze the convergence of the DOS wrt to the k-point sampling.\nAs we know that ``w0_t2``, `w0_t3`` and ``w0_t4`` are DOS calculations, we can\nbuild a GSR robot for these tasks with:\n\n abirun.py flow_mgb2_edoses/ ebands -nids=241034,241035,241036\n\nthen, inside the ipython shell, one can use:\n\n.. code-block:: ipython\n\n In [1]: %matplotlib\n In [2]: robot.combiplot_edos()\n\nto plot the electronic DOS obtained with different number of k-points in the IBZ.\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RĚD) ) run_ht_si_g0w0ppm.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# G0W0 Flow with factory functions\n\nG0W0 corrections with the HT interface.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.flowtk as flowtk\nfrom abipy import abilab\n\n\ndef build_flow(options):\n # Init structure and pseudos.\n structure = abilab.Structure.from_file(abidata.cif_file(\"si.cif\"))\n pseudos = abidata.pseudos(\"14si.pspnc\")\n\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Initialize the flow.\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n scf_kppa = 120\n nscf_nband = 40\n ecut, ecuteps, ecutsigx = 6, 2, 4\n #scr_nband = 50\n #sigma_nband = 50\n\n multi = abilab.g0w0_with_ppmodel_inputs(\n structure, pseudos, scf_kppa, nscf_nband, ecuteps, ecutsigx,\n ecut=ecut, shifts=(0, 0, 0), # By default the k-mesh is shifted! TODO: Change default?\n accuracy=\"normal\", spin_mode=\"unpolarized\", smearing=None,\n #ppmodel=\"godby\", charge=0.0, scf_algorithm=None, inclvkb=2, scr_nband=None,\n #sigma_nband=None, gw_qprange=1):\n )\n #multi.set_vars(paral_kgb=1)\n\n scf_input, nscf_input, scr_input, sigma_input = multi.split_datasets()\n work = flowtk.G0W0Work(scf_input, nscf_input, scr_input, sigma_input)\n flow.register_work(work)\n\n return flow\n\n\n# This block generates the thumbnails in the Abipy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_ht_si_g0w0ppm.py -s\n\nThe last task ``w0_t3`` is the SigmaTask who has produced a netcdf file with the GW results\nas you can we with the command:\n\n abirun.py flow_ht_si_g0w0ppm/ listext SIGRES\n\nLet's print the QP results with:\n\n abiopen.py flow_ht_si_g0w0ppm/w0/t3/outdata/out_SIGRES.nc -p\n\n.. code-block:: bash\n\n ================================= File Info =================================\n Name: out_SIGRES.nc\n Directory: /Users/gmatteo/git_repos/abipy/abipy/examples/flows/flow_ht_si_g0w0ppm/w0/t3/outdata\n Size: 254.07 kb\n Access Time: Sat Dec 9 19:16:05 2017\n Modification Time: Sat Dec 9 15:16:15 2017\n Change Time: Sat Dec 9 15:16:15 2017\n\n ================================= Structure =================================\n Full Formula (Si2)\n Reduced Formula: Si\n abc : 3.866975 3.866975 3.866975\n angles: 60.000000 60.000000 60.000000\n Sites (2)\n # SP a b c\n --- ---- ---- ---- ----\n 0 Si 0 0 0\n 1 Si 0.25 0.25 0.25\n\n Abinit Spacegroup: spgid: 0, num_spatial_symmetries: 48, has_timerev: True, symmorphic: True\n\n ============================== Kohn-Sham bands ==============================\n Number of electrons: 8.0, Fermi level: 5.963 [eV]\n nsppol: 1, nkpt: 8, mband: 40, nspinor: 1, nspden: 1\n smearing scheme: none, tsmear_eV: 0.272, occopt: 1\n Direct gap:\n Energy: 2.512 [eV]\n Initial state: spin=0, kpt=[+0.000, +0.000, +0.000], weight: 0.016, band=3, eig=5.640, occ=2.000\n Final state: spin=0, kpt=[+0.000, +0.000, +0.000], weight: 0.016, band=4, eig=8.152, occ=0.000\n Fundamental gap:\n Energy: 0.646 [eV]\n Initial state: spin=0, kpt=[+0.000, +0.000, +0.000], weight: 0.016, band=3, eig=5.640, occ=2.000\n Final state: spin=0, kpt=[+0.500, +0.500, +0.000], weight: 0.047, band=4, eig=6.286, occ=0.000\n Bandwidth: 11.867 [eV]\n Valence minimum located at:\n spin=0, kpt=[+0.000, +0.000, +0.000], weight: 0.016, band=0, eig=-6.227, occ=2.000\n Valence maximum located at:\n spin=0, kpt=[+0.000, +0.000, +0.000], weight: 0.016, band=3, eig=5.640, occ=2.000\n\n ============================ QP direct gaps in eV ============================\n QP_dirgap: 3.000 for K-point: [+0.000, +0.000, +0.000], spin: 0\n QP_dirgap: 3.087 for K-point: [+0.250, +0.000, +0.000], spin: 0\n QP_dirgap: 3.068 for K-point: [+0.500, +0.000, +0.000], spin: 0\n QP_dirgap: 3.421 for K-point: [+0.250, +0.250, +0.000], spin: 0\n QP_dirgap: 4.165 for K-point: [+0.500, +0.250, +0.000], spin: 0\n QP_dirgap: 4.206 for K-point: [-0.250, +0.250, +0.000], spin: 0\n QP_dirgap: 4.003 for K-point: [+0.500, +0.500, +0.000], spin: 0\n QP_dirgap: 8.683 for K-point: [-0.250, +0.500, +0.250], spin: 0\n\n ============== QP results for each k-point and spin (All in eV) ==============\n K-point: [+0.000, +0.000, +0.000], spin: 0\n band e0 qpe qpe_diago vxcme sigxme sigcmee0 vUme ze0\n 1 1 5.640 5.547 5.520 -11.156 -12.870 1.594 0.0 0.776\n 2 2 5.640 5.547 5.521 -11.156 -12.870 1.594 0.0 0.776\n 3 3 5.640 5.547 5.521 -11.156 -12.870 1.594 0.0 0.776\n 4 4 8.152 8.547 8.662 -9.969 -5.622 -3.837 0.0 0.774\n 5 5 8.152 8.547 8.662 -9.969 -5.622 -3.837 0.0 0.774\n 6 6 8.152 8.547 8.662 -9.969 -5.622 -3.837 0.0 0.774\n\n K-point: [+0.250, +0.000, +0.000], spin: 0\n band e0 qpe qpe_diago vxcme sigxme sigcmee0 vUme ze0\n 2 2 4.870 4.751 4.716 -10.936 -12.831 1.741 0.0 0.772\n 3 3 4.870 4.751 4.716 -10.936 -12.831 1.741 0.0 0.772\n 4 4 7.449 7.838 7.949 -10.031 -5.725 -3.806 0.0 0.778\n 5 5 9.108 9.534 9.660 -10.013 -5.381 -4.079 0.0 0.771\n 6 6 9.108 9.534 9.660 -10.013 -5.381 -4.079 0.0 0.771\n\n K-point: [+0.500, +0.000, +0.000], spin: 0\n band e0 qpe qpe_diago vxcme sigxme sigcmee0 vUme ze0\n 2 2 4.431 4.282 4.238 -10.908 -13.077 1.976 0.0 0.769\n 3 3 4.431 4.282 4.238 -10.908 -13.077 1.976 0.0 0.769\n 4 4 6.972 7.350 7.456 -10.016 -5.844 -3.687 0.0 0.781\n 5 5 8.982 9.410 9.534 -9.621 -4.942 -4.127 0.0 0.775\n 6 6 8.982 9.410 9.534 -9.621 -4.942 -4.127 0.0 0.775\n\n K-point: [+0.250, +0.250, +0.000], spin: 0\n band e0 qpe qpe_diago vxcme sigxme sigcmee0 vUme ze0\n 2 2 3.743 3.571 3.518 -10.603 -12.883 2.056 0.0 0.764\n 3 3 3.743 3.571 3.518 -10.603 -12.883 2.056 0.0 0.764\n 4 4 6.692 6.993 7.076 -9.352 -5.373 -3.595 0.0 0.783\n 5 5 8.669 9.035 9.139 -9.203 -4.548 -4.184 0.0 0.779\n\n K-point: [+0.500, +0.250, +0.000], spin: 0\n band e0 qpe qpe_diago vxcme sigxme sigcmee0 vUme ze0\n 2 2 2.099 1.893 1.825 -10.130 -12.839 2.435 0.0 0.752\n 3 3 3.427 3.242 3.184 -10.596 -13.077 2.238 0.0 0.761\n 4 4 7.086 7.408 7.496 -9.224 -5.065 -3.748 0.0 0.784\n 5 5 10.015 10.397 10.510 -9.594 -4.730 -4.369 0.0 0.771\n\n K-point: [-0.250, +0.250, +0.000], spin: 0\n band e0 qpe qpe_diago vxcme sigxme sigcmee0 vUme ze0\n 2 2 1.887 1.667 1.594 -9.982 -12.769 2.493 0.0 0.751\n 3 3 4.302 4.157 4.113 -10.820 -12.927 1.917 0.0 0.769\n 4 4 7.983 8.363 8.470 -9.567 -5.113 -3.966 0.0 0.779\n 5 5 10.350 10.800 10.942 -10.046 -4.859 -4.595 0.0 0.760\n\n K-point: [+0.500, +0.500, +0.000], spin: 0\n band e0 qpe qpe_diago vxcme sigxme sigcmee0 vUme ze0\n 2 2 2.784 2.567 2.497 -10.480 -13.270 2.503 0.0 0.755\n 3 3 2.784 2.567 2.497 -10.480 -13.270 2.503 0.0 0.755\n 4 4 6.286 6.571 6.647 -9.003 -5.038 -3.603 0.0 0.787\n 5 5 6.286 6.571 6.647 -9.003 -5.038 -3.603 0.0 0.787\n\n K-point: [-0.250, +0.500, +0.250], spin: 0\n band e0 qpe qpe_diago vxcme sigxme sigcmee0 vUme ze0\n 2 2 1.787 1.557 1.481 -9.917 -12.751 2.527 0.0 0.749\n 3 3 1.787 1.557 1.481 -9.917 -12.751 2.527 0.0 0.749\n 4 4 9.875 10.241 10.347 -9.523 -4.876 -4.176 0.0 0.775\n 5 5 9.875 10.241 10.347 -9.523 -4.876 -4.176 0.0 0.775\n\nwe can also plot the QP data as function of the initial KS energy with ipython:\n\n abiopen.py flow_ht_si_g0w0ppm/w0/t3/outdata/out_SIGRES.nc\n\n.. code-block:: ipython\n\n In [1]: %matplotlib\n In [2]: abifile.plot_qps_vs_e0()\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R run_ht_si_bsemdf.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Bethe-Salpeter Flow with factory functions\n\nCalculation of the BSE spectrum with the High-throuhput interface (factory functions).\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.flowtk as flowtk\n\nfrom abipy import abilab\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Initialize pseudos and Structure.\n pseudos = abidata.pseudos(\"14si.pspnc\")\n structure = abilab.Structure.from_file(abidata.cif_file(\"si.cif\"))\n\n kppa = scf_kppa = 1\n nscf_nband = 6\n nscf_ngkpt = [4, 4, 4]\n nscf_shiftk = [0.1, 0.2, 0.3]\n bs_loband = 2\n bs_nband = nscf_nband\n mbpt_sciss = 0.7 * abilab.units.eV_to_Ha\n mdf_epsinf = 12\n ecuteps = 2\n ecut = 12\n\n flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)\n\n # BSE calculation with model dielectric function.\n multi = abilab.bse_with_mdf_inputs(\n structure, pseudos,\n scf_kppa, nscf_nband, nscf_ngkpt, nscf_shiftk,\n ecuteps, bs_loband, bs_nband, mbpt_sciss, mdf_epsinf,\n ecut=ecut,# pawecutdg=None,\n exc_type=\"TDA\", bs_algo=\"haydock\", accuracy=\"normal\", spin_mode=\"unpolarized\",\n smearing=None)\n #smearing=\"fermi_dirac:0.1 eV\", charge=0.0, scf_algorithm=None)\n\n work = flowtk.BseMdfWork(scf_input=multi[0], nscf_input=multi[1], bse_inputs=multi[2:])\n\n flow.register_work(work)\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_ht_si_bsemdf.py -s\n\nthen use:\n\n abirun.py flow_ht_si_bsemdf/ status -v\n\nto get the status of the flow\n\n.. code-block:: bash\n\n Work #0: , Finalized=True\n +--------+-----------+-----------------+--------------+------------+----------+-----------------+----------+-----------+\n | Task | Status | Queue | MPI|Omp|Gb | Warn|Com | Class | Sub|Rest|Corr | Time | Node_ID |\n +========+===========+=================+==============+============+==========+=================+==========+===========+\n | w0_t0 | Completed | 62430@localhost | 1| 1|2.0 | 2| 0 | ScfTask | (1, 0, 0) | 0:00:01R | 241907 |\n +--------+-----------+-----------------+--------------+------------+----------+-----------------+----------+-----------+\n | w0_t1 | Completed | 62438@localhost | 2| 1|2.0 | 3| 0 | NscfTask | (1, 0, 0) | 0:00:05R | 241908 |\n +--------+-----------+-----------------+--------------+------------+----------+-----------------+----------+-----------+\n | w0_t2 | Completed | 62449@localhost | 2| 1|2.0 | 10| 6 | BseTask | (1, 0, 0) | 0:00:17R | 241909 |\n +--------+-----------+-----------------+--------------+------------+----------+-----------------+----------+-----------+\n\n all_ok reached\n\nThe macroscopic dielectric function produced by the BseTask is stored in the ``out_MDF.nc`` file:\n\n.. code-block:: bash\n\n abirun.py flow_ht_si_bsemdf/ listext MDF\n\n Found 1 files with extension `MDF` produced by the flow\n File Size [Mb] Node_ID Node Class\n ------------------------------------------ ----------- --------- ------------\n flow_ht_si_bsemdf/w0/t2/outdata/out_MDF.nc 0.4 241909 BseTask\n\nOpen the file with:\n\n abiopen.py flow_ht_si_bsemdf/w0/t2/outdata/out_MDF.nc\n\nand then inside the ipython terminal, issue:\n\n.. code-block:: ipython\n\n In [1]: %matplotlib\n In [2]: abifile.plot_mdfs()\n\nto produce:\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R/W run_eph_mob.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow for phonon-limited mobilities in semiconductors\n\nThis flow computes the phonon-limited mobility in AlAs.\nusing different dense k/q meshes\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\nimport abipy.core.abinit_units as abu\n\n\ndef build_flow(options):\n\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Initialize the flow\n flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)\n\n # Initialize the tmesh, sigma_kerange, sigma_erange and dense meshes for the eph integrations\n tmesh = [300, 300, 1]\n sigma_kerange = [0, 0.5 * abu.eV_Ha] # 0.5 eV range for the WFK of electrons\n sigma_erange = [0, 0.25 * abu.eV_Ha] # 0.25 eV range for the EPH computation for electrons\n dense_meshes = [[30, 30, 30],\n [40, 40, 40]]\n\n # Initialize the structure and pseudos\n structure = abidata.structure_from_ucell(\"AlAs\")\n pseudos = abidata.pseudos(\"13al.981214.fhi\", \"33as.pspnc\")\n\n # Ground-state computation for 1) the phonons and 2) the WFK generation\n scf_input = abilab.AbinitInput(structure, pseudos=pseudos)\n\n scf_input.set_vars(\n nband=8,\n ecut=2.0,\n ngkpt=[4, 4, 4],\n shiftk=[0, 0, 0],\n tolvrs=1.0e-10,\n diemac=9.0,\n prtden=1,\n #iomode=3,\n )\n\n # Initialize the first work and add the ground-state task\n work0 = flowtk.Work()\n work0.register_scf_task(scf_input)\n\n # Band structure calculation to make sure everything is OK\n # Also allows to compare the results obtained with abitk to\n # check the SKW interpolation works as needed\n bs_input = scf_input.make_ebands_input(tolwfr=1e-12, ndivsm=10, nb_extra=5)\n bs_input.set_vars(nstep=100, nbdbuf=1)\n work0.register_nscf_task(bs_input, deps={work0[0]: \"DEN\"})\n\n # NSCF input for the WFK needed to interpolate with kerange\n nscf_input = abilab.AbinitInput(structure, pseudos)\n nscf_input.set_vars(\n ecut=2,\n nband=8,\n iscf=-2,\n tolwfr=1e-20,\n prtwf=1,\n ngkpt=[16, 16, 16], # Should be dense enough so that the kerange interpolation works\n shiftk=[0.0, 0.0, 0.0],\n )\n\n work0.register_nscf_task(nscf_input, deps={work0[0]: \"DEN\"})\n flow.register_work(work0)\n\n # Add the phonon work to the flow\n ddb_ngqpt = [4, 4, 4]\n ph_work = flowtk.PhononWork.from_scf_task(work0[0], qpoints=ddb_ngqpt,\n is_ngqpt=True, with_becs=True, with_quad=False)\n flow.register_work(ph_work)\n\n # We loop over the dense meshes\n for i, sigma_ngkpt in enumerate(dense_meshes):\n # Use the kerange trick to generate a WFK file\n multi = nscf_input.make_wfk_kerange_inputs(sigma_kerange=sigma_kerange,\n sigma_ngkpt=sigma_ngkpt)\n kerange_input, wfk_input = multi.split_datasets()\n\n work_eph = flowtk.Work()\n work_eph.register_kerange_task(kerange_input, deps={work0[2]: \"WFK\"})\n work_eph.register_nscf_task(wfk_input,\n deps={work0[0]: \"DEN\", work_eph[0]: \"KERANGE.nc\"})\n\n # Generate the input file for the transport calculation.\n # Use ibte_prep = 1 to activate the iterative BTE.\n eph_input = wfk_input.make_eph_transport_input(ddb_ngqpt=ddb_ngqpt,\n sigma_erange=sigma_erange,\n tmesh=tmesh,\n eph_ngqpt_fine=sigma_ngkpt,\n ibte_prep=1)\n\n # We compute the phonon dispersion in the EPH code to be able to check they are ok.\n if i == 0:\n eph_input.set_qpath(20)\n\n work_eph.register_eph_task(eph_input,\n deps={work_eph[1]: \"WFK\", ph_work: [\"DDB\", \"DVDB\"]})\n\n flow.register_work(work_eph)\n\n flow.allocate(use_smartio=True)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RX1 1 run_elastic.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow for elastic constants and piezoelectric tensor with DFPT\n\nThis example shows how to use AbiPy to calculate physical properties\nrelated to strain for an insulator.\n\n - the rigid-atom elastic tensor\n - the rigid-atom piezoelectric tensor (insulators only)\n - the internal strain tensor\n - the atomic relaxation corrections to the elastic and piezoelectric tensor\n\nHere we follow the discussion presented in\nin the `the official tutorial `_\n\nThe DDB file with all the perturbations will be produced automatically at the end of the run\nand saved in ``flow_elastic/w0/outdata/out_DDB``.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport numpy as np\nimport abipy.abilab as abilab\nimport abipy.data as abidata\n\nfrom abipy import flowtk\n\n\ndef make_scf_input(paral_kgb=0):\n \"\"\"\n This function constructs the input file for the GS calculation of\n AlAs in hypothetical wurzite (hexagonal) structure.\n In principle, the stucture should be relaxed before starting the calculation\n \"\"\"\n\n # Initialize structure. Use enough significant digits\n # so that Abinit will recognize the correct spacegroup\n # (Hexagonal and rhombohedral lattices are a bit problematic).\n structure = abilab.Structure.from_abivars(\n acell=[7.5389648144E+00, 7.5389648144E+00, 1.2277795374E+01],\n natom=4,\n ntypat=2,\n rprim=[np.sqrt(0.75), 0.5, 0.0,\n -np.sqrt(0.75), 0.5, 0.0,\n 0.0, 0.0, 1.0],\n typat=[1, 1, 2, 2],\n xred=[1/3, 2/3, 0,\n 2/3, 1/3, 1/2,\n 1/3, 2/3, 3.7608588373E-01,\n 2/3, 1/3, 8.7608588373E-01],\n znucl=[13, 33],\n )\n\n pseudos = abidata.pseudos(\"13al.pspnc\", \"33as.pspnc\")\n gs_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n\n # Set other important variables (consistent with tutorial)\n # Aall the other DFPT runs will inherit these parameters.\n gs_inp.set_vars(\n nband=8,\n ecut=6.0,\n ecutsm=0.5, # Important when performing structural optimization\n # with variable cell. All DFPT calculations should use\n # the same value to be consistent.\n ngkpt=[4, 4, 4],\n nshiftk=1,\n shiftk=[0.0, 0.0, 0.5], # This choice preserves the hexagonal symmetry of the grid.\n diemac=9.0,\n nstep=40,\n paral_kgb=paral_kgb,\n tolvrs=1.0e-18,\n )\n\n return gs_inp\n\n\ndef build_flow(options):\n \"\"\"\n Create a `Flow` for phonon calculations. The flow has one work with:\n\n - 1 GS Task\n - 3 DDK Task\n - 4 Phonon Tasks (Gamma point)\n - 6 Elastic tasks (3 uniaxial + 3 shear strain)\n\n The Phonon tasks and the elastic task will read the DDK produced at the beginning\n \"\"\"\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n flow = flowtk.Flow(workdir=options.workdir)\n\n # Build input for GS calculation and register the first work.\n scf_input = make_scf_input()\n\n elast_work = flowtk.ElasticWork.from_scf_input(scf_input, with_relaxed_ion=True, with_piezo=True)\n\n flow.register_work(elast_work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_elastic.py -s\n\n then use:\n\n abirun.py flow_elastic deps\n\n to get the list of dependencies in the flow.\n Note, in particular, how the ``ElasticTasks`` depend on 3 DdkTasks and the initial ScfTask\n\n .. code-block:: bash\n\n\t\n\t +--\n\t +--\n\t | +--\n\t +--\n\t | +--\n\t +--\n\t +--\n\n Use:\n\n abiopen.py flow_elastic/w0/outdata/out_DDB -p\n\n to print information about the DDB file. You should see that the DDB file contains:\n\n .. code-block:: bash\n\n\t Has (at least one) atomic pertubation: True\n\t Has (at least one) electric-field perturbation: True\n\t Has (at least one) Born effective charge: True\n\t Has (all) strain terms: True\n\t Has (all) internal strain terms: True\n\t Has (all) piezoelectric terms: True\n\n Now open the final DDB file with:\n\n abiopen.py flow_elastic/w0/outdata/out_DDB\n\n and invoke anaddb to compute the elastic and piezoelectric properties\n\n .. code-block:: ipython\n\n In [1]: edata = abifile.anaget_elastic()\n In [2]: print(edata)\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK ݄Ro run_ht_si_ebands.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Band structure Flow with factory functions\n\nThis example show how to build a flow to compute the band structure and the DOS of silicon.\nInput files are automatically generated with factory functions designed for automatic calculations.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.flowtk as flowtk\n\nfrom abipy import abilab\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Initialize structure and pseudos.\n structure = abilab.Structure.from_file(abidata.cif_file(\"si.cif\"))\n pseudos = abidata.pseudos(\"14si.pspnc\")\n\n # Initialize the flow.\n flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)\n\n # Use the ebands_input factory function to build a MultiDataset.\n # keyword args are optional (default values are given or computed automatically, see docs).\n multi = abilab.ebands_input(structure, pseudos, kppa=40, dos_kppa=80,\n nscf_nband=6, ndivsm=10, ecut=6, spin_mode=\"unpolarized\")\n\n work = flowtk.BandStructureWork(scf_input=multi[0], nscf_input=multi[1], dos_inputs=multi[2])\n flow.register_work(work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_hs_si_ebands.py -s\n\nUse:\n\n abirun.py flow_h_si_ebands deps\n\nTo print the connections among the tasks.\n\n.. code-block:: bash\n\n \n\n \n +--\n\n \n +--\n\n``w0/t1`` is a band structure calculation along a k-path\n while ``w0/t2`` produced KS eigenvalues in the IBZ for the DOS.\n\n You can use ipython to plot the electronic bands with the DOS:\n\n.. code-block:: ipython\n\n In [1]: %matplotlib\n In [2]: from abipy import abilab\n In [3]: gsr_kpath = abilab.abiopen(\"flow_ht_si_ebands/w0/t1/outdata/out_GSR.nc\")\n In [4]: gsr_kmesh = abilab.abiopen(\"flow_ht_si_ebands/w0/t2/outdata/out_GSR.nc\")\n In [5]: gsr_kpath.ebands.plot_with_edos(gsr_kmesh.ebands.get_edos())\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RRi i
run_eos.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow for equation of state\n\nFlow to compute the equation of state by fitting E(V) at T = 0.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef build_flow(options):\n # Set working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Build GS input file.\n pseudos = abidata.pseudos(\"Si.GGA_PBE-JTH-paw.xml\")\n #silicon = abilab.Structure.zincblende(5.431, [\"Si\", \"Si\"], units=\"ang\")\n silicon = abidata.cif_file(\"si.cif\")\n\n scf_input = abilab.AbinitInput(silicon, pseudos)\n ecut = 12\n scf_input.set_vars(\n ecut=ecut,\n pawecutdg=40,\n nband=6,\n paral_kgb=0,\n iomode=3,\n toldfe=1e-9,\n )\n\n # K-point sampling (shifted)\n scf_input.set_autokmesh(nksmall=4)\n\n from abipy.flowtk.gs_works import EosWork\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n # Si is cubic and atomic positions are fixed by symmetry so we\n # use move_atoms=False to compute E(V) with SCF-GS tasks instead of\n # performing a constant-volume optimization of the cell geometry.\n work = EosWork.from_scf_input(scf_input, move_atoms=False, ecutsm=0.5)\n flow.register_work(work)\n flow.allocate(use_smartio=True)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_eos.py -s\n\nthen use:\n\n abirun.py flow_eos structures\n\nto get info about the initial and final structures.\n\n.. code-block:: bash\n\n Lattice parameters:\n formula natom angle0 angle1 angle2 a b c volume \\\n w0_t0_in Si2 2 60.0 60.0 60.0 3.854 3.854 3.854 40.479\n w0_t0_out Si2 2 60.0 60.0 60.0 3.854 3.854 3.854 40.479\n w0_t1_in Si2 2 60.0 60.0 60.0 3.857 3.857 3.857 40.582\n w0_t1_out Si2 2 60.0 60.0 60.0 3.857 3.857 3.857 40.582\n w0_t2_in Si2 2 60.0 60.0 60.0 3.861 3.861 3.861 40.684\n w0_t2_out Si2 2 60.0 60.0 60.0 3.861 3.861 3.861 40.684\n w0_t3_in Si2 2 60.0 60.0 60.0 3.864 3.864 3.864 40.786\n w0_t3_out Si2 2 60.0 60.0 60.0 3.864 3.864 3.864 40.786\n w0_t4_in Si2 2 60.0 60.0 60.0 3.867 3.867 3.867 40.888\n w0_t4_out Si2 2 60.0 60.0 60.0 3.867 3.867 3.867 40.888\n w0_t5_in Si2 2 60.0 60.0 60.0 3.870 3.870 3.870 40.991\n w0_t5_out Si2 2 60.0 60.0 60.0 3.870 3.870 3.870 40.991\n w0_t6_in Si2 2 60.0 60.0 60.0 3.873 3.873 3.873 41.093\n w0_t6_out Si2 2 60.0 60.0 60.0 3.873 3.873 3.873 41.093\n w0_t7_in Si2 2 60.0 60.0 60.0 3.877 3.877 3.877 41.195\n w0_t7_out Si2 2 60.0 60.0 60.0 3.877 3.877 3.877 41.195\n w0_t8_in Si2 2 60.0 60.0 60.0 3.880 3.880 3.880 41.297\n w0_t8_out Si2 2 60.0 60.0 60.0 3.880 3.880 3.880 41.297\n\n abispg_num P [GPa] Max|F| eV/ang task_class status\n w0_t0_in None NaN NaN ScfTask Completed\n w0_t0_out 227 1.327 9.506e-28 ScfTask Completed\n w0_t1_in None NaN NaN ScfTask Completed\n w0_t1_out 227 1.092 1.877e-27 ScfTask Completed\n w0_t2_in None NaN NaN ScfTask Completed\n w0_t2_out 227 0.859 4.649e-27 ScfTask Completed\n w0_t3_in None NaN NaN ScfTask Completed\n w0_t3_out 227 0.629 5.062e-27 ScfTask Completed\n w0_t4_in None NaN NaN ScfTask Completed\n w0_t4_out 227 0.403 5.945e-27 ScfTask Completed\n w0_t5_in None NaN NaN ScfTask Completed\n w0_t5_out 227 0.178 6.306e-27 ScfTask Completed\n w0_t6_in None NaN NaN ScfTask Completed\n w0_t6_out 227 -0.042 1.738e-27 ScfTask Completed\n w0_t7_in None NaN NaN ScfTask Completed\n w0_t7_out 227 -0.259 2.725e-27 ScfTask Completed\n w0_t8_in None NaN NaN ScfTask Completed\n w0_t8_out 227 -0.474 6.939e-27 ScfTask Completed\n\n Use `--verbose` to print atoms.\n\nSilicon is a cubic materials and the positions are fixed by symmeetry so we only need ScfTask to get E(V).\n\nThe EOS results are saved in the JSON file in flow_eos/w0/outdata/eos_data.json.\n\nWe can also use the GSR robot to compute and plot the EOS.\n\nUse\n\n abirun.py flow_eos robot GSR\n\nto build a robot for GSR files and start an ipython shell.\nThen, inside ipython, type:\n\n.. code-block:: ipython\n\n In [1]: %matplotlib\n In [2]: robot.gridplot_eos()\n\nto produce\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RPn run_fe_ebands.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Band structure w/wo magnetization\n\nCalculation of the band structure of Fe with and without magnetization.\nSee also <~abinit/tutorial/Input/tspin_1.in>\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\nimport sys\nimport abipy.data as data\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef make_scf_nscf_inputs(nsppol, paral_kgb=1):\n \"\"\"\n Generate two input files for the GS and the NSCF run for given `nsppol`.\n \"\"\"\n # Fe normal bcc structure for test of a ferromagnetic calculation\n multi = abilab.MultiDataset(structure=data.structure_from_ucell(\"Fe-fm\"),\n pseudos=data.pseudos(\"26fe.pspnc\"), ndtset=2)\n\n # Global variables\n global_vars = dict(\n nsppol=nsppol,\n ecut=18,\n nband=8,\n occopt=3,\n tsmear=0.01,\n paral_kgb=paral_kgb,\n )\n if nsppol == 2:\n global_vars.update(spinat=[0.0, 0.0, 4.0])\n\n multi.set_vars(global_vars)\n\n # Dataset 1 (GS run)\n multi[0].set_kmesh(ngkpt=[4,4,4], shiftk=[0.5,0.5,0.5])\n multi[0].set_vars(tolvrs=1e-6)\n\n # Dataset 2 (NSCF run)\n multi[1].set_kpath(ndivsm=4)\n multi[1].set_vars(tolwfr=1e-8)\n\n # Generate two input files for the GS and the NSCF run\n scf_input, nscf_input = multi.split_datasets()\n\n return scf_input, nscf_input\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Create the Flow.\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n # Create the task defining the calculation and run and register it in the flow\n for nsppol in [1, 2]:\n scf_input, nscf_input = make_scf_nscf_inputs(nsppol)\n work = flowtk.BandStructureWork(scf_input, nscf_input)\n flow.register_work(work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_fe_ebands -s\n\nthen use:\n\n abirun.py flow_fe_ebands ebands -p\n\nto analyze all the band structures produced by the Flow and plot the data\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R6 run_relax_vs_kpts.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Relaxation of GaN with different K-meshes\n\nIn this example, we employ the relaxation algorithms implemented in Abinit (``ionmov`` and ``optcell``)\nto find the equilibrium configuration of GaN (atomic positions and lattice vectors).\nThe relaxation is done with different k-meshes to monitor the convergence of the results.\nYou will observe a change of the equilibrium parameters with respect to the k-point mesh.\n\nNote the we are using pseudopotentials generated with the GGA which tends to\noverestimate the lattice parameters and ecut is way too low.\nIf you replace GGA with LDA, you will observe that LDA tends to underestimate the parameters.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\n\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\nimport abipy.data as abidata\n\n\ndef build_flow(options):\n \"\"\"\n Build and return a flow performing structural relaxations with different k-point samplings.\n \"\"\"\n # Set working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # List of k-meshes.\n ngkpt_list = [\n [3, 3, 2],\n [6, 6, 4],\n [8, 8, 6],\n ]\n\n structure = abilab.Structure.from_file(abidata.cif_file(\"gan2.cif\"))\n pseudos = abidata.pseudos(\"Ga.oncvpsp\", \"N.oncvpsp\")\n\n # Build multidataset.\n multi = abilab.MultiDataset(structure=structure, pseudos=pseudos, ndtset=len(ngkpt_list))\n\n # Set global variables for structural relaxation. Note dilatmx and ecutsm\n # Ecut should depend on pseudos.\n multi.set_vars(\n ecut=15, # Too low\n optcell=2,\n ionmov=3,\n tolrff=5.0e-2,\n tolmxf=5.0e-5,\n ntime=50,\n dilatmx=1.05, # Important!\n ecutsm=0.5, # Important!\n )\n\n # Here we set the k-meshes (Gamma-centered for simplicity)\n for i, ngkpt in enumerate(ngkpt_list):\n multi[i].set_kmesh(ngkpt=ngkpt, shiftk=[0, 0, 0])\n\n # As the calculations are independent, we can use Flow.from_inputs\n # and call split_datasets to create len(ngkpt_list) inputs.\n # Note that it's a good idea to specify the task_class so that AbiPy knows how to restart the calculation.\n return flowtk.Flow.from_inputs(options.workdir, inputs=multi.split_datasets(),\n task_class=flowtk.RelaxTask)\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_relax_vs_kpts.py -s\n\nthen use:\n\n abirun.py flow_relax_vs_kpts hist -p\n\nto print (and plot) the relaxed parameters at the end of the run.\n\n.. code-block:: bash\n\n Table with final structures, pressures in GPa and force stats in eV/Ang:\n\n formula natom angle0 angle1 angle2 a b c volume \\\n w0_t0 Ga2 N2 4 90.0 90.0 120.0 3.224 3.224 5.343 48.080\n w0_t1 Ga2 N2 4 90.0 90.0 120.0 3.249 3.249 5.321 48.635\n w0_t2 Ga2 N2 4 90.0 90.0 120.0 3.254 3.254 5.335 48.909\n\n abispg_num num_steps final_energy final_pressure task_class \\\n w0_t0 None 9 -755.344 -1.088e-04 RelaxTask\n w0_t1 None 9 -755.632 -5.088e-03 RelaxTask\n w0_t2 None 11 -755.645 -4.314e-03 RelaxTask\n\n ncfile status\n w0_t0 flow_relax_vs_kpts/w0/t0/outdata/out_HIST.nc Completed\n w0_t1 flow_relax_vs_kpts/w0/t1/outdata/out_HIST.nc Completed\n w0_t2 flow_relax_vs_kpts/w0/t2/outdata/out_HIST.nc Completed\n\nThe experimental results are:\n\n * Volume of the unit cell of GaN: 45.73 A^3\n * Lattice parameters of GaN: a = 3.190 A, c = 5.189 A\n * Vertical distance between Ga and N : about 0.377 * c [ Schulz & Thiemann, 1977]\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R>t1% % run_si_g0w0.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# G0W0 Flow with convergence study wrt nband\n\nThis script shows how to compute the G0W0 corrections in silicon.\nMore specifically, we build a flow to analyze the convergence of the QP corrections\nwrt to the number of bands in the self-energy. More complicated convergence studies\ncan be implemented on the basis of this example.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\nimport sys\nimport abipy.data as data\nimport abipy.abilab as abilab\nfrom abipy import flowtk\n\n\ndef make_inputs(ngkpt, paral_kgb=1):\n # Crystalline silicon\n # Calculation of the GW correction to the direct band gap in Gamma\n # Dataset 1: ground state calculation\n # Dataset 2: NSCF calculation\n # Dataset 3: calculation of the screening\n # Dataset 4-5-6: Self-Energy matrix elements (GW corrections) with different values of nband\n\n multi = abilab.MultiDataset(structure=data.cif_file(\"si.cif\"),\n pseudos=data.pseudos(\"14si.pspnc\"), ndtset=6)\n\n # This grid is the most economical, but does not contain the Gamma point.\n scf_kmesh = dict(\n ngkpt=ngkpt,\n shiftk=[0.5, 0.5, 0.5,\n 0.5, 0.0, 0.0,\n 0.0, 0.5, 0.0,\n 0.0, 0.0, 0.5]\n )\n\n # This grid contains the Gamma point, which is the point at which\n # we will compute the (direct) band gap.\n gw_kmesh = dict(\n ngkpt=ngkpt,\n shiftk=[0.0, 0.0, 0.0,\n 0.0, 0.5, 0.5,\n 0.5, 0.0, 0.5,\n 0.5, 0.5, 0.0]\n )\n\n # Global variables. gw_kmesh is used in all datasets except DATASET 1.\n ecut = 6\n\n multi.set_vars(\n ecut=ecut,\n timopt=-1,\n istwfk=\"*1\",\n paral_kgb=paral_kgb,\n gwpara=2,\n )\n multi.set_kmesh(**gw_kmesh)\n\n # Dataset 1 (GS run)\n multi[0].set_kmesh(**scf_kmesh)\n multi[0].set_vars(\n tolvrs=1e-6,\n nband=4,\n )\n\n # Dataset 2 (NSCF run)\n # Here we select the second dataset directly with the syntax multi[1]\n multi[1].set_vars(\n iscf=-2,\n tolwfr=1e-12,\n nband=35,\n nbdbuf=5,\n )\n\n # Dataset3: Calculation of the screening.\n multi[2].set_vars(\n optdriver=3,\n nband=25,\n ecutwfn=ecut,\n symchi=1,\n inclvkb=0,\n ecuteps=4.0,\n ppmfrq=\"16.7 eV\",\n )\n\n # Dataset4: Calculation of the Self-Energy matrix elements (GW corrections)\n kptgw = [\n -2.50000000E-01, -2.50000000E-01, 0.00000000E+00,\n -2.50000000E-01, 2.50000000E-01, 0.00000000E+00,\n 5.00000000E-01, 5.00000000E-01, 0.00000000E+00,\n -2.50000000E-01, 5.00000000E-01, 2.50000000E-01,\n 5.00000000E-01, 0.00000000E+00, 0.00000000E+00,\n 0.00000000E+00, 0.00000000E+00, 0.00000000E+00,\n ]\n\n bdgw = [1, 8]\n\n # Convergence study wrt nband in sigma.\n for idx, nband in enumerate([10, 20, 30]):\n multi[3+idx].set_vars(\n optdriver=4,\n nband=nband,\n ecutwfn=ecut,\n ecuteps=4.0,\n ecutsigx=6.0,\n symsigma=1,\n #gw_qprange=0,\n #nkptgw=0,\n )\n multi[3+idx].set_kptgw(kptgw, bdgw)\n\n return multi.split_datasets()\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\",\"flow_\")\n\n # Change the value of ngkpt below to perform a GW calculation with a different k-mesh.\n scf, nscf, scr, sig1, sig2, sig3 = make_inputs(ngkpt=[2, 2, 2])\n\n return flowtk.g0w0_flow(options.workdir, scf, nscf, scr, [sig1, sig2, sig3], manager=options.manager)\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_si_g0w0.py -s\n\nThe last three tasks (``w0_t3``, ``w0_t4``, ``w0_t5``) are the SigmaTask who have produced\na netcdf file with the GW results with different number of bands.\nWe can check this with the command:\n\n abirun.py flow_si_g0w0/ listext SIGRES\n\n.. code-block:: bash\n\n Found 3 files with extension `SIGRES` produced by the flow\n File Size [Mb] Node_ID Node Class\n ---------------------------------------- ----------- --------- ------------\n flow_si_g0w0/w0/t3/outdata/out_SIGRES.nc 0.05 241325 SigmaTask\n flow_si_g0w0/w0/t4/outdata/out_SIGRES.nc 0.08 241326 SigmaTask\n flow_si_g0w0/w0/t5/outdata/out_SIGRES.nc 0.13 241327 SigmaTask\n\nLet's use the SIGRES robot to collect and analyze the results:\n\n abirun.py flow_si_g0w0/ robot SIGRES\n\nand then, inside the ipython terminal, type:\n\n.. code-block:: ipython\n\n In [1]: df = robot.get_dataframe()\n In [2]: df\n Out[2]:\n nsppol qpgap ecutwfn \\\n flow_si_g0w0/w0/t3/outdata/out_SIGRES.nc 1 3.627960 5.914381651684836\n flow_si_g0w0/w0/t4/outdata/out_SIGRES.nc 1 3.531781 5.914381651684836\n flow_si_g0w0/w0/t5/outdata/out_SIGRES.nc 1 3.512285 5.914381651684836\n\n ecuteps \\\n flow_si_g0w0/w0/t3/outdata/out_SIGRES.nc 3.6964885323070074\n flow_si_g0w0/w0/t4/outdata/out_SIGRES.nc 3.6964885323070074\n flow_si_g0w0/w0/t5/outdata/out_SIGRES.nc 3.6964885323070074\n\n ecutsigx scr_nband \\\n flow_si_g0w0/w0/t3/outdata/out_SIGRES.nc 5.914381651684846 25\n flow_si_g0w0/w0/t4/outdata/out_SIGRES.nc 5.914381651684846 25\n flow_si_g0w0/w0/t5/outdata/out_SIGRES.nc 5.914381651684846 25\n\n sigma_nband gwcalctyp scissor_ene \\\n flow_si_g0w0/w0/t3/outdata/out_SIGRES.nc 10 0 0.0\n flow_si_g0w0/w0/t4/outdata/out_SIGRES.nc 20 0 0.0\n flow_si_g0w0/w0/t5/outdata/out_SIGRES.nc 30 0 0.0\n\n nkibz\n flow_si_g0w0/w0/t3/outdata/out_SIGRES.nc 6\n flow_si_g0w0/w0/t4/outdata/out_SIGRES.nc 6\n flow_si_g0w0/w0/t5/outdata/out_SIGRES.nc 6\n\n In [3]: %matplotlib\n In [4]: df.plot(\"sigma_nband\", \"qpgap\", marker=\"o\")\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK Ry3vw w run_gwconv_ecuteps.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# G0W0 convergence study\n\nG0W0 convergence study wrt ecuteps and the number of bands in W.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport numpy as np\n\nimport abipy.abilab as abilab\nimport abipy.data as abidata\nimport abipy.flowtk as flowtk\n\n\ndef make_inputs(paral_kgb=1):\n \"\"\"\n Returns a tuple of 4 input files for SCF, NSCF, SCR, SIGMA calculations.\n These files are then used as templates for the convergence study\n wrt ecuteps and the number of bands in W.\n \"\"\"\n multi = abilab.MultiDataset(abidata.structure_from_ucell(\"SiC\"),\n pseudos=abidata.pseudos(\"14si.pspnc\", \"6c.pspnc\"), ndtset=4)\n\n ecut = 12\n global_vars = dict(\n ecut=ecut,\n istwfk=\"*1\",\n paral_kgb=paral_kgb,\n gwpara=2,\n iomode=1,\n )\n\n ecuteps = 4\n ngkpt = [4, 4, 4]\n shiftk = [0, 0, 0]\n\n multi.set_vars(global_vars)\n multi.set_kmesh(ngkpt=ngkpt, shiftk=shiftk)\n\n # SCF\n multi[0].set_vars(\n nband=10,\n tolvrs=1.e-8,\n )\n\n # NSCF\n multi[1].set_vars(\n nband=25,\n tolwfr=1.e-8,\n iscf=-2\n )\n\n # SCR\n multi[2].set_vars(\n optdriver=3,\n ecutwfn=ecut,\n nband=20,\n symchi=1,\n inclvkb=0,\n ecuteps=ecuteps,\n )\n\n # SIGMA\n multi[3].set_vars(\n optdriver=4,\n nband=20,\n ecutwfn=ecut,\n ecutsigx=ecut,\n #ecutsigx=(4*ecut), ! This is problematic\n symsigma=1,\n ecuteps=ecuteps,\n )\n\n multi[3].set_kptgw(kptgw=[[0,0,0], [0.5, 0, 0]], bdgw=[1, 8])\n\n return multi.split_datasets()\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Get our templates\n scf_inp, nscf_inp, scr_inp, sig_inp = make_inputs()\n\n ecuteps_list = np.arange(2, 8, 2)\n max_ecuteps = max(ecuteps_list)\n\n flow = flowtk.Flow(workdir=options.workdir, manager=options.manager)\n\n # Band structure work to produce the WFK file\n bands = flowtk.BandStructureWork(scf_inp, nscf_inp)\n flow.register_work(bands)\n\n # Build a work made of two SCR runs with different value of nband\n # Use max_ecuteps for the dielectric matrix (sigma tasks will\n # read a submatrix when we test the convergence wrt to ecuteps.\n scr_work = flowtk.Work()\n\n for inp in scr_inp.generate(nband=[10, 15]):\n inp.set_vars(ecuteps=max_ecuteps)\n scr_work.register_scr_task(inp, deps={bands.nscf_task: \"WFK\"})\n\n flow.register_work(scr_work)\n\n # Do a convergence study wrt ecuteps, each work is connected to a\n # different SCR file computed with a different value of nband.\n\n # Build a list of sigma inputs with different ecuteps\n sigma_inputs = list(sig_inp.generate(ecuteps=ecuteps_list))\n\n for scr_task in scr_work:\n sigma_conv = flowtk.SigmaConvWork(wfk_node=bands.nscf_task, scr_node=scr_task,\n sigma_inputs=sigma_inputs)\n flow.register_work(sigma_conv)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RP run_conducwork.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Conductivity in metals\n\nFlow to compute conductivity in metals\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import os\nimport sys\nimport abipy.data as abidata\nimport abipy.abilab as abilab\n\nfrom abipy import flowtk\nfrom abipy.abio.factories import conduc_kerange_from_inputs\n\n\ndef make_scf_input(structure, pseudos, ngkpt=(2,2,2), shiftk=(0,0,0),\n **variables):\n \"\"\"Build and return SCF input given the structure and pseudopotentials\"\"\"\n\n scf_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n\n # Global variables\n scf_inp.set_vars(**variables)\n\n # Dataset 1 (GS run)\n scf_inp.set_kmesh(ngkpt=ngkpt, shiftk=shiftk)\n #scf_inp.set_vars(toldfe=1e-10)\n\n return scf_inp\n\n\ndef make_nscf_input(structure, pseudos, ngkpt=(2,2,2), shiftk=(0,0,0),\n **variables):\n \"\"\"Build and return NSCF input given the structure and pseudopotentials\"\"\"\n scf_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n\n # Global variables\n scf_inp.set_vars(**variables)\n\n # Dataset 1 (GS run)\n scf_inp.set_kmesh(ngkpt=ngkpt, shiftk=shiftk)\n scf_inp.set_vars(iscf=-2)\n\n return scf_inp\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(__file__).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Get structure and pseudos from the abipy database\n structure = abidata.structure_from_ucell(\"Al\")\n pseudos = abidata.pseudos(\"13al.pspnc\")\n\n # Variables\n variables = dict(\n ecut=20,\n tsmear=0.05,\n nband=12,\n nbdbuf=2,\n occopt=3,\n iomode=1,\n nstep=20)\n\n ngkpt = [4, 4, 4]\n ngkpt_fine = [8, 8, 8]\n shiftk = [0.0, 0.0, 0.0]\n ngqpt = [2, 2, 2]\n tmesh = [0, 30, 11] # Conductivity at temp from 0K to 300K by increment of 30\n boxcutmin = 1.1\n mixprec = 1\n\n #Kerange Variables\n nbr_proc = 4\n ngqpt_fine = [16, 16, 16] # The sigma_ngkpt grid must be divisible by the qpt grid\n sigma_ngkpt = [16, 16, 16]\n einterp = [1, 5, 0, 0] # Star functions Interpolation\n sigma_erange = [-0.3, -0.3, \"eV\"] # Negative value for metals\n\n # Nom de mon flow\n flow = flowtk.Flow(workdir=options.workdir)\n\n # Create inputs Object\n scf_input = make_scf_input(structure, pseudos,\n tolvrs=1e-12,\n ngkpt=ngkpt,\n shiftk=shiftk,\n **variables)\n\n nscf_input = make_nscf_input(structure, pseudos,\n tolwfr=1e-18,\n ngkpt=ngkpt_fine,\n shiftk=shiftk,\n **variables)\n\n # Create Work Object\n # Work 0: SCF run\n gs_work = flowtk.Work()\n gs_work.register_scf_task(scf_input)\n flow.register_work(gs_work)\n\n # Work 1: Compute DDB et DVDB\n ph_work = flowtk.PhononWork.from_scf_task(gs_work[0],\n qpoints=ngqpt, is_ngqpt=True,\n tolerance={\"tolvrs\": 1e-8})\n flow.register_work(ph_work)\n\n # Work 2: Conduc with Kerange\n multi = conduc_kerange_from_inputs(scf_input=scf_input,\n nscf_input=nscf_input,\n tmesh=tmesh,\n ddb_ngqpt=ngqpt,\n eph_ngqpt_fine=ngqpt_fine,\n sigma_ngkpt=sigma_ngkpt,\n sigma_erange=sigma_erange,\n einterp=einterp,\n boxcutmin=boxcutmin, # 1.1 is the default value of the function\n mixprec=mixprec # 1 is the default value of the function\n )\n\n # Here we can change multi to change the variable of a particular dataset\n\n conduc_work = flowtk.ConducWork.from_phwork(phwork=ph_work, # Linking the DDB and DVDB via a |PhononWork|\n multi=multi, # The multidataset object\n nbr_proc=nbr_proc, # Needed to parallelize the calculation\n flow=flow,\n with_kerange=True, # Using Kerange\n omp_nbr_thread=1) # 1 is the default value of the function\n # If you already have the DDB and DVDB, use from_filepath(ddb_path, dvdb_path, multi, ...) instead of from_phwork\n\n flow.register_work(conduc_work)\n\n return flow.allocate(use_smartio=True)\n\n\n# This block generates the thumbnails in the Abipy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK Rq\v run_phonopy_si.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Phonopy with AbiPy Flow\n\nThis example shows how to compute phonon frequencies with phonopy\n(supercells and finite-difference method).\n\nThis approach could be useful to obtain vibrational properties with XC functionals\nfor which DFPT is not yet implemented.\n\n.. warning:\n\n This example requires the `phonopy package `_\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.abilab as abilab\nimport abipy.data as abidata\nimport abipy.flowtk as flowtk\n\nfrom abipy.flowtk.abiphonopy import PhonopyWork\n\n\ndef build_flow(options):\n \"\"\"\n Create a `Flow` for phonon calculations with phonopy:\n \"\"\"\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Initialize structure and pseudos\n structure = abilab.Structure.from_file(abidata.cif_file(\"si.cif\"))\n pseudos = abidata.pseudos(\"14si.pspnc\")\n\n # Build input for GS calculation.\n gsinp = abilab.AbinitInput(structure, pseudos)\n gsinp.set_vars(ecut=4, nband=4, toldff=1.e-6)\n\n # This gives ngkpt = 4x4x4 with 4 shifts for the initial unit cell.\n # The k-point sampling will be rescaled when we build the supercell in PhonopyWork.\n gsinp.set_autokmesh(nksmall=4)\n #gsinp.set_vars(ngkpt=[4, 4, 4])\n\n flow = flowtk.Flow(workdir=options.workdir)\n\n # Use a 2x2x2 supercell to compute phonons with phonopy\n work = PhonopyWork.from_gs_input(gsinp, scdims=[2, 2, 2])\n flow.register_work(work)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_phonopy_si.py -s\n\nthe output results are produced in ``flow_phonopy_si/w0/outdata/``\nFollow the instructions in the README file:\n\n.. code-block:: md\n\n To plot bands, use:\n phonopy -p band.conf\n\n To plot phonon dos, use:\n phonopy -p dos.conf\n\n To plot bands and dos, use:\n phonopy -p band-dos.conf\n\n See also:\n http://atztogo.github.io/phonopy/examples.html\n http://atztogo.github.io/phonopy/setting-tags.html#setting-tags\n\nThe command:\n\n phonopy -p band-dos.conf\n\nwill produce:\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R2 run_eph_al.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Flow for E-PH calculations\n\nThis flow computes the phonon linewidths and the Eliashberg function in Al.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport abipy.data as abidata\nimport abipy.abilab as abilab\nimport abipy.flowtk as flowtk\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\", \"flow_\")\n\n # Preparatory run for E-PH calculations.\n # The sequence of datasets makes the ground states and\n # all of the independent perturbations of the single Al atom\n # for the irreducible qpoints in a 4x4x4 grid.\n # Note that the q-point grid must be a sub-grid of the k-point grid (here 8x8x8)\n pseudos = abidata.pseudos(\"Al.oncvpsp\")\n\n structure = abilab.Structure.from_abivars(\n acell=3 * [7.5],\n rprim=[0.0, 0.5, 0.5,\n 0.5, 0.0, 0.5,\n 0.5, 0.5, 0.0],\n typat=1,\n xred=[0.0, 0.0, 0.0],\n ntypat=1,\n znucl=13,\n )\n\n same_structure = abilab.Structure.fcc(a=7.5, species=[\"Al\"], units=\"bohr\")\n assert same_structure == structure\n\n gs_inp = abilab.AbinitInput(structure, pseudos)\n\n gs_inp.set_vars(\n ecut=8.0,\n nband=5,\n occopt=7, # include metallic occupation function with a small smearing\n tsmear=0.04,\n tolvrs=1e-7,\n )\n\n # The kpoint grid is minimalistic to keep the calculation manageable.\n gs_inp.set_kmesh(\n ngkpt=[8, 8, 8],\n shiftk=[0.0, 0.0, 0.0],\n )\n\n # Phonon calculation with 4x4x4\n ddb_ngqpt = [4, 4, 4]\n qpoints = gs_inp.abiget_ibz(ngkpt=ddb_ngqpt, shiftk=[0, 0, 0], kptopt=1).points\n\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n work0 = flow.register_scf_task(gs_inp)\n\n ph_work = flowtk.PhononWork.from_scf_task(work0[0], qpoints)\n flow.register_work(ph_work)\n\n eph_work = flow.register_work(flowtk.Work())\n eph_deps = {work0[0]: \"WFK\", ph_work: [\"DDB\", \"DVDB\"]}\n\n for eph_ngqpt_fine in [(4, 4, 4,), (8, 8, 8)]:\n # Build input file for E-PH run.\n eph_inp = gs_inp.new_with_vars(\n optdriver=7,\n ddb_ngqpt=ddb_ngqpt, # q-mesh used to produce the DDB file (must be consistent with DDB data)\n eph_intmeth=2, # Tetra method\n eph_fsewin=\"0.8 eV\", # Energy window around Ef\n eph_mustar=0.12, # mustar parameter\n eph_ngqpt_fine=eph_ngqpt_fine, # Interpolate DFPT potentials if != ddb_ngqpt\n )\n\n # Set q-path for phonons and phonon linewidths.\n eph_inp.set_qpath(20)\n\n # TODO: Define wstep and smear\n # Set q-mesh for phonons DOS and a2F(w)\n eph_inp.set_phdos_qmesh(nqsmall=16, method=\"tetra\")\n eph_work.register_eph_task(eph_inp, deps=eph_deps)\n\n flow.allocate(use_smartio=True)\n\n return flow\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK R5HTE E run_raman_bse.ipynb{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n# Raman Flow with BSE and frozen phonon\n\nThis script shows how to perform a Raman calculation with\nexcitonic effects included with the BSE formalism.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import sys\nimport os\nimport numpy as np\nimport abipy.abilab as abilab\nimport abipy.data as abidata\nfrom abipy import flowtk\n\n\ndef build_flow(options):\n # Working directory (default is the name of the script with '.py' removed and \"run_\" replaced by \"flow_\")\n if not options.workdir:\n options.workdir = os.path.basename(sys.argv[0]).replace(\".py\", \"\").replace(\"run_\",\"flow_\")\n\n flow = flowtk.Flow(options.workdir, manager=options.manager)\n\n pseudos = abidata.pseudos(\"14si.pspnc\")\n\n # Get the unperturbed structure.\n base_structure = abidata.structure_from_ucell(\"Si\")\n\n etas = [-.001, 0, +.001]\n ph_displ = np.reshape(np.zeros(3*len(base_structure)), (-1,3))\n ph_displ[0,:] = [+1, 0, 0]\n ph_displ[1,:] = [-1, 0, 0]\n\n # Build new structures by displacing atoms according to the phonon displacement\n # ph_displ (in cartesian coordinates). The Displacement is normalized so that\n # the maximum atomic diplacement is 1 Angstrom and then multiplied by eta.\n modifier = abilab.StructureModifier(base_structure)\n\n displaced_structures = modifier.displace(ph_displ, etas, frac_coords=False)\n\n # Generate the different shifts to average\n ndiv = 2\n shift1D = np.arange(1,2*ndiv+1,2)/(2*ndiv)\n all_shifts = [[x,y,z] for x in shift1D for y in shift1D for z in shift1D]\n all_shifts = [[0, 0, 0]]\n\n for structure, eta in zip(displaced_structures, etas):\n for shift in all_shifts:\n flow.register_work(raman_work(structure, pseudos, shift))\n\n return flow\n\n\ndef raman_work(structure, pseudos, shiftk, paral_kgb=1):\n # Generate 3 different input files for computing optical properties with BSE.\n\n # Global variables\n global_vars = dict(\n ecut=8,\n istwfk=\"*1\",\n chksymbreak=0,\n #nstep=4,\n nstep=10,\n paral_kgb=paral_kgb,\n )\n\n # GS run\n scf_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n scf_inp.set_vars(global_vars)\n scf_inp.set_kmesh(ngkpt=[2, 2, 2], shiftk=shiftk)\n scf_inp[\"tolvrs\"] = 1e-6\n\n # NSCF run\n nscf_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n nscf_inp.set_vars(global_vars)\n nscf_inp.set_kmesh(ngkpt=[2, 2, 2], shiftk=shiftk)\n\n nscf_inp.set_vars(\n tolwfr=1e-8,\n nband=12,\n nbdbuf=4,\n iscf=-2,\n )\n\n # BSE run with Model dielectric function and Haydock (only resonant + W + v)\n # Note that SCR file is not needed here\n bse_inp = abilab.AbinitInput(structure, pseudos=pseudos)\n bse_inp.set_vars(global_vars)\n bse_inp.set_kmesh(ngkpt=[2, 2, 2], shiftk=shiftk)\n\n bse_inp.set_vars(\n optdriver=99,\n ecutwfn=global_vars[\"ecut\"],\n ecuteps=3,\n inclvkb=2,\n bs_algorithm=2, # Haydock\n bs_haydock_niter=4, # No. of iterations for Haydock\n bs_exchange_term=1,\n bs_coulomb_term=21, # Use model W and full W_GG.\n mdf_epsinf=12.0,\n bs_calctype=1, # Use KS energies and orbitals to construct L0\n mbpt_sciss=\"0.8 eV\",\n bs_coupling=0,\n bs_loband=2,\n nband=6,\n #bs_freq_mesh=\"0 10 0.1 eV\",\n bs_hayd_term=0, # No terminator\n )\n\n # Build the work representing a BSE run with model dielectric function.\n return flowtk.BseMdfWork(scf_inp, nscf_inp, bse_inp)\n\n\n# This block generates the thumbnails in the AbiPy gallery.\n# You can safely REMOVE this part if you are using this script for production runs.\nif os.getenv(\"READTHEDOCS\", False):\n __name__ = None\n import tempfile\n options = flowtk.build_flow_main_parser().parse_args([\"-w\", tempfile.mkdtemp()])\n build_flow(options).graphviz_imshow()\n\n\n@flowtk.flow_main\ndef main(options):\n \"\"\"\n This is our main function that will be invoked by the script.\n flow_main is a decorator implementing the command line interface.\n Command line args are stored in `options`.\n \"\"\"\n return build_flow(options)\n\n\nif __name__ == \"__main__\":\n sys.exit(main())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Run the script with:\n\n run_raman_bse.py -s\n\nthen use:\n\n abirun.py flow_raman_bse robot MDF\n\nto analyze all the macroscopic dielectric functions produced by the Flow with the robot.\nInside the ipython terminal type:\n\n.. code-block:: ipython\n\n [1] %matplotlib\n [2] robot.plot()\n\nto compare the real and imaginary part of the macroscopic dielectric function for the different displacements.\n\n\n\n\n"
]
}
],
"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.8.0"
}
},
"nbformat": 4,
"nbformat_minor": 0
}PK RWk k run_ldaus.ipynbPK R' run_raman_optic.ipynbPK Rwim b7 run_sic_relax.ipynbPK R?M xI run_phonons_with_quad.ipynbPK RdD0 _ run_gruneisen_abinit.ipynbPK RM"= o run_relax_vs_kpts_tsmear.ipynbPK Ruሳ " Q run_mgb2_phonons_nkpt_tsmear.ipynbPK R;Y D run_phfrozen_ebands.ipynbPK R
run_effmass_finitediff.ipynbPK RaPS I run_nonlinear.ipynbPK R|- _ run_from_files.ipynbPK R܂ run_phonons.ipynbPK R;Y Y G run_gaas_ebands_soc.ipynbPK RQb run_relax.ipynbPK RM{ * run_screening.ipynbPK Rlqz @ run_optic.ipynbPK R4} " W run_becs_and_epsilon_vs_kpts.ipynbPK Rlz Ok run_flexoelectric.ipynbPK ݄R@} } t run_si_ebands.ipynbPK RZM9 9 " run_relax_and_ebands.ipynbPK R,0 0 run_effmass_dfpt.ipynbPK R.Ɇ$ run_phonons_wkq.ipynbPK R$2
run_eph_pot.ipynbPK R.*' 1 run_frohlich_zpr.ipynbPK R$ run_frohlich_zpr_from_ddb.ipynbPK R6
run_gkq.ipynbPK Rt]ZT T m run_mgb2_edoses.ipynbPK RĚD) ) 8 run_ht_si_g0w0ppm.ipynbPK R b run_ht_si_bsemdf.ipynbPK R/W y run_eph_mob.ipynbPK RX1 1 run_elastic.ipynbPK ݄Ro run_ht_si_ebands.ipynbPK RRi i
5 run_eos.ipynbPK RPn run_fe_ebands.ipynbPK R6
run_relax_vs_kpts.ipynbPK R>t1% % + run_si_g0w0.ipynbPK Ry3vw w " run_gwconv_ecuteps.ipynbPK RP ,6 run_conducwork.ipynbPK Rq\v WP run_phonopy_si.ipynbPK R2 a run_eph_al.ipynbPK R5HTE E s run_raman_bse.ipynbPK ) )
Y