In [ ]:
from IPython.display import HTML
HTML('<iframe width="560" height="315" src="https://www.youtube.com/embed/zV949buXdSg?autoplay=1&loop=1" frameborder="0" allowfullscreen></iframe>')

Structures like these are encoded in "PDB" files

Entries are determined by columns in the file, not by spaces between the columns


In [ ]:
#record   atom_name chain           x       y       z   occupancy        atom_type
#  |          |       |             |       |       |      |                  |
#ATOM   1086  CG  LYS A 141      -4.812   9.683   2.584  1.00 26.78           N0
#         |        |      |                                     |
#    atom_num amino_acid  resid_num                           bfactor

Predict what the following will do


In [ ]:
line_frompdb = "ATOM   1086  N   SER A 141      -4.812   9.683   2.584  1.00 26.78           N0"
print(line_frompdb[2:4])

Write a program that:

  • Reads a pdb file (download 1stn.pdb)
  • Grabs all "ATOM" lines whose atom type is "CA"
  • Shifts the position of the molecule in x by +10 angstroms
  • Writes out a new pdb file containing these shifted atoms
  • If you want to check your work, download PyMOL and open up the files

In [ ]:
#record   atom_name chain           x       y       z   occupancy        atom_type
#  |          |       |             |       |       |      |                  |
#ATOM   1086  CG  LYS A 141      -4.812   9.683   2.584  1.00 26.78           N0
#         |        |      |                                     |
#    atom_num amino_acid  resid_num                           bfactor

In [ ]:
f = open("data/1stn.pdb")
g = open("1stn_shifted.pdb","w")

for line in f.readlines():
    if line[0:4] == "ATOM" and line[13:16] == "CA ":

        first_chunk = line[:30]
        x = line[30:38]
        last_chunk = line[38:]
        
        new_x = float(x) + 10
        
        g.write("{:}{:8.3f}{:}".format(first_chunk,new_x,last_chunk))

f.close()
g.close()