0

I am Using AMBER to simulation molecular system. In AMBER there is a module to analyse data called "cpptraj".

Normally I use the command in bash script as below:

#!/bin/bash


path="../Production-from-gpu"
system="maltoLyo-23per" 
top="maltoLyo23per.top" 
alltraj="md-product.center.reimage-all.traj" 
outtraj="maltoLyo-23per-reimage" 


cpptraj $top << EOF


trajin  ../$system-MD001-run0100.traj 1 100 5 
trajin  ../$system-MD001-run0200.traj 1 100 5 
trajin  ../$system-MD001-run0300.traj 1 100 5 
trajin  ../$system-MD001-run0400.traj 1 100 5 
trajin  ../$system-MD001-run0500.traj 1 100 5 
trajin  ../$system-MD001-run0600.traj 1 100 5 
trajin  ../$system-MD001-run0700.traj 1 100 5 
trajin  ../$system-MD001-run0800.traj 1 100 5 
trajin  ../$system-MD001-run0900.traj 1 100 5 
trajin  ../$system-MD001-run1000.traj 1 100 5 

trajout abc.traj mdcrd

EOF

I find no problem running this script.

Now I want to use "for" loop in this script, like,

#!/bin/bash


path="../Production-from-gpu"
system="maltoLyo-23per" 
top="maltoLyo23per.top" 
alltraj="md-product.center.reimage-all.nc" 
outtraj="maltoLyo-23per-reimage" 



cpptraj $top << EOF

for i in {0..5};do

if [[ ($i -ge 0) && ($i -lt  10) ]]; then


trajin  $path/$system-MD00i-run0100.traj 1 100 5 
trajin  $path/$system-MD00i-run0200.traj 1 100 5 
trajin  $path/$system-MD00i-run0300.traj 1 100 5 
trajin  $path/$system-MD00i-run0400.traj 1 100 5 
trajin  $path/$system-MD00i-run0500.traj 1 100 5 
trajin  $path/$system-MD00i-run0600.traj 1 100 5 
trajin  $path/$system-MD00i-run0700.traj 1 100 5 
trajin  $path/$system-MD00i-run0800.traj 1 100 5 
trajin  $path/$system-MD00i-run0900.traj 1 100 5 
trajin  $path/$system-MD00i-run1000.traj 1 100 5 
fi


trajout abc.traj mdcrd
##############################################


done
EOF

I find this code can not be executed. I get error message like:

vijay@glycosim:/media/glycoExtra/TRAJECTORY-lyotropic-system300ns/maltoLyo-C12-23per/Select-traj-using-cpptraj$ ./generate_traj_select_script.sh

CPPTRAJ: Trajectory Analysis. V13.15
    ___  ___  ___  ___
     | \/ | \/ | \/ | 
    _|_/\_|_/\_|_/\_|_
    AmberParm Title: [default_name]
    Radius Set: modified Bondi radii (mbondi)
INPUT: Reading Input from STDIN
  [for i in {0..5};do]
[for]: Command not found.

vijay@glycosim:/media/glycoExtra/TRAJECTORY-lyotropic-system300ns/maltoLyo-C12-23per/Select-traj-using-cpptraj$ 

How I can make this script to run without problem? Appreciate any help in advance. Thank you.

1
  • Why would you try to pass for to cpptraj? Commented Mar 17, 2014 at 10:22

2 Answers 2

1

for wouldn't work as a loop within the heredoc.

You need to put the loop outside of it. When you place it inside the heredoc, the

for i in {0..5};do

gets passed as is to the program.

Moreover, since you are looping from 0 to 5, the condition

if [[ ($i -ge 0) && ($i -lt  10) ]]; then

is completely useless. You might write your code as:

for i in {0..5};do

cpptraj $top << EOF

trajin  $path/$system-MD00i-run0100.traj 1 100 5 
trajin  $path/$system-MD00i-run0200.traj 1 100 5 
trajin  $path/$system-MD00i-run0300.traj 1 100 5 
trajin  $path/$system-MD00i-run0400.traj 1 100 5 
trajin  $path/$system-MD00i-run0500.traj 1 100 5 
trajin  $path/$system-MD00i-run0600.traj 1 100 5 
trajin  $path/$system-MD00i-run0700.traj 1 100 5 
trajin  $path/$system-MD00i-run0800.traj 1 100 5 
trajin  $path/$system-MD00i-run0900.traj 1 100 5 
trajin  $path/$system-MD00i-run1000.traj 1 100 5 

trajout abc.traj mdcrd

EOF

done
Sign up to request clarification or add additional context in comments.

1 Comment

The code is running now. Thanks. But I do not get what I want. When the i=0, the code inside the "cpptraj" will select some data and will write into "abc.traj" file. Then, when i=1, the code inside the "cpptraj" suppose to do the same but it must append to the file "abc.traj". Unfortunately, this time it just over write the "abc.trah" file. Is there anyway to avoid the over writing and append to the file? Thanks in advance.
0

Try moving the cpptraj command inside of the if and for loop. cpptraj probably isn't a unix shell prompt.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.