SMTG-Bham / sumo

Heavyweight plotting tools for ab initio calculations
https://smtg-bham.github.io/sumo/
MIT License
194 stars 79 forks source link

KeyError: 'up', when setting spin='up' #94

Closed zrqustc closed 4 years ago

zrqustc commented 4 years ago

Dear developers,

When I want to plot one spin channel, I got KeyError: 'up'.


KeyError Traceback (most recent call last)

in 10 spin='up', 11 ymin=-1, ymax=1, ---> 12 width=a,height=b) 13 #for i in range(72): 14 # plt.plot(X[i,:], Y[i,:],linewidth=2.0,c='b') ~/.local/lib/python3.6/site-packages/sumo/cli/bandplot.py in bandplot(filenames, code, prefix, directory, vbm_cbm_marker, projection_selection, mode, interpolate_factor, circle_size, dos_file, cart_coords, scissor, ylabel, dos_label, elements, lm_orbitals, atoms, spin, total_only, plot_total, legend_cutoff, gaussian, height, width, ymin, ymax, colours, yscale, style, no_base_style, image_format, dpi, plt, fonts) 311 plt=plt, dos_plotter=dos_plotter, dos_options=dos_opts, 312 dos_label=dos_label, fonts=fonts, style=style, --> 313 no_base_style=no_base_style, spin=spin) 314 315 if save_files: ~/.local/lib/python3.6/site-packages/sumo/plotting/__init__.py in wrapper(fonts, style, no_base_style, *args, **kwargs) 59 60 matplotlib.pyplot.style.use(list_style) ---> 61 return get_plot(*args, **kwargs) 62 63 return wrapper ~/.local/lib/python3.6/site-packages/sumo/plotting/bs_plotter.py in get_plot(self, zero_to_efermi, ymin, ymax, width, height, vbm_cbm_marker, ylabel, dpi, plt, plot_dos_legend, dos_plotter, dos_options, dos_label, dos_aspect, aspect, fonts, style, no_base_style, spin) 164 165 elif spin is not None: --> 166 is_vb = self._bs.bands[spin] <= self._bs.get_vbm()['energy'] 167 elif self._bs.is_spin_polarized or self._bs.is_metal(): 168 is_vb = [True] KeyError: 'up'
utf commented 4 years ago

@kavanase can you look into this?

kavanase commented 4 years ago

Dear @zrqustc, Thank you for raising this issue and attaching your error log. It seems that the spin argument being passed to bs_plotter.py is not being correctly parsed and converted to a pymatgen Spin.up object. From your error log, it appears you are using the sumo Python API functions rather than the command line, and this is what leads to the error. From inspection of the code and your error log, I can see that the string_to_spin conversion function (which converts the input --spin flag to a pymatgen Spin object) is only applied to the cli argument parser, and so does not convert your spin argument when directly using the bandplot function. This is a minor bug which I will fix now. Thanks again for raising this issue!

zrqustc commented 4 years ago

Okay, Thanks for your reply.

Best, Ruiqi

On Tue, Mar 10, 2020 at 8:02 AM Seán Kavanagh notifications@github.com wrote:

Dear @zrqustc https://github.com/zrqustc, Thank you for raising this issue and attaching your error log. It seems that the spin argument being passed to bs_plotter.py is not being correctly parsed and converted to a pymatgen Spin.up object. From your error log, it appears you are using the sumo Python API functions rather than the command line, and this is what leads to the error. From inspection of the code and your error log, I can see that the string_to_spin conversion function (which converts the input --spin flag to a pymatgen Spin object) is only applied to the cli argument parser, and so does not convert your spin argument when directly using the bandplot function. This is a minor bug which I will fix now. Thanks again for raising this issue!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SMTG-UCL/sumo/issues/94?email_source=notifications&email_token=AD4XHGEVW3IJYWYSX2DTHOLRGY26PA5CNFSM4LDMG2O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOLJ2UA#issuecomment-597073232, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4XHGDBFTNSX2CSUMQV6F3RGY26PANCNFSM4LDMG2OQ .

