py4vasp band plot and save

Queries about input and output files, running specific calculations, etc.


Moderators: Global Moderator, Moderator

Post Reply
Message
Author
asiyeh_shokri2
Newbie
Newbie
Posts: 32
Joined: Wed Aug 03, 2022 10:42 am

py4vasp band plot and save

#1 Post by asiyeh_shokri2 » Mon Jul 29, 2024 3:39 pm

Hello

I am using py4vasp to plot my bandstructre. I would like to know how can I extract .dat format or change the size of the plot before saving it.
I know I can use for example vaspkit, but is it possible using py4vasp?

Best regards,
Asiyeh

manuel_engel1
Global Moderator
Global Moderator
Posts: 121
Joined: Mon May 08, 2023 4:08 pm

Re: py4vasp band plot and save

#2 Post by manuel_engel1 » Tue Jul 30, 2024 8:45 am

Hi Asiyeh,

Thanks for posting on the forum. The capabilities of py4vasp are constantly evolving. As a result, some features might still be missing or they might be incomplete. However, here are two advanced ways of achieving what you want with the current version of py4vasp:
  1. Use the to_plotly function of the data class to get the underlying plotly figure. This allows you to modify the figure in the same way you could modify any other plotly figure (for details, please consult the official plotly documentation).

    Code: Select all

    from py4vasp import Calculation
    calc = Calculation.from_path(".")
    fig = calc.band.to_plotly()
    fig.update_layout(
        autosize=False,
        width=800,
        height=800,
    )
    
  2. Extract the x/y values programmatically and write them to a text file. I provide you with a small python snippet that should do what you want (1st column is k-point distances, other columns are eigenvalues of each band):

    Code: Select all

    from py4vasp import Calculation
    calc = Calculation.from_path(".")
    band_dict = calc.band.to_dict()
    dists = band_dict["kpoint_distances"]
    bands = band_dict["bands"]
    data = np.hstack([dists[:, np.newaxis], bands])
    np.savetxt("band.dat", data)
    
If you are using the new KPOINTS_OPT driver for band-structure calculations, make sure to update these snippets to use the KPOINTS_OPT data instead. Let me know if this works for you.
Manuel
VASP developer

asiyeh_shokri2
Newbie
Newbie
Posts: 32
Joined: Wed Aug 03, 2022 10:42 am

Re: py4vasp band plot and save

#3 Post by asiyeh_shokri2 » Tue Jul 30, 2024 12:22 pm

Hello

Thank you for your response. The first one works, but unfortunately, for second one I get this error:
KeyError: 'bands'

Best regards,
Asiyeh

manuel_engel1
Global Moderator
Global Moderator
Posts: 121
Joined: Mon May 08, 2023 4:08 pm

Re: py4vasp band plot and save

#4 Post by manuel_engel1 » Tue Jul 30, 2024 12:45 pm

I'm glad the first method is already working for you. Regarding the second one, are you running a spin-polarized calculation (ISPIN=2)? In this case, instead of

Code: Select all

bands = bands_dict["bands"]
in the snippet I posted, you would have to choose either "bands_up" or "bands_down", depending on the spin component you are interested in. For example, to get the band structure for the spin-up channel:

Code: Select all

bands = bands_dict["bands_up"]
Manuel
VASP developer

asiyeh_shokri2
Newbie
Newbie
Posts: 32
Joined: Wed Aug 03, 2022 10:42 am

Re: py4vasp band plot and save

#5 Post by asiyeh_shokri2 » Tue Jul 30, 2024 1:22 pm

Thank you for your help. Yes it is working when I change bands to bands_up or down.
Can you please help also with the k-points on the x-axis. I saw some time ago that I should use "source=kpoints" but I get error using this method on source.

Best regards,
Asiyeh

manuel_engel1
Global Moderator
Global Moderator
Posts: 121
Joined: Mon May 08, 2023 4:08 pm

Re: py4vasp band plot and save

#6 Post by manuel_engel1 » Tue Jul 30, 2024 1:37 pm

Great that it's working!

The source keyword was removed in recent versions of py4vasp. It is now possible to select the KPOINTS source by simply specifying it as a string. For example, to use the bands from the KPOINTS_OPT file, you can adapt the function calls like so:

Code: Select all

# to get a figure
fig = calc.band.to_plotly("kpoints_opt")
# to get the dictionary
band_dict = calc.band.to_dict("kpoints_opt")
# to simply plot
calc.band.plot("kpoints_opt")
The same goes of course for the regular KPOINTS file but that is selected by default anyway.
Manuel
VASP developer

asiyeh_shokri2
Newbie
Newbie
Posts: 32
Joined: Wed Aug 03, 2022 10:42 am

Re: py4vasp band plot and save

#7 Post by asiyeh_shokri2 » Tue Jul 30, 2024 1:48 pm

