py4vasp band plot and save
Moderators: Global Moderator, Moderator
-
- Newbie
- Posts: 34
- Joined: Wed Aug 03, 2022 10:42 am
py4vasp band plot and save
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
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
-
- Global Moderator
- Posts: 126
- Joined: Mon May 08, 2023 4:08 pm
Re: py4vasp band plot and save
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:
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:
- 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, )
- 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)
Manuel
VASP developer
VASP developer
-
- Newbie
- Posts: 34
- Joined: Wed Aug 03, 2022 10:42 am
Re: py4vasp band plot and save
Hello
Thank you for your response. The first one works, but unfortunately, for second one I get this error:
KeyError: 'bands'
Best regards,
Asiyeh
Thank you for your response. The first one works, but unfortunately, for second one I get this error:
KeyError: 'bands'
Best regards,
Asiyeh
-
- Global Moderator
- Posts: 126
- Joined: Mon May 08, 2023 4:08 pm
Re: py4vasp band plot and save
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
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"]
Code: Select all
bands = bands_dict["bands_up"]
Manuel
VASP developer
VASP developer
-
- Newbie
- Posts: 34
- Joined: Wed Aug 03, 2022 10:42 am
Re: py4vasp band plot and save
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
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
-
- Global Moderator
- Posts: 126
- Joined: Mon May 08, 2023 4:08 pm
Re: py4vasp band plot and save
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:
The same goes of course for the regular KPOINTS file but that is selected by default anyway.
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")
Manuel
VASP developer
VASP developer
-
- Newbie
- Posts: 34
- Joined: Wed Aug 03, 2022 10:42 am
Re: py4vasp band plot and save
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
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
-
- Global Moderator
- Posts: 542
- Joined: Fri Nov 08, 2019 7:18 am
Re: py4vasp band plot and save
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
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.
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 Γ
Martin Schlipf
VASP developer
-
- Newbie
- Posts: 34
- Joined: Wed Aug 03, 2022 10:42 am
Re: py4vasp band plot and save
Thank you for explaining. Here is my KPOINTS file:
and using fig = calc.band.to_plotly() yet instead of high symmetry points I get 1 1 1...
Best regards,
Asiyeh
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
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
Reason: Put k-points file into code block for better readability
-
- Global Moderator
- Posts: 542
- Joined: Fri Nov 08, 2019 7:18 am
Re: py4vasp band plot and save
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
-
- Newbie
- Posts: 34
- Joined: Wed Aug 03, 2022 10:42 am
Re: py4vasp band plot and save
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
Best regards,
Asiyeh
Last edited by asiyeh_shokri2 on Fri Aug 02, 2024 12:38 pm, edited 5 times in total.
-
- Global Moderator
- Posts: 542
- Joined: Fri Nov 08, 2019 7:18 am
Re: py4vasp band plot and save
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