Beispiel #1
0
def run_propka(options, pdb_path, tmp_path):
    """Run PROPKA software.

    Args:
        options:  list of PROPKA options
        pdb_path:  path to PDB file
        tmp_path:  path for working directory
    """
    options += [str(pdb_path)]
    args = loadOptions(options)
    try:
        _LOGGER.warning(
            "Working in tmpdir {0:s} because of PROPKA file output; "
            "need to fix this.".format(str(tmp_path)))
        cwd = Path.cwd()
        os.chdir(tmp_path)
        parameters = read_parameter_file(args.parameters, Parameters())
        molecule = MolecularContainer(parameters, args)
        molecule = read_molecule_file(str(pdb_path), molecule)
        molecule.calculate_pka()
        molecule.write_pka()
        if args.generate_propka_input:
            molecule.write_propka()
    finally:
        os.chdir(cwd)
Beispiel #2
0
def single(pdbfile, optargs=None):
    """Run a single PROPKA calculation using *pdbfile* as input.

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

    Example
    -------
    Given an input file "protein.pdb", run the equivalent of ``propka3
    --mutation=N25R/N181D -v --pH=7.2 protein.pdb`` as::

       propka.run.single("protein.pdb",
                         optargs=["--mutation=N25R/N181D", "-v", "--pH=7.2"])


    .. todo::
       Test :func:`single`, not sure if it is correctly processing ``pdbfile``.

    """
    optargs = optargs if optargs is not None else []
    options = loadOptions(*optargs)
    pdbfile = options.filenames.pop(0)
    parameters = read_parameter_file(options.parameters, Parameters())
    if len(options.filenames) > 0:
        _LOGGER.warning("Ignoring filenames: {0:s}".format(options.filenames))
    my_molecule = MolecularContainer(parameters, options)
    my_molecule = read_molecule_file(pdbfile, my_molecule)
    my_molecule.calculate_pka()
    my_molecule.write_pka()
    if options.generate_propka_input:
        my_molecule.write_propka()
    return my_molecule
Beispiel #3
0
def main(optargs=None):
    """Read in structure files, calculate pKa values, and print pKa files."""
    # loading options, flags and arguments
    optargs = optargs if optargs is not None else []
    options = loadOptions(*optargs)
    pdbfiles = options.filenames
    parameters = read_parameter_file(options.parameters, Parameters())
    for pdbfile in pdbfiles:
        my_molecule = MolecularContainer(parameters, options)
        my_molecule = read_molecule_file(pdbfile, my_molecule)
        my_molecule.calculate_pka()
        my_molecule.write_pka()
        if options.generate_propka_input:
            my_molecule.write_propka()
Beispiel #4
0
def run_propka_stream(options, input_file, filename):
    """Run PROPKA software.

    Args:
        options:  list of PROPKA options
        input_file:  file-like PDB object
        filename: filename for the file-like PDB object
    """
    options += [filename]
    args = loadOptions(options)
    parameters = read_parameter_file(args.parameters, Parameters())
    molecule = MolecularContainer(parameters, args)
    molecule = read_molecule_file(filename, molecule, stream=input_file)
    molecule.calculate_pka()
    molecule.write_pka()
    if args.generate_propka_input:
        molecule.write_propka()
Beispiel #5
0
def single(pdbfile, optargs=None):
    """Run a single PROPKA calculation using *pdbfile* as input.

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

    .. rubric:: Example

    ::
       single("protein.pdb", optargs=["--mutation=N25R/N181D", "-v",
              "--pH=7.2"])
    """
    optargs = optargs if optargs is not None else []
    options = loadOptions(*optargs)
    pdbfile = options.filenames.pop(0)
    parameters = read_parameter_file(options.parameters, Parameters())
    if len(options.filenames) > 0:
        _LOGGER.warning("Ignoring filenames: {0:s}".format(options.filenames))
    my_molecule = MolecularContainer(parameters, options)
    my_molecule = read_molecule_file(pdbfile, my_molecule)
    my_molecule.calculate_pka()
    my_molecule.write_pka()
    if options.generate_propka_input:
        my_molecule.write_propka()
    return my_molecule
Beispiel #6
0
def single(file, optargs: tuple = (), write_pka: bool = True):
    """Run a single PROPKA calculation using ``filename`` as input.

    Args:
        filename (str): name of input file. If filestream is not passed via
            ``stream``, should be a path to the file to be read.
        optargs (tuple): Optional, commandline options for propka. Extra files
            passed via ``optargs`` will be ignored, see Notes.
        stream : optional filestream handle. If ``None``, then ``filename``
            will be used as path to input file for reading.
        write_pka (bool): Controls if the pKa file should be writen to disk.

    Returns:
        :class:`~propka.molecular_container.MolecularContainer` object.

    Examples:
        Given an input file "protein.pdb", run the equivalent of ``propka3
        --mutation=N25R/N181D -v --pH=7.2 protein.pdb`` as::

            propka.run.single("protein.pdb", 
                optargs=["--mutation=N25R/N181D", "-v", "--pH=7.2"])

        By default, a pKa file will be written. However in some cases one may
        wish to not output this file and just have access to the
        :class:`~propka.molecular_container.MolecularContainer` object. If so,
        then pass ``False`` to ``write_pka``::

            mol = propka.run.single("protein.pdb", write_pka=False)

        In some cases, one may also want to pass a file-like (e.g.
        :class:`io.StringIO`) object instead of a file path as a string. In
        these cases the file-like object should be passed to the ``stream``
        argument and a string indicating the file type in the ``filename``
        argument; this string only has to look like a valid file name, it does
        not need to exist because the data are actually read from ``stream``.
        This approach is necessary because file-like objects do not usually
        have names, and propka uses the ``filename`` argument  to determine the
        input file type, and assigns the file name for the
        :class:`~propka.molecular_container.MolecularContainer` object::

            mol = propka.run.single('input.pdb', stream=string_io_file)

        In this case, a PDB file-like object was passed as `string_io_file`.
        The resultant pKa file will be written out as `input.pka`.

    Notes:
        * Only a single input structure file will be processed, defined by
          ``filename`` (and ``stream`` if passing a file-like object). Any
          additional files passed via the `-f` or `--file` flag to optargs will
          be ignored.


    .. seealso::

        :func:`propka.input.read_molecule_file`

    """
    # Deal with input optarg options
    optargs = tuple(optargs)
    optargs += (filename,)
    options = loadOptions(optargs)

    parameters = read_parameter_file(options.parameters, Parameters())

    # Only filename present should be the one passed via the arguments
    # Anything else will probably have been passed using optargs' `-f` flag.
    ignored_list = [i for i in options.filenames if i != filename]
    if ignored_list:
        _LOGGER.warning(f"Ignoring extra filenames passed: {ignored_list}")
    options.filenames = [filename]

    my_molecule = MolecularContainer(parameters, options)
    my_molecule = read_molecule_file(file, my_molecule)
    my_molecule.calculate_pka()

    # write outputs
    if options.generate_propka_input:
        my_molecule.write_propka()
    if write_pka:
        my_molecule.write_pka()

    return my_molecule