Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sumo-optplot failed to plot optical absorption spectra diagrams of VASP GW+BSE computation. #221

Closed
hongyi-zhao opened this issue Aug 3, 2023 · 17 comments

Comments

@hongyi-zhao
Copy link

hongyi-zhao commented Aug 3, 2023

I try to test sumo-optplot using the calculation results of Dielectric_properties_of_Si_using_BSE, but failed as follows:

(datasci) werner@X10DAi:~/Downloads/GW_BSE/Si_BSE$ sumo-optplot 
Traceback (most recent call last):
  File "/home/werner/.pyenv/versions/datasci/bin/sumo-optplot", line 33, in <module>
    sys.exit(load_entry_point('sumo', 'console_scripts', 'sumo-optplot')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/Public/repo/github.com/SMTG-UCL/sumo.git/sumo/cli/optplot.py", line 455, in main
    optplot(
  File "/home/werner/Public/repo/github.com/SMTG-UCL/sumo.git/sumo/cli/optplot.py", line 170, in optplot
    latexify(vr.final_structure.composition.reduced_formula).replace(
             ^^^^^^^^^^^^^^^^^^
AttributeError: 'Vasprun' object has no attribute 'final_structure'. Did you mean: 'initial_structure'?


(datasci) werner@X10DAi:~/Downloads/GW_BSE/Si_BSE$ sumo-optplot ./vasprun.xml
usage: sumo-optplot [-h] [-f F [F ...]] [-p P] [-d D] [-c C [C ...]] [-g G] [-b [E ...]]
                    [-l L [L ...]] [-a] [--height HEIGHT] [--width WIDTH] [--xmin XMIN] [--xmax XMAX]
                    [--ymin YMIN [YMIN ...]] [--ymax YMAX [YMAX ...]] [--style STYLE [STYLE ...]]
                    [--no-base-style] [--format FORMAT] [--dpi DPI] [--font FONT] [--units UNITS]
                    [M ...]
sumo-optplot: error: argument M: invalid choice: './vasprun.xml' (choose from 'eps_real', 'absorption', 'n_real', 'n_imag', 'loss', 'eps_imag')

I attached the vasprun.xml file below.

vasprun.zip

Regards,
Zhao

@utf
Copy link
Member

utf commented Aug 3, 2023

sumo-optplotautomatically looks for the vasprun in the current directory. If you want to specify the file explicitly you need to use the -f option. E.g., sumo-optplot -f vasprun.xml. See the docs for more details: https://smtg-ucl.github.io/sumo/sumo-optplot.html

@utf utf closed this as completed Aug 3, 2023
@utf utf reopened this Aug 3, 2023
@utf
Copy link
Member

utf commented Aug 3, 2023

I just realised I only responded to your second issue. I will look into the first one.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Aug 3, 2023

sumo-optplotautomatically looks for the vasprun in the current directory. If you want to specify the file explicitly you need to use the -f option. E.g., sumo-optplot -f vasprun.xml. See the docs for more details: https://smtg-ucl.github.io/sumo/sumo-optplot.html

This does not solve the problem, as shown below:

(datasci) werner@X10DAi:~/Downloads/GW_BSE/Si_BSE$ sumo-optplot -f vasprun.xml
Traceback (most recent call last):
  File "/home/werner/.pyenv/versions/datasci/bin/sumo-optplot", line 33, in <module>
    sys.exit(load_entry_point('sumo', 'console_scripts', 'sumo-optplot')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/werner/Public/repo/github.com/SMTG-UCL/sumo.git/sumo/cli/optplot.py", line 455, in main
    optplot(
  File "/home/werner/Public/repo/github.com/SMTG-UCL/sumo.git/sumo/cli/optplot.py", line 170, in optplot
    latexify(vr.final_structure.composition.reduced_formula).replace(
             ^^^^^^^^^^^^^^^^^^
AttributeError: 'Vasprun' object has no attribute 'final_structure'. Did you mean: 'initial_structure'?

@ajjackson
Copy link
Member

Taking a look at the Pymatgen code: the Vasprun parser has lots of places that assume final_structure has been set, but it is only set under certain conditions when the relevant data is found in the file:
https://github.com/materialsproject/pymatgen/blob/6d1ffa40123f4f714323f4308418b4062d422d65/pymatgen/io/vasp/outputs.py#L475

So if your Vasprun object does not have a final_structure attribute, this means that either:

  • your calculation output is invalid (did it terminate succesfully?), or
  • there exist valid outputs that don't have "finalpos" structure block. (i.e. a bug in Pymatgen, which assumes that they always do.)

@utf
Copy link
Member

utf commented Aug 3, 2023

The VASP output is for a GW BSE calculation. I guess that includes different outputs than a regular optics calculation. I don't have much experience in them though.

@ajjackson
Copy link
Member

Ah right. I started a branch to implement some of these other dielectric function calculations a few years ago but didn't have much incentive to work on it after leaving UCL 😆

#48

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Aug 3, 2023

With the increasing number of researchers using GW+BSE method in current and future computational study, this is not an issue that can be casually ignored. For example, there is a dedicated package pyGWBSE developed for this purpose, which also based on pymatgen.

So, I must first confirm whether the current issue is in sumo or Pymatgen. If it is the latter, I should submit a bug report there. Otherwise, it should be fixed in this project.

@hongyi-zhao hongyi-zhao changed the title sumo-optplot failed to plot optical absorption spectra diagrams. sumo-optplot failed to plot optical absorption spectra diagrams of VASP GW+BSE computation. Aug 4, 2023
@hongyi-zhao
Copy link
Author

Taking a look at the Pymatgen code: the Vasprun parser has lots of places that assume final_structure has been set, but it is only set under certain conditions when the relevant data is found in the file: https://github.com/materialsproject/pymatgen/blob/6d1ffa40123f4f714323f4308418b4062d422d65/pymatgen/io/vasp/outputs.py#L475

So if your Vasprun object does not have a final_structure attribute, this means that either:

* your calculation output is invalid (did it terminate succesfully?), or

* there exist valid outputs that don't have "finalpos" structure block. (i.e. a bug in Pymatgen, which assumes that they always do.)

See the comment given by @shyuep below:

I don't think a final_structure even makes sense in a GW_BSE calculation isn't it? It only makes sense in a relaxation. This is not a bug. It simply means the calculation does not change the position of the atoms.

@ajjackson
Copy link
Member

ajjackson commented Aug 7, 2023

Well, the line of code triggering the error here is only responsible for getting the chemical formula anyway. So Sumo could possibly be made more robust against this specific (i.e. optics) situation where the vasprun is not used heavily.

As far as I can tell from the code, many attributes of the Pymatgen Vasprun object such CompleteDos, get_computed_entry(), get_band_structure() ... will attempt to access self.final_structure regardless of whether it "makes sense".

@shyuep
Copy link

shyuep commented Aug 7, 2023

In any case, I have just pushed a fix that makes sure Vasprun.final_structure == Vasprun.initial_structure if there is no relaxation. For getting the chemical formula only, the initial structure (which is always set) is as good as the final structure.

@utf
Copy link
Member

utf commented Aug 7, 2023

Agreed that using initial_structure is the better way to go, and we should probably update sumo to use that. But thanks for the fix @shyuep.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Aug 7, 2023

Glad to see this progress. This problem also makes pymatgen more robust via the fix added by @shyuep.

@ajjackson
Copy link
Member

That sounds great, hopefully the upstream fix will prevent the same issue being hit for other properties.

@hongyi-zhao
Copy link
Author

Now, it works, but even I use the -a option, it still generates only one plot, as shown below:

$ sumo-optplot -a -f ./vasprun.xml 

image

@ajjackson
Copy link
Member

Is the data for xx, yy, zz different in the file? It looks like it plotted all three but they were identical.

@hongyi-zhao
Copy link
Author

hongyi-zhao commented Aug 10, 2023

It seems that your conjecture is correct:

In [6]: import pymatgen.io.vasp as vasp
   ...: import numpy as np
   ...: 
   ...: # Read the vasprun.xml file
   ...: vr = vasp.Vasprun("sumo/vasprun.xml")
   ...: e2 = np.array(vr.dielectric[2])
   ...: e2x = e2[:, 0]
   ...: e2y = e2[:, 1]
   ...: e2z = e2[:, 2]
   ...: 
   ...: # Calculate absolute differences and store them in new lists
   ...: differences_x_y = [abs(a - b) for a, b in zip(e2x, e2y)]
   ...: differences_y_z = [abs(a - b) for a, b in zip(e2y, e2z)]
   ...: differences_z_x = [abs(a - b) for a, b in zip(e2z, e2x)]
   ...: 
   ...: # Calculate the maximum and minimum absolute differences
   ...: max_difference = max(max(differences_x_y), max(differences_y_z), max(differences_z_x))
   ...: min_difference = min(min(differences_x_y), min(differences_y_z), min(differences_z_x))
   ...: 
   ...: # Print the maximum and minimum values
   ...: print(f"Maximum absolute difference: {max_difference}")
   ...: print(f"Minimum absolute difference: {min_difference}")
   ...: 
/home/werner/Public/hpc/tools/materialsproject/pymatgen.git/pymatgen/io/vasp/outputs.py:1084: UserWarning: No POTCAR file with matching TITEL fields was found in /home/werner/Public/hpc/vasp/learning-by-doing/optical-absorption-spectra/sumo
  warnings.warn(f"No POTCAR file with matching TITEL fields was found in {os.path.abspath(p)}")
Maximum absolute difference: 0.18339999999999979
Minimum absolute difference: 0.0

@ajjackson
Copy link
Member

Good, good! Then I will close this issue for now.

I suppose we should make a note to update the Pymatgen requirements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants