This is a read-only mirror of pymolwiki.org

User:Speleo3/VMD plugins

From PyMOL Wiki
Jump to navigation Jump to search

Patching the PyMOL source with the latest VMD plugins.

Procedure

1) Download VMD to /tmp.

2) Save the #Required Files to /tmp

3) Run in a shell:

cd /tmp
tar xzf vmd-1.9.1.src.tar.gz plugins
svn co https://pymol.svn.sourceforge.net/svnroot/pymol/trunk/pymol
cd /tmp/pymol
python /tmp/vmd_plugins_update.py /tmp/plugins
patch -p0 -i /tmp/setup.patch

4) Continue with Linux_Install#Compile_and_install

Required Files

setup.patch

--- setup.py	(revision 3998)
+++ setup.py	(working copy)
@@ -265,6 +265,16 @@
                       "-g" ]
     ext_link_args = []
 
+with_vmd_plugins = 1
+if with_vmd_plugins:
+    try:
+        from setup_vmd_plugins import vmd_plugins_dirs, vmd_plugins_files
+    except ImportError:
+        raise SystemExit('please run vmd_plugins_update.py first')
+    inc_dirs += vmd_plugins_dirs
+    def_macros += [ ("_PYMOL_VMD_PLUGINS", None) ]
+else:
+    vmd_plugins_files = []
 
 distribution = setup ( # Distribution meta-data
     name      = "pymol",
@@ -420,6 +430,7 @@
                 "layer5/TestPyMOL.c",
                 "layer5/main.c"
                 # VMD plugin support
+                ] + vmd_plugins_files + [
                 # switch the 0 to 1 to activate the additional source code
                 ] + 0 * [
                 # (incomplete support -- only TRJ, TRR, XTC, DCD so far...)

vmd_plugins_update.py

'''
Convert VMD plugin source files for PyMOL.
(Modified version of "contrib/uiuc/plugins/molfile_plugin/update.py")

Please download and unpack the VMD source code from:

  http://www.ks.uiuc.edu/Development/Download/download.cgi?PackageName=VMD

Then run this script from the PyMOL source root and point it to the "plugins"
directory from the VMD source tree. Example:

  cd /tmp
  tar xzf vmd-1.9.1.src.tar.gz
  cd /tmp/pymol
  python vmd_plugins_update.py /tmp/plugins

You can enable/disable particular plugins from the "src_list" variable in
this file.
'''

import os
import sys
from glob import glob
from distutils import file_util, dir_util

src_list = [
#    'avsplugin',
#    'babelplugin', # requires openbabel
#    'basissetplugin', #
#    'bgfplugin',
#    'binposplugin',
#    'biomoccaplugin',
#    'brixplugin',
#    'carplugin',
#    'ccp4plugin',
#    'cdfplugin', # requires netcdf
#    'corplugin',
#    'cpmdlogplugin', #
#    'cpmdplugin',
    'crdplugin',
#    'cubeplugin',
    'dcdplugin',
#    'dlpolyplugin',
#    'dsn6plugin',
#    'dtrplugin', #
#    'dxplugin',
#    'edmplugin',
#    'fs4plugin',
#    'gamessplugin',
#    'gaussianplugin', #
#    'graspplugin',
#    'grdplugin',
#    'gridplugin',
    'gromacsplugin',
#    'hoomdplugin', # requires expat
#    'jsplugin', #
#    'lammpsplugin', # requires gz
#    'maeffplugin', #
#    'mapplugin',
#    'mdfplugin',
#    'mmcif', #
#    'mol2plugin',
#    'moldenplugin',
#    'mrcplugin', # gone?
#    'msmsplugin',
#    'namdbinplugin',
#    'netcdfplugin', # requires netcdf
#    'parm7plugin',
#    'parmplugin',
#    'pbeqplugin', #
#    'pdbplugin',
#    'phiplugin',
#    'pltplugin',
#    'pqrplugin',
#    'psfplugin',
#    'raster3dplugin',
#    'rst7plugin',
#    'situsplugin',
#    'spiderplugin',
#    'stlplugin',
#    'tinkerplugin',
#    'uhbdplugin',
#    'vaspchgcarplugin', #
#    'vaspoutcarplugin', #
#    'vaspparchgplugin', #
#    'vaspposcarplugin', #
#    'vaspxdatcarplugin', #
#    'vaspxmlplugin', #
#    'vtfplugin', #
#    'webpdbplugin', # tcl dependent
#    'xbgfplugin',
#    'xsfplugin',
#    'xyzplugin',
]

# check command line argument
if len(sys.argv) < 2 or sys.argv[1] in ('-h', '--help'):
    print __doc__.strip()
    sys.exit(1)

# paths
vmd_plugins_path = sys.argv[1]
molfile_src_path = os.path.join(vmd_plugins_path, 'molfile_plugin', 'src')
molfile_dst_path = os.path.join('contrib', 'uiuc_molfile_plugin')

# copy required files
dir_util.mkpath(molfile_dst_path)
for f in [os.path.join(molfile_src_path, 'hash.c')] + \
        glob(os.path.join(molfile_src_path, '*.h*')) + \
        glob(os.path.join(vmd_plugins_path, 'include', '*.h')):
    file_util.copy_file(f, molfile_dst_path)

# prepare setup_vmd_plugins.py
setup_out = open('setup_vmd_plugins.py', 'w')
setup_out.write('vmd_plugins_dirs = [ %s ]\n' % repr(molfile_dst_path))
setup_out.write('vmd_plugins_files = [\n')
for f in ['PlugIOManagerInit.c', 'hash.c']:
    out_file = os.path.join(molfile_dst_path, f)
    setup_out.write(repr(out_file) + ',\n')

# patch and copy desired plugin source files
for pref in src_list:
    try:
        in_file = glob(molfile_src_path + "/" + pref + ".[cC]*")[0]
    except KeyError:
        print 'MISSING:', pref
        continue

    out_file = os.path.join(molfile_dst_path, pref + '.c')
    content = open(in_file).read()
    content.replace('(vmdplugin_t *)', '(vmdplugin_t *)(void*)')

    # c++
    if in_file[-2:] == '.C' or in_file[-4:] == '.cxx':
        out_file += 'pp'
        content = content.replace('VMDPLUGIN_API', 'VMDPLUGIN_EXTERN')

    print in_file, '->', out_file
    setup_out.write(repr(out_file) + ',\n')

    with open(out_file, 'w') as g:
        g.write("/* MACHINE GENERATED FILE, DO NOT EDIT! */\n\n")
        g.write("#define VMDPLUGIN molfile_%s\n" % pref)
        g.write("#define STATIC_PLUGIN 1\n\n")    
        g.write(content)

setup_out.write(']\n')
setup_out.close()

# PlugIO init file
with open(os.path.join(molfile_dst_path, 'PlugIOManagerInit.c'), 'w') as g:
    g.write('''
/* MACHINE GENERATED FILE, DO NOT EDIT! */
#include "vmdplugin.h"
typedef struct _PyMOLGlobals PyMOLGlobals;
int PlugIOManagerRegister(PyMOLGlobals *G, vmdplugin_t *);
''')

    # prototypes
    for pref in src_list:
        g.write('''
int molfile_%s_init(void);
int molfile_%s_register(void *, vmdplugin_register_cb);
int molfile_%s_fini(void);
''' % (pref, pref, pref))

    g.write('''
int PlugIOManagerInitAll(PyMOLGlobals *G) {
   int ok = 1 \\
''')

    # init
    for pref in src_list:
        g.write('''
      && (molfile_%s_init() == VMDPLUGIN_SUCCESS)''' % pref)

    # register
    for pref in src_list:
        g.write('''
      && (molfile_%s_register(G, (vmdplugin_register_cb)PlugIOManagerRegister) == VMDPLUGIN_SUCCESS)''' % pref)

    g.write(''';

   return ok;
}

int PlugIOManagerFreeAll(void) {
   int ok = 1 \\
''')

    # fini
    for pref in src_list:
        g.write('''
      && (molfile_%s_fini() == VMDPLUGIN_SUCCESS)''' % pref)

    g.write(''';

   return ok;
}
''')