我从http://easybioinfo.free.fr/?q=content/amber-trajectory-gromacs-xtc-conversion获得了以下Python脚本
#!/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") 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") 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") 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")但当我运行它:python amber2xtc.py R_1HHO.md5.pdb R_1HHO.prmtop mdcrd R_1HHO_md * .mdcrd R_1HHO_gromacs
我收到以下错误:
File "./amber2xtc.py", line 28 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 ^ SyntaxError: invalid syntaxSyntaxError指向“if”
我认为它可能是Python的旧语法,并且当前版本无法识别?
谁能帮我。 谢谢^ _ ^
I got the following Python script from http://easybioinfo.free.fr/?q=content/amber-trajectory-gromacs-xtc-conversion
#!/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") 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") 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") 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")But when I run it with: python amber2xtc.py R_1HHO.md5.pdb R_1HHO.prmtop mdcrd R_1HHO_md*.mdcrd R_1HHO_gromacs
I got the following error:
File "./amber2xtc.py", line 28 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 ^ SyntaxError: invalid syntaxThe SyntaxError points to "if"
I think it may be an old grammar for Python and was not recognized by current version?
Can anyone help me. Thanks^_^
最满意答案
Python 2.5版本中引入了条件表达式 : link 。 2.4.3不支持它们,这就是你正在运行的。
解决这个问题的一种方法是, int(g) if g.isdigit() else g转换为函数, int(g) if g.isdigit() else g转换为函数,并从列表int(g) if g.isdigit() else g调用该函数。
Conditional expressions have been introduced to Python in version 2.5: link. They are not supported in 2.4.3, which is what you're running.
One way to work around this is by turning int(g) if g.isdigit() else g into a function, and calling that function from the list comprehension.
更多推荐
os,pdb,xtc,pdb_tmp,电脑培训,计算机培训,IT培训"/> <meta name="descriptio
发布评论