예제 #1
0
    def test_protein_folding_problem_2_second_bead_side_chain(self):
        """Tests if a protein folding problem is created and returns a correct qubit operator if
        a second main bead has a side chain."""
        lambda_back = 10
        lambda_chiral = 10
        lambda_1 = 10
        penalty_terms = PenaltyParameters(lambda_chiral, lambda_back, lambda_1)

        main_chain_residue_seq = "SAAS"
        side_chain_residue_sequences = ["", "A", "A", ""]

        peptide = Peptide(main_chain_residue_seq, side_chain_residue_sequences)

        mj_interaction = MiyazawaJerniganInteraction()

        protein_folding_problem = ProteinFoldingProblem(
            peptide, mj_interaction, penalty_terms)
        qubit_op = protein_folding_problem._qubit_op_full()

        expected_path = self.get_resource_path(
            "test_protein_folding_problem_2_second_bead_side_chain",
            PATH,
        )
        expected = read_expected_file(expected_path)
        self.assertEqual(qubit_op, expected)
예제 #2
0
def create_protein_folding_result(main_chain: str, side_chains: List[str],
                                  turn_sequence: str) -> ProteinFoldingResult:
    """
    Creates a protein_folding_problem, solves it and uses the result
    to create a protein_folding_result instance.
    Args:
        main_chain: The desired main_chain for the molecules to be optimized
        side_chains: The desired side_chains for the molecules to be optimized
        turn_sequence: The best sequence found by ProteinFoldingResult pre-computed
    Returns:
        Protein Folding Result
    """
    algorithm_globals.random_seed = 23
    peptide = Peptide(main_chain, side_chains)
    mj_interaction = MiyazawaJerniganInteraction()

    penalty_back = 10
    penalty_chiral = 10
    penalty_1 = 10

    penalty_terms = PenaltyParameters(penalty_chiral, penalty_back, penalty_1)

    protein_folding_problem = ProteinFoldingProblem(peptide, mj_interaction,
                                                    penalty_terms)
    protein_folding_problem.qubit_op()

    return ProteinFoldingResult(
        unused_qubits=protein_folding_problem.unused_qubits,
        peptide=protein_folding_problem.peptide,
        turn_sequence=turn_sequence,
    )
    def test_get_result_binary_vector_compressed(self):
        """Tests if a protein folding result returns a correct expanded best sequence."""
        lambda_back = 10
        lambda_chiral = 10
        lambda_1 = 10
        penalty_terms = PenaltyParameters(lambda_chiral, lambda_back, lambda_1)

        main_chain_residue_seq = "SAASSASAA"
        side_chain_residue_sequences = [
            "", "", "A", "A", "A", "A", "A", "A", ""
        ]

        peptide = Peptide(main_chain_residue_seq, side_chain_residue_sequences)

        mj_interaction = MiyazawaJerniganInteraction()

        protein_folding_problem = ProteinFoldingProblem(
            peptide, mj_interaction, penalty_terms)
        best_sequence = "101110010"
        protein_folding_problem._unused_qubits = [0, 1, 2, 5, 7]

        protein_folding_result = ProteinFoldingResult(protein_folding_problem,
                                                      best_sequence)

        result = protein_folding_result.get_result_binary_vector()
        expected_sequence = "101110*0*10***"

        self.assertEqual(result, expected_sequence)
    def test_check_turns(self):
        """
        Tests that check turns operators are generate correctly.
        """
        main_chain_residue_seq = "SAASSA"
        side_chain_residue_sequences = ["", "", "A", "A", "A", ""]

        peptide = Peptide(main_chain_residue_seq, side_chain_residue_sequences)
        bead_2 = peptide.get_main_chain[2]
        bead_3 = peptide.get_main_chain[3]
        bead_4 = peptide.get_main_chain[4]
        side_bead_2 = bead_2.side_chain[0]
        side_bead_3 = bead_3.side_chain[0]
        side_bead_4 = bead_4.side_chain[0]

        lambda_back = 10
        lambda_chiral = 10
        lambda_1 = 10
        penalty_params = PenaltyParameters(lambda_chiral, lambda_back, lambda_1)
        mj_interaction = MiyazawaJerniganInteraction()
        pair_energies = mj_interaction.calculate_energy_matrix(main_chain_residue_seq)

        qubit_op_builder = QubitOpBuilder(peptide, pair_energies, penalty_params)

        t_23 = qubit_op_builder._create_turn_operators(bead_2, bead_3)
        t_34 = qubit_op_builder._create_turn_operators(bead_3, bead_4)
        t_2s3 = qubit_op_builder._create_turn_operators(side_bead_2, bead_3)
        t_3s4s = qubit_op_builder._create_turn_operators(side_bead_3, side_bead_4)

        expected_path_t23 = self.get_resource_path(
            "test_check_turns_expected_t23",
            PATH,
        )
        expected_t23 = read_expected_file(expected_path_t23)
        expected_path_t34 = self.get_resource_path(
            "test_check_turns_expected_t34",
            PATH,
        )
        expected_t34 = read_expected_file(expected_path_t34)
        expected_path_t2s3 = self.get_resource_path(
            "test_check_turns_expected_t2s3",
            PATH,
        )
        expected_t_2s3 = read_expected_file(expected_path_t2s3)
        expected_path_t3s4s = self.get_resource_path(
            "test_check_turns_expected_t3s4s",
            PATH,
        )
        expected_t_3s4s = read_expected_file(expected_path_t3s4s)
        self.assertEqual(t_23, expected_t23)
        self.assertEqual(t_34, expected_t34)
        self.assertEqual(t_2s3, expected_t_2s3)
        self.assertEqual(t_3s4s, expected_t_3s4s)
 def test_create_h_short(self):
     """
     Tests that the Hamiltonian to back-overlaps is created correctly.
     """
     main_chain_residue_seq = "APRLAAAA"
     side_chain_residue_sequences = ["", "", "A", "A", "A", "A", "A", ""]
     mj_interaction = MiyazawaJerniganInteraction()
     pair_energies = mj_interaction.calculate_energy_matrix(main_chain_residue_seq)
     peptide = Peptide(main_chain_residue_seq, side_chain_residue_sequences)
     penalty_params = PenaltyParameters()
     qubit_op_builder = QubitOpBuilder(peptide, pair_energies, penalty_params)
     h_short = qubit_op_builder._create_h_short()
     expected = PauliSumOp.from_list([("IIIIIIIIIIIIIIIIIIIIIIIIIIII", 0)])
     self.assertEqual(h_short, expected)
 def test_create_h_bbsc_and_h_scbb_3(self):
     """
     Tests if H_BBBB Hamiltonian qubit operator is built correctly.
     """
     main_chain_residue_seq = "SAACS"
     side_chain_residue_sequences = ["", "", "A", "A", ""]
     mj_interaction = MiyazawaJerniganInteraction()
     pair_energies = mj_interaction.calculate_energy_matrix(main_chain_residue_seq)
     peptide = Peptide(main_chain_residue_seq, side_chain_residue_sequences)
     penalty_params = PenaltyParameters()
     qubit_op_builder = QubitOpBuilder(peptide, pair_energies, penalty_params)
     h_bbsc, h_scbb = qubit_op_builder._create_h_bbsc_and_h_scbb()
     self.assertEqual(h_bbsc, 0)
     self.assertEqual(h_scbb, 0)
 def test_create_h_bbbb(self):
     """Tests if H_BBBB Hamiltonian qubit operator is built correctly."""
     main_chain_residue_seq = "SAASSASA"
     side_chain_residue_sequences = ["", "", "A", "", "", "A", "A", ""]
     mj_interaction = MiyazawaJerniganInteraction()
     pair_energies = mj_interaction.calculate_energy_matrix(main_chain_residue_seq)
     peptide = Peptide(main_chain_residue_seq, side_chain_residue_sequences)
     penalty_params = PenaltyParameters()
     qubit_op_builder = QubitOpBuilder(peptide, pair_energies, penalty_params)
     h_bbbb = qubit_op_builder._create_h_bbbb()
     expected_path = self.get_resource_path(
         "test_create_h_bbbb_expected",
         PATH,
     )
     expected = read_expected_file(expected_path)
     self.assertEqual(h_bbbb, expected)
 def test_create_h_chiral_2(self):
     """
     Tests that the Hamiltonian chirality constraints is created correctly.
     """
     main_chain_residue_seq = "SAACS"
     side_chain_residue_sequences = ["", "", "A", "A", ""]
     peptide = Peptide(main_chain_residue_seq, side_chain_residue_sequences)
     mj_interaction = MiyazawaJerniganInteraction()
     pair_energies = mj_interaction.calculate_energy_matrix(main_chain_residue_seq)
     penalty_params = PenaltyParameters()
     qubit_op_builder = QubitOpBuilder(peptide, pair_energies, penalty_params)
     h_chiral = qubit_op_builder._create_h_chiral()
     expected_path = self.get_resource_path(
         "test_create_h_chiral_2_expected",
         PATH,
     )
     expected = read_expected_file(expected_path)
     self.assertEqual(h_chiral, expected)
    def test_build_qubit_op(self):
        """Tests if a total Hamiltonian qubit operator is built correctly."""
        lambda_back = 10
        lambda_chiral = 10
        lambda_1 = 10
        main_chain_residue_seq = "SAASSASAA"
        side_chain_residue_sequences = ["", "", "A", "A", "A", "A", "A", "A", ""]

        peptide = Peptide(main_chain_residue_seq, side_chain_residue_sequences)
        mj_interaction = MiyazawaJerniganInteraction()
        penalty_params = PenaltyParameters(lambda_chiral, lambda_back, lambda_1)
        pair_energies = mj_interaction.calculate_energy_matrix(main_chain_residue_seq)
        qubit_op_builder = QubitOpBuilder(peptide, pair_energies, penalty_params)
        qubit_op = qubit_op_builder._build_qubit_op()
        expected_path = self.get_resource_path(
            "test_build_qubit_op_expected",
            PATH,
        )
        expected = read_expected_file(expected_path)
        self.assertEqual(qubit_op, expected)
