#
# title: Assignment 6, Question 5
# summary: Calculate an average consecutive CA-distance in a PDB file
# author:
# date:
#
# description:
#
# This program calculates the average distance between two consecutive
# alpha carbons in a protein. It should be run from the command line
# using the following syntax:
#
# python cadist.py
#
# Where filename is the name of a simple PDB file.
#
import sys, math
def main(pdbfile):
# Insert your solution below this line.
print 'Average CA-CA Distance:', 'Not Implemented'
print 'Sample Variance:', 'Not Implemented'
# Insert your solution above this line
#
# The following function calculates the average of a list of
# numbers.
#
def average(mylist):
avg = 0.0
for val in mylist:
avg = avg + val
return avg/float(len(mylist))
#
# This function calculates the variance (standard deviation)
# of a list of numbers.
#
def variance(mylist):
var = 0.0
avg = average(mylist)
for val in mylist:
dif = val - avg
var = var + dif*dif
return math.sqrt(var/float(len(mylist) - 1.0))
#
# This function calculates the distance between two points,
# given as x1, y1, z1, and x2, y2, z2.
#
def distance(x1, y1, z1, x2, y2, z2):
x = x1 - x2
y = y1 - y2
z = z1 - z2
return math.sqrt(x*x + y*y + z*z)
#
# This function loads the coordinates stored in a PDB file.
# The return result is a list, each of whose elements correspond
# to an atom in the PDB file. The list elements are themselves
# a list, containing the following values (in this order):
#
# * The residue name (a string)
#
# * The residue index (an integer number)
#
# * The atom name (a string)
#
# * The atom's x coordinate (a floating-point number)
#
# * The atom's y coordinate (a floating-point number)
#
# * The atom's z coordinate (a floating-point number)
#
def read_pdb(pdbfile):
pdbf = open(pdbfile)
l = pdbf.readline()
atoms = []
while l:
if l[0:4].upper() == 'ATOM':
toks = l.split()
atm_name = toks[2]
res_name = toks[3]
res_indx = int(toks[4])
x = float(toks[5])
y = float(toks[6])
z = float(toks[7])
atoms.append([res_name, res_indx, atm_name, x, y, z])
l = pdbf.readline()
pdbf.close()
return atoms
#
# The lines below parse the command line. You are welcome to study them,
# but don't worry if you don't know what's going on.
#
if __name__ == '__main__':
if len(sys.argv) <> 2:
print 'usage: python cadist.py '
sys.exit()
else:
main(sys.argv[1])