def test_create_pauli_for_contacts_2(self): """ Tests that Pauli operators for contact qubits are created correctly. """ main_chain_residue_seq = "SAASSS" side_chain_residue_sequences = ["", "", "A", "A", "S", ""] peptide = Peptide(main_chain_residue_seq, side_chain_residue_sequences) ( lower_main_upper_main, lower_side_upper_main, lower_main_upper_side, lower_side_upper_side, r_contact, ) = contact_map_builder._create_contact_qubits(peptide) expected_path = self.get_resource_path( "test_create_pauli_for_contacts_2_expected_1", PATH, ) expected_1 = read_expected_file(expected_path) expected_path = self.get_resource_path( "test_create_pauli_for_contacts_2_expected_2", PATH, ) expected_2 = read_expected_file(expected_path) self.assertEqual(lower_main_upper_main[1][6], expected_1) self.assertEqual(lower_main_upper_side[1][5], expected_2) self.assertEqual(lower_side_upper_main, {}) self.assertEqual(lower_side_upper_side, {}) self.assertEqual(r_contact, 2)
def test_calc_total_distances(self): """ Tests that total distances for all beads are calculated correctly. """ distance_map = DistanceMap(self.peptide) upper_bead_1 = self.peptide.get_main_chain[2].side_chain[0] lower_bead_1 = self.peptide.get_main_chain[1] upper_bead_2 = self.peptide.get_main_chain[2].side_chain[0] lower_bead_2 = self.peptide.get_main_chain[0] expected_path = self.get_resource_path( "test_calc_total_distances_1", PATH, ) expected_1 = read_expected_file(expected_path) expected_path = self.get_resource_path( "test_calc_total_distances_2", PATH, ) expected_2 = read_expected_file(expected_path) self.assertEqual(distance_map[lower_bead_1, upper_bead_1], expected_1) self.assertEqual(distance_map[lower_bead_2, upper_bead_2], expected_2)
def test_calc_distances_main_chain(self): """ Tests that distances for all beads on the main chain are calculated correctly. """ self.distance_map_builder._calc_distances_main_chain(self.peptide) expected_path = self.get_resource_path( "test_calc_distances_main_chain_1", PATH, ) expected_1 = read_expected_file(expected_path) expected_path = self.get_resource_path( "test_calc_distances_main_chain_2", PATH, ) expected_2 = read_expected_file(expected_path) expected_path = self.get_resource_path( "test_calc_distances_main_chain_3", PATH, ) expected_3 = read_expected_file(expected_path) expected_path = self.get_resource_path( "test_calc_distances_main_chain_4", PATH, ) expected_4 = read_expected_file(expected_path) lower_main_bead_0 = self.peptide.get_main_chain[0] upper_main_bead_4 = self.peptide.get_main_chain[4] lower_main_bead_1 = self.peptide.get_main_chain[1] upper_main_bead_3 = self.peptide.get_main_chain[3] # checking only some of the entries self.assertEqual( self.distance_map_builder._distance_map_axes[0][lower_main_bead_0] [upper_main_bead_4], expected_1, ) self.assertEqual( self.distance_map_builder._distance_map_axes[0][lower_main_bead_1] [upper_main_bead_4], expected_2, ) self.assertEqual( self.distance_map_builder._distance_map_axes[1][lower_main_bead_0] [upper_main_bead_3], expected_3, ) self.assertEqual( self.distance_map_builder._distance_map_axes[1][lower_main_bead_0] [upper_main_bead_4], expected_4, )
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_main_bead_constructor(self): """Tests that a MainBead is created.""" main_chain_len = 4 num_turn_qubits = 2 * (main_chain_len - 1) main_bead_id = 3 residue_type = "S" turn_qubits = ( 0.5 * _build_full_identity(num_turn_qubits) - 0.5 * (I ^ Z ^ I ^ I ^ I ^ I), 0.5 * _build_full_identity(num_turn_qubits) - 0.5 * (Z ^ I ^ I ^ I ^ I ^ I), ) side_chain_residue_sequences = ["S"] side_chain = SideChain(main_chain_len, main_bead_id, side_chain_residue_sequences) main_bead = MainBead(main_bead_id, residue_type, turn_qubits, side_chain) self.assertEqual(main_bead.side_chain, side_chain) indic_0, indic_1, indic_2, indic_3 = main_bead.indicator_functions expected_path_indic_0 = self.get_resource_path( "test_main_bead_constructor_expected_indic_0", PATH, ) expected_indic_0 = read_expected_file(expected_path_indic_0) expected_path_indic_1 = self.get_resource_path( "test_main_bead_constructor_expected_indic_1", PATH, ) expected_indic_1 = read_expected_file(expected_path_indic_1) expected_path_indic_2 = self.get_resource_path( "test_main_bead_constructor_expected_indic_2", PATH, ) expected_indic_2 = read_expected_file(expected_path_indic_2) expected_path_indic_3 = self.get_resource_path( "test_main_bead_constructor_expected_indic_3", PATH, ) expected_indic_3 = read_expected_file(expected_path_indic_3) self.assertEqual(indic_0, expected_indic_0) self.assertEqual(indic_1, expected_indic_1) self.assertEqual(indic_2, expected_indic_2) self.assertEqual(indic_3, expected_indic_3)
def test_second_neighbor(self): """ Tests that Pauli operators for 2nd neighbor interactions are created correctly. """ main_chain_residue_seq = "SAASS" side_chain_residue_sequences = ["", "", "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) lambda_1 = 2 lower_main_bead_index = 1 upper_main_bead_index = 4 side_chain_lower_main_bead = 0 side_chain_upper_main_bead = 0 distance_map = DistanceMap(peptide) second_neighbor = distance_map._second_neighbor( peptide, lower_main_bead_index, side_chain_upper_main_bead, upper_main_bead_index, side_chain_lower_main_bead, lambda_1, pair_energies, ) expected_path = self.get_resource_path( "test_second_neighbor", PATH, ) expected = read_expected_file(expected_path) self.assertEqual(second_neighbor, expected)
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)
def test_side_bead_constructor(self): """Tests that a SideBead is created.""" residue_type = "S" main_chain_len = 4 num_turn_qubits = 2 * (main_chain_len - 1) main_chain_id = 3 side_bead_id = 3 turn_qubits = ( 0.5 * _build_full_identity(num_turn_qubits) - 0.5 * (I ^ I ^ I ^ I ^ I ^ Z), 0.5 * _build_full_identity(num_turn_qubits) - 0.5 * (I ^ I ^ I ^ I ^ Z ^ I), ) side_bead = SideBead(main_chain_id, side_bead_id, residue_type, turn_qubits) indic_0, indic_1, indic_2, indic_3 = side_bead.indicator_functions expected_path_indic_0 = self.get_resource_path( "test_side_bead_constructor_expected_indic_0", PATH, ) expected_indic_0 = read_expected_file(expected_path_indic_0) expected_path_indic_1 = self.get_resource_path( "test_side_bead_constructor_expected_indic_1", PATH, ) expected_indic_1 = read_expected_file(expected_path_indic_1) expected_path_indic_2 = self.get_resource_path( "test_side_bead_constructor_expected_indic_2", PATH, ) expected_indic_2 = read_expected_file(expected_path_indic_2) expected_path_indic_3 = self.get_resource_path( "test_side_bead_constructor_expected_indic_3", PATH, ) expected_indic_3 = read_expected_file(expected_path_indic_3) self.assertEqual(indic_0, expected_indic_0) self.assertEqual(indic_1, expected_indic_1) self.assertEqual(indic_2, expected_indic_2) self.assertEqual(indic_3, expected_indic_3)
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)
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_add_distances_side_chain(self): """ Tests that distances for all beads on side chains are calculated correctly. """ self.distance_map_builder._calc_distances_main_chain(self.peptide) self.distance_map_builder._add_distances_side_chain(self.peptide) expected_path = self.get_resource_path( "test_add_distances_side_chain", PATH, ) expected = read_expected_file(expected_path) lower_main_bead = self.peptide.get_main_chain[0] upper_side_bead = self.peptide.get_main_chain[2].side_chain[0] # checking only some of the entries self.assertEqual( self.distance_map_builder._distance_map_axes[0][lower_main_bead][upper_side_bead], 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)
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)