[Tutor] map one file and print it out following the sequence

lina lina.lastname at gmail.com
Wed Oct 12 05:31:42 CEST 2011


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,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111012/7c6ce21a/attachment-0001.html>


More information about the Tutor mailing list