Exemple #1
0
    def run(self):

        for j in tqdm(range(0, self.try_number)):
            a = Protein(copy.deepcopy(self.string), j)

            self.direction_list.append(0)

            for i in range(1, len(self.string)):
                check = True
                while check:
                    direction = random.choice(self.direction_options)
                    check = a.fold_next_amino(i, direction)

                self.direction_list.append(
                    direction)  # output z klopt hierdoor niet

            a.getscore()
            score = a.score
            self.score_list.append(score)
            self.protein_list.append(a)
            if score > self.highscore:
                self.highscore = score
                self.counter = j

        self.best_solution = self.protein_list[self.counter]
        return self.best_solution
Exemple #2
0
    def __init__(self, string):

        self.string = string
        self.proteins = [Protein(string, uuid.uuid4())]
        self.best_solution = None
        self.best_value = -float('inf')
        self.direction_options = [-1, 1, -2, 2, -3, 3]
Exemple #3
0
    def run(self):
        """
        Runs three fold one step
        """

        self.best_score = 1

        # runs the program x times depending on the runamount
        for z in range(self.runamount):

            done = False

            # restarts the program if an error occurs
            while done == False:

                # sets first fold and adds to final
                protein = Protein(self.user_input)

                # splits protein sequence into chunks of three amino acids
                user_input_split = split_protein(self.user_input)

                # updates x,y coordinates based on most recently determined fold
                coordinate_update = CoordinateUpdate()
                coordinate_update.update_coordinates(protein.final_placement)

                for i in range(len(user_input_split)):

                    current_x, current_y = coordinate_update.update_coordinates(
                        protein.final_placement)
                    current_fold = protein.final_placement[-1][1]
                    current_amino = self.user_input[len(
                        protein.final_placement)]
                    best_option = three_fold(protein.final_placement,
                                             user_input_split, current_fold,
                                             current_x, current_y,
                                             current_amino, i)

                    # checks if an error has occured
                    if best_option == False:
                        break

                    placement = [
                        current_amino, best_option[0], current_x, current_y
                    ]
                    protein.add_amino_info(placement)

                    # checks if the end of protein hasn't been reached
                    if current_fold != 0:
                        current_x, current_y = coordinate_update.update_coordinates(
                            protein.final_placement)

                    # checks if last amino of sequence is reached
                    if len(protein.final_placement) == (len(self.user_input) -
                                                        1):
                        protein.add_last_amino_of_chunk_without_score(
                            current_x, current_y, self.user_input)

                    # end of protein has been reached
                    if protein.final_placement[-1][1] == 0:
                        done = True
                        self.stability = Stability()

                        stability_score, stability_connections = self.stability.get_stability_score(
                            protein.final_placement)
                        self.stability_coordinates = stability_connections
                        self.stability.stability_score_coordinates(
                            self.stability_coordinates)
                        amino_stability_x = self.stability.amino_stability_x
                        amino_stability_y = self.stability.amino_stability_y

                        # checks if current score is lower than the current lowest score
                        if stability_score < self.best_score:
                            self.best_score = stability_score
                            self.best_protein = protein.final_placement
                            self.best_stability = stability_score
                            self.amino_stability_x = amino_stability_x
                            self.amino_stability_y = amino_stability_y
