²é¿´: 6336  |  »Ø¸´: 7
¡¾½±Àø¡¿ ±¾Ìû±»ÆÀ¼Û6´Î£¬×÷ÕßhakunaÔö¼Ó½ð±Ò 4.6 ¸ö
µ±Ç°Ö»ÏÔʾÂú×ãÖ¸¶¨Ìõ¼þµÄ»ØÌû£¬µã»÷ÕâÀï²é¿´±¾»°ÌâµÄËùÓлØÌû

hakuna

ľ³æ (ÖªÃû×÷¼Ò)


[×ÊÔ´] Bands diagram using VASP and pymatgen

Ô­ÎĵØÖ·£ºhttp://gvallver.perso.univ-pau.fr/?p=587
Èý¸öÀý×Ó¼û¸½¼þ
This article presents a python source code in order to plot the bands diagram of graphene calculated using VASP. The plot is done using pymatgen library and RGB coloring adapted from this example.
Edit 2016, March 15, update : source code is now python3 and pymatgen version 3.3.5 compatible
CODE:
#!/usr/bin/env python
# -*- coding=utf-8 -*-

import sys

import numpy as np
from numpy import array as npa

import matplotlib.pyplot as plt
from matplotlib.collections import LineCollection
from matplotlib.gridspec import GridSpec

import pymatgen as mg
from pymatgen.io.vasp.outputs import Vasprun, Procar
from pymatgen.symmetry.bandstructure import HighSymmKpath
from pymatgen.electronic_structure.core import Spin, Orbital


def rgbline(ax, k, e, red, green, blue, alpha=1.):
    # creation of segments based on
    # http://nbviewer.ipython.org/urls/raw.github.com/dpsanders/matplotlib-examples/master/colorline.ipynb
    pts = np.array([k, e]).T.reshape(-1, 1, 2)
    seg = np.concatenate([pts[:-1], pts[1:]], axis=1)

    nseg = len(k) - 1
    r = [0.5 * (red[i] + red[i + 1]) for i in range(nseg)]
    g = [0.5 * (green[i] + green[i + 1]) for i in range(nseg)]
    b = [0.5 * (blue[i] + blue[i + 1]) for i in range(nseg)]
    a = np.ones(nseg, np.float) * alpha
    lc = LineCollection(seg, colors=list(zip(r, g, b, a)), linewidth=2)
    ax.add_collection(lc)

