Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing a stream no longer works #83

Closed
IAlibay opened this issue Jul 14, 2020 · 0 comments · Fixed by #84
Closed

Passing a stream no longer works #83

IAlibay opened this issue Jul 14, 2020 · 0 comments · Fixed by #84

Comments

@IAlibay
Copy link
Contributor

IAlibay commented Jul 14, 2020

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:

propka/propka/input.py

Lines 55 to 56 in 01debbf

conformations, conformation_names = read_pdb(
input_path, mol_container.version.parameters, mol_container)

  1. open_file_for_reading does not work as expected.
  • At some point in De-lint PROPKA #40, the attribute checks for file-like streams were removed, it's unclear if this was intentional.
  • Calling fseek(0) does not work. It's unclear to me as to what object this originally expected as most python file-like objects implement seek.

Possible fix

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant