Difference between revisions of "Plugindirectory"

From PyMOLWiki
Jump to: navigation, search
(Example of use)
(Example of use)
Line 68: Line 68:
== Example of use ==
== Example of use ==
[http://www.pymolwiki.org/index.php/Git_install#Adding_Pymol-script-repo_to_PyMOL_search_path If you have '''Pymol-script-repo''' added to your path, you don't have to do anything]
[http://www.pymolwiki.org/index.php/Git_install#Adding_Pymol-script-repo_to_PyMOL_search_path If you have '''Pymol-script-repo''' added to your path, you don't have to do anything.]
Write in PyMOL
Write in PyMOL

Revision as of 11:05, 3 December 2011

This page describes how to set up a personal plugin directory. It supports single python files as well as directories which contain a __init__.py file.

1) Create a directory $HOME/.pymol/pymolplugins, this will be your personal plugin directory. Copy plugins here instead of using the "Plugin > Manage Plugins > Install..." menu.

2) Create a file $HOME/.pymol/pymolplugins/__init__.py with the folling content:

PyMOL personal plugin directory
Recommended location of this file: ~/.pymol/pymolplugins/__init__.py

import os, sys, traceback

# import pymolplugins (allow different name)
pymolplugins = sys.modules[__name__]

import pmg_tk.PMGApp
x__initializePlugins = pmg_tk.PMGApp.initializePlugins

def initializePlugins(self):
    Overloaded version of pmg_tk.PMGApp.initializePlugins
    See pmg_tk/PMGApp.py
    # load global plugins

    # load user plugins
    modules = set()
    for path in pymolplugins.__path__:
        for filename in os.listdir(path):
            name, _, ext = filename.partition('.')
            if ext not in ['py', 'pyc', 'pyo']:
                if os.path.isdir(os.path.join(path, filename)):
            elif name != '__init__':
    for name in modules:
        mod_name = pymolplugins.__name__ + '.' + name
            __import__(mod_name, level=0)
            mod = sys.modules[mod_name]
            if hasattr(mod,'__init_plugin__'):
            elif hasattr(mod,'__init__'):
            print "Exception in plugin '%s' -- Traceback follows..."%name
            print "Error: unable to initialize plugin '%s'."%name

# overload method
pmg_tk.PMGApp.initializePlugins = initializePlugins

3) We need to import pymolplugins before the GUI launches, so insert into your $HOME/.pymolrc file:

import sys, os
import pymolplugins
python end

This plugin is being used in the Pymol-script-repo project

Example of use

If you have Pymol-script-repo added to your path, you don't have to do anything.

Write in PyMOL

import plugins

Python Code

This code has been put under version control. In the project, Pymol-script-repo.

For a color coded view: