<jupyter_start><jupyter_text>Exercise 4: Band structure calculations In this notebook we will see, how to calculate band structures using pyiron.<jupyter_code>from pyiron.project import Project
from ase.spacegroup import crystal
import matplotlib.pyplot as plt
import seekpath as sp
import numpy as np
pr = Project("demo/band_structure")
# pr.remove_jobs(recursive=True)<jupyter_output><empty_output><jupyter_text>Structures with seekpath First we see how [seekpath](https://github.com/giovannipizzi/seekpath) works! Therefore we create firts a structure using pyiron.  Create structure with pyiron<jupyter_code>structure_Fe = pr.create_structure("Fe", "bcc", 2.81)
structure_Fe.plot3d()
structure_Fe<jupyter_output><empty_output><jupyter_text>Create structure with seekpath For seekpath we need a tuple containing1. The cell in $3\times3$ array2. The scaled positions3. List of `ints` to distinguish the atom types (indices of pyiron structure)as input structure.<jupyter_code>input_sp = (structure_Fe.cell, structure_Fe.get_scaled_positions(), structure_Fe.indices)<jupyter_output><empty_output><jupyter_text>Just to see how the output looks like, let us do...<jupyter_code>sp.get_path(input_sp)<jupyter_output><empty_output><jupyter_text>The code creates automatically the conventional and primitive cell with all high-symmetry points and a suggested path taking all high-symmetry paths into account.**Keep in mind:** The high-symmetry points and paths make only sence for the primitive cell! Therefore we run all calculations in the primitive cell created by seekpath.  Create a structure We use the same structure as before!  Create new structure (primitive cell) with high-symmetry points and paths For the following command all arguments valid for seekpath are supported. Look at the docstring and at seekpath.<jupyter_code>structure_Fe_sp = structure_Fe.create_line_mode_structure()
structure_Fe_sp.plot3d()
structure_Fe_sp<jupyter_output><empty_output><jupyter_text>We see, that the structure is now the primitive cell containing only one atom.<jupyter_code>structure_Fe_sp.get_high_symmetry_points()
structure_Fe_sp.get_high_symmetry_path()<jupyter_output><empty_output><jupyter_text>The path is stored like this. Here you can also add paths to the dictionary.Each tuple gives a start and end point for this specific trace. Thus also disonnected paths are possible to calculate.<jupyter_code>structure_Fe_sp.add_high_symmetry_path({"my_path": [("GAMMA", "H"), ("GAMMA", "P")]})
structure_Fe_sp.get_high_symmetry_path()<jupyter_output><empty_output><jupyter_text>Create jobs We need two jobs for a band structure! The first gives us the correct Fermi energy and the charge densities used for the second calculations.  Create job for charge density This is only a small example for BS calculations. Could be that the input parameter like cutoff etc. does not make much sense... for real physics...<jupyter_code>def setup_hamiltonian_sphinx(project, jobname, structure, chgcar_file=""): 
    
    #version 1.0 (08.03.2019)
    
    #Name und typ
    ham = project.create_job(job_type='Sphinx', job_name=jobname)
    
    #parameter für xc functional
    ham.exchange_correlation_functional = 'PBE'
    
    #struktur
    ham.structure = structure
    
    ham.set_encut(450)
    ham.set_empty_states(6)
    ham.set_convergence_precision(electronic_energy=1e-8)
    ham.set_occupancy_smearing(width=0.2)
          
    #parameter für kpoints
    ham.set_kpoints([8, 8, 8])
    
    return ham
ham_spx_chg = setup_hamiltonian_sphinx(pr, "Fe_spx_CHG", structure_Fe_sp)<jupyter_output><empty_output><jupyter_text>Run it!<jupyter_code>ham_spx_chg.run()
pr.get_jobs_status()<jupyter_output><empty_output><jupyter_text>Create second job We restart the fist job with the following command. Then the charge density of the first job is taken for the second!<jupyter_code>ham_spx_bs = ham_spx_chg.restart_for_band_structure_calculations(job_name="Fe_spx_BS")<jupyter_output><empty_output><jupyter_text>Set line mode for k-points To set the correct path, we have to give the name of the path (in our example either `full` or `my_path`) and the number of points for each subpath (would be for `n_path=100`and `path_name="my_path"` 200 k-points in total)<jupyter_code>ham_spx_bs.set_kpoints(scheme="Line", path_name="full", n_path=100)<jupyter_output>/srv/conda/envs/notebook/lib/python3.7/site-packages/pyiron_base/generic/inputlist.py:325: UserWarning: The input in Group changed, while the state of the job was already finished.
  "finished.".format(cls.__name__)<jupyter_text>A parameter usefull for BS calculations. Look at the sphinx manual for details.<jupyter_code>ham_spx_bs.input["nSloppy"] = 6<jupyter_output><empty_output><jupyter_text>Run it!<jupyter_code>ham_spx_bs.run()
pr.get_jobs_status()<jupyter_output><empty_output><jupyter_text>Store the data! The energy values are stored in the following paths of the hdf5 file.<jupyter_code>energy_sphinx = ham_spx_bs['output/generic/dft/bands_eigen_values'][-1]
ef_sphinx = ham_spx_chg['output/generic/dft/bands_e_fermi'][-1]
energy_sphinx -= ef_sphinx<jupyter_output><empty_output><jupyter_text>Plot it! Now we can easily plot it!<jupyter_code>plt.plot(energy_sphinx[:-1], 'b-')
plt.axhline(y=0, ls='--', c='k')
plt.xlim(0, len(energy_sphinx));
plt.ylim(-10,40);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.090177736202058, 'fraction_numerical': 0.010664172123479887, 'mean_word_length': 6.466480446927374, 'pattern_counts': {'":': 1, '<': 60, '<?xml version=': 0, '>': 60, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '580781', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1797, 'n_tokens_neox': 1746, 'n_words': 482, 'path': 'book/tutorials/sol_4_bandstructure.ipynb', 'repo_name': 'pyiron/pyiron-virtual-workshop-2020', 'size': '5345'}