parsing pdb file with format change
<p>I have a file that looks something like this:</p>

<pre><code>ATOM   7748  CG2 ILE A 999      53.647  54.338  82.768  1.00 82.10           C  
ATOM   7749  CD1 ILE A 999      51.224  54.016  84.367  1.00 83.16           C  
ATOM   7750  N   ASN A1000      55.338  57.542  83.643  1.00 80.67           N  
ATOM   7751  CA  ASN A1000      56.604  58.163  83.297  1.00 80.45           C  
ATOM   7752  C   ASN A1000      57.517  58.266  84.501  1.00 80.30           C  
</code></pre>

<p>As you can see the " " disappears between column 4 and 5 (starting to count at 0). Thus the code below fails. I'm new to python (total time now a whole 3 days!) and was wondering what's the best way to handle this. As long as there is a space, the line.split() works. Do I have to do a character count and then parse the string with an absolute reference?</p>

<pre><code>import string
visited = {}
outputfile = open(file_output_location, "w")
for line in open(file_input_location, "r"):
    list = line.split()
    id = list[0]
    if id == "ATOM":
        type = list[2]
        if type == "CA":
            residue = list[3]
            if len(residue) == 4:
                residue = residue[1:]
            type_of_chain = list[4]
            atom_count = int(list[5])
            position = list[6:9]
            if(atom_count &gt;= 1):
                if atom_count not in visited and type_of_chain == chain_required:
                    visited[atom_count] = 1
                    result_line = " ".join([residue,str(atom_count),type_of_chain," ".join(position)])
                    print result_line
                    print &gt;&gt;outputfile, result_line
outputfile.close()
</code></pre>
