示例#1
0
def test_align_vectors(input_atoms, as_list, use_support, random_seed):
    """
    Align, swap alignment vectors and align again.
    Expect that the original coordinates have been restored.
    """
    np.random.seed(random_seed)
    source_direction = np.random.rand(3)
    target_direction = np.random.rand(3)
    if use_support:
        source_position = np.random.rand(3)
        target_position = np.random.rand(3)
    else:
        source_position = None
        target_position = None

    if as_list:
        source_direction = source_direction.tolist()
        target_direction = target_direction.tolist()
        if use_support:
            source_position = source_position.tolist()
            target_position = target_position.tolist()

    transformed = struc.align_vectors(input_atoms, source_direction,
                                      target_direction, source_position,
                                      target_position)
    restored = struc.align_vectors(transformed, target_direction,
                                   source_direction, target_position,
                                   source_position)

    assert type(restored) == type(input_atoms)
    assert struc.coord(restored).shape == struc.coord(input_atoms).shape
    assert np.allclose(struc.coord(restored),
                       struc.coord(input_atoms),
                       atol=1e-5)
示例#2
0
def test_align_vectors_non_vector_inputs(input_atoms):
    """
    Ensure input vectors to ``struct.align_vectors`` have the correct shape.
    """
    source_direction = np.random.rand(2, 3)
    target_direction = np.random.rand(2, 3)
    with pytest.raises(ValueError):
        struc.align_vectors(
            input_atoms,
            source_direction,
            target_direction,
        )
    source_direction = np.random.rand(4)
    target_direction = np.random.rand(4)
    with pytest.raises(ValueError):
        struc.align_vectors(
            input_atoms,
            source_direction,
            target_direction,
        )
示例#3
0
RAY_ALPHA = 0.03
# The color map to use to depict the charge
CMAP_NAME = "bwr_r"



# Get an atom array for the selected molecule
molecule = info.residue(MOLECULE_NAME)

# Align molecule with principal component analysis:
# The component with the least variance, i.e. the axis with the lowest
# number of atoms lying over each other, is aligned to the z-axis,
# which points into the plane of the figure
pca = PCA(n_components=3)
pca.fit(molecule.coord)
molecule = struc.align_vectors(molecule, pca.components_[-1], [0, 0, 1])

# Balls should be colored by partial charge
charges = struc.partial_charges(molecule, ITERATION_NUMBER)
# Later this variable stores values between 0 and 1 for use in color map
normalized_charges = charges.copy()
# Show no partial charge for atoms
# that are not parametrized for the PEOE algorithm
normalized_charges[np.isnan(normalized_charges)] = 0
# Norm charge values to highest absolute value
max_charge = np.max(np.abs(normalized_charges))
normalized_charges /= max_charge
# Transform range (-1, 1) to range (0, 1)
normalized_charges = (normalized_charges + 1) / 2
# Calculate colors
color_map = plt.get_cmap(CMAP_NAME)
示例#4
0
                            in struc.get_residue_masks(nucleotides, [i, j])]
        break
pairs = [(guanine, cytosine), (adenine, thymine)]

fig = plt.figure(figsize=(8.0, 8.0))
ax = fig.add_subplot(111, projection="3d")

# Arrange bases
for i, (purine, pyrimidine) in enumerate(pairs):
    n1, n3, c5, c6 = [pyrimidine[pyrimidine.atom_name == name][0]
                      for name in ("N1", "N3", "C5", "C6")]
    # Pyrimidine N3-C6 axis is aligned to x-axis
    purine, pyrimidine = [
        struc.align_vectors(
            base,
            n3.coord - c6.coord,
            np.array([1, 0, 0])
        ) for base in (purine, pyrimidine)
    ]
    # Coords are changed -> update 'Atom' objects
    n1, n3, c4, c5 = [pyrimidine[pyrimidine.atom_name == name][0]
                      for name in ("N1", "N3", "C4", "C5")]
    # Pyrimidine base plane normal vector is aligned to z-axis
    # Furthermore, distance between bases is set
    purine, pyrimidine = [
        struc.align_vectors(
            base,
            np.cross(n3.coord - n1.coord, c5.coord - n1.coord),
            np.array([0, 0, 1]),
            origin_position = struc.centroid(purine + pyrimidine),
            # 10 Å separation between pairs
示例#5
0
import biotite.structure as struc
import biotite.structure.info as info
import biotite.structure.graphics as graphics

# Get an atom array for caffeine
# Caffeine has the PDB reside name 'CFF'
caffeine = info.residue("CFF")

# For cosmetic purposes align central rings to x-y plane
n1 = caffeine[caffeine.atom_name == "N1"][0]
n3 = caffeine[caffeine.atom_name == "N3"][0]
n7 = caffeine[caffeine.atom_name == "N7"][0]
# Normal vector of ring plane
normal = np.cross(n1.coord - n3.coord, n1.coord - n7.coord)
# Align ring plane normal to z-axis
caffeine = struc.align_vectors(caffeine, normal, np.array([0, 0, 1]))

# Caffeine should be colored by element
colors = np.zeros((caffeine.array_length(), 3))
colors[caffeine.element == "H"] = (0.8, 0.8, 0.8)  # gray
colors[caffeine.element == "C"] = (0.0, 0.8, 0.0)  # green
colors[caffeine.element == "N"] = (0.0, 0.0, 0.8)  # blue
colors[caffeine.element == "O"] = (0.8, 0.0, 0.0)  # red

fig = plt.figure(figsize=(8.0, 8.0))
ax = fig.add_subplot(111, projection="3d")
graphics.plot_atoms(ax,
                    caffeine,
                    colors,
                    line_width=5,
                    background_color="white",