|
本帖最后由 rtransformation 于 2017-4-15 21:27 编辑
距离自己上两个愚蠢的帖子:
http://bbs.keinsci.com/forum.php?mod=viewthread&tid=5172&extra=
和http://bbs.keinsci.com/forum.php?mod=viewthread&tid=5358&extra=
过去一个多月了,实验室管理服务器的师兄面临毕业,只能我来管理管理服务器了,起初真的是懒得管,懒得学,现在却觉得特别好玩。
起初决定学tcsh的,后来发现bash才是最广的,学习资源也多,所以转投bash,两星期前萌发转到zsh上去的念头,各个节点也都配置好了,后来被自己的理性扼杀了,
为啥?
因为并没有什么用。
这段时间写了套自己用着舒服的bashrc,按照我自己的意愿给自己组的服务器归置了以下,主要写了个gaussian和gamess的脚本,也没什么高明的,贴出来抛砖引玉,
主要是希望大家在这个帖子下面分享分享自己平时能够提高自己运作效率实用脚本或功能,我也好好学习学习。
论坛里也很多高人写的各种脚本,我就不在这儿一一列举了,我发这个帖子主要想把大家的贡献集中起来。
(写的这脚本实验室成员也测试了挺久了,大体没啥问题,但是发现有时候算特别长的任务的时候,不能执行到脚本结尾。)
一、gaussian的计算脚本:
主要能实现的功能就是:
1.运算成功结束后自动删除临时文件。
2.登录时会有提示哪些任务还在进行。
3.登录时会有提示哪些任务已经结束,哪个人物成功了,哪个任务失败了。
4.你在线时,如果有程序结束,会打印log文件最后25行,这在输入文件有问题时比较有用,这样就省的自己打开log文件查看了。
5.在log文件最后追加计算时间,提交及结束日期。
6.在log文件最后追加临时文件夹路径,非正常结束时方便定位。(脚本中没有把gaussian给临时目录弄的随机数字改成分子名称,主要是因为实验室有人喜欢弄同名文件)。
注:要实现2,3需要在.bashrc,或.bash_profile或.bash_login中加入:
- if [ -e ~/tmp/results.log ] ; then
- echo -e "\n\033[33m Tasks that have been already done:\033[0m"
- /bin/cat ~/tmp/results.log
- fi
- rm -f ~/tmp/results.log > /dev/null
- if [ -s ~/tmp/now.log ] ; then
- echo -e "\n\033[33m Tasks that are still going on:\033[0m"
- /bin/cat -n ~/tmp/now.log
- else
- rm -f ~/tmp/now.log > /dev/null
- fi
复制代码
二、gamess脚本(和gaussian大同小异,写好gaussian脚本后,这个几乎是马上就完成了,所以就主要贴不同的地方吧)
- #!/bin/bash
- export MOL=$1
- export NCPUS=$2 #gamess还得自己在外部指定核数,挺讨厌。
- export SUBDIR=~+
- export GMS_SCRDIR=~/tmp/gamess/$
- export GMS_EXEDIR=xxxxxxxxxxxxxxxxx #写你的gamess路径
- export VERNO=00
- if [ null$MOL == null ]; then
- echo -e "\n\033[31m ************************************* \033[0m"
- echo -e "\033[31m Please input the name of a .inp file! \033[0m"
- echo -e "\033[31m ************************************* \033[0m"
- exit
- fi
- if [ null"$NCPUS" == null ] ; then
- export NCPUS=1
- fi
- if [ -e $MOL.inp ] ; then #这儿自动创建路径的地方您要是不喜欢自己可以改改。
- dir=$(dirname `find $PWD -name $MOL.inp`)
- dirpart=${dir#*gamess}
- if [ -e $SUBDIR/$MOL.dat ] ; then #这个地方主要是删除同一任务上次的dat等文件,以确保运算进行。
- rm -f $SUBDIR/$MOL.dat
- echo -e "\n Files that produced by last calculation has been deleted, calculation is going on~"
- else
- echo -e "\n There is no files that produced by last calculation, calculation is just going on~"
- fi
- echo -e "\n *******************************************************"
- echo " Gamess Task:"
- echo " Now calculating $SUBDIR/$MOL.inp!"
- echo " *******************************************************"
- mkdir -p ~/gamess/scratch/$dirpart/$MOL
- export INTGLDIR=~/gamess/scratch/$dirpart/$MOL
- mkdir -p $GMS_SCRDIR
- echo -e "\033[31m Now $SUBDIR/$MOL.inp is still calculated in the background~ \033[0m" >> ~/tmp/now.log
- $GMS_EXEDIR/rungms $MOL $VERNO $NCPUS $GMS_SCRDIR $SUBDIR $GMS_EXEDIR >& $SUBDIR/$MOL.log
- else
- echo -e "\n\033[31m ************************************************************************* \033[0m"
- echo -e "\033[31m Cannot find $SUBDIR/$MOL.inp! Please check your PATH! \033[0m"
- echo -e "\033[31m ************************************************************************* \033[0m"
- exit
- 剩下的和gaussian大同小异。
复制代码
三、检查gaussian的log收敛情况的小脚本。
- #!/bin/bash
- export LOG=$1
- export PATH=~+
- exten=${LOG#*.}
- if [ $exten == "log" ] ; then
- if [ `/usr/bin/grep 'Converged' $PATH/$LOG|/usr/bin/head -n 1|/usr/bin/sed 's/ //g'` ] ; then
- echo -e "\n Now Shows the CONVERGED condition of this calculation:\n"
- /usr/bin/grep 'Converged' $PATH/$LOG -A4
- times=`/usr/bin/grep 'Converged' $PATH/$LOG -c`
- /usr/bin/grep -q "Normal termination" $PATH/$LOG
- if [ $? -eq 0 ] ; then
- echo -e "\n The molecule experienced \033[31m$times\033[0m times iteration during this calculation~\n"
- else
- echo -e "\n This molecule is ERROR terminated or the calculation is still going on with the \033[31m$times\033[0m th iteration~\n"
- fi
- else
- echo -e "\n There exists no CONVERGED information during this calculation~\n"
- fi
- else
- echo -e "\n Please input the right logfile name or make sure that you are inputting a logfile!\n"
- fi
复制代码
我这脚本里肯定有写的罗嗦的地方,希望大家批评指正,
希望大家多多分享linux实用脚本,以及其他跟计算化学相关的实用脚本,互相学习。
|
评分 Rate
-
查看全部评分 View all ratings
|