Znn3bq.jpeg
±±¾©Ê¯ÓÍ»¯¹¤Ñ§Ôº2026ÄêÑо¿ÉúÕÐÉú½ÓÊÕµ÷¼Á¹«¸æ
²é¿´: 2709  |  »Ø¸´: 1

hakuna

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

[½»Á÷] ´¦Àí̬ÃܶȵĽű¾£ºvasp_pdos.py ÒÑÓÐ1È˲ÎÓë

http://cmd.kist.re.kr/code/etc/vasp_pdos.py
CODE:
#!/usr/bin/python

##### by jhshin #####
##
## 1. Extract DOS and from DOSCAR of VASP
## 2. Analysis DOS by distribution moment Eq.
##
## 2010.12.2
##########

import os
import sys

from getopt               import getopt
from numpy                import array
from ase.io               import *     
from ase.calculators.vasp import Vasp
from ase.calculators.vasp import VaspDos
from ase.dft              import get_distribution_moment

outcar_name_q = " OUTCAR name      > "
doscar_name_q = " DOSCAR name      > "
atom_list_q   = " Atom index       > "
orbit_list_q  = " Orbital          > "
en_range_q    = " Energy Min. Max. > "
screen_q      = " Screen on/off    > "

#####  Check and read options  #####
optlist, args = getopt(sys.argv[1:], 'hs')

help = 0 ; script = 0

for op,p in optlist:
  if op == '-h'   : help        = 1
  if op == '-s'   : script      = 1

if help==1:
  print ""
  print " Wellcome!"
  print ""
  print " Usage) ./vasp_pdos.py                : Input variables directly."
  print "        ./vasp_pdos.py < vasp_pdos.in : Use script file generated by user."
  print "        ./vasp_pdos.py -h             : Print explanation of this utility."
  print "        ./vasp_pdos.py -s             : Generate the sample script file named"
  print "                                        as 'vasp_pdos.in'."
  print "        ./vasp_pdos.py -hs (or) -sh   : Use 'h' and then 's' option, or inversly."
  print ""
  print " For all variables, see bellow. () is a default value"
  print ""
  print " - OUTCAR name : one string(OUTCAR), name of OUTCAR file"
  print "   ex) OUTCAR.xXX0"
  print ""
  print " - DOSCAR name : one string(DOSCAR), name of DOSCAR file"
  print "   ex) DOSCAR.xXX0"
  print ""
  print " - Atom index : list of integer, from 0 to # of total atoms"
  print "   ex) 0 1 2 3"
  print ""
  print " - Orbital : list of strings, which orbital to plot"
  print ""
  print "                     | Phase factor : X       | Phase factor : O          "
  print "   ==================.========================.==========================="
  print "                     | s                      | s                         "
  print "    Spin-unpolarized | p                      | px py pz                  "
  print "                     | d                      | dxy dyz dz2 dxz dx2       "
  print "   ------------------.------------------------.---------------------------"
  print "                     | s-up s-down (or) s+ s- | s-up s-down (or) s+ s-    "
  print "    Spin-polarized   | p-up p-down (or) p+ p- | px-up  ...  (or) px+ ...  "
  print "                     | d-up d-down (or) d+ d- | dxy-up ...  (or) dxy+ ... "
  print "   ex) s d"
  print ""
  print " - Energy Min. Max. : list of integer(* *), minimum and maximum of energy range"
  print "   ex) -10.0 5.0"
  print ""
  print " - Screen on/off : one integer(0), 0 is off and 1 is on"
  print ""
  print " Thanks!!\n"
  exit()

if script==1:
  print ""
  print " Edit 'vasp_pdos.in' file !!\n"
  in_script = open("vasp_pdos.in", 'wb')
  in_script.write( "%s\n"   % outcar_name_q)
  in_script.write( "%s\n"   % doscar_name_q)
  in_script.write( "%s\n"   % atom_list_q  )
  in_script.write( "%s\n"   % orbit_list_q )
  in_script.write( "%s\n"   % en_range_q   )
  in_script.write( "%s\n\n" % screen_q     )
  in_script.write( "# Enter values on the right side of '>'\n")
  in_script.write( "# Orbital list | (s) s  (p) px py pz  (d) dxy dyz dz2 dxz dx2")

  in_script.close()
  exit()
##########

#####  Input variables  #####
print ""
print " Wellcome! Enter bellow."
print " If you want to use a default value, do not enter anything."
print " ----------------------------------------------------------\n"
print " < Input variables >"
print ""
print " - Orbital list | (s) s  (p) px py pz  (d) dxy dyz dz2 dxz dx2"
print ""

print outcar_name_q, ; outcar_name = raw_input().replace(outcar_name_q,"")
if len(outcar_name) == outcar_name.count(" "): outcar_name="OUTCAR"
outcar_name = outcar_name.replace(" ","")
print "", outcar_name

print doscar_name_q, ; doscar_name = raw_input().replace(doscar_name_q,"")
if len(doscar_name) == doscar_name.count(" "): doscar_name="DOSCAR"
doscar_name = doscar_name.replace(" ","")
print "", doscar_name

