Skip to content

Plugin Python Console

Hiromichi Yokoyama edited this page Sep 24, 2026 · 3 revisions

Plugin: Python Console

Python Console embeds an interactive Python REPL directly within MoleditPy, providing live script execution, inspection of runtime objects, molecule manipulation via RDKit, and direct access to the PluginContext API.

Repository Bundled in moleditpy-plugins (plugins/Python_Console)
Author HiroYokoyama
Supported OS Windows, macOS, Linux, WSL
Supported Python >=3.9, <3.15
Menu location Plugin ▸ Python Console (or launchable via Plugin Manager)
Extra dependencies None (uses RDKit, PyQt6 from MoleditPy)

See Official Plugins for the full catalogue.


1. Interactive Environment & Pre-bound Variables

When opened, the interactive console injects convenient handles into the local namespace:

Variable Type Description
mol rdkit.Chem.Mol Current active molecule in MoleditPy (refreshed before every command execution)
context PluginContext Official MoleditPy plugin API handle (recommended for stable access)
mw MainWindow The host application's top-level main window
Chem module Direct reference to rdkit.Chem
help GUIHelp Non-blocking GUI-safe help utility

2. Key Capabilities & Scripting Examples

Inspecting and Querying

# Atom count and properties
print("Atom count:", mol.GetNumAtoms())
for atom in mol.GetAtoms():
    print(f"Atom {atom.GetIdx()}: {atom.GetSymbol()}, charge={atom.GetFormalCharge()}")

# Show a transient status message in MoleditPy's bottom bar
context.show_status_message("Hello from embedded Python Console!", 4000)

Mutating and Redrawing the 3D Structure

from rdkit.Chem import AllChem

# Run an in-memory MMFF optimization and redraw 3D viewport
AllChem.MMFFOptimizeMolecule(mol)
context.draw_molecule_3d(mol)

# Or construct an entirely new molecule from SMILES
new_mol = Chem.MolFromSmiles("c1ccccc1CC(=O)O")
AllChem.EmbedMolecule(new_mol)
context.current_molecule = new_mol  # Automatically updates 2D and 3D views

3. Console Controls

  • Enter: Execute the current single- or multi-line statement.
  • Shift+Enter: Insert a line break to write indented code blocks, functions, or loops.
  • Up / Down Arrows: Navigate command history.
  • Syntax Highlighting: Built-in real-time color highlighting for Python keywords, strings, comments, and numbers.

4. See also


This page documents Python Console v2026.09.24, and was last updated on 2026-09-24. See REGISTRY/plugins.json for the current version.

Clone this wiki locally