Example #1
0
 def test_minimal_line_distance(self):
     for i in range(100):
         a, b, c, d = random.sample(self.vectors, 4)
         segments = random.choice([True, False])
         d1 = geometry.minimal_distance_between_lines(a,
                                                      b,
                                                      c,
                                                      d,
                                                      segments=segments)
         d2 = geometry.distance(a, c)
         d3 = geometry.distance(a, d)
         d4 = geometry.distance(b, c)
         d5 = geometry.distance(b, d)
         at = numpy.isclose(min([d1, d2, d3, d4, d5]),
                            d1) or (numpy.isclose(d1, 0, atol=1e-07))
         self.assertTrue(at)
def test_create_residue_frame_backbone_only(residue_number):
    assembly = ampal.load_pdb(str(TEST_DATA_DIR / "3qy1.pdb"))
    focus_residue = assembly[0][residue_number]

    # Make sure that residue correctly aligns peptide plane to XY
    cfds.align_to_residue_plane(focus_residue)
    assert np.array_equal(focus_residue["CA"].array, (
        0,
        0,
        0,
    )), "The CA atom should lie on the origin."
    assert np.isclose(focus_residue["N"].x,
                      0), "The nitrogen atom should lie on XY."
    assert np.isclose(focus_residue["N"].z,
                      0), "The nitrogen atom should lie on XY."
    assert np.isclose(focus_residue["C"].z,
                      0), "The carbon atom should lie on XY."
    # Make sure that all relevant atoms are pulled into the frame
    frame_edge_length = 12.0
    voxels_per_side = 21
    centre = voxels_per_side // 2
    max_dist = np.sqrt(((frame_edge_length / 2)**2) * 3)
    for atom in (a for a in assembly.get_atoms(ligands=False)
                 if cfds.within_frame(frame_edge_length, a)):
        assert g.distance(atom, (0, 0, 0)) <= max_dist, (
            "All atoms filtered by `within_frame` should be within "
            "`frame_edge_length/2` of the origin")

    # Make sure that aligned residue sits on XY after it is discretized
    single_res_assembly = ampal.Assembly(molecules=ampal.Polypeptide(
        monomers=copy.deepcopy(focus_residue).backbone))
    # Need to reassign the parent so that the residue is the only thing in the assembly
    single_res_assembly[0].parent = single_res_assembly
    single_res_assembly[0][0].parent = single_res_assembly[0]
    # Obtain atom encoder:
    codec = cfds.Codec.CNO()
    array = cfds.create_residue_frame(single_res_assembly[0][0],
                                      frame_edge_length,
                                      voxels_per_side,
                                      encode_cb=False,
                                      codec=codec)
    np.testing.assert_array_equal(array[centre, centre, centre],
                                  [True, False, False],
                                  err_msg="The central atom should be CA.")
    nonzero_indices = list(zip(*np.nonzero(array)))
    assert (len(nonzero_indices) == 4
            ), "There should be only 4 backbone atoms in this frame"
    nonzero_on_xy_indices = list(zip(*np.nonzero(array[:, :, centre])))
    assert (3 <= len(nonzero_on_xy_indices) <=
            4), "N, CA and C should lie on the xy plane."
Example #3
0
 def test_distance_in_unit_cube(self):
     """Generate pair of random points in unit cube, checks distances."""
     results = []
     # maximum distance between two points on unit cube is sqrt(3)
     # (e.g. [0, 0, 1] and [1, 1, 0]
     max_d = numpy.sqrt(3)
     for _ in range(1000):
         points = numpy.random.rand(2, 3)
         d = geometry.distance(*points)
         if (d >= 0.0) and (d <= max_d):
             results.append(1)
         else:
             results.append(0)
     at = numpy.all(results)
     self.assertTrue(at)
     return
Example #4
0
 def test_distance_reflexive(self, vectors):
     a, b = vectors
     d1 = geometry.distance(a, b)
     d2 = geometry.distance(b, a)
     self.assertEqual(d1, d2)
Example #5
0
 def test_distance_float(self):
     self.assertAlmostEqual(geometry.distance((11.43, -12.9, -23.11),
                                              (-32.43, 42.9, 33.11)),
                            90.54,
                            places=2)
Example #6
0
 def test_distance(self):
     for z in range(-100, 105, 5):
         self.assertEqual(geometry.distance((0, 0, 0), (0, 0, z)), abs(z))