qijingzheng / pyband Goto Github PK
View Code? Open in Web Editor NEWband plot using python matplotlib
band plot using python matplotlib
Dear Dr. Zheng,
Firstly thank you very much for this wonderful tool. I've been using this without any problem for PBE functionals. But recently I started HSE06 and since I'm getting this type of distorted band structure. It is not wrong or anything, It's just the distance from gamma to k point is too much and it looks distorted. Any idea how to fix this or do I need to modify something in KPOINTS file for HSE06?
Thank you very much.
I am getting this error while busing the pyband to plot the bandstructures:
File "/home/pyband.py", line 434, in
kpath, bands, efermi, kpt_bounds = get_bandInfo(opts.filename)
File "/home/pyband.py", line 113, in get_bandInfo
kpt_path = np.linalg.norm(np.dot(vkpt_diff, B), axis=1)
TypeError: norm() got an unexpected keyword argument 'axis'
Dear Qijing,
An error occurred to me while executing 'pydos', and I found it's because there were too many bands (2800), then no blank space left between ":" and "2800", as shown below
And using large number of k-points and ions will cause this failure as well, do you have any improvement to avoid modifying 'PROCAR' manually? Thanks a lot.
Best Wishes,
homleeguo
Hi Thanks for this useful script. I have tried
python pyband.py -k mrgx
but it is showing this error message
Traceback (most recent call last):
File "pyband.py", line 434, in
kpath, bands, efermi, kpt_bounds = get_bandInfo(opts.filename)
File "pyband.py", line 104, in get_bandInfo
Nk_in_seg = int(kp[1].strip())
ValueError: invalid literal for int() with base 10: '90 ! number of k-points = 0 ->automatic generation scheme'
Can you please look on that?
Dear Qijing,
Thank you very much for developing this wonderful tool!
I have one quick question: is it possible to change separately the colors of the bands corresponding to spin up and down, from a spin-polarized calculation?
Thank you!
Lídia
Hello Mr. Zheng
I ran into an error like
Traceback (most recent call last):
File "../pyband", line 434, in <module>
kpath, bands, efermi, kpt_bounds = get_bandInfo(opts.filename)
File "../pyband", line 108, in get_bandInfo
for ii in range(Nseg):
TypeError: 'float' object cannot be interpreted as an integer
when I testing pyband
with the examples listed in this repo.
And I guess this issue was caused by the difference of division operator /
in py2 and py3.
The MWE below confirmed it:
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 12:01:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 3 / 2
1
while in python3:
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 3 / 2
1.5
So I provide a fix to it: in this line, substitute /
with //
and everything would go well (both python2 and python3 could perform //
in same behavior.
With --lsorbit
and --spin
one can plot the spin components along a specific direction (x, y, z). However, If one doesn't use --occL
option, the negative values in the projection (corresponds to the spin "down" state) is by default discarded and the plot will miss almost half of the weights.
Plotted with (BCC Iron):
pyband -y -10 10 --occ '1' --lsorbit --spin z
The only benefit of not using the line collection plot for this use scenario that if we also want to set --spd
, then zero weighted points will disappear in scatter plot while in the line collection plot they will show up the same as spin flipping points. i.e.:
Plotted with (BCC Iron):
pyband -y -10 10 --occ '1' --spd 'p' --lsorbit --spin z --occL --occLC_cbar_vmin -1 --occLC_cbar_vmax 1
Obviously this use scenario is better suited with --occL
so the easiest way is to issue an error or select --occL
automatically if --lsorbit
and --spin
option is used together.
So, to enable this feature, one could override the user selected occMarkerColor
(and issue a warning) and set the positive values to red and negative values to blue while retaining the weight based size for points by taking the absolute value of the weight. As a side note, I think only use red and blue is enough since these plots already have too many information on them and I doubt people would want to show multiple contributions from atomic orbitals alongside spin informations....
To do this, change these lines in bandplot
to:
if whts is not None:
for ii in range(len(opts.occ)):
color = ['red' if weight > 0 else 'blue' for weight in whts[ii][Ispin, :, Iband]]
ax.scatter(kpath, bands[Ispin, :, Iband],
color=color,#opts.occMarkerColor[ii],
s=np.abs(whts[ii][Ispin, :, Iband]) *
opts.occMarkerSize[ii],
marker=opts.occMarker[ii], zorder=1, lw=0.0,
alpha=0.5)
Plotted with (BCC Iron):
pyband -y -10 10 --occ '1' --lsorbit --spin z
pyband -y -10 10 --occ '1' --spd 'p' --lsorbit --spin z
If you think this is good enough, I'll submit a pull request and add this use scenario to the README file. 🤓
Dear Dr. Zheng,
when I have 'pyband ' command in your example folder, the error message comes out:
Traceback (most recent call last):
File "/data/qiangbai/bin/pyband/pyband", line 456, in
call(['feh', '-xdF', opts.bandimage])
File "/data/qiangbai/anaconda2/lib/python2.7/subprocess.py", line 168, in call
return Popen(*popenargs, **kwargs).wait()
File "/data/qiangbai/anaconda2/lib/python2.7/subprocess.py", line 390, in init
errread, errwrite)
File "/data/qiangbai/anaconda2/lib/python2.7/subprocess.py", line 1025, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
Do you know how to solve it?
Best,
Qiang
Dear Dr. Zheng,
when I use --occ '1 2', error occurs
ValueError: invalid literal for int() with base 10: "'1"
When I check opts.occ, it was ["'1"] instead of ['1 2'] or [1, 2] or ['1'. '2'].
It seems the parser does not work correctly to get the atom list.
The same issue also occurs with pydos.
If I use " instead of ', so "1 2", it looks fine. It printed,
opts.occ: ['1 2']
occ: 1, 2
occAtom: {1, 2}
I'm wondering if the code works okay with those occ variables!
Any help would be greatly appreciated!
Thank you!
Best regards,
Soonho
Dear Dr.Zheng
I got the following warning:
Do you have any idea for that
Thanks in advance
Traceback (most recent call last):
File "pyband", line 434, in
kpath, bands, efermi, kpt_bounds = get_bandInfo(opts.filename)
File "pyband", line 131, in get_bandInfo
kpt_bounds = np.concatenate(([0.0,], kpt_path[np.isclose(xx, 0.0)], [kpt_path[-1],]))
IndexError: boolean index did not match indexed array along dimension 0; dimension is 16 but corresponding boolean dimension is 15
Dear Dr.Zheng
I got the following problems:
Do you have any idea for that
Thank you very much!
Traceback (most recent call last):
File "./pyband", line 690, in
call(['feh', '-xdF', opts.bandimage])
File "/home-gk/soft/packagedir/anaconda3/install/lib/python3.6/subprocess.py", line 267, in call
with Popen(*popenargs, **kwargs) as p:
File "/home-gk/soft/packagedir/anaconda3/install/lib/python3.6/subprocess.py", line 709, in init
restore_signals, start_new_session)
File "/home-gk/soft/packagedir/anaconda3/install/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'feh': 'feh'
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
def gaussian_smearing_org(x, x0, sigma=0.05):
'''
Gaussian smearing of a Delta function.
'''
return 1. / (np.sqrt(2*np.pi) * sigma) * np.exp(-(x - x0)**2 / (2*sigma**2))
if '__main__' == __name__:
x = np.linspace(0, 120, 300)
y1 = gaussian_smearing_org(x, 10, sigma=0.1)
y2 = gaussian_smearing_org(x, 20, sigma=0.1)
y3 = gaussian_smearing_org(x, 30, sigma=0.1)
y4 = gaussian_smearing_org(x, 40, sigma=0.1)
y5 = gaussian_smearing_org(x, 50, sigma=0.1)
y6 = gaussian_smearing_org(x, 60, sigma=0.1)
y7 = gaussian_smearing_org(x, 70, sigma=0.1)
y8 = gaussian_smearing_org(x, 80, sigma=0.1)
y9 = gaussian_smearing_org(x, 90, sigma=0.1)
plt.figure()
plt.plot(x, y1)
plt.plot(x, y2)
plt.plot(x, y3)
plt.plot(x, y4)
plt.plot(x, y5)
plt.plot(x, y6)
plt.plot(x, y7)
plt.plot(x, y8)
plt.plot(x, y9)
plt.savefig('test_smearing.png')
Code:
pyband
Symptom:
Plottable band data "pyband_up.dat" and "pyband_do.dat" contain the same information.
Traceback:
Line 271 in 14aed42
Fix:
line += '%8.4f' % bands[Ispin,ii,jj]
Should be "axis" instead of "exis" in molAdd.py line 53 :)
Otherwise
Traceback (most recent call last):
File "../molAdd.py", line 135, in
add_mol(sys.argv[1:])
File "../molAdd.py", line 54, in add_mol
new.center(vacuum=arg.vacuum / 2., axis=axis)
UnboundLocalError: local variable 'axis' referenced before assignment
Hello,
I would like to plot a band structure where the path is discontinuous. How could I do something like "X|M" on the X-axis?
Best regards,
Jorge
how do you install this?
Dear Dr. Zheng,
When I plot the all pdos which cover all atoms in the system,
it does not look like pdos sum equals to total dos.
The ranges, 0.5 ~ 1 eV and 2 ~ 2.5 eV, are especially noticeable.
or is there any known issue for decomposing the total dos into pdos?
Any help would be greatly appreciated!
Thank you!
Best regards,
Soonho
The help section states that the smearing factor, sigma, has a default value of 0.02, however, when --sigma = 0.02 the smearing factor of the resulting plots and data appear to be different. Looking through the code it appears there is a difference between the actual default and the stated default:
par.add_option('--sigma',
action='store', type="float",
dest='sigma', default=0.05,
help='smearing parameter, default 0.02')
Hi Qijing,
Thank you for your scripts! I am using your pyband to plot the contribution of some atoms to each KS state using " --occ" option. My command is python pyband -k gfbg -y -2 2 --occ '123 124'
. And I got the following error :
Traceback (most recent call last): File "pyband", line 429, in <module> lsorbit=opts.lsorbit)) File "pyband", line 40, in WeightFromPro Weights.resize(nspin, nkpts, nbands, nions) TypeError: 'float' object cannot be interpreted as an integer
Can you look into that? Thanks!
Hi Qijing,
Thank you for making open source your excellent electronic analysis codes for VASP outputs. I want to suggest one bugfix for pyband.
line 78-79 can be changed from:
B = np.array([line.split()[3:] for line in outcar[ibasis:ibasis+3]],
dtype=float)
to:
B = np.array([line.split()[-3:] for line in outcar[ibasis:ibasis+3]],
dtype=float)
The original version will give erroneous reciprocal space lattice vectors for large supercells. e.g.:
-12.226061000 0.000000000 0.000000000 -0.081792492 0.000227405 0.013623480
-0.034230000-12.311772000 0.000000000 0.000000000 -0.081223077 0.006755451
2.743373000 1.367989000 16.447796000 0.000000000 0.000000000 0.060798419
because space(s) between real space lattice vector elements may be missing (see row 2 above). Such an issue will not happen for values in the last three columns corresponding to reciprocal space lattice vectors for almost all realistic crystals so a safe fix is to parse the last three elements instead of 4th to the last elements.
Cheers
Wei
Dear Dr. Zheng,
How can I adjust the range of energy for band structure?
My band plot shows -3 ~ 3 eV, but I want to expand the range.
Thank you for work!
Sincerely,
Soonho
Hello,
I wanted to point out that pydos seems to generate plots that do not reflect the underlying data. Upon examining the results of DOS from pymatgen, for comparison, I see that with pydos an energy gap is missing. Yet the bandgap is observable with pyband.
The first figure is from pydos, and the second, with all elements plotted, is from pymatgen. Looking at pymatgen result, we can see all DOS goes to zero at the Fermi level. This is consistent with the data. However, comparing the pymatgen result to pydos we can see the TDOS doesn't converge to zero as it should. I not certain the cause of this, perhaps the smearing function...? I do not believe this has to do with scale...I can zoom in and see nonzero DOS...Anyway, I felt you should be made aware. Thank you.
pyband -f PROCAR
Traceback (most recent call last):
File "/home/awkum/SCRIPTS/pyband/pyband", line 710, in
kpath, bands, efermi, kpt_bounds, wkpts = get_bandInfo(opts.filename)
File "/home/awkum/SCRIPTS/pyband/pyband", line 192, in get_bandInfo
B = np.array([line.split()[-3:] for line in outcar[ibasis:ibasis+3]],
UnboundLocalError: local variable 'ibasis' referenced before assignment
Dear Qijing,
Ni Hao,
Firstly, thanks for an excellent piece of work for plotting VASP data.
I am using pyband to plot the orbital projected band structures. However, as there is no option to change the marker edge color, my figures look like the linewidth changes when the weights are present but it does not look like weighted spheres.
this could be a trivial issue but I would like your help to plot markers with different edgecolors and marker colors.
waiting for your response.
Dear Qijing Zheng,
Greetings of the day!
I am trying to plot separate orbital contribution of atoms in a single band structure plot (for MoS2 system).
I am using the following command line to get the same,
./pyband.py --occ '1' --spd '0' --occMc indigo --occ '1' --spd '1 2 3' --occMc yellow --occ '1' --spd '4 5 6 7 8' --occMc orange --occ '2 3' --spd '0' --occMc violet --occ '2 3' --spd '1 2 3' --occMc cyan
##where, my (--occ '1' , --occ '2 3' ) Mo=1, S1=2, S2=3 /## --spd '0' = s, --spd '1 2 3'= 2p-orbitals, --spd '4 5 6 7 8'=5d-orbitals, respectively.
In the end, I am getting separate atomic contribution (weight) only in my band structure plot not their orbitals. The following line for Mo-atom, only gives all Mo-orbitals only not the separate orbital (1s, 3p, 5d) contribution.
./pyband.py --occ '1' --spd '0' --occMc indigo --occ '1' --spd '1 2 3' --occMc yellow --occ '1' --spd '4 5 6 7 8' --occMc orange .
The same for Mo-d orbitals ( 4 5 6 7 8), ./pyband.py --occ '1' --spd '4' --occMc orange --occ '1' --spd '5' --occMc red --occ '1' --spd '6' --occMc blue --occ '1' --spd '7' --occMc yellow --occ '1' --spd '8' --occMc green
gives all Mo-atom contribution.
Thanking you in advance for your kind support to the problem !
I am using VASP6.2.0. When using pyband
to read the OUTCAR file, there is an error.
According to the hint and comparison between OUTCAR-VASP5.4.4 and OUTCAR-VASP-6.2.0, I found there is a little difference between these two versions of OUTCAR. I am guessing this is might be a bug of pyband.
I upload an OUTCAR file from VASP6.2.0 to a new Github repo. Here is the link:https://github.com/Satinelamp/pyband-VASP6.2.0
Here is error info:
Dear Dr.Zheng
I was trying to use npdos compare several PROCAR with SOC
The code telling me that
$ ./DOS.sh
Figure Initialization Completed! Time Used: 0.07 [sec]
Traceback (most recent call last):
File "/home/hsu_andy/pyband-master/npdos", line 996, in
main(sys.argv[1:])
File "/home/hsu_andy/pyband-master/npdos", line 986, in main
p = init_procar(p)
File "/home/hsu_andy/pyband-master/npdos", line 858, in init_procar
tmp = procar(inf=inf, lsoc=p.soc[ii])
File "/home/hsu_andy/pyband-master/npdos", line 119, in init
self.readProcar()
File "/home/hsu_andy/pyband-master/npdos", line 158, in readProcar
self._kptv = np.asarray([line.split()[-6:-3] for line in inp if 'weight' in line], dtype=float)
File "/home/hsu_andy/.local/lib/python2.7/site-packages/numpy/core/numeric.py", line 538, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: could not convert string to float: :
Where the DOS.sh is :
#!/bin/bash
python ~/pyband-master/npdos
-i MAG_2.7/LAMBDA_20/DOS/PROCAR
-i MAG_3.0/LAMBDA_20/DOS/PROCAR
-soc 1
Could this be some sort of bug?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.