jensengroup / propka

PROPKA predicts the pKa values of ionizable groups in proteins and protein-ligand complexes based in the 3D structure.
http://propka.org
GNU Lesser General Public License v2.1
263 stars 58 forks source link

Passing a stream no longer works #83

Closed IAlibay closed 4 years ago

IAlibay commented 4 years ago

Related issues

Related to #57

Expected behaviour

In propka 3.1, passing a "Named Stream" i.e. a Stream-like object that also provides a mocked filename that can be read via pathlib.Path (see: MDAnalysis.lib.util.NamedStream) instead of a path of an input PDB file would work.

Example (based on https://github.com/Becksteinlab/propkatraj):

import propka.run as pk
import MDAnalysis as mda
from MDAnalysisTests.datafiles import PSF, DCD
u = mda.Universe(PSF, DCD)

pstream = pstream = mda.lib.util.NamedStream(StringIO(), 'input.pdb')
u.atoms.write(pstream)
pstream.reset()

mol = pk.single(pstream, optargs=['--quiet'])

Actual behaviour

As detailed in #82 using propka.run.single does not seem to currently work, however we would expect the following to work (it does not):

# based on test_basic_regression
from propka.parameters import Parameters
from propka.molecular_container import MolecularContainer
from propka.input import read_parameter_file, read_molecule_file
from propka.lib import loadOptions

options = ['--quiet']
options += [str(Path(pstream))]
args  = loadOptions(options)
parameters = read_parameter_file('propka.cfg', Parameters())
molecule = MolecularContainer(parameters, args)
molecule = read_molecule_file(pstream, molecule)
molecule.calculate_pka()

Causes

As far as I could tell, there are two main causes for this:

1) read_pdb passes input_path instead of input_file:

https://github.com/jensengroup/propka/blob/01debbf63dd51a7edac38e18d96b406abd532351/propka/input.py#L55-L56

2) open_file_for_reading does not work as expected.

Possible fix

Switching fseek -> seek and input_path -> input_file fixes things and does not seem to cause any issues in the regression tests.