2013-04-04 44 views
7

我需要一些幫助來運行此代碼。我從(http://easybioinfo.free.fr/?q=content/amber-trajectory-gromacs-xtc-conversion)獲取了此代碼。 我想將琥珀色的軌跡轉換成gromacs軌跡。sh:語法錯誤:錯誤的fd編號

當我執行此代碼時,出現一些錯誤。我粘貼誤差低於該代碼:

#!/usr/bin/python 

#Workflow based on Trajectory Converter - v1.5 by: Justin Lemkul 
#completely reimplemented and improved by Peter Schmidtke & Jesus Seco 

import sys,os,re,fnmatch 

if len(sys.argv)>4 : 
    f=sys.argv[1] 
    if not os.path.exists(f): 
     sys.exit(" ERROR : Something you provided does not exist. Breaking up.\n\nUSAGE : python trajconv_peter.py amberCrd amberTop trajDir trajPattern outPutPrefix\n\n \ 
Example : python amber2xtc.py mdcrd.crd mdcrd.top md *.x.gz md_gromacs\n") 
else : 
    sys.exit(" \n USAGE : python amber2xtc.py AMBERCRD AMBERTOP TRAJDIR TRAJPATTERN OUTPUTPREFIX\n\ 
    Example : python amber2xtc.py mdcrd.crd mdcrd.top md *.x.gz md_gromacs\n\ 
    Note that the AmberCrd can also be a PDB file.\n") 

crd=sys.argv[1] 
top=sys.argv[2] 
trajdir=sys.argv[3] 
pattern=sys.argv[4] 
outputPref=sys.argv[5] 

traj_files=fnmatch.filter(os.listdir(trajdir),pattern) #get the fpocket output folders 


RE_DIGIT = re.compile(r'(\d+)')  #set a pattern to find digits 
ALPHANUM_KEY = lambda s: [int(g) if g.isdigit() else g for g in RE_DIGIT.split(s)]  #create on the fly function (lambda) to return numbers in filename strings 
traj_files.sort(key=ALPHANUM_KEY)  #sort by these numbers in filenames 

print "Will convert the following files : " 
print traj_files 

csn=1 
for file in traj_files : 
    ptrajtmp=open("ptraj_tmp.ptr","w") 
    print "currently converting "+file 
    ptrajtmp.write("trajin "+trajdir+os.sep+file+"\n") 
    ptrajtmp.write("reference "+crd+"\n") 
    ptrajtmp.write("center ~:WAT,CIO mass origin\n") 
    ptrajtmp.write("image origin center :* byres familiar\n") 

    ptrajtmp.write("trajout pdb_tmp/mdcrd.pdb pdb") 
    ptrajtmp.close() 
    if not os.path.exists("pdb_tmp"): 
     os.mkdir("pdb_tmp") 

    os.system("ptraj "+top +" ptraj_tmp.ptr >/dev/null 2>&1") 
    if not os.path.exists("xtc_tmp"): 
     os.mkdir("xtc_tmp") 
    #move to *.pdb 
    os.system("cd pdb_tmp; ls *.pdb.* | cut -f3 -d\".\" | awk '{print \"mv mdcrd.pdb.\"$0\" mdcrd_\"$0\".pdb\" }' | sh ; cd ../") 
    pdb_files=fnmatch.filter(os.listdir("pdb_tmp"),"*.pdb") 
    pdb_files.sort(key=ALPHANUM_KEY)  #sort by these numbers in filenames 
    if csn==1: 
     os.system("editconf -f pdb_tmp/mdcrd_1.pdb -o "+outputPref+"_t1_top.gro >/dev/null 2>&1") 

    for pdb in pdb_files: 
     os.system("echo \"0\" | trjconv -s pdb_tmp/"+pdb+" -f pdb_tmp/"+pdb+" -o xtc_tmp/traj_"+str(csn)+".pdb.xtc -t0 "+str(csn)+" >/dev/null 2>&1") 
     csn+=1 
    if os.path.exists(outputPref+"_traj.xtc"): 
     os.system("trjcat -f "+outputPref+"_traj.xtc xtc_tmp/*.pdb.xtc -o "+outputPref+"_traj.xtc >& trajcat.log") 
    else : 
     os.system("trjcat -f xtc_tmp/*.pdb.xtc -o "+outputPref+"_traj.xtc >& trajcat.log") 
    os.system("rm -rf pdb_tmp/*.pdb") 

    os.system("rm -rf xtc_tmp/*.xtc") 


os.remove("ptraj_tmp.ptr") 
os.system("rmdir pdb_tmp") 
os.system("rmdir xtc_tmp") 

該錯誤是如下:

[email protected]:~/Simulation-Folder-Feb2013/chapter5-thermo-paper2-Vj/analysis-malto-/28-difusion-coeff-malto-thermo/convert-gromacs-format$ python2.7 amber2xtc.py malto-THERMO.crd malto-THERMO.top TRAJDIR malto*.traj md_gromacss 
Will convert the following files : 
['malto-thermo.set11.traj', 'malto-thermo.set12.traj', 'malto-thermo.set13.traj', 'malto-thermo.set14.traj', 'malto-thermo.set15.traj'] 
currently converting malto-thermo.set11.traj 
ls: cannot access *.pdb.*: No such file or directory 
sh: Syntax error: Bad fd number 
currently converting malto-thermo.set12.traj 
ls: cannot access *.pdb.*: No such file or directory 
sh: Syntax error: Bad fd number 
currently converting malto-thermo.set13.traj 
ls: cannot access *.pdb.*: No such file or directory 
sh: Syntax error: Bad fd number 
currently converting malto-thermo.set14.traj 
ls: cannot access *.pdb.*: No such file or directory 
sh: Syntax error: Bad fd number 
currently converting malto-thermo.set15.traj 
ls: cannot access *.pdb.*: No such file or directory 
sh: Syntax error: Bad fd number 
[email protected]:~/Simulation-Folder-Feb2013/chapter5-thermo-paper2-Vj/analysis-malto-/28-difusion-coeff-malto-thermo/convert-gromacs-format$ 

有關信息,我使用的Ubuntu 11.10(64位)。

如何糾正這個錯誤?感謝任何幫助。 謝謝。

+0

關注[PEP - 8](http://www.python.org/dev/peps/pep-0008/) – pradyunsg 2013-04-04 11:20:07

回答

26

的問題可能是,在Ubuntu的11.x的/ bin中/ sh鏈接到/ bin/dash而不是bin bash。

檢查鏈接:

ls -l /bin/sh 

如果/ bin/sh的是爲/ bin /破折號的鏈接,將其更改爲/ bin/bash的。

sudo mv /bin/sh /bin/sh.orig 
sudo ln -s /bin/bash /bin/sh 
+0

非常感謝您的幫助。 – Vijay 2013-04-04 12:53:09

+9

您應該使用'dpkg-reconfigure dash'代替,並在詢問您是否想將短劃線作爲默認系統外殼時選擇'no'。 – Jan 2014-12-02 11:41:31

2

似乎系統命令「ptraj」無法生成該「.pdb」文件/文件。

我會建議更改以下行以不抑制可能出現的錯誤:

os.system("ptraj "+top +" ptraj_tmp.ptr >/dev/null 2>&1") 

repace有:

os.system("ptraj "+top +" ptraj_tmp.ptr") 
+0

抱歉。錯誤地張貼。 PTRAJ正在運行,但我收到錯誤消息(sh:語法錯誤:錯誤的fd號碼)。如何解決這個問題?請多謝,謝謝。 – Vijay 2013-04-04 11:31:28