I am not using kpints_opt for now. but in case of kpoints if I put " " empty I get the plot and on x axis I see 1 1 1 .. instead of high symmetry kpoints. and if I put "kpoints":
IncorrectUsage: Could not find `kpoints` in the list of projectors. Please check if everything is spelled correctly. Notice that the selection is case sensitive so that 's' (orbital) can be distinguished from 'S' (sulfur).

Best regards,
Asiyeh

martin.schlipf
Global Moderator
Global Moderator
Posts: 531
Joined: Fri Nov 08, 2019 7:18 am

Re: py4vasp band plot and save

#8 Post by martin.schlipf » Wed Jul 31, 2024 7:01 am

If you are wondering about the high-symmetry labels, py4vasp takes them from the KPOINTS file (or KPOINTS_OPT). To do so, please give your high symmetry points labels in the file like this

Code: Select all

k points along high symmetry lines
 40              ! number of points per line
line mode
fractional
  0    0    0    Γ
  0.5  0.5  0    X

  0.5  0.5  0    X
  0.5  0.75 0.25 W

  0.5  0.75 0.25 W
  0    0    0    Γ
Note that for the default KPOINTS file you do not need to select anything, so calc.band.plot() will use the k points in KPOINTS, calc.band.plot("kpoints_opt") will use the ones from KPOINTS_OPT. In either case you should see the high symmetry labels you provide added to the x axis.

Martin Schlipf
VASP developer


asiyeh_shokri2
Newbie
Newbie
Posts: 32
Joined: Wed Aug 03, 2022 10:42 am

Re: py4vasp band plot and save

#9 Post by asiyeh_shokri2 » Wed Jul 31, 2024 8:57 am

Thank you for explaining. Here is my KPOINTS file:

Code: Select all

k points along high symmetry lines
20  ! number of points per line 
line-mode
reciprocal
  0.0000000000	   0.0000000000	    0.0000000000 Γ
  0.2663201916	   0.2663201916	    0.0000000000 C 
          
 -0.2663201916	   0.7336798084	    0.0000000000 C_2
 -0.5000000000	   0.5000000000	    0.0000000000 Y_2
              
              
 -0.5000000000	   0.5000000000	    0.0000000000 Y_2
  0.0000000000	   0.0000000000	    0.0000000000 Γ
                     
                     
  0.0000000000	   0.0000000000     0.0000000000 Γ
 -0.5000000000 	   0.5000000000	    0.5000000000 M_2
                            
                            
 -0.5000000000     0.5000000000     0.5000000000 M_2
 -0.2581231308     0.7418768692     0.5000000000 D 
                                  
                                  
  0.2581231308     0.2581231308     0.5000000000 D_2
  0.0000000000     0.0000000000     0.5000000000 A 
                                          
                                          
  0.0000000000     0.0000000000     0.5000000000 A 
  0.0000000000     0.0000000000     0.0000000000 Γ
                                                  
                                                  
  0.0000000000     0.5000000000     0.5000000000 L_2
  0.0000000000     0.0000000000     0.0000000000 Γ
                                                          
                                                          
  0.0000000000     0.0000000000     0.0000000000 Γ
  0.0000000000     0.5000000000     0.0000000000 V_2
and using fig = calc.band.to_plotly() yet instead of high symmetry points I get 1 1 1...

Best regards,
Asiyeh
Last edited by manuel_engel1 on Wed Jul 31, 2024 11:52 am, edited 1 time in total.
Reason: Put k-points file into code block for better readability

martin.schlipf
Global Moderator
Global Moderator
Posts: 531
Joined: Fri Nov 08, 2019 7:18 am

Re: py4vasp band plot and save

#10 Post by martin.schlipf » Wed Jul 31, 2024 6:31 pm

Can you attach the vaspout.h5 file, please? If it is too big see if you can reproduce the issue in a simpler system with less points and attach that file.

Martin Schlipf
VASP developer


asiyeh_shokri2
Newbie
Newbie
Posts: 32
Joined: Wed Aug 03, 2022 10:42 am

Re: py4vasp band plot and save

#11 Post by asiyeh_shokri2 » Fri Aug 02, 2024 11:27 am

I am sending you a test gga-band using kpoints_opt for Graphene with gamma only kpoints and even for this structure the file can not be attached!I did just because my own result was too large to be attached.

Best regards,
Asiyeh
Last edited by asiyeh_shokri2 on Fri Aug 02, 2024 12:38 pm, edited 5 times in total.

martin.schlipf
Global Moderator
Global Moderator
Posts: 531
Joined: Fri Nov 08, 2019 7:18 am

Re: py4vasp band plot and save

#12 Post by martin.schlipf » Tue Aug 27, 2024 1:04 pm

Does this issue still persist? If you cannot send the vaspout.h5 file, can you send the other input files so that I can reproduce the calculation locally?

Martin Schlipf
VASP developer


Post Reply