if __name__ == "__main__":
    # read data
    # ---------

    # kpoints labels
    path = HighSymmKpath(mg.Structure.from_file("./opt/CONTCAR")).kpath["path"]
    labels = [r"$%s$" % lab for lab in path[0][0:4]]

    # bands
    bands = Vasprun("./bands/vasprun.xml").get_band_structure("./bands/KPOINTS", line_mode=True)

    # projected bands
    data = Procar("./bands/PROCAR").data

    # density of state
    dosrun = Vasprun("./dos/vasprun.xml")

    # set up matplotlib plot
    # ----------------------

    # general options for plot
    font = {'family': 'serif', 'size': 24}
    plt.rc('font', **font)

    # set up 2 graph with aspec ration 2/1
    # plot 1: bands diagram
    # plot 2: Density of State
    gs = GridSpec(1, 2, width_ratios=[2, 1])
    fig = plt.figure(figsize=(11.69, 8.27))
    fig.suptitle("Bands diagram of graphene")
    ax1 = plt.subplot(gs[0])
    ax2 = plt.subplot(gs[1])  # , sharey=ax1)

    # set ylim for the plot
    # ---------------------
    emin = 1e100
    emax = -1e100
    for spin in bands.bands.keys():
        for b in range(bands.nb_bands):
            emin = min(emin, min(bands.bands[spin][b]))
            emax = max(emax, max(bands.bands[spin][b]))

    emin -= bands.efermi + 1
    emax -= bands.efermi - 1
    ax1.set_ylim(emin, emax)
    ax2.set_ylim(emin, emax)

    # Band Diagram
    # ------------

    # sum up contribution over carbon atoms
    data = data[Spin.up].sum(axis=2)

    # sum up px and py contributions and normalize contributions
    contrib = np.zeros((bands.nb_bands, len(bands.kpoints), 3))
    for b in range(bands.nb_bands):
        for k in range(len(bands.kpoints)):
            sc = data[k][b][Orbital.s.value]**2
            pxpyc = data[k][b][Orbital.px.value]**2 + \
                data[k][b][Orbital.py.value]**2
            pzc = data[k][b][Orbital.pz.value]**2
            tot = sc + pxpyc + pzc
            if tot != 0.0:
                contrib[b, k, 0] = sc / tot
                contrib[b, k, 1] = pxpyc / tot
                contrib[b, k, 2] = pzc / tot

    # plot bands using rgb mapping
    for b in range(bands.nb_bands):
        rgbline(ax1,
                range(len(bands.kpoints)),
                [e - bands.efermi for e in bands.bands[Spin.up][b]],
                contrib[b, :, 0],
                contrib[b, :, 1],
                contrib[b, :, 2])

    # style
    ax1.set_xlabel("k-points")
    ax1.set_ylabel(r"$E - E_f$   /   eV")
    ax1.grid()

    # fermi level at 0
    ax1.hlines(y=0, xmin=0, xmax=len(bands.kpoints), color="k", lw=2)

    # labels
    nlabs = len(labels)
    step = len(bands.kpoints) / (nlabs - 1)
    for i, lab in enumerate(labels):
        ax1.vlines(i * step, emin, emax, "k")
    ax1.set_xticks([i * step for i in range(nlabs)])
    ax1.set_xticklabels(labels)

    ax1.set_xlim(0, len(bands.kpoints))

    # Density of state
    # ----------------

    ax2.set_yticklabels([])
    ax2.grid()
    ax2.set_xticks(np.arange(0, 1.5, 0.4))
    ax2.set_xticklabels(np.arange(0, 1.5, 0.4))
    ax2.set_xlim(1e-6, 1.5)
    ax2.hlines(y=0, xmin=0, xmax=1.5, color="k", lw=2)
    ax2.set_xlabel("Density of State")

    # s contribution
    ax2.plot(npa(dosrun.pdos[0][Orbital.s][Spin.up]) +
             npa(dosrun.pdos[1][Orbital.s][Spin.up]),
             dosrun.tdos.energies - dosrun.efermi,
             "r-", label="s", linewidth=2)

    # px py contribution
    ax2.plot(npa(dosrun.pdos[0][Orbital.px][Spin.up]) +
             npa(dosrun.pdos[1][Orbital.px][Spin.up]) +
             npa(dosrun.pdos[0][Orbital.py][Spin.up]) +
             npa(dosrun.pdos[1][Orbital.py][Spin.up]),
             dosrun.tdos.energies - dosrun.efermi,
             "g-",
             label="(px, py)",
             linewidth=2)

    # pz contribution
    ax2.plot(npa(dosrun.pdos[0][Orbital.pz][Spin.up]) +
             npa(dosrun.pdos[1][Orbital.pz][Spin.up]),
             dosrun.tdos.energies - dosrun.efermi,
             "b-", label="pz", linewidth=2)

    # total dos
    ax2.fill_between(dosrun.tdos.densities[Spin.up],
                     0,
                     dosrun.tdos.energies - dosrun.efermi,
                     color=(0.7, 0.7, 0.7),
                     facecolor=(0.7, 0.7, 0.7))

    ax2.plot(dosrun.tdos.densities[Spin.up],
             dosrun.tdos.energies - dosrun.efermi,
             color=(0.6, 0.6, 0.6),
             label="total DOS")

    # plot format style
    # -----------------

    ax2.legend(fancybox=True, shadow=True, prop={'size': 18})
    plt.subplots_adjust(wspace=0)

    # plt.show()
    plt.savefig(sys.argv[0].strip(".py") + ".pdf", format="pdf")

Bands diagram using VASP and pymatgen
bands_Cu-510x403.png


Bands diagram using VASP and pymatgen-1
bands_Si-510x395.png


Bands diagram using VASP and pymatgen-2
graphene-750x453.png
»Ø¸´´ËÂ¥

