Visualization — mdpath.scr.visualization

This module contains the class MDPathVisualize which contains all visualization functions for the MDPath package. The class only contains static methods for visualization purposes.

Classes

MDPathVisualize

class mdpath.src.visualization.MDPathVisualize[source]

Bases: object

Methods for visualization within the MDPath package.

Attributes:

None (only static methods)

static apply_backtracking(original_dict: dict, translation_dict: dict) dict[source]

Backtracks the original dictionary with a translation dictionary.

Args:

original_dict (dict): Cluster pathways dictionary.

translation_dict (dict): Residue coordinates dictionary.

Returns:

updated_dict (dict): Updated cluster pathways dictionary with residue coordinates.

static assign_generic_numbers(pdb_file_path: str, output_file_path: str = 'numbered_structure.pdb') None[source]

Assigns generic numbers to residues in a PDB file by querying the gpcrdb.org.

Args:

pdb_file_path (str): Path to the PDB file.

output_file_path (str, optional): Path to save the new PDB file with generic numbers. Defaults to “numbered_structure.pdb”.

static assign_generic_numbers_paths(cluster_pathways: dict, generic_number_dict: dict) tuple[source]

Assigns generic numbers to residues in the cluster pathways.

Args:

cluster_pathways (dict): Dictionary with cluster pathways.

generic_number_dict (dict): Dictionary with residue numbers, generic numbers, and amino acids.

Returns:

updated_cluster_residues (dict): Updated dictionary with cluster pathways and generic numbers.

no_genetic_number_list (list): List of residue numbers with no generic numbers.

static cluster_prep_for_visualisation(cluster: list, pdb_file: str) list[source]

Prepares pathway clusters for visualisation.

Args:

cluster (list): Cluster of pathways.

pdb_file (str): Path to PDB file.

Returns:

cluster (list): Cluster of pathways with CA atom coordinates.

static create_gpcr_2d_path_vis(updated_cluster_residues: dict, cutoff_percentage: int = 0, image_name: str = 'GPCR_2D_pathways', fontsize_tm: int = 20, fontsize_numbers: int = 18, fontfile: str | None = None) None[source]

Creates a 2D visualization of pathways within a GPCR based on the provided cluster residues.

Args:

updated_cluster_residues (dict): A dictionary where keys are cluster identifiers and values are lists of paths. Each path is a list of residue identifiers in the format ‘TMx.y’.

cutoff_percentage (int, optional): The percentage cutoff for drawing connections between residues. Only connections with a frequency above this percentage will be drawn. Defaults to 0.

image_name (str, optional): The base name for the output image files. Defaults to “GPCR_2D_pathways”.

fontsize_tm (int, optional): The font size for the transmembrane (TM) labels. Defaults to 20.

fontsize_numbers (int, optional): The font size for the residue numbers. Defaults to 18.

fontfile (str, optional): The path to a font file to use for text rendering. If None, the default Pillow font is used. Defaults to None.

Returns:

None. The function saves the generated images to disk with filenames based on the provided image_name and cluster identifiers.

static create_splines(json_path: str) None[source]
static draw_column(draw: ~PIL.ImageDraw.Draw, col: int, res: list, label: str, circle_positions: dict, circle_diameter: int, padding: int, column_width: int, height: int, font: <module 'PIL.ImageFont' from '/home/docs/checkouts/readthedocs.org/user_builds/mdpath/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py'>, title_font: <module 'PIL.ImageFont' from '/home/docs/checkouts/readthedocs.org/user_builds/mdpath/envs/latest/lib/python3.10/site-packages/PIL/ImageFont.py'>, align: str = 'top') None[source]

Draws a column in the given pillow drawing context corresponding to a TM region or loop region with a label, a rectangle, and circles with genetic numbers corresponding to residues in this region that are part of a path.

Args:

draw (ImageDraw.Draw): The drawing context. col (int): The column index (1-based). res (list): A list of tuples containing data to be visualized, where each tuple contains an identifier and a genetic number. label (str): The label for the column. circle_positions (dict): A dictionary to store the positions of the circles, keyed by genetic number. circle_diameter (int): The diameter of the circles to be drawn. padding (int): The padding between elements. column_width (int): The width of the column. height (int): The height of the drawing area. font (ImageFont): The font to be used for the genetic numbers. title_font (ImageFont): The font to be used for the column label. align (str, optional): The alignment of the circles within the column. Can be ‘top’ or ‘bottom’. Defaults to ‘top’.

static format_dict(updated_dict: dict) dict[source]

Reformats the dictionary to be JSON serializable.

Args:

updated_dict (dict): Dictionary to be reformatted.

Returns:

transformed_dict (dict): Reformatted dictionary.

static parse_pdb_and_create_dictionary(pdb_file_path: str) dict[source]

Parses a PDB file and creates a dictionary with residue numbers, generic numbers, and amino acids.

Args:

pdb_file_path (str): Path to the PDB file.

Returns:

residue_dict (dict): Dictionary with residue numbers, generic numbers, and amino acids.

static precompute_cluster_properties_quick(json_data: dict) list[source]

Precomputes cluster properties for quicker visualization in Jupyter notebook.

Args:

json_data (dict): Cluster data with pathways and CA atom coordinates.

Returns:

cluster_properties (list): List of cluster properties. Contains clusterid,coordinates, color, and radius.

static precompute_path_properties(json_data: dict) list[source]

Precomputes path properties for quicker visualization in Jupyter notebook.

Args:

json_data (dict): Cluster data with pathways and CA atom coordinates.

Returns:

path_properties (list): List of path properties. Contains clusterid, pathway index, path segment index, coordinates, color, radius, and path number.

static remove_non_protein(input_pdb: str, output_pdb: str) None[source]

Function to remove non-protein atoms (e.g., water, ligands, ions) from a PDB file and write only the protein atoms to a new PDB file.

Args:

input_pdb (str): Path to the input PDB file.

output_pdb (str): Path to the output PDB file to save the protein-only structure.

static residue_CA_coordinates(pdb_file: str, end: int) dict[source]

Collects CA atom coordinates for residues.

Args:

pdb_file (str): Path to PDB file.

end (int): Last residue to consider.

Returns:

residue_coordinates_dict (dict): Dictionary with residue number as key and CA atom coordinates as value.

static visualise_graph(graph: Graph, k=0.1, node_size=200) None[source]

Draws residue graph to PNG file.

Args:

graph (nx.Graph): Residue graph.

k (float, optional): Distance between individual nodes. Defaults to 0.1.

node_size (int, optional): Size of individual nodes. Defaults to 200.