Exemplo n.º 1
0
def test_get_residue_masks(array):
    SAMPLE_SIZE = 100
    np.random.seed(0)
    indices = np.random.randint(0, array.array_length(), SAMPLE_SIZE)
    masks = struc.get_residue_masks(array, indices)
    for index, mask in zip(indices, masks):
        ref_mask = array.res_id == array.res_id[index]
        assert mask.tolist() == ref_mask.tolist()
Exemplo n.º 2
0
def find_leaflets(structure,
                  head_atom_mask,
                  cutoff_distance=15.0,
                  periodic=False):
    """
    Identify which lipids molecules belong to the same lipid bilayer
    leaflet.

    Parameters
    ----------
    structure : AtomArray, shape=(n,)
        The structure containing the membrane.
        May also include other molecules, e.g. water or an embedded
        protein.
    head_atom_mask : ndarray, dtype=bool, shape=(n,)
        A boolean mask that selects atoms from `structure` that
        represent lipid head groups.
    cutoff_distance : float, optional
        When the distance of two head groups is larger than this value,
        they are not (directly) connected in the same leaflet.
    periodic : bool, optional,
        If true, periodic boundary conditions are considered.
        This requires that `structure` has an associated `box`.
    
    Returns
    -------
    leaflets : ndarray, dtype=bool, shape=(m,n)
        Multiple boolean masks, one for each identified leaflet.
        Each masks indicates which atoms of the input `structure`
        are in the leaflet.
    """

    cell_list = struc.CellList(structure,
                               cell_size=cutoff_distance,
                               selection=head_atom_mask,
                               periodic=periodic)
    adjacency_matrix = cell_list.create_adjacency_matrix(cutoff_distance)
    graph = nx.Graph(adjacency_matrix)

    head_leaflets = [
        sorted(c) for c in nx.connected_components(graph)
        # A leaflet cannot consist of a single lipid
        # This also removes all entries
        # for atoms not in 'head_atom_mask'
        if len(c) > 1
    ]

    # 'leaflets' contains indices to head atoms
    # Broadcast each head atom index to all atoms in its corresponding
    # residue
    leaflet_masks = np.empty((len(head_leaflets), structure.array_length()),
                             dtype=bool)
    for i, head_leaflet in enumerate(head_leaflets):
        leaflet_masks[i] = struc.get_residue_masks(structure, head_leaflet) \
                                .any(axis=0)
    return leaflet_masks
Exemplo n.º 3
0
def test_get_residue_starts_for(array):
    SAMPLE_SIZE = 100
    np.random.seed(0)
    indices = np.random.randint(0, array.array_length(), SAMPLE_SIZE)
    ref_starts = np.array([
        np.where(mask)[0][0]
        for mask in struc.get_residue_masks(array, indices)
    ])
    test_starts = struc.get_residue_starts_for(array, indices)
    assert test_starts.tolist() == ref_starts.tolist()
Exemplo n.º 4
0
import biotite.structure.io.mmtf as mmtf
import biotite.structure.graphics as graphics
import biotite.database.rcsb as rcsb


# Structure of a DNA double helix
mmtf_file = mmtf.MMTFFile.read(rcsb.fetch("1qxb", "mmtf"))
structure = mmtf.get_structure(mmtf_file, model=1, include_bonds=True)
nucleotides = structure[struc.filter_nucleotides(structure)]

# Choose one adenine-thymine and one guanine-cytosine base pair
base_pairs = struc.base_pairs(nucleotides)
for i, j in base_pairs:
    if (nucleotides.res_name[i], nucleotides.res_name[j]) == ("DG", "DC"):
        guanine, cytosine = [nucleotides[mask] for mask
                             in struc.get_residue_masks(nucleotides, [i, j])]
        break
for i, j in base_pairs:
    if (nucleotides.res_name[i], nucleotides.res_name[j]) == ("DA", "DT"):
        adenine, thymine = [nucleotides[mask] for mask
                            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")]