Electrostatics / pdb2pqr

PDB2PQR - determining titration states, adding missing atoms, and assigning charges/radii to biomolecules.
http://www.poissonboltzmann.org/
Other
125 stars 34 forks source link

use pd2pqr in python3 script #316

Closed EtienneReboul closed 2 years ago

EtienneReboul commented 2 years ago

Hello,

I would like to implement pdb2pqr directly into my python3 script , but I only found an outdated documentation : https://www.ics.uci.edu/~dock/pdb2pqr/pydoc/ And a clear example doesn't appear in the up to date documentation : https://pdb2pqr.readthedocs.io/en/latest/using/index.html

Could you tell me if it is still possible without tinkering with the code ? And if it is , could you give me a short example on how to implement it or point me to the right documentation?

Thanks in advance , Etienne Reboul

mimminou commented 2 years ago

I actually just opened Github to open an issue about something similar to this...

There are a few problems if you want to implement this library with file streams ( as in without using file paths, only passing streams ), I'm working on fixing that right now since most methods don't accept that, and Argparse ( the library that is used to generate default arguments and parse them ) does not accept passing StringIO either, however I have some ideas on how to circumvent that,

I'm working on it as I'm writing this so you may want to watch my fork. You can find an example of how ( I think ) it should be used here

Note that most of the stuff I deliberately copied from functions already existing in pdb2pqr files. It's full of comments so you shouldn't get lost. Good Luck

sobolevnrm commented 2 years ago

@mimminou Are there problems with the code you checked in?

mimminou commented 2 years ago

@mimminou Are there problems with the code you checked in?

At first glance, there were apparent issues all around because I wasn't familiar with the api, but once I read followed how it works, the only true problem was the fact that get_molecules() is hardcoded to verify if an input file is a true file ( it does this to know it's extension, pdb or cif ) but it can be easily replaced with pdb.read_pdb() so it's not really an issue.

The real issue however is the argument parser, it only accepts subscriptable objects as inputs ( which StringIO isn't ) so you can't pass streams or virtual files to it. This behavior can easily be circumvented without having to modify the library, you just have to initialize the parser with mock arguments and then write the true arguments on it's attributes using the dot notation, this is detailed in here, line 24.

TLDR : I was wrong, the only issue is the argument parser and not the api, it's actually fairly accessible and I really love it, which is why I'm currently working on implementing some of it's functionality in this project.

sobolevnrm commented 2 years ago

@EtienneReboul please see:

Is this what you are looking for?