473,396 Members | 1,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

6
#!/usr/bin/python
import sys
import os
f1=open('1tfz.pdb','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(residue)
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
Mar 6 '17 #1
2 2178
dwblas
626 Expert 512MB
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
Expand|Select|Wrap|Line Numbers
  1. res_number=line[22-26]
  2. print("res_number =", res_number)
  3. if res_number not in residue and line[17-20]!='HOH' and line[17-20]!='WAT':
  4.     print("res_number not in")
  5. else:
  6.     print("res_number else")
  7. ##  etc. 
Mar 6 '17 #2
iromi
6
thank you very much for your kind explanation. I will proceed with this.
Mar 7 '17 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Scott Chapman | last post by:
Hi! I'd like a "file" on the Linux box to actually be the input and output of a Python script. Anything written to the file would be sent to a database and anything read from the file would...
7
by: Pankaj | last post by:
The module which i am creating is like Part A: 1. It does some processing by using python code. 2. The result of this python code execution is written to a text file. ] Part B: 1. I read a...
3
by: Water Cooler v2 | last post by:
How does one use a .pdb file that contains debug symbols for a project. It contains binary data. How do I use it to diagnose the application?
22
by: Glurt Wuntal | last post by:
I am a newbie with Python. It's a great language, but I would like to be able to present a simple gui menu for some of my scripts; something better than using 'raw_input' prompts. Any...
4
by: Chris8Boyd | last post by:
I am embedding Python in a MSVC++ (2005) application. The application creates some environment and then launches a Python script that will call some functions exported from the MSVC++ application....
1
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent...
1
by: Siegfried Heintze | last post by:
Does someone have a little python script that will read a file in UTF-8/UTF-16/UTF-32 (my choice) and search for all the characters between 0x7f-0xffffff and convert them to an ASCII digit string...
1
by: Ormazd | last post by:
Hello, I was wondering if anyone might be able to help me with a little PERL script? I'm very new and I have been given a task to write a simple Perl script that prints out the file names and...
6
by: Dave067 | last post by:
Hi This is my first attempt at writing Python script - it's probably a bit ambitious, but there again, whatever doesn't kill you makes you stronger... ;-) I'm trying to write a script for a...
0
by: discusshere | last post by:
Hello, I have to count the number of pages in the document that I am uploading. This document can be a word file, xls, txt or pdf. I have my code working for pdf but not for other types. Here is the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.