Plugindirectory: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
No edit summary
Line 1: Line 1:
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.
== Introduction ==


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.
This page describes how to set up a personal plugin directory, that will automatically install plugins herein.  
It supports single python files as well as directories which contain a __init__.py file.


2) Create a file '''$HOME/.pymol/pymolplugins/__init__.py''' with the folling content:
This plugin is being used in the Pymol-script-repo project [http://www.pymolwiki.org/index.php/Git_intro Pymol-script-repo].


<source lang="python">
== Adding Pymol-script-repo to PyMOL search path ==
'''
You should have the "Pymol-script-repo" directory  or another directory with your plugins to the PyMOL search path.
PyMOL personal plugin directory
We need to import and also import folder '''plugins''' before the GUI launches. So insert into your [[pymolrc|$HOME/.pymolrc]] file:
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
    x__initializePlugins(self)
    # 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)):
                    modules.add(filename)
            elif name != '__init__':
                modules.add(name)
    for name in modules:
        mod_name = pymolplugins.__name__ + '.' + name
        try:
            __import__(mod_name, level=0)
            mod = sys.modules[mod_name]
            if hasattr(mod,'__init_plugin__'):
                mod.__init_plugin__(self)
            elif hasattr(mod,'__init__'):
                mod.__init__(self)
        except:
            print "Exception in plugin '%s' -- Traceback follows..."%name
            traceback.print_exc()
            print "Error: unable to initialize plugin '%s'."%name
# overload method
pmg_tk.PMGApp.initializePlugins = initializePlugins
</source>
3) We need to import '''pymolplugins''' before the GUI launches, so insert into your [[pymolrc|$HOME/.pymolrc]] file:
<source lang="python">
python
import sys, os
sys.path.append(os.path.expanduser('~/.pymol'))
import pymolplugins
python end
</source>
= This plugin is being used in the Pymol-script-repo project =
== Adding Pymol-script-repo to PyMOL search path ==
You should have the "Pymol-script-repo" directory to the PyMOL search path, and also import folder "plugins" before use
=== For windows users ===
=== For windows users ===
# Open notepad
# Open notepad

Revision as of 11:15, 3 December 2011

Introduction

This page describes how to set up a personal plugin directory, that will automatically install plugins herein. It supports single python files as well as directories which contain a __init__.py file.

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

Adding Pymol-script-repo to PyMOL search path

You should have the "Pymol-script-repo" directory or another directory with your plugins to the PyMOL search path. We need to import and also import folder plugins before the GUI launches. So insert into your $HOME/.pymolrc file:

For windows users

  1. Open notepad
  2. Write (Remember forward slashes)
import sys
sys.path.append('C:/Users/YOURNAME/Documents/Pymol-script-repo')
import plugins

Save under: C:/Users/YOURNAME/pymolrc.pym (Set: "Save as type" to "All files")

For Ubuntu/Mint users

gedit ~/.pymolrc

Write

import sys
sys.path.append('/home/YOURNAME/Software/pymol/Pymol-script-repo')
import plugins

Save and exit

Python Code

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

For a color coded view:

https://github.com/Pymol-Scripts/Pymol-script-repo/blob/master/__init__.py