This is a read-only mirror of pymolwiki.org
Difference between revisions of "User:Speleo3"
Jump to navigation
Jump to search
(Scripts Pastebin) |
(→Scripts Pastebin: cbm, dev2b, select_extendbyss) |
||
Line 70: | Line 70: | ||
cmd.sort() | cmd.sort() | ||
cmd.extend('remove_alt', remove_alt) | cmd.extend('remove_alt', remove_alt) | ||
+ | </source> | ||
+ | |||
+ | <source lang="python"> | ||
+ | def cbm(selection='(all)'): | ||
+ | ''' | ||
+ | DESCRIPTION | ||
+ | |||
+ | Color by molecule | ||
+ | ''' | ||
+ | col = 2 | ||
+ | for model in cmd.get_object_list(selection): | ||
+ | cmd.color(col, '%s and (%s)' % (model, selection)) | ||
+ | col += 1 | ||
+ | cmd.extend('cbm', cbm) | ||
+ | </source> | ||
+ | |||
+ | <source lang="python"> | ||
+ | def dev2b(selection='name CA'): | ||
+ | ''' | ||
+ | DESCRIPTION | ||
+ | |||
+ | Determine the RMSD per residue for a multi-state object and assign b-factor | ||
+ | ''' | ||
+ | import numpy | ||
+ | stored.x = dict() | ||
+ | stored.b = dict() | ||
+ | for state in range(1, cmd.count_states()+1): | ||
+ | cmd.iterate_state(state, selection, 'stored.x.setdefault((model,segi,chain,resi,name), []).append([x,y,z])') | ||
+ | for key, coord_list in stored.x.iteritems(): | ||
+ | b_sq = numpy.array(coord_list).var(0).mean() # var over states, mean over x,y,z | ||
+ | stored.b[key] = numpy.sqrt(b_sq) * 10.0 | ||
+ | cmd.alter(selection, 'b = stored.b[model,segi,chain,resi,name]') | ||
+ | cmd.extend('dev2b', dev2b) | ||
+ | </source> | ||
+ | |||
+ | <source lang="python"> | ||
+ | def select_extendbyss(selection, name=None, quiet=0): | ||
+ | ''' | ||
+ | DESCRIPTION | ||
+ | |||
+ | Extend selection by connected secondary structure elements. | ||
+ | |||
+ | ARGUMENTS | ||
+ | |||
+ | selection = string: selection-expression | ||
+ | |||
+ | name = string: create a named atom selection if not None {default: None} | ||
+ | ''' | ||
+ | def in_intervals(i, intervals): | ||
+ | for interval in intervals: | ||
+ | if interval[0] <= i and i <= interval[1]: | ||
+ | return True | ||
+ | return False | ||
+ | quiet = int(quiet) | ||
+ | stored.x = set() | ||
+ | # only iterate over CAs since for example PyMOL's dss command just | ||
+ | # assignes ss to CAs. | ||
+ | cmd.iterate('bycalpha (%s)' % (selection), | ||
+ | 'stored.x.add((model,segi,chain,resv,ss))') | ||
+ | elements = dict() | ||
+ | for model,segi,chain,resv,ss in stored.x: | ||
+ | key = (model,segi,chain,ss) | ||
+ | elements.setdefault(key, []) | ||
+ | if in_intervals(resv, elements[key]): | ||
+ | continue | ||
+ | stored.b = set() | ||
+ | cmd.iterate('/%s/%s/%s//CA and ss "%s"' % key, 'stored.b.add(resv)') | ||
+ | resv_min = resv | ||
+ | resv_max = resv | ||
+ | while (resv_min - 1) in stored.b: | ||
+ | resv_min -= 1 | ||
+ | while (resv_max + 1) in stored.b: | ||
+ | resv_max += 1 | ||
+ | elements[key].append((resv_min, resv_max)) | ||
+ | sele_list = [] | ||
+ | ss_names = {'S': 'Strand', 'H': 'Helix', '': 'Loop'} | ||
+ | for key in elements: | ||
+ | model,segi,chain,ss = key | ||
+ | for resv_min,resv_max in elements[key]: | ||
+ | sele = '/%s/%s/%s/%d-%d' % (model, segi, chain, resv_min, resv_max) | ||
+ | sele_list.append(sele) | ||
+ | if not quiet: | ||
+ | print ss_names.get(ss, ss), sele | ||
+ | sele = ' or '.join(sele_list) | ||
+ | if name is not None: | ||
+ | cmd.select(name, sele) | ||
+ | if not quiet: | ||
+ | print 'Selection:', sele | ||
+ | return sele | ||
+ | cmd.extend('select_extendbyss', select_extendbyss) | ||
</source> | </source> |
Revision as of 09:15, 25 January 2011
My name is Thomas Holder and I am a bioinformatician at the MPI for Developmental Biology in Tübingen, Germany.
Contact
- speleo3/users.sourceforge.net
- thomas.holder/tuebingen.mpg.de
Scripts written by me
Scripts Pastebin
Some random scripts with no dedicated PyMOLWiki page.
def extra_fit(selection='(all)', reference=None, method=cmd.align):
'''
DESCRIPTION
Like "intra_fit", but for multiple objects instead of
multiple states.
'''
models = cmd.get_object_list(selection)
if reference is None:
reference = models[0]
models = models[1:]
elif reference in models:
models.remove(reference)
if cmd.is_string(method):
method = eval(method)
for model in models:
print model, method(model, reference)
cmd.extend('extra_fit', extra_fit)
def mse2met(selection='all', quiet=1):
'''
DESCRIPTION
Mutate selenomethionine to methionine
'''
quiet = int(quiet)
x = cmd.alter('(%s) and MSE/SE' % selection, 'name="SD";elem="S"')
cmd.alter('(%s) and MSE/' % selection, 'resn="MET";type="ATOM"')
if not quiet:
print 'Altered %d MSE residues to MET' % (x)
cmd.sort()
cmd.extend('mse2met', mse2met)
def remove_alt(selection='all', keep='A', quiet=1):
'''
DESCRIPTION
Remove alternative location atoms.
ARGUMENTS
selection = string: atom selection
keep = string: AltLoc to keep {default: A}
'''
cmd.remove('(%s) and not alt +%s' % (selection, keep), quiet=int(quiet))
cmd.alter(selection, 'alt=""')
cmd.sort()
cmd.extend('remove_alt', remove_alt)
def cbm(selection='(all)'):
'''
DESCRIPTION
Color by molecule
'''
col = 2
for model in cmd.get_object_list(selection):
cmd.color(col, '%s and (%s)' % (model, selection))
col += 1
cmd.extend('cbm', cbm)
def dev2b(selection='name CA'):
'''
DESCRIPTION
Determine the RMSD per residue for a multi-state object and assign b-factor
'''
import numpy
stored.x = dict()
stored.b = dict()
for state in range(1, cmd.count_states()+1):
cmd.iterate_state(state, selection, 'stored.x.setdefault((model,segi,chain,resi,name), []).append([x,y,z])')
for key, coord_list in stored.x.iteritems():
b_sq = numpy.array(coord_list).var(0).mean() # var over states, mean over x,y,z
stored.b[key] = numpy.sqrt(b_sq) * 10.0
cmd.alter(selection, 'b = stored.b[model,segi,chain,resi,name]')
cmd.extend('dev2b', dev2b)
def select_extendbyss(selection, name=None, quiet=0):
'''
DESCRIPTION
Extend selection by connected secondary structure elements.
ARGUMENTS
selection = string: selection-expression
name = string: create a named atom selection if not None {default: None}
'''
def in_intervals(i, intervals):
for interval in intervals:
if interval[0] <= i and i <= interval[1]:
return True
return False
quiet = int(quiet)
stored.x = set()
# only iterate over CAs since for example PyMOL's dss command just
# assignes ss to CAs.
cmd.iterate('bycalpha (%s)' % (selection),
'stored.x.add((model,segi,chain,resv,ss))')
elements = dict()
for model,segi,chain,resv,ss in stored.x:
key = (model,segi,chain,ss)
elements.setdefault(key, [])
if in_intervals(resv, elements[key]):
continue
stored.b = set()
cmd.iterate('/%s/%s/%s//CA and ss "%s"' % key, 'stored.b.add(resv)')
resv_min = resv
resv_max = resv
while (resv_min - 1) in stored.b:
resv_min -= 1
while (resv_max + 1) in stored.b:
resv_max += 1
elements[key].append((resv_min, resv_max))
sele_list = []
ss_names = {'S': 'Strand', 'H': 'Helix', '': 'Loop'}
for key in elements:
model,segi,chain,ss = key
for resv_min,resv_max in elements[key]:
sele = '/%s/%s/%s/%d-%d' % (model, segi, chain, resv_min, resv_max)
sele_list.append(sele)
if not quiet:
print ss_names.get(ss, ss), sele
sele = ' or '.join(sele_list)
if name is not None:
cmd.select(name, sele)
if not quiet:
print 'Selection:', sele
return sele
cmd.extend('select_extendbyss', select_extendbyss)