» ±¾Ìû¸½¼þ×ÊÔ´Áбí

  • »¶Ó­¼à¶½ºÍ·´À¡£ºÐ¡Ä¾³æ½öÌṩ½»Á÷ƽ̨£¬²»¶Ô¸ÃÄÚÈݸºÔð¡£
    ±¾ÄÚÈÝÓÉÓû§×ÔÖ÷·¢²¼£¬Èç¹ûÆäÄÚÈÝÉæ¼°µ½ÖªÊ¶²úȨÎÊÌ⣬ÆäÔðÈÎÔÚÓÚÓû§±¾ÈË£¬Èç¶Ô°æÈ¨ÓÐÒìÒ飬ÇëÁªÏµÓÊÏ䣺xiaomuchong@tal.com
  • ¸½¼þ 1 : Cu_bands.zip
  • 2016-03-25 17:34:49, 1.18 M
  • ¸½¼þ 2 : graphene.zip
  • 2016-03-25 17:34:59, 5.52 M
  • ¸½¼þ 3 : Si_bands.zip
  • 2016-03-25 17:35:00, 720.29 K

» ÊÕ¼±¾ÌûµÄÌÔÌûר¼­ÍƼö

MD Composite

» ²ÂÄãϲ»¶

ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

°®ÑǵÄÐÉÐÉ

гæ (ÕýʽдÊÖ)


¡ï¡ï¡ï¡ï¡ï ÎåÐǼ¶,ÓÅÐãÍÆ¼ö

ÄãºÃ°¡ ÎÒÔÚÔËÐÐÄúµÄÀý×ÓµÄʱºò ÌáʾÁËModuleNotFoundError: No module named 'pymatgen.io.vaspio'£¬ÄúÖªµÀÊÇʲôԭÒòÂð£¿Ð»Ð»ÄãÀ²
8Â¥2020-01-20 09:48:12
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
²é¿´È«²¿ 8 ¸ö»Ø´ð

emilyoyang

ľ³æ (ÕýʽдÊÖ)


·ÖÏíµÄÕâ¸öcode Ì«¹ýʱÁË£¡ ºóÀ´Õß¿´ÁË ÔËÐлáÓöµ½¸÷ÖÖ¸÷Ñù´íÎó£¬
ÎÒÔÚÕâÀï·ÖÏíÒ»¸ö×îеģ¬https://github.com/materialsvirt ... re%20of%20NiO.ipynb
Germain Salvato VallverduÊ®ÌìǰдµÄÒ»¸ö½Ì³Ì
3Â¥2018-03-13 04:06:22
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

¡ï¡ï¡ï ÈýÐǼ¶,Ö§³Ö¹ÄÀø

