.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gallery/structure/misc/diameter.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_misc_diameter.py: Calculation of protein diameter =============================== This script calculates the diameter of a protein defined as the maximum pairwise atom distance. .. GENERATED FROM PYTHON SOURCE LINES 8-36 .. rst-class:: sphx-glr-script-out .. code-block:: none Diameter of 1QAW: 88.78395 Angstrom | .. code-block:: Python # Code source: Patrick Kunzmann # License: BSD 3 clause from tempfile import gettempdir import numpy as np import biotite.database.rcsb as rcsb import biotite.structure as struc import biotite.structure.io as strucio def get_diameter(pdb_id): file_name = rcsb.fetch(pdb_id, "bcif", gettempdir()) atom_array = strucio.load_structure(file_name) # Remove all non-amino acids atom_array = atom_array[struc.filter_amino_acids(atom_array)] coord = atom_array.coord # Calculate all pairwise difference vectors diff = coord[:, np.newaxis, :] - coord[np.newaxis, :, :] # Calculate absolute of difference vectors -> square distances sq_dist = np.sum(diff * diff, axis=-1) # Maximum distance is diameter diameter = np.sqrt(np.max(sq_dist)) return diameter # Example application print("Diameter of 1QAW:", get_diameter("1QAW"), "Angstrom") .. _sphx_glr_download_examples_gallery_structure_misc_diameter.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: diameter.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: diameter.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_