Skip to main content

PyMOL integration for Claude Code - control molecular visualization via natural language

Project description

ai-mol: Control PyMOL with Claude Code

Control PyMOL through natural language using Claude Code. This integration enables conversational structural biology, molecular visualization, and analysis.

https://github.com/user-attachments/assets/687f43dc-d45e-477e-ac2b-7438e175cb36

Features

  • Natural language control: Tell Claude what you want to visualize and it executes PyMOL commands
  • Direct socket communication: Claude Code talks directly to PyMOL (no intermediary server)
  • Full PyMOL access: Manipulate representations, colors, views, perform measurements, alignments, and more
  • Skill-based workflows: Built-in skills for common tasks like binding site visualization and publication figures

Architecture

Claude Code → TCP Socket (port 9880) → PyMOL Plugin → cmd.* execution

Quick Start

Prerequisites

  • PyMOL installed on your system
  • Claude Code CLI installed
  • Python 3.10+

Installation

  1. Clone the repository:

    git clone https://github.com/ANaka/ai-mol
    cd ai-mol
    
  2. Set up the PyMOL plugin:

    Add this line to your ~/.pymolrc (create it if it doesn't exist):

    run /path/to/ai-mol/claude_socket_plugin.py
    

    Replace /path/to/ai-mol with the actual path where you cloned the repository.

  3. Start using it:

    Open Claude Code in the ai-mol directory and say:

    "Open PyMOL and load structure 1UBQ"

    Claude will launch PyMOL (with the socket listener active) and load the structure.

Usage

Starting a Session

Simply ask Claude to open PyMOL or load a structure:

  • "Open PyMOL"
  • "Load PDB 4HHB and show as cartoon"
  • "Fetch 1UBQ from the PDB"

Claude will launch PyMOL if it's not already running.

Example Commands

  • "Color the protein by secondary structure"
  • "Show the binding site residues within 5Å of the ligand as sticks"
  • "Align these two structures and calculate RMSD"
  • "Create a publication-quality figure with ray tracing"
  • "Make a 360° rotation movie"

PyMOL Console Commands

Check or control the socket listener from PyMOL's command line:

claude_status   # Check if listener is running
claude_stop     # Stop the listener
claude_start    # Start the listener

Available Skills

Claude Code has built-in skills for common workflows:

  • pymol-fundamentals - Basic visualization, selections, coloring
  • protein-structure-basics - Secondary structure, B-factor, representations
  • binding-site-visualization - Protein-ligand interactions
  • structure-alignment-analysis - Comparing and aligning structures
  • antibody-visualization - CDR loops, epitopes, Fab structures
  • publication-figures - High-quality figure export
  • movie-creation - Animations and rotations

Troubleshooting

Connection Issues

  • "Could not connect to PyMOL": Make sure PyMOL is running and the plugin is loaded
  • Check listener status: Run claude_status in PyMOL's command line
  • Restart listener: Run claude_stop then claude_start in PyMOL

Plugin Not Loading

  • Verify the path in your ~/.pymolrc is correct
  • Check PyMOL's output for any error messages on startup
  • Try running run /path/to/claude_socket_plugin.py manually in PyMOL

First-Time Setup Help

Run the /pymol-setup skill in Claude Code for guided setup assistance.

Configuration

The default socket port is 9880. Both the plugin and Claude Code connection module use this port.

Key files:

  • claude_socket_plugin.py - PyMOL plugin (headless, auto-loads via pymolrc)
  • pymol_connection.py - Python module for socket communication
  • .claude/skills/ - Claude Code skills for PyMOL workflows

Limitations

  • PyMOL and Claude Code must run on the same machine (localhost connection)
  • One active connection at a time
  • Some complex multi-step operations may need guidance

Contributing

Contributions welcome! This project aims to build comprehensive skills for Claude-PyMOL interaction. If you discover useful patterns or workflows, consider adding them as skills.

License

MIT License - see LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

claudemol-0.1.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

claudemol-0.1.0-py3-none-any.whl (14.9 kB view details)

Uploaded Python 3

File details

Details for the file claudemol-0.1.0.tar.gz.

File metadata

  • Download URL: claudemol-0.1.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for claudemol-0.1.0.tar.gz
Algorithm Hash digest
SHA256 264658fb905de5c03981954288f61752674666446e784b9dec5c8ae969a1887e
MD5 e436488dcc39343db6eae9ef0fb7132e
BLAKE2b-256 ab499e7f0dadf9592672a1be2cfcc1d7d6f3e73221b46d4f7188065588f9a2e9

See more details on using hashes here.

File details

Details for the file claudemol-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: claudemol-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for claudemol-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9778a555db2413751a3d93b977b6d9455a142537669b40ad92a607839ddda9f
MD5 bbf68dbe6bdfca9889644e5f24e3711f
BLAKE2b-256 25ebf19c62d588257a297da68ef52a1eaaba38876ed8309fe813552e2fff0706

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page