Esempio n. 1
0
    def test_plot_PMF(self, density):

        density.plot_density()

        reference = {
            'contour-vertices':
            np.array([[153.5, -7.0], [154.0, -6.5], [153.5, -6.0],
                      [153.0, -6.5], [153.5, -7.0]]),
            'cbar-orientation':
            'vertical',
            'cbar-ylabel':
            'PMF',
            'cbar-aspect':
            30,
            'cbar-x-extent': (0.78375, 0.809417),
            'cbar-ticks':
            np.linspace(0, 3, 7)
        }

        # assert_array_almost_equal(density.ax.collections[1].get_paths()[0].vertices.round(1), reference['contour-vertices'])
        assert density.cbar.orientation == reference['cbar-orientation']
        assert_array_almost_equal((density.cbar.ax.get_position().x0,
                                   density.cbar.ax.get_position().x1),
                                  reference['cbar-x-extent'],
                                  decimal=1)
        assert_array_almost_equal(density.cbar.get_ticks(),
                                  reference['cbar-ticks'])
Esempio n. 2
0
    def test_PMF_difference(self, density, density_310K):

        density.plot_density(difference=density_310K)

        reference = {'cbar-ticks': np.linspace(-1, 1, 9)}

        assert_array_almost_equal(density.cbar.get_ticks(),
                                  reference['cbar-ticks'])
Esempio n. 3
0
    def test_plot_projection_vmin_vmax(self, projection_data):

        projection_data.plot_projection(vmin=0.0, vmax=1.0)

        reference = {'cbar-ticks': np.linspace(0, 1, 6)}

        assert_array_almost_equal(projection_data.cbar.get_ticks(),
                                  reference['cbar-ticks'])
Esempio n. 4
0
    def test_vmin_vmax(self, density):

        density.plot_density(vmin=0.0, vmax=1.0)

        reference = {'cbar-ticks': np.linspace(0, 1, 6)}

        assert_array_almost_equal(density.cbar.get_ticks(),
                                  reference['cbar-ticks'])
Esempio n. 5
0
    def test_interpolate(self, density):

        density.interpolate(method="linear")

        reference = {'density': np.array([[0, 0, 0], [1, 1, 1], [0, 0, 0]])}

        assert np.sum(np.isnan(density.joint_mesh_values)) == 0
        assert_array_almost_equal(density.joint_mesh_values,
                                  reference['density'])
    def test_SCC_weighted_average(self, sn1_scc):
        
        scc = SCC.weighted_average(sn1_scc, sn1_scc)
        
        reference = {
            'n_residues': 50,
            'n_frames': 1,
            'scc': np.full((50, 1), fill_value=-0.5)  # all bonds are perpendicular to the z-axis
        }

        assert scc.SCC.shape == (reference['n_residues'], reference['n_frames'])
        assert_array_almost_equal(scc.SCC, reference['scc'])
Esempio n. 7
0
    def test_interpolate(self, projection):

        projection.statistic = np.array([[np.NaN, 0, np.NaN], [1, np.NaN, 1],
                                         [np.NaN, 0, np.NaN]])

        projection.interpolate(method="linear")

        reference = {
            'statistic': np.array([[1, 0.0, 0.5], [1, 1, 1], [1, 0.0, 0.5]])
        }

        assert_array_almost_equal(projection.statistic, reference['statistic'])
 def test_SCC(self, universe):
     
     scc = SCC(universe, **self.kwargs)
     scc.run()
 
     reference = {
         'n_residues': 100,
         'n_frames': 1,
         'scc': np.full((100, 1), fill_value=-0.5)  # all bonds are perpendicular to the z-axis
     }
     
     assert scc.SCC.shape == (reference['n_residues'], reference['n_frames'])
     assert_array_almost_equal(scc.SCC, reference['scc'])
Esempio n. 9
0
def test_get_zarr_labels_successful(tmp_path):
    out_pth = os.path.join(tmp_path, 'out_labels.zarr')
    data = np.random.randint(4, size=(3, 100, 100))
    meta = {'name': 'test_labels'}
    labels_to_zarr(out_pth, data, meta)

    reader = get_zarr_labels(out_pth)
    assert callable(
        reader), "Get reader does not return reader given valid path"

    layer_data = reader(out_pth)
    assert_array_almost_equal(
        data, layer_data[0][0]), "Reader did not return same data"
    assert layer_data[0][2] == 'labels', "Reader did not return labels layer"
 def test_msd_com_removal(self, universe):
     
     msd = MSD(universe, **self.kwargs, com_removal_sel="all")
     msd.run(stop=2)
     
     reference = {
         'n_residues': 1,
         'n_frames': 2,
         'msd': [[0.0, 0.0]],
         'lagtimes': [0.0, 5.0]
     }
     
     assert msd.msd.shape == (reference['n_residues'], reference['n_frames'])
     assert_array_almost_equal(msd.msd, reference['msd'])
     assert_array_almost_equal(msd.lagtimes, reference['lagtimes'])
