Monday, April 6, 2009

More hints for exercise 1

When reading a pdb file, you might want to first create two empty lists and add to them as you are parsing the lines. At the end, you can turn the position list into an array. For example,
Pos = []
ResNames = []
for line in file(PdbFile, 'r').readlines():
if line.startswith("TER"):
#break out of the loop over lines
break
elif line.startswith("ATOM"):
#check to see if it's an alpha carbon
if line[12:16].strip() == "CA":
#.... your code here to get x, y, z
#and ResName from the string line...
Pos.append([x, y, z])
ResNames.append(ResName)
Pos = np.array(Pos, float)
MSS

No comments: