Difference between revisions of "Extractedmin2pdb.py"
Jump to navigation
Jump to search
import>Em427 |
import>Em427 |
||
Line 1: | Line 1: | ||
− | #!/usr/bin/env python |
+ | #!/usr/bin/env python |
+ | |||
+ | import sys |
||
+ | import string |
||
+ | |||
+ | ############################################################### |
||
+ | ## # |
||
+ | ## Edyta Malolepsza # |
||
+ | ## David Wales' group, University of Cambridge # |
||
+ | ## in case of problems please send email: em427@cam.ac.uk # |
||
+ | ## # |
||
+ | ############################################################### |
||
+ | ## |
||
+ | ## transform path.info into path_all.pdb |
||
+ | ## ./path2pdb.py |
||
+ | ## |
||
+ | ############################################################### |
||
+ | |||
+ | prmtop = open("coords.prmtop").read() |
||
+ | f = string.split(prmtop, "\n") |
||
+ | q0 = f.index("%FLAG POINTERS ") |
||
− | import sys |
||
+ | q1 = f.index("%FLAG ATOM_NAME ") |
||
− | import string |
||
+ | q2 = f.index("%FLAG RESIDUE_LABEL ") |
||
− | |||
+ | q3 = f.index("%FLAG RESIDUE_POINTER ") |
||
− | ############################################################### |
||
+ | |||
− | ## # |
||
+ | ## names of tables are related to names in prmtop file |
||
− | ## Edyta Malolepsza # |
||
+ | |||
− | ## David Wales' group, University of Cambridge # |
||
+ | atomNumber = int(string.split(f[q0+2])[0]) |
||
− | ## in case of problems please send email: em427@cam.ac.uk # |
||
+ | |||
− | ## # |
||
+ | atomName = [] |
||
− | ############################################################### |
||
+ | residueLabel = [] |
||
− | ## |
||
+ | |||
− | ## transform path.info into path_all.pdb |
||
+ | an = 0 |
||
− | ## ./path2pdb.py |
||
+ | line = 0 |
||
− | ## |
||
+ | while (an<atomNumber): |
||
− | ############################################################### |
||
+ | for j in range(20): |
||
− | |||
+ | if (an<atomNumber): |
||
− | prmtop = open("coords.prmtop").read() |
||
+ | an = an+1 |
||
− | f = string.split(prmtop, "\n") |
||
+ | atomName.append(f[q1+2+line][j*4:(j+1)*4].strip()) |
||
− | |||
+ | else: |
||
− | q0 = f.index("%FLAG POINTERS ") |
||
+ | break |
||
− | q1 = f.index("%FLAG ATOM_NAME ") |
||
+ | line = line+1 |
||
− | q2 = f.index("%FLAG RESIDUE_LABEL ") |
||
+ | |||
− | q3 = f.index("%FLAG RESIDUE_POINTER ") |
||
+ | for i in range(q3-q2-2): |
||
− | |||
+ | for j in range((len(f[q2+2+i])+1)/4): |
||
− | ## names of tables are related to names in prmtop file |
||
+ | residueLabel.append(string.strip(f[q2+2+i][j*4:4*(j+1)])) |
||
− | |||
+ | |||
− | atomNumber = int(string.split(f[q0+2])[0]) |
||
+ | info = open("extractedmin").read() |
||
− | |||
+ | ff = string.split(info, "\n") |
||
− | atomName = [] |
||
+ | |||
− | residueLabel = [] |
||
+ | xyz = open('points.min.pdb','w') |
||
− | |||
+ | |||
− | an = 0 |
||
+ | for i in range(len(ff)/(atomNumber)): |
||
− | line = 0 |
||
+ | mm = 1 |
||
− | while (an<atomNumber): |
||
− | for j in range( |
+ | for j in range(atomNumber): |
− | + | x = float(string.split(ff[atomNumber*i+j])[0]) |
|
+ | y = float(string.split(ff[atomNumber*i+j])[1]) |
||
− | an = an+1 |
||
+ | z = float(string.split(ff[atomNumber*i+j])[2]) |
||
− | atomName.append(f[q1+2+line][j*4:(j+1)*4].strip()) |
||
+ | if (atomName[j]=='N' and atomName[j+1]=='H'): |
||
− | else: |
||
− | + | mm = mm+1 |
|
+ | xyz.write("%4s%7d %-4s %-4s%5d%12.3f%8.3f%8.3f\n" % ('ATOM', j+1, atomName[j], residueLabel[mm-1], mm, x, y, z)) |
||
− | line = line+1 |
||
+ | else: |
||
− | |||
+ | xyz.write("%4s%7d %-4s %-4s%5d%12.3f%8.3f%8.3f\n" % ('ATOM', j+1, atomName[j], residueLabel[mm-1], mm, x, y, z)) |
||
− | for i in range(q3-q2-2): |
||
+ | |||
− | for j in range((len(f[q2+2+i])+1)/4): |
||
+ | xyz.write("END\n") |
||
− | residueLabel.append(string.strip(f[q2+2+i][j*4:4*(j+1)])) |
||
+ | |||
− | |||
+ | xyz.write("\n") |
||
− | info = open("extractedmin").read() |
||
+ | xyz.close() |
||
− | ff = string.split(info, "\n") |
||
− | |||
− | xyz = open('points.min.pdb','w') |
||
− | |||
− | for i in range(len(ff)/(atomNumber)): |
||
− | mm = 1 |
||
− | for j in range(atomNumber): |
||
− | x = float(string.split(ff[atomNumber*i+j])[0]) |
||
− | y = float(string.split(ff[atomNumber*i+j])[1]) |
||
− | z = float(string.split(ff[atomNumber*i+j])[2]) |
||
− | if (atomName[j]=='N' and atomName[j+1]=='H'): |
||
− | mm = mm+1 |
||
− | xyz.write("%4s%7d %-4s %-4s%5d%12.3f%8.3f%8.3f\n" % ('ATOM', j+1, atomName[j], residueLabel[mm-1], mm, x, y, z)) |
||
− | else: |
||
− | xyz.write("%4s%7d %-4s %-4s%5d%12.3f%8.3f%8.3f\n" % ('ATOM', j+1, atomName[j], residueLabel[mm-1], mm, x, y, z)) |
||
− | |||
− | xyz.write("END\n") |
||
− | |||
− | xyz.write("\n") |
||
− | xyz.close() |
Revision as of 14:23, 30 April 2008
#!/usr/bin/env python import sys import string ############################################################### ## # ## Edyta Malolepsza # ## David Wales' group, University of Cambridge # ## in case of problems please send email: em427@cam.ac.uk # ## # ############################################################### ## ## transform path.info into path_all.pdb ## ./path2pdb.py ## ############################################################### prmtop = open("coords.prmtop").read() f = string.split(prmtop, "\n")
q0 = f.index("%FLAG POINTERS ") q1 = f.index("%FLAG ATOM_NAME ") q2 = f.index("%FLAG RESIDUE_LABEL ") q3 = f.index("%FLAG RESIDUE_POINTER ") ## names of tables are related to names in prmtop file atomNumber = int(string.split(f[q0+2])[0]) atomName = [] residueLabel = [] an = 0 line = 0 while (an<atomNumber): for j in range(20): if (an<atomNumber): an = an+1 atomName.append(f[q1+2+line][j*4:(j+1)*4].strip()) else: break line = line+1 for i in range(q3-q2-2): for j in range((len(f[q2+2+i])+1)/4): residueLabel.append(string.strip(f[q2+2+i][j*4:4*(j+1)])) info = open("extractedmin").read() ff = string.split(info, "\n") xyz = open('points.min.pdb','w') for i in range(len(ff)/(atomNumber)): mm = 1 for j in range(atomNumber): x = float(string.split(ff[atomNumber*i+j])[0]) y = float(string.split(ff[atomNumber*i+j])[1]) z = float(string.split(ff[atomNumber*i+j])[2]) if (atomName[j]=='N' and atomName[j+1]=='H'): mm = mm+1 xyz.write("%4s%7d %-4s %-4s%5d%12.3f%8.3f%8.3f\n" % ('ATOM', j+1, atomName[j], residueLabel[mm-1], mm, x, y, z)) else: xyz.write("%4s%7d %-4s %-4s%5d%12.3f%8.3f%8.3f\n" % ('ATOM', j+1, atomName[j], residueLabel[mm-1], mm, x, y, z)) xyz.write("END\n") xyz.write("\n") xyz.close()