Pymol Script Generator

GitHub Link to Code.

PyMOL script generator for structure visualization.

This module generates PyMOL scripts (.pml) for visualizing molecular structures with beta-factor-based thickness and coloring, plus feature highlights with licorice representation.

class mdxplain.structure_visualization.helper.pymol_script_generator.PyMolScriptGenerator

Generator for PyMOL visualization scripts.

Creates .pml scripts with putty cartoons (thickness from beta-factor), color gradients, and focus groups for context visualization. Each focus group contains own structure/features (opak) plus other structures/features (transparent) for context.

Examples

>>> pdb_info = {
...     "cluster_0": {"path": "/path/to/c0.pdb", "color": "#ff0000"}
... }
>>> features = [{"feature_name": "ALA5-GLU10", "residue_seqids": [5, 10]}]
>>> colors = {"ALA5-GLU10": "#00ff00"}
>>> script = PyMolScriptGenerator.generate_script(
...     pdb_info, features, colors
... )
static generate_script(pdb_info: Dict[str, Dict[str, str]], top_features_global: List[Dict[str, Any]], feature_colors_global: Dict[str, str], top_features_local: Dict[str, List[Dict[str, Any]]], feature_colors_local: Dict[str, Dict[str, str]], feature_own_color: bool = True, use_putty: bool = True) str

Generate complete PyMOL script with focus groups.

Creates script with background and focus groups only. Each group contains up to 6 objects: own structure, own global features, own local features, other structures (combined), other global features, other local features (all transparent for context).

Parameters

pdb_infoDict[str, Dict[str, str]]

Structure info: {name: {“path”: pdb_path, “color”: hex_color}}

top_features_globalList[Dict[str, Any]]

Global top features (averaged across all clusters)

feature_colors_globalDict[str, str]

Mapping from global feature_name to HEX color

top_features_localDict[str, List[Dict[str, Any]]]

Local top features per structure {struct_name: features}

feature_colors_localDict[str, Dict[str, str]]

Mapping from struct_name to feature colors {struct_name: {feat_name: color}}

feature_own_colorbool, default=True

If True, features use their own color from feature_colors. If False, features use the color of their structure.

use_puttybool, default=True

If True, use putty cartoon with beta-factor thickness. If False, use normal cartoon with uniform thickness.

Returns

str

Complete PyMOL script as string

Examples

>>> # With global and local features
>>> script = PyMolScriptGenerator.generate_script(
...     pdb_info, global_features, global_colors,
...     local_features, local_colors, use_putty=True
... )
>>> # Only global features (empty dict for local)
>>> script = PyMolScriptGenerator.generate_script(
...     pdb_info, global_features, global_colors,
...     {}, {}, use_putty=True
... )

Notes

  • Only focus groups in script

  • First group enabled, rest disabled

  • Each group: up to 6 objects (struct, global/local features x own/other)

  • Global and local features independently toggleable

  • Putty cartoons: thickness from beta-factor (if use_putty=True)

  • Normal cartoons: uniform thickness (if use_putty=False)

  • Color gradient: base_color → white