From PyMOLWiki
Revision as of 10:19, 21 September 2012 by Hongbo zhu (talk | contribs) (The Code: load(object=name))
Jump to: navigation, search


Try fetching local copy of PDB files before going on internet to fetch a remote copy.

Sometimes you have a local copy of the PDB structure files, or biological unit files. They are, however, usually organized into sub-directories (for a good reason). Setting Fetch_Path to the top directory will not make PyMOL to use local files before go on internet to fetch a remote copy. This script extends the functionality of the PyMOL command Fetch by searching local sub-directories for target files first.

The search order of the script: 1. local copy of PDB; 2. Fetch_Path; 3. remote repository (Fetch_Host).


The script only copes with .pdb and .pdb1 (or .pdb2, .pdb3, ...) file types.


See Fetch

The Code

""" 2012_09_18, Hongbo Zhu <hongbo.zhu.cn gmail>
    DESCRIPTION: Look for pdb* on local disk before fetching remotely.
import os
import cmd

# user configuration
localpdbdir = '/your/dir/to/PDB/divided'
localbudir  = '/your/dir/to/PDB_BU/divided' # set to '' (empty string) if N/A

def fetchlocal(code, name='', state=0, finish=1, discrete=-1,
               multiplex=-2, zoom=-1, type='pdb', async=-1, path=None,
               file=None, quiet=1):  
    """ Default parameters are the same as in function definition for fetch() 
        in file ./modules/pymol/importing.py
    if type.startswith('pdb'): # pdb files, or biological unit files .pdb1 .pdb2 etc.
        if type == 'pdb': # pdb files
            localdir = localpdbdir
            localdir = localbudir
        for c in string.split(str(code)):
            subdir = c.lower()[1:3]
            if type == 'pdb': 
                if os.path.isfile('%s/%s/pdb%s.ent.gz' % (localdir,subdir,c.lower())):
                    localfn = '%s/%s/pdb%s.ent.gz' % (localdir,subdir,c.lower())
                elif os.path.isfile('%s/%s/pdb%s.ent' % (localdir,subdir,c.lower())):
                    localfn = '%s/%s/pdb%s.ent.gz' % (localdir,subdir,c.lower())
                    localfn = None
                if os.path.isfile('%s/%s/%s.%s.gz' % (localdir,subdir,c.lower(),type)):
                    localfn =  '%s/%s/%s.%s.gz' % (localdir,subdir,c.lower(),type)
                elif os.path.isfile('%s/%s/%s.%s' % (localdir,subdir,c.lower(),type)):
                    localfn = '%s/%s/%s.%s' % (localdir,subdir,c.lower(),type)
                    localfn = None

            if localfn is not None:
                print 'Load local file instead of fetching from internet: ', localfn 
                cmd.load(filename=localfn, object=name, format='pdb', state=state, 
                         finish=finish, discrete=discrete, multiplex=multiplex, 
                         zoom=zoom, quiet=quiet)
            else:  # otherwise hand it over to pymol fetch function

cmd.extend('fetchlocal', fetchlocal)

See Also

Fetch, Fetch_Path, Fetch_Host