Get Hetnam Information From A Pdb File
3
0
Entering edit mode
10.9 years ago
Mark ▴ 70

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

python pdb • 2.5k views
ADD COMMENT
2
Entering edit mode

What have you tried so far?

ADD REPLY
2
Entering edit mode

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).

ADD REPLY
0
Entering edit mode

I only can find whether the file has HETNAM or not but i cannot extract the information within the hetnam and formul

ADD REPLY
0
Entering edit mode

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

ADD REPLY
2
Entering edit mode
10.9 years ago

In pseudocode, with links to the appropriate documentation:

ADD COMMENT
0
Entering edit mode

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?

ADD REPLY
2
Entering edit mode
10.9 years ago

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...

ADD COMMENT
1
Entering edit mode

Wasn't this a solved problem 15 years ago :)

ADD REPLY
0
Entering edit mode
10.9 years ago
Abid ▴ 30

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

ADD COMMENT
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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...

ADD REPLY
0
Entering edit mode

Sorry but the above Python code is totally wrong.

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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.

ADD REPLY

Login before adding your answer.

Traffic: 2259 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6