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

Fix: BSPlotterProjected._Orbitals_SumOrbitals() method #4167

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ShengLin1001
Copy link

Fix: Ensure BSPlotterProjected._Orbitals_SumOrbitals() checks if sum_morbs is not None, as a NoneType object cannot be iterated.

Summary

Major changes:

  • Fixed the BSPlotterProjected._Orbitals_SumOrbitals() method to handle cases where sum_morbs is None.

Description

When running the following code, I encountered an error in the get_projected_plots_dots_patom_pmorb() method, which uses _Orbitals_SumOrbitals(). The error occurred because sum_morbs was None, making it non-iterable.

This fix addresses the issue by ensuring that sum_morbs is checked to confirm it is not None before any iteration, especially when plotting a single orbital. The order of statements has been adjusted accordingly.

Example Code to Reproduce:

from pymatgen.electronic_structure.plotter import DosPlotter, BSPlotter, BSPlotterProjected, BSDOSPlotter
from pymatgen.io.vasp import BSVasprun, Vasprun

v = BSVasprun("./bs/vasprun.xml", parse_projected_eigen=True)
bs = v.get_band_structure(kpoints_filename="./bs/KPOINTS", line_mode=True)
plotter = BSPlotterProjected(bs)
plotter.get_projected_plots_dots_patom_pmorb({"Au": ["dxy"]}, {"Au": [1]}, ylim=[-5, 5])

This change ensures more robust handling of cases where sum_morbs is None to prevent runtime errors.

… is not None, because Nonetype couldn't be iterable
@ShengLin1001
Copy link
Author

And I also have a question, why we need run this

elif len(dictio[elt][0]) > 1:

for example code, the len("dxy") = 3, what's meaning of this?

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

Successfully merging this pull request may close these issues.

2 participants