Esempio n. 1
0
class SplitPDB(object):
    """
    Split the models of a PDB file into new PDB file, where a model corresponds to a new PDB file
    """

    def __init__(self, opts=None):
        """
        @type self: koala.SplitPDB.SplitPDB
        @type opts: OptionParser parameters
        """
        assert opts is not None
        self.opts = opts
        self.path_runs = PathRuns()

    def run_SplitPDB(self):
        """
        Get the PDB input files and run the splitting
        @type self: koala.SplitPDB.SplitPDB
        """
        try:
            self.path_runs.set_path_execute()
            self.path_runs.set_execution_directory()

            link_name = os.path.join(self.opts.outputdir, os.path.basename(self.opts.pdbName))
            if not os.path.exists(link_name):
                os.symlink(self.opts.inputPDB, link_name)
                os.system("cp %s %s" % (link_name, self.path_runs.get_path_execution()))

            pdbs = parse_pdb(
                    self.path_runs.get_path_execution(),
                    os.path.join(self.path_runs.get_path_execution(), self.opts.pdbName))

            path_output, file_output = os.path.split(self.opts.output)

            send_multiple_outputs(
                    self.path_runs.get_path_execution(),
                    pdbs, self.opts.galaxydir,
                    self.opts.outputID)

            if self.opts.createCompressFile == "True":
                if compress_files(pdbs, self.path_runs.get_path_execution(), self.opts.toolname):
                    path_output, file_output = os.path.split(self.opts.outputZip)
                    send_output_results(
                            path_output,
                            file_output,
                            os.path.join(
                                self.path_runs.get_path_execution(), '%s.zip' % self.opts.toolname))

        except Exception, e:
            show_error_message(str(e))
Esempio n. 2
0
class MergePDB(object):
    """
    Merge a set of PDB files into models on a single PDB file
    """

    methods = []
    ignoreoutfiles = ['.pdb']

    def __init__(self, opts=None):
        """
        @type self: koala.MergePDB.MergePDB
        @type opts: OptionParser parameters
        """
        assert opts is not None
        self.opts = opts
        self.path_runs = PathRuns()

    def run_MergePDB(self):
        """
        Get the input PDB files and run to merge
        @type self: koala.MergePDB.MergePDB
        """

        self.path_runs.set_path_execute()
        self.path_runs.set_execution_directory()

        if self.opts.compressedFile == '1':
            if zipfile.is_zipfile(opts.inputPDBs):
                extract_zip_file(opts.inputPDBs, self.path_runs.get_path_execution())
            else:
                try:
                    inF = gzip.GzipFile(opts.inputPDBs, 'rb')
                    f = inF.read()
                    inF.close()
                    if f:
                        extract_gz_file(opts.inputPDBs, self.path_runs.get_path_execution())
                except Exception, e:
                    raise Exception("The input file could not be read.\n%s" % e)
        else:
Esempio n. 3
0
class BuildPopulationMEAMT(object):
    """
    Execute the MEAMT Build Population algorithm.
    """

    sequence = None
    path_execute = None
    os.environ["GMX_MAXBACKUP"] = "-1"

    def __init__(self, opts=None):
        """
        @type self: koala.BuildPopulationMEAMT.BuildPopulationMEAMT
        @type opts: OptionParser parameters
        """
        assert opts is not None
        self.opts = opts
        self.time_execution = TimeJobExecution()
        self.path_runs = PathRuns()
        self.framework = Params('MEAMT')

    def main(self):
        """
        Create the MEAMT Build Population configuration file and begin
        the execution to create a initial population.

        @type self: koala.BuildPopulationMEAMT.BuildPopulationMEAMT
        """
        try:
            self.path_runs.set_path_execute()
            self.path_runs.set_execution_directory()

            print 'create dirs'

            self.sequence = create_local_fasta_file(
                    self.path_runs.get_path_execution(),
                    self.opts.fromFasta,
                    self.opts.inputFasta,
                    self.opts.toolname,
                    self.framework)

            print 'create fasta'

            copy_necessary_files(
                self.path_runs.get_path_execute(),
                self.path_runs.get_path_execution(),
                self.framework.get_framework())

            print 'copy files'

            self.framework.set_command(
                self.path_runs.get_path_execution(),
                'aemt-pop-up2')

            print 'set command'

            size = int(self.opts.sizePopulation) / 15

            cl = [
                self.framework.get_command(),
                str(0),
                self.opts.sizePopulation,
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(size),
                str(0),
                str(0),
                self.opts.VanderWaalsWeight,
                self.opts.ChargeWeight,
                str(0),
                str(0),
                str(0),
                str(0),
                str(0),
                self.opts.SolvWeight,
                self.opts.HbondWeight,
                os.path.join(self.path_runs.get_path_execution(), "fasta.txt"),
                os.path.join(self.path_runs.get_path_execution(), "result.txt"),
                os.path.join(self.path_runs.get_path_execution(), "pop_meamt.txt"),
                os.path.join(self.path_runs.get_path_execution(), "protein.pdb"),
                os.path.join(self.path_runs.get_path_execution(), "saida1.txt"),
                os.path.join(self.path_runs.get_path_execution(), "angles.txt"),
                str(0),
                os.path.join(self.path_runs.get_path_execution(), "meat.txt"),
                '&']

            print cl

            retProcess = subprocess.Popen(cl, 0, None, None, None, False)
            retProcess.wait()

            path_output, file_output = os.path.split(self.opts.output)

            result, html = get_result_files(
                self.path_runs.get_path_execution(), self.opts.toolname)

            send_output_results(path_output, file_output, result)

        except Exception, e:
            show_error_message(str(e))
class RenameAtoms(object):
    """
    Rename the missing atoms of a PDB file according to GROMACS
    """

    path_execute = None
    os.environ["GMX_MAXBACKUP"] = "-1"

    def __init__(self, opts=None):
        """
        @type self: koala.RenameAtoms.RenameAtoms
        @type opts: OptionParser parameters
        """
        assert opts is not None
        self.opts = opts
        self.path_runs = PathRuns()

    def rename_atoms_structure(self, pdbfile, gmx_path, forcefield):
        """
        Create a subprocess to rename the atoms of the PDB input file using pdb2gmx
        @type self: koala.RenameAtoms.RenameAtoms
        @type pdbfile: file
        @type gmx_path: string
        @type forcefield: string
        """
        delete_check_files(self.path_runs.get_path_execution())

        program = os.path.join(gmx_path, "pdb2gmx")
        process = Popen(
            [program, "-f", pdbfile, "-o", pdbfile, "-p", "check.top", "-water", "none", "-ff", forcefield],
            stdout=PIPE,
            stderr=PIPE,
        )
        stdout, stderr = process.communicate()
        process.wait()

        delete_check_files(self.path_runs.get_path_execution())

    def run_RenameAtoms(self):
        """
        Get the PDB file and run the renaming
        @type self: koala.CheckPDBStructure.CheckPDBStructure
        """
        try:
            self.path_runs.set_path_execute()
            self.path_runs.set_execution_directory()

            self.opts.pdbName = self.opts.pdbName.replace(" ", "-").replace("(", "").replace(")", "")

            link_name = os.path.join(self.opts.outputdir, os.path.basename(self.opts.pdbName))
            if not os.path.exists(link_name):
                os.symlink(self.opts.inputPDB, link_name)
                os.system("cp %s %s" % (link_name, self.path_runs.get_path_execution()))

            self.rename_atoms_structure(
                os.path.join(self.path_runs.get_path_execution(), self.opts.pdbName),
                get_path_gromacs(),
                self.opts.forceField,
            )

            path_output, file_output = os.path.split(self.opts.output)

            send_output_results(
                path_output, file_output, os.path.join(self.path_runs.get_path_execution(), self.opts.pdbName)
            )

        except Exception, e:
            show_error_message(str(e))
class BuildConformation2PG(object):
    """
    Execute the 2PG Build Conformation algorithm.
    """

    os.environ["GMX_MAXBACKUP"] = "-1"

    def __init__(self, opts=None):
        """
        @type self: koala.BuildConformation2PG.BuildConformation2PG
        @type opts: OptionParser parameters
        """
        assert opts is not None
        self.opts = opts
        self.path_runs = PathRuns()
        self.framework = Params("2PG")

    def run_Build_Conformation(self):
        """
        Create the 2PG Build Conformation configuration file and begin
        the execution to create a initial population.

        @type self: koala.BuildConformation2PG.BuildConformation2PG
        """
        try:
            self.path_runs.set_path_execute()
            self.path_runs.set_execution_directory()

            self.sequence = create_local_fasta_file(
                self.path_runs.get_path_execution(),
                self.opts.fromFasta,
                self.opts.inputFasta,
                self.opts.toolname,
                self.framework,
            )

            copy_necessary_files(
                self.path_runs.get_path_execute(), self.path_runs.get_path_execution(), self.framework.get_framework()
            )

            self.framework.set_parameter("gromacs_energy_min", self.opts.gromacsEnergyMin)
            self.framework.set_parameter("SizePopulation", self.opts.sizePopulation)
            self.framework.set_parameter("force_field", self.opts.forceField)
            self.framework.set_parameter("rotamer_library", self.opts.rotamerLibrary)

            if self.opts.forceField == "amber99sb-ildn":
                self.framework.set_parameter("c_terminal_charge", self.opts.cTerminal)
                self.framework.set_parameter("n_terminal_charge", self.opts.nTerminal)

            self.framework.set_parameter(
                "SequenceAminoAcidsPathFileName", self.path_runs.get_path_execution() + "fasta.txt"
            )
            self.framework.set_parameter("Local_Execute", self.path_runs.get_path_execution())
            self.framework.set_parameter("Path_Gromacs_Programs", get_path_gromacs())
            self.framework.set_parameter("NativeProtein", "%s1VII.pdb" % self.path_runs.get_path_execution())
            self.framework.set_parameter("Database", "%sDatabase/" % get_path_algorithms("2pg_build_conformation"))

            create_configuration_file(self.path_runs.get_path_execution(), self.framework)

            self.framework.set_command(self.path_runs.get_path_execution(), "protpred-Gromacs_pop_initial")

            config = "configuration.conf"

            cl = [self.framework.get_command(), config, "&"]

            retProcess = subprocess.Popen(cl, 0, stdout=None, stderr=subprocess.STDOUT, shell=False)
            retCode = retProcess.wait()
            if retCode != 0:
                show_error_message("The 2PG framework finished wrong.\nContact the system administrator.")

            path_output, file_output = os.path.split(self.opts.output)

            result, html = get_result_files(self.path_runs.get_path_execution(), self.opts.toolname)

            send_output_results(path_output, file_output, result)

        except Exception, e:
            show_error_message(str(e))