.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery/structure/nucleotide/base_pairs.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_gallery_structure_nucleotide_base_pairs.py: Plotting the base pairs of a tRNA-like-structure ================================================ In this example we plot a linear secondary-structure diagram of a tRNA mimic (PDB ID: 4P5J) from the *turnip yellow mosaic virus* (TYMV). .. GENERATED FROM PYTHON SOURCE LINES 8-93 .. image-sg:: /examples/gallery/structure/nucleotide/images/sphx_glr_base_pairs_001.png :alt: base pairs :srcset: /examples/gallery/structure/nucleotide/images/sphx_glr_base_pairs_001.png :class: sphx-glr-single-img .. code-block:: Python # Code source: Tom David Müller # License: BSD 3 clause from tempfile import gettempdir import matplotlib.pyplot as plt import matplotlib.ticker as ticker import numpy as np from matplotlib.patches import Arc import biotite import biotite.database.rcsb as rcsb import biotite.structure as struc import biotite.structure.io.pdb as pdb # Download the PDB file and read the structure pdb_file_path = rcsb.fetch("4p5j", "pdb", gettempdir()) pdb_file = pdb.PDBFile.read(pdb_file_path) atom_array = pdb.get_structure(pdb_file)[0] nucleotides = atom_array[struc.filter_nucleotides(atom_array)] # Get the residue names and residue ids of the nucleotides residue_ids = [] residue_names = [] for residue in struc.residue_iter(nucleotides): mapped_nucleotide, exact_match = struc.map_nucleotide(residue) if mapped_nucleotide is None: continue residue_ids.append(residue[0].res_id) if exact_match: residue_names.append(mapped_nucleotide) else: residue_names.append(mapped_nucleotide.lower()) # Create a matplotlib pyplot fig, ax = plt.subplots(figsize=(8.0, 4.5)) # Setup the axis ax.set_xlim(0.5, len(residue_ids) + 0.5) ax.set_ylim(0, len(residue_ids) / 2 + 0.5) ax.set_aspect("equal") ax.xaxis.set_major_locator(ticker.MultipleLocator(3)) ax.tick_params(axis="both", which="major", labelsize=8) ax.set_yticks([]) # Remove the frame plt.box(False) # Plot the residue names in order for residue_name, residue_id in zip(residue_names, residue_ids): ax.text(residue_id, 0, residue_name, ha="center", fontsize=8) # Compute the basepairs and pseudknot order (first result) base_pairs = struc.base_pairs(nucleotides) pseudoknot_order = struc.pseudoknots(base_pairs)[0] # Draw the arcs between base pairs for (base1, base2), order in zip(base_pairs, pseudoknot_order): arc_center = (np.mean((nucleotides.res_id[base1], nucleotides.res_id[base2])), 1.5) arc_diameter = abs(nucleotides.res_id[base2] - nucleotides.res_id[base1]) name1 = nucleotides.res_name[base1] name2 = nucleotides.res_name[base2] if sorted([name1, name2]) in [["A", "U"], ["C", "G"]]: color = biotite.colors["dimorange"] else: color = biotite.colors["brightorange"] if order == 0: linestyle = "-" elif order == 1: linestyle = "--" else: linestyle = ":" arc = Arc( arc_center, arc_diameter, arc_diameter, theta1=0, theta2=180, color=color, linewidth=1.5, linestyle=linestyle, ) ax.add_patch(arc) # Display the plot plt.show() .. _sphx_glr_download_examples_gallery_structure_nucleotide_base_pairs.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: base_pairs.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: base_pairs.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_