Thank you very much! but could you please explain to me how can i achieve the 3rd "Find and extract the line that starts with HETNAM" founction?
nowadays I have the PDB file I need but I would like to get the HETNAM information automatically by running python scripts.
Please show me how to do this! thank you very much
3 answers
In pseudocode, with links to the appropriate documentation:
This should work (hopefully). [?]
open file to read it (mode 'r')
f_in = open('/home/pdb/filename.pdb', 'r')
iterate over lines
for line in f_in:
# print the line when HETNAM is found
if line.startswith('HETNAM'):
print line
close the file
f_in.close() [?]
One Unix command line will do the job even quicker: [?] grep HETNAM /home/pdb/filename.pdb [?]
Mark, I advise you to read and learn a bit about common Unix tools such as grep, awk, sed...
Wasn't this a solved problem 15 years ago :)
Here is you python code I hope this helps
//Open the file
file = open('/home/pdb/filename.pdb', 'w')
//print to check file is loaded or not
print file
// iterate through the file till the end of file for line in file.readline():
//check weather line is containing the Keyword
if line == 'HETNAM'
//if yes the print the line or store it in another string
print line
Sorry but the above Python code is totally wrong.
open file to read it (mode 'r')
f_in = open('/home/pdb/filename.pdb', 'r')
iterate over lines
for line in f_in: # print the line when HETNAM is found if line.startswith('HETNAM'): print line
close the file
f_in.close()
One line of Unix command line will do the job even quicker: grep HETNAM /home/pdb/filename.pdb
Mark, I will advise you to read and learn a bit about common Unix tools such as grep, awk, sed...
Sorry but the above Python code is totally wrong.
Sorry but the above Python code is incorrect. Indeed, // are not used for comments (# instead), never use 'file' as a variable name since it is already used by Python. The 'if' statement must be terminated by a colon (:) and eventually indentation is mandatory in Python code.
Sorry but the above Python code is incorrect. Indeed, // are not used for comments (# instead), never use 'file' as a variable name since it is already used by Python, to read a file use the 'r' mode not the 'w' one that is used to write a file, the 'if' statement must be terminated by a colon (:) and eventually indentation is mandatory in Python code
Sorry but the above Python code is incorrect. Indeed, // are not used for comments (# instead), never use 'file' as a variable name since it is already used by Python, use the 'r' mode to read a file (not the 'w' one), the 'if' statement must be terminated by a colon (:) and eventually indentation is mandatory in Python code.
Thanks a lot Pierre. I am use to java coding a lot that's why did some mistakes while posting it. Thanks for your honest reply.
Log in to answer this question.
What have you tried so far?
I only can find whether the file has HETNAM or not but i cannot extract the information within the hetnam and formul
HETNAM M3L N-TRIMETHYLLYSINE
FORMUL 3 M3L 2(C9 H21 N2 O2 1+)
FORMUL 5 HOH *63(H2 O)
this is the information I want thank you
The problem with this kind of question: it's unreasonable to expect other people to simply "write your code for you", without giving some indication that you have made an effort. And in the long run, that won't help you anyway. If your problem is that you know little/no Python, then you need to learn some, then come back when you have specific problems. If you just want some working code, search Google for "python pdb parser"; you'll find plenty of examples and useful libraries (hint: BioPython).