Advertisement
Guest User

doscar_analysis_spd

a guest
Jan 22nd, 2013
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.13 KB | None | 0 0
  1. ! this program written in fortran 90 analyzes the DOSCAR output file of VASP
  2.  
  3.  
  4.  
  5. ! depending on user answers, it may compute the total density of states, or projected density of states of any atom labeled as in the POSCAR file.
  6.  
  7.  
  8.  
  9. ! the program askes the user what it needs during execution. no input file is needed. for simplicity.
  10.  
  11.  
  12.  
  13. ! the energies may be translated so that Fermi energy is the reference (abscissa is E-Efermi) if user wants.
  14.  
  15.  
  16.  
  17. ! it has been written by Maximilien Levesque, while in postdoc @ Ecole Normale Superieure, Paris
  18.  
  19.  
  20.  
  21. ! in the group of theoretical physical-chemistry of Daniel Borgis
  22.  
  23.  
  24.  
  25. ! it is free of any copyright. just send me an email max.....en.lev....e at gmail.com for thanks :) or bug reports.
  26.  
  27.  
  28.  
  29. ! it's based on VASP 4.6 documentation written found at http://cms.mpi.univie.ac.at/vasp/vasp/DOSCAR_file.html
  30.  
  31.  
  32.  
  33. ! I recommand to use the GNU fortran compiler (gfortran)
  34.  
  35.  
  36.  
  37. ! for compilation, just type in almost any terminal : gfortran doscar_analysis_spd.f90 -o doscar_analysis_spd
  38.  
  39.  
  40.  
  41. ! and then execute it : ./doscar_analysis_spd
  42.  
  43.  
  44.  
  45. ! the POSCAR file should be in the directory from which you call doscar_analysis_spd
  46.  
  47.  
  48.  
  49. ! for instance, if you have compilde doscar_analysis in /home/max/bin , and your DOSCAR is in /home/max/vaspoutput/DOSCAR
  50.  
  51.  
  52.  
  53. ! type : cd /home/max/vaspoutput/
  54.  
  55.  
  56.  
  57. ! and then : ../bin/doscar_analysis_spd
  58.  
  59.  
  60.  
  61. ! Maximilien Levesque 201108040017
  62.  
  63. ! Maximilien Levesque 201109011504 debug of number of steps in case of local density of states
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73. program doscar_analysis
  74.  
  75.  
  76.  
  77. implicit none
  78.  
  79.  
  80.  
  81. integer :: number_of_atoms ! total number of atoms in POSCAR
  82.  
  83.  
  84.  
  85. integer :: i ! dummy
  86.  
  87.  
  88.  
  89. double precision :: t ! dummy
  90.  
  91.  
  92.  
  93. double precision :: Emax , Emin ! max and min value of the energy (absciss limits)
  94.  
  95.  
  96.  
  97. integer :: number_of_steps ! discretization of the abscissa
  98.  
  99.  
  100.  
  101. double precision :: Efermi ! Fermi energy of the system
  102.  
  103.  
  104.  
  105. integer :: choice ! choice made by user
  106.  
  107.  
  108.  
  109. integer :: choice_translate ! choice made by user : translate or not to fermi energy
  110.  
  111.  
  112.  
  113. integer :: choice_polarization ! choice made by user : polarization enabled or not
  114.  
  115.  
  116.  
  117. integer :: choice_atom ! choice made by user : label of the atom the user wants the PDOS of
  118.  
  119.  
  120.  
  121. integer :: choice_spdf ! choice made by user : whether to specify orbital contributions separately
  122.  
  123.  
  124.  
  125. double precision :: dos_up , dos_down ! local value of dos spin up and spin down
  126.  
  127.  
  128.  
  129. double precision :: dos_up_s, dos_down_s ! local values of dos spin up and spin down for s-shell
  130.  
  131.  
  132.  
  133. double precision :: dos_up_p, dos_down_p ! local values of dos spin up and spin down for p-shell
  134.  
  135.  
  136.  
  137. double precision :: dos_up_d, dos_down_d ! local values of dos spin up and spin down for d-shell
  138.  
  139.  
  140.  
  141. double precision :: n1=0, n2=0, n3=0, n4=0, n5=0, n6=0, n7=0, n8=0, n9=0
  142.  
  143.  
  144.  
  145. double precision :: n10=0, n11=0, n12=0, n13=0, n14=0, n15=0, n16=0, n17=0, n18=0
  146.  
  147.  
  148.  
  149. ! open DOSCAR
  150.  
  151.  
  152.  
  153. open ( 10 , file = 'DOSCAR' , form = 'formatted' )
  154.  
  155.  
  156.  
  157. ! first line is the total number of atoms and 3 numbers i don't know what they mean
  158.  
  159.  
  160.  
  161. read ( 10 , * ) number_of_atoms , i , i , i
  162.  
  163.  
  164.  
  165. ! line 2 to 5 are useless
  166.  
  167.  
  168.  
  169. do i = 2 , 5 ; read ( 10 , * ) ; end do
  170.  
  171.  
  172.  
  173. ! line 6 contains Emax , Emin , number_of_steps , Efermi and ?
  174.  
  175.  
  176.  
  177. read ( 10 , * ) Emax , Emin , number_of_steps , Efermi , t
  178.  
  179.  
  180.  
  181. ! ask user what he wants of me
  182.  
  183.  
  184.  
  185. 77 write ( * , * ) "Do you want to compute the total density of states (press 1) or a projected one (press 2) ?"
  186.  
  187.  
  188.  
  189. read ( * , * ) choice
  190.  
  191.  
  192.  
  193. ! test if answer is correct
  194.  
  195.  
  196.  
  197. if ( choice /= 1 .and. choice /= 2 ) then
  198.  
  199.  
  200.  
  201. write ( * , * ) "Only 1 or 2 is possible."
  202.  
  203.  
  204.  
  205. goto 77
  206.  
  207.  
  208.  
  209. end if
  210.  
  211.  
  212.  
  213. ! ask user if he wants to translate to Fermi level or not
  214.  
  215.  
  216.  
  217. 88 write ( * , * ) "Do you want to translate all the energies to Fermi energy (press 1 for yes , press 2 for no) ?"
  218.  
  219.  
  220.  
  221. read ( * , * ) choice_translate
  222.  
  223.  
  224.  
  225. ! test if answer is correct
  226.  
  227.  
  228.  
  229. if ( choice_translate /= 1 .and. choice_translate /= 2 ) then
  230.  
  231.  
  232.  
  233. write ( * , * ) "Only 1 or 2 is possible."
  234.  
  235.  
  236.  
  237. goto 88
  238.  
  239.  
  240.  
  241. end if
  242.  
  243.  
  244.  
  245. ! ask user if the calculation is polarized or not
  246.  
  247.  
  248.  
  249. 99 write ( * , * ) "Is system polarized (press 1 for yes , press 2 for no) ?"
  250.  
  251.  
  252.  
  253. read ( * , * ) choice_polarization
  254.  
  255.  
  256.  
  257. ! test if answer is correct
  258.  
  259.  
  260.  
  261. if ( choice_polarization /= 1 .and. choice_polarization /= 2 ) then
  262.  
  263.  
  264.  
  265. write ( * , * ) "Only 1 or 2 is possible."
  266.  
  267.  
  268.  
  269. goto 99
  270.  
  271.  
  272.  
  273. end if
  274.  
  275.  
  276.  
  277. ! open file for writting output
  278.  
  279.  
  280.  
  281. open ( unit = 11 , file = 'doscar_analysis_spd.dat' , form = 'formatted' )
  282.  
  283.  
  284.  
  285. ! write it Fermi energy
  286.  
  287.  
  288.  
  289. write ( 11 , * ) "# E fermi = " , Efermi
  290.  
  291.  
  292.  
  293. ! if total DOS is wanted
  294.  
  295.  
  296.  
  297. if ( choice == 1 ) then
  298.  
  299.  
  300.  
  301. ! read the number_of_steps next lines.
  302.  
  303.  
  304.  
  305. if ( choice_polarization == 1 ) then
  306.  
  307.  
  308.  
  309. do i = 1 , number_of_steps
  310.  
  311.  
  312.  
  313. read ( 10 , * ) t , dos_up , dos_down
  314.  
  315.  
  316.  
  317. write ( 11 , * ) "Energy - DOS_UP - DOS_DOWN - DOS_TOT"
  318.  
  319.  
  320.  
  321. if ( choice_translate == 1 ) write ( 11 , * ) t - Efermi , dos_up , dos_down , dos_up + dos_down
  322.  
  323.  
  324.  
  325. if ( choice_translate == 2 ) write ( 11 , * ) t , dos_up , dos_down , dos_up + dos_down
  326.  
  327.  
  328.  
  329. end do
  330.  
  331.  
  332.  
  333. else if ( choice_polarization == 2 ) then
  334.  
  335.  
  336.  
  337. do i = 1 , number_of_steps
  338.  
  339.  
  340.  
  341. read ( 10 , * ) t , dos_up
  342.  
  343.  
  344.  
  345. write ( 11 , * ) "Energy - DOS_TOT"
  346.  
  347.  
  348.  
  349. if ( choice_translate == 1 ) write ( 11 , * ) t - Efermi , dos_up
  350.  
  351.  
  352.  
  353. if ( choice_translate == 2 ) write ( 11 , * ) t , dos_up
  354.  
  355.  
  356.  
  357. end do
  358.  
  359.  
  360.  
  361. end if
  362.  
  363.  
  364.  
  365. else if ( choice == 2 ) then
  366.  
  367.  
  368.  
  369. ! if projected DOS is wanted
  370.  
  371.  
  372.  
  373. ! first ask user which atom he is interested in
  374.  
  375.  
  376.  
  377. 1010 write ( * , * ) "Which atom (same label as in POSCAR and first label is 1 (not 0)) ?"
  378.  
  379.  
  380.  
  381. read ( * , * ) choice_atom
  382.  
  383.  
  384.  
  385. ! test if answer is correct
  386.  
  387.  
  388.  
  389. if ( choice_atom < 1 .or. choice_atom > number_of_atoms ) then
  390.  
  391.  
  392.  
  393. write ( * , * ) "Wrong answer"
  394.  
  395.  
  396.  
  397. goto 1010
  398.  
  399.  
  400.  
  401. end if
  402.  
  403.  
  404.  
  405. ! Next ask if the specific orbital DOS are to be printed as well
  406.  
  407.  
  408.  
  409. 1111 write ( * , * ) "Also specify s-p-d contributions separately (1 for yes or 2 for no) ?"
  410.  
  411.  
  412.  
  413. read ( * , * ) choice_spdf
  414.  
  415.  
  416.  
  417. ! test if the answer is a valid option
  418.  
  419.  
  420.  
  421. if ( choice_spdf /= 1 .and. choice_spdf /= 2) then
  422.  
  423.  
  424.  
  425. write ( * , * ) "Wrong answer"
  426.  
  427.  
  428.  
  429. goto 1111
  430.  
  431.  
  432.  
  433. end if
  434.  
  435.  
  436.  
  437. ! go to line corresponding to good label
  438.  
  439.  
  440.  
  441. ! ignore first total dos lines
  442.  
  443.  
  444.  
  445. do i = 1 , number_of_steps ; read ( 10 , * ) ; end do
  446.  
  447.  
  448.  
  449. ! ignore non wanted atoms
  450.  
  451.  
  452.  
  453. if ( choice_atom > 1 ) then
  454.  
  455.  
  456.  
  457. do i = 1 , ( choice_atom - 1) * ( number_of_steps + 1 ) ; read ( 10 , * ) ; end do
  458.  
  459.  
  460.  
  461. end if
  462.  
  463.  
  464.  
  465. ! read useless line
  466.  
  467.  
  468.  
  469. read ( 10 , * )
  470.  
  471.  
  472.  
  473. ! for spin polarised s+ s- px+ px- py+ py- pz+ pz- dxy+ dxy- dyz+ dyz- dxz+ dxz- dx2-y2+ dx2-y2- dz2+ dz2-
  474.  
  475. ! for non-spin polarized s px py pz dxy dyz dxz dx2-y2 dz2
  476.  
  477.  
  478.  
  479. if ( choice_spdf == 1 ) then
  480.  
  481.  
  482.  
  483. if ( choice_polarization == 1 ) then
  484.  
  485.  
  486.  
  487. write ( 11 , * ) "Energy - DOS_UP - DOS_DOWN - DOS_TOT - DOS_UP_s - DOS_DOWN_s - DOS_TOT_s - &
  488.  
  489. &DOS_UP_p - DOS_DOWN_p - DOS_TOT_p - DOS_UP_d - DOS_DOWN_d - DOS_TOT_d"
  490.  
  491.  
  492.  
  493. do i = 1 , number_of_steps
  494.  
  495.  
  496.  
  497. read(10,*) t, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18
  498.  
  499.  
  500.  
  501. dos_up = n1+n3+n5+n7+n9+n11+n13+n15+n17
  502.  
  503.  
  504.  
  505. dos_down = n2+n4+n6+n8+n10+n12+n14+n16+n18
  506.  
  507.  
  508.  
  509. dos_up_s = n1
  510.  
  511.  
  512.  
  513. dos_down_s = n2
  514.  
  515.  
  516.  
  517. dos_up_p = n3+n5+n7
  518.  
  519.  
  520.  
  521. dos_down_p = n4+n6+n8
  522.  
  523.  
  524.  
  525. dos_up_d = n9+n11+n13+n15+n17
  526.  
  527.  
  528.  
  529. dos_down_d = n10+n12+n14+n16+n18
  530.  
  531.  
  532.  
  533. if ( choice_translate == 1 ) write ( 11 , * ) t - Efermi, dos_up, dos_down, dos_up+dos_down,&
  534.  
  535. & dos_up_s, dos_down_s, dos_up_s+dos_down_s, dos_up_p, dos_down_p, dos_up_p+dos_down_p,&
  536.  
  537. & dos_up_d, dos_down_d, dos_up_d+dos_down_d
  538.  
  539.  
  540.  
  541. if ( choice_translate == 2 ) write ( 11 , * ) t, dos_up, dos_down, dos_up+dos_down,&
  542.  
  543. & dos_up_s, dos_down_s, dos_up_s+dos_down_s, dos_up_p, dos_down_p, dos_up_p+dos_down_p,&
  544.  
  545. & dos_up_d, dos_down_d, dos_up_d+dos_down_d
  546.  
  547.  
  548.  
  549. end do
  550.  
  551.  
  552.  
  553. else if ( choice_polarization == 2 ) then
  554.  
  555.  
  556.  
  557. write ( 11 , * ) "Energy - DOS_TOT - DOS_s - DOS_p - DOS_d"
  558.  
  559.  
  560.  
  561. do i = 1 , number_of_steps
  562.  
  563.  
  564.  
  565. read(10,*) t, n1, n2, n3, n4, n5, n6, n7, n8, n9
  566.  
  567.  
  568.  
  569. dos_up = n1+n2+n3+n4+n5+n6+n7+n8+n9
  570.  
  571.  
  572.  
  573. dos_up_s = n1
  574.  
  575.  
  576.  
  577. dos_up_p = n2+n3+n4
  578.  
  579.  
  580.  
  581. dos_up_d = n5+n6+n7+n8+n9
  582.  
  583.  
  584.  
  585. if ( choice_translate == 1 ) write ( 11 , * ) t - Efermi, dos_up, dos_up_s, dos_up_p, dos_up_d
  586.  
  587.  
  588.  
  589. if ( choice_translate == 2 ) write ( 11 , * ) t, dos_up, dos_up_s, dos_up_p, dos_up_d
  590.  
  591.  
  592.  
  593. end do
  594.  
  595.  
  596.  
  597. end if
  598.  
  599.  
  600.  
  601. else if ( choice_spdf == 2 ) then
  602.  
  603.  
  604.  
  605. if ( choice_polarization == 1 ) then
  606.  
  607.  
  608.  
  609. write ( 11 , * ) "Energy - DOS_UP - DOS_DOWN - DOS_TOT"
  610.  
  611.  
  612.  
  613. do i = 1 , number_of_steps
  614.  
  615.  
  616.  
  617. read(10,*) t, n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14, n15, n16, n17, n18
  618.  
  619.  
  620.  
  621. dos_up = n1+n3+n5+n7+n9+n11+n13+n15+n17
  622.  
  623.  
  624.  
  625. dos_down = n2+n4+n6+n8+n10+n12+n14+n16+n18
  626.  
  627.  
  628.  
  629. if ( choice_translate == 1 ) write ( 11 , * ) t - Efermi, dos_up, dos_down, dos_up+dos_down
  630.  
  631.  
  632.  
  633. if ( choice_translate == 2 ) write ( 11 , * ) t, dos_up, dos_down, dos_up+dos_down
  634.  
  635.  
  636.  
  637. end do
  638.  
  639.  
  640.  
  641. else if ( choice_polarization == 2 ) then
  642.  
  643.  
  644.  
  645. write ( 11 , * ) "Energy - DOS_TOT"
  646.  
  647.  
  648.  
  649. do i = 1 , number_of_steps
  650.  
  651.  
  652.  
  653. read(10,*) t, n1, n2, n3, n4, n5, n6, n7, n8, n9
  654.  
  655.  
  656.  
  657. dos_up = n1+n2+n3+n4+n5+n6+n7+n8+n9
  658.  
  659.  
  660.  
  661. if ( choice_translate == 1 ) write ( 11 , * ) t - Efermi , dos_up
  662.  
  663.  
  664.  
  665. if ( choice_translate == 2 ) write ( 11 , * ) t , dos_up
  666.  
  667.  
  668.  
  669. end do
  670.  
  671.  
  672.  
  673. end if
  674.  
  675.  
  676.  
  677. end if
  678.  
  679.  
  680.  
  681. end if
  682.  
  683.  
  684.  
  685.  
  686.  
  687. ! close DOSCAR
  688.  
  689.  
  690.  
  691. close ( 10 )
  692.  
  693.  
  694.  
  695. ! close output file doscar_analysis_spd.dat
  696.  
  697.  
  698.  
  699. close ( 11 )
  700.  
  701.  
  702.  
  703. write ( * , * ) 'done. look at => doscar_analysis_spd.dat'
  704.  
  705.  
  706.  
  707. write ( * , * ) 'To read it, you may use => xmgrace -nxy doscar_analysis_spd.dat'
  708.  
  709.  
  710.  
  711. end program doscar_analysis
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement