コード例 #1
0
def test_dihedral_backbone_result(file_name):
    import mdtraj

    mmtf_file = mmtf.MMTFFile()
    mmtf_file.read(file_name)
    array = mmtf.get_structure(mmtf_file, model=1)
    array = array[struc.filter_amino_acids(array)]
    for chain in struc.chain_iter(array):
        print("Chain: ", chain.chain_id[0])
        if len(struc.check_id_continuity(chain)) != 0:
            # Do not test discontinuous chains
            return
        test_phi, test_psi, test_ome = struc.dihedral_backbone(chain)

        temp_file_name = biotite.temp_file("pdb")
        strucio.save_structure(temp_file_name, chain)
        traj = mdtraj.load(temp_file_name)
        _, ref_phi = mdtraj.compute_phi(traj)
        _, ref_psi = mdtraj.compute_psi(traj)
        _, ref_ome = mdtraj.compute_omega(traj)
        ref_phi, ref_psi, ref_ome = ref_phi[0], ref_psi[0], ref_ome[0]

        assert test_phi[1:] == pytest.approx(ref_phi, abs=1e-5, rel=5e-3)
        assert test_psi[:-1] == pytest.approx(ref_psi, abs=1e-5, rel=5e-3)
        assert test_ome[:-1] == pytest.approx(ref_ome, abs=1e-5, rel=5e-3)
コード例 #2
0
def test_dihedral_backbone_result(file_name):
    import mdtraj

    mmtf_file = mmtf.MMTFFile.read(file_name)
    array = mmtf.get_structure(mmtf_file, model=1)
    array = array[struc.filter_amino_acids(array)]
    if array.array_length() == 0:
        # Structure contains no protein
        # -> determination of backbone angles makes no sense
        return

    for chain in struc.chain_iter(array):
        print("Chain: ", chain.chain_id[0])
        if len(struc.check_res_id_continuity(chain)) != 0:
            # Do not test discontinuous chains
            return
        test_phi, test_psi, test_ome = struc.dihedral_backbone(chain)

        temp = NamedTemporaryFile("w+", suffix=".pdb")
        strucio.save_structure(temp.name, chain)
        traj = mdtraj.load(temp.name)
        temp.close()
        _, ref_phi = mdtraj.compute_phi(traj)
        _, ref_psi = mdtraj.compute_psi(traj)
        _, ref_ome = mdtraj.compute_omega(traj)
        ref_phi, ref_psi, ref_ome = ref_phi[0], ref_psi[0], ref_ome[0]

        assert test_phi[1:] == pytest.approx(ref_phi, abs=1e-5, rel=5e-3)
        assert test_psi[:-1] == pytest.approx(ref_psi, abs=1e-5, rel=5e-3)
        assert test_ome[:-1] == pytest.approx(ref_ome, abs=1e-5, rel=5e-3)
コード例 #3
0
def test_dihedral_backbone():
    file = npz.NpzFile()
    file.read(join(data_dir, "1l2y.npz"))
    # Test array
    array = file.get_structure()[0]
    phi, psi, omega = struc.dihedral_backbone(array, "A")
    assert omega.shape == (20, )
    # Remove nan values
    omega = np.abs(omega)[:-1]
    assert omega.tolist() == pytest.approx([np.pi] * len(omega), rel=0.05)
    # Test stack
    stack = file.get_structure()
    phi, psi, omega = struc.dihedral_backbone(stack, "A")
    assert omega.shape == (38, 20)
    # Remove nan values
    omega = np.abs(omega)[:, :-1]
    omega = np.average(omega, axis=0)
    assert omega.tolist() == pytest.approx([np.pi] * len(omega), rel=0.05)
コード例 #4
0
def calculate_dihedral(msaName):
    array = pdb2biotite(msaName)
    # plt.figure(0)
    # plt.plot(phi * 360/(2*np.pi), psi * 360/(2*np.pi),
    #          marker="o", linestyle="None")
    # plt.xlim(-180,180)
    # plt.ylim(-180,180)
    # plt.xlabel("$\phi$")
    # plt.ylabel("$\psi$")
    # plt.close()
    return struc.dihedral_backbone(array)
コード例 #5
0
def test_dihedral_backbone_general(multiple_chains):
    stack = strucio.load_structure(join(data_dir, "1l2y.mmtf"))
    n_models = stack.stack_depth()
    n_res = stack.res_id[-1]
    if multiple_chains:
        stack2 = stack.copy()
        stack2.chain_id[:] = "B"
        stack = stack + stack2
        n_res = n_res * 2
    array = stack[0]
    # Test array
    phi, psi, omega = struc.dihedral_backbone(array)
    assert phi.shape == (n_res, )
    assert psi.shape == (n_res, )
    assert omega.shape == (n_res, )
    _assert_plausible_omega(omega)
    # Test stack
    phi, psi, omega = struc.dihedral_backbone(stack)
    assert phi.shape == (n_models, n_res)
    assert psi.shape == (n_models, n_res)
    assert omega.shape == (n_models, n_res)
    _assert_plausible_omega(omega)