Æäʵû±ØÒªÓÃpymatgen£¬ÄãÓÃÄǸö¿âÎ޷ǾÍÊǶÁvasprun.xmlºÍprocar
5Â¥2018-09-24 12:10:39
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
¼òµ¥»Ø¸´
mink6Â¥
2019-05-11 08:56   »Ø¸´  
ÎåÐÇºÃÆÀ  ¶¥Ò»Ï£¬¸Ðл·ÖÏí£¡
springxa7Â¥
2019-11-30 00:17   »Ø¸´  
ÎåÐÇºÃÆÀ  ¶¥Ò»Ï£¬¸Ðл·ÖÏí£¡
2018-09-24 10:04   »Ø¸´  
ÎåÐÇºÃÆÀ  ¶¥Ò»Ï£¬¸Ðл·ÖÏí£¡
¡î ÎÞÐǼ¶ ¡ï Ò»ÐǼ¶ ¡ï¡ï¡ï ÈýÐǼ¶ ¡ï¡ï¡ï¡ï¡ï ÎåÐǼ¶
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] 085700×ÊÔ´Óë»·¾³308Çóµ÷¼Á +3 īīĮ 2026-03-18 3/150 2026-03-18 22:35 by bingxueer79
[¿¼ÑÐ] Ò»Ö¾Ô¸¼ªÁÖ´óѧ²ÄÁÏѧ˶321Çóµ÷¼Á +4 Ymlll 2026-03-18 6/300 2026-03-18 22:15 by li123456789.
[¿¼ÑÐ] 0703»¯Ñ§ 305Çóµ÷¼Á +3 FY_yy 2026-03-14 3/150 2026-03-18 19:40 by macy2011
[¿¼ÑÐ] 314Çóµ÷¼Á +8 ÎÞи¿É»÷µÄ¾ÞÈË 2026-03-12 8/400 2026-03-18 14:50 by haxia
[¿¼ÑÐ] 08¹¤¿Æ 320×Ü·Ö Çóµ÷¼Á +5 À滨çóÍí·ç 2026-03-17 5/250 2026-03-18 14:49 by haxia
[¿¼ÑÐ] ÉúÎïѧ071000 329·ÖÇóµ÷¼Á +3 ÎÒ°®ÉúÎïÉúÎﰮΠ2026-03-17 3/150 2026-03-18 10:12 by macy2011
[»ù½ðÉêÇë] ±»ÎÒÑÔÖУºÐÂÄ£°å²»Ç¿µ÷¸ñʽÁË£¬¼Ùר¼Ò¿ªÊ¼¹Ü¸ñʽÁË +4 beefly 2026-03-14 4/200 2026-03-17 22:04 by »ÆÄñÓÚ·ÉChao
[¿¼ÑÐ] Ò»Ö¾Ô¸ËÕÖÝ´óѧ²ÄÁϹ¤³Ì£¨085601£©×¨Ë¶ÓпÆÑо­ÀúÈýÏî¹ú½±Á½¸öʵÓÃÐÍרÀûÒ»ÏîÊ¡¼¶Á¢Ïî +6 ´ó»ðɽС»ðɽ 2026-03-16 8/400 2026-03-17 15:05 by ÎÞи¿É»÷111
[¿¼ÑÐ] 304Çóµ÷¼Á +3 ÂüÊâ2266 2026-03-14 3/150 2026-03-16 16:39 by houyaoxu
[¿¼ÑÐ] 0703Ò»Ö¾Ô¸211 285·ÖÇóµ÷¼Á +5 ly3471z 2026-03-13 5/250 2026-03-16 16:16 by ŶŶ123
[¿¼ÑÐ] 283Çóµ÷¼Á +10 С¥¡£ 2026-03-12 14/700 2026-03-16 16:08 by 13811244083
[¿¼ÑÐ] 326Çóµ÷¼Á +3 mlpqaz03 2026-03-15 3/150 2026-03-16 07:33 by Iveryant
[¿¼²©] ¶«»ªÀí¹¤´óѧ»¯²Äרҵ26½ì˶ʿ²©Ê¿ÉêÇë +6 zlingli 2026-03-13 6/300 2026-03-15 20:00 by ryzcf
[¿¼ÑÐ] 070305Çóµ÷¼Á +3 mlpqaz03 2026-03-14 4/200 2026-03-15 11:04 by peike
[¿¼ÑÐ] 080500£¬²ÄÁÏѧ˶302·ÖÇóµ÷¼ÁѧУ +4 ³õʶ¿ÉÀÖ 2026-03-14 5/250 2026-03-14 21:08 by peike
[¿¼ÑÐ] Öпƴó²ÄÁÏר˶319Çóµ÷¼Á +3 ÃÏöβÄÁÏ 2026-03-13 3/150 2026-03-14 18:10 by houyaoxu
[¿¼ÑÐ] 255Çóµ÷¼Á +3 Àî¼Î»Û£¬ 2026-03-12 4/200 2026-03-14 16:58 by ÓÐÖ»ÀêÅ«
[¿¼ÑÐ] ¸´ÊÔµ÷¼Á +4 z1z2z3879 2026-03-14 5/250 2026-03-14 16:30 by JourneyLucky
[¿¼ÑÐ] 328Çóµ÷¼Á +3 5201314Lsy£¡ 2026-03-13 6/300 2026-03-14 15:31 by hyswxzs
[¿¼ÑÐ] 26µ÷¼Á/²ÄÁÏ¿ÆÑ§Ó빤³Ì/×Ü·Ö295/ÇóÊÕÁô +9 2026µ÷¼ÁÏÀ 2026-03-12 9/450 2026-03-13 20:46 by 18595523086
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û