I tried to write one (not working one) as below, so many problems here. #!/usr/bin/python3
import os.path LINESTOSKIP=0 CHAINID="CDEFGHI" INFILENAME="pdbone.pdb" DICTIONARYFILE="itpone.itp" mapping={} valuefromdict={} def sortfile(): for chainid in CHAINID: sortoneblock(chainid) def generatedictionary(dictfilename): text=fetchonefiledata(DICTIONARYFILE) for line in text: parts=line.strip().split() if len(parts)==8: mapping[parts[4]]=parts[0] print(mapping) def sortoneblock(cID) text=fetchonefiledata(INFILENAME) for line in text: blocks=line.strip().split() if len(blocks)== 11 and blocks[3] == "CUR" and blocks[4] == "cID": valuefromdict[blocks[2]]=mapping[block[2]] return def fetchonefiledata(infilename): text=open("infilename").readlines() if os.path.splitext(infilename)[1]=".itp" return text if os.path.splitext(infilename)[1]=".pdb" return text[LINESTOSKIP:] if __name__=="__main__": sortfiles() The representative lines from itpone.itp is: 1 CH3 1 CUR C21 1 0.200 15.0350 2 OA 1 CUR O4 1 -0.400 15.9994 3 C 1 CUR C19 1 0.200 12.0110 The representative lines from pdbone.pdb is: ATOM 827 C19 CUR C 85 31.891 29.624 0.280 1.00 0.00 ... ATOM 831 O4 CUR C 85 31.865 28.248 0.183 1.00 0.00 ATOM 832 C21 CUR C 85 32.823 27.366 0.801 1.00 0.00 The expected results of pdbone.pdb will be: ATOM 832 C21 CUR C 85 32.823 27.366 0.801 1.00 0.00 ATOM 831 O4 CUR C 85 31.865 28.248 0.183 1.00 0.00 ATOM 827 C19 CUR C 85 31.891 29.624 0.280 1.00 0.00 Thanks for telling me the existing problems. Best regards,
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor