def run_SortByFront(self, fitness):
        """
        Run the 2PG Sort algorithm for each objectivies combinations
        @type self: koala.DominanceRanking.DominanceRanking
        @type fitness: string
        """

        NumberObjective, Fitness_Energy = format_fitness(fitness)

        self.framework.set_parameter('NumberObjective', NumberObjective)
        self.framework.set_parameter('Fitness_Energy', Fitness_Energy)

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

        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.\n"
                "Try to check and rename the PDB input files or contact the system administrator.")
    def run_SortByFront(self):
        """
        Run the 2PG Sort algorithm to calculate the Pareto fronts and sorting
        @type self: koala.SortByFront.SortByFront
        """

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

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

        self.framework.set_parameter(
                'objective_analisys_dimo_source',
                '/home/%s/programs/dimo/DIMO2' % get_logged_user())
        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())

        NumberObjective, Fitness_Energy = format_fitness(self.opts.inputFitness)

        self.framework.set_parameter('NumberObjective', NumberObjective)
        self.framework.set_parameter('Fitness_Energy', Fitness_Energy)

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

        config = 'configuration.conf'

        if self.opts.compressedFile == '1':

            inputFiles = self.opts.inputPDBs.split(",")

            for input_f in inputFiles:
                if zipfile.is_zipfile(input_f):
                    extract_zip_file(input_f, self.path_runs.get_path_execution())
                else:
                    try:
                        inF = gzip.GzipFile(input_f, 'rb')
                        f = inF.read()
                        inF.close()
                        if f:
                            extract_gz_file(input_f, self.path_runs.get_path_execution())
                    except Exception, e:
                        raise Exception("The input file could not be read.\n%s" % e)
    def run_SortByFront(self):
        """
        Run the 2PG Sort Method algorithm to calculate the Pareto fronts and sorting
        @type self: koala.SortByFront.SortByFront
        """

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

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

        self.framework.set_parameter(
                'objective_analisys_dimo_source',
                '/home/%s/programs/dimo/DIMO2' % get_logged_user())
        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())

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

        self.loadMatrixFile(self.opts.inputTxt)

        objFile = os.path.join(self.path_runs.get_path_execution(), 'objectivies.txt')

        self.framework.set_command(
            self.path_runs.get_path_execution(),
            'protpred-Gromacs-Sort_Method_by_Front_Dominance')

        cl = ['nohup', self.framework.get_command(), objFile, '&']

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

        self.getBetterPDBs(self.path_runs.get_path_execution())

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

        send_output_files_html(self.opts.htmlfiledir, filesHtml)
        send_output_files_html(self.opts.htmlfiledir, [result])

        self.makeHtml()
    def run_Random(self):
        """
        Create the 2PG Random configuration file and begin the execution.

        @type self: koala.Random2PG.Random2PG
        """

        try:
            self.path_runs.set_path_execute()
            if self.opts.inputEmail:
                email = validate_email(self.opts.inputEmail)
                self.path_runs.set_execution_directory(email)
            else:
                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)

            SizePopulation = create_local_pop_file(
                    self.path_runs.get_path_execution(),
                    self.opts.inputPop,
                    self.framework)

            if SizePopulation > 1:
                show_error_message(
                    "Error: The population file must contain only one model")

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

            self.framework.set_parameter(
                'rotamer_library', self.opts.rotamerLibrary)
            self.framework.set_parameter(
                'StepNumber', self.opts.stepNumber)
            self.framework.set_parameter(
                'How_Many_Rotation', self.opts.howManyRotation)
            self.framework.set_parameter(
                'force_field', self.opts.forceField)
            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',
                    '%s/Database/' %
                    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-Random_Algorithm')

            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.")

            parse_pdb(
                    self.path_runs.get_path_execution(),
                    'random_algorithm_solutions.pdb',
                    20,
                    'randomSolution')

            if(self.opts.runMinimization == 'true'):
                self.do_minimization("randomSolution")

            pdbs = list_directory(
                self.path_runs.get_path_execution(), 'randomSolution-M*.pdb')

            build_images(pdbs, self.path_runs.get_path_execution())

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

            name, ext = os.path.splitext(self.opts.filehtml)

            htmldir = os.path.join(path_output, '%s_files' % name)

            if not os.path.exists(htmldir):
                os.makedirs(htmldir)

            self.opts.htmlfiledir = htmldir

            result, filesHtml = get_result_files(
                    self.path_runs.get_path_execution(),
                    self.opts.toolname,
                    'randomSolution-M')

            send_output_files_html(self.opts.htmlfiledir, filesHtml)
            send_output_files_html(self.opts.htmlfiledir, [result])

            if self.opts.createCompressFile == "True":
                if compress_files(pdbs, self.path_runs.get_path_execution(), "2PGRandom"):
                    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(), '2PGRandom.zip'))

            self.makeHtml()

            if(self.opts.useJmol in ('True', 'true')):
                self.makeHtmlWithJMol(pdbs[0])

            if(self.opts.inputEmail):
                send_email(
                        '*****@*****.**',
                        email,
                        '%s Execution on Galaxy - Cloud USP' % self.opts.toolname,
                        get_message_email(self.opts.toolname),
                        [],
                        'smtp.gmail.com')

        except Exception, e:
            show_error_message(str(e))
    def main(self):
        """
        Create the ProtPred-EDA configuration file and begin the execution.

        @type self: koala.ProtPredEDA.ProtPredEDA
        """
        try:
            self.path_runs.set_path_execute()
            if self.opts.inputEmail:
                email = validate_email(self.opts.inputEmail)
                self.path_runs.set_execution_directory(email)
            else:
                self.path_runs.set_execution_directory()

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

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

            # Config
            self.framework.set_parameter('OptimMethod', 'rboa')
            self.framework.set_parameter('MaxEval', self.opts.MaxEval)
            self.framework.set_parameter('Threshold', self.opts.Threshold)

            # FitnessPSP
            self.framework.set_parameter('VanderWaals', self.opts.VanderWaals)
            # ClassColection.setParameter('SASA', self.opts.SASA)
            self.framework.set_parameter('Coulomb', self.opts.Coulomb)
            self.framework.set_parameter('Solvatation', self.opts.Solvatation)
            self.framework.set_parameter('HydrogenBond', self.opts.HydrogenBond)
            self.framework.set_parameter('Torsion', self.opts.Torsion)
            self.framework.set_parameter('UseAngleDB', self.opts.UseAngleDB)
            self.framework.set_parameter('AminoAcidL', self.opts.AminoAcidL)

            # rboa
            self.framework.set_parameter('PopSize', self.opts.PopSize)
            self.framework.set_parameter('SelSize', self.opts.SelSize)
            self.framework.set_parameter('MaxParents', self.opts.MaxParents)
            self.framework.set_parameter('MixtureComponents', self.opts.MixtureComponents)

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

            self.framework.set_command(
                self.path_runs.get_path_execution(),
                'protpred')

            config = 'input.ini'

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

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

            copy_files_to_execute_folder(
                self.path_runs.get_path_execution(),
                'ProtPredEDA_rBOA')

            if(self.opts.runMinimization == 'true'):
                self.do_minimization("ProtPredEDA_rBOA")

            pdbs = sorted(list_directory(self.path_runs.get_path_execution(), '*.pdb'))

            build_images(pdbs, self.path_runs.get_path_execution())

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

            name, ext = os.path.splitext(self.opts.filehtml)

            htmldir = os.path.join(path_output, '%s_files' % name)

            if not os.path.exists(htmldir):
                os.makedirs(htmldir)

            self.opts.htmlfiledir = htmldir

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

            send_output_results(path_output, file_output, result)

            send_output_files_html(self.opts.htmlfiledir, filesHtml)
            send_output_files_html(self.opts.htmlfiledir, [result])

            if self.opts.createCompressFile == "True":
                if compress_files(pdbs, self.path_runs.get_path_execution(), "ProtPredEDA-rBOA"):
                    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(), 'ProtPredEDA-rBOA.zip'))

            self.makeHtml()

            if(self.opts.useJmol in ('True', 'true')):
                self.makeHtmlWithJMol(pdbs[0])

            if(self.opts.inputEmail):
                send_email(
                        '*****@*****.**',
                        email,
                        '%s Execution on Galaxy - Cloud USP' % self.opts.toolname,
                        get_message_email(self.opts.toolname),
                        [],
                        'smtp.gmail.com')

        except Exception, e:
            show_error_message(str(e))
    def run_NSGAII(self):
        """
        Create the 2PG NSGA-II configuration file and begin the execution.

        @type self: koala.NSGAII2PG.NSGAII2PG
        """
        try:
            self.path_runs.set_path_execute()
            if self.opts.inputEmail:
                email = validate_email(self.opts.inputEmail)
                self.path_runs.set_execution_directory(email)
            else:
                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,
            )

            SizePopulation = create_local_pop_file(
                self.path_runs.get_path_execution(), self.opts.inputPop, 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("NumberGeration", self.opts.numberGeration)
            self.framework.set_parameter("SizePopulation", SizePopulation)
            self.framework.set_parameter(
                "SequenceAminoAcidsPathFileName", self.path_runs.get_path_execution() + "fasta.txt"
            )
            self.framework.set_parameter("How_Many_Rotation", self.opts.howManyRotation)
            self.framework.set_parameter("rotamer_library", self.opts.rotamerLibrary)
            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"))

            NumberObjective, Fitness_Energy = format_fitness(self.opts.inputFitness, self.opts.toolname)

            self.framework.set_parameter("NumberObjective", NumberObjective)
            self.framework.set_parameter("Fitness_Energy", Fitness_Energy)

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

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

            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.")

            parse_pdb(
                self.path_runs.get_path_execution(),
                "pop_NON_DOMINATED_%s.pdb" % self.opts.numberGeration,
                20,
                "NSGAIISolutions",
            )

            if self.opts.runMinimization == "true":
                self.do_minimization("NSGAIISolutions")

            pdbs = list_directory(self.path_runs.get_path_execution(), "NSGAIISolutions-M*.pdb")

            build_images(pdbs, self.path_runs.get_path_execution())

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

            name, ext = os.path.splitext(self.opts.filehtml)

            htmldir = os.path.join(path_output, "%s_files" % name)

            if not os.path.exists(htmldir):
                os.makedirs(htmldir)

            self.opts.htmlfiledir = htmldir

            result, filesHtml = get_result_files(
                self.path_runs.get_path_execution(), self.opts.toolname, "NSGAIISolutions-M"
            )

            send_output_results(path_output, file_output, result)

            send_output_files_html(self.opts.htmlfiledir, filesHtml)
            send_output_files_html(self.opts.htmlfiledir, [result])

            if self.opts.createCompressFile == "True":
                if compress_files(pdbs, self.path_runs.get_path_execution(), "2PGNSGAII"):
                    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(), "2PGNSGAII.zip")
                    )

            self.makeHtml()

            if self.opts.useJmol in ("True", "true"):
                self.makeHtmlWithJMol(pdbs[0])

            if self.opts.inputEmail:
                send_email(
                    "*****@*****.**",
                    email,
                    "%s Execution on Galaxy - Cloud USP" % self.opts.toolname,
                    get_message_email(self.opts.toolname),
                    [],
                    "smtp.gmail.com",
                )

        except Exception, e:
            show_error_message(str(e))
    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))