diff --git a/doc/conf.py b/doc/conf.py index cbfb38f77..1b3c05fab 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -195,7 +195,7 @@ "within_subsection_order": FileNameSortKey, # Do not run example scripts with a trailing '_noexec' "filename_pattern": "^((?!_noexec).)*$", - "ignore_pattern": r"(.*ignore\.py)|(.*pymol\.py)", + "ignore_pattern": r"(.*ignore\.py)", "download_all_examples": False, # Never report run time "min_reported_time": sys.maxsize, diff --git a/doc/examples/scripts/structure/alphabet/structure_search.png b/doc/examples/scripts/structure/alphabet/structure_search.png deleted file mode 100644 index d24320157..000000000 Binary files a/doc/examples/scripts/structure/alphabet/structure_search.png and /dev/null differ diff --git a/doc/examples/scripts/structure/alphabet/structure_search.py b/doc/examples/scripts/structure/alphabet/structure_search.py index 696c54627..edf83dc15 100644 --- a/doc/examples/scripts/structure/alphabet/structure_search.py +++ b/doc/examples/scripts/structure/alphabet/structure_search.py @@ -24,6 +24,7 @@ import numpy as np import biotite import biotite.database.rcsb as rcsb +import biotite.interface.pymol as pymol_interface import biotite.sequence as seq import biotite.sequence.align as align import biotite.sequence.graphics as graphics @@ -374,8 +375,20 @@ def filter_undefined_spans(sequence, min_length): _, transform = struc.superimpose(query_anchors, target_anchors) # Apply this transformation to full structure target_chain = transform.apply(target_chain) -# Visualization with PyMOL... -# sphinx_gallery_ammolite_script = "structure_search_pymol.py" + +# Visualization with PyMOL +pymol_interface.cmd.set("cartoon_rect_length", 1.0) +pymol_interface.cmd.set("depth_cue", 0) +pymol_interface.cmd.set("cartoon_cylindrical_helices", 1) +pymol_interface.cmd.set("cartoon_helix_radius", 1.5) +pymol_query = pymol_interface.PyMOLObject.from_structure(query_chain) +pymol_target = pymol_interface.PyMOLObject.from_structure(target_chain) +pymol_query.show_as("cartoon") +pymol_target.show_as("cartoon") +pymol_query.color("biotite_lightgreen") +pymol_target.color("biotite_lightorange") +pymol_query.orient() +pymol_interface.show((1500, 1000)) # sphinx_gallery_thumbnail_number = 3 ######################################################################################## diff --git a/doc/examples/scripts/structure/alphabet/structure_search_pymol.py b/doc/examples/scripts/structure/alphabet/structure_search_pymol.py deleted file mode 100644 index 0e8434d58..000000000 --- a/doc/examples/scripts/structure/alphabet/structure_search_pymol.py +++ /dev/null @@ -1,26 +0,0 @@ -import ammolite -from matplotlib.colors import to_rgb -import biotite - -PNG_SIZE = (1000, 750) - -ammolite.cmd.set("cartoon_rect_length", 1.0) -ammolite.cmd.set("depth_cue", 0) -ammolite.cmd.set("cartoon_cylindrical_helices", 1) -ammolite.cmd.set("cartoon_helix_radius", 1.5) - -# Define colors -for color_name, color_value in biotite.colors.items(): - ammolite.cmd.set_color("biotite_" + color_name, to_rgb(color_value)) - -pymol_query = ammolite.PyMOLObject.from_structure(query_chain) -pymol_target = ammolite.PyMOLObject.from_structure(target_chain) -pymol_query.show_as("cartoon") -pymol_target.show_as("cartoon") -pymol_query.color("biotite_lightgreen") -pymol_target.color("biotite_lightorange") -pymol_query.orient() - -# Save image -ammolite.cmd.ray(*PNG_SIZE) -ammolite.cmd.png(__image_destination__) diff --git a/doc/examples/scripts/structure/contacts/contact_sites.png b/doc/examples/scripts/structure/contacts/contact_sites.png deleted file mode 100644 index be2a5b554..000000000 Binary files a/doc/examples/scripts/structure/contacts/contact_sites.png and /dev/null differ diff --git a/doc/examples/scripts/structure/contacts/contact_sites.py b/doc/examples/scripts/structure/contacts/contact_sites.py index d4723426b..f4509c346 100644 --- a/doc/examples/scripts/structure/contacts/contact_sites.py +++ b/doc/examples/scripts/structure/contacts/contact_sites.py @@ -15,6 +15,7 @@ import numpy as np import biotite.database.rcsb as rcsb +import biotite.interface.pymol as pymol_interface import biotite.structure as struc import biotite.structure.io.pdbx as pdbx @@ -25,7 +26,8 @@ # Fetch and load structure pdbx_file = pdbx.BinaryCIFFile.read(rcsb.fetch("2or1", "bcif")) -structure = pdbx.get_structure(pdbx_file, model=1) +structure = pdbx.get_structure(pdbx_file, model=1, include_bonds=True) +structure = structure[~struc.filter_solvent(structure)] # Separate structure into the DNA and the two identical protein chains @@ -70,5 +72,41 @@ res_name = protein_l.res_name[protein_l.res_id == res_id][0] print(res_name.capitalize() + str(res_id)) -# Visualization with PyMOL... -# sphinx_gallery_ammolite_script = "contact_sites_pymol.py" + +# Visualization with PyMOL +pymol_obj = pymol_interface.PyMOLObject.from_structure(structure) +pymol_obj.color("gray", np.isin(structure.chain_id, ["A", "B"])) +pymol_obj.color("biotite_brightorange", structure.chain_id == "L") +pymol_obj.color("biotite_lightgreen", structure.chain_id == "R") +# Set view +pymol_interface.cmd.set_view( + ( + -0.044524662, + 0.767611504, + 0.639355302, + 0.998693943, + 0.018437184, + 0.047413416, + 0.024606399, + 0.640637815, + -0.767439663, + 0.000000000, + 0.000000000, + -115.614288330, + 56.031833649, + 23.317802429, + 3.761308193, + 73.517341614, + 157.711288452, + -20.000000000, + ) +) +# Highlight contacts +residue_mask = np.isin(structure.res_id, common_ids) +pymol_obj.show("sticks", np.isin(structure.chain_id, ["L", "R"]) & residue_mask) +for chain, color in zip(("L", "R"), ("biotite_dimorange", "biotite_darkgreen")): + pymol_obj.color( + color, + (structure.chain_id == chain) & (structure.atom_name != "CA") & residue_mask, + ) +pymol_interface.show((1500, 800)) diff --git a/doc/examples/scripts/structure/contacts/contact_sites_pymol.py b/doc/examples/scripts/structure/contacts/contact_sites_pymol.py deleted file mode 100644 index a4eb3622e..000000000 --- a/doc/examples/scripts/structure/contacts/contact_sites_pymol.py +++ /dev/null @@ -1,64 +0,0 @@ -import ammolite -import numpy as np -from matplotlib.colors import to_rgb -import biotite -import biotite.structure as struc - -PNG_SIZE = (1000, 550) - -# General configuration -ammolite.cmd.set("cartoon_side_chain_helper", 1) -ammolite.cmd.set("cartoon_discrete_colors", 1) -ammolite.cmd.set("depth_cue", 0) -ammolite.cmd.set("cartoon_oval_length", 0.8) - -# Define colors -for color_name, color_value in biotite.colors.items(): - ammolite.cmd.set_color("biotite_" + color_name, to_rgb(color_value)) - -# Add bonds to structure and convert to PyMOL -structure = structure[~struc.filter_solvent(structure)] -structure.bonds = struc.connect_via_residue_names(structure) -pymol_obj = ammolite.PyMOLObject.from_structure(structure) - -# Set overall colors -pymol_obj.color("gray", np.isin(structure.chain_id, ["A", "B"])) -pymol_obj.color("biotite_brightorange", structure.chain_id == "L") -pymol_obj.color("biotite_lightgreen", structure.chain_id == "R") - -# Set view -ammolite.cmd.set_view( - ( - -0.044524662, - 0.767611504, - 0.639355302, - 0.998693943, - 0.018437184, - 0.047413416, - 0.024606399, - 0.640637815, - -0.767439663, - 0.000000000, - 0.000000000, - -115.614288330, - 56.031833649, - 23.317802429, - 3.761308193, - 73.517341614, - 157.711288452, - -20.000000000, - ) -) - -# Highlight contacts -residue_mask = np.isin(structure.res_id, common_ids) -pymol_obj.show("sticks", np.isin(structure.chain_id, ["L", "R"]) & residue_mask) -for chain, color in zip(("L", "R"), ("biotite_dimorange", "biotite_darkgreen")): - pymol_obj.color( - color, - (structure.chain_id == chain) & (structure.atom_name != "CA") & residue_mask, - ) - -# Save image -ammolite.cmd.ray(*PNG_SIZE) -ammolite.cmd.png(__image_destination__) diff --git a/doc/examples/scripts/structure/contacts/leaflet.png b/doc/examples/scripts/structure/contacts/leaflet.png deleted file mode 100644 index 5ab551ac8..000000000 Binary files a/doc/examples/scripts/structure/contacts/leaflet.png and /dev/null differ diff --git a/doc/examples/scripts/structure/contacts/leaflet.py b/doc/examples/scripts/structure/contacts/leaflet.py index 1a8655ecd..828b06af2 100644 --- a/doc/examples/scripts/structure/contacts/leaflet.py +++ b/doc/examples/scripts/structure/contacts/leaflet.py @@ -25,6 +25,7 @@ from tempfile import NamedTemporaryFile import networkx as nx import numpy as np +import biotite.interface.pymol as pymol_interface import biotite.structure as struc import biotite.structure.io as strucio @@ -111,7 +112,32 @@ def find_leaflets(structure, head_atom_mask, cutoff_distance=15.0, periodic=Fals # Save marked lipids to structure file temp = NamedTemporaryFile(suffix=".pdb") strucio.save_structure(temp.name, structure) -# Visualization with PyMOL... -# sphinx_gallery_ammolite_script = "leaflet_pymol.py" - temp.close() + + +# Visualization with PyMOL +pymol_interface.cmd.set("sphere_scale", 1.5) +# Remove hydrogen and water +structure = structure[(structure.element != "H") & (structure.res_name != "TIP")] +structure.bonds = struc.connect_via_distances(structure) +pymol_obj = pymol_interface.PyMOLObject.from_structure(structure) +# Configure lipid tails +pymol_obj.color("biotite_lightgreen", structure.chain_id == "A") +pymol_obj.color("biotite_brightorange", structure.chain_id == "B") +pymol_obj.show("sticks", np.isin(structure.chain_id, ("A", "B"))) +# Configure lipid heads +pymol_obj.color( + "biotite_darkgreen", (structure.chain_id == "A") & (structure.atom_name == "P") +) +pymol_obj.color( + "biotite_dimorange", (structure.chain_id == "B") & (structure.atom_name == "P") +) +pymol_obj.show( + "spheres", np.isin(structure.chain_id, ("A", "B")) & (structure.atom_name == "P") +) +# Adjust camera +pymol_obj.orient() +pymol_interface.cmd.turn("x", 90) +pymol_obj.zoom(buffer=-10) +# Display +pymol_interface.show((1500, 1000)) diff --git a/doc/examples/scripts/structure/contacts/leaflet_pymol.py b/doc/examples/scripts/structure/contacts/leaflet_pymol.py deleted file mode 100644 index 59b2e98a0..000000000 --- a/doc/examples/scripts/structure/contacts/leaflet_pymol.py +++ /dev/null @@ -1,46 +0,0 @@ -import ammolite -import numpy as np -from matplotlib.colors import to_rgb -import biotite -import biotite.structure as struc - -PNG_SIZE = (1000, 700) - - -# General configuration -ammolite.cmd.set("sphere_scale", 1.5) -ammolite.cmd.set("depth_cue", 0) - -# Define colors -for color_name, color_value in biotite.colors.items(): - ammolite.cmd.set_color("biotite_" + color_name, to_rgb(color_value)) - -# Remove hydrogen and water and convert to PyMOL -structure = structure[(structure.element != "H") & (structure.res_name != "TIP")] -structure.bonds = struc.connect_via_distances(structure) -pymol_obj = ammolite.PyMOLObject.from_structure(structure) - -# Configure lipid tails -pymol_obj.color("biotite_lightgreen", structure.chain_id == "A") -pymol_obj.color("biotite_brightorange", structure.chain_id == "B") -pymol_obj.show("sticks", np.isin(structure.chain_id, ("A", "B"))) - -# Configure lipid heads -pymol_obj.color( - "biotite_darkgreen", (structure.chain_id == "A") & (structure.atom_name == "P") -) -pymol_obj.color( - "biotite_dimorange", (structure.chain_id == "B") & (structure.atom_name == "P") -) -pymol_obj.show( - "spheres", np.isin(structure.chain_id, ("A", "B")) & (structure.atom_name == "P") -) - -# Adjust camera -pymol_obj.orient() -ammolite.cmd.turn("x", 90) -pymol_obj.zoom(buffer=-10) - -# Save image -ammolite.cmd.ray(*PNG_SIZE) -ammolite.cmd.png(__image_destination__) diff --git a/doc/examples/scripts/structure/misc/biological_assembly.png b/doc/examples/scripts/structure/misc/biological_assembly.png deleted file mode 100644 index 1290b2e49..000000000 Binary files a/doc/examples/scripts/structure/misc/biological_assembly.png and /dev/null differ diff --git a/doc/examples/scripts/structure/misc/biological_assembly.py b/doc/examples/scripts/structure/misc/biological_assembly.py index 83586dcca..7ca9959d7 100644 --- a/doc/examples/scripts/structure/misc/biological_assembly.py +++ b/doc/examples/scripts/structure/misc/biological_assembly.py @@ -28,8 +28,7 @@ `this page `_. In this example, we will create the complete biological assembly of the -capsid from the *Sulfolobus turreted icosahedral virus* -- a hetero 1080-mer! +capsid from the lambda phage. At first we will check, which assemblies are available to us. """ @@ -37,13 +36,15 @@ # Code source: Patrick Kunzmann # License: BSD 3 clause -from tempfile import NamedTemporaryFile import biotite.database.rcsb as rcsb +import biotite.interface.pymol as pymol_interface import biotite.structure as struc -import biotite.structure.io as strucio import biotite.structure.io.pdbx as pdbx -pdbx_file = pdbx.BinaryCIFFile.read(rcsb.fetch("3J31", "bcif")) +PDB_ID = "7VII" + + +pdbx_file = pdbx.BinaryCIFFile.read(rcsb.fetch(PDB_ID, "bcif")) assemblies = pdbx.list_assemblies(pdbx_file) print("ID name") @@ -61,19 +62,38 @@ # It returns the chosen assembly as :class:`AtomArray`. # Note that the assembly ID is a string, not an integer. -biological_unit = pdbx.get_assembly(pdbx_file, assembly_id="1", model=1) -print("Number of protein chains:", struc.get_chain_count(biological_unit)) +assembly = pdbx.get_assembly( + pdbx_file, + assembly_id="1", + model=1, + # To identify later which atoms belong to which protein type + extra_fields=["label_entity_id"], +) + +print("Number of protein chains:", struc.get_chain_count(assembly)) ######################################################################## -# Now we could do some analysis on the biological unit. -# But for this example we will simply save the entire assembly as *PDB* -# file for later visualization. +# The assembly consists of two different protein types, so called entities. +# Each entity may be represented by multiple chain IDs. -# For brevity, save only CA atoms to file for visualization -biological_unit = biological_unit[biological_unit.atom_name == "CA"] -temp = NamedTemporaryFile(suffix=".cif") -strucio.save_structure(temp.name, biological_unit) -# Visualization with PyMOL... -# sphinx_gallery_ammolite_script = "biological_assembly_pymol.py" +entity_info = pdbx_file.block["entity"] +print("ID description") +print() +for entity_id, description in zip( + entity_info["id"].as_array(), entity_info["pdbx_description"].as_array() +): + print(f"{entity_id:2} {description}") + +######################################################################## +# Now we could do some analysis on the biological unit. +# But for this example we will visualize the entire assembly. -temp.close() +# Show capsid structure as CA spheres to increase rendering speed +assembly = assembly[assembly.atom_name == "CA"] +pymol_object = pymol_interface.PyMOLObject.from_structure(assembly) +pymol_object.color("biotite_dimgreen", assembly.label_entity_id == "1") +pymol_object.color("biotite_lightorange", assembly.label_entity_id == "2") +pymol_object.set("sphere_scale", 2.0) +pymol_object.show_as("spheres") +pymol_object.zoom(buffer=25) +pymol_interface.show((1500, 1500)) diff --git a/doc/examples/scripts/structure/misc/biological_assembly_pymol.py b/doc/examples/scripts/structure/misc/biological_assembly_pymol.py deleted file mode 100644 index 3175b4eb9..000000000 --- a/doc/examples/scripts/structure/misc/biological_assembly_pymol.py +++ /dev/null @@ -1,22 +0,0 @@ -import ammolite -import matplotlib.pyplot as plt -import numpy as np - -PNG_SIZE = (1000, 1000) - - -# Convert to PyMOL -# Skip adding bonds, since all atoms but CA are filtered out -pymol_obj = ammolite.PyMOLObject.from_structure(biological_unit) - -# Set spheres and color -pymol_obj.zoom(buffer=50) -ammolite.cmd.set("sphere_scale", 1.5) -pymol_obj.show_as("spheres") -chain_ids = np.unique(biological_unit.chain_id) -for chain_id, color in zip(chain_ids, plt.get_cmap("tab20").colors): - pymol_obj.color(color, biological_unit.chain_id == chain_id) - -# Save image -ammolite.cmd.ray(*PNG_SIZE) -ammolite.cmd.png(__image_destination__) diff --git a/doc/examples/scripts/structure/misc/homolog_superimposition.png b/doc/examples/scripts/structure/misc/homolog_superimposition.png deleted file mode 100644 index 54677db1f..000000000 Binary files a/doc/examples/scripts/structure/misc/homolog_superimposition.png and /dev/null differ diff --git a/doc/examples/scripts/structure/misc/homolog_superimposition.py b/doc/examples/scripts/structure/misc/homolog_superimposition.py index 4db689581..b97a4b892 100644 --- a/doc/examples/scripts/structure/misc/homolog_superimposition.py +++ b/doc/examples/scripts/structure/misc/homolog_superimposition.py @@ -2,9 +2,7 @@ Superimposition of homologous protein structures ================================================ -This script superimposes the structure of a streptavidin monomer -into an avidin monomer. -The visualization was conducted with PyMOL. +This script superimposes the structure of a streptavidin monomer into an avidin monomer. - *Green*: Avidin - *Orange*: Strepatvidin @@ -14,6 +12,7 @@ # License: BSD 3 clause import biotite.database.rcsb as rcsb +import biotite.interface.pymol as pymol_interface import biotite.structure as struc import biotite.structure.io.pdbx as pdbx @@ -32,5 +31,13 @@ def _extract_monomer(complex): ) streptavidin, _, _, _ = struc.superimpose_homologs(avidin, streptavidin) -# Visualization with PyMOL... -# sphinx_gallery_ammolite_script = "homolog_superimposition_pymol.py" + +# Visualization with PyMOL +pymol_avidin = pymol_interface.PyMOLObject.from_structure(avidin) +pymol_streptavidin = pymol_interface.PyMOLObject.from_structure(streptavidin) +pymol_avidin.color("biotite_lightgreen") +pymol_streptavidin.color("biotite_lightorange") +pymol_avidin.show_as("cartoon") +pymol_streptavidin.show_as("cartoon") +pymol_avidin.orient() +pymol_interface.show((1500, 1000)) diff --git a/doc/examples/scripts/structure/misc/homolog_superimposition_pymol.py b/doc/examples/scripts/structure/misc/homolog_superimposition_pymol.py deleted file mode 100644 index 1760d527e..000000000 --- a/doc/examples/scripts/structure/misc/homolog_superimposition_pymol.py +++ /dev/null @@ -1,30 +0,0 @@ -import ammolite -from matplotlib.colors import to_rgb -import biotite - -PNG_SIZE = (1000, 750) - -# General configuration -ammolite.cmd.set("cartoon_oval_length", 0.8) -ammolite.cmd.set("depth_cue", 0) - -# Define colors -for color_name, color_value in biotite.colors.items(): - ammolite.cmd.set_color("biotite_" + color_name, to_rgb(color_value)) - -# Convert to PyMOL -pymol_avidin = ammolite.PyMOLObject.from_structure(avidin) -pymol_streptavidin = ammolite.PyMOLObject.from_structure(streptavidin) - -# Set overall colors -pymol_avidin.color("biotite_lightgreen") -pymol_streptavidin.color("biotite_lightorange") - -# Set view -pymol_avidin.show_as("cartoon") -pymol_streptavidin.show_as("cartoon") -pymol_avidin.orient() - -# Save image -ammolite.cmd.ray(*PNG_SIZE) -ammolite.cmd.png(__image_destination__) diff --git a/doc/examples/scripts/structure/modeling/docking.png b/doc/examples/scripts/structure/modeling/docking.png deleted file mode 100644 index f468cf380..000000000 Binary files a/doc/examples/scripts/structure/modeling/docking.png and /dev/null differ diff --git a/doc/examples/scripts/structure/modeling/docking.py b/doc/examples/scripts/structure/modeling/docking.py index eb9a3fcfa..efb1031f5 100644 --- a/doc/examples/scripts/structure/modeling/docking.py +++ b/doc/examples/scripts/structure/modeling/docking.py @@ -33,6 +33,7 @@ from scipy.stats import spearmanr import biotite.application.autodock as autodock import biotite.database.rcsb as rcsb +import biotite.interface.pymol as pymol_interface import biotite.structure as struc import biotite.structure.info as info import biotite.structure.io.pdbx as pdbx @@ -145,6 +146,36 @@ ref_ligand = ref_ligand[ref_ligand.element != "H"] docked_ligand = docked_ligand[docked_ligand.element != "H"] -# Visualization with PyMOL... + +# Visualization with PyMOL # sphinx_gallery_thumbnail_number = 2 -# sphinx_gallery_ammolite_script = "docking_pymol.py" +pymol_receptor = pymol_interface.PyMOLObject.from_structure(receptor) +pymol_ref_ligand = pymol_interface.PyMOLObject.from_structure(ref_ligand) +pymol_docked_ligand = pymol_interface.PyMOLObject.from_structure(docked_ligand) +# Visualize receptor as surface +pymol_receptor.show_as("surface") +pymol_receptor.color("white") +pymol_interface.cmd.set("surface_quality", 2) +# Visualize as stick model +pymol_interface.cmd.set("stick_radius", 0.15) +pymol_interface.cmd.set("sphere_scale", 0.25) +pymol_interface.cmd.set("sphere_quality", 4) +# The reference is a blue 'shadow' +pymol_ref_ligand.show("spheres") +pymol_ref_ligand.color("blue") +pymol_ref_ligand.set("stick_color", "blue") +pymol_ref_ligand.set("sphere_transparency", 0.6) +pymol_ref_ligand.set_bond("stick_transparency", 0.6) +# Visualize docked model +pymol_docked_ligand.show("spheres") +pymol_docked_ligand.color("gray", docked_ligand.element == "C") +pymol_docked_ligand.set("stick_color", "grey80") +# Adjust camera +pymol_docked_ligand.orient() +pymol_interface.cmd.rotate("y", 180) +pymol_interface.cmd.rotate("x", -15) +pymol_docked_ligand.zoom(buffer=-1) +pymol_interface.cmd.set("depth_cue", 0) +pymol_interface.cmd.clip("slab", 100) +# Display +pymol_interface.show((1500, 600)) diff --git a/doc/examples/scripts/structure/modeling/docking_pymol.py b/doc/examples/scripts/structure/modeling/docking_pymol.py deleted file mode 100644 index 8f9adc263..000000000 --- a/doc/examples/scripts/structure/modeling/docking_pymol.py +++ /dev/null @@ -1,50 +0,0 @@ -import ammolite -from matplotlib.colors import to_rgb -import biotite - -PNG_SIZE = (1000, 400) - - -# Define colors -for color_name, color_value in biotite.colors.items(): - ammolite.cmd.set_color("biotite_" + color_name, to_rgb(color_value)) - -# Convert to PyMOL -pymol_receptor = ammolite.PyMOLObject.from_structure(receptor) -pymol_ref_ligand = ammolite.PyMOLObject.from_structure(ref_ligand) -pymol_docked_ligand = ammolite.PyMOLObject.from_structure(docked_ligand) - -# Visualize receptor as surface -pymol_receptor.show_as("surface") -pymol_receptor.color("white") -ammolite.cmd.set("surface_quality", 2) - -# Visualize as stick model -ammolite.cmd.set("stick_radius", 0.15) -ammolite.cmd.set("sphere_scale", 0.25) -ammolite.cmd.set("sphere_quality", 4) - -# The reference is a blue 'shadow' -REF_COLOR = "skyblue" -REF_ALPHA = 0.4 -pymol_ref_ligand.show("spheres") -pymol_ref_ligand.color(REF_COLOR) -pymol_ref_ligand.set("stick_color", REF_COLOR) -pymol_ref_ligand.set("sphere_transparency", 1 - REF_ALPHA) -pymol_ref_ligand.set_bond("stick_transparency", 1 - REF_ALPHA) - -pymol_docked_ligand.show("spheres") -pymol_docked_ligand.color("black", docked_ligand.element == "C") -pymol_docked_ligand.set("stick_color", "grey80") - -# Adjust camera -pymol_docked_ligand.orient() -ammolite.cmd.rotate("y", 180) -ammolite.cmd.rotate("x", -15) -pymol_docked_ligand.zoom(buffer=-1) -ammolite.cmd.set("depth_cue", 0) -ammolite.cmd.clip("slab", 100) - -# Save image -ammolite.cmd.ray(*PNG_SIZE) -ammolite.cmd.png(__image_destination__) diff --git a/doc/examples/scripts/structure/modeling/normal_modes.gif b/doc/examples/scripts/structure/modeling/normal_modes.gif deleted file mode 100644 index fda4f7cde..000000000 Binary files a/doc/examples/scripts/structure/modeling/normal_modes.gif and /dev/null differ diff --git a/doc/examples/scripts/structure/modeling/normal_modes.py b/doc/examples/scripts/structure/modeling/normal_modes.py index ac760c459..745d86d85 100644 --- a/doc/examples/scripts/structure/modeling/normal_modes.py +++ b/doc/examples/scripts/structure/modeling/normal_modes.py @@ -33,12 +33,11 @@ # Code source: Patrick Kunzmann # License: BSD 3 clause -from tempfile import NamedTemporaryFile import numpy as np from numpy import newaxis import biotite.database.rcsb as rcsb +import biotite.interface.pymol as pymol_interface import biotite.structure as struc -import biotite.structure.io as strucio import biotite.structure.io.pdbx as pdbx # A CSV file containing the eigenvectors for the CA atoms @@ -58,7 +57,7 @@ # Load structure pdbx_file = pdbx.BinaryCIFFile.read(rcsb.fetch(PDB_ID, "bcif")) -structure = pdbx.get_structure(pdbx_file, model=1) +structure = pdbx.get_structure(pdbx_file, model=1, include_bonds=True) # Filter first peptide chain @@ -106,9 +105,33 @@ # An atom array stack containing all frames oscillating_structure = struc.from_template(protein_chain, oscillation) -# Save as PDB for rendering a video with PyMOL -temp = NamedTemporaryFile(suffix=".pdb") -strucio.save_structure(temp.name, oscillating_structure) -# sphinx_gallery_static_image = "normal_modes.gif" -temp.close() +# Visualization with PyMOL +pymol_object = pymol_interface.PyMOLObject.from_structure(oscillating_structure) +pymol_object.color("biotite_lightgreen", oscillating_structure.chain_id == "A") +# Set custom view +pymol_interface.cmd.set_view( + ( + 0.605540633, + 0.363677770, + -0.707855821, + -0.416691631, + 0.902691007, + 0.107316799, + 0.678002179, + 0.229972601, + 0.698157668, + 0.000000000, + 0.000000000, + -115.912551880, + 32.098876953, + 31.005725861, + 78.377349854, + 89.280677795, + 142.544403076, + -20.000000000, + ) +) +# Prepare output video frames +pymol_interface.cmd.mset() +pymol_interface.play((600, 600)) diff --git a/doc/examples/scripts/structure/modeling/normal_modes_pymol.py b/doc/examples/scripts/structure/modeling/normal_modes_pymol.py deleted file mode 100644 index 1c0ad0e2c..000000000 --- a/doc/examples/scripts/structure/modeling/normal_modes_pymol.py +++ /dev/null @@ -1,53 +0,0 @@ -from os.path import isdir, join -from pymol import cmd - -INPUT_STRUCTURE = "normal_modes.pdb" -OUTPUT_DIR = "normal_modes" - - -# Load structure and remove water -cmd.load(INPUT_STRUCTURE) - -# Add secondary structure -cmd.dss() - -# Define colors -cmd.set_color("biotite_lightgreen", [111 / 255, 222 / 255, 76 / 255]) - -# Set overall colors -cmd.color("biotite_lightgreen", "chain A") - -# Set view -cmd.set_view( - ( - 0.605540633, - 0.363677770, - -0.707855821, - -0.416691631, - 0.902691007, - 0.107316799, - 0.678002179, - 0.229972601, - 0.698157668, - 0.000000000, - 0.000000000, - -115.912551880, - 32.098876953, - 31.005725861, - 78.377349854, - 89.280677795, - 142.544403076, - -20.000000000, - ) -) - -# Prepare output video frames -cmd.mset() -cmd.set("ray_shadows", 0) -if not isdir(OUTPUT_DIR): - os.mkdir(OUTPUT_DIR) -cmd.mpng(join(OUTPUT_DIR, "img_"), mode=2, width=600, height=600) - - -# Render animated GIF -# convert -delay 3 -loop 0 -dispose 2 normal_modes/*.png normal_modes.gif diff --git a/doc/examples/scripts/structure/protein/peptide_assembly.png b/doc/examples/scripts/structure/protein/peptide_assembly.png deleted file mode 100644 index f4f1b1872..000000000 Binary files a/doc/examples/scripts/structure/protein/peptide_assembly.png and /dev/null differ diff --git a/doc/examples/scripts/structure/protein/peptide_assembly.py b/doc/examples/scripts/structure/protein/peptide_assembly.py index de9f24704..9b3c371a8 100644 --- a/doc/examples/scripts/structure/protein/peptide_assembly.py +++ b/doc/examples/scripts/structure/protein/peptide_assembly.py @@ -22,13 +22,12 @@ # License: BSD 3 clause import itertools -from tempfile import NamedTemporaryFile import numpy as np from numpy.linalg import norm +import biotite.interface.pymol as pymol_interface import biotite.sequence as seq import biotite.structure as struc import biotite.structure.info as info -import biotite.structure.io as strucio C_N_LENGTH = 1.34 N_CA_LENGTH = 1.46 @@ -40,7 +39,7 @@ # Reference peptide bond atom coordinates taken from 1l2y: # CA, C, N, O, H -PEPTIDE_COORD = np.array( +peptide_coord = np.array( [ [-8.608, 3.135, -1.618], [-7.117, 2.964, -1.897], @@ -70,8 +69,8 @@ def create_raw_backbone_coord(number_of_res): else: # Rotate about z-axis -> backbone lies in z-plane rot_axis = [0, 0, angle_direction] - # Calculate the coordinates of a new atoms by rotating the - # previous bond by the given angle + # Calculate the coordinates of a new atoms by rotating the previous + # bond by the given angle new_coord = struc.rotate_about_axis( coord[i - 2], axis=rot_axis, @@ -116,46 +115,42 @@ def append_residue(chain, residue): return chain -def assemble_peptide(sequence): - res_names = [seq.ProteinSequence.convert_letter_1to3(r) for r in sequence] - backbone_coord = create_raw_backbone_coord(len(sequence)) - - chain = struc.AtomArray(0) - for i, res_name in enumerate(res_names): - residue = info.residue(res_name) - - # Superimpose residue to corresponding backbone coordinates +sequence = seq.ProteinSequence("WRKFWKYLK") +res_names = [seq.ProteinSequence.convert_letter_1to3(r) for r in sequence] +backbone_coord = create_raw_backbone_coord(len(sequence)) + + +chain = struc.AtomArray(0) +for i, res_name in enumerate(res_names): + residue = info.residue(res_name) + + # Superimpose residue to corresponding backbone coordinates + _, transformation = struc.superimpose( + backbone_coord[3 * i : 3 * i + 3], + residue.coord[np.isin(residue.atom_name, ["N", "CA", "C"])], + ) + residue = transformation.apply(residue) + + chain = append_residue(chain, residue) + + if i != 0: + # Fix positions of peptide hydrogen and oxygen atom + ca_i, c_i, o_i = [ + np.where(chain.atom_name == atom_name)[0][-2] + for atom_name in ["CA", "C", "O"] + ] + n_i, h_i = [ + np.where(chain.atom_name == atom_name)[0][-1] for atom_name in ["N", "H"] + ] _, transformation = struc.superimpose( - backbone_coord[3 * i : 3 * i + 3], - residue.coord[np.isin(residue.atom_name, ["N", "CA", "C"])], + chain.coord[[ca_i, c_i, n_i]], peptide_coord[:3] ) - residue = transformation.apply(residue) - - chain = append_residue(chain, residue) - - if i != 0: - # Fix positions of peptide hydrogen and oxygen atom - ca_i, c_i, o_i = [ - np.where(chain.atom_name == atom_name)[0][-2] - for atom_name in ["CA", "C", "O"] - ] - n_i, h_i = [ - np.where(chain.atom_name == atom_name)[0][-1] - for atom_name in ["N", "H"] - ] - _, transformation = struc.superimpose( - chain.coord[[ca_i, c_i, n_i]], PEPTIDE_COORD[:3] - ) - chain.coord[[o_i, h_i]] = transformation.apply(PEPTIDE_COORD[3:]) - return chain - + chain.coord[[o_i, h_i]] = transformation.apply(peptide_coord[3:]) -# Sequence of an antimicrobial peptide -sequence = seq.ProteinSequence("WRKFWKYLK") -chain = assemble_peptide(sequence) -out_file = NamedTemporaryFile(suffix=".bcif", delete=False) -strucio.save_structure(out_file.name, chain) -# Visualization with PyMOL... -# sphinx_gallery_ammolite_script = "peptide_assembly_pymol.py" -out_file.close() +# Visualization with PyMOL +pymol_object = pymol_interface.PyMOLObject.from_structure(chain) +pymol_object.show_as("sticks") +pymol_object.orient() +pymol_object.zoom(buffer=-7.5) +pymol_interface.show((1500, 600)) diff --git a/doc/examples/scripts/structure/protein/peptide_assembly_pymol.py b/doc/examples/scripts/structure/protein/peptide_assembly_pymol.py deleted file mode 100644 index 7afdc6a06..000000000 --- a/doc/examples/scripts/structure/protein/peptide_assembly_pymol.py +++ /dev/null @@ -1,29 +0,0 @@ -import ammolite -from matplotlib.colors import to_rgb -import biotite -import biotite.structure as struc - -PNG_SIZE = (1000, 400) - - -# Define colors -for color_name, color_value in biotite.colors.items(): - ammolite.cmd.set_color("biotite_" + color_name, to_rgb(color_value)) - -# Convert to PyMOL -chain.bonds = struc.connect_via_distances(chain) -pymol_obj = ammolite.PyMOLObject.from_structure(chain) - -# Visualize as stick model -pymol_obj.show_as("sticks") -pymol_obj.color("biotite_lightgreen", (chain.res_id % 2 == 0) & (chain.element == "C")) -pymol_obj.color("biotite_dimgreen", (chain.res_id % 2 != 0) & (chain.element == "C")) -ammolite.cmd.set("depth_cue", 0) - -# Adjust camera -pymol_obj.orient() -pymol_obj.zoom(buffer=-7.5) - -# Save image -ammolite.cmd.ray(*PNG_SIZE) -ammolite.cmd.png(__image_destination__)