Exemple #4
0
def main(string_input, algorithm_input):

    # analyse user input to choose the string and convert to numerical string
    if string_input == 1:
        protein_string = ["H", "H", "P", "H", "H", "H", "P", "H", "P", "H", "H", "H", "P", "H"]
    
    if string_input == 2:
        protein_string = ["H", "P", "H", "P", "P", "H", "H", "P", "H", "P", "P", "H", "P", "H", "H", "P", "P", "H", "P", "H"]

    if string_input == 3:
        protein_string = ["P","P","P","H","H","P","P","H","P","P","P","P","P","H","H","H","H","H","H","H","P","P","H","H","P","P","P","P","H","H","P","P","H","P","P"]

    if string_input == 4:
        protein_string = ["H", "H", "P", "H", "P", "H", "P", "H", "P", "H", "H", "H", "H", "P", "H", "P", "P", "P", "H", "P", "P" , "P", "H", "P", "P", "P", "P", "H", "P", "P", "P", "H", "P", "P", "P", "H", "P", "H", "H", "H", "H", "P", "H", "P", "H", "P", "H", "P", "H", "H"]
    
    if string_input == 5:
        protein_string = ["P", "P", "C", "H", "H", "P", "P", "C", "H", "P", "P", "P", "P", "C", "H", "H", "H", "H", "C", "H", "H", "P", "P", "H", "H", "P", "P", "P", "H", "H", "P", "P", "H", "P", "P"]

    if string_input == 6:
        protein_string = ["C", "P", "P", "C", "H", "P", "P", "C", "H", "P", "P", "C", "P", "P", "H", "H", "H", "H", "H", "H", "C", "C", "P", "C", "H", "P", "P", "C", "P", "C", "H", "P", "P", "H", "P", "C"]

    if string_input == 7:
        protein_string = ["H", "C", "P", "H", "P", "C", "P", "H", "P", "C", "H", "C", "H", "P", "H", "P", "P", "P", "H", "P", "P", "P", "H", "P", "P", "P", "P", "H", "P", "C", "P", "H", "P", "P", "P", "H", "P", "H", "H", "H", "C", "C", "H", "C", "H", "C", "H", "C", "H", "H"]

    if string_input == 8:
        protein_string = ["H", "C", "P", "H", "P", "H", "P", "H", "C", "H", "H", "H", "H", "P", "C", "C", "P", "P", "H", "P", "P", "P", "H", "P", "P", "P", "P", "C", "P", "P", "P", "H", "P", "P", "P", "H", "P", "H", "H", "H", "H", "C", "H", "P", "H", "P", "H", "P", "H", "H"]  
        
    protein_string_converted = string_converter(protein_string)

    # set initial values
    height = int(len(protein_string_converted) * 2)
    width = int(len(protein_string_converted) * 2)
    
    # create matrix object
    initial_matrix = Matrix(width, height)
    
    # create the first amino acid object with coordinates in the middle of the matrix    
    amino_acid = AminoAcid(height/2, width/2, protein_string_converted[0])
    
    # add coordinates and value to protein
    protein = Protein()
    
    # initilize connection
    connections = Connection()
    
    # ---------------- Initilize grid with first amino acid --------------------
    initial_matrix = matrix_initializer(initial_matrix, amino_acid, protein)
    
    # -------------------- Random protein construction -------------------------
    # run the entire algorithm 1000 times and store all the scores, plot a histogram
    if algorithm_input == "random":
        scores = []
        
        best_score = 0
        for i in range(5000):
            solution = random_algorithm(initial_matrix[0], protein_string_converted[1:], initial_matrix[1], initial_matrix[2], connections)
            print("solution:",i,"out of 10.000")
            if solution == "Terminate":
                pass
            else: 
                matrix, protein, score = solution
                scores.append(score)
                if score < best_score:
                    best_score = copy.deepcopy(score)
                    best_protein = copy.deepcopy(protein)

        plt.hist(scores, 20)
        plt.title("Counts for random scores of 10.000 iterations")
Exemple #5
0
    if protein_string:
        print(f"Your string is: {protein_string}.")
        print()
        break

# promt for 3D
print("Do you want to use 3D? (y for yes) ")
while True:
    dimension3 = input("")
    if dimension3:
        print()
        break

# create protein class
if dimension3 == "y":
    protein = Protein(protein_string, dim3=True)
else:
    protein = Protein(protein_string)

print("What algorithm do you want to perform on this protein?")
print("Insert r for random, g for greedy, c for chunky path and f for \
forward search.")

while True:
    algorithm = input("")
    if (algorithm == "r" or algorithm == "g" or algorithm == "c"
            or algorithm == "f"):
        print("You have chosen.")
        print()
        break