FetchLocal
Jump to navigation
Jump to search
Overview
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).
Note
The script only copes with .pdb and .pdb1 (or .pdb2, .pdb3, ...) file types.
Syntax
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
else:
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())
else:
localfn = None
else:
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)
else:
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.fetch(c,name,state,finish,discrete,multiplex,zoom,type,path,file,quiet)
else:
cmd.fetch(code,name,state,finish,discrete,multiplex,zoom,type,path,file,quiet)
cmd.extend('fetchlocal', fetchlocal)