Пример #1
0
def test_rotate_about_axis_consistency(input_atoms, axis, random_seed):
    """
    Compare the outcome of :func:`rotate_about_axis()` with
    :func:`rotate()`.
    """
    np.random.seed(random_seed)
    angle = np.random.rand() * 2 * np.pi

    angles = np.zeros(3)
    angles[axis] = angle
    ref_rotated = struc.rotate(input_atoms, angles)

    rot_axis = np.zeros(3)
    # Length of axis should be irrelevant
    rot_axis[axis] = np.random.rand()
    test_rotated = struc.rotate_about_axis(
        input_atoms,
        rot_axis,
        angle,
    )

    assert type(test_rotated) == type(ref_rotated)
    assert struc.coord(test_rotated).shape == struc.coord(ref_rotated).shape
    assert np.allclose(struc.coord(test_rotated),
                       struc.coord(ref_rotated),
                       atol=1e-5)
Пример #2
0
def test_superimposition_array(path):
    pdbx_file = pdbx.PDBxFile()
    pdbx_file.read(path)
    fixed = pdbx.get_structure(pdbx_file, model=1)
    mobile = fixed.copy()
    mobile = struc.rotate(mobile, (1, 2, 3))
    mobile = struc.translate(mobile, (1, 2, 3))
    fitted, transformation = struc.superimpose(fixed, mobile,
                                               (mobile.atom_name == "CA"))
    assert struc.rmsd(fixed, fitted) == pytest.approx(0)
    fitted = struc.superimpose_apply(mobile, transformation)
    assert struc.rmsd(fixed, fitted) == pytest.approx(0)
Пример #3
0
def test_rotate_known(ndim):
    """
    Rotate a vector at the Y-axis about the X-axis by 90 degrees and
    expect a rotated vector at the Z-axis.
    """
    shape = (1,) * (ndim-1) + (3,)
    vector = np.zeros(shape)
    vector[...] = [0, 1, 0]

    exp_rotated = np.zeros(shape)
    exp_rotated[...] = [0, 0, 1]

    # Rotation by 90 degrees
    test_rotated = struc.rotate(vector, [0.5 * np.pi, 0, 0])
    
    assert test_rotated.shape == exp_rotated.shape
    assert np.allclose(test_rotated, exp_rotated, atol=1e-5)
Пример #4
0
def test_superimposition_array(path):
    """
    Take a structure and rotate and translate a copy of it, so that they
    are not superimposed anymore.
    Then superimpose these structure onto each other and expect an
    almost perfect match.
    """
    fixed = strucio.load_structure(path, model=1)

    mobile = fixed.copy()
    mobile = struc.rotate(mobile, (1, 2, 3))
    mobile = struc.translate(mobile, (1, 2, 3))

    fitted, transformation = struc.superimpose(fixed, mobile)

    assert struc.rmsd(fixed, fitted) == pytest.approx(0, abs=6e-4)

    fitted = struc.superimpose_apply(mobile, transformation)

    assert struc.rmsd(fixed, fitted) == pytest.approx(0, abs=6e-4)
Пример #5
0
def test_rotate_measure(axis, random_seed):
    """
    Rotate and measure resulting angle that should be equal to the input
    angle.
    """
    np.random.seed(random_seed)
    # Maximum rotation is only 180 degrees,
    # as with higher angles the measured angle would decrease again
    ref_angle = np.random.rand() * np.pi
    angles = np.zeros(3)
    angles[axis] = ref_angle

    # The measured angle is only equal to the input angle,
    # if the input coordinates have no component on the rotation axis 
    input_coord = np.ones(3)
    input_coord[axis] = 0

    rotated = struc.rotate(input_coord, angles)
    test_angle = struc.angle(rotated, 0, input_coord)
    
    # Vector length should be unchanged
    assert np.linalg.norm(rotated) \
        == pytest.approx(np.linalg.norm(input_coord))
    assert test_angle == pytest.approx(ref_angle)
Пример #6
0
print(structure[structure.res_id == 1])
print()
structure.coord += 100
print("After:")
print(structure[structure.res_id == 1])

########################################################################
# *Biotite* provides also some transformation functions, for example
# :func:`rotate()` for rotations about the *x*-, *y*- or *z*-axis.

structure = mmtf.get_structure(mmtf_file, model=1)
print("Before:")
print(structure[structure.res_id == 1])
print()
# Rotation about z-axis by 90 degrees
structure = struc.rotate(structure, [0, 0, np.deg2rad(90)])
print("After:")
print(structure[structure.res_id == 1])

########################################################################
# For a complete list of transformation functions have a look in the
# :doc:`API reference </apidoc/biotite.structure>`.
#
# Structure analysis
# ------------------
#
# This package would be almost useless, if there wasn't some means to
# analyze your structures.
# Therefore, *Biotite* offers a bunch of functions for this purpose,
# reaching from simple bond angle and length measurements to more
# complex characteristics, like accessible surface area and