I am trying to print some predefined sequence in python
<p>I am trying to add to more paragraph but getting error? I am able to print first three paragraph but while I trying to add to more paragraph getting error. Can anyone please correct?</p>

<p>Input file:</p>

<pre><code>HETATM10910  C4B NAD A 363      60.856 -58.575 149.282  1.00 40.44           C  
HETATM10911  O4B NAD A 363      61.320 -59.488 148.275  1.00 43.48           O  
HETATM10912  C3B NAD A 363      60.243 -57.426 148.473  1.00 40.37           C  
HETATM10914  C2B NAD A 363      60.167 -57.970 147.054  1.00 40.90           C  
HETATM10916  C1B NAD A 363      61.394 -58.766 147.056  1.00 43.29           C  
HETATM10954  C4B NAD B 363      41.496 -54.407 140.932  1.00 39.26           C  
HETATM10955  O4B NAD B 363      41.936 -54.715 139.568  1.00 41.96           O  
HETATM10956  C3B NAD B 363      42.061 -55.476 141.894  1.00 37.13           C  
HETATM10958  C2B NAD B 363      42.883 -56.336 140.942  1.00 38.13           C  
HETATM10960  C1B NAD B 363      42.233 -56.127 139.593  1.00 42.92           C 
</code></pre>

<p>I want to print data as per following: </p>

<pre><code>HETATM 3788  C4B NAI A 302      52.695  15.486   8.535  1.00 57.28           C  
HETATM 3789  O4B NAI A 302      52.258  14.631   7.456  1.00 56.26           O  
HETATM 3794  C1B NAI A 302      53.348  13.816   7.022  1.00 53.44           C 
HETATM 3792  C2B NAI A 302      54.537  14.748   7.190  1.00 50.93           C  

HETATM 3789  O4B NAI A 302      52.258  14.631   7.456  1.00 56.26           O  
HETATM 3794  C1B NAI A 302      53.348  13.816   7.022  1.00 53.44           C 
HETATM 3792  C2B NAI A 302      54.537  14.748   7.190  1.00 50.93           C 
HETATM 3790  C3B NAI A 302      54.225  15.525   8.465  1.00 52.99           C  

HETATM 3794  C1B NAI A 302      53.348  13.816   7.022  1.00 53.44           C 
HETATM 3792  C2B NAI A 302      54.537  14.748   7.190  1.00 50.93           C 
HETATM 3790  C3B NAI A 302      54.225  15.525   8.465  1.00 52.99           C  
HETATM 3788  C4B NAI A 302      52.695  15.486   8.535  1.00 57.28           C  

HETATM 3792  C2B NAI A 302      54.537  14.748   7.190  1.00 50.93           C 
HETATM 3790  C3B NAI A 302      54.225  15.525   8.465  1.00 52.99           C  
HETATM 3788  C4B NAI A 302      52.695  15.486   8.535  1.00 57.28           C  
HETATM 3789  O4B NAI A 302      52.258  14.631   7.456  1.00 56.26           O  

HETATM 3790  C3B NAI A 302      54.225  15.525   8.465  1.00 52.99           C  
HETATM 3788  C4B NAI A 302      52.695  15.486   8.535  1.00 57.28           C  
HETATM 3789  O4B NAI A 302      52.258  14.631   7.456  1.00 56.26           O  
HETATM 3794  C1B NAI A 302      53.348  13.816   7.022  1.00 53.44           C 
</code></pre>

<p>same lie that for each chain. Chain ID may be A to H.
Code: </p>

<pre><code>import os
import sys

d = {}
chainIDs = ('A', 'B', 'C', 'D',)
atomIDs = ('C4B', 'O4B', 'C1B', 'C2B', 'C3B', 'C4B')
with open('1A7K.pdb') as pdbfile:
    for line in map(str.rstrip, pdbfile):
        if line[:6] != "HETATM":
            continue
        chainID = line[21:22]
        atomID = line[13:16].strip()
        if chainID not in chainIDs:
            continue
        if atomID not in atomIDs:
            continue
        try:
            d[chainID][atomID] = line
        except KeyError:
            d[chainID] = {atomID: line}

n = 4
for chain, atoms in d.items():
for atom, line in atoms.items():
    for i in range(len(atom)-n+1):
        for j in range(n):
            print d[chain][atomIDs[i+j]]
        print
</code></pre>

<p>Msg is:</p>

<pre><code>runfile('C:/Users/Desktop/test_python_2.py', wdir='C:/Users/Desktop')
</code></pre>

<p>In your code</p>

<pre><code>for i in range(len(atomIDs)-n+1):
    for j in range(len(i)-n+1):
        for k in range(len((j))-n+1):
            for l in range(n):
</code></pre>

<p>you take the length of <code>i</code> and <code>j</code>. These are integers (obtained from range), and as the error you receive states, <code>int</code> objects do not have a length as such (at least as far as Python's <code>len</code> function is concerned).</p>

<p>What precisely are you trying to do with these for loops? If you wish to print each line for each chain and atom, would something like the following would work?</p>

<pre><code>for chain, atoms in d.items():
    for atom, line in atoms.items():
        print line
</code></pre>

python python-2.7 python-3.x bioinformatics