因为需要将文件中的站点名按照字母顺序排序,用matlab实现比较简单。 源文件: e_ann.gps 源程序: clear; clc; tic; filename = 'e_ann.gps'; fid = fopen(filename,'r'); i = 0; % 270个站点,对应文件270行 site_name = cell(1,270); while 1 line = fgetl(fid); if ~ischar(line),break,end text = textscan(line,'%s %f %f %f %f %f %f %f %s'); i = i+1; site_name{i} = text{9}{1}; end site_sort = sort(site_name); fclose(fid); fid = fopen('e_ann.gps_new','wt'); a = importdata(filename); nn = length(a); for i = 1:nn for j = 1:nn if strfind(a{j},site_sort{i}) 0 fprintf(fid,'%s\n',a{j}); end end end toc; 生成需要的文件: e_ann.gps_new
split_dos and vp 源文件 Split_dos 源文件 #!/bin/ksh # Script to break the VASP DOSCAR file into segments for # each atomic site. # JMS NRL 5/0/02 # Modified to also align the Fermi level from the ground state # to E=0.0 # JMS NRL 6/19/02 # Executables reside here BIN=~/bin if ; then echo "Usage: split_dos" exit 2 fi # Script to split the DOSCAR file into the atomic # projections labeled by atom number dosfile=DOSCAR outfile=OUTCAR infile=INCAR # Token for splitting the files token=$(sed -n '6 p' $dosfile | awk '{print $1}') # Number of points nl=$(sed -n '6 p' $dosfile | awk '{print $3}') # Number of atoms natom=$(sed -n '1 p' $dosfile | awk '{print $1}') # Get the Fermi level if the OUTCAR file is present, # else we set it to zero. if ; then echo "The" $outfile "exists, we use it to get the Fermi level," echo "the RWIGS tag and the number of spins." efermi=$(grep "E-fermi" $outfile | tail -1 | awk '{print $3}') echo "Fermi level:" $efermi nspin=$(grep "ISPIN" $outfile | tail -1 | awk '{print $3}') if ; then echo "Spin polarized calculation" else echo "Unpolarized calculation" fi # 2.a # JMS 2/3/03 Modified to accept specification by LORBIT token. # lorbit=$(grep "LORBIT" $outfile | tail -1 | awk '{print $3}') if ; then echo "LORBIT 10" echo "WARNING: not completely test for vasp.4.*" echo "Use at your own risk. Please check results for consistency." form=1 else # 2.a rwigs=$(grep "RWIGS" $outfile | tail -1 | awk '{print $3}' | sed 's/\.//g') if ; then echo "RWIGS token not set" form=0 else echo "RWIGS token set" form=1 fi # 2.a fi # 2.a else echo "The" $outfile "does not exist, we set the Fermi level to 0" echo "assume an unpolarized calculation, and RWIGS not set" form=0 nspin=1 efermi=0.0 fi # If the outcar file is not present and you wish to set something by hand # you should do it here. Uncomment the tokens below and set them by hand. #efermi=2.255 #form= #nspin= # Get the atomic coordinates $BIN/vp | tmp.dat tail -$natom tmp.dat | awk '{printf "%s %12.8f %12.8f %12.8f \n", "#", $2, $3, $4}' | tmp.dat2 # Total is first DOS if ; then i=0 else i=0 fi start=7 end=$((start+nl-1)) #echo $start $end #exit 0 rm -f DOS0 if ; then while ; do #echo $i $start $end if ; then sed -n ''$i' p' tmp.dat2 | DOS$i fi if ; then # Atomic projected DOS if ; then sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, -1*$3, $4, -1*$5, $6, -1*$7}' DOS$i else sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, $3, $4 }' DOS$i fi else # Total DOS if ; then sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, -1*$3, $4, -1*$5 }' DOS$i else sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, $3 }' DOS$i fi fi start=$((end+2)) end=$((start+nl-1)) i=$((i+1)) done else while ; do #echo $i $start $end if ; then sed -n ''$i' p' tmp.dat2 | DOS$i fi if ; then # Atomic projected DOS if ; then sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, -1*$3, $4, -1*$5, $6, -1*$7}' DOS$i else sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, $3, $4 }' DOS$i fi else # Total DOS if ; then sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, -1*$3, $4, -1*$5 }' DOS$i else sed -n ''$start','$end' p' $dosfile | awk '{printf "%12.8f %12.8f %12.8f \n", $1+(-1)*'$efermi', $2, $3 }' DOS$i fi fi start=$((end+2)) end=$((start+nl-1)) i=$((i+1)) done fi exit 0 VP文件 #注意,split_dos中默认路径为BIN/vp,vp所在文件夹要有POSCAR,OUTCAR #用来得到原子坐标 #!/bin/ksh # Script to grab the atomic positions from the # OUTCAR VASP file and write them to a file for use # with an xmol movie. # J M Sullivan NRL 12/4/01 # Scale the forces by this factor for visualization fscale=1 posfile=POSCAR # Output file containing the data outfile=OUTCAR # Token to search for to get the atomic positions token=POSITION # Get the atom number types set -A ntype $(sed -n '6 p' $posfile) echo "Number of atom types:" ${#ntype } echo "Multiplicities of these types:" ${ntype } ns=${#ntype } i=0 natoms=0 while ; do nt=${ntype } let natoms=$natoms+$nt i=$((i+1)) done echo "Total number of atoms:" $natoms # Get the atom labels from the OUTCAR file set -A type #_jms 4/2/03 #set -A label $(grep "POTCAR:" $outfile | head -$ns | sed 's/POTCAR://g' | sed 's/US//g') #set -A label $(grep "POTCAR:" $outfile | head -$ns | sed 's/POTCAR://g' | sed 's/US//g'| sed 's/PAW//g' | awk '{print $1}') set -A label $(grep "POTCAR:" $outfile | head -$ns | sed 's/POTCAR://g' | sed 's/US//g'| sed 's/PAW//g' | sed 's/_PBE//g' | awk '{print $1}') #_jms 4/2/03 #label =H1 echo ${label } nt=0 i=0 while ; do j=1 while } ]; do nt=$((nt+1)) j=$((j+1)) type =${label } #echo $nt ${type } done i=$((i+1)) done echo ${type } grep -n "$token" $outfile | sed 's/POSITION/\ POSITION/g' | sed 's/://g' | tmp.dump while read nstart trash do nstart=$((nstart+2)) nend=$((nstart+natoms-1)) #nend=$(echo $nstart $natoms | awk '{print $1+$2-1}') #echo $nstart $nend echo $natoms echo sed -n ''$nstart','$nend' p' $outfile | awk '{printf "%12.9f %12.9f %12.9f %s %12.9f %12.9f %12.9f \n", $1, $2, $3, NR, '$fscale'*$4, '$fscale'*$5, '$fscale'*$6}' | tmp.dump2 i=1 while read a b c do echo ${type } $a $b $c i=$((i+1)) done tmp.dump2 done tmp.dump rm -f tmp.dump tmp.dump2 exit 0