├── .gitignore ├── COsys.sh ├── IR-intensity.sh ├── Ptsys.sh ├── README.md ├── Ru1sys.sh ├── Rusys.sh ├── VASP.py ├── Vasp.pm ├── WorkDir.sh ├── add_c.sh ├── all2unix.py ├── cel2vas.py ├── chg2cube.pl ├── chgflag.py ├── choice.pl ├── ck ├── clc ├── clean ├── cluster.py ├── cpfile ├── difenergy ├── dir2car.py ├── drawcluster.py ├── energy ├── example ├── frequency.xyz └── neb_movie.xyz ├── excongjf.py ├── excoor.py ├── exfreq.py ├── flagck.py ├── freqmov.py ├── g09_jobs.py ├── gjf2vas.py ├── gjf2xyz.py ├── gvextend.py ├── hlcluster.py ├── ic2cc.pl ├── isWorkFinished.sh ├── modemake.py ├── mvall ├── mycp ├── mysort.pl ├── neb2dim.pl ├── nebbarrier.pl ├── nebclc ├── nebef.pl ├── nebforce.py ├── nebgjf2vas.py ├── nebinfo ├── nebmake.pl ├── nebmovie ├── nebresults.pl ├── nebspline.pl ├── nebtar ├── nebtarall ├── nebvtst.py ├── node.sh ├── posdiff.py ├── rmall ├── start_freq_job.sh ├── stdoutput.pl ├── sub ├── tmp.py ├── vas2cif.pl ├── vas2gjf.py ├── vas2xyz.py ├── xdat2xyz.pl └── xyzmerge.py /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | __pycache__/ 3 | -------------------------------------------------------------------------------- /COsys.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #vas2xyz.pl ts.vasp 3 | in=$1 4 | moviecombine.pl $in $in 12.xyz 5.4116 0 0 5 | moviecombine.pl 12.xyz $in 123.xyz 10.8232 0 0 6 | moviecombine.pl 123.xyz 123.xyz 123123.xyz 2.7058000565 4.6865831729 0 7 | moviecombine.pl 123123.xyz 123.xyz final.xyz 5.4116 9.37316634 0 8 | rm 12.xyz 123.xyz 123123.xyz 9 | mv final.xyz $in 10 | -------------------------------------------------------------------------------- /IR-intensity.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # A utility for calculating the vibrational intensities from VASP output (OUTCAR) 3 | # (C) David Karhanek, 2011-03-25, ICIQ Tarragona, Spain (www.iciq.es) 4 | 5 | # extract Born effective charges tensors 6 | printf "..reading OUTCAR" 7 | BORN_NROWS=`grep NIONS OUTCAR | awk '{print $12*4+1}'` 8 | if [ `grep 'BORN' OUTCAR | wc -l` = 0 ] ; then \ 9 | printf " .. FAILED! Born effective charges missing! Bye! \n\n" ; exit 1 ; fi 10 | grep "in e, cummulative" -A $BORN_NROWS OUTCAR > born.txt 11 | 12 | # extract Eigenvectors and eigenvalues 13 | if [ `grep 'SQRT(mass)' OUTCAR | wc -l` != 1 ] ; then \ 14 | printf " .. FAILED! Restart VASP with NWRITE=3! Bye! \n\n" ; exit 1 ; fi 15 | EIG_NVIBS=`grep -A 2000 'SQRT(mass)' OUTCAR | grep 'cm-1' | wc -l` 16 | EIG_NIONS=`grep NIONS OUTCAR | awk '{print $12}'` 17 | EIG_NROWS=`echo "($EIG_NIONS+3)*$EIG_NVIBS+3" | bc` 18 | grep -A $(($EIG_NROWS+2)) 'SQRT(mass)' OUTCAR | tail -n $(($EIG_NROWS+1)) | sed 's/f\/i/fi /g' > eigenvectors.txt 19 | printf " ..done\n" 20 | 21 | # set up a new directory, split files - prepare for parsing 22 | printf "..splitting files" 23 | mkdir intensities ; mv born.txt eigenvectors.txt intensities/ 24 | cd intensities/ 25 | let NBORN_NROWS=BORN_NROWS-1 26 | let NEIG_NROWS=EIG_NROWS-3 27 | let NBORN_STEP=4 28 | let NEIG_STEP=EIG_NIONS+3 29 | tail -n $NBORN_NROWS born.txt > temp.born.txt 30 | tail -n $NEIG_NROWS eigenvectors.txt > temp.eige.txt 31 | mkdir inputs ; mv born.txt eigenvectors.txt inputs/ 32 | split -a 3 -d -l $NEIG_STEP temp.eige.txt temp.ei. 33 | split -a 3 -d -l $NBORN_STEP temp.born.txt temp.bo. 34 | mkdir temps01 ; mv temp.born.txt temp.eige.txt temps01/ 35 | for nu in `seq 1 $EIG_NVIBS` ; do 36 | let nud=nu-1 ; ei=`printf "%03u" $nu` ; eid=`printf "%03u" $nud` ; mv temp.ei.$eid eigens.vib.$ei 37 | done 38 | for s in `seq 1 $EIG_NIONS` ; do 39 | let sd=s-1 ; bo=`printf "%03u" $s` ; bod=`printf "%03u" $sd` ; mv temp.bo.$bod borncs.$bo 40 | done 41 | printf " ..done\n" 42 | 43 | # parse deviation vectors (eig) 44 | printf "..parsing eigenvectors" 45 | let sad=$EIG_NIONS+1 46 | for nu in `seq 1 $EIG_NVIBS` ; do 47 | nuu=`printf "%03u" $nu` 48 | tail -n $sad eigens.vib.$nuu | head -n $EIG_NIONS | awk '{print $4,$5,$6}' > e.vib.$nuu.allions 49 | split -a 3 -d -l 1 e.vib.$nuu.allions temp.e.vib.$nuu.ion. 50 | for s in `seq 1 $EIG_NIONS` ; do 51 | let sd=s-1; bo=`printf "%03u" $s`; bod=`printf "%03u" $sd`; mv temp.e.vib.$nuu.ion.$bod e.vib.$nuu.ion.$bo 52 | done 53 | done 54 | printf " ..done\n" 55 | 56 | # parse born effective charge matrices (born) 57 | printf "..parsing eff.charges" 58 | for s in `seq 1 $EIG_NIONS` ; do 59 | ss=`printf "%03u" $s` 60 | awk '{print $2,$3,$4}' borncs.$ss | tail -3 > bornch.$ss 61 | done 62 | mkdir temps02 ; mv eigens.* borncs.* temps02/ 63 | printf " ..done\n" 64 | 65 | # parse matrices, multiply them and collect squares (giving intensities) 66 | printf "..multiplying matrices, summing " 67 | for nu in `seq 1 $EIG_NVIBS` ; do 68 | nuu=`printf "%03u" $nu` 69 | int=0.0 70 | for alpha in 1 2 3 ; do # summing over alpha coordinates 71 | sumpol=0.0 72 | for s in `seq 1 $EIG_NIONS` ; do # summing over atoms 73 | ss=`printf "%03u" $s` 74 | awk -v a="$alpha" '(NR==a){print}' bornch.$ss > z.ion.$ss.alpha.$alpha 75 | # summing over beta coordinates and multiplying Z(s,alpha)*e(s) done by the following awk script 76 | paste z.ion.$ss.alpha.$alpha e.vib.$nuu.ion.$ss | \ 77 | awk '{pol=$1*$4+$2*$5+$3*$6; print $0," ",pol}' > matr-vib-${nuu}-alpha-${alpha}-ion-${ss} 78 | done 79 | sumpol=`cat matr-vib-${nuu}-alpha-${alpha}-ion-* | awk '{sum+=$7} END {print sum}'` 80 | int=`echo "$int+($sumpol)^2" | sed 's/[eE]/*10^/g' | bc -l` 81 | done 82 | freq=`awk '(NR==1){print $8}' temps02/eigens.vib.$nuu` 83 | echo "$nuu $freq $int">> exact.res.txt 84 | printf "." 85 | done 86 | printf " ..done\n" 87 | 88 | # format results, normalize intensities 89 | printf "..normalizing intensities" 90 | max=`awk '(NR==1){max=$3} $3>=max {max=$3} END {print max}' exact.res.txt` 91 | awk -v max="$max" '{printf "%03u %6.1f %5.3f\n",$1,$2,$3/max}' exact.res.txt > results.txt 92 | printf " ..done\n" 93 | 94 | # clean up, display results 95 | printf "..finalizing:\n" 96 | mkdir temps03; mv bornch.* e.vib.*.allions temps03/ 97 | mkdir temps04; mv z.ion* e.vib.*.ion.* temps04/ 98 | mkdir temps05; mv matr-* temps05/ 99 | mkdir results; mv *res*txt results/ 100 | let NMATRIX=$EIG_NVIBS**2 101 | printf "%5u atoms found\n%5u vibrations found\n%5u matrices evaluated" \ 102 | $EIG_NIONS $EIG_NVIBS $NMATRIX > results/statistics.txt 103 | # fast switch to clean up all temporary files 104 | rm -r temps* 105 | cat results/results.txt -------------------------------------------------------------------------------- /Ptsys.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | out="$1.xyz" 3 | moviecombine.pl $1 $1 12.xyz -22.57063 0 0 4 | moviecombine.pl 12.xyz $1 123.xyz -5.64266 9.7755 0 5 | moviecombine.pl 123.xyz $1 1234.xyz -28.2133 9.7755 0 6 | rm 12.xyz 123.xyz 7 | mv 1234.xyz $out 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # VASP-script 2 | ## 介绍 3 | 本仓库用于保存我在工作中经常用到的全部脚本文件,包括几个用于制作动画的脚本,对我工作帮助很大,现在共享出来供大家交流使用。部分脚本文件是在[vtst tool](http://theory.cm.utexas.edu/vtsttools/scripts.html)工具中提供的脚本上修改而来。编程语言主要为perl和shell script,含有少量python脚本。 4 | 5 | 6 | ## 使用方法 7 | 将所有脚本文件拷到本地用户目录文件夹~/bin中(没有则新建文件夹),然后执行`chmod +x ~/bin/*`添加权限。之后添加环境变量,在~/.bashrc中加入`export PATH=~/bin:$PATH`,保存后执行命令`source ~/.bashrc`即可使用。 8 | 9 | ## 主要脚本功能及用法详细介绍 10 | 注:没有介绍到的属于临时脚本,可不考虑,大部分的perl脚本在执行时如果不输入参数,将会给出简明用法,例如输入: 11 | ``` 12 | vas2gv.pl 13 | ``` 14 | 则输出: 15 | ``` 16 | ############### This script converts vasp file into gview file ############### 17 | ############ CONTCAR or POSCAR -> .gjf ############ 18 | 19 | Usage: vas2gv.pl file1 file2 file3..... 20 | file can be POSCAR or CONTCAR and either direct or cartesian 21 | Please try again! 22 | ``` 23 | ----- 24 | #### cel2pos.pl 25 | 用法: 26 | ``` 27 | cel2pos.pl file.cell 28 | ``` 29 | 用于将materials studio的CASTEP模块生成的cell文件转化为VASP输入文件POSCAR,生成file.vasp文件 30 | 31 | ----- 32 | 33 | #### ck 34 | 用法: 35 | ``` 36 | ck 37 | ``` 38 | 在运行前用于检查参数的脚本,可检查K点的设置,POTCAR的赝势类型和POSCAR的前六行输入 39 | 如果执行该脚本的文件夹路径中含有关键字`dimer`,则还会检查是否有MODECAR存在 40 | 41 | ----- 42 | 43 | #### cpfile 44 | 用法: 45 | ``` 46 | cpfile target_directory 47 | ``` 48 | 把target_directory路径下的INCAR、POTCAR、KPOINTS以及所有的可执行文件拷贝到当前文件夹。 49 | 使用`-a`选项除了拷贝以上文件,还会将POSCAR拷贝到当前文件夹。 50 | 51 | ----- 52 | 53 | #### dir2car.pl 54 | 用法: 55 | ``` 56 | dir2car.pl file1 file2 ... 57 | ``` 58 | 将VASP的输入/输出文件从分数坐标转化为笛卡尔坐标,可一次性添加多个文件file1 file2 .... 59 | 60 | ----- 61 | 62 | #### energy 63 | 用法: 64 | ``` 65 | energy dir1 dir2 ... 66 | ``` 67 | 用于快速获取体系能量,会分别抓取文件夹dir1 dir2 ...中OUTCAR文件中的能量`energy without entropy`,并输出最后一个值。如果没有参数,则会输出当前文件夹下(包括子文件夹)所有的OUTCAR中的最后一个`energy without entropy`的值。 68 | 69 | ----- 70 | 71 | #### excoor.pl 72 | 用法: 73 | ``` 74 | excoor.pl step1 step2 ... 75 | ``` 76 | 该脚本会首先抓取OUTCAR文件中每一个离子步结束后体系的能量以及其中每个原子的坐标和受力情况,并在行末会计算出每个原子收到的xyz合力的大小,结果保存到OUTCAR.pos文件中。然后将第'step1'、'step2' ... 的坐标另存为POSCAR文件。 77 | step1 step2 ... 是离子步的步数,可以省略。 78 | 例如执行命令`excoor.pl 10`,会生成一个OURCAR.pos文件,以及包含第10个离子步的POSCAR文件。 79 | 80 | ----- 81 | 82 | #### chgflag.py 83 | 用法: 84 | ``` 85 | flachg.pl line1,line2,.... T/F vaspfile 86 | ``` 87 | line1、line2 ... 是需要改变驰豫标记的原子编号,POSCAR文件中的原子从上至下的编号依次是1,2,3,...,n。 88 | 例如执行命令`chgflag.py 2,5,10-13,22 F POSCAR`则会将POSCAR文件中第2个、第5个、第10-13个以及第22个原子的驰豫标记变为`F F F` 89 | 90 | ----- 91 | 92 | #### freqmov.pl 93 | 用法: 94 | ``` 95 | freqmov.pl POSCAR freqfile 30 0.6 96 | ``` 97 | 用于把频率计算的结果转化为动画。首先要制作freqfile文件,其格式为: 98 | ``` 99 | 30 f/i= 43.595023 THz 273.915607 2PiTHz 1454.173389 cm-1 180.294587 meV 100 | X Y Z dx dy dz 101 | -1.334507 2.369499 6.388597 -0.015951 0.008861 -0.024862 102 | 2.621978 4.667179 6.419931 -0.008397 -0.017126 -0.024545 103 | 1.361682 2.515564 6.433748 0.010846 0.019286 -0.030780 104 | 2.704039 0.032985 6.442084 0.010923 -0.007642 -0.018801 105 | ``` 106 | - freqfile中保存的是OUTCAR中的某一个振动频率**完整**的信息。1、2行必须有,之后是每个原子的坐标及其振动方向,原子的数量必须与本体系数量一致。例如30个原子的体系,就必须有32行数据,至于是不是虚频则无所谓。 107 | - POSCAR是本体系的输入文件; 108 | - 30是动画的帧数,数字越大动画越细腻,30足够了; 109 | - 0.6是系数,用于调节振幅。OUTCAR中给出的振幅很大,需要适当缩减,0.6即可; 110 | 111 | 最后会产生一个freqfile.xyz文件,用VMD打开即可播放。 112 | freqfile文件可用下列方法提取: 113 | ``` 114 | grep "20 f/i" OUTCAR -A 20 >freq20 115 | ``` 116 | `-A 20`是输出查找到的信息以及其后20行,命令的具体含义请自行百度。也可以自己打开OUTCAR,找到所需信息直接存为文本格式。 117 | 118 | ----- 119 | 120 | #### gv2vas.pl 121 | 用法: 122 | ``` 123 | gv2vas.pl POSCAR file1.gjf file2.gjf ... 124 | ``` 125 | 把GaussianView生成的构型文件file.gjf转化为VASP的输入文件,以file1.vasp file2.vasp ...形式保存。生成VASP输入文件,其2-4行的坐标基以及原子弛豫标记将与POSCAR文件相同。元素种类和数量与gjf文件保持一致。 126 | **重要:gjf文件中相同的元素必须相邻,用GaussianView画出的构型保存后将无法保证这一点,需要自行调整** 127 | 128 | ---- 129 | 130 | #### modemake.pl 131 | 用法: 132 | ``` 133 | modemake.pl freqfile 0.5 134 | ``` 135 | 用于生成跑dimer所需要的MODECAR文件(VAPS需要与vtst tool一起编译),freqfile与之前的相同,0.5是系数,可以是负数,用于确定dimer的搜寻方向。正数则与freqfile中标识的振动方向相同,负数则相反。 136 | 137 | ---- 138 | 139 | #### moviecombine.pl 140 | 用法: 141 | ``` 142 | moviecombine.pl file1 file2 file3 ..... fileN output X Y Z 143 | ``` 144 | 用于把多个xdat2xyz.pl生成的movie.xyz文件拼接到一起,可在NEB计算中实现多个镜像点按顺序排列的动画,方便找出过渡态。file1 file2 ....是.xyz文件,output是输出文件,可以VMD打开。X、Y、Z是设置偏移量。 145 | 例如计算一个2*3*4的立方超胞,设置了3个images,计算完成后在三个image的文件夹中分别执行`xdat2xyz.pl XDATCAR`生成各自的`movie.xyz`,并重行命名为`file1.xyz file2.xyz file3.xyz`,在该文件夹中执行: 146 | ``` 147 | moviecombine.pl file1.xyz file2.xyz file3.xyz out.xyz 2.0 0.0 0.0 148 | ``` 149 | `file1.xyz`中的所有原子坐标不变; 150 | `file2.xyz`中的所有原子坐标将会加上(1\*X,1\*Y,1\*Z),即统一在X轴方向加2; 151 | `file3.xyz`中的所有原子坐标将会加上(2\*X,2\*Y,2\*Z),即统一在X轴方向加4; 152 | 最后生成的`out.xyz`文件中,3个images将按照X轴的方向进行排列。 153 | 154 | ---- 155 | 156 | #### nebinfo 157 | 用法: 158 | ``` 159 | nebinfo 160 | ``` 161 | 生成压缩包`NEBINFO.tar.gz`,其中包含三个文件夹`vaspfile`、`gvfile`、`movie` 162 | `vaspfile` 包含每个像点的POSCAR和CONTCAR文件; 163 | `gvfile` 包含每个像点的POSCAR和CONTCAR的gjf文件; 164 | `movie` 包含了动画文件,把每个像点从起始构型到最终构型的POSCAR和CONTACR分别做成动画,用于计算前的构型检查; 165 | 166 | ---- 167 | 168 | #### nebmake.pl 169 | 用法: 170 | ``` 171 | nebmake.pl initail_image final_image num_image 172 | ``` 173 | vtst tool中自带的镜像生成脚本,在此基础上做了一些修改。如果final_image是分数坐标,则生成的像点文件都是分数坐标;如果final_image是笛卡尔坐标,则生成的像点文件都是笛卡尔坐标; 174 | 175 | ---- 176 | 177 | #### nebmovie 178 | 用法: 179 | ``` 180 | nebmovie X Y Z 181 | ``` 182 | 把moviecombine.pl的繁琐操作合成为一个脚本。在含有POTCAR的文件夹中执行,将会进入到每一个像点文件夹生成movie.xyz,最后统一合成并压缩为一个名称movie.xyz的压缩包。 183 | 184 | ---- 185 | 186 | #### nebvtst.pl 187 | 用法: 188 | ``` 189 | nebvtst.pl num_images 190 | ``` 191 | 会抓取NEB计算中每一个离子步中每个像点的能量,切线力以及需要弛豫的原子中受力最大的一个原子受到的力(即该力小于EDIFFG时计算会终止),列表输出,类似于这样: 192 | ``` 193 | steps: 1 194 | images: 1 -151.68812 -0.27764 0.16389 195 | images: 2 -151.54168 -0.70352 0.25647 196 | images: 3 -151.28943 -0.85346 0.32021 197 | images: 4 -150.97526 -1.15730 0.53053 198 | 199 | steps: 2 200 | images: 1 -151.68918 -0.26855 0.16441 201 | images: 2 -151.54293 -0.70139 0.25001 202 | images: 3 -151.29082 -0.90557 0.39795 203 | images: 4 -150.97396 -1.11050 0.41420 204 | ``` 205 | 结果太多时可重定向到另一个文件保存: 206 | ``` 207 | nebvtst.pl num_images > info 208 | ``` 209 | 210 | ---- 211 | 212 | #### vas2cif.pl 213 | 用法: 214 | ``` 215 | vas2cif.pl file1 file2 ... 216 | ``` 217 | file是VASP的输入输出文件,坐标系不限。可转化为cif文件供materials studio打开。 218 | 219 | ---- 220 | 221 | #### vas2gv.pl 222 | 用法: 223 | ``` 224 | vas2gv.pl file1 file2 ... 225 | ``` 226 | file是VASP的输入输出文件,坐标系不限。可转化为gjf文件。 227 | 228 | ---- 229 | 230 | #### vas2xyz.pl 231 | 用法: 232 | ``` 233 | vas2xyz.pl file1 file2 ... 234 | ``` 235 | file是VASP的输入输出文件,坐标系不限。可转化为xyz文件。 236 | 237 | ---- 238 | 239 | #### xdat2xyz.pl 240 | 用法: 241 | ``` 242 | xdat2xyz.pl XDATCAR 243 | ``` 244 | vtst tool原生脚本,可以把XDATCAR转化为xyz文件。 245 | 246 | ---- 247 | 248 | #### g09_jobs.py 249 | 用法: 250 | 1. 在天河二号上直接使用命令`yhbatch -n cores g09_jobs.py`提交即可。 251 | 使用前需要自行修改脚本的14-17行: 252 | ``` 253 | wait_directory = '~/test-1' 254 | exec_directory = '~/test-2' 255 | max_cores = 24 256 | interval = 10 257 | ``` 258 | - `wait_directory`是放置gjf文件的文件夹,`exec_directory`是执行gjf文件的文件夹,`max_cores`是节点的cpu核心数量,`interval`是检查任务是否完成的时间间隔,单位是秒。 259 | - 脚本运行之后将会不断检查`wait_directory`文件夹中是否有gjf文件,如果有则将其移动到`exec_directory`文件夹中执行。脚本运行期间可不断往`wait_directory`文件夹中添加gjf文件。检查的时间间隔由`interval`来控制,该间隔不宜太短,以免影响性能,也不宜过长,以免机器空转,推荐10~30秒。 260 | - 每一个gjf文件执行前都会先根据关键字`nprocshared`来查找执行该gjf文件需要多少核心数,如果节点有足够的空闲核心数才会执行该文件。因此每个gjf文件都必须通过关键字`%nprocshared=cores`来设定所需要的cpu核心数,没有设定的文件将会被跳过。 261 | - 脚本运行过程中的一些关键信息会输出到`wait_directory`文件夹下的`output`文件中。 262 | - 如果要终止某个运行中的gjf文件,可以在`wait_directory`文件夹创建`STOP`文件,文件格式为: 263 | ``` 264 | xxx.gjf 265 | xxx.gjf 266 | xxx.gjf 267 | ``` 268 | 其中的gjf文件将会被终止运行,随后该`STOP`文件会被删除。因此最好在其它目录中编辑该`STOP`文件,然后将其拷贝到`wait_directory`文件夹中。 269 | - 尽量避免在`wait_directory`文件夹中编辑文件,以免脚本出现不必要的错误。如果需要编辑文件,最好把文件移动到其它文件夹中,编辑好之后再移动回来。如果脚本运行出错,则所有正在运行的任务都会被强行终止。 270 | -------------------------------------------------------------------------------- /Ru1sys.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #vas2xyz.pl ts.vasp 3 | in=$1 4 | out="$1.xyz" 5 | moviecombine.pl $in $in $in 12.xyz 13.529 0 0 6 | moviecombine.pl 12.xyz 12.xyz 12.xyz final.xyz 0 12.8448 0 7 | rm 12.xyz 8 | mv final.xyz $out 9 | -------------------------------------------------------------------------------- /Rusys.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #vas2xyz.pl ts.vasp 3 | moviecombine.pl $1 $2 12.xyz 9.9550820148943 0 0 4 | moviecombine.pl 12.xyz $2 123.xyz -9.9550820148943 0 0 5 | moviecombine.pl 123.xyz 123.xyz 123123.xyz -4.9775410074471500 8.6213539216560395 0 6 | moviecombine.pl 123123.xyz 123.xyz final.xyz 4.9775410074471500 -8.6213539216560395 0 7 | rm 12.xyz 123.xyz 123123.xyz 8 | mv final.xyz $1 9 | -------------------------------------------------------------------------------- /VASP.py: -------------------------------------------------------------------------------- 1 | import re 2 | import subprocess 3 | # 注意:所有函数读取的坐标统一为笛卡尔坐标 4 | 5 | 6 | class CmdRrror(Exception): 7 | def __init__(self, errorinfo): 8 | super().__init__(self) # 初始化父类 9 | self.errorinfo = errorinfo 10 | 11 | def __str__(self): 12 | return 'Command Execution Error: ' + self.errorinfo 13 | 14 | 15 | def execCmd(command): 16 | pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 17 | (content, error) = (pipe.stdout.readlines(), pipe.stderr.read().decode()) 18 | if content: 19 | for i in range(len(content)): 20 | content[i] = content[i].decode() 21 | return content 22 | 23 | if error != "": 24 | raise CmdRrror(error) 25 | 26 | 27 | # this function can only read file in VASP 5.0 or later 28 | def readVasp(file_name): 29 | """ 30 | :param file_name: 31 | :return: [lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective] 32 | lattice: scale, float 33 | basis: [x1, y1, z1], [x2, y2, z2], [x3, y3, z3]], float 34 | elements: [element1, element2, ...], str 35 | num_atoms: [number_of_element1, number_of_element2, ...], int 36 | selectiveflag: 'Selective dynamics' or '', str 37 | coordinate_type: 'Cartesian', str 38 | coordinates: [[x1, y1, z1], [x2, y2, z2], ...], float 39 | selective: [[T/F, T/F, T/F], [T/F, T/F, T/F], ...], str 40 | """ 41 | space = re.compile(r'\s+') 42 | with open(file_name) as input_file: 43 | content = input_file.readlines() 44 | 45 | lattice = float(content[1].strip()) 46 | 47 | basis = [] 48 | for i in range(2, 5): 49 | line = space.split(content[i].strip()) 50 | basis.append([float(line[0]), float(line[1]), float(line[2])]) 51 | 52 | elements = space.split(content[5].strip()) 53 | num_atoms = list(map(int, space.split(content[6].strip()))) 54 | 55 | if re.search(r'^[Ss]', content[7]) is None: 56 | selectiveflag = '' 57 | index = 7 58 | else: 59 | selectiveflag = content[7].strip() 60 | index = 8 61 | 62 | if re.search(r'^[Dd]', content[index]) is None: 63 | coordinate_type = 'Cartesian' 64 | else: 65 | coordinate_type = 'Direct' 66 | 67 | coordinates = [] 68 | selective = [] 69 | start = index + 1 70 | end = start + sum(num_atoms) 71 | if selectiveflag == '': 72 | for i in range(start, end): 73 | line = space.split(content[i].strip()) 74 | coordinates.append([float(line[0]), float(line[1]), float(line[2])]) 75 | else: 76 | for i in range(start, end): 77 | line = space.split(content[i].strip()) 78 | coordinates.append([float(line[0]), float(line[1]), float(line[2])]) 79 | if len(line) == 6: 80 | selective.append([line[3], line[4], line[5]]) 81 | else: 82 | selective.append(['', '', '']) 83 | 84 | if re.search(r'^[Cc]', coordinate_type) is None: 85 | coordinate_type = 'Cartesian' 86 | coordinates = dirkar(basis, coordinates) 87 | 88 | return lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective 89 | 90 | 91 | def writeVasp(file_name, lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective): 92 | """ 93 | :param file_name: str 94 | :param lattice: float 95 | :param basis: [x1, y1, z1], [x2, y2, z2], [x3, y3, z3]], float 96 | :param elements: element1, element2, element3], str 97 | :param num_atoms: [number_of_element1, number_of_element2, ...], int 98 | :param selectiveflag: 'Selective dynamics' or '', str 99 | :param coordinate_type: 'Cartesian' or 'Direct', str 100 | :param coordinates: [[x1, y1, z1], [x2, y2, z2], ...], float 101 | :param selective: [[T/F, T/F, T/F], [T/F, T/F, T/F], ...] or [], str 102 | :return: 103 | """ 104 | with open(file_name, 'w') as output_file: 105 | description = ' '.join(elements) 106 | output_file.write('%s\n' % description) 107 | output_file.write(" %15.10f\n" % lattice) 108 | for i in range(0, 3): 109 | output_file.write(" %15.10f %15.10f %15.10f\n" % (basis[i][0], basis[i][1], basis[i][2])) 110 | output_file.write(description.rstrip() + '\n') 111 | 112 | num_atom = ' '.join(list(map(str, num_atoms))) 113 | output_file.write('%s\n' % num_atom) 114 | 115 | if selectiveflag != '': 116 | output_file.write('%s\n' % selectiveflag) 117 | output_file.write('%s\n' % coordinate_type) 118 | 119 | if re.search(r'^[Dd]', coordinate_type): 120 | coordinates = kardir(basis, coordinates) 121 | 122 | # keeping dimension the same 123 | if len(coordinates) - len(selective) > 0: 124 | for i in range(len(selective), len(coordinates)): 125 | selective.append(['', '', '']) 126 | 127 | for i in range(0, len(coordinates)): 128 | output_file.write("%16.10f %16.10f %16.10f %s %s %s\n" % (coordinates[i][0], coordinates[i][1], coordinates[i][2], 129 | selective[i][0], selective[i][1], selective[i][2])) 130 | 131 | 132 | def readGjf(file_name): 133 | """ 134 | :param file_name: str 135 | :return: [elements, num_atoms, coordinates] 136 | elements: [element1, element2, ...], str 137 | num_atoms: [number_of_element1, number_of_element2, ...], int 138 | coordinates: [[x1, y1, z1], [x2, y2, z2], ...], float 139 | """ 140 | # 搜索自旋数值 141 | begin = re.compile(r'^[0-9]+\s+[0-9]+$') 142 | space = re.compile(r'\s+') 143 | 144 | with open(file_name) as input_file: 145 | content = input_file.readlines() 146 | index = 4 147 | # 找到自旋值之后下一行开始为原子坐标 148 | while index < len(content): 149 | if begin.search(content[index].strip()) is not None: 150 | index += 1 151 | break 152 | index += 1 153 | 154 | elements = [''] 155 | num_atoms = [] 156 | coordinates = [] 157 | 158 | while index < len(content): 159 | line = content[index].strip() 160 | if line == '': 161 | break 162 | 163 | # line: [元素符号, x, y, z] 164 | line = space.split(line) 165 | coordinates.append([float(line[1]), float(line[2]), float(line[3])]) 166 | if elements[-1] == line[0]: 167 | num_atoms[-1] += 1 168 | elif elements[-1] != line[0]: 169 | elements.append(line[0]) 170 | num_atoms.append(1) 171 | index += 1 172 | 173 | return elements[1:], num_atoms, coordinates 174 | 175 | 176 | def writeGjf(file_name, elements, num_atoms, coordinates): 177 | """ 178 | :param file_name: str 179 | :param elements: [element1, element2, ...], str 180 | :param num_atoms: [number_of_element1, number_of_element2, ...], int 181 | :param coordinates: [[x1, y1, z1], [x2, y2, z2], ...], float 182 | :return: 183 | """ 184 | with open(file_name, 'w') as output_file: 185 | output_file.write("# opt freq b3lyp/6-31g\n\n") 186 | output_file.write("creat from vasp file\n\n") 187 | output_file.write("0 1\n") 188 | total_index = 0 189 | for element_id, element in enumerate(elements): 190 | for element_index in range(num_atoms[element_id]): 191 | output_file.write("%2s %16.10f %16.10f %16.10f\n" % 192 | (element, coordinates[total_index][0], coordinates[total_index][1], 193 | coordinates[total_index][2])) 194 | total_index += 1 195 | 196 | output_file.write("\n\n") 197 | 198 | 199 | def readCell(file_name): 200 | """ 201 | 把Materials Studio生成的cell文件转换成vasp文件 202 | :param file_name: str 203 | :return: [basis, elements, num_atoms, coordinates] 204 | basis: [x1, y1, z1], [x2, y2, z2], [x3, y3, z3]], float 205 | elements: [element1, element2, ...], str 206 | num_atoms: [number_of_element1, number_of_element2, ...], int 207 | coordinates: [[x1, y1, z1], [x2, y2, z2], ...], float 208 | """ 209 | space = re.compile(r'\s+') 210 | with open(file_name, 'r') as cell_file: 211 | content = cell_file.readlines() 212 | 213 | basis = [] 214 | for i in range(1, 4): 215 | basis.append(list(map(float, space.split(content[i].strip())))) 216 | 217 | index = 7 218 | elements = [''] 219 | num_atoms = [] 220 | coordinates = [] 221 | 222 | while index < len(content): 223 | line = content[index].strip() 224 | if line.startswith('%'): 225 | break 226 | 227 | line = space.split(line) 228 | coordinates.append([float(line[1]), float(line[2]), float(line[3])]) 229 | if elements[-1] == line[0]: 230 | num_atoms[-1] += 1 231 | elif elements[-1] != line[0]: 232 | elements.append(line[0]) 233 | num_atoms.append(1) 234 | index += 1 235 | 236 | coordinate_type = 'Cartesian' 237 | coordinates = dirkar(basis, coordinates) 238 | 239 | return basis, elements[1:], num_atoms, coordinate_type, coordinates 240 | 241 | 242 | def readXYZ(file_name): 243 | """ 244 | :param file_name: str 245 | :return: [num_structures, elements, num_atoms, coordinates] 246 | num_structures: number of structures in xyz file, int 247 | elements: [element1, element2, ...], str 248 | num_atoms: [number_of_element1, number_of_element2, ...], int 249 | coordinates: [[x1, y1, z1], [x2, y2, z2], ...], float 250 | """ 251 | num_structures = 0 252 | elements = [''] 253 | num_atoms = [] 254 | coordinates = [] 255 | 256 | space = re.compile(r'\s+') 257 | 258 | with open(file_name, 'r') as xyz_file: 259 | content = xyz_file.readlines() 260 | 261 | total_atoms = int(content[0].strip()) 262 | index = 2 263 | while index < len(content): 264 | if content[index].strip() == '': 265 | break 266 | num_structures += 1 267 | max_line = index + total_atoms 268 | while index < max_line: 269 | line = space.split(content[index].strip()) 270 | coordinates.append([float(line[1]), float(line[2]), float(line[3])]) 271 | if num_structures == 1: 272 | if elements[-1] == line[0]: 273 | num_atoms[-1] += 1 274 | elif elements[-1] != line[0]: 275 | elements.append(line[0]) 276 | num_atoms.append(1) 277 | index += 1 278 | index += 2 279 | return num_structures, elements[1:], num_atoms, coordinates 280 | 281 | 282 | def writeXYZ(file_name, num_structures, elements, num_atoms, coordinates): 283 | """ 284 | :param num_structures: number of structures in xyz file, int 285 | :param elements: [element1, element2, ...], str 286 | :param num_atoms: [number_of_element1, number_of_element2, ...], int 287 | :param coordinates: [[x1, y1, z1], [x2, y2, z2], ...], float 288 | :return: 289 | """ 290 | total_atoms = sum(num_atoms) 291 | index = 0 292 | with open(file_name, 'w') as output_file: 293 | while num_structures != 0: 294 | output_file.write('%d\n' % total_atoms) 295 | output_file.write('create form python\n') 296 | for element_id, element in enumerate(elements): 297 | for element_index in range(num_atoms[element_id]): 298 | output_file.write("%2s %16.10f %16.10f %16.10f\n" % 299 | (element, coordinates[index][0], coordinates[index][1], 300 | coordinates[index][2])) 301 | index += 1 302 | num_structures -= 1 303 | 304 | 305 | def dirkar(basis, coordinates): 306 | for i in range(0, len(coordinates)): 307 | v1 = coordinates[i][0] * basis[0][0] + coordinates[i][1] * basis[1][0] + coordinates[i][2] * basis[2][0] 308 | v2 = coordinates[i][0] * basis[0][1] + coordinates[i][1] * basis[1][1] + coordinates[i][2] * basis[2][1] 309 | v3 = coordinates[i][0] * basis[0][2] + coordinates[i][1] * basis[1][2] + coordinates[i][2] * basis[2][2] 310 | coordinates[i][0] = v1 311 | coordinates[i][1] = v2 312 | coordinates[i][2] = v3 313 | return coordinates 314 | 315 | 316 | def kardir(basis, coordinates): 317 | inverse = [[basis[1][1]*basis[2][2]-basis[2][1]*basis[1][2], basis[2][1]*basis[0][2]-basis[0][1]*basis[2][2], basis[0][1]*basis[1][2]-basis[1][1]*basis[0][2]], 318 | [basis[2][0]*basis[1][2]-basis[1][0]*basis[2][2], basis[0][0]*basis[2][2]-basis[2][0]*basis[0][2], basis[1][0]*basis[0][2]-basis[0][0]*basis[1][2]], 319 | [basis[1][0]*basis[2][1]-basis[2][0]*basis[1][1], basis[2][0]*basis[0][1]-basis[0][0]*basis[2][1], basis[0][0]*basis[1][1]-basis[1][0]*basis[0][1]]] 320 | omega = basis[0][0]*basis[1][1]*basis[2][2] + basis[0][1]*basis[1][2]*basis[2][0] + basis[0][2]*basis[1][0]*basis[2][1] - \ 321 | basis[0][2]*basis[1][1]*basis[2][0] + basis[1][2]*basis[2][1]*basis[0][0] + basis[2][2]*basis[0][1]*basis[1][0] 322 | 323 | inverse = [[inverse[0][0]/omega, inverse[0][1]/omega, inverse[0][2]/omega], 324 | [inverse[1][0]/omega, inverse[1][1]/omega, inverse[1][2]/omega], 325 | [inverse[2][0]/omega, inverse[2][1]/omega, inverse[2][2]/omega]] 326 | 327 | for i in range(0, len(coordinates)): 328 | v1 = coordinates[i][0] * inverse[0][0] + coordinates[i][1] * inverse[1][0] + coordinates[i][2] * inverse[2][0] 329 | v2 = coordinates[i][0] * inverse[0][1] + coordinates[i][1] * inverse[1][1] + coordinates[i][2] * inverse[2][1] 330 | v3 = coordinates[i][0] * inverse[0][2] + coordinates[i][1] * inverse[1][2] + coordinates[i][2] * inverse[2][2] 331 | 332 | # move atoms to primative cell 333 | coordinates[i][0] = v1 + 60 - int(v1 + 60) 334 | coordinates[i][1] = v2 + 60 - int(v2 + 60) 335 | coordinates[i][2] = v3 + 60 - int(v3 + 60) 336 | return coordinates 337 | -------------------------------------------------------------------------------- /Vasp.pm: -------------------------------------------------------------------------------- 1 | # VTSTSCRIPTS version V2.04 (07/07/11) 2 | # v2.1 by sky, adjust write_poscar function to put out cartesian coordination 3 | # v2.2 by sky, add a function to convert direct into cartesian 4 | #I can't promise correct result if $lattice!=1.0 5 | 6 | package Vasp; 7 | use strict; 8 | use Math::Trig; 9 | 10 | BEGIN { 11 | use Exporter(); 12 | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); 13 | 14 | $VERSION = 1.00; 15 | 16 | @ISA = qw(Exporter); 17 | #add 18 | @EXPORT = qw(&read_poscar &write_poscar &write_carposcar &rotate_basis &read_othercar &write_othercar &dot_product 19 | &magnitude &pbc_difference &vsum &vmult &dirkar &kardir &volume &inverse 20 | &set_bc &bbc &pbc &gauss &unit); 21 | @EXPORT_OK = qw(); 22 | } 23 | 24 | use vars @EXPORT_OK; 25 | #add 26 | use vars qw($coordinationflag); 27 | 28 | #---------------------------------------------------------------------- 29 | # subroutine read_poscar 30 | # This routine reads in a POSCAR file. 31 | # 32 | # INPUT: $filename: name of POSCAR file to read 33 | # 34 | # OUTPUT: $coordinates: reference to Nx3 array of coordinates of 35 | # POSCAR 36 | # $basis: reference to 3x3 array of basis vectors 37 | # $lattice: lattice constant of POSCAR 38 | # $num_atoms: reference to Mx1 array of number atoms/component 39 | # $total_atoms: N 40 | # $selectiveflag: is selective dynamics turned on? 41 | # $selective: flags for selective dynamics for each atom 42 | # (reference to Nx1 array) 43 | # add:coordinationflag: direct or cartesian 44 | #---------------------------------------------------------------------- 45 | 46 | sub read_poscar { 47 | my $filename = shift; 48 | my $description = ""; 49 | my @poscar = (); 50 | my $lattice = 0; 51 | my $basis; 52 | my $num_atoms; 53 | my $total_atoms = 0; 54 | my $coordinates; 55 | my $selectiveflag = ""; 56 | my $atomtypeflag = ""; 57 | my $selective; 58 | my $filetype; 59 | my $num_atoms_ = ""; 60 | my @num_atoms = (); 61 | my $line = ""; 62 | my @line = (); 63 | my $i = 0; 64 | my $j = 0; 65 | my $index; 66 | my $coords_kar; 67 | 68 | open (IN,$filename) or die "In vasp.pm::read_poscar, cannot open $filename\n"; 69 | @poscar = ; 70 | close (IN); 71 | 72 | chop($description = $poscar[0]); 73 | chop($lattice = $poscar[1]); 74 | 75 | $line = $poscar[5]; 76 | $line =~ s/^\s+//; 77 | @line = split(/\s+/,$line); 78 | # if ($line =~ /^s/i) { 79 | if ($line[0] =~ /^\d+$/) { 80 | $filetype = "vasp4"; 81 | $index = 5; 82 | } else { 83 | $filetype = "vasp5"; 84 | $atomtypeflag = 1; 85 | chop($description = $poscar[5]); 86 | $index = 6; 87 | } 88 | $description =~ s/^\s+//; 89 | 90 | $num_atoms_ = $poscar[$index]; 91 | $num_atoms_ =~ s/^\s+//; 92 | @num_atoms = split(/\s+/,$num_atoms_); 93 | for ($i=0; $i<@num_atoms; $i++) { 94 | $num_atoms->[$i] = $num_atoms[$i]; 95 | $total_atoms += $num_atoms[$i]; 96 | } 97 | 98 | for ($i=0; $i<3; $i++) { 99 | $line = $poscar[$i+2]; 100 | $line =~ s/^\s+//; 101 | @line = split(/\s+/,$line); 102 | # This is how Vasp reads in the basis 103 | for ($j=0; $j<3; $j++) { 104 | $basis->[$j][$i] = $line[$j]*$lattice; 105 | } 106 | } 107 | $index += 1; 108 | 109 | $line = $poscar[$index]; 110 | $line =~ s/^\s+//; 111 | if ($line =~ /^s/i) { 112 | chop($selectiveflag = $line); 113 | $index += 2; 114 | } else { $index += 1; } 115 | 116 | for ($i=$index; $i<$index+$total_atoms; $i++) { 117 | $poscar[$i] =~ s/^\s+//; 118 | @line = split(/\s+/,$poscar[$i]); 119 | for ($j=0; $j<3; $j++) { 120 | $coordinates->[$i-$index][$j] = $line[$j]; } 121 | if ($selectiveflag=~/^s/i) { 122 | $selective->[$i-$index] = $line[3]." ".$line[4]." ".$line[5]; 123 | } else { 124 | $selective->[$i-$index] = " "; } 125 | } 126 | 127 | if ($poscar[$index-1] =~ /^c/i) { 128 | for ($i=0; $i<$total_atoms; $i++) { 129 | for ($j=0; $j<3; $j++) { 130 | $coordinates->[$i][$j] *= $lattice; 131 | } 132 | } 133 | $coordinates = kardir($coordinates,$basis,$lattice,$total_atoms); 134 | } 135 | 136 | #add 137 | chop($coordinationflag = $poscar[$index-1]); 138 | #$basis=rotate_basis($basis); # this ensures that there is a smooth conversion back from con format 139 | return($coordinates,$basis,$lattice,$num_atoms,$total_atoms,$selectiveflag,$selective,$description,$filetype,$coordinationflag); 140 | } 141 | 142 | #---------------------------------------------------------------------- 143 | # subroutine write_poscar 144 | # This routine writes out the POSCAR file in direct coordinates 145 | # 146 | # INPUT: $coordinates: reference to Nx3 array 147 | # $basis: reference to 3x3 array containing basis vectors 148 | # $lattice: lattice constant of POSCAR 149 | # $num_atoms: reference to Mx1 array containing number of 150 | # each component of atoms 151 | # $total_atoms: N 152 | # $selectiveflag: flag saying if selective dynamics were 153 | # used for this POSCAR 154 | # $selective: reference to Nx1 array containing selective 155 | # dynamics flags for each atom 156 | # 157 | # OUTPUT: none 158 | #---------------------------------------------------------------------- 159 | 160 | sub write_poscar { 161 | my $coordinates = shift; 162 | my $basis = shift; 163 | my $lattice = shift; 164 | my $num_atoms = shift; 165 | my $total_atoms = shift; 166 | my $selectiveflag = shift; 167 | my $selective = shift; 168 | my $description = shift; 169 | my $filename = shift; 170 | my $filetype = shift; 171 | my $i = 0; 172 | my $j = 0; 173 | my $coord; 174 | 175 | open (OUT,">$filename") or die "In vasp.pm::write_poscar, cannot open $filename\n"; 176 | print OUT $description."\n"; 177 | print OUT $lattice."\n"; 178 | for ($i=0; $i<3; $i++) { 179 | for ($j=0; $j<3; $j++) { 180 | printf OUT "%21.16f", ($basis->[$j][$i]/$lattice)." "; 181 | } 182 | print OUT "\n"; 183 | } 184 | # this right now sets default as vasp5 file type 185 | #if ($filetype eq "vasp5") { 186 | if ($filetype ne "vasp4") { 187 | print OUT $description."\n"; 188 | } 189 | for ($i=0; $i<@{$num_atoms}; $i++) { 190 | print OUT $num_atoms->[$i]." "; 191 | } 192 | print OUT "\n"; 193 | 194 | if ($selectiveflag =~ /^s/i) { 195 | print OUT $selectiveflag."\n"; 196 | } 197 | #add 198 | if ($coordinationflag =~ /^c/i){ 199 | print OUT "Cartesian\n"; 200 | for ($i=0; $i<$total_atoms; $i++) { 201 | for ($j=0; $j<3; $j++) { 202 | $coord->[$i][$j] = $coordinates->[$i][$j]; 203 | if ($coord->[$i][$j]>1) { $coord->[$i][$j] -= 1; } 204 | elsif ($coord->[$i][$j]<0) { $coord->[$i][$j] += 1; } 205 | } 206 | } 207 | $coord = dirkar($coord,$basis,$lattice,$total_atoms); 208 | for ($i=0; $i<$total_atoms; $i++) { 209 | for ($j=0; $j<3; $j++) { 210 | printf OUT "%20.16f", $coord->[$i][$j]." "; 211 | } 212 | print OUT " ".$selective->[$i]."\n"; 213 | } 214 | }else{ 215 | print OUT "Direct\n"; 216 | for ($i=0; $i<$total_atoms; $i++) { 217 | for ($j=0; $j<3; $j++) { 218 | $coord = $coordinates->[$i][$j]; 219 | if ($coord>1) { $coord -= 1; } 220 | elsif ($coord<0) { $coord += 1; } 221 | printf OUT "%20.16f", $coord." "; 222 | } 223 | print OUT " ".$selective->[$i]."\n"; 224 | } 225 | } 226 | close (OUT); 227 | return(); 228 | } 229 | 230 | #---------------------------------------------------------------------- 231 | # subroutine write_carposcar 232 | # the same as write_carposcar except outputing cartesian 233 | #---------------------------------------------------------------------- 234 | 235 | sub write_carposcar { 236 | my $coordinates = shift; 237 | my $basis = shift; 238 | my $lattice = shift; 239 | my $num_atoms = shift; 240 | my $total_atoms = shift; 241 | my $selectiveflag = shift; 242 | my $selective = shift; 243 | my $description = shift; 244 | my $filename = shift; 245 | my $filetype = shift; 246 | my $i = 0; 247 | my $j = 0; 248 | my $coord; 249 | 250 | open (OUT,">$filename") or die "In vasp.pm::write_poscar, cannot open $filename\n"; 251 | print OUT $description."\n"; 252 | print OUT $lattice."\n"; 253 | for ($i=0; $i<3; $i++) { 254 | for ($j=0; $j<3; $j++) { 255 | printf OUT "%21.16f", ($basis->[$j][$i]/$lattice)." "; 256 | } 257 | print OUT "\n"; 258 | } 259 | # this right now sets default as vasp5 file type 260 | #if ($filetype eq "vasp5") { 261 | if ($filetype ne "vasp4") { 262 | print OUT $description."\n"; 263 | } 264 | for ($i=0; $i<@{$num_atoms}; $i++) { 265 | print OUT $num_atoms->[$i]." "; 266 | } 267 | print OUT "\n"; 268 | 269 | if ($selectiveflag =~ /selective/i) { 270 | print OUT $selectiveflag."\n"; 271 | } 272 | 273 | print OUT "Cartesian\n"; 274 | for ($i=0; $i<$total_atoms; $i++) { 275 | for ($j=0; $j<3; $j++) { 276 | $coord->[$i][$j] = $coordinates->[$i][$j]; 277 | if ($coord->[$i][$j]>1) { $coord->[$i][$j] -= 1; } 278 | elsif ($coord->[$i][$j]<0) { $coord->[$i][$j] += 1; } 279 | } 280 | } 281 | $coord = dirkar($coord,$basis,$lattice,$total_atoms); 282 | for ($i=0; $i<$total_atoms; $i++) { 283 | for ($j=0; $j<3; $j++) { 284 | printf OUT "%20.16f", $coord->[$i][$j]." "; 285 | } 286 | print OUT " ".$selective->[$i]."\n"; 287 | } 288 | close (OUT); 289 | return(); 290 | } 291 | 292 | 293 | #---------------------------------------------------------------------- 294 | # subroutine rotate_basis 295 | # subroutine that rotates basis vectors so that v1->xdir and v2->xy plane 296 | # this is important for smooth conversions between con and POSCAR formats 297 | # INPUT: $basis: reference to 3x3 array containing basis vectors 298 | # 299 | # OUTPUT: $basis 300 | #---------------------------------------------------------------------- 301 | sub rotate_basis { 302 | my $basis = shift; 303 | my $a; 304 | my $b; 305 | my $angle; 306 | my $i = 0; 307 | if ($basis->[1][0] != 0.) { # rotate around Z 308 | $angle = acos($basis->[0][0]/sqrt($basis->[0][0]**2+$basis->[1][0]**2)); 309 | if ($basis->[1][0]<0) { $angle *= -1; } 310 | #print "angle ",$angle,"\n"; 311 | for ($i=0; $i<3; $i++) { 312 | $a = $basis->[0][$i]; 313 | $b = $basis->[1][$i]; 314 | $basis->[0][$i] = $a*cos($angle) + $b*sin($angle); 315 | $basis->[1][$i] = -$a*sin($angle) + $b*cos($angle); 316 | } 317 | } 318 | if ($basis->[2][0] != 0.) { # rotate around Y 319 | $angle = acos($basis->[0][0]/sqrt($basis->[0][0]**2 + $basis->[2][0]**2)); 320 | if ($basis->[2][0]<0) { $angle *= -1; } 321 | #print "angle ",$angle,"\n"; 322 | for ($i=0; $i<3; $i++) { 323 | $a = $basis->[0][$i]; 324 | $b = $basis->[2][$i]; 325 | $basis->[0][$i] = $a*cos($angle) + $b*sin($angle); 326 | $basis->[2][$i] = -$a*sin($angle) + $b*cos($angle); 327 | } 328 | } 329 | if ($basis->[2][1] != 0.) { # rotate around X 330 | $angle = acos($basis->[1][1]/sqrt($basis->[1][1]**2 + $basis->[2][1]**2)); 331 | if ($basis->[2][1]<0) { $angle *= -1; } 332 | #print "angle ",$angle,"\n"; 333 | for ($i=0; $i<3; $i++) { 334 | $a = $basis->[1][$i]; 335 | $b = $basis->[2][$i]; 336 | $basis->[1][$i] = $a*cos($angle)+$b*sin($angle); 337 | $basis->[2][$i] = -$a*sin($angle)+$b*cos($angle); 338 | } 339 | } 340 | $basis->[1][0] = 0; # No need to carry floating point errors 341 | $basis->[2][0] = 0; 342 | $basis->[2][1] = 0; 343 | return($basis); 344 | } 345 | #---------------------------------------------------------------------- 346 | # subroutine read_othercar 347 | # This routine reads files that are just an Nx3 array of numbers 348 | # (like INTERCAR and NORMCAR, for example). 349 | # 350 | # INPUT: $filename: name of file to read 351 | # 352 | # OUTPUT: $coordinates: reference to Nx3 array 353 | # $total_atoms: N 354 | #---------------------------------------------------------------------- 355 | 356 | sub read_othercar { 357 | my $filename = shift; 358 | my @othercar = (); 359 | my $total_atoms = 0; 360 | my $coordinates; 361 | my $line = ""; 362 | my @line = (); 363 | my $i = 0; 364 | my $j = 0; 365 | 366 | open (IN,$filename) or die "In vasp.pm::read_othercar, cannot open $filename\n"; 367 | while ($line = ) { 368 | $line =~ s/^\s+//g; 369 | @line = split(/\s+/,$line); 370 | # check to see if the first entry is a number 371 | # if($line[0] =~ /^\d+\.*\d*$/){ 372 | if($line[0] =~ /^[-+]?\d+(\.\d+)?([eE][-+]?\d+)?$/) { 373 | for ($j=0; $j<3; $j++) { 374 | $coordinates->[$i][$j] = $line[$j]; 375 | } 376 | $i++; 377 | } 378 | } 379 | close (IN); 380 | $total_atoms = $i; 381 | 382 | return($coordinates,$total_atoms); 383 | } 384 | 385 | #---------------------------------------------------------------------- 386 | # subroutine write_othercar 387 | # This routine writes an Nx3 array of numbers to a file 388 | # (like INTERCAR and NORMCAR, for example). 389 | # 390 | # INPUT: $coordinates: reference to Nx3 array 391 | # $total_atoms: N 392 | #---------------------------------------------------------------------- 393 | 394 | sub write_othercar{ 395 | my $coordinates = shift; 396 | my $total_atoms = shift; 397 | my $filename = shift; 398 | my ($i,$j,$coord); 399 | open (OUT,">$filename") || die "In Vasp.pm::write_othercar : cannot open $filename\n"; 400 | for ($i=0; $i<$total_atoms; $i++) { 401 | for ($j=0; $j<3; $j++) { 402 | $coord = $coordinates->[$i][$j]; 403 | printf OUT "%20.16f", $coord." "; 404 | } 405 | print OUT "\n"; 406 | } 407 | close (OUT); 408 | } 409 | 410 | #---------------------------------------------------------------------- 411 | # subroutine dot_product 412 | # This routine does a dot product between two arrays. 413 | # 414 | # INPUT: $coordinates1: reference to Nx3 array 415 | # $coordinates2: reference to Nx3 array 416 | # $total_atoms: N 417 | # 418 | # OUTPUT: $mag: dot product between $coordinates1 and $coordinates2 419 | #---------------------------------------------------------------------- 420 | 421 | sub dot_product { 422 | my $coordinates1 = shift; 423 | my $coordinates2 = shift; 424 | my $total_atoms = shift; 425 | 426 | my ($i,$j); 427 | my $mag = 0; 428 | 429 | for ($i=0; $i<$total_atoms; $i++) { 430 | for ($j=0; $j<3; $j++) { 431 | $mag += $coordinates1->[$i][$j]*$coordinates2->[$i][$j]; 432 | } 433 | } 434 | return ($mag); 435 | } 436 | 437 | #---------------------------------------------------------------------- 438 | # subroutine magnitude 439 | # This routine calculates the magnitude of a vector 440 | # 441 | # INPUT: $coordinates: reference to Nx3 array 442 | # $total_atoms: N 443 | # 444 | # OUTPUT: $mag: magnitude of $coordinates 445 | #---------------------------------------------------------------------- 446 | 447 | sub magnitude { 448 | my $coordinates = shift; 449 | my $total_atoms = shift; 450 | 451 | my ($i,$j); 452 | my $mag = 0; 453 | 454 | for ($i=0; $i<$total_atoms; $i++) { 455 | for ($j=0; $j<3; $j++) { 456 | $mag += $coordinates->[$i][$j]**2; 457 | } 458 | } 459 | $mag = sqrt($mag); 460 | return ($mag); 461 | } 462 | 463 | #---------------------------------------------------------------------- 464 | # subroutine pbc_difference 465 | # This routine does a difference between two vectors and applies 466 | # periodic boundary conditions to the difference. 467 | # 468 | # INPUT: $coordinates1: reference to Nx3 array 469 | # $coordinates2: reference to Nx3 array 470 | # $total_atoms: N 471 | # 472 | # OUTPUT: $difference: difference between $coordinates1 and $coordinates2 473 | #---------------------------------------------------------------------- 474 | 475 | sub pbc_difference { 476 | my $coordinates1 = shift; 477 | my $coordinates2 = shift; 478 | my $total_atoms = shift; 479 | 480 | my $i = 0; 481 | my $j = 0; 482 | my $difference; 483 | 484 | for ($i=0; $i<$total_atoms; $i++) { 485 | for ($j=0; $j<3; $j++) { 486 | $difference->[$i][$j] = pbc($coordinates1->[$i][$j] - $coordinates2->[$i][$j]); 487 | } 488 | } 489 | return ($difference); 490 | } 491 | 492 | #---------------------------------------------------------------------- 493 | # subroutine unit 494 | # This routine returns the unit vector of the given vector 495 | # 496 | # INPUT: $coordinates: reference to Nx3 array 497 | # $total_atoms: N 498 | # 499 | # OUTPUT: $unitv: unit vector of $coordinates 500 | #---------------------------------------------------------------------- 501 | 502 | sub unit 503 | { 504 | my $coordinates = shift; 505 | my $total_atoms = shift; 506 | 507 | my $i = 0; 508 | my $j = 0; 509 | my $unitv; 510 | my $sum = 0; 511 | 512 | for ($i=0; $i<$total_atoms; $i++) { 513 | for ($j=0; $j<3; $j++) { 514 | $sum += $coordinates->[$i][$j] * $coordinates->[$i][$j]; 515 | $unitv->[$i][$j] = $coordinates->[$i][$j]; 516 | } 517 | } 518 | my $mag = sqrt($sum); 519 | for ($i=0; $i<$total_atoms; $i++) 520 | { 521 | for ($j=0; $j<3; $j++) 522 | { 523 | $unitv->[$i][$j] = $unitv->[$i][$j] / $mag; 524 | } 525 | } 526 | return ($unitv); 527 | } 528 | 529 | #---------------------------------------------------------------------- 530 | # subroutine vsum 531 | # This routine adds two vectors 532 | # 533 | # INPUT: $v1: reference to array containing coordinates (Nx3) 534 | # $v2: reference to array containing coordinates (Nx3) 535 | # $total_atoms: N 536 | # 537 | # OUTPUT: $vector: summed vectors 538 | #---------------------------------------------------------------------- 539 | 540 | sub vsum { 541 | my $v1 = shift; 542 | my $v2 = shift; 543 | my $total_atoms = shift; 544 | 545 | my ($i,$j,$vector); 546 | for ($i=0; $i<$total_atoms; $i++) { 547 | for ($j=0; $j<3; $j++) { 548 | $vector->[$i][$j] = $v1->[$i][$j] + $v2->[$i][$j]; 549 | } 550 | } 551 | return ($vector); 552 | } 553 | 554 | #---------------------------------------------------------------------- 555 | # subroutine vmult 556 | # This routine multiplies a number with a vector 557 | # 558 | # INPUT: $v: reference to array containing coordinates (Nx3) 559 | # $fact: multiplication factor 560 | # $total_atoms: N 561 | # 562 | # OUTPUT: $vector: summed vectors 563 | #---------------------------------------------------------------------- 564 | 565 | sub vmult { 566 | my $v = shift; 567 | my $fact = shift; 568 | my $total_atoms = shift; 569 | 570 | my ($i,$j,$vector); 571 | for ($i=0; $i<$total_atoms; $i++) { 572 | for ($j=0; $j<3; $j++) { 573 | $vector->[$i][$j] = $v->[$i][$j]*$fact; 574 | } 575 | } 576 | return ($vector); 577 | } 578 | #---------------------------------------------------------------------- 579 | # subroutine dirkar 580 | # This routine converts coordinates from direct lattice to 581 | # cartesian. NOTE: OUTPUT is in full cartesian, not scaled 582 | # cartesian. 583 | # 584 | # INPUT: $vector: reference to array containing coordinates (Nx3) 585 | # $basis: reference to 3x3 array containing basis 586 | # $lattice: lattice constant of coordinates 587 | # $total_atoms: N 588 | # 589 | # OUTPUT: $vector: converted coordinates 590 | #---------------------------------------------------------------------- 591 | 592 | sub dirkar { 593 | my $vector = shift; 594 | my $basis = shift; 595 | my $lattice = shift; 596 | my $total_atoms = shift; 597 | 598 | my ($i,$v1,$v2,$v3); 599 | 600 | for ($i=0; $i<$total_atoms; $i++) { 601 | $v1 = $vector->[$i][0]*$basis->[0][0] + $vector->[$i][1]*$basis->[0][1] + $vector->[$i][2]*$basis->[0][2]; 602 | $v2 = $vector->[$i][0]*$basis->[1][0] + $vector->[$i][1]*$basis->[1][1] + $vector->[$i][2]*$basis->[1][2]; 603 | $v3 = $vector->[$i][0]*$basis->[2][0] + $vector->[$i][1]*$basis->[2][1] + $vector->[$i][2]*$basis->[2][2]; 604 | $vector->[$i][0] = $v1; 605 | $vector->[$i][1] = $v2; 606 | $vector->[$i][2] = $v3; 607 | } 608 | 609 | return ($vector); 610 | } 611 | 612 | #---------------------------------------------------------------------- 613 | # subroutine kardir 614 | # This routine converts coordinates from cartesian to 615 | # direct lattice. NOTE: INPUT should be in full cartesian, not 616 | # scaled cartesian, coordinates. 617 | # 618 | # INPUT: $vector: reference to array containing coordinates (Nx3) 619 | # $basis: reference to 3x3 array containing basis 620 | # $lattice: lattice constant of coordinates 621 | # $total_atoms: N 622 | # 623 | # OUTPUT: $vector: converted coordinates 624 | #---------------------------------------------------------------------- 625 | 626 | sub kardir { 627 | my $vector = shift; 628 | my $basis = shift; 629 | my $lattice = shift; 630 | my $total_atoms = shift; 631 | my $recip_basis; 632 | my ($v1,$v2,$v3,$i,$j); 633 | 634 | $recip_basis = inverse($basis); 635 | 636 | for ($i=0; $i<$total_atoms; $i++) { 637 | $v1 = $vector->[$i][0]*$recip_basis->[0][0] + $vector->[$i][1]*$recip_basis->[1][0] + $vector->[$i][2]*$recip_basis->[2][0]; 638 | $v2 = $vector->[$i][0]*$recip_basis->[0][1] + $vector->[$i][1]*$recip_basis->[1][1] + $vector->[$i][2]*$recip_basis->[2][1]; 639 | $v3 = $vector->[$i][0]*$recip_basis->[0][2] + $vector->[$i][1]*$recip_basis->[1][2] + $vector->[$i][2]*$recip_basis->[2][2]; 640 | 641 | # move atoms to primative cell 642 | $vector->[$i][0] = $v1+60-int($v1+60); 643 | $vector->[$i][1] = $v2+60-int($v2+60); 644 | $vector->[$i][2] = $v3+60-int($v3+60); 645 | } 646 | for ($i=0;$i<3;$i++) { 647 | for ($j=0;$j<3;$j++) { 648 | # print $basis->[$i][$j]." "; 649 | } 650 | # print " .... "; 651 | for ($j=0;$j<3;$j++) { 652 | # print $recip_basis->[$i][$j]." "; 653 | } 654 | # print "\n"; 655 | } 656 | return ($vector); 657 | } 658 | 659 | #---------------------------------------------------------------------- 660 | # subroutine volume 661 | # This subroutine returns the volume of the basis 662 | # 663 | # INPUT: $basis: reference to 3x3 basis array 664 | # 665 | # OUTPUT: $volume: volume of basis vectors 666 | #---------------------------------------------------------------------- 667 | 668 | sub volume { 669 | my $basis = shift; 670 | 671 | my $volume; 672 | 673 | $volume = 674 | $basis->[0][0]*($basis->[1][1]*$basis->[2][2] - $basis->[1][2]*$basis->[2][1]) - 675 | $basis->[0][1]*($basis->[1][0]*$basis->[2][2] - $basis->[2][0]*$basis->[1][2]) + 676 | $basis->[0][2]*($basis->[1][0]*$basis->[2][1] - $basis->[2][0]*$basis->[1][1]); 677 | 678 | return($volume) 679 | } 680 | 681 | #---------------------------------------------------------------------- 682 | # subroutine inverse 683 | # This subroutine inverts the basis, so that a conversion from 684 | # cartesian to direct coordinates can be done. 685 | # 686 | # INPUT: $basis: reference to 3x3 basis array 687 | # 688 | # OUTPUT: $inverse: reference to 3x3 inverse of basis 689 | #---------------------------------------------------------------------- 690 | 691 | sub inverse { 692 | my $basis = shift; 693 | 694 | my $inverse; 695 | 696 | my $omega = 0; 697 | my ($i,$ii,$iii,$j,$jj,$jjj); 698 | 699 | for ($i=0; $i<3; $i++) { 700 | $ii = $i+1; 701 | if ($ii>2) { $ii-=3; } 702 | $iii = $ii+1; 703 | if ($iii>2) { $iii-=3; } 704 | for ($j=0;$j<3;$j++) { 705 | $jj = $j+1; 706 | if ($jj>2) { $jj-=3; } 707 | $jjj = $jj + 1; 708 | if ($jjj>2) { $jjj-=3; } 709 | $inverse->[$j][$i] = $basis->[$jj][$ii]*$basis->[$jjj][$iii] - $basis->[$jjj][$ii]*$basis->[$jj][$iii]; 710 | # print "$i $ii $iii $j $jj $jjj: ".$inverse->[$j][$i]."\n"; 711 | } 712 | } 713 | 714 | $omega = $inverse->[0][0]*$basis->[0][0] + $inverse->[1][0]*$basis->[1][0] + $inverse->[2][0]*$basis->[2][0]; 715 | 716 | for ($i=0; $i<3; $i++) { 717 | for ($j=0; $j<3; $j++) { 718 | $inverse->[$i][$j] /= $omega; 719 | } 720 | } 721 | 722 | return($inverse); 723 | } 724 | 725 | #---------------------------------------------------------------------- 726 | # subroutine set_bc 727 | # This routine applies boundary conditions (bc) 728 | # 729 | # INPUT: $coordinates: coordinate to apply bc to, in direct lattice 730 | # $total_atoms: total number of atoms 731 | # 732 | # OUTPUT: $coordinates: coordinate with bc applied 733 | #---------------------------------------------------------------------- 734 | 735 | sub set_bc { 736 | my $coordinates = shift; 737 | my $total_atoms = shift; 738 | 739 | my($i,$j); 740 | 741 | # Boundaries [0,1] 742 | if($ENV{'VTST_BC'} eq 'BBC') { 743 | for($i=0; $i<$total_atoms; $i++){ 744 | for($j=0; $j<3; $j++){ 745 | $coordinates->[$i][$j] = bbc($coordinates->[$i][$j]); }} 746 | # Boundaries [-0.5,0.5] 747 | } elsif($ENV{'VTST_BC'} eq 'PBC') { 748 | for($i=0; $i<$total_atoms; $i++){ 749 | for($j=0; $j<3; $j++){ 750 | $coordinates->[$i][$j] = pbc($coordinates->[$i][$j]); }} 751 | # Boundaries [1-x,x] 752 | } elsif($ENV{'VTST_BC'} eq 'CBC') { 753 | for($i=0; $i<$total_atoms; $i++){ 754 | for($j=0; $j<3; $j++){ 755 | $coordinates->[$i][$j] = cbc($coordinates->[$i][$j]); }} 756 | } 757 | } 758 | 759 | #---------------------------------------------------------------------- 760 | # subroutine pbc 761 | # This routine applies periodic boundary conditions to a direct 762 | # lattice coordinate. 763 | # 764 | # INPUT: $distance: coordinate to apply PBC to, in direct lattice 765 | # 766 | # OUTPUT: $distance: coordinate with PBC applied 767 | #---------------------------------------------------------------------- 768 | 769 | sub pbc { 770 | my $distance = shift; 771 | 772 | #GH: this should be changed to a Wigner-Sitz algorithm 773 | if ($distance <= -0.5) { 774 | $distance += 1.0; 775 | } elsif ($distance > 0.5) { 776 | $distance -= 1.0; 777 | } 778 | return($distance); 779 | } 780 | 781 | #---------------------------------------------------------------------- 782 | # subroutine bbc 783 | # This routine applies box boundary conditions to a direct 784 | # lattice coordinate. 785 | # 786 | # INPUT: $distance: coordinate to apply BBC to, in direct lattice 787 | # 788 | # OUTPUT: $distance: coordinate with BBC applied 789 | #---------------------------------------------------------------------- 790 | 791 | sub bbc { 792 | my $distance=shift; 793 | 794 | while($distance <= 0.0) { 795 | $distance += 1.0; } 796 | while($distance > 1.0) { 797 | $distance -= 1.0; } 798 | return($distance); 799 | } 800 | 801 | #---------------------------------------------------------------------- 802 | # subroutine gauss 803 | # This routine generates a Gaussian distributed random number 804 | # Algorithm from Numeric Recipes (mean 0, width 1) 805 | # 806 | # OUTPUT: $gset: Gaussian distributed random number 807 | #---------------------------------------------------------------------- 808 | { 809 | my $gset; 810 | my $iset = 0; 811 | 812 | srand(); 813 | 814 | sub gauss { 815 | my ($v1,$v2,$rsq,$fac); 816 | if ($iset == 0){ 817 | do{ 818 | $v1 = 2.0*rand() - 1.0; 819 | $v2 = 2.0*rand() - 1.0; 820 | $rsq = $v1*$v1 + $v2*$v2; 821 | } while ($rsq >= 1.0 || $rsq == 0.0); 822 | $fac = sqrt(-2.0*log($rsq)/$rsq); 823 | $gset = $v1*$fac; 824 | $iset = 1; 825 | return $v2*$fac; 826 | } else { 827 | $iset = 0; 828 | return $gset; 829 | } 830 | } 831 | } 832 | 833 | 1; 834 | -------------------------------------------------------------------------------- /WorkDir.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | yhqueue 4 | echo "" 5 | 6 | for j in `yhqueue| sed '1d'| awk '{print $1}'` 7 | do 8 | mydir=`yhcontrol show jobs $j| grep "WorkDir"` 9 | echo " $j $mydir" 10 | done 11 | -------------------------------------------------------------------------------- /add_c.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #Usage: add_c.sh (gjf file) (three coordinate) (one H that you want delete) 3 | name=${1/%gjf/tmp} 4 | cp $1 $name 5 | if [ ! -e POSCAR.bak ];then 6 | cp POSCAR POSCAR.bak 7 | fi 8 | 9 | sed -i '1,5d' $name 10 | sed -n "$2p" $name >c_coor 11 | sed -n "$3p" $name >>c_coor 12 | sed -n "$4p" $name >>c_coor 13 | sed -i "$5d" $name 14 | 15 | cat c_coor ~/bak/16C_coor_inner >c_coor_inner 16 | sed -i '/^[[:space:]]*$/d' c_coor_inner 17 | ic2cc.pl c_coor_inner 18 | sed -i '1,3d' c_coor_inner.car 19 | cat $name c_coor_inner.car >c_coor 20 | sed -i '/^[[:space:]]*$/d' c_coor 21 | mysort.pl c_coor 22 | head -5 $1 >POSCAR-18C.gjf 23 | cat c_coor >>POSCAR-18C.gjf 24 | gv2vas.pl ~/bak/POSCARmod POSCAR-18C.gjf 25 | mv POSCAR-18C.vasp POSCAR 26 | rm c_coor* *.gjf *.vasp POSCAR.tmp 27 | sed -i -f ~/bak/sed_addTTT POSCAR 28 | vas2gv.pl POSCAR 29 | mv POSCAR.gjf POSCAR-18C.gjf 30 | 31 | for i in is fs 32 | do 33 | if [ -x $i ];then 34 | sed -i '/IBRION/s/2/1/' $i 35 | sub $i 36 | exit 37 | elif [ -x relax ];then 38 | rm relax 39 | cp ../is/is ts 40 | sed -i '/IBRION/s/2/1/' ts 41 | sed -i '/NSW/s/500/80/' ts 42 | sub ts 43 | exit 44 | fi 45 | done 46 | -------------------------------------------------------------------------------- /all2unix.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | separator = re. compile(r'\r\n') 5 | 6 | for i in xrange(1, len(sys.argv)): 7 | content = '' 8 | with open(sys.argv[i]) as IN: 9 | content = IN.readlines() 10 | for j in xrange(0, len(content)): 11 | content[j] = content[j].rstrip() 12 | with open(sys.argv[i], 'w') as OUT: 13 | for line in content: 14 | OUT.write(line + '\n') 15 | 16 | -------------------------------------------------------------------------------- /cel2vas.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | from VASP import readCell, writeVasp 4 | import sys 5 | 6 | if len(sys.argv) < 2: 7 | print('') 8 | print('Usage: %s cell_file1 cell_file2 ...' % sys.argv[0].split('/')[-1]) 9 | print('Please try again') 10 | exit(1) 11 | 12 | print('') 13 | print('################## This script converts .cell into POSCAR ##################') 14 | print(' ############### .cell -> POSCAR ###############') 15 | for file_name in sys.argv[1:]: 16 | print(' processing %s' % file_name) 17 | basis, elements, num_atoms, coordinate_type, coordinates = readCell(file_name) 18 | writeVasp(file_name.replace('.cell', '.vasp'), 1.0, basis, elements, 19 | num_atoms, '', coordinate_type, coordinates, []) 20 | 21 | print(' ----------------- Done -----------------\n') 22 | -------------------------------------------------------------------------------- /chg2cube.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | #;-*- Perl -*- 3 | 4 | # Created by dano 5-28-08 5 | # LAST MODIFIED by dano: 4-29-10 6 | # convert chgcar and locpot to cube format 7 | ################################################## 8 | # 4-29: fixed RHO reading issuse 9 | # 4-28: fix output units, reduced memory needed 10 | # 2-16: Setup to read also vasp5 format 11 | # 2-16: Fixed error optional 1st comment line 12 | # 12-29: checked for non-ortho box 13 | # 8-22: fixed units for chgcar conversion 14 | # 8-13: del vars when done with them 15 | ################################################## 16 | 17 | use FindBin qw($Bin); 18 | use lib "$Bin"; 19 | #use Vasp; 20 | use Math::Trig; 21 | $fact = 180/pi; 22 | 23 | print "\n"; 24 | @args = @ARGV; 25 | @args >= 1 || die "usage: chg2cube.pl \n"; 26 | $inputfilename = $args[0]; 27 | 28 | # prompt USER for file format 29 | print "SELECT INPUT FILE FORMAT 1=CHGCAR or 2=LOCPOT 3=PARCHG: "; 30 | chomp($filetype_ = ); 31 | #$filetype_ = 1; 32 | if ($filetype_ == 1) {$filetype = "chgcar";} 33 | if ($filetype_ == 2) {$filetype = "locpot";} 34 | if ($filetype_ == 3) {$filetype = "parchg";} 35 | if ($filetype_ == 1 or $filetype_ == 2 or $filetype_ == 3) { 36 | print " READING '$filetype' FILE FORMAT\n"; 37 | print "\n"; 38 | }else{ 39 | die " YOU MUST ENTER 1 or 2 or # FOR FILE FORMAT\n"; 40 | } 41 | 42 | ## bohr or ang (uncomment for selection) 43 | #print "SELECT UNITS FOR OUTPUT 1=BOHR/HARTREE or 2=ANGSTROMS/eV: "; 44 | #chomp($units = ); 45 | #if ($units == 1) {$unittype= "bohr/hartree"; $l_units=1.889725992; $e_units=0.036749309; $unit_flag=-1;} # Ang ----> Bohr 46 | #if ($units == 2) {$unittype= "angstroms/eV"; $l_units=1.0; $e_units=1; $unit_flag=1} # Ang ----> Ang 47 | #if ($units == 1 or $units == 2) { 48 | # print " USING '$unittype' FOR OUTPUT UNITS\n"; 49 | # print "\n";} 50 | #else {die " YOU MUST ENTER 1 or 2 FOR UNITS\n";} 51 | 52 | # Assume atomic units 53 | $unittype = "bohr/hartree"; 54 | $l_units = 1.889725992; 55 | $e_units = 0.036749309; 56 | $unit_flag = 1; 57 | print " USING '$unittype' FOR OUTPUT UNITS\n"; 58 | 59 | # prompt USER for ATOMIC NUMBERS of ELEMENTs in file 60 | print "ENTER ELEMENT TYPES BY ATOMIC NUMBER: "; 61 | #$atom_types_=@_; 62 | #$atom_types_ = 63 | chomp($atom_types_ = ); 64 | print "\n"; 65 | $atom_types_ =~ s/^\s+//; 66 | @atom_types = split(/\s+/,$atom_types_); 67 | #@atom_types=(3,8,15,26); 68 | for ($i=0; $i<@atom_types; $i++) { 69 | $atom_types->[$i] = $atom_types[$i]; 70 | } 71 | 72 | $inputfile = ""; 73 | open (IN,$inputfilename); 74 | while () { 75 | $_ =~ s/^\s+//g; 76 | $inputfile .= $_; 77 | } 78 | close (IN); 79 | 80 | @inputfile = split(/\n/,$inputfile); 81 | 82 | # check for a comment line 83 | $line = $inputfile[0] ; 84 | $line =~ s/^\s+//; 85 | @line = split(/\s+/,$line); 86 | if ($line[0] =~ /^\d+(\.\d+)?/) { 87 | $index = 0; 88 | } else { 89 | chop($description = $inputfile[0]); 90 | $index = 1; 91 | } 92 | $lattice = $inputfile[$index]; 93 | 94 | #Check for vasp5 format 95 | $line = $inputfile[$index+4] ; 96 | $line =~ s/^\s+//; 97 | @line = split(/\s+/,$line); 98 | # if ($line=~/^s/i) { 99 | if ($line[0] =~ /^\d+$/) { 100 | $vasp5 = 0; 101 | }else{ 102 | chop($description = $inputfile[$index+4]); 103 | $vasp5 = 1; 104 | } 105 | 106 | # read total atoms 107 | $num_atoms_ = $inputfile[$index+4+$vasp5]; 108 | #print $num_atoms; 109 | $num_atoms_ =~ s/^\s+//; 110 | @num_atoms = split(/\s+/,$num_atoms_); 111 | #print @num_atoms; 112 | for ($i=0; $i<@num_atoms; $i++) { 113 | $num_atoms->[$i] = $num_atoms[$i]; 114 | $total_atoms += $num_atoms->[$i]; 115 | } 116 | 117 | # make sure you have as many types of elements as atomic numbers entered 118 | #print "@num_atoms\n"; 119 | #print "@atom_types\n"; 120 | if (@num_atoms!=@atom_types) {die " NUMBER OF ELEMENT TYPES DOES NOT MATCH NUMBER OF ATOMIC NUMBERS GIVEN\n";} 121 | 122 | for ($i=0; $i<3; $i++) { 123 | $line_ = $inputfile[$i+$index+1]; 124 | $line_ =~ s/^\s+//; 125 | @line = split(/\s+/,$line_); 126 | # This is how Vasp reads in the basis 127 | for ($j=0; $j<@line; $j++) { 128 | $basis->[$j][$i] = $line[$j]*$lattice*$l_units; 129 | } 130 | } 131 | 132 | # correct volume for non-orthognal box (expansion by minors) 133 | $vol = $basis->[0][0]*($basis->[1][1]*$basis->[2][2] - $basis->[2][1]*$basis->[1][2]) 134 | - $basis->[1][0]*($basis->[0][1]*$basis->[2][2] - $basis->[2][1]*$basis->[0][2]) 135 | + $basis->[2][0]*($basis->[0][1]*$basis->[1][2] - $basis->[1][1]*$basis->[0][3]); 136 | 137 | # make sure volume is + 138 | # this volume is in units selected (default bohr) but we need it in ang**3 139 | $vol = abs($vol)/($l_units**3); 140 | #print "$vol\n"; 141 | 142 | # read in coordinates 143 | $index = $index + $vasp5 + 6; 144 | #print "$index\n"; 145 | for ($i=$index; $i<$index+$total_atoms; $i++) { 146 | $line_ = $inputfile[$i]; 147 | $line_ =~ s/^\s+//; 148 | @line = split(/\s+/,$line_); 149 | for ($j=0; $j<@line; $j++) { 150 | $coordinates->[$i-$index][$j] = $line[$j]; 151 | } 152 | } 153 | 154 | # change coordinates to cartesian 155 | for ($i=0; $i<$total_atoms; $i++) { 156 | $v1 = $coordinates->[$i][0]*$basis->[0][0] + $coordinates->[$i][1]*$basis->[0][1] + $coordinates->[$i][2]*$basis->[0][2]; 157 | $v2 = $coordinates->[$i][0]*$basis->[1][0] + $coordinates->[$i][1]*$basis->[1][1] + $coordinates->[$i][2]*$basis->[1][2]; 158 | $v3 = $coordinates->[$i][0]*$basis->[2][0] + $coordinates->[$i][1]*$basis->[2][1] + $coordinates->[$i][2]*$basis->[2][2]; 159 | 160 | $coordinates->[$i][0] = $v1; 161 | $coordinates->[$i][1] = $v2; 162 | $coordinates->[$i][2] = $v3; 163 | } 164 | 165 | # read number of grid-points 166 | $index = $index + $total_atoms; 167 | $fft_grid_ = $inputfile[$index]; 168 | $fft_grid_ =~ s/^\s+//; 169 | @fft_grid = split(/\s+/,$fft_grid_); 170 | $grid_points = 1; 171 | for ($i=0; $i<@fft_grid; $i++) { 172 | $fft_grid->[$i] = $fft_grid[$i]; 173 | $grid_points *= $fft_grid->[$i]; 174 | } 175 | 176 | $nx = $fft_grid->[0]; 177 | $ny = $fft_grid->[1]; 178 | $nz = $fft_grid->[2]; 179 | print "gridpoints $grid_points\n"; 180 | $data_lines = int($grid_points/5+1); 181 | if ($filetype_ == 3) { 182 | $data_lines = int($grid_points/10); 183 | } 184 | #print "$data_lines\n"; 185 | 186 | ####READ IN THE RHO DATA#### 187 | $index += 1; 188 | $ii = 0; 189 | #print $index; 190 | for ($i=$index; $i<($index+$data_lines); $i++) { 191 | $line_ = $inputfile[$i]; 192 | $line_ =~ s/^\s+//; 193 | @line = split(/\s+/,$line_); 194 | for ($j=0; $j<@line; $j++) { 195 | # density is read in x-inner,y-middle,z-outer loop 196 | $density->[$ii] = $line[$j]; 197 | $ii++; 198 | } 199 | } 200 | print "gridpoints read $ii \n"; 201 | print "$density->[$ii-1]\n"; 202 | 203 | #print "$density->[0]\n"; 204 | #print "$density->[1]\n"; 205 | #print "$density->[2]\n"; 206 | #print "$density->[3]\n"; 207 | 208 | # del inputfile 209 | undef @inputfile; 210 | undef $inputfile; 211 | 212 | ############################################## 213 | ###### WRITE OUT THE CUBE FILE ############### 214 | ############################################## 215 | if(@args >= 2) { $outputfilename = $args[1]; } 216 | else { $outputfilename = $inputfilename.".cube"; } 217 | open (OUT,">$outputfilename"); 218 | # printing garbage header 219 | print OUT "CUBE FILE CONVERTED FROM VASP format\n"; 220 | print OUT "OUTTER LOOP: X, MIDDLE LOOP: Y, INNER LOOP: Z\n"; 221 | # Natoms center of volumetric data? whatever that means 222 | printf OUT "%5i %12.6f %12.6f %12.6f\n",$total_atoms,0,0,0 ; 223 | 224 | # grid numbers box vectors 225 | # unit flag is negative for bohr 226 | printf OUT "%5i %12.6f %12.6f %12.6f\n",$unit_flag*$nx,$basis->[0][0]/$nx,$basis->[1][0]/$nx,$basis->[2][0]/$nx; 227 | printf OUT "%5i %12.6f %12.6f %12.6f\n",$ny,$basis->[0][1]/$ny,$basis->[1][1]/$ny,$basis->[2][1]/$ny; 228 | printf OUT "%5i %12.6f %12.6f %12.6f\n",$nz,$basis->[0][2]/$nz,$basis->[1][2]/$nz,$basis->[2][2]/$nz; 229 | 230 | # atomic number | ? | x y z in direct coordinates 231 | $cum_num_atom_types->[0] = $num_atoms->[0]; 232 | for ($i=1; $i<@num_atoms; $i++){ 233 | $cum_num_atom_types->[$i] = $cum_num_atom_types->[$i-1] + $num_atoms->[$i]; 234 | } 235 | 236 | $j = 0; 237 | for ($i=0; $i<$total_atoms; $i++) { 238 | if ($i<$cum_num_atom_types->[$j]) { 239 | printf OUT "%5i %12.6f %12.6f %12.6f %12.6f\n",$atom_types->[$j],0,$coordinates->[$i][0],$coordinates->[$i][1],$coordinates->[$i][2]; 240 | }else{ 241 | $j++; 242 | printf OUT "%5i %12.6f %12.6f %12.6f %12.6f\n",$atom_types->[$j],0,$coordinates->[$i][0],$coordinates->[$i][1],$coordinates->[$i][2]; 243 | } 244 | } 245 | 246 | ##### Write out the density ########### 247 | # volume scaling for CHGCAR 248 | if ($filetype_ == 1) { $vol_scale = 1.0/($vol); } # chgcar 249 | if ($filetype_ == 2) { $vol_scale = 1.0; } # locpot 250 | if ($filetype_ == 3) { $vol_scale = 1.0/($vol); } # parchg 251 | 252 | # density is read in x-inner,y-middle,z-outer loop 253 | # needs to be written as z-inner,y-middle,x-outer loop 254 | $ii=0; 255 | for ($ix=0; $ix<$nx; $ix++) { 256 | for ($iy=0; $iy<$ny; $iy++) { 257 | for ($iz=0; $iz<$nz; $iz++) { 258 | $itr = ($iz*$nx*$ny) + ($iy*$nx) + $ix; 259 | printf OUT "%13.5E ",$vol_scale*$e_units*$density->[$itr]; 260 | if ($ii%6 ==5) { 261 | print OUT " \n"; 262 | } 263 | $ii++; 264 | } 265 | } 266 | } 267 | 268 | close (OUT); 269 | 270 | 271 | ########################################## 272 | 273 | -------------------------------------------------------------------------------- /chgflag.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | import re 5 | from VASP import readVasp 6 | from VASP import writeVasp 7 | 8 | 9 | if len(sys.argv) != 3 and len(sys.argv) != 4: 10 | print("") 11 | print("Usage: %s line1,line2,.... T/F vaspfile" % sys.argv[0].split('/')[-1]) 12 | print("the format of line1,line2,... can be either x or x-x") 13 | print("try again") 14 | print("") 15 | exit(1) 16 | 17 | 18 | flag = sys.argv[-2] 19 | if flag != 'T' and flag != 'F': 20 | print('') 21 | print("Error: unidentified flag '%s'" % flag) 22 | print('') 23 | exit(1) 24 | 25 | lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective = readVasp(sys.argv[-1]) 26 | 27 | edit_line_number = [] 28 | pattern = re.compile(r'-') 29 | if len(sys.argv) == 4: 30 | line_number = re.split(',', sys.argv[1]) 31 | for num in line_number: 32 | if pattern.search(num): 33 | num_list = pattern.split(num) 34 | num_list[0] = int(num_list[0]) - 1 35 | num_list[1] = int(num_list[1]) 36 | for i in range(num_list[0], num_list[1]): 37 | edit_line_number.append(i) 38 | else: 39 | edit_line_number.append(int(num) - 1) 40 | 41 | if selectiveflag == '': 42 | selectiveflag = 'Selective dynamics' 43 | total_atoms = sum(num_atoms) 44 | if sys.argv[-2] == 'T': 45 | for i in range(0, total_atoms): 46 | selective.append(['F', 'F', 'F']) 47 | else: 48 | for i in range(0, total_atoms): 49 | selective.append(['T', 'T', 'T']) 50 | 51 | if edit_line_number: 52 | for i in edit_line_number: 53 | selective[i] = [sys.argv[-2], sys.argv[-2], sys.argv[-2]] 54 | else: 55 | for i in range(0, len(coordinates)): 56 | selective[i] = [sys.argv[-2], sys.argv[-2], sys.argv[-2]] 57 | 58 | writeVasp(sys.argv[-1], lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective) 59 | 60 | print('') 61 | print('---------------Done---------------') 62 | print('') 63 | -------------------------------------------------------------------------------- /choice.pl: -------------------------------------------------------------------------------- 1 | #!/bin/env perl 2 | use strict; 3 | use Math::Trig; 4 | use vars qw($file $line @eachline $coor $O $i $array @array); 5 | 6 | sub dot { 7 | my $v1 = shift; 8 | my $v2 = shift; 9 | return $v1->[0]*$v2->[0]+$v1->[1]*$v2->[1]+$v1->[2]*$v2->[2]; 10 | } 11 | 12 | sub angle { 13 | my $v1 = shift; 14 | my $v2 = shift; 15 | return rad2deg(acos(dot($v1,$v2)/(sqrt(dot($v1,$v1))*sqrt(dot($v2,$v2))))); 16 | } 17 | 18 | sub substra { 19 | my $v1 = shift; 20 | my $v2 = shift; 21 | return [$v2->[0]-$v1->[0],$v2->[1]-$v1->[1],$v2->[2]-$v1->[2]]; 22 | } 23 | 24 | sub add { 25 | my $v1 = shift; 26 | my $v2 = shift; 27 | return [$v2->[0]+$v1->[0],$v2->[1]+$v1->[1],$v2->[2]+$v1->[2]]; 28 | } 29 | 30 | sub midvt { 31 | my $v1 = shift; 32 | my $v2 = shift; 33 | my $v3 = shift; 34 | my $half = [[0.5,0.5,0.5]]; 35 | return substra(add(dot(substra($v1,$v2),$half),$v1),$v3); 36 | } 37 | 38 | 39 | open IN,'<',$ARGV[0] or die; 40 | 41 | $i = 0; 42 | while($line=){ 43 | chomp $line; 44 | @eachline=split(/\s+/,$line); 45 | $coor->[$i][0] = $eachline[1]; 46 | $coor->[$i][1] = $eachline[2]; 47 | $coor->[$i][2] = $eachline[3]; 48 | $i++; 49 | } 50 | close(IN); 51 | close(OUT); 52 | 53 | for(my $i=0;$i<4;$i++){ 54 | for(my $j=0;$j<4;$j++){ 55 | next if($j==$i); 56 | my $v1=substra($coor->[$i],$coor->[$i+4]); 57 | my $v2=substra($coor->[$i],$coor->[$j]); 58 | #print "$i $j\n"; 59 | #print "$v1->[0] $v1->[1] $v1->[2]\n"; 60 | #print "$v2->[0] $v2->[1] $v2->[2]\n"; 61 | $O->[$i][$j]=angle($v1,$v2); 62 | #print "$O->[$i][$j]\n"; 63 | } 64 | } 65 | 66 | 67 | 68 | @array=( 69 | ["1","2","3","4","1"], 70 | ["1","4","3","2","1"], 71 | ["1","2","4","3","1"], 72 | ["1","3","4","2","1"], 73 | ["1","3","2","4","1"], 74 | ["1","4","2","3","1"], 75 | ); 76 | 77 | for(my $i=0;$i<6;$i++){ 78 | my $j=0; 79 | while($j<6){ 80 | print "$array[$i][$j] "; 81 | $j++; 82 | } 83 | print "\n"; 84 | print "$O->[0][$array[$i][1]-1]; $O->[$array[$i][1]-1][$array[$i][2]-1]; $O->[$array[$i][2]-1][$array[$i][3]-1]; $O->[$array[$i][3]-1][$array[$i][4]-1];\n"; 85 | print "\n"; 86 | } 87 | #data 88 | #O1 89 | #O2 90 | #O3 91 | #O4 92 | #Sn1 93 | #Si2 94 | #Si3 95 | #Si4 96 | # 97 | # 98 | # 99 | ##possibility 100 | #12341 101 | #12431 102 | # 103 | #13241 104 | #13421 105 | # 106 | #14231 107 | #14321 108 | -------------------------------------------------------------------------------- /ck: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # check information before running vasp 3 | 4 | echo "" 5 | echo "KPOINTS:" 6 | tail -3 KPOINTS 7 | echo "" 8 | 9 | echo "POTCAR:" 10 | grep "TITEL" POTCAR 11 | echo "" 12 | 13 | if [ -e POSCAR ];then 14 | echo "POSCAR:" 15 | sed -n '6,8p' POSCAR 16 | flagck.py 17 | elif [ -e 00/POSCAR ];then 18 | echo "00/POSCAR:" 19 | sed -n '6,8p' 00/POSCAR 20 | cd 00/ 21 | flagck.py 22 | cd .. 23 | else 24 | echo "POSCAR do not exit!" 25 | fi 26 | 27 | dir=`pwd` 28 | if [[ $dir =~ dimer ]];then 29 | if [ ! -f MODECAR ];then 30 | echo "" 31 | echo " !!!!!warning: MODECAR undetected!!!!!" 32 | echo "" 33 | fi 34 | fi 35 | 36 | 37 | -------------------------------------------------------------------------------- /clc: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | for i in CHG CHGCAR WAVECAR DOSCAR EIGENVAL OSZICAR PCDAT vasprun.xml slurm-* vasp-gamma *.gjf *.vasp *.pos *.xyz 3 | do 4 | for j in `find ./ -name $i` 5 | do 6 | echo "$j" 7 | rm $j 8 | done 9 | done 10 | -------------------------------------------------------------------------------- /clean: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "" 3 | echo "This script clear all file but POSCAR INCAR KPOINTS POTCAR and executable file" 4 | read -p "Are sure to continue?[Y/N]:" flag 5 | echo "" 6 | if [ "$flag" != "Y" -a "$flag" != "y" ];then 7 | exit 8 | fi 9 | 10 | list="POSCAR POTCAR INCAR KPOINTS ""$@" 11 | 12 | for i in `ls -1` 13 | do 14 | for j in $list 15 | do 16 | if [[ $i =~ ${j}$ ]];then 17 | continue 2 18 | elif [ -x $i ];then 19 | continue 2 20 | fi 21 | done 22 | rm $i 23 | done 24 | echo " ---------- Done ----------" 25 | echo "" 26 | -------------------------------------------------------------------------------- /cluster.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | import sys 4 | from VASP import read_poscar 5 | from VASP import write_poscar 6 | 7 | pos=[ [5.8542326628848222, 8.6627288616639202, 5.8614577958952649], 8 | [19.1457883626720999, 8.6618038283281429, 5.8617364474046472], 9 | [12.4996292966500064, 15.5432216444165245, 5.8505835915867426], 10 | [12.4996643651611539, 20.1731884887187114, 5.8689022630647800], 11 | [ 9.8642435232315151, 10.9792336123257641, 5.8473985708617429], 12 | [15.1357647669649271, 10.9791445570918995, 5.8472893749556079], 13 | [ 8.5184517876025279, 17.9094319106692339, 5.8404122824553175], 14 | [16.4803808630984250, 17.9094750385708004, 5.8387698865076327], 15 | [ 5.8239686065138274, 13.2430151734748378, 5.8366213458278002], 16 | [19.1756365833384415, 13.2430391136603038, 5.8350835858967098], 17 | [ 9.8067481495349647, 6.3495826586473152, 5.8328105220657820], 18 | [15.1937500782213348, 6.3490794563218671, 5.8330243464332350], 19 | [ 7.1904979234005300, 15.5651383106483276, 5.8259475258861704], 20 | [17.8087338711519259, 15.5652572833824330, 5.8245572976908671], 21 | [12.5000405878065539, 6.3729308348105809, 5.8218156883507675], 22 | [ 9.8820227202533282, 20.1615823696097038, 5.7844099681486449], 23 | [15.1170850426095829, 20.1616169957727216, 5.7828276269297225], 24 | [ 9.8122233556618639, 15.6062771111702467, 5.7978947497764279], 25 | [15.1870343137687520, 15.6062640823243584, 5.7973780728100950], 26 | [ 8.4652256331715456, 13.2749294624138567, 5.7971824780871497], 27 | [16.5343455597751188, 13.2747877636130056, 5.7962617201112181], 28 | [11.1535516011113938, 8.6216877683269875, 5.7938944716497121], 29 | [13.8466676349981466, 8.6214440419079121, 5.7943806235593751], 30 | [11.1490651429739547, 17.9761055906219411, 5.7801712196507227], 31 | [13.8496966421608665, 17.9760454193992452, 5.7804718311372252], 32 | [ 7.0806236588204898, 10.9316354119090882, 5.7771740040302655], 33 | [17.9196297301407306, 10.9312779304740122, 5.7762362324898824], 34 | [11.1466749444189528, 13.2819533837950718, 5.7838345774454654], 35 | [13.8529870474015446, 13.2820766532686125, 5.7835474481279379], 36 | [ 8.4321768825083225, 8.5939250693677529, 5.7740131122559575], 37 | [16.5679980292057039, 8.5938416892026712, 5.7741364855875670], 38 | [12.5001416610547142, 10.9397393077747278, 5.7828449293659103], 39 | [ 4.5545882618995801, 10.9372558294256201, 5.7785902068256227], 40 | [20.4451384058851815, 10.9363239532347656, 5.7776259828189218], 41 | [ 7.1740910330408996, 6.4035538749654872, 5.7743942607092302], 42 | [17.8255437064344839, 6.4026847899577053, 5.7752304099191845], 43 | [ 5.8568607540469744, 11.7651243950267137, 3.6608883120443871], 44 | [19.1436939971528197, 11.7667770355312129, 3.6604706101656226], 45 | [ 8.5426819733447310, 7.1162155758867005, 3.6587428673277396], 46 | [16.4586851339770135, 7.1174272612378884, 3.6584426541561030], 47 | [ 9.8136168292230721, 18.6222830403632145, 3.6663636877511325], 48 | [12.4995145412520650, 18.6312555181673005, 3.6548235558601054], 49 | [15.1831458084883888, 18.6231885937048105, 3.6654539879666501], 50 | [ 7.1905459875948967, 9.4375562195163099, 3.6484179628325952], 51 | [17.8089055071839013, 9.4369088439504623, 3.6479812702380898], 52 | [ 8.5106357931706622, 16.3341139136295936, 3.6206149773764928], 53 | [16.4878788265676661, 16.3351489370489098, 3.6202856639716825], 54 | [ 7.1851154172870926, 14.0394083936080634, 3.6189915219198379], 55 | [17.8144949861972179, 14.0402357499072128, 3.6176999795794704], 56 | [11.1752410014319725, 7.1318705445070725, 3.6144877158625528], 57 | [13.8259816450236723, 7.1317412695549667, 3.6160137060298552], 58 | [12.4996158325251283, 14.0602012265637786, 3.6075313553575503], 59 | [11.1505765206244050, 11.7223267224017249, 3.6068877754449300], 60 | [13.8502987706658622, 11.7232173727088629, 3.6066155977606549], 61 | [11.1498571077593756, 16.4113638209514292, 3.5760358823059648], 62 | [13.8485674418494789, 16.4107606851385235, 3.5759996716579900], 63 | [ 9.7891812762153094, 9.3780459876955025, 3.5711816461132022], 64 | [15.2101276867227853, 9.3789002597240856, 3.5716568501771477], 65 | [ 8.4393762279991158, 11.7162332293038247, 3.5731022570868047], 66 | [16.5617228908786025, 11.7167625758915364, 3.5727113095524476], 67 | [ 9.7777043270454023, 14.0726331225701404, 3.5575765222356122], 68 | [15.2221258811660487, 14.0731293508385509, 3.5569787180677124], 69 | [12.5002525096445680, 9.3601828303336774, 3.5542392678181502], 70 | [ 8.5320020693175405, 14.7910868434451501, 1.5187845488341576], 71 | [16.4668862744892053, 14.7933338472709952, 1.5180927858648652], 72 | [ 9.8887961265038822, 17.1463588545972883, 1.5146754477426800], 73 | [15.1081461908212749, 17.1487848478586997, 1.5146578136720801], 74 | [12.5020410432031692, 7.9226726991187002, 1.5145458408523949], 75 | [ 7.1705177122920194, 12.4396711855405453, 1.5118473503168626], 76 | [17.8294570832127093, 12.4413426726000420, 1.5111017865561325], 77 | [ 9.7860910857492662, 7.9205963993608606, 1.5076994932664651], 78 | [15.2171821019143749, 7.9212608271536356, 1.5081308582786375], 79 | [12.5003167921428595, 12.5030053504844716, 1.4977462763204274], 80 | [12.4991949683432502, 17.0771780327954161, 1.4738220963398374], 81 | [11.1387551669516434, 14.8215426119312426, 1.4782594263777826], 82 | [13.8601305439163998, 14.8216561851532873, 1.4781982275442249], 83 | [ 9.8121148532213063, 12.5195525373460228, 1.4769349629129875], 84 | [15.1895751883270265, 12.5200970496508468, 1.4764890499645225], 85 | [11.1714269060458786, 10.1654087289077619, 1.4752615333521850], 86 | [13.8288820354799782, 10.1668810853471037, 1.4752820024869751], 87 | [ 8.5369568562395006, 10.2155217644163354, 1.4700324542918575], 88 | [16.4634057452755975, 10.2154701580726197, 1.4701338323750650] 89 | ] 90 | 91 | 92 | lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective = read_poscar(sys.argv[1]) 93 | 94 | temp = coordinates[:119] 95 | temp.extend(pos) 96 | temp.extend(coordinates[119:]) 97 | num_atoms[0] += 82 98 | 99 | write_poscar('POSCAR.vasp', lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, temp, selective) 100 | 101 | -------------------------------------------------------------------------------- /cpfile: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ $1 = "-a" ];then 3 | if [ -d $2 ];then 4 | cp $2/POSCAR . 5 | dir=$2 6 | else 7 | echo "fold $2 does not exit" 8 | exit 9 | fi 10 | elif [ -d $1 ];then 11 | dir=$1 12 | else 13 | echo "fold $dir does not exit" 14 | exit 15 | fi 16 | 17 | cp $dir/INCAR . 18 | cp $dir/KPOINTS . 19 | cp $dir/POTCAR . 20 | if [ -f $dir/vdw_kernel.bindat ];then 21 | cp $dir/vdw_kernel.bindat . 22 | fi 23 | for i in `ls $dir` 24 | do 25 | if [ -x $dir/$i ];then 26 | cp $dir/$i . 27 | fi 28 | done 29 | -------------------------------------------------------------------------------- /difenergy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ "$#" -eq "2" ];then 3 | energy $@ 4 | energy $@ |sed -n '/energy/p' |awk 'BEGIN{count=0;} {a[count]=$4;count++;} END{print a[1]-a[0]}' 5 | else 6 | echo "number of parameters is wrong" 7 | fi 8 | -------------------------------------------------------------------------------- /dir2car.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | from VASP import readVasp 5 | from VASP import writeVasp 6 | 7 | if len(sys.argv) == 1: 8 | print('') 9 | print('Usage: %s vasp_file1 vasp_file2 ...' % sys.argv[0].split('/')[-1]) 10 | print('') 11 | exit(1) 12 | 13 | print('') 14 | print('############ This script converts direct to cartesian ############') 15 | print(' ############ direct -> cartesian ############') 16 | print('') 17 | for vasp_file in sys.argv[1:]: 18 | print(' processing %s' % vasp_file) 19 | lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective = readVasp(vasp_file) 20 | if vasp_file.endswith('.vasp'): 21 | vasp_file = '%s-C.vasp' % vasp_file[:-5] 22 | else: 23 | vasp_file = '%s-C.vasp' % vasp_file 24 | writeVasp(vasp_file, lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective) 25 | 26 | print('') 27 | print(' ---------- Done ----------') 28 | print('') 29 | -------------------------------------------------------------------------------- /drawcluster.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | import os 5 | from VASP import readCell 6 | import re 7 | import numpy as np 8 | 9 | """ 10 | crystal_conf.txt 格式: 11 | x, y, z //在x,y,z三个方向上晶胞的数量 12 | h, k, l, distance //晶面指标,距离原点的距离 13 | ... 14 | h, k, l, distance //晶面指标,距离原点的距离 15 | """ 16 | 17 | if len(sys.argv) == 1: 18 | print('') 19 | print('Usage: %s cell_file' % sys.argv[0].split('/')[-1]) 20 | print('') 21 | exit(1) 22 | 23 | if not os.path.isfile('crystal_conf.txt'): 24 | print('') 25 | print('Error: crystal_conf.txt missing!') 26 | print('') 27 | exit(1) 28 | 29 | 30 | def product(coord, hkl): 31 | # 截距为0时该项置0 32 | if hkl == 0: 33 | return np.zeros(coord.shape[0]) 34 | else: 35 | return coord / hkl 36 | 37 | epsilion = 0.000001 38 | space = re.compile(r'\s+') 39 | with open('crystal_conf.txt', 'r') as conf_file: 40 | content = conf_file.readlines() 41 | x, y, z = map(int, content[0].strip().split(',')) 42 | 43 | planes = [] 44 | for i in range(1, len(content)): 45 | line = content[i].strip() 46 | if line == '': 47 | break 48 | 49 | if line.startswith('#'): 50 | continue 51 | line = line.split(',') 52 | planes.append([int(line[0]), int(line[1]), int(line[2]), float(line[3])]) 53 | 54 | basis, elements, num_atoms, coordinate_type, coordinates = readCell(sys.argv[1]) 55 | basis = np.array(basis) 56 | coordinates = np.array(coordinates) 57 | 58 | # 构建超胞 59 | coordinates_ret = [] 60 | for ix in range(-x, x + 1): 61 | coordinates_ret.append(coordinates + basis[0] * ix) 62 | coordinates = np.concatenate(coordinates_ret) 63 | 64 | coordinates_ret = [] 65 | for iy in range(-y, y + 1): 66 | coordinates_ret.append(coordinates + basis[1] * iy) 67 | coordinates = np.concatenate(coordinates_ret) 68 | 69 | coordinates_ret = [] 70 | for iz in range(-z, z + 1): 71 | coordinates_ret.append(coordinates + basis[2] * iz) 72 | coordinates = np.concatenate(coordinates_ret) 73 | 74 | print('') 75 | for i, plane in enumerate(planes): 76 | # 知道截距时候的平面公式: x/h + y/k + z/l = 1 77 | print('processing plane: (%2d, %2d, %2d); distance = %5.4f' % (plane[0], plane[1], plane[2], plane[3])) 78 | ret = np.zeros(coordinates.shape[0]) 79 | ret += product(coordinates[:, 0], plane[0] * plane[3]) 80 | ret += product(coordinates[:, 1], plane[1] * plane[3]) 81 | ret += product(coordinates[:, 2], plane[2] * plane[3]) 82 | 83 | coordinates = coordinates[ret < 1.0] 84 | print('') 85 | 86 | with open('ret.xyz', 'w') as output_file: 87 | output_file.write("%d\n" % coordinates.shape[0]) 88 | output_file.write('create from python\n') 89 | for coord in coordinates: 90 | output_file.write("%2s %16.10f %16.10f %16.10f\n" % (elements[0], coord[0], coord[1], coord[2])) 91 | output_file.write('\n') 92 | 93 | -------------------------------------------------------------------------------- /energy: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "" 3 | if [ -e OUTCAR ] 4 | then 5 | tac OUTCAR |grep -m 1 "energy with" 6 | elif [ "$1" != "" ] 7 | then 8 | for i in $@ 9 | do 10 | for j in `find $i -name OUTCAR |sort` 11 | do 12 | echo "$j" 13 | tac $j |grep -m 1 "energy with" 14 | done 15 | done 16 | else 17 | for i in `find ./ -name OUTCAR |sort` 18 | do 19 | echo "$i" 20 | tac $i |grep -m 1 "energy with" 21 | done 22 | fi 23 | echo "" 24 | -------------------------------------------------------------------------------- /excongjf.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | # 把指定目录中的default_file转换为gjf文件 4 | 5 | import sys 6 | import os 7 | import subprocess 8 | 9 | default_file = 'CONTCAR' 10 | 11 | if len(sys.argv) == 1: 12 | print('') 13 | print("Usage: %s directory1 directory2 ... (default_file)" % sys.argv[0].split('/')[-1]) 14 | print("Please try again!") 15 | exit(1) 16 | 17 | if not os.path.isdir(sys.argv[-1]): 18 | default_file = sys.argv[-1] 19 | 20 | print('') 21 | print('--------------------') 22 | print('') 23 | print("Default file: %s" % default_file) 24 | dir_list = [] 25 | for directory in sys.argv[1:]: 26 | if os.path.isdir(directory): 27 | dir_list.append(directory.rstrip('/')) 28 | else: 29 | print("%s is not a directory!" % directory) 30 | 31 | print('') 32 | print('Processing...') 33 | for directory in dir_list: 34 | pipe = subprocess.Popen("vas2gjf.py %s" % (directory + '/' + default_file), 35 | shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 36 | error = pipe.stderr.read().decode() 37 | if error != '': 38 | print("Error in path(%s): %s" % (directory, error)) 39 | continue 40 | os.system("mv %s/%s.gjf %s" % (directory, default_file, '%s.gjf' % directory)) 41 | print('') 42 | print('----- Done -----') 43 | print('') 44 | -------------------------------------------------------------------------------- /excoor.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | # 提取OUTCAR中每一步的原子坐标和能量 4 | # 用法:excoor.py 5 | # 或:excoor.py 20 24 35 (将分别提取第20,24,35步的构型并生成相应的POSCAR文件) 6 | 7 | import re 8 | import math 9 | import sys 10 | import os 11 | from VASP import execCmd, CmdRrror 12 | 13 | def writePOSCAR(content, base, number_of_atoms, step): 14 | os.system("head -7 POSCAR > POSCAR%d" % step) 15 | with open("POSCAR%d" % step, 'a') as output_file: 16 | output_file.write("Selective dynamics\n") 17 | output_file.write("Cartesian\n") 18 | for i in range(base, base + number_of_atoms): 19 | line = list(map(float, space.split(content[i].strip()))) 20 | output_file.write(" %10.5f %10.5f %10.5f F F F\n" % (line[0], line[1], line[2])) 21 | 22 | 23 | space = re.compile(r'\s+') 24 | position = re.compile(r'POSITION') 25 | 26 | 27 | cmd = "sed -n '7p' POSCAR" 28 | try: 29 | number_of_atoms = sum(map(int, space.split(execCmd(cmd)[0].strip()))) 30 | except CmdRrror: 31 | print(CmdRrror) 32 | exit(1) 33 | 34 | 35 | cmd = 'grep "POSITION" -A %d OUTCAR' % (int(number_of_atoms) + 15) 36 | try: 37 | content = execCmd(cmd) 38 | except CmdRrror: 39 | print(CmdRrror) 40 | exit(1) 41 | 42 | print('') 43 | if len(sys.argv) > 1: 44 | step_set = set(map(int, sys.argv[1:])) 45 | else: 46 | step_set = set() 47 | 48 | with open('OUTCAR.pos', 'w') as output_file: 49 | step = 0 50 | i = 0 51 | length = len(content) 52 | while i < length: 53 | if re.search(position, content[i]) is None: 54 | i += 1 55 | continue 56 | step += 1 57 | output_file.write("Step: %d\n" % step) 58 | output_file.write(content[i + 1]) 59 | i += 2 60 | base = i 61 | 62 | if step in step_set: 63 | writePOSCAR(content, base, number_of_atoms, step) 64 | 65 | while i - base < number_of_atoms: 66 | line = space.split(content[i].strip()) 67 | output_file.write("%10s %10s %10s %10.5f\n" % (line[0], line[1], line[2], 68 | math.sqrt(float(line[3]) ** 2 + float(line[4]) ** 2 + 69 | float(line[5]) ** 2))) 70 | i += 1 71 | output_file.write(content[i]) 72 | output_file.write(content[i + 10]) 73 | output_file.write(content[i + 12] + "\n") 74 | i += 14 75 | 76 | print(" --------------------Done--------------------") 77 | print('') 78 | -------------------------------------------------------------------------------- /exfreq.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import re 4 | import sys 5 | from VASP import execCmd, CmdRrror 6 | 7 | 8 | if len(sys.argv) == 1: 9 | print("") 10 | print("Usage: %s -a (for all frequencies)" % sys.argv[0].split('/')[-1]) 11 | print("Usage: %s -i (for all image frequencies)" % sys.argv[0].split('/')[-1]) 12 | print("Please try again!") 13 | print("") 14 | exit(1) 15 | 16 | 17 | print("") 18 | print(" --------------------Processing--------------------") 19 | print("") 20 | 21 | space = re.compile(r'\s+') 22 | cmd = "grep 'ions per type' OUTCAR" 23 | try: 24 | atom_num = execCmd(cmd) 25 | except CmdRrror: 26 | print(CmdRrror) 27 | print("") 28 | exit(1) 29 | 30 | # print(atom_num[0].strip().split('=')[-1]) 31 | atom_num = sum(map(int, space.split(atom_num[0].strip().split('=')[-1].strip()))) + 2 32 | 33 | if sys.argv[1] == '-a': 34 | cmd = "grep \"meV\" OUTCAR -A %d" % atom_num 35 | if sys.argv[1] == '-i': 36 | cmd = "grep \"f/i\" OUTCAR -A %d" % atom_num 37 | 38 | try: 39 | content = execCmd(cmd) 40 | except CmdRrror: 41 | print(CmdRrror) 42 | exit(1) 43 | 44 | if content is None: 45 | print(' No frequencies\n') 46 | print(" --------------------Done--------------------\n") 47 | exit(1) 48 | pattern = re.compile("([0-9]+)\s+f") 49 | content_length = len(content) 50 | freq_start = 0 51 | freq_end = 0 52 | freq_id = 0 53 | for index in range(0, content_length): 54 | if content[index].strip() == "": 55 | freq_end = index 56 | file_name = "freq" + freq_id 57 | with open(file_name, 'w') as output_file: 58 | for i in range(freq_start, freq_end + 1): 59 | output_file.write(str(content[i])) 60 | continue 61 | 62 | freq_id_search = re.search(pattern, content[index]) 63 | if freq_id_search is None: 64 | continue 65 | else: 66 | freq_start = index 67 | freq_id = freq_id_search.group(1) 68 | print(" freq%s" % freq_id) 69 | 70 | print('') 71 | print(" --------------------Done--------------------\n") 72 | -------------------------------------------------------------------------------- /flagck.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | # 检查T/F标记 3 | 4 | import re 5 | 6 | file_name = 'POSCAR' 7 | with open(file_name) as input_file: 8 | content = input_file.readlines() 9 | 10 | pattern = re.compile('\s+') 11 | pre_flag = [] 12 | flag = [] 13 | 14 | if re.search(r'^[Ss]', content[7]) is None: 15 | print('') 16 | print("Selective flag not found!") 17 | print('') 18 | exit(1) 19 | 20 | print('') 21 | print("Atom_id Content") 22 | print("------------------------------------------") 23 | for i in range(9, len(content)): 24 | temp = pattern.split(content[i].strip()) 25 | 26 | if len(temp) == 1: 27 | exit(1) 28 | 29 | if len(temp) != 6: 30 | print("-----------") 31 | print("%4d: %s" % (i - 8, content[i].rstrip())) 32 | print("-----------") 33 | continue 34 | 35 | if len(pre_flag) == 0: 36 | pre_flag = [temp[3], temp[4], temp[5]] 37 | flag = [temp[3], temp[4], temp[5]] 38 | else: 39 | flag = [temp[3], temp[4], temp[5]] 40 | 41 | if flag == pre_flag: 42 | continue 43 | else: 44 | pre_flag = flag 45 | print("%4d: %s" % (i - 9, content[i - 1].rstrip())) 46 | print("%4d: %s" % (i - 8, content[i].rstrip())) 47 | print("-----------") 48 | 49 | print('') 50 | -------------------------------------------------------------------------------- /freqmov.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | from VASP import execCmd, CmdRrror 5 | from VASP import writeXYZ 6 | import numpy as np 7 | import re 8 | 9 | if len(sys.argv) < 3: 10 | print('') 11 | print('Usage: %s freq1 freq2 ... frames scale' % sys.argv[0].split('/')[-1]) 12 | print('') 13 | exit(1) 14 | 15 | space = re.compile(r'\s+') 16 | 17 | def readFreq(file_name): 18 | """ 19 | :param file_name: str 20 | :return: [coordinates, dcoordinates] 21 | coordinates: 原子坐标(x,y,z) 22 | dcoordinates: 震动坐标(dx,dy,dz) 23 | """ 24 | coordinates = [] 25 | dcoordinates = [] 26 | with open(file_name, 'r') as freq_file: 27 | content = freq_file.readlines() 28 | index = 2 29 | while index < len(content): 30 | line = content[index].strip() 31 | if line == '': 32 | break 33 | 34 | line = list(map(float, space.split(line))) 35 | coordinates.append(np.array([line[0], line[1], line[2]])) 36 | dcoordinates.append(np.array([line[3], line[4], line[5]])) 37 | index += 1 38 | 39 | return np.stack(coordinates), np.stack(dcoordinates) 40 | 41 | 42 | def get_elements_info(): 43 | # 元素符号 44 | cmd = "grep 'VRHFIN' OUTCAR" 45 | try: 46 | content = execCmd(cmd) 47 | except CmdRrror: 48 | print(CmdRrror) 49 | print("") 50 | exit(1) 51 | pattern = re.compile(r'=(.*?):') 52 | elements = [] 53 | for line in content: 54 | line = line.strip() 55 | elements.append(pattern.search(line).group(1)) 56 | 57 | # 各元素原子数量 58 | cmd = "grep 'ions per type' OUTCAR" 59 | try: 60 | atom_num = execCmd(cmd) 61 | except CmdRrror: 62 | print(CmdRrror) 63 | print("") 64 | exit(1) 65 | 66 | num_atoms = list(map(int, space.split(atom_num[0].strip().split('=')[-1].strip()))) 67 | return elements, num_atoms 68 | 69 | 70 | print('') 71 | print('################ This script makes animation of vibration ################') 72 | print('') 73 | elements, num_atoms = get_elements_info() 74 | frames = int(sys.argv[-2]) 75 | dframe = 1 / float(frames) 76 | scale = float(sys.argv[-1]) 77 | for freq_file in sys.argv[1:-2]: 78 | print(' Processing %s' % freq_file) 79 | freq_pos, vibration = readFreq(freq_file) 80 | 81 | num_structures = 0 82 | coordinates = [] 83 | 84 | # 0→1 85 | for i in range(0, frames + 1): 86 | num_structures += 1 87 | coordinates.append(freq_pos + vibration * dframe * i * scale) 88 | 89 | # 1→0 90 | for i in range(frames, -1, -1): 91 | num_structures += 1 92 | coordinates.append(freq_pos + vibration * dframe * i * scale) 93 | 94 | # 0→-1 95 | for i in range(-1, -frames - 1, -1): 96 | num_structures += 1 97 | coordinates.append(freq_pos + vibration * dframe * i * scale) 98 | 99 | # -1→0 100 | for i in range(-frames, 0): 101 | num_structures += 1 102 | coordinates.append(freq_pos + vibration * dframe * i * scale) 103 | 104 | coordinates = np.concatenate(coordinates) 105 | 106 | writeXYZ('%s.xyz' % freq_file, num_structures, elements, num_atoms, coordinates) 107 | 108 | print('') 109 | print(' ------------------ Done ------------------\n') 110 | -------------------------------------------------------------------------------- /g09_jobs.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | # -*- coding=utf-8 -*- 3 | 4 | import os 5 | import subprocess 6 | import time 7 | import re 8 | import shutil 9 | import signal 10 | 11 | # 填入参数,分别是用于等待的文件夹路径,用于执行的文件夹路径和最大可以使用的CPU核心数(!是CPU核心数,不是CPU个数!) 12 | # 需要执行的gjf文件放到'wait_directory'路径下,本脚本会自动将其移动到'exec_directory'路径中执行 13 | # 本脚本放在哪里都可以,程序一开始会自动切换到'wait_directory' 14 | wait_directory = '/WORK/nankai_chem_ldli_1/temp/test-1' 15 | exec_directory = '/WORK/nankai_chem_ldli_1/temp/test-2' 16 | max_cores = 24 17 | interval = 10 18 | 19 | # 注意事项 20 | # gjf文件所用的核心数必须用关键字%nprocshared=xx来指定,否则将搜索不到 21 | 22 | os.chdir(wait_directory) 23 | output_file = open('output', 'w') 24 | 25 | 26 | if not os.path.exists(wait_directory): 27 | output_file.write("Path '%s' is not existed\n" % wait_directory) 28 | output_file.write("Please check your settings!\n") 29 | output_file.close() 30 | exit(0) 31 | 32 | if not os.path.exists(exec_directory): 33 | output_file.write("Path '%s' is not existed\n" % exec_directory) 34 | output_file.write("Please check your settings!\n") 35 | output_file.close() 36 | exit(0) 37 | 38 | file_list = [] 39 | cores_pattern = re.compile(r'%nprocshared=([0-9]+)') 40 | 41 | 42 | def exec_command(command): 43 | pipe = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 44 | return pipe.stdout.read().strip() 45 | 46 | 47 | def cores_occupy_query(): 48 | global jobs_list 49 | if jobs_list: 50 | cores_num = 0 51 | new_jobs_list = [] 52 | flag = False 53 | for job in jobs_list: 54 | if job[0].poll() is None: 55 | cores_num += job[1] 56 | new_jobs_list.append(job) 57 | else: 58 | output_file.write("Finished: %s\n" % job[2]) 59 | flag = True 60 | if flag: 61 | output_file.write('\n') 62 | output_file.flush() 63 | jobs_list = new_jobs_list 64 | return cores_num 65 | else: 66 | return 0 67 | 68 | 69 | def g09_file_run(g09_file_list): 70 | global jobs_list 71 | for g09_file in g09_file_list: 72 | if os.path.isfile(g09_file): 73 | # 移动文件并切换目录 74 | shutil.move(wait_directory + '/' + g09_file, exec_directory) 75 | os.chdir(exec_directory) 76 | 77 | # 查找需要的core数 78 | cores_match = cores_pattern.search(exec_command('head %s' % g09_file)) 79 | if cores_match is None: 80 | output_file.write("Error: can not find key word 'nprocshared' in file: %s\n" % g09_file) 81 | output_file.write("This file will be ignored!\n") 82 | output_file.flush() 83 | os.chdir(wait_directory) 84 | continue 85 | cores = int(cores_match.group(1)) 86 | 87 | # 查询已占用核心数 88 | cores_occupy = cores_occupy_query() 89 | while cores_occupy + cores > max_cores: 90 | time.sleep(interval) 91 | stop_run() 92 | cores_occupy = cores_occupy_query() 93 | 94 | if os.path.isfile(g09_file): 95 | output_file.write("Execute file: %s (free cores: %d)\n" % (g09_file, max_cores - cores - cores_occupy)) 96 | output_file.flush() 97 | g09_job = subprocess.Popen('g09 %s' % g09_file, shell=True, preexec_fn=os.setsid) 98 | jobs_list.append([g09_job, cores, g09_file]) 99 | os.chdir(wait_directory) 100 | 101 | 102 | def kill_job_in_jobs_list(file_name): 103 | for job in jobs_list: 104 | if file_name == job[2]: 105 | os.killpg(os.getpgid(job[0].pid), signal.SIGTERM) 106 | # ---------- debug ---------- 107 | # output_file.write("%s has been found and killed\n" % file_name) 108 | # output_file.flush() 109 | break 110 | 111 | 112 | def stop_run(): 113 | global jobs_list 114 | if os.path.isfile(wait_directory + '/STOP'): 115 | with open(wait_directory + '/STOP') as stop_file: 116 | for line in stop_file.readlines(): 117 | line = line.strip() 118 | if line.endswith('.gjf'): 119 | kill_job_in_jobs_list(line) 120 | os.remove(wait_directory + '/STOP') 121 | 122 | 123 | # jobs_list存放当前运行的Gaussian程序任务列表,其中每一项任务由三个元素构成:[Popen, cores, file_name] 124 | # Popen是任务对象,cores是所用CPU核心数, file_name是文件名 125 | jobs_list = [] 126 | 127 | while 1: 128 | os.chdir(wait_directory) 129 | file_list = [] 130 | for g09_file in os.listdir(wait_directory): 131 | if g09_file.endswith('.gjf'): 132 | file_list.append(g09_file) 133 | 134 | # ---------- debug ---------- 135 | # if jobs_list: 136 | # for job in jobs_list: 137 | # output_file.write(' %s is running!' % job[2]) 138 | # output_file.write('\n') 139 | # output_file.flush() 140 | 141 | # 两个列表都空了,执行完毕,程序退出 142 | if not jobs_list and not file_list: 143 | break 144 | # file_list空了,jobs_list没空,等待程序执行 145 | elif not file_list and jobs_list: 146 | time.sleep(interval) 147 | stop_run() 148 | cores_occupy_query() 149 | continue 150 | else: 151 | g09_file_run(file_list) 152 | output_file.write("---------- All Tasks Finished! ----------\n") 153 | output_file.close() 154 | -------------------------------------------------------------------------------- /gjf2vas.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | from VASP import readGjf, readVasp, writeVasp 5 | 6 | if len(sys.argv) == 1: 7 | print('') 8 | print('Usage: %s POSCAR gjf_file1 gjf_file2 ...' % sys.argv[0].split('/')[-1]) 9 | print('') 10 | exit(1) 11 | 12 | print('') 13 | print('############### This script converts gjf file into vasp file ###############') 14 | print(' ################# .gjf → .vasp #################') 15 | 16 | print('') 17 | lattice, basis, _, _, selectiveflag, coordinate_type, _, selective = readVasp(sys.argv[1]) 18 | for gjf_file in sys.argv[2:]: 19 | print(' Processing %s' % gjf_file) 20 | elements, num_atoms, coordinates = readGjf(gjf_file) 21 | if gjf_file.endswith('.gjf'): 22 | gjf_file = '%s.vasp' % gjf_file[:-4] 23 | else: 24 | gjf_file = '%s.vasp' % gjf_file 25 | writeVasp(gjf_file, lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective) 26 | 27 | print('') 28 | print(' -------------------- DONE --------------------') 29 | print('') 30 | -------------------------------------------------------------------------------- /gjf2xyz.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import re 4 | from VASP import readGjf, writeXYZ 5 | import sys 6 | 7 | space = re.compile(r'\s+') 8 | 9 | if len(sys.argv) == 1: 10 | print("") 11 | print("Usage: %s line1,line2,.... T/F vaspfile" % sys.argv[0].split('/')[-1]) 12 | print("the format of line1,line2,... can be either x or x-x") 13 | print("try again") 14 | print("") 15 | exit(1) 16 | 17 | 18 | print('') 19 | print('############ This script converts gjf to xyz ############') 20 | print(' ############ gjf -> xyz ############') 21 | print('') 22 | for gjf_file in sys.argv[1:]: 23 | print(' processing %s' % gjf_file) 24 | elements, num_atoms, coordinates = readGjf(gjf_file) 25 | if gjf_file.endswith('.gjf'): 26 | gjf_file = '%s.xyz' % gjf_file[:-4] 27 | else: 28 | gjf_file = '%s.xyz' % gjf_file 29 | writeXYZ(gjf_file, 1, elements, num_atoms, coordinates) 30 | 31 | print('') 32 | print(' ---------- Done ----------') 33 | -------------------------------------------------------------------------------- /gvextend.py: -------------------------------------------------------------------------------- 1 | # -*- coding=utf-8 -*- 2 | 3 | import VASP 4 | import sys 5 | 6 | # if len(sys.argv) < 4: 7 | # print "Usage: gvextend.py file1 file2 ... X Y Z" 8 | # print "Try again!" 9 | # exit(0) 10 | 11 | elements, num_atoms, coordinates = VASP.read_gjf('temp.gjf') 12 | print elements 13 | print num_atoms 14 | 15 | -------------------------------------------------------------------------------- /hlcluster.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python 2 | 3 | import sys 4 | import VASP 5 | import re 6 | 7 | 8 | pos1 = [[ 8.52663112, 14.79337948, 14.52301881], 9 | [ 16.47997580, 14.79343097, 14.51908835], 10 | [ 11.14789630, 14.85687226, 14.51622011], 11 | [ 13.85760488, 14.85722967, 14.51548506], 12 | [ 9.78287211, 12.49254211, 14.51553649], 13 | [ 15.22261961, 12.49238169, 14.51371286], 14 | [ 11.13563815, 10.14933498, 14.51532174], 15 | [ 13.86597088, 10.14847010, 14.51428049], 16 | [ 12.50012880, 7.90943392, 14.51976956], 17 | [ 12.50372460, 12.50075283, 14.72163059], 18 | [ 9.78440676, 17.09766453, 14.48773211], 19 | [ 15.22295554, 17.09739644, 14.48602752], 20 | [ 7.15981020, 12.55477124, 14.48660210], 21 | [ 17.84482988, 12.55353408, 14.48367771], 22 | [ 12.50374400, 17.08727980, 14.47394451], 23 | [ 9.87605186, 7.84598863, 14.48403817], 24 | [ 15.12400216, 7.84505696, 14.48361730], 25 | [ 8.52637045, 10.20520181, 14.47173998], 26 | [ 16.47553419, 10.20431563, 14.47057725], 27 | [ 12.50162082, 15.62744811, 12.44805426], 28 | [ 9.78981284, 10.93427811, 12.44606936], 29 | [ 15.21142132, 10.93350182, 12.44513778], 30 | [ 9.80328010, 15.61779801, 12.45193423], 31 | [ 15.19879468, 15.61737840, 12.45016375], 32 | [ 8.44957785, 13.27629042, 12.45064043], 33 | [ 16.55283128, 13.27448455, 12.44803144], 34 | [ 11.14706080, 8.60486927, 12.44908613], 35 | [ 13.85249392, 8.60483110, 12.44875320], 36 | [ 11.14080909, 13.28417801, 12.37402178], 37 | [ 13.86129087, 13.28384618, 12.37357051], 38 | [ 12.50040244, 10.93013268, 12.37344562], 39 | [ 11.16790993, 17.86382119, 12.37953773], 40 | [ 13.83623659, 17.86393157, 12.37839810], 41 | [ 7.18532081, 10.97162350, 12.37640674], 42 | [ 17.81618039, 10.96917629, 12.37482430], 43 | [ 8.52043182, 8.66069151, 12.37565154], 44 | [ 16.47890651, 8.65897510, 12.37489045], 45 | [ 7.19477108, 15.56239596, 12.31904726], 46 | [ 17.80774841, 15.56122995, 12.31656077], 47 | [ 12.49966163, 6.37471536, 12.31590153], 48 | [ 8.55158958, 17.88809068, 12.32062468], 49 | [ 16.45265851, 17.88723731, 12.31870385], 50 | [ 5.85767123, 13.22339656, 12.31734762], 51 | [ 19.14459556, 13.22189528, 12.31494919], 52 | [ 9.80713808, 6.38527824, 12.31505608], 53 | [ 15.19009880, 6.38373013, 12.31477027], 54 | [ 7.17419958, 18.59601593, 10.22637496], 55 | [ 17.82830097, 18.59530226, 10.22321914], 56 | [ 4.55461164, 14.05906469, 10.22249110], 57 | [ 20.44650799, 14.05754717, 10.21944311], 58 | [ 8.42136455, 16.41006373, 10.18936218], 59 | [ 16.58069447, 16.40942145, 10.18738731], 60 | [ 12.50057691, 14.05937074, 10.21535316], 61 | [ 9.87962931, 4.83952796, 10.21780715], 62 | [ 15.11771081, 4.83864890, 10.21828204], 63 | [ 11.14849921, 11.71880557, 10.21433043], 64 | [ 13.85197245, 11.71839398, 10.21388722], 65 | [ 7.07163033, 14.07557769, 10.18966559], 66 | [ 17.92981245, 14.07451466, 10.18715058], 67 | [ 11.15032078, 7.01258145, 10.18585555], 68 | [ 13.84805427, 7.01260553, 10.18468742], 69 | [ 11.15374139, 16.38258017, 10.19406419], 70 | [ 13.84797712, 16.38262181, 10.19305577], 71 | [ 8.46142283, 11.72200026, 10.19193337], 72 | [ 16.53912952, 11.72137050, 10.19082751], 73 | [ 9.80868275, 9.39175408, 10.19042848], 74 | [ 15.19121513, 9.39139801, 10.19000713], 75 | [ 12.50135228, 18.62698462, 10.16962569], 76 | [ 7.19030646, 9.43427206, 10.16393883], 77 | [ 17.80928245, 9.43264096, 10.16320550], 78 | [ 9.81079791, 18.65246946, 10.15161108], 79 | [ 15.19173033, 18.65258132, 10.15047131], 80 | [ 5.82378702, 11.74973673, 10.14719363], 81 | [ 19.17687861, 11.74901365, 10.14552497], 82 | [ 8.51399694, 7.09243078, 10.14437820], 83 | [ 16.48462386, 7.09196221, 10.14483167], 84 | [ 9.86853781, 14.01808792, 10.15838631], 85 | [ 15.13244188, 14.01737556, 10.15760583], 86 | [ 12.49981106, 9.46102591, 10.15664749], 87 | [ 5.85053309, 16.33653652, 10.14074533], 88 | [ 19.15069695, 16.33600992, 10.13783351], 89 | [ 12.49931777, 4.82427576, 10.13718242], 90 | [ 7.18523207, 17.13677427, 8.01539152], 91 | [ 17.81493362, 17.13612020, 8.01291170], 92 | [ 5.82590638, 14.78219838, 8.01390731], 93 | [ 19.17465308, 14.78132898, 8.01158728], 94 | [ 11.14006478, 5.58027740, 8.01015883], 95 | [ 13.85860959, 5.58043958, 8.00916219], 96 | [ 8.53147710, 19.37002966, 8.00455541], 97 | [ 16.46920527, 19.36960314, 8.00259121], 98 | [ 8.46738535, 14.82637476, 8.00658441], 99 | [ 16.53288730, 14.82600301, 8.00537653], 100 | [ 11.13861128, 14.84751514, 8.00240172], 101 | [ 13.86148623, 14.84720046, 8.00199886], 102 | [ 12.49994745, 12.50006125, 8.00063110], 103 | [ 9.78416859, 17.21308386, 7.99515119], 104 | [ 15.21588849, 17.21290637, 7.99420108], 105 | [ 4.56377466, 12.49940921, 7.99904840], 106 | [ 20.43610028, 12.49779898, 7.99698832], 107 | [ 12.49920704, 7.84559494, 8.00242003], 108 | [ 7.05812000, 12.49413290, 7.99278396], 109 | [ 17.94178450, 12.49358184, 7.99141504], 110 | [ 9.78582520, 12.50421909, 8.00089516], 111 | [ 15.21413615, 12.50369827, 8.00052122], 112 | [ 12.50007180, 17.15587369, 7.99900446], 113 | [ 11.14649591, 10.14802062, 7.99941063], 114 | [ 13.85314391, 10.14774254, 7.99948145], 115 | [ 9.77481016, 7.79245421, 7.98959054], 116 | [ 15.22469429, 7.79201704, 7.98943559], 117 | [ 8.46632515, 10.17202968, 7.99540983], 118 | [ 8.53256540, 5.62907836, 7.99458204], 119 | [ 16.46612157, 5.62801086, 7.99582303], 120 | [ 16.53337285, 10.17092209, 7.99467923], 121 | [ 11.13544681, 19.42130452, 7.97773530], 122 | [ 13.86508896, 19.42136867, 7.97785955], 123 | [ 5.82074273, 10.21941636, 7.97126648], 124 | [ 19.17882835, 10.21844766, 7.97010409], 125 | [ 7.18631774, 7.85639597, 7.96997322], 126 | [ 17.81284174, 7.85499234, 7.97028496]] 127 | 128 | # hlcluster.py inputfile.gjf -n +n n-n 129 | 130 | lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective = VASP.read_poscar('POSCAR') 131 | with open(sys.argv[1]) as IN: 132 | input_file = IN.readlines() 133 | space = re.compile(r'\s+') 134 | a = int(sys.argv[2]) - 1 135 | b = int(sys.argv[3]) - 1 136 | temp = sys.argv[4].split('-') 137 | c = int(temp[0]) - 1 138 | d = int(temp[1]) 139 | 140 | gjfcoord = [] 141 | for i in xrange(5, len(input_file)): 142 | if input_file[i].strip() == '': 143 | break 144 | line = space.split(input_file[i].strip()) 145 | gjfcoord.append([float(line[1]), float(line[2]), float(line[3]), line[0]]) 146 | 147 | coor = [] 148 | elements = elements[:1] 149 | num_atoms = num_atoms[:1] 150 | prev_element = '' 151 | for i in xrange(c, d): 152 | if gjfcoord[i][3] != prev_element: 153 | elements.append(gjfcoord[i][3]) 154 | prev_element = gjfcoord[i][3] 155 | num_atoms.append(1) 156 | else: 157 | num_atoms[-1] += 1 158 | 159 | v1 = gjfcoord[i][0] - gjfcoord[a][0] + pos1[b][0] 160 | v2 = gjfcoord[i][1] - gjfcoord[a][1] + pos1[b][1] 161 | v3 = gjfcoord[i][2] - gjfcoord[a][2] + pos1[b][2] 162 | pos1.append([v1, v2, v3]) 163 | 164 | 165 | VASP.write_poscar('POSCAR', lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, pos1, selective) 166 | -------------------------------------------------------------------------------- /ic2cc.pl: -------------------------------------------------------------------------------- 1 | #!/bin/env perl 2 | use strict; 3 | use warnings; 4 | use vars qw($num $coor $c_coor $line); 5 | use Math::Trig; 6 | 7 | #cross product 8 | sub cross{ 9 | my $v1 = shift; 10 | my $v2 = shift; 11 | my $v; 12 | $v->[0] = $v1->[1] * $v2->[2] - $v2->[1] * $v1->[2]; 13 | $v->[1] = $v2->[0] * $v1->[2] - $v1->[0] * $v2->[2]; 14 | $v->[2] = $v1->[0] * $v2->[1] - $v2->[0] * $v1->[1]; 15 | return $v; 16 | } 17 | 18 | sub dot{ 19 | my $v1 = shift; 20 | my $v2 = shift; 21 | return $v1->[0] * $v2->[0] + $v1->[1] * $v2->[1] + $v1->[2] * $v2->[2]; 22 | } 23 | 24 | #scalar x vector 25 | sub scalvect{ 26 | my $scal = shift; 27 | my $v = shift; 28 | my $vresult; 29 | for(my $i = 0; $i <= 2; $i++){ 30 | $vresult->[$i] = $scal * $v->[$i]; 31 | } 32 | return $vresult; 33 | } 34 | 35 | sub add{ 36 | my $v1 = shift; 37 | my $v2 = shift; 38 | my $v; 39 | for(my $i = 0; $i <= 2; $i++){ 40 | $v->[$i] = $v1->[$i] + $v2->[$i]; 41 | } 42 | return $v; 43 | } 44 | 45 | sub subtract{ 46 | my $v1 = shift; 47 | my $v2 = shift; 48 | my $v; 49 | for(my $i = 0; $i <= 2; $i++){ 50 | $v->[$i] = $v1->[$i] - $v2->[$i]; 51 | } 52 | return $v; 53 | } 54 | 55 | #Rodrigues' rotation formula 56 | sub ro_rotation{ 57 | my $rotatev = shift; 58 | my $beta = shift; 59 | my $point = shift; 60 | my $unit; 61 | 62 | $beta = deg2rad($beta); 63 | 64 | #unit 65 | my $len = sqrt(dot($rotatev, $rotatev)); 66 | for(my $i = 0; $i <= 2; $i++){ 67 | $unit->[$i] = $rotatev->[$i] / $len; 68 | } 69 | 70 | my $first = scalvect(cos($beta), $point); 71 | my $sec = scalvect(sin($beta), cross($unit, $point)); 72 | my $third = scalvect(dot($unit, $point) * (1 - cos($beta)), $unit); 73 | 74 | return add($first, add($sec, $third)); 75 | } 76 | 77 | #use NeRF Method 78 | sub innertoc{ 79 | my $coor1 = shift; #distance 80 | my $coor2 = shift; #angle between tow bonds 81 | my $coor3 = shift; #dihedral angle 82 | my $inner_coo = shift; 83 | my $coor; 84 | 85 | #First, placing the new atom a bond length away from the previous atom in line 86 | #with the previous bond axis 87 | 88 | #unit 89 | my $vect12 = subtract($coor1, $coor2); 90 | my $len = sqrt(dot($vect12, $vect12)); 91 | my $unit; 92 | for(my $i = 0; $i <= 2; $i++){ 93 | $unit->[$i] = $vect12->[$i] / $len; 94 | } 95 | #add unit*distance to atom1 to get the new atom 96 | for(my $i = 0; $i <= 2; $i++){ 97 | $coor->[$i] = $unit->[$i] * $inner_coo->[0] + $coor1->[$i]; 98 | } 99 | 100 | #Second, put atoms to the origin of the coordinate 101 | my $trans_coor = $coor1; 102 | my $coor1_re = subtract($coor1, $trans_coor); 103 | my $coor2_re = subtract($coor2, $trans_coor); 104 | my $coor3_re = subtract($coor3, $trans_coor); 105 | my $coor_re = subtract($coor, $trans_coor); 106 | 107 | #rotate the new atom, setting the angle between the two bonds 108 | #normal vector 109 | my $normal = cross(subtract($coor2, $coor3), subtract($coor1, $coor2)); 110 | $coor_re = ro_rotation($normal, 180 - $inner_coo->[1], $coor_re); 111 | 112 | #rotate the new atom arount the vect atom1-atom2 113 | $coor_re = ro_rotation(subtract($coor1_re, $coor2_re), $inner_coo->[2], $coor_re); 114 | 115 | return add($coor_re, $trans_coor); 116 | } 117 | 118 | if(!defined($ARGV[0])){ 119 | print "Usage: ic2cc.pl coordinate_file\n"; 120 | print "The first three line in coordinate_file must be cartesian coordinate.\n"; 121 | print "Please try again!\n"; 122 | print "\n"; 123 | die; 124 | } 125 | 126 | open COOR, '<', $ARGV[0] or die "cannot open file $ARGV[0]: $!\n"; 127 | open OUT, '>', $ARGV[0].".car" or die "cannot creat file output: $!\n"; 128 | 129 | 130 | #read coordinates 131 | $num= 0; 132 | while(defined($line = )){ 133 | chomp($line); 134 | $line =~ s/^\s+//; 135 | last if $line =~ /^$/; 136 | $num++; 137 | if($num <= 3){ 138 | my @tmp = split(/\s+/, $line); 139 | for(my $i = 0; $i <= 3; $i++){ 140 | $coor->[$num - 1][$i] = $tmp[$i]; 141 | } 142 | }else{ 143 | my @tmp = split(/\s+/, $line); 144 | for(my $i = 0; $i <= 6; $i++){ 145 | $coor->[$num - 1][$i] = $tmp[$i]; 146 | } 147 | } 148 | } 149 | 150 | die "Wrong coordinates\n" if($num < 4); 151 | 152 | for(my $i = 0; $i <=2; $i++){ 153 | $c_coor->[$i] = $coor->[$i]; 154 | } 155 | 156 | #Convert coordinates 157 | for(my $i = 3; $i < $num; $i++){ 158 | my $coor1; 159 | my $coor2; 160 | my $coor3; 161 | my $inner; 162 | for(my $j = 0; $j <= 2; $j++){ 163 | $coor1->[$j] = $c_coor->[$coor->[$i][1] - 1][$j + 1]; 164 | $coor2->[$j] = $c_coor->[$coor->[$i][3] - 1][$j + 1]; 165 | $coor3->[$j] = $c_coor->[$coor->[$i][5] - 1][$j + 1]; 166 | } 167 | 168 | $inner->[0] = $coor->[$i][2]; 169 | $inner->[1] = $coor->[$i][4]; 170 | $inner->[2] = $coor->[$i][6]; 171 | 172 | $c_coor->[$i][0] = $coor->[$i][0]; 173 | my $tmp = innertoc($coor1, $coor2, $coor3, $inner); 174 | for(my $j = 1; $j <= 3; $j++){ 175 | $c_coor->[$i][$j] = $tmp->[$j - 1]; 176 | } 177 | } 178 | 179 | for(my $i = 0; $i < $num; $i++){ 180 | printf OUT "%2s %20.16f %20.16f %20.16f\n", $c_coor->[$i][0], 181 | $c_coor->[$i][1], $c_coor->[$i][2], $c_coor->[$i][3]; 182 | } 183 | print OUT "\n"; 184 | 185 | close(COOR); 186 | close(OUT); 187 | -------------------------------------------------------------------------------- /isWorkFinished.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | echo "" 3 | if [ -e output ] 4 | then 5 | result=`tail -20 output |grep "reached required accuracy"` 6 | if [ "$result" != "" ] 7 | then 8 | echo "YES" 9 | echo "" 10 | else 11 | echo "NO" 12 | echo "" 13 | fi 14 | elif [ "$1" != "" ] 15 | then 16 | for i in $@ 17 | do 18 | for j in `find $i -name output |sort` 19 | do 20 | echo "$j" 21 | result=`tail -20 $j |grep "reached required accuracy"` 22 | if [ "$result" != "" ] 23 | then 24 | echo "YES" 25 | echo "" 26 | else 27 | echo "NO" 28 | echo "" 29 | fi 30 | done 31 | done 32 | else 33 | for i in `find ./ -name output| sort` 34 | do 35 | echo "$i" 36 | result=`tail -20 $i |grep "reached required accuracy"` 37 | if [ "$result" != "" ] 38 | then 39 | echo "YES" 40 | echo "" 41 | else 42 | echo "NO" 43 | echo "" 44 | fi 45 | done 46 | fi 47 | 48 | -------------------------------------------------------------------------------- /modemake.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | import re 5 | 6 | if len(sys.argv) != 3: 7 | print('') 8 | print("Usage: %s freqfile scale" % sys.argv[0]) 9 | print("Please try again!") 10 | print('') 11 | exit(0) 12 | 13 | print('') 14 | with open(sys.argv[1]) as input_file: 15 | content = input_file.readlines() 16 | scale = float(sys.argv[2]) 17 | 18 | with open('MODECAR', 'w') as output_file: 19 | length = len(content) 20 | space = re.compile(r'\s+') 21 | for i in range(2, length): 22 | line = content[i].strip() 23 | if line == "": 24 | break 25 | line = list(map(float, space.split(line))) 26 | output_file.write("%10.5f %10.5f %10.5f\n" % (line[3] * scale, line[4] * scale, line[5] * scale)) 27 | 28 | print(" --------------------Done--------------------") 29 | print('') 30 | -------------------------------------------------------------------------------- /mvall: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in `ls -1` 3 | do 4 | if [ -d $i ];then 5 | continue 6 | fi 7 | mv $i $1 8 | done 9 | -------------------------------------------------------------------------------- /mycp: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cp $1/CONTCAR ./POSCAR 3 | dir2car.pl POSCAR 4 | mv POSCAR-C.vasp POSCAR 5 | vas2gv.pl POSCAR 6 | cpfile $1 7 | -------------------------------------------------------------------------------- /mysort.pl: -------------------------------------------------------------------------------- 1 | #!/bin/env perl 2 | use warnings; 3 | use strict; 4 | use vars qw($line %element @ele_order); 5 | 6 | open IN, '<', $ARGV[0]; 7 | 8 | while(defined($line = )){ 9 | $line =~ s/^\s+//; 10 | my @tmp = split(/\s+/, $line); 11 | 12 | if(exists $element{$tmp[0]}){ 13 | push(@{$element{$tmp[0]}}, $line); 14 | }else{ 15 | push(@{$element{$tmp[0]}}, $line); 16 | push(@ele_order, $tmp[0]); 17 | } 18 | 19 | } 20 | close(IN); 21 | 22 | open OUT, '>', $ARGV[0]; 23 | for(my $i = 0; $i < @ele_order; $i++){ 24 | print OUT @{$element{$ele_order[$i]}}; 25 | } 26 | close(OUT); 27 | -------------------------------------------------------------------------------- /neb2dim.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | #;-*- Perl -*- 3 | 4 | # Set up a dimer saddle point search from a NEB run. 5 | # Assume for now that the run as been stopped and vfin.pl run so the 6 | # configuration is contain in POSCARs and not CONTCAR. 7 | # If there is an input argument then it the image number to be used. 8 | 9 | use FindBin qw($Bin); 10 | use lib "$Bin"; 11 | 12 | if($ARGV[0]) { 13 | $i = $ARGV[0]; 14 | $f = 0; 15 | } else { 16 | # Select the image from the exts.dat file 17 | open EXT , "exts.dat" 18 | or die " NO EXTS.DAT IN THIS DIRECTORY; RUN nebresults.pl \n"; 19 | @ext = ; 20 | close EXT; 21 | chomp(@ext); 22 | $n = @ext; 23 | $max = -1.0; 24 | for($i=0; $i<$n; $i++) { 25 | $t = $ext[$i]; 26 | $t =~ s/^\s+//g; 27 | @t = split /\s+/,$t; 28 | if($t[8] > $max) { 29 | $max = $t[8]; 30 | $im = $t[5]; 31 | } 32 | } 33 | $i = int($im); 34 | $f = $im - $i; 35 | if($im<=0) { 36 | $i=0; 37 | $f=0; 38 | } 39 | } 40 | print "\n FORMING DIMER BETWEEN IMAGES ",$i," and ",$i+1,"\n\n"; 41 | 42 | die "NUMBER OF IMAGES MUST BE LESS THAN 99 FOR NOW ! \n" if $i >= 99; 43 | 44 | $d1 = sprintf "%02d",$i; 45 | $d2 = sprintf "%02d",$i+1; 46 | open (DIST, "$Bin/dist.pl $d1/POSCAR $d2/POSCAR |"); 47 | $d12 = ; 48 | close DIST; 49 | $d12>0 || die "ZERO DISTANCE BETWEEN IMAGES ",$i1," AND ",$i2,"\n"; 50 | $NdR = 5e-3; 51 | $f1 = $f - $NdR/$d12; 52 | $f2 = $f + $NdR/$d12; 53 | 54 | # Generate the dimer POSCARs. 55 | 56 | system "$Bin/posinterp.pl $d1/POSCAR $d2/POSCAR $f1 > /dev/null"; 57 | rename "POSCAR.out" , "POSCAR1"; 58 | system "$Bin/posinterp.pl $d1/POSCAR $d2/POSCAR $f2 > /dev/null"; 59 | rename "POSCAR.out" , "POSCAR2"; 60 | system "$Bin/posinterp.pl $d1/POSCAR $d2/POSCAR $f > /dev/null"; 61 | rename "POSCAR.out" , "POSCAR"; 62 | 63 | $dir = "dim"; 64 | mkdir $dir ; # mkdir "$dir/01" ; mkdir "$dir/02"; 65 | system "cp INCAR KPOINTS $dir"; 66 | if(-e "POTCAR") { 67 | system "cp POTCAR $dir"; 68 | } elsif(-e "../POTCAR") { 69 | system "cp ../POTCAR $dir"; 70 | } 71 | system "$Bin/modemake.pl POSCAR1 POSCAR2 ; mv MODECAR $dir ; mv POSCAR $dir"; 72 | # system "cp POSCAR1 $dir/01/POSCAR" ; 73 | # system "cp POSCAR2 $dir/02/POSCAR" ; 74 | print " FOR DIMER, REMEMBER TO SET IN THE INCAR: \n\n"; 75 | print "ICHAIN = 2 \n"; 76 | print "IOPT = 2 \n"; 77 | print "IBRION = 3 \n"; 78 | print "POTIM = 0.0 \n"; 79 | print "EDIFF = 1E-7 \n \n"; 80 | print "DdR (DEFAULT = 5E-3) \n"; 81 | print "DRotMax (DEFAULT = 4) \n"; 82 | print "DFNMax (DEFAULT = 1.0) \n"; 83 | print "DFNMin (DEFAULT = 0.01) \n\n"; 84 | 85 | unlink glob "POSCAR1"; 86 | unlink glob "POSCAR2"; 87 | 88 | -------------------------------------------------------------------------------- /nebbarrier.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | #;-*- Perl -*- 3 | 4 | use FindBin qw($Bin); 5 | use lib "$Bin"; 6 | use Vasp; 7 | 8 | open NEB , ">neb.dat" ; 9 | 10 | @args = @ARGV; 11 | if (@args==0) { 12 | opendir(DIR,".") or die "couldn't open . ($!)\n"; 13 | @list = readdir(DIR); 14 | closedir(DIR); 15 | 16 | @directories = grep {-d && /^[0-9][0-9]$/i} @list; 17 | @directories = sort {$a<=>$b} @directories; 18 | } else { 19 | @directories = @args; 20 | } 21 | # check for ssneb 22 | $ssneb_flag = `grep 'LNEBCELL' 01/OUTCAR|tail -1`; 23 | @ssneb_flag = split(/\s+/,$ssneb_flag); 24 | $ssneb_flag = $ssneb_flag[@ssneb_flag-1]; 25 | $nions = `grep 'NIONS' 01/OUTCAR|tail -1`; 26 | @nions = split(/\s+/,$nions); 27 | $nions = $nions[@nions-1]; 28 | 29 | if ($ssneb_flag =~ /T/){ 30 | open NEBSS , ">nebss.dat" ; 31 | #print "$ssneb_flag \n"; 32 | } 33 | 34 | # print "#Directories found: ".join(" ",@directories)."\n"; 35 | 36 | $dist_cum = 0; 37 | for ($i=0; $i<@directories; $i++) { 38 | (-e "$directories[$i]/OUTCAR") || die "No OUTCAR in $directories[$i]!\n"; 39 | 40 | $energy = `grep 'energy w' $directories[$i]/OUTCAR|tail -1`; 41 | # $dist = `grep 'NEB: distance' $directories[$i]/OUTCAR|tail -1`; 42 | $force = `grep 'NEB: projections' $directories[$i]/OUTCAR|tail -1`; 43 | if ($ssneb_flag =~ /T/){ 44 | $force = `grep 'NEBCELL: projections' $directories[$i]/OUTCAR|tail -1`; 45 | }; 46 | 47 | $energy =~ s/\s+$//g; 48 | @energy = split(/\s+/,$energy); 49 | $energy = $energy[@energy-1]; 50 | 51 | if ($i==0) { $energy0 = $energy; } 52 | $energy -= $energy0; 53 | 54 | if ($i>0) { 55 | if (-e "$directories[$i]/CONTCAR") { 56 | $file1 = "$directories[$i]/CONTCAR"; 57 | } else { 58 | $file1 = "$directories[$i]/POSCAR"; 59 | } 60 | if (-e "$directories[$i-1]/CONTCAR") { 61 | $file2 = "$directories[$i-1]/CONTCAR"; 62 | } else { 63 | $file2 = "$directories[$i-1]/POSCAR"; 64 | } 65 | $dist = `$Bin/dist.pl $file1 $file2`; 66 | if ($ssneb_flag =~ /T/){ 67 | if($i == @directories-1){ 68 | $dist = $dist1[@dist1-2]; 69 | } else{ 70 | $dist1 = `grep 'NEBCELL: distance' $directories[$i]/OUTCAR|tail -1`; 71 | @dist1 = split(/\s+/,$dist1); 72 | $dist = $dist1[@dist1-3];} 73 | } 74 | } else { 75 | $dist = 0; 76 | } 77 | 78 | @force = split(/\s+/,$force); 79 | $force = $force[@force-1]; 80 | 81 | $dist_cum += $dist; 82 | 83 | if ($ssneb_flag !~ /T/){ 84 | # Get the coordinates to find the local tangent for the end images 85 | if($i == 0) { 86 | if (-e "$directories[$i]/CONTCAR") { 87 | $file1 = "$directories[$i]/CONTCAR"; 88 | } else { 89 | $file1 = "$directories[$i]/POSCAR"; 90 | } 91 | if (-e "$directories[$i+1]/CONTCAR") { 92 | $file2 = "$directories[$i+1]/CONTCAR"; 93 | } else { 94 | $file2 = "$directories[$i+1]/POSCAR"; 95 | } 96 | $ocar = "$directories[$i]/OUTCAR"; 97 | $force = `$Bin/nebforces.pl $file1 $file2 $ocar`; 98 | } elsif($i == @directories-1) { 99 | if (-e "$directories[$i]/CONTCAR") { 100 | $file1 = "$directories[$i]/CONTCAR"; 101 | } else { 102 | $file1 = "$directories[$i]/POSCAR"; 103 | } 104 | if (-e "$directories[$i-1]/CONTCAR") { 105 | $file2 = "$directories[$i-1]/CONTCAR"; 106 | } else { 107 | $file2 = "$directories[$i-1]/POSCAR"; 108 | } 109 | $ocar = "$directories[$i]/OUTCAR"; 110 | $force = `$Bin/nebforces.pl $file1 $file2 $ocar`; 111 | } 112 | } 113 | printf NEB "%3i %12.6f %12.6f %12.6f %3i\n",$i,$dist_cum,$energy,$force,$directories[$i]; 114 | if ($ssneb_flag =~ /T/){ 115 | printf NEBSS "%3i %12.6f %12.6f %12.6f %3i\n",$i,$dist_cum/sqrt($nions),$energy/$nions,$force/sqrt($nions),$directories[$i]; 116 | } 117 | } 118 | #print "nebbarrier.pl done \n"; 119 | close NEB; 120 | if ($ssneb_flag !~ /T/){close NEBSS;} 121 | 122 | -------------------------------------------------------------------------------- /nebclc: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | echo "" 3 | echo "" 4 | echo "###############This script will remove all CHG CHHCAR WAVECAR###############" 5 | echo "" 6 | echo "" 7 | #read -p "number of images: " n 8 | n=16 9 | for((i=0;i<=$(($n+1));i=i+1)) 10 | do 11 | if [ $i -lt 10 ]; 12 | then 13 | [ -e ./0$i/CHG ] &&rm ./"0$i"/CHG 14 | [ -e ./0$i/CHGCAR ] &&rm ./"0$i"/CHGCAR 15 | [ -e ./0$i/WAVECAR ] &&rm ./"0$i"/WAVECAR 16 | else 17 | [ -e ./$i/CHG ] &&rm ./"$i"/CHG 18 | [ -e ./$i/CHGCAR ] &&rm ./"$i"/CHGCAR 19 | [ -e ./$i/WAVECAR ] &&rm ./"$i"/WAVECAR 20 | fi 21 | done 22 | rm vasprun.xml *.xyz 23 | echo "" 24 | -------------------------------------------------------------------------------- /nebef.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | #;-*- Perl -*- 3 | 4 | # Script prints the force, energy etc of OUTCAR's in immediate subdir 5 | # of present working directory. 6 | 7 | use Cwd; 8 | 9 | $dir = cwd; 10 | $outlist =`ls -1 "$dir"/[0-9][0-9]/OUTCAR`; #specifies location of OUTCARs 11 | @outlist = split("\n",$outlist); 12 | 13 | $i = 0; 14 | foreach $outfile (@outlist) { 15 | $energy = `grep 'energy without' "$outfile" | tail -n 1 |cut -c 67-78`; 16 | $force = `grep 'max\ at' "$outfile" | tail -n 1 |cut -c 27-38`; 17 | if(!$i) { $e0 = $energy; } 18 | $rel = $energy - $e0; 19 | @f4 = ($i,$force,$energy,$rel); 20 | printf "%4i %16.6f %16.6f %16.6f \n",@f4; 21 | $i++; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /nebforce.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | ################################################################################ 3 | # The tangential force analyzer for NEB calculation by VASP # 4 | ################################################################################ 5 | 6 | #This script generates the tangential force profile for the NEB calculation by VASP 7 | #This script is based on the work from the Computational Heterogeneous Catalysis group at the Nankai University 8 | #writen by sky from Energy & Environmental Catalysis Research Group of Nankai University 9 | #ver 1.0 10 | #this is for the original VASP code 11 | #this script can noly be used in python2. 12 | #if you want to use it in python3, you only need to change grammar of "print" in the end of the script 13 | 14 | import os 15 | import sys 16 | import subprocess 17 | 18 | 19 | def die_out(a): 20 | print "Error occurred in "+a 21 | print "This may possibly due to the fact that the information had not been output by VASP yet." 22 | print "Please try later" 23 | sys.exit(1) 24 | 25 | 26 | def readlist(tmp_file,list_name,field): 27 | try: 28 | in_buf = tmp_file.readline() 29 | except: 30 | die_out("reading and parsing the computational result.") 31 | if (len(in_buf)==0): 32 | die_out("reading and parsing the computational result.") 33 | tmp_file.seek(0) 34 | try: 35 | for in_buf in tmp_file.readlines(): 36 | in_buf = in_buf.split() 37 | list_name.append(in_buf[field]) 38 | except: 39 | die_out("reading and parsing the computational result.") 40 | 41 | #welcome 42 | print "********************************************************************************" 43 | print "* The tangential force analyzer for NEB calculation by VASP *" 44 | print "********************************************************************************" 45 | 46 | print "by the Energy & Environmental Catalysis Research Group of Nankai University" 47 | print "based on Energetic profile generator" 48 | print "which comes from Computational Heterogeneous Catalysis group at the Nankai University" 49 | print "Version 1.0" 50 | print 51 | print 52 | 53 | 54 | #get the number of image points 55 | while True: 56 | in_buf=raw_input( "Please type in the number of image points in your simulation:") 57 | try: 58 | images=int(eval(in_buf)) 59 | break 60 | except: 61 | print "Invalid value, type again!" 62 | continue 63 | 64 | while True: 65 | in_filename=raw_input( "you need to creat a file to save information, please type in a file name:") 66 | try: 67 | f=open(in_filename,'w') 68 | break 69 | except: 70 | print "failed to creat file, try again!" 71 | continue 72 | 73 | #information acquisition 74 | line_number = ['0'] 75 | energy_list = ['0'] 76 | tangential_list = ['0'] 77 | 78 | for i in xrange(1,(images+1),1): 79 | folder_name = "./%2.2d" % i 80 | try: 81 | os.chdir(folder_name) 82 | 83 | if os.path.isfile('OUTCAR'): 84 | print "OUTCAR successfully spotted in folder %2.2d." % i 85 | outcar_zipped = False 86 | elif os.path.isfile('OUTCAR.gz'): 87 | print "OUTCAR.gz successfully spotted. It would be unzipped temporarily in folder %2.2d." % i 88 | gunzip_outcar = subprocess.Popen(['gunzip','OUTCAR.gz']) 89 | gunzip_outcar.wait() 90 | outcar_zipped = True 91 | else: 92 | die_out('opening the file OUTCAR.') 93 | 94 | #creat energy list 95 | os.system("grep -n 'energy without' OUTCAR > prof_tmp_ene_all") 96 | prof_tmp_ene_all = open("prof_tmp_ene_all",mode='r') 97 | energy_tmp_list = [] 98 | readlist(prof_tmp_ene_all,energy_tmp_list,4) 99 | energy_list.append(energy_tmp_list) 100 | line_tmp_list = [] 101 | prof_tmp_ene_all.seek(0) 102 | readlist(prof_tmp_ene_all,line_tmp_list,0) 103 | line_number.append(line_tmp_list) 104 | prof_tmp_ene_all.close() 105 | 106 | 107 | #reading the projections onto the tangent 108 | os.system("grep 'tangential force (eV/A)' OUTCAR >prof_tmp_tan_all") 109 | prof_tmp_tan_all = open('prof_tmp_tan_all',mode='r') 110 | tangential_tmp_list = [] 111 | readlist(prof_tmp_tan_all,tangential_tmp_list,3) 112 | tangential_list.append(tangential_tmp_list) 113 | prof_tmp_tan_all.close() 114 | 115 | 116 | os.system("rm -f prof_tmp_*") 117 | 118 | if outcar_zipped: 119 | os.system("gzip OUTCAR") 120 | print "The file OUTCAR had been successfully gzipped back in folder %2.2d!" % i 121 | 122 | 123 | os.chdir("..") 124 | except: 125 | die_out("reading and parsing the result in folder %2.2d." % i) 126 | 127 | 128 | #information output 129 | 130 | min=10.0 131 | min_index=0 132 | min_distance=10 133 | min_distance_index=0 134 | n=len(line_number[1]) 135 | print >>f, " %.10s %.10s" % ("energy","tangential") 136 | print " %.10s %.10s" % ("energy","tangential") 137 | for i in xrange(0,n,1): 138 | print >>f, "steps:%d" % (i+1) 139 | print "steps:%d" % (i+1) 140 | for j in xrange(1,(images+1),1): 141 | print >>f, "folder%2.2d %10s %12.10f %12.10s" % (j,line_number[j][i],eval(energy_list[j][i]),eval(tangential_list[j][i])) 142 | print "folder%2.2d %10s %12.10f %12.10s" % (j,line_number[j][i],eval(energy_list[j][i]),eval(tangential_list[j][i])) 143 | if abs(float(tangential_list[j][i])-0) < min: 144 | min=abs(float(tangential_list[j][i])) 145 | min_index=i 146 | if float(tangential_list[1][i]) < 0 and float(tangential_list[images][i]) > 0: 147 | for j in xrange(1,(images+1),1): 148 | if float(tangential_list[j][i]) < 0 and float(tangential_list[j+1][i]) > 0 and (float(tangential_list[j+1][i]) - float(tangential_list[j][i])) < min_distance: 149 | min_distance=float(tangential_list[j+1][i]) - float(tangential_list[j][i]) 150 | min_distance_index=i 151 | 152 | print >>f, "" 153 | print "" 154 | print >>f, "The minimum tangential force is in steps:%d The value is:%f" % (min_index+1,min) 155 | print >>f, "Transition state may be in steps:%d The value is:%f" % (min_distance_index+1,min_distance) 156 | print "The minimum tangential force is in steps:%d The value is:%f" % (min_index+1,min) 157 | print "Transition state may be in steps:%d The value is:%f" % (min_distance_index+1,min_distance) 158 | f.close() 159 | print "" 160 | print "Result has been saved in", in_filename 161 | print "" 162 | -------------------------------------------------------------------------------- /nebgjf2vas.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | import os 5 | 6 | if len(sys.argv) < 2: 7 | print('') 8 | print('Usage: %s POSCAR gjf_file1 gjf_file2 ...' % sys.argv[0].split('/')[-1]) 9 | print('') 10 | exit(1) 11 | 12 | 13 | print('############### Replacing images with gvfile ###############') 14 | print('') 15 | os.system('gjf2vas.py %s > /dev/null' % (' '.join(sys.argv[1:]))) 16 | folder_id = 1 17 | for gjf_file in sys.argv[2:]: 18 | print('%28s → %02d' % (gjf_file, folder_id)) 19 | vasp_file = '%s.vasp' % gjf_file[:-4] 20 | os.system('mv %s %02d/POSCAR' % (vasp_file, folder_id)) 21 | folder_id += 1 22 | 23 | print('') 24 | print(' ############### DONE ###############\n') 25 | -------------------------------------------------------------------------------- /nebinfo: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | echo "" 3 | echo "" 4 | echo "############ All CONTACRs and POSCARs in packege will be converted to cartesian file ############" 5 | echo "" 6 | echo "" 7 | 8 | read -p "The number of images:" n 9 | echo "" 10 | echo "############################# Processing #############################" 11 | echo "" 12 | mkdir vaspfile gvfile movie 13 | 14 | for i in `seq -f '%02g' 0 $(($n+1))` 15 | do 16 | if [ -e ./$i/CONTCAR ] 17 | then 18 | cat ./$i/CONTCAR >./vaspfile/CONTCAR-$i 19 | cat ./$i/CONTCAR >./gvfile/CONTCAR-$i 20 | cat ./$i/CONTCAR >./movie/CONTCAR-$i 21 | fi 22 | 23 | if [ -e ./$i/POSCAR ] 24 | then 25 | cat ./$i/POSCAR >./vaspfile/POSCAR-$i 26 | cat ./$i/POSCAR >./gvfile/POSCAR-$i 27 | cat ./$i/POSCAR >./movie/POSCAR-$i 28 | fi 29 | done 30 | 31 | cd vaspfile/ 32 | echo " vaspfile/ processing" 33 | dir2car.py * > /dev/null 34 | tar -cf ./POSITION.tar ./*.vasp 35 | rm *.vasp POSCAR* CONTCAR* 2> /dev/null 36 | tar -xf ./POSITION.tar 37 | rm POSITION.tar 38 | cd .. 39 | 40 | cd gvfile/ 41 | echo " gvfile/ processing" 42 | vas2gjf.py * > /dev/null 43 | tar -cf ./GVFILE.tar ./*.gjf 44 | rm *.gjf POSCAR* CONTCAR* 2> /dev/null 45 | tar -xf ./GVFILE.tar 46 | rm GVFILE.tar 47 | cd .. 48 | 49 | cd movie 50 | echo " movie/ processing" 51 | cp POSCAR-00 CONTCAR-00 52 | 53 | nn=`seq -f '%02g' 1 $(($n+1)) |tail -1` 54 | 55 | cp POSCAR-$nn CONTCAR-$nn 56 | 57 | for i in `seq -f '%02g' 0 $(($n+1))` 58 | do 59 | if [ -e POSCAR-$i ] 60 | then 61 | vas2xyz.py POSCAR-$i >/dev/null 62 | cat POSCAR-$i.xyz >>POSmovie.xyz 63 | fi 64 | if [ -e CONTCAR-$i ] 65 | then 66 | vas2xyz.py CONTCAR-$i >/dev/null 67 | cat CONTCAR-$i.xyz >>CONmovie.xyz 68 | fi 69 | done 70 | sed -i '/^$/d' *.xyz 71 | tar -cf ./MOVIE.tar ./POSmovie.xyz ./CONmovie.xyz 72 | rm POSCAR* CONTCAR* 73 | tar -xf MOVIE.tar 74 | rm MOVIE.tar 75 | cd .. 76 | 77 | tar -zcf ./NEBINFO.tar.gz vaspfile/ gvfile/ movie/ 78 | rm -rf movie/ vaspfile/ gvfile/ 79 | echo "" 80 | echo " --------------- Done ---------------" 81 | echo "" 82 | -------------------------------------------------------------------------------- /nebmake.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | #;-*- Perl -*- 3 | 4 | # Makes a linear interpolation between to POSCARs with N points 5 | 6 | use FindBin qw($Bin); 7 | use lib "$Bin"; 8 | use Vasp; 9 | 10 | # Get the input parameters 11 | @ARGV >= 3 || die "PLEASE INPUT THE TWO POSCARS AND THE NUMBER OF IMAGES!\n"; 12 | $pos1 = $ARGV[0]; 13 | $pos2 = $ARGV[1]; 14 | $nim = $ARGV[2] + 2; 15 | 16 | $nim < 100 || die "THE NUMBER OF IMAGES (INCLUDING END-POINTS) IS LIMITED TO 100 AS IS \n"; 17 | 18 | # Read in the POSCAR files and make sure that the number of atoms and types are the same 19 | ($coo1,$basis1,$lattice1,$natoms1,$totatoms1,$selectiveflag,$selective,$description,$filetype1) 20 | = read_poscar($pos1); 21 | ($coo2,$basis2,$lattice2,$natoms2,$totatoms2,$selectiveflag,$selective,$description,$filetype2) 22 | = read_poscar($pos2); 23 | 24 | print "filetype1: ",$filetype1,"\n"; 25 | print "filetype2: ",$filetype2,"\n"; 26 | 27 | if($filetype1 ne $filetype2) { 28 | print "TYPE OF FILE 1 IS: ",$filetype1,"\n"; 29 | print "TYPE OF FILE 2 IS: ",$filetype2,"\n"; 30 | die; 31 | } 32 | if($totatom1 != $totatom2) { 33 | print "TOTAL NUMBER OF ATOMS IN FILE 1 IS: ",$totatoms1,"\n"; 34 | print "TOTAL NUMBER OF ATOMS IN FILE 2 IS: ",$totatoms2,"\n"; 35 | die; 36 | } 37 | if(@{$natoms1} != @{$natoms2}) { 38 | print "TYPES OF ATOMS IN FILE 1 IS: ",$n=@{$natoms1},"\n"; 39 | print "TYPES OF ATOMS IN FILE 2 IS: ",$n=@{$natoms2},"\n"; 40 | die; 41 | } 42 | for($i=0; $i<@{$natoms1}; $i++) { 43 | if($natoms1->[$i] != $natoms2->[$i]) { 44 | print "FOR ELEMENT ",$i," ... \n"; 45 | print "... ATOMS IN FILE 1 IS: ",$natoms1->[$i],"\n"; 46 | print "... ATOMS IN FILE 2 IS: ",$natoms2->[$i],"\n"; 47 | die; 48 | } 49 | } 50 | if($lattice1 != $lattice2) { 51 | print "WARNING: LATTICE CONSTANTS ARE NOT THE SAME \n"; 52 | print "THE LATTICE CONSTANT IN FILE 1 IS: ",$lattice1,"\n"; 53 | print "THE LATTICE CONSTANT IN FILE 2 IS: ",$lattice2,"\n"; 54 | print "I HOPE YOU KNOW WHAT YOU ARE DOING\n"; 55 | $dyn_cell = 1; 56 | } 57 | for($i=0; $i<3; $i++) { 58 | for($j=0; $j<3; $j++) { 59 | if(($basis1->[$j][$i] != $basis2->[$j][$i])&&($dyn_cell != 1)) { 60 | print "WARNING: BASIS VECTORS ARE NOT THE SAME \n" ; 61 | print "BASIS ELEMENT ",$i," ",$j," ... \n" ; 62 | print "... IS IN FILE 1: ",$basis1->[$j][$i],"\n" ; 63 | print "... IS IN FILE 2: ",$basis2->[$j][$i],"\n" ; 64 | print "I HOPE YOU KNOW WHAT YOU ARE DOING\n"; 65 | $dyn_cell = 1; 66 | } 67 | } 68 | } 69 | 70 | # Ok, the POSCARs appear to be for the same system. 71 | # Get te header, i.e. the element symbols from the first POSCAR line 72 | #$header = `head -n 1 $pos1`; 73 | #chop($header); 74 | 75 | # Calculate basis and lattice step if dyn_cell 76 | if ($dyn_cell==1) { 77 | $latt_step = ($lattice2-$lattice1)/($nim-1); 78 | #$latt_avg = ($lattice2-$lattice1)/(2); 79 | $t_latt = $lattice1; 80 | for($i=0; $i<3; $i++) { 81 | for($j=0; $j<3; $j++) { 82 | $basis_step->[$j][$i] = ($basis2->[$j][$i] - $basis1->[$j][$i])/($nim-1); 83 | $basis_avg->[$j][$i] = ($basis2->[$j][$i] + $basis1->[$j][$i])/(2); 84 | $t_basis->[$j][$i] = $basis1->[$j][$i]; 85 | } 86 | } 87 | } 88 | 89 | # Calculate the distance between the two images ... dirkar: direct -> cartesian 90 | $diff = pbc_difference($coo2,$coo1,$totatoms1); 91 | #if ($dyn_cell==1) { dirkar($diff,$basis_avg,$latt_avg,$totatoms1); } 92 | #else { dirkar($diff,$basis1,$lattice1,$totatoms1); } 93 | if ($dyn_cell != 1) { dirkar($diff,$basis1,$lattice1,$totatoms1); } 94 | for($i=0; $i<$totatoms1; $i++) { 95 | for($j=0; $j<3; $j++) { 96 | $step->[$i][$j] = ($diff->[$i][$j])/($nim-1); 97 | } 98 | } 99 | 100 | # Because zero is the number of the first image 101 | $nim--; 102 | 103 | # Put the POSCAR in the initial state folder 104 | mkdir "00"; 105 | #write_poscar($coo1,$basis1,$lattice1,$natoms1,$totatoms1, 106 | # $selectiveflag,$selective,$header,"00/POSCAR",$filetype1); 107 | write_poscar($coo1,$basis1,$lattice1,$natoms1,$totatoms1, 108 | $selectiveflag,$selective,$description,"00/POSCAR",$filetype1); 109 | 110 | # Put the POSCAR in the final state folder 111 | if($nim < 10) { $dir = "0$nim"; } 112 | else { $dir = "$nim"; } 113 | mkdir $dir; 114 | #write_poscar($coo2,$basis2,$lattice2,$natoms1,$totatoms1, 115 | # $selectiveflag,$selective,$header,"$dir/POSCAR",$filetype1); 116 | write_poscar($coo2,$basis2,$lattice2,$natoms1,$totatoms1, 117 | $selectiveflag,$selective,$description,"$dir/POSCAR",$filetype1); 118 | 119 | # Make the rest of the images in the chain 120 | for($i=0; $i<$totatoms1; $i++) { 121 | for($j=0; $j<3; $j++) { 122 | $t->[$i][$j] = $coo1->[$i][$j]; 123 | } 124 | } 125 | for($im=1; $im<$nim; $im++) { 126 | #if ($dyn_cell==1) {dirkar($t,$t_basis,$t_latt,$totatoms1);} 127 | #else {dirkar($t,$basis1,$lattice1,$totatoms1)} ; 128 | if ($dyn_cell != 1) { dirkar($t,$basis1,$lattice1,$totatoms1); } 129 | for($i=0; $i<$totatoms1; $i++) { 130 | for($j=0; $j<3; $j++) { 131 | $t->[$i][$j] += $step->[$i][$j]; 132 | } 133 | } 134 | if ($dyn_cell==1) { 135 | $t_latt += $latt_step; 136 | #print "lattice ",$t_latt,"\n"; 137 | for($i=0; $i<3; $i++) { 138 | for($j=0; $j<3; $j++) { 139 | $t_basis->[$j][$i] += $basis_step->[$j][$i]; 140 | } 141 | } 142 | } else { kardir($t,$basis1,$lattice1,$totatoms1); } 143 | if($im < 10) { $dir = "0$im"; } 144 | else { $dir = "$im"; } 145 | mkdir $dir; 146 | if ($dyn_cell==1) { 147 | # write_poscar($t,$t_basis,$t_latt,$natoms1,$totatoms1, 148 | # $selectiveflag,$selective,$header,"$dir/POSCAR",$filetype1); 149 | write_poscar($t,$t_basis,$t_latt,$natoms1,$totatoms1, 150 | $selectiveflag,$selective,$description,"$dir/POSCAR",$filetype1); 151 | } else { 152 | # write_poscar($t,$basis1,$lattice1,$natoms1,$totatoms1, 153 | # $selectiveflag,$selective,$header,"$dir/POSCAR",$filetype1); 154 | write_poscar($t,$basis1,$lattice1,$natoms1,$totatoms1, 155 | $selectiveflag,$selective,$description,"$dir/POSCAR",$filetype1); 156 | } 157 | } 158 | 159 | print "\n" ; 160 | print "OK, ALL SETUP HERE\n"; 161 | print "FOR LATER ANALYSIS, PUT OUTCARs IN FOLDERS 00 and "; 162 | if($im < 10) { 163 | print "0$nim !!! \n"; 164 | } else { 165 | print "$nim !!! \n"; 166 | } 167 | 168 | -------------------------------------------------------------------------------- /nebmovie: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | echo "" 3 | echo "" 4 | echo "####################This script creats movie.xyz for each image####################" 5 | echo "" 6 | read -p "The nember of images:" n 7 | 8 | for i in `seq -f '%02g' 1 $n` 9 | do 10 | cd ./$i/ &&xdat2xyz.pl XDATCAR 11 | mv movie.xyz ../movie-$i.xyz 12 | cd .. 13 | done 14 | 15 | echo "" 16 | echo " ####################Finished####################" 17 | echo "" 18 | 19 | if [ -z $3 ];then 20 | exit 21 | fi 22 | 23 | xyzmerge.py *.xyz $@ 24 | gzip merge.xyz 25 | rm *.xyz 26 | -------------------------------------------------------------------------------- /nebresults.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | #;-*- Perl -*- 3 | 4 | # 29-05-2003 5 | 6 | # After vto has been run, go into the dir from vto . 7 | # All the OUTCARs should now be zipped. 8 | 9 | # nebmovie.pl should use CONTCARs not POSCARs. 10 | 11 | use Cwd; 12 | $dir = cwd; 13 | use FindBin qw($Bin); 14 | 15 | # Unzip the OUTCARs 16 | print "\n" ; 17 | print 'Unziping the OUTCARs ... ' ; 18 | $i=0; 19 | $string = "00" ; 20 | while(chdir $string) { 21 | if(-e "OUTCAR") { ; } 22 | elsif(-e "OUTCAR.gz") { system "gunzip OUTCAR.gz"; } 23 | elsif(-e "OUTCAR.bz2") { system "bunzip2 OUTCAR.bz2"; } 24 | else {die "No OUTCAR in $string\n"; } 25 | $i++; 26 | if($i < 10) { $string = "0$i"; } 27 | elsif($i < 100) { $string = "$i"; } 28 | else { die "Too many images"; } 29 | chdir $dir; 30 | } 31 | print 'done',"\n"; 32 | 33 | # The number of images, not including endpoints. 34 | $i-=2; 35 | 36 | # Same as the 'spline' alias 37 | print 'Do nebbarrier.pl ; nebspline.pl',"\n"; 38 | system "$Bin/nebbarrier.pl ; $Bin/nebspline.pl"; 39 | if (-e "nebss.dat"){system "$Bin/nebspliness.pl";} 40 | 41 | print 'Do nebef.pl',"\n"; 42 | system "$Bin/nebef.pl > nebef.dat"; 43 | if (-e "nebss.dat"){system "$Bin/nebefs.pl > nebefs.dat";} 44 | 45 | # Generate a xyz-movie 46 | print 'Do nebmovie.pl',"\n"; 47 | system "$Bin/nebmovie.pl CONTCAR > /dev/null"; 48 | 49 | # Generate a vasp-movie 50 | print 'Do nebjmovie.pl',"\n"; 51 | system "$Bin/nebjmovie.pl CONTCAR > /dev/null"; 52 | 53 | # nebconverge script 54 | print 'Do nebconverge.pl',"\n"; 55 | system "$Bin/nebconverge.pl > /dev/null"; 56 | 57 | # Zip the OUTCARs again 58 | print 'Zipping the OUTCARs again ... ' ; 59 | $zip = $ENV{'VTST_ZIP'}; 60 | if($zip eq ''){ $zip = 'gzip'; } 61 | 62 | $i = 0; 63 | $string = "00"; 64 | while(chdir $string) { 65 | system "$zip OUTCAR"; 66 | $i++; 67 | if($i < 10) { $string = "0$i"; } 68 | elsif($i < 100) { $string = "$i"; } 69 | chdir $dir; 70 | } 71 | print "done\n"; 72 | 73 | print "\nForces and Energy:\n"; 74 | system "cat nebef.dat"; 75 | print "\n" ; 76 | system "cat exts.dat"; 77 | print "\n"; 78 | 79 | -------------------------------------------------------------------------------- /nebspline.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | #;-*- Perl -*- 3 | 4 | @args=@ARGV; 5 | 6 | use Cwd; 7 | $dir = cwd; 8 | use FindBin qw($Bin); 9 | 10 | # default values for the aguments 11 | 12 | if(scalar($ARGV)==0) { $args[0] = "neb.dat"; } 13 | if(scalar($ARGV)<=1) { $args[1] = 20; } 14 | 15 | $inputfilename = $args[0]; 16 | $NumJ = $args[1]; 17 | 18 | # read in the mep file 19 | 20 | $inputfile = ""; 21 | open (IN,$inputfilename); 22 | while () { 23 | $_ =~ s/^\s+//g; 24 | $inputfile .= $_; 25 | } 26 | #print $inputfile; 27 | close (IN); 28 | @inputfile = split(/\n/,$inputfile); 29 | $NumI = scalar @inputfile; 30 | #print $NumI; 31 | 32 | # load in the data: position energy force 33 | 34 | for($i=0; $i<$NumI; $i++) { 35 | $line = @inputfile[$i]; 36 | @line = split(/\s+/,$line); 37 | @R[$i] = @line[1]; 38 | @E[$i] = @line[2]; 39 | @F[$i] = @line[3];} 40 | 41 | # calculate the cubic parameters for each interval (a,b,c,d) 42 | 43 | for($i=0; $i<($NumI-1); $i++) { 44 | @dR[$i] = @R[$i+1] - @R[$i]; 45 | $F1 = $F[$i]*@dR[$i]; 46 | $F2 = $F[$i+1]*@dR[$i]; 47 | $U1 = $E[$i]; 48 | $U2 = $E[$i+1]; 49 | $Fs = $F1 + $F2; 50 | $Ud = $U2 - $U1; 51 | @a[$i] = $U1; 52 | @b[$i] = -$F1; 53 | @c[$i] = 3*$Ud + $F1 + $Fs; 54 | @d[$i] = -2*$Ud - $Fs; 55 | } 56 | 57 | # generating the output file containing the spline 58 | 59 | $l = 0; 60 | for($i=0; $i<$NumI; $i++) { 61 | @line = ($i,@R[$i],@E[$i],@F[$i]); 62 | @outputfile[$l] = join "\t",@line; 63 | $l++; 64 | if($i != ($NumI-1)) { 65 | for($j=1; $j<$NumJ; $j++){ 66 | $f = $j/$NumJ; 67 | $Ispl = $i + $f; 68 | $Rspl = @R[$i] + $f*@dR[$i]; 69 | $Espl = @d[$i]*$f**3 + @c[$i]*$f**2 + @b[$i]*$f + @a[$i]; 70 | $Fspl = -(3*@d[$i]*$f**2 + 2*@c[$i]*$f + @b[$i])/@dR[$i]; 71 | @line = ($Ispl,$Rspl,$Espl,$Fspl); 72 | @outputfile[$l] = join "\t",@line; 73 | $l++; 74 | } 75 | } 76 | } 77 | 78 | # writing the spline to the output file spline.dat 79 | 80 | $outputfile = join "\n",@outputfile; 81 | open (OUT,">spline.dat"); 82 | print OUT $outputfile; 83 | close (OUT); 84 | 85 | # finding extrema along the MEP 86 | 87 | $NumE = 0; 88 | for($i=0; $i<($NumI-1); $i++){ 89 | $Desc = @c[$i]**2-3*@b[$i]*@d[$i]; 90 | if($Desc >= 0) { 91 | $f = -1; 92 | # Quadratic case 93 | if (@d[$i] == 0 && @c[$i] != 0) { 94 | $f = -(@b[$i]/(2*@c[$i])); 95 | # Cubic case 1 96 | } elsif (@d[$i]!=0) { 97 | $f = -(@c[$i] + sqrt($Desc))/(3*@d[$i]); 98 | } 99 | if ($f >= 0 && $f <= 1) { 100 | $Pos = $i + $f; 101 | $Ext{$Pos} = @d[$i]*$f**3 + @c[$i]*$f**2 + @b[$i]*$f + @a[$i]; 102 | $NumE++; 103 | } 104 | # Cubic case 2 105 | if (@d[$i] != 0) { 106 | $f = -(@c[$i] - sqrt($Desc))/(3*@d[$i]); 107 | if ($f >= 0 && $f <= 1) { 108 | $Pos = $i + $f; 109 | $Ext{$Pos} = @d[$i]*$f**3 + @c[$i]*$f**2 + @b[$i]*$f + @a[$i]; 110 | $NumE++; 111 | } 112 | } 113 | } 114 | } 115 | 116 | # write out the extrema information to exts.dat 117 | 118 | open (OUT,">exts.dat"); 119 | $NumE = 0; 120 | foreach $Pos (sort {$a<=>$b} (keys(%Ext))){ 121 | $NumE++; 122 | $outline = sprintf("Extrema %d found at image %9.6f with energy: %9.6f\n",$NumE,$Pos,$Ext{$Pos}); 123 | print OUT $outline; 124 | } 125 | close (OUT); 126 | 127 | system "gnuplot $Bin/nebplot.gnu > /dev/null"; 128 | -------------------------------------------------------------------------------- /nebtar: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | echo "This script will pack all the CONTCAR and POSCAR" 3 | read -p "continue?(y/n)" x 4 | if [ "$x" == "y" -o "$x" == "Y" ]; then 5 | read -p "The number of images:" n 6 | for((i=0;i<=$(($n+1));i=i+1)) 7 | do 8 | test -e ./0"$i"/CONTCAR &&cat ./0"$i"/CONTCAR >CONTCAR-"0$i".vasp 9 | [ -e ./0"$i"/POSCAR ] &&cat ./0"$i"/POSCAR >POSCAR-"0$i".vasp 10 | done 11 | tar -zcvf ./POSITION.tar.gz ./*.vasp 12 | rm *.vasp 13 | fi 14 | -------------------------------------------------------------------------------- /nebtarall: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | echo "This script will pack all the CONTCAR POSCAR and OUTCAR, nothing will be deleted" 3 | read -p "continue?(y/n)" x 4 | if [ "$x" == "y" -o "$x" == "Y" ]; then 5 | read -p "The number of images:" n 6 | for((i=0;i<=$(($n+1));i=i+1)) 7 | do 8 | test -e ./0$i/CONTCAR &&cat ./0$i/CONTCAR >CONTCAR-0$i.vasp 9 | [ -e ./0$i/POSCAR ] &&cat ./0$i/POSCAR >POSCAR-0$i.vasp 10 | [ -e ./0$i/OUTCAR ] &&cp ./0$i/OUTCAR ./OUTCAR-0$i 11 | done 12 | tar -zcvf ./OUTCAR.tar.gz ./*.vasp ./OUTCAR* 13 | rm *.vasp 14 | rm *-0* 15 | fi 16 | -------------------------------------------------------------------------------- /nebvtst.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | import re 5 | from VASP import execCmd, CmdRrror 6 | from multiprocessing import Pool 7 | 8 | energyPattern = re.compile(r'=.*?([-.0-9]+)') 9 | tangentPattern = re.compile(r'([-.0-9]+).*?([-.0-9]+)') 10 | 11 | 12 | def getInfo(image_folder): 13 | """ 14 | :param image_folder: 00, 01, 02, ... 15 | :return: 16 | """ 17 | cmd = 'grep "free energy " ./%02d/OUTCAR' % image_folder 18 | try: 19 | energy = execCmd(cmd) 20 | except CmdRrror: 21 | print(CmdRrror) 22 | exit(1) 23 | 24 | for i in range(len(energy)): 25 | energy[i] = float(energyPattern.search(energy[i]).group(1)) 26 | 27 | # try: 28 | # cmd = 'grep "distance to prev" ./%02d/OUTCAR' % image_folder 29 | # except CmdRrror: 30 | # print(CmdRrror) 31 | # exit(1) 32 | # dist = execCmd(cmd) 33 | 34 | cmd = 'grep "projections on to tangent" ./%02d/OUTCAR' % image_folder 35 | try: 36 | tangent = execCmd(cmd) 37 | except CmdRrror: 38 | print(CmdRrror) 39 | exit(1) 40 | for i in range(len(tangent)): 41 | tangent[i] = float(tangentPattern.search(tangent[i]).group(2)) 42 | 43 | cmd = 'grep "FORCES: max atom" ./%02d/OUTCAR' % image_folder 44 | try: 45 | force = execCmd(cmd) 46 | except CmdRrror: 47 | print(CmdRrror) 48 | exit(1) 49 | for i in range(len(force)): 50 | force[i] = float(tangentPattern.search(force[i]).group(1)) 51 | 52 | return [energy, tangent, force] 53 | 54 | 55 | if len(sys.argv) == 1: 56 | print('') 57 | print('Usage: %s number_of_images' % sys.argv[0].split('/')[-1]) 58 | print('') 59 | exit(1) 60 | 61 | 62 | print('##########This script is used to get information about energy, distance, force##########') 63 | print('') 64 | 65 | pool = Pool(4) 66 | folder_ids = [folder_id for folder_id in range(1, int(sys.argv[1]) + 1)] 67 | info = pool.map(getInfo, folder_ids) 68 | 69 | best_ret = [] 70 | for step in range(len(info[0][0])): 71 | print('step: %d' % (step + 1)) 72 | print(' Energy Tangent Max force') 73 | for i, each_info in enumerate(info): 74 | # energy, tangent, force 75 | print('images: %d %10.5f %10.5f %10.5f' % (i + 1, each_info[0][step], each_info[1][step], 76 | each_info[2][step])) 77 | # step, tangent, force 78 | best_ret.append([step + 1, i + 1, abs(each_info[1][step]), each_info[2][step]]) 79 | print('') 80 | 81 | # sorted by tangent 82 | best_ret.sort(key=lambda x: x[2]) 83 | print('') 84 | print('-------------- Best Result --------------') 85 | print(' Step Image_id Tangent Max force') 86 | for i in range(min(10, len(best_ret))): 87 | print('%5d %4d %10.5f %10.5f' % (best_ret[i][0], best_ret[i][1], best_ret[i][2], best_ret[i][3])) 88 | print('') 89 | 90 | -------------------------------------------------------------------------------- /node.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in 0 1 2 3 3 | do 4 | echo "ln$i:" 5 | ssh ln$i-gn0 "uptime" 6 | done 7 | 8 | read -p "chose one node: " node 9 | ssh ln$node-gn0 10 | -------------------------------------------------------------------------------- /posdiff.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | from VASP import readVasp 5 | 6 | threshold = 0.001 7 | if len(sys.argv) == 4: 8 | threshold = float(sys.argv[3]) 9 | elif len(sys.argv) != 3: 10 | print('') 11 | print("usage: poscar.py POSCAR1 POSCAR2 threshold") 12 | print("try again!") 13 | print('') 14 | exit(1) 15 | 16 | lattice1, basis1, elements1, num_atoms1, selectiveflag1, coordinate_type1, coordinates1, selective1 = readVasp(sys.argv[1]) 17 | lattice2, basis2, elements2, num_atoms2, selectiveflag2, coordinate_type2, coordinates2, selective2 = readVasp(sys.argv[2]) 18 | 19 | 20 | if abs(lattice1 - lattice2) > threshold: 21 | print('') 22 | print("Lattices are different:") 23 | print("%s: %10.5f" % (sys.argv[1], lattice1)) 24 | print("%s: %10.5f" % (sys.argv[2], lattice2)) 25 | print('') 26 | 27 | basis_diff = [] 28 | for i in range(0, 3): 29 | for j in range(0, 3): 30 | if abs(basis1[i][j] - basis2[i][j]) > threshold: 31 | basis_diff.append([i, j, basis1[i][j] - basis2[i][j]]) 32 | 33 | if basis_diff: 34 | print('') 35 | print("Basis are differernt:") 36 | print(" basis_id(within 3*3 array) difference") 37 | for i in basis_diff: 38 | print(" (%4d,%4d) %14.10f" % (i[0] + 1, i[1] + 1, i[2])) 39 | print('') 40 | 41 | if elements1 != elements2: 42 | print('') 43 | print("Elements are differernt:") 44 | print("%s: " % sys.argv[1], elements1) 45 | print("%s: " % sys.argv[2], elements2) 46 | print("") 47 | exit(0) 48 | 49 | if num_atoms1 != num_atoms2: 50 | print('') 51 | print("Number of atoms are different:") 52 | print("%s: " % sys.argv[1], num_atoms1) 53 | print("%s: " % sys.argv[2], num_atoms2) 54 | print("") 55 | exit(0) 56 | 57 | coordinate_diff = [] 58 | for i in range(0, len(coordinates1)): 59 | for j in range(0, 3): 60 | if abs(coordinates1[i][j] - coordinates2[i][j]) > threshold: 61 | coordinate_diff.append([i, j, coordinates1[i][j] - coordinates2[i][j]]) 62 | 63 | if coordinate_diff: 64 | print("") 65 | print("coordinates are different: ") 66 | print(" atoms_id difference") 67 | for i in coordinate_diff: 68 | print(" (%4d,%4d) %14.10f" % (i[0] + 1, i[1] + 1, i[2])) 69 | print("") 70 | -------------------------------------------------------------------------------- /rmall: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | for i in $@ 3 | do 4 | for j in `find ./ -name $i` 5 | do 6 | echo "$j" 7 | rm $j 8 | done 9 | done 10 | -------------------------------------------------------------------------------- /start_freq_job.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -d $1 ];then 4 | mkdir $1 5 | fi 6 | 7 | vas2gv.pl CONTCAR 8 | mv CONTCAR.gjf $1/temp.gjf 9 | 10 | if [ -n "$2" ];then 11 | cp $2/POSCAR $1 12 | cp KPOINTS $1 13 | cp POTCAR $1 14 | if [ -f vdw_kernel.bindat ];then 15 | cp vdw_kernel.bindat $1 16 | fi 17 | for i in `ls $2` 18 | do 19 | if [ -x $2/$i ];then 20 | cp $2/$i $1 21 | fi 22 | done 23 | fi 24 | 25 | cd $1 26 | if [ ! -f POSCAR ];then 27 | echo "POSCAR: No such file" 28 | echo "" 29 | exit 30 | fi 31 | 32 | gv2vas.pl POSCAR temp.gjf 33 | mv *vasp POSCAR 34 | 35 | #sub sub 36 | 37 | -------------------------------------------------------------------------------- /stdoutput.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | # 3 | #version 1.0 4 | use 5.010; 5 | use warnings; 6 | use strict; 7 | use vars qw($line); 8 | $ARGV[0]='INPUT' if $ARGV[0] eq ''; 9 | $ARGV[1]='OUTPUT' if $ARGV[1] eq ''; 10 | open IN, '<', $ARGV[0] or die "Cannot open file $ARGV[0]: $!\n"; 11 | open OUT, '>', $ARGV[1] or die "Cannot open file $ARGV[1]: $!\n"; 12 | while(defined($line = )){ 13 | chomp($line); 14 | $line =~ s/^\s+//; 15 | my @output = split(/\s+/,$line); 16 | if($line =~ /[a-zA-Z]/){ 17 | print OUT ($line); 18 | }else{ 19 | for(my $i=0; $i<@output; $i++){ 20 | printf OUT ("%20.9f",$output[$i]); 21 | } 22 | } 23 | print OUT ("\n"); 24 | } 25 | close(IN); 26 | close(OUT); 27 | print "results now have been saved in file $ARGV[1].\n"; 28 | $line=; 29 | -------------------------------------------------------------------------------- /sub: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | node=`grep "node=" $1 |sed 's/\s*//g' |cut -c 6-` 3 | res=$((${node}%24)) 4 | if [ -z $node ];then 5 | echo "" 6 | echo "node has not been defined! Check your script $1." 7 | echo "" 8 | exit 9 | elif [ "$res" -ne "0" ];then 10 | echo "" 11 | echo "you defined node=$node, which is wrong. Please check again!" 12 | echo "" 13 | exit 14 | fi 15 | yhbatch -n $node $1 16 | recent_jobs.sh 17 | -------------------------------------------------------------------------------- /tmp.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | from VASP import readVasp 4 | import sys 5 | import math 6 | 7 | 8 | def dist(atom1, atom2): 9 | return math.sqrt(abs(atom1[0] - atom2[0]) ** 2 + abs(atom1[1] - atom2[1]) ** 2 + abs(atom1[2] - atom2[2]) ** 2) 10 | 11 | lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective = readVasp(sys.argv[1]) 12 | 13 | 14 | distance = [] 15 | for i in range(len(coordinates) - 1): 16 | for j in range(i + 1, len(coordinates)): 17 | distance.append([i, j, dist(coordinates[i], coordinates[j])]) 18 | 19 | distance.sort(key=lambda x: x[2]) 20 | 21 | for i in range(10): 22 | print(distance[i]) 23 | -------------------------------------------------------------------------------- /vas2cif.pl: -------------------------------------------------------------------------------- 1 | #!/bin/env perl 2 | use FindBin qw($Bin); 3 | use lib "$Bin"; 4 | use Vasp; 5 | use strict; 6 | use warnings; 7 | use Math::Trig; 8 | use vars qw($input $output $coo $basis $lattice $natoms $totatoms $selectiveflag $selective $description $filetype @element $element); 9 | 10 | print "\n"; 11 | print "\n"; 12 | print "############### This script converts vasp file into cif file ###############\n"; 13 | print " ############ CONTCAR or POSCAR -> .cif ############\n"; 14 | print "\n"; 15 | 16 | if(!defined($ARGV[0])){ 17 | print "Usage: pos2cif.pl file1 file2 file3.....\n"; 18 | print "file can be POSCAR or CONTCAR and either direct or cartesian\n"; 19 | print "Please try again!\n"; 20 | print "\n"; 21 | print "\n"; 22 | exit 1; 23 | } 24 | 25 | #product of two vectors 26 | sub dot { 27 | my $v1 = shift; 28 | my $v2 = shift; 29 | return $v1->[0]*$v2->[0]+$v1->[1]*$v2->[1]+$v1->[2]*$v2->[2] 30 | } 31 | 32 | #angle between tow vectors 33 | sub angle { 34 | my $v1 = shift; 35 | my $v2 = shift; 36 | return rad2deg(acos(dot($v1,$v2)/(sqrt(dot($v1,$v1))*sqrt(dot($v2,$v2))))); 37 | } 38 | 39 | 40 | while(defined($ARGV[0])){ 41 | my $va; 42 | my $vb; 43 | my $vc; 44 | my $length_a; 45 | my $length_b; 46 | my $length_c; 47 | my $alpha; 48 | my $beta; 49 | my $gamma; 50 | 51 | $input = shift @ARGV; 52 | $output = $input.".cif"; 53 | print " Processing $input\n"; 54 | ($coo,$basis,$lattice,$natoms,$totatoms,$selectiveflag,$selective,$description,$filetype) 55 | = read_poscar($input); 56 | 57 | for(my $i = 0; $i < 3; $i++){ 58 | $va->[$i] = $basis->[$i][0]; 59 | $vb->[$i] = $basis->[$i][1]; 60 | $vc->[$i] = $basis->[$i][2]; 61 | } 62 | 63 | $length_a = sqrt(dot($va,$va)); 64 | $length_b = sqrt(dot($vb,$vb)); 65 | $length_c = sqrt(dot($vc,$vc)); 66 | 67 | $alpha = angle($vb,$vc); 68 | $beta = angle($vc,$va); 69 | $gamma = angle($va,$vb); 70 | 71 | open OUT, '>', $output or die "cannot creat file $output: $!\n"; 72 | 73 | print OUT "data_\n"; 74 | print OUT "_audit_creation_method 'Materials Studio'\n"; 75 | printf OUT "_cell_length_a %15.6f\n", $length_a; 76 | printf OUT "_cell_length_b %15.6f\n", $length_b; 77 | printf OUT "_cell_length_c %15.6f\n", $length_c; 78 | printf OUT "_cell_angle_alpha %10.6f\n", $alpha; 79 | printf OUT "_cell_angle_beta %10.6f\n", $beta; 80 | printf OUT "_cell_angle_gamma %10.6f\n", $gamma; 81 | print OUT "_symmetry_space_group_name_H-M 'P1'\n"; 82 | print OUT "loop_\n"; 83 | print OUT "_atom_site_type_symbol\n"; 84 | print OUT "_atom_site_label\n"; 85 | print OUT "_atom_site_fract_x\n"; 86 | print OUT "_atom_site_fract_y\n"; 87 | print OUT "_atom_site_fract_z\n"; 88 | 89 | @element = split(/\s+/, $description); 90 | for(my $m = 0, my $count = 0; $m < @element; $m++){ 91 | for(my $n = 0; $n < ($natoms->[$m]); $n++){ 92 | $count++; 93 | printf OUT " %6s %6s", $element[$m], $element[$m]; 94 | printf OUT "%-8s", $count; 95 | for(my $i = 0; $i < 3; $i++){ 96 | my $coord = $coo->[$count-1][$i]; 97 | if ($coord>1) { $coord -= 1; } 98 | elsif ($coord<0) { $coord += 1; } 99 | printf OUT "%20.16f", $coord; 100 | } 101 | print OUT "\n"; 102 | } 103 | } 104 | close(OUT); 105 | } 106 | print "\n"; 107 | print " --------------- Done ---------------\n"; 108 | print "\n"; 109 | print "\n"; 110 | -------------------------------------------------------------------------------- /vas2gjf.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | from VASP import readVasp 5 | from VASP import writeGjf 6 | 7 | if len(sys.argv) == 1: 8 | print('') 9 | print('Usage: %s vasp_file1 vasp_file2 ...' % sys.argv[0].split('/')[-1]) 10 | print('') 11 | exit(1) 12 | 13 | print('') 14 | print('############### This script converts vasp file into gview file ###############') 15 | print(' ############ CONTCAR or POSCAR -> .gjf ############') 16 | print('') 17 | for vasp_file in sys.argv[1:]: 18 | print(' Processing %s' % vasp_file) 19 | lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective = readVasp(vasp_file) 20 | if vasp_file.endswith('.vasp'): 21 | vasp_file = '%s.gjf' % vasp_file[:-5] 22 | else: 23 | vasp_file = '%s.gjf' % vasp_file 24 | writeGjf(vasp_file, elements, num_atoms, coordinates) 25 | 26 | print('') 27 | print(' --------------- Done ---------------\n') 28 | -------------------------------------------------------------------------------- /vas2xyz.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | from VASP import readVasp 5 | from VASP import writeXYZ 6 | 7 | if len(sys.argv) == 1: 8 | print('') 9 | print('Usage: %s vasp_file1 vasp_file2 ...' % sys.argv[0].split('/')[-1]) 10 | print('') 11 | exit(1) 12 | 13 | print('') 14 | print("############### This script converts vasp file into .xyz file ###############") 15 | print(" ############ CONTCAR or POSCAR -> .xyz ############") 16 | print('') 17 | 18 | for vasp_file in sys.argv[1:]: 19 | print(' Processing %s' % vasp_file) 20 | lattice, basis, elements, num_atoms, selectiveflag, coordinate_type, coordinates, selective = readVasp(vasp_file) 21 | if vasp_file.endswith('.vasp'): 22 | vasp_file = '%s.xyz' % vasp_file[:-5] 23 | else: 24 | vasp_file = '%s.xyz' % vasp_file 25 | writeXYZ(vasp_file, 1, elements, num_atoms, coordinates) 26 | 27 | print('') 28 | print(" --------------------- DONE ---------------------\n") 29 | print('') 30 | -------------------------------------------------------------------------------- /xdat2xyz.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env perl 2 | #;-*- Perl -*- 3 | 4 | # Open the XDATCAR. If no argument is supplied XDATCAR is open 5 | # by default. If argument is supplied that file will be opened. 6 | 7 | $zip = $ENV{'VTST_ZIP'}; 8 | if($zip eq '') { $zip = 'gzip'; } 9 | 10 | if(@ARGV == undef){ 11 | if(-e "XDATCAR") { 12 | $xdatzipped = 0; 13 | } elsif(-e "XDATCAR.gz") { 14 | print " XDATCAR IS ZIPPED, UNZIPPING \n"; 15 | system "gunzip XDATCAR.gz"; 16 | $xdatzipped = 1; 17 | } elsif(-e "XDATCAR.bz2") { 18 | print " XDATCAR IS ZIPPED, UNZIPPING \n"; 19 | system "bunzip2 XDATCAR.bz2"; 20 | $xdatzipped = 1; 21 | } else { 22 | die " NO XDATCAR IN THIS DIRECTORY \n"; 23 | } 24 | print " OPEN XDATCAR ... \n"; 25 | open XDAT, "XDATCAR" 26 | or die " ... XDATCAR MISSING FROM THIS DIRECTORY \n"; 27 | } else { 28 | print " OPEN ",@ARGV[0]," ... \n"; 29 | open XDAT, @ARGV[0] 30 | or die " ... ",@ARGV[0]," MISSING FROM THIS DIRECTORY \n"; 31 | } 32 | 33 | # Get the forces and energies to print in the xyz-file 34 | 35 | if(-e "OUTCAR") { 36 | $zipped = 0; 37 | } elsif(-e "OUTCAR.gz") { 38 | print " OUTCAR IS ZIPPED, UNZIPPING \n"; 39 | system "gunzip OUTCAR.gz"; 40 | $zipped = 1; 41 | } elsif(-e "OUTCAR.bz2") { 42 | print " OUTCAR IS ZIPPED, UNZIPPING \n"; 43 | system "bunzip2 OUTCAR.bz2"; 44 | $zipped = 1; 45 | } else { 46 | die " NO OUTCAR IN THIS DIRECTORY \n"; 47 | } 48 | 49 | $forces = `grep 'FORCES: max atom, RMS' OUTCAR`; 50 | $energy = `grep 'energy without entropy' OUTCAR`; 51 | @forces = split /\n/, $forces; 52 | @energy = split /\n/, $energy; 53 | if($zipped) { 54 | print " ZIPPING OUTCAR AGAIN \n"; 55 | system "$zip OUTCAR &"; 56 | } 57 | 58 | # Get information about, number and types of atoms, box lengths ets. 59 | # from the POSCAR file. 60 | 61 | 62 | if(-e "XDATCAR") { 63 | open POS, "CONTCAR"; 64 | }else{ 65 | open POS, "POSCAR" or die " NO POSCAR IN THIS DIRECTORY \n"; 66 | } 67 | for($i=0; $i<=8; $i++) { 68 | $line = ; 69 | chomp($line); 70 | $line =~ s/^\s+//g; 71 | @line = split /\s+/,$line; 72 | if($i == 0){ 73 | @elements = split /\s+/, $line; 74 | $nel = @elements; 75 | } 76 | if($i == 1) { $latt = $line[0]; } 77 | if($i == 2) { @sidex[0..2] = @line[0..2]; } 78 | if($i == 3) { @sidey[0..2] = @line[0..2]; } 79 | if($i == 4) { @sidez[0..2] = @line[0..2]; } 80 | if($i == 5) { 81 | if($line[0] =~ /^\d+$/) { 82 | @not[0..$nel-1] = @line[0..$nel-1]; 83 | # Calculate the number of atoms 84 | while($not[$k] != undef) { 85 | $natoms += $not[$k++]; 86 | } 87 | } else { 88 | $atomtypeflag = 1; #check for vasp5 style POSCAR 89 | print "VASP 5 format\n"; 90 | @elements = split /\s+/, $line; 91 | $nel = @elements; 92 | } 93 | } 94 | if($i == 6) { 95 | if($atomtypeflag == 1){ 96 | @not[0..$nel-1] = @line[0..$nel-1]; 97 | # Calculate the number of atoms 98 | while($not[$k] != undef) { 99 | $natoms += $not[$k++]; 100 | } 101 | } 102 | } 103 | } 104 | close POS; 105 | 106 | # Assign a type (element) to each atom. 107 | 108 | $n = 0; 109 | $j = 0; 110 | for($i=1; $i<=$natoms; $i++) { 111 | $j++; 112 | if($j <= $not[$n]){ 113 | $type[$i-1] = $elements[$n]; 114 | } else { 115 | $n++; 116 | $type[$i-1] = $elements[$n]; 117 | $j = 1; 118 | } 119 | } 120 | 121 | # Read the XDAT file and make .xyz files 122 | 123 | if($atomtypeflag == 1) { 124 | # Jump over the first few line "vasp 5" 125 | for($i=0; $i<7; $i++){ 126 | $line = ; 127 | } 128 | } else { 129 | # Jump over the first few lines old XDATCAR 130 | for($i=0; $i<5; $i++) { 131 | $line = ; 132 | } 133 | } 134 | 135 | $n = 0; 136 | open MOV, ">movie.xyz"; 137 | while($line = ) { 138 | chomp($line); 139 | print MOV $natoms,"\n"; 140 | $f = $forces[$n]; chomp($f); $f =~ s/^\s+//g; @f = split /\s+/,$f; 141 | $e = $energy[$n]; chomp($e); $e =~ s/^\s+//g; @e = split /\s+/,$e; 142 | print MOV "FORCE: $f[4] ... ENERGY: $e[6]","\n" ; 143 | for($i=0; $i<$natoms; $i++){ 144 | $line = ; 145 | chomp($line); $line =~ s/^\s+//g; @line = split /\s+/,$line; 146 | 147 | # Transform from direct coordinates to cart. coordinates. 148 | $x = $line[0]; 149 | $y = $line[1]; 150 | $z = $line[2]; 151 | # Periodic boundaries 152 | # while($x<-0.5){$x+=1.0;} while($x>0.5){$x-=1.0;} 153 | # while($y<-0.5){$y+=1.0;} while($y>0.5){$y-=1.0;} 154 | # while($z<-0.5){$z+=1.0;} while($z>0.5){$z-=1.0;} 155 | $xt = $x*$sidex[0] + $y*$sidey[0] + $z*$sidez[0]; 156 | $yt = $x*$sidex[1] + $y*$sidey[1] + $z*$sidez[1]; 157 | $zt = $x*$sidex[2] + $y*$sidey[2] + $z*$sidez[2]; 158 | $x = $latt*$xt; 159 | $y = $latt*$yt; 160 | $z = $latt*$zt; 161 | printf MOV "%2s %18.13f %18.13f %18.13f \n",$type[$i],$x,$y,$z; 162 | } 163 | $n++; 164 | } 165 | close XDAT; 166 | if($xdatzipped) { 167 | print " ZIPPING XDATCAR AGAIN \n"; 168 | system "$zip -9 XDATCAR &"; 169 | } 170 | -------------------------------------------------------------------------------- /xyzmerge.py: -------------------------------------------------------------------------------- 1 | #!/bin/env python3 2 | 3 | import sys 4 | import numpy as np 5 | from VASP import readXYZ 6 | 7 | 8 | def writeCoordinates(base, file_handle): 9 | for pos in ret_coordinates: 10 | index = base 11 | for i, atoms in enumerate(num_atoms): 12 | for j in range(atoms): 13 | file_handle.write("%2s %16.10f %16.10f %16.10f\n" % (elements[i], 14 | pos[index][0], pos[index][1], pos[index][2])) 15 | index += 1 16 | 17 | 18 | if len(sys.argv) < 6: 19 | print('') 20 | print('Usage: %s xyz_file1 xyz_file2 ... X Y Z' % sys.argv[0].split('/')[-1]) 21 | print('') 22 | exit(1) 23 | 24 | print('') 25 | print("############### Merging xyz files into one single file ###############") 26 | print('') 27 | 28 | offset = np.array(list(map(float, sys.argv[-3:]))) 29 | xyz_files = [readXYZ(file_name) for file_name in sys.argv[1:-3]] 30 | 31 | elements = xyz_files[0][1] 32 | num_atoms = xyz_files[0][2] 33 | for i, xyz_file in enumerate(xyz_files): 34 | if xyz_file[0] != xyz_files[0][0]: 35 | print('') 36 | print('ERROR: number of structures not equal, %s' % sys.argv[i + 1]) 37 | print('') 38 | exit(1) 39 | 40 | num_structures = xyz_files[0][0] 41 | read_coordinates = np.array([pos[3] for pos in xyz_files]) 42 | ret_coordinates = [] 43 | for i, pos in enumerate(read_coordinates): 44 | ret_coordinates.append(pos + offset * i) 45 | 46 | atoms_in_single_file = sum(xyz_files[0][2]) 47 | total_atoms = atoms_in_single_file * len(xyz_files) 48 | base = 0 49 | with open('merge.xyz', 'w') as merge_file: 50 | for frame in range(num_structures): 51 | merge_file.write('%d\n' % total_atoms) 52 | merge_file.write('create from python\n') 53 | writeCoordinates(base, merge_file) 54 | base += atoms_in_single_file 55 | 56 | print('') 57 | print(" --------------------- DONE ---------------------\n") 58 | --------------------------------------------------------------------------------