A brief guide to MoDaR script language
- Modar wraps a bounch of functions for setuping and running a MD simulation job, these functions can actually be seen as internal commands of Modar. A simple and easy script language is implemented in Modar for concatenating these internal commands to realize all available modules designed by the developers. Taking the advantage of the script language, user can do some very flexiable modeling and complex analyzing jobs without making effort to play with the source code, developers can also save a lot of time and suffering on test stage when developing a new module.
- Modar script language is very simlar to the Linux shell script language. Let's take a example first, bellow is the content of a script file "rst.inp" for resuming a MD simulation.
To run 1000000 steps more resuming MD simulation simply by command: ./modar rst.inp nstepmore=1000000 –o rst_1.log
Where:
|
Here is the list of content
Basic rules of Modar script
- One single line of script can only take one Modar command or statement. But one command or statement can be splited in several lines. Character “\” in the end of command line means continuous line following.
- Character “#” serves as a comments marker. Comments cannot be resided in the middle a sentence, only can
- Modar script is case insensitive except the filename used in some internal command.
Variable and array
- Variables in Modar scrip can be a string or a real number type, Modar can determine the type automatically according to the expression, user don’t need to declared it with a type name.
- Modar supports one dimension array only and the member index can be negative. The array exported by Modar commands always start from 0.
- For example:
outputfile=”test.out” # initiate a file name string
istepstart=1000000 # initiate a number
nstepmore=100000 # assign nstepmore a value 100000
x[0]=10 # assign nstepmore a value 100000
x[1]=20 # assign nstepmore a value 100000
echo $istepstart #print the value of istepstart
echo $x[0] $x[1] #print the value of istepstart
echo $nstepmore > $outputfile #print the value of nstepmore to file “test.out”
Expression
- Modar supports both math expression and string expression, but they are only valid in assignment statement, if statement and while statement.
- For example:
#assign the sum of istepstart and nstepmore to nsteptot
nsteptot=$istepstart+$nstepmore
i=rand(1.0)
j=int(rand(1000000))
wd=/home/mengen/villin
trjfn=$wd/villin.trj
- Additionally, Modar supports selection expression in many intrinsic commands.
For example:
#define a atoms cluster
defcls pocket select="segid proa && seq 26 82 99 59 56 55 46 && ! type N C O HN CA HA*"
#to calculate the distance between a ligand and the binding pocket
calc dist select=”pocket” select=”resname DMS”
- Math expression
Please see here - Bool expression
Please see here - String functions
Please see here
If statement
- There are two forms of “if” statement. The short form is typed on a single line and but can specify only a single command if the expression is true.
if ( expression ) command
for example:
outputfile=”test.out” # initiate a file name string
if(-f $outputfile) exec rm ¨Crf $outputfile
- The long form uses else and braces to allow for blocks of commands to be nested inside the condition.
if ( bool expression1 ) {
command
}
else if ( bool expression2 ) {
command
...
}
else {
command
}
- For example:
include “size.inc” #feed a,b,c,boxl
#get a box type from user
getText boxtype default=”cubic” msg=”please tell the box type”
#process the boxtype
if($boxtype .head. "cubi") { #cubic
boxl=$a
if($boxl<$b) boxl=$b
if($boxl<$c) boxl=$c
a=$boxl
b=$boxl
c=$boxl
}
else if($boxtype .head. "tetr") { #tetragonal
boxl=$a
if($boxl<$b) boxl=$b
a=$boxl
b=$boxl
}
else if($boxtype .head. "octa") { #octahidralt
boxl=$a
if($boxl<$b) boxl=$b
if($boxl<$c) boxl=$c
a=$boxl
b=$boxl
c=$boxl
}
else{
echo -hs "| ** unknown boxtype: $boxtype"
goto tellboxtype_and_abort
}
While statement (loop)
- The while statement evaluates an expression, if it is true, the shell runs the nested commands and then repeats for as long as the expression remains true. Please note that there is no short form of while statement supported, only long form as shown bellow is available.
while ( bool expression){
command
...
}
- For example:
#load a trajectory
trjin file="step9_harvest.trj"
ifrm=0
while($ifrm<$ntotframes){
trjreadnextframe
mdtime=$curmdtime
#print progress for every 10ps
tmod=$mdtime%10
if($tmod==0) echo -hs "current MD time: $mdtime ps"
#calculate RMSD for main chain atoms
calc rmsd fitgroup="mainpro and name C CA N O" \
calcgroup="mainpro and name C CA N O"
echo "$mdtime $value" >> mainrmsd.txt
#calculate distance between terminals
calc dist group1="residue PROA 41" group2="residue PROA 76"
echo "$mdtime $value" >> dist.txt
#calculate PHI,PSI for residue 50
calc dihe group1="atom PROA 49 C" \
group2="atom PROA 50 N" \
group3="atom PROA 50 CA" \
group4="atom PROA 50 C"
phi=$value
calc dihe group1="atom PROA 50 N" \
group2="atom PROA 50 CA" \
group3="atom PROA 50 C" \
group4="atom PROA 51 N"
psi=$value
echo "$mdtime $PHI $PSI" >> phipsi.txt
#calculate Radius of Gyration
calc rgy select="all"
echo "$mdtime $value" >> rgy.txt
ifrm=$ifrm+1
}
Goto statement and label
- Modar script supports label and goto statement, which also can serve as a loop, a switch or a psudo-routine.
- For example:
if(!-var boxtype) {
echo -hs "| ** please specify the boxtype in command line"
echo -hs "| for example: $scmdline boxtype=cubic"
goto tellboxtype_and_abort
}
... # command blocks skipeed
stop
:tellboxtype_and_abort
echo -hs valid boxtype are:
echo -hs " cubic a=b=c alpha=beta=gamma=90 ndgf=1"
echo -hs " tetragonal a=b alpha=beta=gamma=90 ndgf=2"
echo -hs " rectangular a/A=b/B=c/C alpha=beta=gamma=90 ndgf=1"
echo -hs " orthorhombic a,b,c alpha=beta=gamma=90 ndgf=3"
echo -hs " octahidralt a=b=c alpha=beta=gamma=ACOS(-1/3) ndgf=1"
abort
Contact us
Phone: | 400-660-8656 | |
Email: | support@beemd.org |
我们长期和北京市计算中心合作提供计算培训服务,承接托管计算业务,如有需求请随时联系我们。