我正在使用AMBER模拟分子系统。在AMBER中,有一个模块来分析名为" cpptraj"的数据。
通常我在bash脚本中使用命令如下:
#!/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
我发现运行此脚本没有问题。
现在我想使用&#34;用于&#34;在这个脚本中循环,比如,
#!/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
我发现这段代码无法执行。我收到如下错误消息:
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$
如何让这个脚本无问题地运行?提前感谢任何帮助。 谢谢。
答案 0 :(得分:1)
for
不会在heredoc
中作为循环工作。
你需要把循环放在它之外。当您将其放在heredoc
内时,
for i in {0..5};do
按原样传递给程序。
此外,由于您从0
循环到5
,因此条件
if [[ ($i -ge 0) && ($i -lt 10) ]]; then
完全没用。您可以将代码编写为:
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
答案 1 :(得分:0)
尝试在if和for循环中移动cpptraj命令。 cpptraj可能不是unix shell提示符。