Esempio n. 11
0
    def test_ZThickness_average_different_tails(self, sn1_thickness,
                                                sn2_thickness):

        thickness = ZThickness.average(sn1_thickness, sn2_thickness)

        reference = {
            'n_residues': 50,
            'n_frames': 1,
            'z_thickness': np.full((50, 1), fill_value=20)
        }

        assert thickness.z_thickness.shape == (reference['n_residues'],
                                               reference['n_frames'])
        assert_array_almost_equal(thickness.z_thickness,
                                  reference['z_thickness'])
Esempio n. 12
0
    def test_ZThickness_average(self, sn1_thickness):

        thickness = ZThickness.average(sn1_thickness, sn1_thickness)

        reference = {
            'n_residues': 25,
            'n_frames': 1,
            'z_thickness': np.full((25, 1), fill_value=20)
        }

        assert isinstance(thickness, ZThickness)
        assert thickness.z_thickness.shape == (reference['n_residues'],
                                               reference['n_frames'])
        assert_array_almost_equal(thickness.z_thickness,
                                  reference['z_thickness'])
 def test_msd(self, universe):
     
     msd = MSD(universe, **self.kwargs)
     msd.run(stop=2)
 
     reference = {
         'n_residues': 1,
         'n_frames': 2,
         'msd': [[0.0, 0.04394855]],
         'lagtimes': [0.0, 5000.0]
     }
     
     assert msd.msd.shape == (reference['n_residues'], reference['n_frames'])
     assert_array_almost_equal(msd.msd, reference['msd'])
     assert_array_almost_equal(msd.lagtimes, reference['lagtimes'])
Esempio n. 14
0
    def test_interpolate_PMF(self, density):

        # Becayse density is a fixture with scope=class,
        # we need to reset the NaN values before interpolating
        density.joint_mesh_values = np.array([[np.NaN, 0, np.NaN],
                                              [1, np.NaN, 1],
                                              [np.NaN, 0, np.NaN]])

        density.temperature = 300  # The fill values should now be set to np.nanmax(density.joint_mesh_values), i.e 1.0
        density.interpolate(method="linear")

        reference = {'density': np.array([[1, 0, 1], [1, 1, 1], [1, 0, 1]])}

        assert np.sum(np.isnan(density.joint_mesh_values)) == 0
        assert_array_almost_equal(density.joint_mesh_values,
                                  reference['density'])
Esempio n. 15
0
    def test_interpolate_fill_value(self, density):

        # Becayse density is a fixture with scope=class,
        # we need to reset the NaN values before interpolating
        density.joint_mesh_values = np.array([[np.NaN, 0, np.NaN],
                                              [1, np.NaN, 1],
                                              [np.NaN, 0, np.NaN]])

        density.interpolate(method="linear", fill_value=100)

        reference = {
            'density': np.array([[100, 0, 100], [1, 1, 1], [100, 0, 100]])
        }

        assert np.sum(np.isnan(density.joint_mesh_values)) == 0
        assert_array_almost_equal(density.joint_mesh_values,
                                  reference['density'])
Esempio n. 16
0
    def test_SCC_weighted_average_different_tails(self, universe, sn1_scc):

        sn2_scc = SCC(universe, "name L")
        sn2_scc.run()
        scc = SCC.weighted_average(sn1_scc, sn2_scc)

        reference = {
            'n_residues': 100,
            'n_frames': 1,
            'scc': np.full(
                (100, 1),
                fill_value=-0.5)  # all bonds are perpendicular to the z-axis
        }

        assert scc.SCC.shape == (reference['n_residues'],
                                 reference['n_frames'])
        assert_array_almost_equal(scc.SCC, reference['scc'])
Esempio n. 17
0
    def test_calc_density(self, density):

        density.calc_density_2D(bins=(self.kwargs['angle-bins'],
                                      self.kwargs['height-bins']))

        reference = {
            'range': [0.0, 0.04,
                      0.08]  # min density, min non-zero density, max density
        }

        actual = {
            'range': [
                np.nanmin(density.joint_mesh_values),
                np.min(density.joint_mesh_values[
                    density.joint_mesh_values > 0.0]),
                np.nanmax(density.joint_mesh_values)
            ]
        }

        assert_array_almost_equal(actual['range'], reference['range'])
Esempio n. 18
0
    def test_cbar_kws(self, density):

        density.plot_density(cbar_kws={
            'label': 'My label',
            'aspect': 10,
            'pad': 0.1
        })

        reference = {
            'label': 'My label',
            'aspect': 10,
            'x-extent': (0.78375, 0.86075),
        }

        assert density.cbar.ax.get_ylabel() == reference['label']
        assert density.cbar.ax.get_aspect() == reference['aspect']
        assert_array_almost_equal((density.cbar.ax.get_position().x0,
                                   density.cbar.ax.get_position().x1),
                                  reference['x-extent'],
                                  decimal=1)