utf commented 4 years ago

This issue should now be fixed in master. Can you try pulling the latest changes in from GitHub and testing again?

zrqustc commented 4 years ago

Sure, I am going to test now and give you feedback.

Best, Ruiqi

On Tue, Mar 10, 2020 at 12:00 PM Alex Ganose notifications@github.com wrote:

This issue should now be fixed in master. Can you try pulling the latest changes in from GitHub and testing again?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SMTG-UCL/sumo/issues/94?email_source=notifications&email_token=AD4XHGA2OSBLEXJFTOB2LZDRGZW2ZA5CNFSM4LDMG2O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOMIQTI#issuecomment-597198925, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4XHGAJEETXLERMBLPCSCLRGZW2ZANCNFSM4LDMG2OQ .

zrqustc commented 4 years ago

Got a new TypeError.

See the following:


TypeError Traceback (most recent call last)

in 10 spin='up', 11 ymin=-1, ymax=1, ---> 12 width=a,height=b) 13 #for i in range(72): 14 # plt.plot(X[i,:], Y[i,:],linewidth=2.0,c='b') ~/repos/miniconda3/lib/python3.6/site-packages/sumo-1.4.0-py3.6.egg/sumo/cli/bandplot.py in bandplot(filenames, code, prefix, directory, vbm_cbm_marker, projection_selection, mode, interpolate_factor, circle_size, dos_file, cart_coords, scissor, ylabel, dos_label, elements, lm_orbitals, atoms, spin, total_only, plot_total, legend_cutoff, gaussian, height, width, ymin, ymax, colours, yscale, style, no_base_style, image_format, dpi, plt, fonts) 312 plt=plt, dos_plotter=dos_plotter, dos_options=dos_opts, 313 dos_label=dos_label, fonts=fonts, style=style, --> 314 no_base_style=no_base_style, spin=spin) 315 316 if save_files: ~/repos/miniconda3/lib/python3.6/site-packages/sumo-1.4.0-py3.6.egg/sumo/plotting/__init__.py in wrapper(fonts, style, no_base_style, *args, **kwargs) 59 60 matplotlib.pyplot.style.use(list_style) ---> 61 return get_plot(*args, **kwargs) 62 63 return wrapper ~/repos/miniconda3/lib/python3.6/site-packages/sumo-1.4.0-py3.6.egg/sumo/plotting/bs_plotter.py in get_plot(self, zero_to_efermi, ymin, ymax, width, height, vbm_cbm_marker, ylabel, dpi, plt, plot_dos_legend, dos_plotter, dos_options, dos_label, dos_aspect, aspect, fonts, style, no_base_style, spin) 164 165 elif spin is not None: --> 166 is_vb = self._bs.bands[spin] <= self._bs.get_vbm()['energy'] 167 elif self._bs.is_spin_polarized or self._bs.is_metal(): 168 is_vb = [True] TypeError: '<=' not supported between instances of 'float' and 'NoneType'
kavanase commented 4 years ago

Dear @zrqustc, Thank you for the quick feedback. From the TypeError, it is suggesting that the issue is now coming from self._bs.get_vbm()['energy'] being NoneType, rather than from self._bs.bands[spin], which is a float type as expected. Is your system semiconducting (does it have a well-defined VBM)?

zrqustc commented 4 years ago

Thanks. My system is metal, not a semiconductor.

On Tue, Mar 10, 2020 at 2:18 PM Seán Kavanagh notifications@github.com wrote:

Dear @zrqustc https://github.com/zrqustc, Thank you for the quick feedback. From the TypeError, it is suggesting that the issue is now coming from self._bs.get_vbm()['energy'] being NoneType, rather than from self._bs.bands[spin], which is a float type as expected. Is your system semiconducting (does it have a well-defined VBM)?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SMTG-UCL/sumo/issues/94?email_source=notifications&email_token=AD4XHGBS3JNJAV6JV5GKTILRG2G7PA5CNFSM4LDMG2O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOMY54Y#issuecomment-597266163, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4XHGGOH54QOD5A43MFRGDRG2G7PANCNFSM4LDMG2OQ .

