.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_monomer.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_auto_examples_plot_monomer.py: Plot a Monomer Structure ======================== This example demonstrates how to parse a monomer PDB file and plot the backbone trace using atomworks.io. .. figure:: /_static/best_practices_mental_models.png :alt: Custom thumbnail for this example :width: 300px Custom thumbnail image for this example. **Key steps:** - Load a PDB file - Visualize the backbone trace .. GENERATED FROM PYTHON SOURCE LINES 20-21 ## Import libraries .. GENERATED FROM PYTHON SOURCE LINES 21-38 .. code-block:: Python import io from biotite.database import rcsb from atomworks.io.utils.io_utils import load_any from atomworks.io.utils.testing import get_pdb_path from atomworks.io.utils.visualize import view def get_example_path_or_buffer(pdb_id: str) -> io.StringIO | str: try: return get_pdb_path(pdb_id) except FileNotFoundError: return rcsb.fetch(pdb_id, format="cif") .. GENERATED FROM PYTHON SOURCE LINES 39-40 ## Load and plot the structure .. GENERATED FROM PYTHON SOURCE LINES 40-48 .. code-block:: Python example = get_example_path_or_buffer("6lyz") # e.g. '/path/to/6lyz.cif' or io.StringIO(rcsb.fetch("6lyz", "cif")) atom_array = load_any(example, model=1, extra_fields=["charge", "occupancy"]) # ... inspect the first 15 atoms print(f"Structure has {atom_array.array_length()} atoms. First 15 atoms:") atom_array[:15] .. rst-class:: sphx-glr-script-out .. code-block:: none Structure has 1102 atoms. First 15 atoms: AtomArray([ Atom(np.array([ 3.287, 10.092, 10.329], dtype=float32), chain_id="A", res_id=1, ins_code="", res_name="LYS", hetero=False, atom_name="N", element="N", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([ 2.445, 10.457, 9.182], dtype=float32), chain_id="A", res_id=1, ins_code="", res_name="LYS", hetero=False, atom_name="CA", element="C", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([ 2.5 , 11.978, 9.038], dtype=float32), chain_id="A", res_id=1, ins_code="", res_name="LYS", hetero=False, atom_name="C", element="C", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([ 2.588, 12.719, 10.041], dtype=float32), chain_id="A", res_id=1, ins_code="", res_name="LYS", hetero=False, atom_name="O", element="O", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([1.006, 9.995, 9.385], dtype=float32), chain_id="A", res_id=1, ins_code="", res_name="LYS", hetero=False, atom_name="CB", element="C", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([ 0.016, 10.546, 8.377], dtype=float32), chain_id="A", res_id=1, ins_code="", res_name="LYS", hetero=False, atom_name="CG", element="C", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([-1.404, 10.093, 8.699], dtype=float32), chain_id="A", res_id=1, ins_code="", res_name="LYS", hetero=False, atom_name="CD", element="C", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([-2.269, 10.03 , 7.451], dtype=float32), chain_id="A", res_id=1, ins_code="", res_name="LYS", hetero=False, atom_name="CE", element="C", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([-3.559, 9.362, 7.735], dtype=float32), chain_id="A", res_id=1, ins_code="", res_name="LYS", hetero=False, atom_name="NZ", element="N", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([ 2.441, 12.404, 7.789], dtype=float32), chain_id="A", res_id=2, ins_code="", res_name="VAL", hetero=False, atom_name="N", element="N", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([ 2.396, 13.826, 7.425], dtype=float32), chain_id="A", res_id=2, ins_code="", res_name="VAL", hetero=False, atom_name="CA", element="C", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([ 1.003, 14.071, 6.846], dtype=float32), chain_id="A", res_id=2, ins_code="", res_name="VAL", hetero=False, atom_name="C", element="C", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([ 0.719, 13.722, 5.679], dtype=float32), chain_id="A", res_id=2, ins_code="", res_name="VAL", hetero=False, atom_name="O", element="O", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([ 3.509, 14.142, 6.435], dtype=float32), chain_id="A", res_id=2, ins_code="", res_name="VAL", hetero=False, atom_name="CB", element="C", occupancy=1.0, charge=0, is_polymer=True), Atom(np.array([ 3.49 , 15.586, 5.874], dtype=float32), chain_id="A", res_id=2, ins_code="", res_name="VAL", hetero=False, atom_name="CG1", element="C", occupancy=1.0, charge=0, is_polymer=True) ]) .. GENERATED FROM PYTHON SOURCE LINES 49-52 .. code-block:: Python # ... show the structure in a jupyter notebook view(atom_array[atom_array.chain_id == "A"]) .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.624 seconds) .. _sphx_glr_download_auto_examples_plot_monomer.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_monomer.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_monomer.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_monomer.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_