Esempio n. 19
0
    def test_SCC_normals_3D(self, universe):

        # The Scc should be the same whether the normal is the positive or negative z-axis
        normals = np.zeros((100, 1, 3))
        normals[:, :50, 2] = 1.0
        normals[:, 50:, 2] = -1.0

        scc = SCC(universe, **self.kwargs, normals=normals)
        scc.run()

        reference = {
            'n_residues': 100,
            'n_frames': 1,
            'scc': np.full(
                (100, 1),
                fill_value=-0.5)  # all bonds are perpendicular to the z-axis
        }

        assert scc.SCC.shape == (reference['n_residues'],
                                 reference['n_frames'])
        assert_array_almost_equal(scc.SCC, reference['scc'])
Esempio n. 20
0
    def test_calc_PMF(self, density):

        density.calc_density_2D(bins=(self.kwargs['angle-bins'],
                                      self.kwargs['height-bins']),
                                temperature=self.kwargs['temperature'])

        density_range = [0.08, 0.04]  # max density, min non-zero density
        pmf_range = -(scipy.constants.Boltzmann * scipy.constants.Avogadro /
                      4184) * self.kwargs['temperature'] * np.log(
                          density_range)

        reference = {'range': pmf_range}

        actual = {
            'range': [
                np.min(density.joint_mesh_values[
                    density.joint_mesh_values > 0.0]),
                np.nanmax(density.joint_mesh_values)
            ]
        }

        assert_array_almost_equal(actual['range'], reference['range'])
Esempio n. 21
0
 def test_z_angles_radians(self, universe):
     
     z_angles = ZAngles(universe, **self.kwargs, rad=True)
     z_angles.run()
 
     reference = {
         'n_residues': 1,
         'n_frames': 25,
         'z_angles': np.array(
             [
                 [
                     15.92562181, 14.85231281, 24.60422584, 3.29616102, 20.58217289,
                     26.1954358, 64.03836333, 153.57140484, 132.91162273, 39.15426908,
                     91.70650991, 158.68468704, 152.26712722, 174.8327533, 152.10209894,
                     148.39876097, 172.02621202, 165.9057974, 92.91682782, 15.35392935,
                     8.44377703, 13.72016516, 17.09063882, 6.39997916, 22.79915101
                 ]
             ]
         )
     }
     
     assert z_angles.z_angles.shape == (reference['n_residues'], reference['n_frames'])
     assert_array_almost_equal(z_angles.z_angles, np.deg2rad(reference['z_angles']))
Esempio n. 22
0
class TestPoses(unittest.TestCase):
    """
    class to check if poses are correct
    """
    # World coordinate system: right handed. X forward, Y left, Z up
    # Create a reference object, facing along X-axis and elevation of 0 deg.
    az = 90
    ele = 0
    tilt = 0
    dist = 3
    # get location and rotation vector from az,ele and dist values
    loc, rot = config_cam(az, ele, dist)
    # compute transformation matrix using pose_spherical function
    computed_T = pose_spherical(az, ele, dist)
    pose_i = gtsam.Pose3(computed_T)
    # Construct pose using rotation and location vectors
    pose_j = gtsam.Pose3(gtsam.Rot3.RzRyRx(rot), loc)
    # Compares rotation vector from constructed pose with rotation vector initially computed
    rot_p = pose_j.rotation()
    rot_from_ele = rot_p.xyz()
    # Returns true
    assert_array_almost_equal(rot_from_ele, rot)

    figure_number = 0
    fig = plt.figure(figure_number)
    axes = fig.gca(projection='3d')
    plt.cla()

    upright = gtsam.Rot3.Ypr(-np.pi / 2, 0., -np.pi / 2)
    pose_j = gtsam.Pose3(upright, gtsam.Point3(0, 0, 0.2))
    axis_length = 1
    gtsam_plot.plot_pose3(figure_number, pose_i, axis_length)
    gtsam_plot.plot_pose3(figure_number, pose_j, axis_length)
    x_axe, y_axe, z_axe = 10, 10, 10
    # Draw
    axes.set_xlim3d(-x_axe, x_axe)
    axes.set_ylim3d(-y_axe, y_axe)
    axes.set_zlim3d(0, z_axe)
    plt.legend()
    #plt.show()
    filename = "/home/sushmitawarrier/results/test_pose_clevr3.png"
    plt.savefig(filename)
Esempio n. 23
0
    def test_filter_by_2D(self, scc):

        scc_projection = scc.project_SCC(
            filter_by=np.full((1, 25), fill_value=True))

        assert_array_almost_equal(scc_projection.values, scc.SCC.mean())
Esempio n. 24
0
    def test_filter_by(self, scc):

        scc_projection = scc.project_SCC(filter_by=[True])

        assert_array_almost_equal(scc_projection.values, scc.SCC.mean())
Esempio n. 25
0
    def test_project_SCC(self, scc):

        scc_projection = scc.project_SCC()

        assert isinstance(scc_projection, ProjectionPlot)
        assert_array_almost_equal(scc_projection.values, scc.SCC.mean())