²é¿´: 6330  |  »Ø¸´: 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µÄ»ØÌû

echoËÕËÕËÕ

гæ (СÓÐÃûÆø)


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

¼ÓÓÍ£¡
2Â¥2018-03-12 12:23:10
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû

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µÄ»ØÌû

°®ÑǵÄÐÉÐÉ

гæ (ÕýʽдÊÖ)


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

ÄãºÃ°¡ ÎÒÔÚÔËÐÐÄúµÄÀý×ÓµÄʱºò ÌáʾÁËModuleNotFoundError: No module named 'pymatgen.io.vaspio'£¬ÄúÖªµÀÊÇʲôԭÒòÂð£¿Ð»Ð»ÄãÀ²
8Â¥2020-01-20 09:48:12
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
¼òµ¥»Ø¸´
2018-09-24 10:04   »Ø¸´  
ÎåÐÇºÃÆÀ  ¶¥Ò»Ï£¬¸Ðл·ÖÏí£¡
mink6Â¥
2019-05-11 08:56   »Ø¸´  
ÎåÐÇºÃÆÀ  ¶¥Ò»Ï£¬¸Ðл·ÖÏí£¡
springxa7Â¥
2019-11-30 00:17   »Ø¸´  
ÎåÐÇºÃÆÀ  ¶¥Ò»Ï£¬¸Ðл·ÖÏí£¡
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ hakuna µÄÖ÷Ìâ¸üÐÂ
¡î ÎÞÐǼ¶ ¡ï Ò»ÐǼ¶ ¡ï¡ï¡ï ÈýÐǼ¶ ¡ï¡ï¡ï¡ï¡ï ÎåÐǼ¶
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] 354Çóµ÷¼Á +3 Tyoumou 2026-03-18 5/250 2026-03-18 16:41 by Tyoumou
[½Ìʦ֮¼Ò] ½¹ÂÇ +8 Ë®±ùÔÂÔÂÒ°Íà 2026-03-13 12/600 2026-03-18 15:27 by ßäÎØß÷ÎØ
[¿¼ÑÐ] Ò»Ö¾Ô¸985£¬±¾¿Æ211£¬0817»¯Ñ§¹¤³ÌÓë¼¼Êõ319Çóµ÷¼Á +6 Liwangman 2026-03-15 6/300 2026-03-18 13:21 by ¾¡Ë´Ò¢1
[¿¼ÑÐ] 299Çóµ÷¼Á +5 ¡÷С͸Ã÷* 2026-03-17 5/250 2026-03-18 11:49 by ¾¡Ë´Ò¢1
[¿¼ÑÐ] 0703»¯Ñ§336·ÖÇóµ÷¼Á +6 zbzihdhd 2026-03-15 7/350 2026-03-18 09:53 by zhukairuo
[¿¼ÑÐ] 334Çóµ÷¼Á +3 Ö¾´æ¸ßÔ¶ÒâÔÚ»úÐ 2026-03-16 3/150 2026-03-18 08:34 by lm4875102
[¿¼ÑÐ] 301Çóµ÷¼Á +4 A_JiXing 2026-03-16 4/200 2026-03-17 17:32 by ruiyingmiao
[¿¼ÑÐ] ²ÄÁϹ¤³Ìר˶µ÷¼Á +5 204818@lcx 2026-03-17 5/250 2026-03-17 17:27 by Little-xue
[¿¼ÑÐ] 302Çóµ÷¼Á +9 ¸ºÐÄÕßµ±Öï 2026-03-11 9/450 2026-03-17 17:13 by ruiyingmiao
[¿¼ÑÐ] ¡¾0856¡¿»¯Ñ§¹¤³Ì£¨085602£©313 ·Ö£¬±¾¿ÆÑ§¿ÆÆÀ¹ÀAÀàԺУ»¯Ñ§¹¤³ÌÓ빤ÒÕ£¬³ÏÇóµ÷¼Á +7 СÁõ¿ì¿ìÉϰ¶ 2026-03-11 8/400 2026-03-17 16:57 by ruiyingmiao
[¿¼ÑÐ] Áº³ÉΰÀÏʦ¿ÎÌâ×é»¶Ó­ÄãµÄ¼ÓÈë +8 һѼѼӴ 2026-03-14 10/500 2026-03-17 15:07 by һѼѼӴ
[¿¼ÑÐ] »úеר˶325£¬Ñ°ÕÒµ÷¼ÁԺУ +3 y9999 2026-03-15 5/250 2026-03-16 19:58 by y9999
[¿¼ÑÐ] 333Çóµ÷¼Á +3 ÎÄ˼¿Í 2026-03-16 7/350 2026-03-16 18:21 by ÎÄ˼¿Í
[¿¼ÑÐ] 321Çóµ÷¼Á +5 ´óÃ×·¹£¡ 2026-03-15 5/250 2026-03-16 16:33 by houyaoxu
[¿¼ÑÐ] 283Çóµ÷¼Á +10 С¥¡£ 2026-03-12 14/700 2026-03-16 16:08 by 13811244083
[¿¼ÑÐ] 0703»¯Ñ§µ÷¼Á£¬Çó¸÷λÀÏʦÊÕÁô +8 ÇïÓÐľ±± 2026-03-14 8/400 2026-03-16 15:21 by ŶŶ123
[¿¼ÑÐ] 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
[¿¼ÑÐ] Çó²ÄÁϵ÷¼Á 085600Ó¢Ò»Êý¶þ×Ü·Ö302 ǰÈý¿Æ235 ¾«Í¨»úÆ÷ѧϰ Ò»Ö¾Ô¸¹þ¹¤´ó +4 ÁÖyaxin 2026-03-12 4/200 2026-03-13 22:04 by ÐÇ¿ÕÐÇÔÂ
[¿¼ÑÐ] 307Çóµ÷¼Á +5 ³¬¼¶ÒÁ°º´óÍõ 2026-03-12 5/250 2026-03-13 15:56 by °ô°ôÇòÊÖ
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û