SMTG-Bham / easyunfold

Band structure unfolding made easy!
https://smtg-bham.github.io/easyunfold/
MIT License
42 stars 12 forks source link

Allow customized terminal color for projected spectral function #8

Closed zhubonan closed 1 year ago

zhubonan commented 1 year ago

This is the final bits of code needed to allow custom colours to be used when generating projected plots.

Supersedes #4

Allow any terminal colours to used via interpolation in a specific colour space (default to RGB).

Example output (MgO supercell example with projection):

easyunfold unfold  plot-projections --atoms-idx="1,2,3,4|5,6,7,8" --procar MgO_super/PROCAR  --emin="-5" --emax=15 --intensity=2  --combined --colors="r,b" --out-file unfold-proj.png

image

easyunfold unfold  plot-projections --atoms-idx="1,2,3,4|5,6,7,8" --procar MgO_super/PROCAR  --emin="-5" --emax=15 --intensity=2  --combined --colors="xkcd:baby poop,xkcd:berry" --out-file unfold-proj.png

image

A potential pitfall is that when there are multiple species, the colours may mix and become white. However, as long as the projections are well separated along the energy/kdistance axis. This should not be a problem.

The other issue is that the use of imshow means that it is not possible to have the xaxis in the scale consistent with the actual kpoint distance. This is because the sampled kpoints along the path may not take equal distances in each segment. The pyplot.pcolormesh solves this (as in the standard spectral function plot), but getting it to display colors from RGB(A) arrays requires calling directly the matplotlib.collections.QuadMesh constructor and supply colours, but it is difficult to have the colors in the right order it seems.

zhubonan commented 1 year ago

Err github has automerged this... I have merged it by mistake... @kavanase take a look here if you want and let me know any comments.

kavanase commented 1 year ago

Hi @zhubonan, sorry I was slow to get round to this (one of those weeks...). This looks really great! 😃

I've used this updated code with the same data as before and this is the output from

easyunfold unfold plot-projections --atoms-idx="1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20|21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40|41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80" --procar PROCAR  --eref 4.196 --emin -4 --emax 4 --intensity=2  --combined --colors="r,g,b" --out-file unfold-proj.png

unfold-proj

Compared to previous (from code in #4):

easyunfold unfold plot --eref 4.196 --emin -4 --emax 4 --atomic_proj

image

I had to do the long comma-separated list above because there was an error when trying to do 1-20 (the re matching was set up to expect only single digits), and I noticed the "Energy (eV)" y-axis label was missing from the projected plot. I've commits to push now fixing these, as well as an example docs page and data for NaBiS$_2$ (which also serves to show what commands and outputs these changes result in). Nice that eref is now auto-detected from the VASP output!! (Wasn't the case before from what I remember).

I'll rebase #4 onto dev, and then add these changes there, so it's easiest to keep track! 😃