print atom_list_q, ; atom_list   = raw_input().replace(atom_list_q,"").split()   
if len(atom_list) == 0:
  print "Enter list of integers!"
  exit()
print "", atom_list

print orbit_list_q, ; orbit_list  = raw_input().replace(orbit_list_q,"").split()   
if len(orbit_list) == 0:
  print "Enter list of strings!"
  exit()
print "", orbit_list

print en_range_q, ; en_range    = raw_input().replace(en_range_q,"")
if len(en_range) == en_range.count(" "): en_range="* *"
en_range = en_range.split()
print "", en_range

print screen_q, ; screen      = raw_input().replace(screen_q,"")
if len(screen) == screen.count(" "): screen="0"
screen = screen.replace(" ","")
print "", screen

print ""
print " ----------------------------------------------------------\n"
##########

#####  Read OUTCAR and DOSCAR  #####
fermiEn = (os.popen('grep E-fermi %s | cut -d":" -f 2' % outcar_name)).read().split()[0]
fermiEn = float(fermiEn)

doscar  = VaspDos(doscar=doscar_name)
doscar.read_doscar(doscar_name)

en_list  = array(doscar._get_energy()) -fermiEn

if en_range[0] == "*": en_min = min(en_list)
else: en_min = float(en_range[0])

if en_range[1] == "*": en_max = max(en_list)
else: en_max = float(en_range[1])
##########

#####  Prepare output  #####
outfile2_name  = doscar_name + ".info.out"
outfile2       = open(outfile2_name, 'wb')
gpInFile       = open("gnuplot.in", 'wb')

print          " < Output results >"
print          "\n# %10s %13s %16s %16s\n" % ("Atom index", "Elec. count", "Band center", "Band width")
outfile2.write("\n# %10s %13s %16s %16s\n" % ("Atom index", "Elec. count", "Band center", "Band width"))
##########

#####  Main loop : make DOS data and analysis  #####
sum=0
orbit0=""
dos_list0 = []

for atom in atom_list:
  for orbit in orbit_list:
    atom  = int(atom)

    if orbit == "+":
      sum = 1
      if len(orbit0)==0 : orbit0= orbit
      dos_list0 = dos_list

    else:
      dos_list = doscar.site_dos(atom, orbit)

      if sum==1:
        orbit = orbit0 + orbit
        orbit0 = orbit
        dos_list = dos_list + dos_list0
        sum = 0

      outfile1_name = str(doscar_name + ".atom" + str(atom) + orbit + "Orbit" + ".dat")
      outfile1      = open(outfile1_name, 'wb')

      en_list_mod  = []
      dos_list_mod = []
      i=0
      for en in en_list:
        dos = dos_list[i]
        if en_min < en < en_max:
          en_list_mod.append(en)
          dos_list_mod.append(dos)
          outfile1.write(' %16.6lf %9.6lf\n' % (en, dos))
        i += 1

      volume, center, width = get_distribution_moment(en_list_mod, dos_list_mod, (0,1,2))
      print          "  %10d %13.3lf %16.6lf %16.6lf     # %s"   % (atom, volume, center, width, orbit + " orbital")
      outfile2.write("  %10d %13.3lf %16.6lf %16.6lf     # %s\n" % (atom, volume, center, width, orbit + " orbital"))

      if str(atom) + str(orbit) == atom_list[0] + orbit_list[0]:
        gpInFile.write ("plot   '%s' w l\n" % outfile1_name)
      else:
        gpInFile.write ("replot '%s' w l\n" % outfile1_name)
##########

#####  Post-precessing  #####
outfile2.write('\n')

outfile1.close()
outfile2.close()
gpInFile.close()

if screen == '1': os.popen('gnuplot -persist gnuplot.in')

print ""
print " End\n"
##########

»Ø¸´´ËÂ¥

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

¾«»ªÍøÌûÊÕ¼¯ ¼ÆËã-vasp vasp

» ²ÂÄãϲ»¶

» ±¾Ö÷ÌâÏà¹Ø¼ÛÖµÌùÍÆ¼ö£¬¶ÔÄúͬÑùÓаïÖú:

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

512771485

½ð³æ (СÓÐÃûÆø)

²©Ê¿