kavanase commented 4 years ago

Thanks for the quick reply. The issue is as I expected, the spin-selection functionality of sumo has been set up to work with semiconducting systems and is currently incompatible with metallic systems. I will update now to include spin-selection capability for metallic systems. Thanks for your patience!

utf commented 4 years ago

I will submit a fix now.

zrqustc commented 4 years ago

Great! Thanks for the update.

On Tue, Mar 10, 2020 at 2:26 PM Seán Kavanagh notifications@github.com wrote:

Thanks for the quick reply. The issue is as I expected, the spin-selection functionality of sumo has been set up to work with semiconducting systems and is currently incompatible with metallic systems. I will update now to include spin-selection capability for metallic systems. Thanks for your patience!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SMTG-UCL/sumo/issues/94?email_source=notifications&email_token=AD4XHGASBKQJB3VZK2FTFEDRG2H63A5CNFSM4LDMG2O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOMZ4DY#issuecomment-597270031, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4XHGAC2ZRYGHAZUTGAGQ3RG2H63ANCNFSM4LDMG2OQ .

utf commented 4 years ago

Ok, I pushed fixes in 027496ccbb811c2da57c162ae2dbed8c76a8ee5e and 0488ce8d4c537aaf10330d0ae8d14619142c299a

Can you please try again and let me know.

zrqustc commented 4 years ago

Sure. I am testing now and give you feedback later.

On Tue, Mar 10, 2020 at 2:54 PM Alex Ganose notifications@github.com wrote:

Ok, I pushed fixes in 027496c https://github.com/SMTG-UCL/sumo/commit/027496ccbb811c2da57c162ae2dbed8c76a8ee5e and 0488ce8 https://github.com/SMTG-UCL/sumo/commit/0488ce8d4c537aaf10330d0ae8d14619142c299a

Can you please try again and let me know.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SMTG-UCL/sumo/issues/94?email_source=notifications&email_token=AD4XHGAJ74OHRRZN3CFWRLDRG2LIXA5CNFSM4LDMG2O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOM5APQ#issuecomment-597282878, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4XHGA2SMY5WNHQLNSVJPDRG2LIXANCNFSM4LDMG2OQ .

zrqustc commented 4 years ago

Thanks, Alex.

I have tested the code. If I don't use the projection mode, everything is fine. But, when I use the projection mode, it will give this error;

---------------------------------------------------------------------------KeyError Traceback (most recent call last) in 10 spin='down', 11 ymin=-1, ymax=1,---> 12 width=a,height=b) 13 #for i in range(72): 14 # plt.plot(X[i,:], Y[i,:],linewidth=2.0,c='b') ~/repos/miniconda3/lib/python3.6/site-packages/sumo-1.4.0-py3.6.egg/sumo/cli/bandplot.py in bandplot(filenames, code, prefix, directory, vbm_cbm_marker, projection_selection, mode, interpolate_factor, circle_size, dos_file, cart_coords, scissor, ylabel, dos_label, elements, lm_orbitals, atoms, spin, total_only, plot_total, legend_cutoff, gaussian, height, width, ymin, ymax, colours, yscale, style, no_base_style, image_format, dpi, plt, fonts) 305 plt=plt, dos_plotter=dos_plotter, dos_options=dos_opts, 306 dos_label=dos_label, fonts=fonts, style=style,--> 307 no_base_style=no_base_style, spin=spin) 308 else: 309 plt = plotter.get_plot( ~/repos/miniconda3/lib/python3.6/site-packages/sumo-1.4.0-py3.6.egg/sumo/plotting/init.py in wrapper(fonts, style, no_base_style, *args, *kwargs) 59 60 matplotlib.pyplot.style.use(list_style)---> 61 return get_plot(args, **kwargs) 62 63 return wrapper ~/repos/miniconda3/lib/python3.6/site-packages/sumo-1.4.0-py3.6.egg/sumo/plotting/bs_plotter.py in get_projected_plot(self, selection, mode, interpolate_factor, circle_size, projection_cutoff, zero_to_efermi, ymin, ymax, width, height, vbm_cbm_marker, ylabel, dpi, plt, dos_plotter, dos_options, dos_label, plot_dos_legend, dos_aspect, aspect, fonts, style, no_base_style, spin) 389 390 proj = get_projections_by_branches(self._bs, selection,--> 391 normalise='select') 392 393

nd is branch index

~/repos/miniconda3/lib/python3.6/site-packages/sumo-1.4.0-py3.6.egg/sumo/electronic_structure/bandstructure.py in get_projections_by_branches(bs, selection, normalise) 70 """ 71 spins = bs.bands.keys()---> 72 projections = get_projections(bs, selection, normalise=normalise) 73 74 branches = [] ~/repos/miniconda3/lib/python3.6/site-packages/sumo-1.4.0-py3.6.egg/sumo/electronic_structure/bandstructure.py in get_projections(bs, selection, normalise) 179 proj = dict(zip(spins, [np.zeros((nbands, nkpts))] * len(spins))) 180 for spin, orbital in it.product(spins, orbitals):--> 181 proj[spin] += dict_proj[element][orbital][spin] 182 183 if normalise == 'select': KeyError: <Spin.up: 1>

On Tue, Mar 10, 2020 at 3:02 PM 张瑞奇 zhangrq2013@gmail.com wrote:

Sure. I am testing now and give you feedback later.

On Tue, Mar 10, 2020 at 2:54 PM Alex Ganose notifications@github.com wrote:

Ok, I pushed fixes in 027496c https://github.com/SMTG-UCL/sumo/commit/027496ccbb811c2da57c162ae2dbed8c76a8ee5e and 0488ce8 https://github.com/SMTG-UCL/sumo/commit/0488ce8d4c537aaf10330d0ae8d14619142c299a

Can you please try again and let me know.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SMTG-UCL/sumo/issues/94?email_source=notifications&email_token=AD4XHGAJ74OHRRZN3CFWRLDRG2LIXA5CNFSM4LDMG2O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEOM5APQ#issuecomment-597282878, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4XHGA2SMY5WNHQLNSVJPDRG2LIXANCNFSM4LDMG2OQ .

utf commented 4 years ago

Can you copy and paste the code you are running when you get this error?

Can you also check that your VASP calculation definitely has band structure projections?

zrqustc commented 4 years ago

Let me test one more example. Maybe it is my mistake.

On Tue, Mar 10, 2020 at 4:25 PM Alex Ganose notifications@github.com wrote:

Can you copy and paste the code you are running when you get this error?

Can you also check that your VASP calculation definitely has band structure projections?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SMTG-UCL/sumo/issues/94?email_source=notifications&email_token=AD4XHGGD7WHXV5NPUNUE6MTRG2V3JA5CNFSM4LDMG2O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEONHLWA#issuecomment-597325272, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4XHGCS46LV2727FWBCO6LRG2V3JANCNFSM4LDMG2OQ .

zrqustc commented 4 years ago

Thanks Alex. All the issues are fixed now. It is my mistake, the first example I test doesn't run normally. Thanks again for your help.

Best regards, Ruiqi

On Tue, Mar 10, 2020 at 4:31 PM 张瑞奇 zhangrq2013@gmail.com wrote:

Let me test one more example. Maybe it is my mistake.

On Tue, Mar 10, 2020 at 4:25 PM Alex Ganose notifications@github.com wrote:

Can you copy and paste the code you are running when you get this error?

Can you also check that your VASP calculation definitely has band structure projections?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/SMTG-UCL/sumo/issues/94?email_source=notifications&email_token=AD4XHGGD7WHXV5NPUNUE6MTRG2V3JA5CNFSM4LDMG2O2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEONHLWA#issuecomment-597325272, or unsubscribe https://github.com/notifications/unsubscribe-auth/AD4XHGCS46LV2727FWBCO6LRG2V3JANCNFSM4LDMG2OQ .

utf commented 4 years ago

Great! Thanks for the bug report.