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

Argument parsing bugfix, plus writeout suppression options. #9

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions propka/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,19 @@ def parse_res_string(res_str):
return chain, resnum, inscode


def loadOptions(*args):
def loadOptions(*args, **kwargs):
"""
load the arguments parser with options

:Keywords:
*commandline*
if True, read options from standard in; otherwise, read options
from args; default True
"""
from optparse import OptionParser

commandline = kwargs.pop('commandline', True)

# defining a 'usage' message
usage = "usage: %prog [options] filename"

Expand Down Expand Up @@ -193,7 +200,7 @@ def loadOptions(*args):


# parsing and returning options and arguments
if len(args) == 0:
if commandline:
# command line
options, args = parser.parse_args()
else:
Expand Down
7 changes: 4 additions & 3 deletions propka/molecular_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import propka.pdb, propka.version, propka.output, propka.conformation_container, propka.group, propka.lib

class Molecular_container:
def __init__(self, input_file, options=None):
def __init__(self, input_file, options=None, writeout=True):
# printing out header before parsing input
propka.output.printHeader()

Expand Down Expand Up @@ -61,8 +61,9 @@ def __init__(self, input_file, options=None):
self.find_covalently_coupled_groups()

# write out the input file
filename = self.file.replace(input_file_extension,'.propka_input')
propka.pdb.write_input(self, filename)
if writeout:
filename = self.file.replace(input_file_extension,'.propka_input')
propka.pdb.write_input(self, filename)


elif input_file_extension == '.propka_input':
Expand Down
13 changes: 9 additions & 4 deletions propka/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,25 @@ def main():
my_molecule.calculate_pka()
my_molecule.write_pka()

def single(pdbfile, optargs=None):
def single(pdbfile, optargs=None, writeout=True):
"""Run a single PROPKA calculation using *pdbfile* as input.

Commandline options can be passed as a **list** in *optargs*.

*writeout* can be set to ``False`` to skip writing results to a file.

.. rubric:: Example

::
single("protein.pdb", optargs=["--mutation=N25R/N181D", "-v", "--pH=7.2"])
"""
optargs = optargs if optargs is not None else []
options, ignored_pdbfiles = propka.lib.loadOptions(*optargs)
options, ignored_pdbfiles = propka.lib.loadOptions(*optargs, commandline=False)

my_molecule = propka.molecular_container.Molecular_container(pdbfile, options)
my_molecule = propka.molecular_container.Molecular_container(pdbfile, options, writeout=writeout)
my_molecule.calculate_pka()
my_molecule.write_pka()

if writeout:
my_molecule.write_pka()

return my_molecule