diff --git a/propka/lib.py b/propka/lib.py index df583a9..a0ad971 100644 --- a/propka/lib.py +++ b/propka/lib.py @@ -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" @@ -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: diff --git a/propka/molecular_container.py b/propka/molecular_container.py index a45a961..39643de 100644 --- a/propka/molecular_container.py +++ b/propka/molecular_container.py @@ -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() @@ -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': diff --git a/propka/run.py b/propka/run.py index 7eb13a5..2ab7ff7 100644 --- a/propka/run.py +++ b/propka/run.py @@ -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