Example #1
0
def test_crystal_with_scan_points(example_crystal):
    c1 = Crystal(**example_crystal)

    A = c1.get_A()
    c1.set_A_at_scan_points([A for i in range(5)])

    # Set the B covariance. The values are nonsense, just ensure they are
    # all different
    cov_B = flex.double(range(9 * 9)) * 1e-5
    c1.set_B_covariance(cov_B)
    cov_B.reshape(flex.grid(1, 9, 9))
    cov_B_array = flex.double(flex.grid(5, 9, 9))
    for i in range(5):
        cov_B_array[i:(i + 1), :, :] = cov_B
    c1.set_B_covariance_at_scan_points(cov_B_array)
    cov_B = c1.get_B_covariance()

    d = c1.to_dict()
    c2 = CrystalFactory.from_dict(d)
    eps = 1e-9
    for Acomp in d["A_at_scan_points"]:
        for e1, e2 in zip(A, Acomp):
            assert abs(e1 - e2) <= eps
    for covBcomp in d["B_covariance_at_scan_points"]:
        for e1, e2 in zip(cov_B, covBcomp):
            assert abs(e1 - e2) <= eps

    assert c1 == c2
Example #2
0
def test_crystal_with_scan_points():
    from dxtbx.model import Crystal, CrystalFactory
    from scitbx import matrix

    real_space_a = matrix.col((35.2402102454, -7.60002142787, 22.080026774))
    real_space_b = matrix.col((22.659572494, 1.47163505925, -35.6586361881))
    real_space_c = matrix.col((5.29417246554, 38.9981792999, 4.97368666613))

    c1 = Crystal(
        real_space_a=real_space_a,
        real_space_b=real_space_b,
        real_space_c=real_space_c,
        space_group_symbol="P 1 2/m 1",
    )

    A = c1.get_A()
    c1.set_A_at_scan_points([A for i in range(5)])

    # Set the B covariance. The values are nonsense, just ensure they are
    # all different
    from scitbx.array_family import flex

    cov_B = flex.double(range((9 * 9))) * 1e-5
    c1.set_B_covariance(cov_B)
    cov_B.reshape(flex.grid(1, 9, 9))
    cov_B_array = flex.double(flex.grid(5, 9, 9))
    for i in range(5):
        cov_B_array[i : (i + 1), :, :] = cov_B
    c1.set_B_covariance_at_scan_points(cov_B_array)
    cov_B = c1.get_B_covariance()

    d = c1.to_dict()
    c2 = CrystalFactory.from_dict(d)
    eps = 1e-9
    for Acomp in d["A_at_scan_points"]:
        for e1, e2 in zip(A, Acomp):
            assert abs(e1 - e2) <= eps
    for covBcomp in d["B_covariance_at_scan_points"]:
        for e1, e2 in zip(cov_B, covBcomp):
            assert abs(e1 - e2) <= eps

    assert c1 == c2
def test_check_old_vs_new():
    from dxtbx.tests.model.crystal_model_old import crystal_model_old

    model_1 = Crystal(
        real_space_a=(10, 0, 0),
        real_space_b=(0, 11, 0),
        real_space_c=(0, 0, 12),
        space_group_symbol="P 1",
    )

    model_2 = crystal_model_old(
        real_space_a=(10, 0, 0),
        real_space_b=(0, 11, 0),
        real_space_c=(0, 0, 12),
        space_group_symbol="P 1",
    )

    cov_B = matrix.sqr([1] * (9 * 9))

    model_1.set_B_covariance(cov_B)
    model_2.set_B_covariance(cov_B)

    A_list = [model_1.get_A() for i in range(20)]

    model_1.set_A_at_scan_points(A_list)
    model_2.set_A_at_scan_points(A_list)

    A1 = model_1.get_A()
    A2 = model_2.get_A()
    U1 = model_1.get_U()
    U2 = model_2.get_U()
    B1 = model_1.get_B()
    B2 = model_2.get_B()
    UC1 = model_1.get_unit_cell()
    UC2 = model_2.get_unit_cell()
    RSV1 = model_1.get_real_space_vectors()
    RSV2 = model_2.get_real_space_vectors()
    SG1 = model_1.get_space_group()
    SG2 = model_2.get_space_group()

    assert model_1.num_scan_points == model_2.num_scan_points

    A_list_1 = [
        model_1.get_A_at_scan_point(i)
        for i in range(model_1.get_num_scan_points())
    ]
    A_list_2 = [
        model_2.get_A_at_scan_point(i)
        for i in range(model_1.get_num_scan_points())
    ]
    B_list_1 = [
        model_1.get_B_at_scan_point(i)
        for i in range(model_1.get_num_scan_points())
    ]
    B_list_2 = [
        model_2.get_B_at_scan_point(i)
        for i in range(model_1.get_num_scan_points())
    ]
    U_list_1 = [
        model_1.get_U_at_scan_point(i)
        for i in range(model_1.get_num_scan_points())
    ]
    U_list_2 = [
        model_2.get_U_at_scan_point(i)
        for i in range(model_1.get_num_scan_points())
    ]

    assert approx_equal(A1, A2)
    assert approx_equal(B1, B2)
    assert approx_equal(U1, U2)
    assert approx_equal(UC1.parameters(), UC2.parameters())
    assert approx_equal(RSV1[0], RSV2[0])
    assert approx_equal(RSV1[1], RSV2[1])
    assert approx_equal(RSV1[2], RSV2[2])
    assert str(SG1.info()) == str(SG2.info())

    for i in range(model_1.get_num_scan_points()):
        assert approx_equal(A_list_1[i], A_list_2[i])
        assert approx_equal(B_list_1[i], B_list_2[i])
        assert approx_equal(U_list_1[i], U_list_2[i])

    cell_sd_1 = model_1.get_cell_parameter_sd()
    cell_sd_2 = model_2.get_cell_parameter_sd()
    cell_volume_sd_1 = model_1.get_cell_volume_sd()
    cell_volume_sd_2 = model_2.get_cell_volume_sd()
    covB1 = model_1.get_B_covariance()
    covB2 = model_1.get_B_covariance()

    assert approx_equal(covB1, covB2)
    assert approx_equal(cell_volume_sd_1, cell_volume_sd_2)
    assert approx_equal(cell_sd_1, cell_sd_2)