Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 5
0
def main(optargs=None):
    """Read in structure files, calculate pKa values, and print pKa files.


    .. versionchanged:: 3.4.0
       Removed ability to write out PROPKA input files.
    """
    # loading options, flags and arguments
    logger = logging.getLogger("")
    stdout_handler = logging.StreamHandler(sys.stdout)
    stdout_handler.setFormatter(logging.Formatter("%(message)s"))
    logger.addHandler(stdout_handler)
    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()
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def run_propka(args, biomolecule):
    """Run a PROPKA calculation.

    :param args:  command-line arguments
    :type args:  argparse.Namespace
    :param biomolecule:  biomolecule object
    :type biomolecule:  Biomolecule
    :return:  (DataFrame-convertible table of assigned pKa values, pKa information from PROPKA)
    :rtype:  (list, str)
    """
    # TODO - eliminate need to write temporary file
    lines = io.print_biomolecule_atoms(atomlist=biomolecule.atoms,
                                       chainflag=args.keep_chain,
                                       pdbfile=True)
    with NamedTemporaryFile("wt", suffix=".pdb", delete=False) as pdb_file:
        for line in lines:
            pdb_file.write(line)
        pdb_path = pdb_file.name
    parameters = pk_in.read_parameter_file(args.parameters, Parameters())
    molecule = MolecularContainer(parameters, args)
    molecule = pk_in.read_molecule_file(pdb_path, molecule)
    molecule.calculate_pka()

    # Extract pKa information from PROPKA
    # write_pka( self, self.version.parameters, filename=filename, conformation='AVR', reference=reference)
    lines = []
    # lines.append(f"{pk_out.get_propka_header()}")
    # lines.append(f"{pk_out.get_references_header()}")
    # lines.append(
    #     pk_out.get_determinant_section(
    #         molecule, 'AVR', molecule.version.parameters
    #     )
    # )
    # lines.append(
    #     pk_out.get_summary_section(
    #         molecule, "AVR", molecule.version.parameters
    #     )
    # )
    # lines.append(pk_out.get_the_line())
    lines.append(
        pk_out.get_folding_profile_section(
            molecule,
            conformation="AVR",
            reference="neutral",
            window=[0.0, 14.0, 1.0],
        ))
    lines.append(
        pk_out.get_charge_profile_section(molecule, conformation="AVR"))
    lines.append(pk_out.get_the_line())
    pka_str = "\n".join(lines)

    # Summarize in pKas in DataFrame for later use
    conformation = molecule.conformations["AVR"]
    rows = []
    for group in conformation.groups:
        row_dict = OrderedDict()
        atom = group.atom
        row_dict["res_num"] = atom.res_num
        row_dict["res_name"] = atom.res_name
        row_dict["chain_id"] = atom.chain_id
        row_dict["group_label"] = group.label
        row_dict["group_type"] = getattr(group, "type", None)
        row_dict["pKa"] = group.pka_value
        row_dict["model_pKa"] = group.model_pka
        if group.coupled_titrating_group:
            row_dict["coupled_group"] = group.coupled_titrating_group.label
        else:
            row_dict["coupled_group"] = None
        rows.append(row_dict)
    return rows, pka_str
Ejemplo n.º 8
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