Example #1
0
def runAntechamber(force_field, file, output_ext="mol2", charge=None):
    """
    A wrapper around antechamber.

    Parameters
    ----------
    force_field : str
        Which force field to use. Only "gaff" and "gaff2" are accepted.
    file : str
        Name of input file.
    output_ext : str
        Output extension.
    charge : int
        The net charge of the molecule. Default: automatic detection by antechamber.

    Returns
    -------
    output_name : str
        Absolute path of the output parametrised file.
    """
    input_base, input_ext = _os.path.splitext(file)[0], file.split(".")[-1]
    if input_ext.lower() in ["mol", "sdf"]:
        _babel.babelTransform(file, output_extension="mol2", pH=None)
        input_ext = "mol2"

    output_name = "%s_antechamber.%s" % (input_base, output_ext)

    commandstr = "antechamber -i '%s' -fi %s -o '%s' -fo %s -c bcc -at %s -s 2" % (
        file, input_ext, output_name, output_ext, force_field)
    if charge is not None:
        commandstr += " -nc {}".format(charge)

    _runexternal.runExternal(commandstr, procname="antechamber")

    return _os.path.abspath(output_name)
Example #2
0
    def protonate(self,
                  reprotonate=False,
                  babel_parameters=None,
                  rdkit_parameters=None):
        """
        Protonates the ligand using OpenBabel.

        Parameters
        ----------
        reprotonate : bool
            Whether to reprotonate an already protonated ligand.
        babel_parameters : dict
            Keyword arguments to be passed to ProtoCaller.Wrappers.babelwrapper
        rdkit_parameters : dict
            Keyword arguments to be passed to ProtoCaller.Wrappers.rdkitwrapper
        """
        with self.workdir:
            if babel_parameters is None: babel_parameters = {}
            babel_parameters = {"pH": 7.0, **babel_parameters}
            if rdkit_parameters is None: rdkit_parameters = {}

            if self.protonated and not reprotonate:
                _logging.info("Ligand %s is already protonated." % self.name)
            else:
                filename_temp = _rdkit.saveFromRdkit(self.molecule,
                                                     filename="%s.mol" %
                                                     self.name)
                # here we use PDB because of parser differences between OpenBabel and RDKit concerning mol and mol2 files
                self.protonated_filename = _babel.babelTransform(
                    filename_temp, "pdb", **babel_parameters)
                _os.remove(filename_temp)
                self.molecule = _rdkit.openFileAsRdkit(
                    self.protonated_filename,
                    removeHs=False,
                    **rdkit_parameters)
Example #3
0
    def parametrise(self,
                    params=None,
                    molecule_type="ligand",
                    id=None,
                    reparametrise=False):
        """
        Parametrises the ligand using ProtoCaller.Parametrise.

        Parameters
        ----------
        params : ProtoCaller.Parametrise.Params
            Force field parameters.
        molecule_type : str
            The type of the molecule. One of: "ligand" and "cofactor".
        id : str
            The name of the molecule. Default: equal to the ligand name.
        reparametrise : bool
            Whether to reparametrise an already parametrised ligand.
        """
        with self.workdir:
            if self._parametrised and not reparametrise:
                _logging.debug("Ligand %s is already parametrised." %
                               self.name)
                return

            _logging.info("Parametrising ligand %s..." % self.name)
            if not self.protonated:
                _logging.warning(
                    "Cannot parametrise unprotonated ligand. Protonating first with default parameters..."
                )
                self.protonate()

            if params is None:
                params = _parametrise.Params()

            # we convert the protonated file into a pdb so that antechamber can read it
            filename = _babel.babelTransform(self.protonated_filename, "pdb")
            if id is None: id = self.name

            charge = _rdmolops.GetFormalCharge(self.molecule)
            self.parametrised_files = _parametrise.parametriseFile(
                params=params,
                filename=filename,
                molecule_type=molecule_type,
                id=id,
                charge=charge)