¡ï
Сľ³æ: ½ð±Ò+0.5, ¸ø¸öºì°ü£¬Ð»Ð»»ØÌû
ÎÒÖ»Ïë˵£¬Óò»¶®£¬Ò»¿ªÊ¼¾ÍÊDz»Í£µÄÊäÈë
ŬÁ¦×öÑо¿£¬ÔçЩ³ö³É¹û
2Â¥2015-07-16 17:27:04
ÒÑÔÄ   »Ø¸´´ËÂ¥   ¹Ø×¢TA ¸øTA·¢ÏûÏ¢ ËÍTAºì»¨ TAµÄ»ØÌû
Ïà¹Ø°æ¿éÌø×ª ÎÒÒª¶©ÔÄÂ¥Ö÷ hakuna µÄÖ÷Ìâ¸üÐÂ
×î¾ßÈËÆøÈÈÌûÍÆ¼ö [²é¿´È«²¿] ×÷Õß »Ø/¿´ ×îºó·¢±í
[¿¼ÑÐ] 327Çóµ÷¼Á +7 Xxjc1107. 2026-04-06 8/400 2026-04-08 07:15 by Î޼ʵIJÝÔ­
[¿¼ÑÐ] 338Çóµ÷¼Á +8 wxygxsaaaaa 2026-04-06 8/400 2026-04-08 06:58 by Î޼ʵIJÝÔ­
[¿¼ÑÐ] 285Çóµ÷¼Á +5 ¶ñ·¨´ó¶þµÄÆøÎ¶ß 2026-04-05 8/400 2026-04-07 23:37 by shanqishi
[¿¼ÑÐ] ²ÄÁϹ¤³Ì322 +14 ¹þ¹þ¹þºðºðºð¹þ 2026-04-07 15/750 2026-04-07 22:51 by À´¿´Á÷ÐÇÓê10
[¿¼ÑÐ] Ò»Ö¾Ô¸ÄϿƴóÉúÎïѧ297·Ö£¬Çóµ÷¼ÁÍÆ¼ö +8 Y-yyusx 2026-04-06 9/450 2026-04-07 19:38 by biomichael
[¿¼ÑÐ] Ò»Ö¾Ô¸Î÷µç085401Çóµ÷¼Á +4 sunw1306 2026-04-07 4/200 2026-04-07 16:40 by à£à£à£0119
[¿¼ÑÐ] Çóµ÷¼Á£¬Ò»Ö¾Ô¸ÏÃÃÅ´óѧ£¬ÉúÎïÓëÒ½Ò©£¬×Ü·Ö272£¬±¾¿Æ211 +7 Electron1cc 2026-04-01 8/400 2026-04-07 16:06 by ¿É¿Ú¿ÉÀÖ²»¼Ó±ùØ
[¿¼ÑÐ] 266·Ö£¬Ò»Ö¾Ô¸µçÆø¹¤³Ì£¬±¾¿Æ²ÄÁÏ£¬Çó²ÄÁÏרҵµ÷¼Á +12 ÍÛºôºßºôºß 2026-04-01 13/650 2026-04-07 10:02 by zhen¡«
[¿¼ÑÐ] »¯Ñ§µ÷¼ÁÇóÖú +8 LULONG1 2026-04-03 8/400 2026-04-06 10:26 by dongzh2009
[¿¼ÑÐ] 315Çóµ÷¼Á +5 £¦123456789 2026-04-05 5/250 2026-04-05 19:55 by nepu_uu
[¿¼ÑÐ] ²ÄÁϵ÷¼Á +7 dxyµ÷¼Á 2026-04-04 7/350 2026-04-05 09:15 by İÇï26
[¿¼ÑÐ] 323·Ö£¨¼ÆËã»úÊÓ¾õºÍ´óÄ£ÐÍÏîÄ¿£©ÄÜÖ±½ÓÉÏÊÖ +3 chaoxiicy 2026-04-01 3/150 2026-04-05 00:50 by chongya
[¿¼ÑÐ] ²ÄÁÏר˶322·Ö +11 ¹þ¹þ¹þºðºðºð¹þ 2026-04-02 11/550 2026-04-04 23:37 by ÓÀ×ÖºÅ
[¿¼ÑÐ] Çóµ÷¼Á +4 ѹÁ¦??´ó 2026-04-03 4/200 2026-04-03 21:36 by à£à£à£0119
[¿¼ÑÐ] Çóµ÷¼Á +3 usbdndj 2026-04-03 3/150 2026-04-03 14:10 by dxiaoxin
[¿¼ÑÐ] 312 »¯¹¤»òÖÆÒ©µ÷¼Á +8 ССī123 2026-04-02 9/450 2026-04-03 09:12 by zhouxiaoyu
[¿¼ÑÐ] µ÷¼Á +7 ìíáº. 2026-04-02 7/350 2026-04-03 09:11 by »¨ß»¹Ç·600
[¿¼ÑÐ] 366Çóµ÷¼ÁÒ»Ö¾Ô¸¶«±±´óѧ +8 ÔËÆøÀ´µÃÈôÓÐËÆÎ 2026-04-02 8/400 2026-04-02 21:39 by dongzh2009
[¿¼ÑÐ] Ò»Ö¾Ô¸±±¾©¿Æ¼¼´óѧ085601²ÄÁϹ¤³ÌÓ¢Ò»Êý¶þ³õÊÔ×Ü·Ö335Çóµ÷¼Á +9 Ë«ÂíβƦÀϰå2 2026-04-01 9/450 2026-04-02 12:14 by oooqiao
[¿¼ÑÐ] ʳƷѧ˶362Çóµ÷¼Á +3 xuanxianxian 2026-04-01 3/150 2026-04-01 21:05 by °¡Àî999
ÐÅÏ¢Ìáʾ
ÇëÌî´¦ÀíÒâ¼û