### Download Example MDAnalysis Datasets Source: https://bradyajohnston.github.io/MolecularNodes/tutorials/trajectories.html Use this command to install the MDAnalysisData package and download example datasets for testing. ```python # pip install MDAnalysisData from MDAnalysisData import datasets datasets.fetch_adk_transitions_FRODA() ``` -------------------------------- ### Install Blender via Snap Source: https://bradyajohnston.github.io/MolecularNodes/tutorials/installation.html On Linux systems experiencing 'biotite' module errors, installing Blender using Snap can resolve dependency issues. This command installs Blender in classic confinement mode. ```bash sudo snap install blender --classic ``` -------------------------------- ### Setup Molecular Nodes Source: https://bradyajohnston.github.io/MolecularNodes/api/density.html Initializes the Molecular Nodes library and creates a canvas object for rendering. ```python import molecularnodes as mn # create a canvas object canvas = mn.Canvas() ``` -------------------------------- ### Add APBS Density Example Source: https://bradyajohnston.github.io/MolecularNodes/api/density.html Loads a density file using the specified path and configures it for visualization. ```python from pathlib import Path apbs_sample = Path("../../") / "tests/data/apbs.dx.gz" # load density file d = mn.entities.density.io.load( file_path=apbs_sample, style="density_iso_surface", overwrite=True, ) ``` -------------------------------- ### Setup Molecular Nodes Source: https://bradyajohnston.github.io/MolecularNodes/api/trajectory/styles.html Initializes the Molecular Nodes canvas and loads a trajectory using MDAnalysis. ```python import molecularnodes as mn import MDAnalysis as mda from MDAnalysis.tests.datafiles import DCD, PSF, TPR, XTC u = mda.Universe(PSF, DCD) canvas = mn.Canvas() ``` -------------------------------- ### Install Molecular Nodes with Blender Support Source: https://bradyajohnston.github.io/MolecularNodes/api Install the molecularnodes package with the necessary Blender dependencies. This ensures compatibility with Blender's Python environment. ```bash pip install molecularnodes[bpy] ``` -------------------------------- ### Import Libraries and Initialize Canvas Source: https://bradyajohnston.github.io/MolecularNodes/api/trajectory/solvent.html Imports necessary libraries for molecular dynamics analysis and visualization, and initializes the MolecularNodes canvas. Ensure all required libraries are installed. ```python import MDAnalysis as mda import molecularnodes as mn import numpy as np from MDAnalysis import transformations as trans from MDAnalysis.analysis import density from MDAnalysis.tests.datafiles import TPR, XTC canvas = mn.Canvas() ``` -------------------------------- ### PyMol Selection Example Source: https://bradyajohnston.github.io/MolecularNodes/tutorials/selections.html This is an example of how to create a selection in PyMol. It selects residues ALA, CYS, and TRP within chain A. ```python select my_selection, chain A and (resn ALA+CYS+TRP) ``` -------------------------------- ### DensityAnnotationManager.get Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.density.annotations.html Get an annotation by name. ```APIDOC ## get ### Description Get an annotation by name. ### Parameters #### Path Parameters - **name** (str) - The name of the annotation to retrieve. ``` -------------------------------- ### Initialize Molecular Nodes Canvas Source: https://bradyajohnston.github.io/MolecularNodes/api Import the molecularnodes library and create a Canvas object to manage scene settings and rendering. This is the starting point for scripting with Molecular Nodes. ```python import molecularnodes as mn canvas = mn.Canvas(mn.scene.Cycles(samples=32), resolution=(720, 480)) ``` -------------------------------- ### Create Ensemble 3D Object Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.Ensemble.html Generate a 3D representation of the ensemble. Configure node setup, world scaling, fraction of instances to display, and simplification for performance. ```python entities.Ensemble.create_object( name='NewEnsemble', node_setup=True, world_scale=0.01, fraction=1.0, simplify=False, )__ ``` -------------------------------- ### Initialize TrajectoryAnnotation Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.trajectory.annotations.html Base class for creating trajectory annotations. Implement the 'draw' method and optionally 'defaults' for initial parameter setup. ```python entities.trajectory.annotations.TrajectoryAnnotation(trajectory)__ ``` -------------------------------- ### Initialize StyleSticks Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/StyleSticks.html Instantiate StyleSticks with custom parameters for quality, radius, color blur, and smooth shading. ```python StyleSticks(quality=3, radius=0.2, color_blur=False, shade_smooth=True) ``` -------------------------------- ### Initialize StyleSpheres Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/StyleSpheres.html Instantiate the StyleSpheres class with desired parameters. Use 'Point' geometry for performance, especially in Cycles. Adjust radius, subdivisions, and smooth shading as needed. ```python StyleSpheres(geometry='Point', radius=0.8, subdivisions=2, shade_smooth=True) ``` -------------------------------- ### Initialize StyleSurface Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/StyleSurface.html Instantiate StyleSurface with various parameters to define the surface's appearance and generation settings. Adjust quality, scale, probe size, relaxation steps, separation, grouping, color source, color blur, and shading for desired results. ```python StyleSurface( quality=3, scale_radius=1.5, probe_size=1.0, relaxation_steps=10, separate_by='chain_id', group_id=0, color_source='Alpha Carbon', color_blur=2, shade_smooth=True, )__ ``` -------------------------------- ### Get Density Annotation by Name Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.density.annotations.html Retrieve a specific annotation by its name from the DensityAnnotationManager. ```python entities.density.annotations.DensityAnnotationManager.get(name)__ ``` -------------------------------- ### Get Operator Subclasses Source: https://bradyajohnston.github.io/MolecularNodes/api/blender.html Use bpy.types.Operator.__subclasses__() to check if temporary operators are unregistered. ```python bpy.types.Operator.__subclasses__() ``` -------------------------------- ### Get Ensemble Viewport Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.Ensemble.html Retrieve the 3D bounding box for the ensemble entity. ```python entities.Ensemble.get_view()__ ``` -------------------------------- ### Create Canvas and Render Snapshot Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/Canvas.html Create a Canvas instance with specified engine and resolution, then render a snapshot of the current scene to a file. Supports transparent backgrounds. ```python import molecularnodes as mn cv = mn.Canvas(engine="CYCLES", resolution=(800, 800), transparent=True) cv.snapshot("frame.png") ``` -------------------------------- ### create_object Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.StreamingTrajectory.html Creates and initializes a Blender object for the trajectory, including mesh computation and modifier setup. ```APIDOC ## create_object ### Description Create and initialize Blender object for trajectory. Creates mesh, computes attributes, sets up modifiers, registers with MolecularNodes. ### Parameters - **name** (str) - Optional - Name for the Blender object. Default is "NewUniverseObject". ### Returns - **bpy.types.Object** - Created Blender object. ``` -------------------------------- ### Initialize DSSP Analysis Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.trajectory.DSSPManager.html Call the init method to prepare the DSSP analysis. This is a prerequisite before performing any secondary structure calculations. ```python entities.trajectory.DSSPManager.init() ``` -------------------------------- ### Apply Multiple Styles and Materials to Molecules Source: https://bradyajohnston.github.io/MolecularNodes/api/styles.html Demonstrates fetching multiple molecules and applying different styles (Cartoon, Ribbon, Spheres) with corresponding materials (Default, AmbientOcclusion, FlatOutline). Each molecule is added to the canvas, snapshotted, and then cleared for the next iteration. ```python codes = ["4ozs", "8H1B", "8U8W"] styles = [ mn.StyleCartoon(), mn.StyleRibbon(), mn.StyleSpheres(geometry="Instance", subdivisions=4), ] materials = [ mn.material.Default(), mn.material.AmbientOcclusion(), mn.material.FlatOutline(), ] for code, style, material in zip(codes, styles, materials): mol = mn.Molecule.fetch(code) mol.add_style(style, material=material) cv.frame_object(mol) cv.snapshot() cv.clear() ``` -------------------------------- ### Get Current Annotations Visibility Source: https://bradyajohnston.github.io/MolecularNodes/api/annotations.html Retrieves the current visibility state (True/False) of all annotations managed by the trajectory. ```python # get current annotations visibility t.annotations.visible ``` -------------------------------- ### Initialize StyleRibbon Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/StyleRibbon.html Instantiate StyleRibbon with various parameters to define the ribbon's appearance. Adjust quality, smoothing, radii, and shape for detailed control. ```python StyleRibbon( quality=3, backbone_smoothing=0.5, backbone_threshold=4.5, backbone_radius=1.6, nucleic_backbone_shape='Cylinder', nucleic_backbone_radius=1.6, backbone_width=3.0, backbone_thickness=1.0, base_scale=(2.5, 0.5, 7.0), base_resolution=4, base_realize=False, uv_map=False, u_component='Factor', color_blur=False, shade_smooth=True, )__ ``` -------------------------------- ### Initialize Canvas for Multiple Render Engines Source: https://bradyajohnston.github.io/MolecularNodes/api/materials.html Sets up a canvas and imports necessary libraries for rendering molecular trajectories with different engines and materials. ```python import MDAnalysis as mda import itertools from MDAnalysis.tests.datafiles import PSF, DCD cv = mn.Canvas(resolution=(800, 800), transparent=True) ``` -------------------------------- ### Get Annotation Function Signature Source: https://bradyajohnston.github.io/MolecularNodes/api/annotations.html Displays the function signature for a specific annotation type, showing its parameters. ```python t.annotations.add_atom_info.func.__signature____ ``` -------------------------------- ### Get Property Group Subclasses Source: https://bradyajohnston.github.io/MolecularNodes/api/blender.html Use bpy.types.PropertyGroup.__subclasses__() to check if temporary property groups are garbage collected. ```python bpy.types.PropertyGroup.__subclasses__() ``` -------------------------------- ### Instantiate Ensemble Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.Ensemble.html Initialize an Ensemble object with a file path. ```python entities.Ensemble(file_path)__ ``` -------------------------------- ### Get Trajectory by Name Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/session.MNSession.html Retrieve a trajectory instance from the session by its name. Raises a ValueError if the trajectory is not found. ```python session.MNSession.get_trajectory(name) ``` -------------------------------- ### Initialize Canvas Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/Canvas.html Instantiate the Canvas class to configure render settings like engine, resolution, transparency, and scene template. ```python Canvas( engine='EEVEE', resolution=(1280, 720), transparent=False, template='Molecular Nodes', )__ ``` -------------------------------- ### Initialize Camera Class Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/scene.camera.html Instantiate the Camera class to create a new camera object for Blender scene management. ```python scene.camera.Camera() ``` -------------------------------- ### Get Current Camera Rotation Source: https://bradyajohnston.github.io/MolecularNodes/api/canvas.html Retrieves and prints the current rotation angles (X, Y, Z) of the camera. ```python # print current rotation canvas.camera.rotation ``` -------------------------------- ### Get Annotation by Name Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/annotations.manager.html Retrieves a specific annotation using its name. This is useful for accessing individual annotations. ```python annotations.manager.BaseAnnotationManager.get(name)__ ``` -------------------------------- ### StyleSpheres Constructor Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/StyleSpheres.html Initializes a StyleSpheres object with specified parameters. ```APIDOC ## StyleSpheres ### Description Style class for Style Spheres. ### Parameters #### Path Parameters - **geometry** (Any) - Optional - Show spheres as a _Point Cloud_ , _Instances_ of a mesh Icosphere, or realised _Mesh_ instances of an Icosphere. Point cloud is best for performance and should definitely be used if rendering in Cycles. Defaults to 'Point'. - **radius** (float) - Optional - Scale the `vdw_radii` of the atom when setting the radius of the spheres. Defaults to 0.8. - **subdivisions** (int) - Optional - Number of subdicisions when using _Instances_ or _Mesh_ to represent atoms. Defaults to 2. - **shade_smooth** (bool) - Optional - Apply smooth shading when using _Instances_ or _Mesh_. Defaults to True. ``` -------------------------------- ### Initialize Canvas and Load Molecule Source: https://bradyajohnston.github.io/MolecularNodes/api/materials.html Initializes a canvas for rendering and loads a molecule, applying an AmbientOcclusion material. ```python import molecularnodes as mn cv = mn.Canvas(engine="EEVEE", resolution=(800, 800), transparent=True) ``` ```python mol = mn.Molecule.fetch("8H1B").add_style( mn.StyleSurface(), material=mn.material.AmbientOcclusion() ) cv.frame_object(mol) cv.snapshot() ``` -------------------------------- ### MoleculeAnnotationManager Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.molecule.annotations.html Manages annotations for a Molecule Entity, providing methods to clear, get, register, remove, and unregister annotations. ```APIDOC ## MoleculeAnnotationManager ### Description Annotation Manager for Molecule Entity. ### Initialization ```python entities.molecule.annotations.MoleculeAnnotationManager(entity) ``` ### Attributes - **visible** (`bool`) - Visibility of all annotations - getter. ### Methods - **clear**(): Remove all annotations. - **get**(name: str): Get an annotation by name. - **register_class**(annotation_class): Register an annotation class. - **remove**(annotation): Remove an annotation by name or instance. - **unregister_type**(annotation_type): Unregister a registered annotation type. ``` -------------------------------- ### Get Selection Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.trajectory.SelectionManager.html Retrieves a selection UI item by its name. If no selection with the given name exists, it returns `None`. ```APIDOC ## get ```python entities.trajectory.SelectionManager.get(name) ``` ### Description Try and get a selection UI Item by name. ### Parameters #### Path Parameters - **name** (str) - Required - Name of the UI item to retrieve. ### Returns #### Success Response - **TrajectorySelectionItem or None** - The matching UI item, or `None` if no match was found. ``` -------------------------------- ### Render Density Object with Default Camera Settings Source: https://bradyajohnston.github.io/MolecularNodes/api/canvas.html Renders a density object from the front view using default camera settings. ```python # frame density object from front and render - default canvas.frame_object(d1, viewpoint="front") canvas.snapshot() ``` -------------------------------- ### Initialize StyleCartoon Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/StyleCartoon.html Instantiate the StyleCartoon class with various parameters to define the visual style. Adjust parameters like quality, peptide and nucleic acid specific styles, and color rendering options. ```python StyleCartoon( quality=2, peptide_dssp=False, peptide_cylinders=False, peptide_arrows=True, peptide_rounded=False, peptide_thickness=0.6, peptide_width=2.2, peptide_loop_radius=0.3, peptide_smoothing=0.5, backbone_shape='Cylinder', nucleic_width=3.0, nucleic_thickness=1.0, nucleic_radius=2.0, base_shape='Rectangle', base_realize=False, color_blur=True, shade_smooth=True, )__ ``` -------------------------------- ### Get Molecule View Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/Molecule.html Retrieves the 3D bounding box of the entity object. This method is part of the Molecule class. ```python Molecule.get_view() ``` -------------------------------- ### TrajectoryAnnotationManager Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.trajectory.annotations.html Manages annotations for a Trajectory Entity, providing methods to clear, get, register, remove, and unregister annotations and their types. ```APIDOC ## TrajectoryAnnotationManager ### Description Annotation Manager for Trajectory Entity ### Constructor entities.trajectory.annotations.TrajectoryAnnotationManager(entity) ### Attributes - **visible** (getter) - Visibility of all annotations ### Methods - **clear**(): Remove all annotations - **get**(name): Get an annotation by name - **register_class**(annotation_class): Register an annotation class. This method adds the annotation class to the entity specific class registry (_classes) and adds a new method (add_) to the manager with a signature that matches the annotation inputs. - **remove**(annotation): Remove an annotation by name or instance. When a name is used, all annotations that match the name will be removed. - **unregister_type**(annotation_type): Unregister a registered annotation type. This method removes the annotation type from the entity specific class registry and removes the ‘add_<>’ method from the manager ``` -------------------------------- ### Initialize MNSession Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/session.MNSession.html Instantiate the MNSession class to manage molecular data within Blender. ```python session.MNSession() ``` -------------------------------- ### Get Trajectory Bounding Box Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/Trajectory.html Retrieve the 3D bounding box for a specified selection within the trajectory at a given frame. ```python Trajectory.get_view(selection=None, frame=None)__ ``` -------------------------------- ### Add Trajectory with Initial Style Source: https://bradyajohnston.github.io/MolecularNodes/api/trajectory/styles.html Demonstrates how to add a trajectory to the scene with a specific style applied from the beginning. ```APIDOC ## Add Trajectory A style can be specified when adding the trajectory to Blender as follows: ```python t = mn.Trajectory(u).add_style(mn.StyleRibbon(quality=4, backbone_radius = 0.5)) canvas.frame_object(t) canvas.snapshot() ``` ``` -------------------------------- ### Initialize DSSPManager Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.trajectory.DSSPManager.html Instantiate the DSSPManager with an entity. This manager is used for analyzing secondary structures within trajectories. ```python entities.trajectory.DSSPManager(entity) ``` -------------------------------- ### Render Animation Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/Canvas.html Render an animation of the current scene. Optionally specify the output path, start and end frames, and render scale. ```python Canvas.animation(path=None, frame_start=None, frame_end=None, render_scale=100)__ ``` -------------------------------- ### Ensemble Constructor Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.Ensemble.html Initializes an Ensemble object with a file path. ```APIDOC ## entities.Ensemble ### Description Initializes an Ensemble object. ### Parameters #### Path Parameters - **file_path** (str) - The path to the file containing the ensemble data. ``` -------------------------------- ### Get Object by UUID Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/session.MNSession.html Retrieve an object from Blender's database using its unique identifier (UUID). Returns None if no object matches. ```python session.MNSession.get_object(uuid) ``` -------------------------------- ### Create Blender Object for Trajectory Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/Trajectory.html Generate and initialize a Blender object for the trajectory, including mesh creation, attribute computation, and modifier setup. ```python Trajectory.create_object(name='NewUniverseObject')__ ``` -------------------------------- ### Configure Cycles Engine and Add Ball-and-Stick Style Source: https://bradyajohnston.github.io/MolecularNodes/api/styles.html Clears the canvas, sets the rendering engine to Cycles with 32 samples, and adds a cartoon style for peptides and a ball-and-stick style for non-peptides. Bond finding is enabled for the ball-and-stick style. ```python cv.clear() cv.engine = mn.scene.Cycles(samples=32) mol = ( mn.Molecule.fetch("9EYM") .add_style("cartoon", material = mn.material.AmbientOcclusion(), selection = "is_peptide") .add_style("ball_and_stick", selection=mn.entities.MoleculeSelector().not_peptide()) ) mol.styles[1].bond_find = True cv.frame_view(mol) cv.snapshot() ``` -------------------------------- ### Get Biological Assemblies Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/Molecule.html Retrieves the biological assemblies of the molecule. Can return assemblies as a dictionary of transformation matrices or as an array of quaternions if `as_array` is set to True. ```python Molecule.assemblies(as_array=False) ``` -------------------------------- ### MNSession Constructor Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/session.MNSession.html Initializes a new MNSession object. ```APIDOC ## MNSession() ### Description Initializes a new MNSession object. ### Method __init__ ### Endpoint N/A (Constructor) ### Parameters None ``` -------------------------------- ### Initialize Molecular Nodes Canvas Source: https://bradyajohnston.github.io/MolecularNodes/api Initializes the Molecular Nodes canvas with a Cycles renderer and sets the canvas size and transparency. This is the first step before any rendering. ```python import MDAnalysis as mda from MDAnalysis.tests.datafiles import PSF, DCD from MDAnalysisData import datasets from MDAnalysis import transformations from MDAnalysis.analysis import rms, align import numpy as np import matplotlib.cm as cm canvas = mn.Canvas(mn.scene.Cycles(samples=16), (800, 800), transparent=True) ``` -------------------------------- ### Initialize StyleBallAndStick Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/StyleBallAndStick.html Instantiate the StyleBallAndStick class with custom parameters to define the molecular visualization style. Adjust parameters like quality, sphere geometry, and radii for desired visual output. ```python StyleBallAndStick( quality=2, sphere_geometry='Instance', sphere_radius=0.3, bond_split=False, bond_radius=0.3, bond_find=False, bond_find_scale=1.0, color_blur=False, shade_smooth=True, )__ ``` -------------------------------- ### Create Blender Object for OXDNA Trajectory Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.OXDNA.html Create and initialize a Blender object for the OXDNA trajectory. This includes mesh creation, attribute computation, and modifier setup. ```python entities.OXDNA.create_object(name='NewUniverseObject')__ ``` -------------------------------- ### Reset Scene from Template Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/Canvas.html Reset the scene using a specified template or the startup file. Allows configuration of the scene template and render engine. ```python Canvas.scene_reset(template='Molecular Nodes', engine='EEVEE')__ ``` -------------------------------- ### Draw Circle in 2D Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.trajectory.annotations.html Use this function to draw a circle or arc in the 2D viewport. Specify center coordinates, radius, and optional angle or start direction. ```python entities.trajectory.annotations.TrajectoryAnnotation.draw_circle_3d( center, radius, normal=None, angle=360.0, start_dv=None, c_arrow=False, cc_arrow=False, overrides=None, )__ ``` -------------------------------- ### Initialize StreamingTrajectory Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.StreamingTrajectory.html Instantiate a StreamingTrajectory object for IMD streaming connections. Requires a Universe with an IMD reader. By default, it creates a linked mesh object. ```python entities.StreamingTrajectory( universe, name='StreamingTrajectory', create_object=True, )__ ``` -------------------------------- ### Get Trajectory Selection Item by Name Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.trajectory.SelectionManager.html Retrieves a specific trajectory selection UI item using its name. Returns None if no item matches the provided name. ```python entities.trajectory.SelectionManager.get(name)__ ``` -------------------------------- ### Initialize AtomInfo Annotation Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.trajectory.annotations.html Instantiate the AtomInfo annotation for a given trajectory. This is typically done via the annotation manager. ```python entities.trajectory.annotations.AtomInfo(trajectory)__ ``` -------------------------------- ### Update Style Node Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/StyleSurface.html Call the update_style_node method to apply the current StyleSurface attributes to a Blender GeometryNodeGroup. This method is used to synchronize the style settings with the node setup. ```python StyleSurface.update_style_node(node_style)__ ``` -------------------------------- ### Instantiate Label3D Annotation Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.molecule.annotations.html Use this to create a Label3D annotation instance. This is a common annotation for all entities. ```python entities.molecule.annotations.Label3D()__ ``` -------------------------------- ### Get Bounding Box of Selection Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.StreamingTrajectory.html Retrieve the 3D bounding box for a specified selection within the trajectory at a given frame. Defaults to the entire entity and current frame if not specified. ```python entities.StreamingTrajectory.get_view(selection=None, frame=None)__ ``` -------------------------------- ### Accessing Annotations Source: https://bradyajohnston.github.io/MolecularNodes/api/annotations.html Demonstrates how to retrieve annotations by name or index, and how to iterate through all available annotations. ```APIDOC ## Accessing Annotations ### Get annotation by name ```python a = t.annotations.get("r1 atom info") print(a) ``` ### Get annotation by index ```python a = t.annotations[1] print(a) ``` ### Iterate through all annotations ```python for a in t.annotations: print(a.name) ``` ``` -------------------------------- ### Draw 2D Circle in Viewport Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.trajectory.annotations.html Draws a circle or arc in the 2D viewport space. Supports specifying radius, angle, start direction, and arrows for clockwise or counter-clockwise direction. ```python entities.trajectory.annotations.AtomInfo.draw_circle_2d( center, radius, angle=360.0, start_dv=None, c_arrow=False, cc_arrow=False, overrides=None, )__ ``` -------------------------------- ### Draw 2D Circle Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.density.annotations.html Draws a circle around a 2D point in the viewport space using normalized coordinates. Supports custom angles, start points, and arrow indicators. ```python entities.density.annotations.DensityAnnotation.draw_circle_2d( center, radius, angle=360.0, start_dv=None, c_arrow=False, cc_arrow=False, overrides=None, )__ ``` -------------------------------- ### Instantiate Label2D Annotation Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.molecule.annotations.html Use this to create a Label2D annotation instance. This is a common annotation for all entities. ```python entities.molecule.annotations.Label2D()__ ``` -------------------------------- ### Render Scene Animation Source: https://bradyajohnston.github.io/MolecularNodes/api/trajectory/rendering.html Renders an animation of the molecular trajectory from a specified start frame to an end frame, with an option to scale the render resolution. This generates a video file of the simulation. ```python # render animation of scene from frame 10 to 50 at 50% sccale canvas.animation(frame_start=10, frame_end=50, render_scale=50) ``` -------------------------------- ### Initialize DensityGridAxes3D Annotation Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.density.annotations.html Initializes a DensityGridAxes3D annotation. This annotation is used for visualizing density grids in 3D space. ```python entities.density.annotations.DensityGridAxes3D(density)__ ``` -------------------------------- ### Draw Line in 2D Viewport Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.density.annotations.html Draws a line between two points in the 2D viewport using normalized coordinates. Optional text can be displayed at the start, end, or midpoint, and arrows can be added. ```python entities.density.annotations.DensityGridAxes3D.draw_line_2d( v1, v2, v1_text=None, v2_text=None, mid_text=None, v1_arrow=False, v2_arrow=False, overrides=None, )__ ``` -------------------------------- ### StyleSurface Constructor Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/StyleSurface.html Initializes a StyleSurface object with specified parameters to define the visual properties of a molecular surface. ```APIDOC ## StyleSurface Constructor ### Description Initializes a StyleSurface object with specified parameters to define the visual properties of a molecular surface. ### Parameters - **quality** (int) - A lower value results in less geometry, with a higher value meaning better looking but more dense geometry. Default: `3` - **scale_radius** (float) - Scale the VDW radii of the atoms when creating the surface. Default: `1.5` - **probe_size** (float) - Size of the probe that is used to check for solvent accessibility (Angstroms). Default: `1.0` - **relaxation_steps** (int) - Number of times smoothening is applied to the generate surface stretched between the atoms. Default: `10` - **separate_by** (Any) - Value for Separate By. Default: `'chain_id'` - **group_id** (int) - Value for Group ID. Default: `0` - **color_source** (Any) - Value for Color Source. Default: `'Alpha Carbon'` - **color_blur** (int) - Interpolate between colors when enabled. When disabled the faces will take their color from their corresponding atom without interpolating. Default: `2` - **shade_smooth** (bool) - Apply smooth shading to the created geometry. Default: `True` ### Example ```python StyleSurface( quality=3, scale_radius=1.5, probe_size=1.0, relaxation_steps=10, separate_by='chain_id', group_id=0, color_source='Alpha Carbon', color_blur=2, shade_smooth=True, ) ``` ``` -------------------------------- ### Custom Annotation with Parameter Overrides Source: https://bradyajohnston.github.io/MolecularNodes/api/annotations.html Example of drawing two 3D circles with different line colors. The first uses a hardcoded color, while the second uses a color defined by a custom input parameter. ```python ... # custom line color input line_color_input: tuple[float, float, float, float] = (1, 1, 1, 1) ... self.draw_circle_3d( center, radius, normal_vector, overrides={"line_color": (1.0, 0.498, 0.055, 1)}, ) self.draw_circle_3d( center, radius * 2, normal_vector, overrides={"line_color": self.interface.line_color_input}, ) ... ``` -------------------------------- ### Load Molecule from File Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/Molecule.html Loads a molecule from a specified file path. Supports various formats like .cif, .bcif, .pdb, .sdf, and .mol. Optionally allows setting a name and removing solvent molecules. ```python Molecule.load(file_path, name=None, remove_solvent=True) ``` -------------------------------- ### Draw 2D Line Annotation Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.density.annotations.html Use to draw a line between two 2D points in normalized viewport coordinates. Optional text labels can be added at the start, end, or middle of the line, and arrows can be displayed at the endpoints. ```python entities.density.annotations.DensityGridAxes.draw_line_2d( v1, v2, v1_text=None, v2_text=None, mid_text=None, v1_arrow=False, v2_arrow=False, overrides=None, )__ ``` -------------------------------- ### Add Styles Based on Atom Selection Source: https://bradyajohnston.github.io/MolecularNodes/api Clears existing styles and adds new styles to the trajectory based on atom selections. Selections can be MDAnalysis selection strings or AtomGroups. This example colors atoms based on their X-coordinate. ```python median = np.median(traj.atoms.positions, axis=0) traj.styles.clear() ( traj .add_style(mn.StyleSpheres(), selection = f"prop x > {median[0]}") .add_style(mn.StyleSpheres(), selection=f"prop x <= {median[0]}", color=(0,0,0,1)) ) canvas.frame_view(traj) canvas.snapshot() ``` -------------------------------- ### Initialize DensityAnnotationManager Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.density.annotations.html Annotation Manager for Density Entity. Manages annotations for density entities. ```python entities.density.annotations.DensityAnnotationManager(entity)__ ``` -------------------------------- ### Render Scene Snapshot Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/Canvas.html Renders an image of the current scene to a specified file path and format. If no path is provided, the image will not be saved. The frame to render can also be specified. ```python Canvas.snapshot(path=None, frame=None, file_format='PNG') ``` -------------------------------- ### Get Bounding Box for OXDNA Trajectory View Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.OXDNA.html Retrieve the 3D bounding box for a specified selection within the OXDNA trajectory at a given frame. If no selection or frame is provided, it considers the whole entity at the current frame. ```python entities.OXDNA.get_view(selection=None, frame=None)__ ``` -------------------------------- ### Set Viewpoint to Top and Snapshot Source: https://bradyajohnston.github.io/MolecularNodes/api/trajectory/solvent.html Sets the viewpoint to 'top', captures a snapshot of the density visualization with grid axes, and then hides the grid axes. This allows for viewing the density from a specific perspective. ```python # set viewpoint to top canvas.frame_view(d.get_view(), viewpoint="top") canvas.snapshot() # hide grid axes ga.visible = False ``` -------------------------------- ### validate Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.density.annotations.html Optional method to validate annotation inputs. This is called during annotation creation and any time the inputs change. It can return False or raise an exception when validation fails, and returns True when all validations succeed. Note: This method gets called when any inputs change, so updating values in here will lead to a recursive loop and should not be done. ```APIDOC ## validate ### Description Optional method to validate annotation inputs This is called during annotation creation and any time the inputs change either through the API or GUI. Can return False or raise an exception when validation fails. Returns True when all validations succeed. Note: This method gets called when any inputs change, so updating values in here will lead to a recursive loop and should not be done. ### Parameters - **input_name** (str) - Optional - The input name update that trigged this validation callback. When no specific input name is available, None is passed. Default: None ``` -------------------------------- ### Initialize Canvas for Molecular Nodes Source: https://bradyajohnston.github.io/MolecularNodes/api/styles.html Initializes a canvas for rendering molecular data with specified resolution and transparency. This is the first step before adding any molecular objects or styles. ```python import molecularnodes as mn cv = mn.Canvas(resolution=(860, 540), transparent=True) ``` -------------------------------- ### StyleRibbon Constructor Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/StyleRibbon.html Initializes a StyleRibbon object with customizable parameters for molecular ribbon styling. ```APIDOC ## StyleRibbon Constructor ### Description Initializes a StyleRibbon object with customizable parameters for molecular ribbon styling. ### Parameters - **quality** (int) - A lower value results in less geometry, with a higher value meaning better looking but more dense geometry. Default: `3` - **backbone_smoothing** (float) - Smoothen the sheet ribbons such as beta-sheets. Default: `0.5` - **backbone_threshold** (float) - Distance (Angstroms) over which subsequent CA points are treated as a new chain. Default: `4.5` - **backbone_radius** (float) - Value for Backbone Radius. Default: `1.6` - **nucleic_backbone_shape** (Any) - Value for Nucleic Backbone Shape. Default: `'Cylinder'` - **nucleic_backbone_radius** (float) - Value for Nucleic Backbone Radius. Default: `1.6` - **backbone_width** (float) - Value for Backbone Width. Default: `3.0` - **backbone_thickness** (float) - Value for Backbone Thickness. Default: `1.0` - **base_scale** (Tuple[float, float, float]) - Value for Base Scale. Default: `(2.5, 0.5, 7.0)` - **base_resolution** (int) - Value for Base Resolution. Default: `4` - **base_realize** (bool) - Value for Base Realize. Default: `False` - **uv_map** (bool) - Compute and store the `uv_map` for the final protein ribbon geometry. Default: `False` - **u_component** (Any) - Value for U Component. Default: `'Factor'` - **color_blur** (bool) - Interpolate between colors when enabled. When disabled the faces will take their color from their corresponding atom without interpolating. Default: `False` - **shade_smooth** (bool) - Apply smooth shading to the created geometry. Default: `True` ### Example ```python StyleRibbon( quality=3, backbone_smoothing=0.5, backbone_threshold=4.5, backbone_radius=1.6, nucleic_backbone_shape='Cylinder', nucleic_backbone_radius=1.6, backbone_width=3.0, backbone_thickness=1.0, base_scale=(2.5, 0.5, 7.0), base_resolution=4, base_realize=False, uv_map=False, u_component='Factor', color_blur=False, shade_smooth=True, ) ``` ``` -------------------------------- ### Load Density Data and Add Annotation Source: https://bradyajohnston.github.io/MolecularNodes/api/trajectory/solvent.html Loads a pre-computed density map from a `.dx` file into MolecularNodes as a `Density` entity with an 'iso_surface' style. It also adds a density information annotation, configuring it to show only the filename and ISO value. ```python # load density file d = mn.entities.density.io.load( file_path="water.dx", style="density_iso_surface", overwrite=True, ) # add a density info annotation for the density entity da = d.annotations.add_density_info() # only show the filename and ISO value da.show_origin = da.show_delta = da.show_shape = False ``` -------------------------------- ### Initialize DensityGridAxes Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/entities.density.annotations.html Density Grid Axes Annotation. Used for density grid visualizations. ```python entities.density.annotations.DensityGridAxes(density)__ ``` -------------------------------- ### Load .blend File Source: https://bradyajohnston.github.io/MolecularNodes/api/reference/Canvas.html Load a .blend file, replacing the current scene. Requires the file path as an argument. ```python Canvas.load(path)__ ``` -------------------------------- ### Load Density File Source: https://bradyajohnston.github.io/MolecularNodes/api/canvas.html Loads a density map file (e.g., EMDB) into Molecular Nodes for visualization. ```python from pathlib import Path d1_path = Path("../../") / "tests/data/emd_24805.map.gz" # load density file d1 = mn.entities.density.io.load( file_path=d1_path, style="density_iso_surface", overwrite=True, ) ```