how to write a python script to count number of residues in a 'pdb' file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • iromi
    New Member
    • Mar 2017
    • 6

    how to write a python script to count number of residues in a 'pdb' file

    #!/usr/bin/python
    import sys
    import os
    f1=open('1tfz.p db','r')
    residue=[]
    for line in f1:
    if line.startswith ('ATOM') or line.startswith ('HETATM'):
    res_number=line[22-26]
    if res_number not in residue and line[17-20]!='HOH' and line[17-20]!='WAT':
    residue.append( res_number)
    else:
    continue
    else:
    continue
    f1.close()
    res_total=len(r esidue)
    if res_total>=50 and res_total<=1000 :
    B=res_total
    else:
    B='NO'

    # please can anyone explain me what's wrong with this codes. as the output i want to know number of residues in this pdb file
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    Your question is really to vague to answer; i.e we do not know what the input is and if you really are counting "residues" or something else in the file. Also, there are no code tags (see How to Ask a Question at https://bytes.com/faq.php?faq=postin...ask_a_question) so it would be a waste of time to try and guess as to the indentations. So the only helpful information is to add some print statements to see what is happening
    Code:
    res_number=line[22-26]
    print("res_number =", res_number)
    if res_number not in residue and line[17-20]!='HOH' and line[17-20]!='WAT':
        print("res_number not in")
    else:
        print("res_number else")
    ##  etc.

    Comment

    • iromi
      New Member
      • Mar 2017
      • 6

      #3
      thank you very much for your kind explanation. I will proceed with this.

      Comment

      Working...