예제 #10
0
    def test_create_h_back_side_chains(self):
        """
        Tests that the Hamiltonian to back-overlaps is created correctly in the presence of side
        chains which should not have any influence in this case.
        """
        main_chain_residue_seq = "SAASS"
        side_chain_residue_sequences = ["", "", "A", "A", ""]

        peptide = Peptide(main_chain_residue_seq, side_chain_residue_sequences)
        mj_interaction = MiyazawaJerniganInteraction()
        pair_energies = mj_interaction.calculate_energy_matrix(main_chain_residue_seq)
        penalty_params = PenaltyParameters()
        qubit_op_builder = QubitOpBuilder(peptide, pair_energies, penalty_params)
        h_back = qubit_op_builder._create_h_back()
        expected_path = self.get_resource_path(
            "test_create_h_back_side_chains_expected",
            PATH,
        )
        expected = read_expected_file(expected_path)
        self.assertEqual(h_back, expected)
예제 #11
0
    def test_create_h_bbsc_and_h_scbb(self):
        """Tests if H_BBSC and H_SCBB Hamiltonians qubit operators are built correctly."""
        main_chain_residue_seq = "APRLAAA"
        side_chain_residue_sequences = ["", "", "A", "", "", "A", ""]
        mj_interaction = MiyazawaJerniganInteraction()
        pair_energies = mj_interaction.calculate_energy_matrix(main_chain_residue_seq)
        peptide = Peptide(main_chain_residue_seq, side_chain_residue_sequences)
        penalty_params = PenaltyParameters()
        qubit_op_builder = QubitOpBuilder(peptide, pair_energies, penalty_params)

        h_bbsc, h_scbb = qubit_op_builder._create_h_bbsc_and_h_scbb()

        expected_path_h_bbsc = self.get_resource_path(
            "test_create_h_bbsc_and_h_scbb_expected_h_bbsc",
            PATH,
        )
        expected_path_h_scbb = self.get_resource_path(
            "test_create_h_bbsc_and_h_scbb_expected_h_scbb",
            PATH,
        )
        expected_h_bbsc = read_expected_file(expected_path_h_bbsc)
        expected_h_scbb = read_expected_file(expected_path_h_scbb)
        self.assertEqual(h_bbsc, expected_h_bbsc)
        self.assertEqual(h_scbb, expected_h_scbb)