コード例 #6
0
organisms = ["H. sapiens", "G. gallus", "C. viginianus", "B. mori"]

# Create a PB sequence from each structure
pb_seqs = []
for file_name in lyso_files:
    file = mmtf.MMTFFile()
    file.read(file_name)
    # Take only the first model into account
    array = mmtf.get_structure(file, model=1)
    # Remove everything but the first protein chain
    array = array[struc.filter_amino_acids(array)]
    array = array[array.chain_id == array.chain_id[0]]

    # Calculate backbone dihedral angles,
    # as the PBs are determined from them
    phi, psi, omega = struc.dihedral_backbone(array)
    # A PB requires the 8 phi/psi angles of 5 amino acids,
    # centered on the amino acid to calculate the PB for
    # Hence, the PBs are not defined for the two amino acids
    # at each terminus
    pb_angles = np.full((len(phi) - 4, 8), np.nan)
    pb_angles[:, 0] = psi[:-4]
    pb_angles[:, 1] = phi[1:-3]
    pb_angles[:, 2] = psi[1:-3]
    pb_angles[:, 3] = phi[2:-2]
    pb_angles[:, 4] = psi[2:-2]
    pb_angles[:, 5] = phi[3:-1]
    pb_angles[:, 6] = psi[3:-1]
    pb_angles[:, 7] = phi[4:]
    pb_angles = np.rad2deg(pb_angles)
コード例 #7
0
import biotite
import biotite.structure as struc
import biotite.structure.io as strucio
import biotite.database.rcsb as rcsb
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import colors
import scipy.stats as sts

# Download and parse file
file = rcsb.fetch("3vkh", "cif", biotite.temp_dir())
atom_array = strucio.load_structure(file)
# Calculate backbone dihedral angles
# from one of the two identical chains in the asymmetric unit
phi, psi, omega = struc.dihedral_backbone(
    atom_array[atom_array.chain_id == "A"])
# Conversion from radians into degree
phi *= 180 / np.pi
psi *= 180 / np.pi
# Remove invalid values (NaN) at first and last position
phi = phi[1:-1]
psi = psi[1:-1]

# Plot density
figure = plt.figure()
ax = figure.add_subplot(111)
h, xed, yed, image = ax.hist2d(phi,
                               psi,
                               bins=(200, 200),
                               cmap="RdYlGn_r",
                               cmin=1)
コード例 #8
0
import biotite
import biotite.structure as struc
import biotite.structure.io as strucio
import biotite.database.rcsb as rcsb
import matplotlib.pyplot as plt
import numpy as np
from matplotlib import colors
import scipy.stats as sts

# Download and parse file
file = rcsb.fetch("3vkh", "cif", biotite.temp_dir())
atom_array = strucio.load_structure(file)
# Calculate backbone dihedral angles
# from one of the two identical chains in the asymmetric unit
phi, psi, omega = struc.dihedral_backbone(atom_array, "A")
# Conversion from radians into degree
phi *= 180/np.pi
psi *= 180/np.pi
# Remove invalid values (NaN) at first and last position
phi= phi[1:-1]
psi= psi[1:-1]

# Plot density
figure = plt.figure()
ax = figure.add_subplot(111)
h, xed, yed, image = ax.hist2d(phi, psi, bins=(200, 200),
                cmap="RdYlGn_r", cmin=1)
cbar = figure.colorbar(image, orientation="vertical")
cbar.set_label("Count")
ax.set_aspect("equal")
コード例 #9
0
# (in radians)
print("Angle:", struc.angle(array[0],array[1],array[2]))
# Calculate dihedral angle between first 4 CA atoms in first frame
# (in radians)
print("Dihedral angle:", struc.dihedral(array[0],array[1],array[2],array[4]))

########################################################################
# In some cases one is interested in the dihedral angles of the peptide
# backbone, :math:`\phi`, :math:`\psi` and :math:`\omega`.
# In the following code snippet we measure these angles and create a
# simple Ramachandran plot for the first frame of *TC5b*.

import matplotlib.pyplot as plt
import numpy as np
array = pdbx.get_structure(file, model=1)
phi, psi, omega = struc.dihedral_backbone(array, chain_id="A")
plt.plot(phi * 360/(2*np.pi), psi * 360/(2*np.pi),
        marker="o", linestyle="None")
plt.xlim(-180,180)
plt.ylim(-180,180)
plt.xlabel("phi")
plt.ylabel("psi")
plt.show()

########################################################################
# Comparing structures
# ^^^^^^^^^^^^^^^^^^^^
# 
# Now we want to calculate a measure of flexibility for each residue in
# *TC5b*. The *root mean square fluctuation* (RMSF) is a good value for
# that.