def testShortcutTiming(self): names = pymol.setting.get_name_list() colors = [c[0] for c in cmd.get_color_indices(0)] with self.timing(): sc = cmd.Shortcut(names) sc = cmd.Shortcut(cmd.kw_list) sc = cmd.Shortcut(colors)
def names_sc(): import os, pymol.wizard names_glob = [ name[:-3] for p in pymol.wizard.__path__ for name in os.listdir(p) if name.endswith('.py') ] return cmd.Shortcut(names_glob + names)
def testShortcutRebuild(self): sc = cmd.Shortcut(words) sc.rebuild(coms) self.assertEqual(None, sc.interpret('f')) self.assertEqual(None, sc.interpret('foo')) self.assertItemsEqual(coms, sc.interpret('c')) self.assertItemsEqual(coms, sc.interpret('com', 1)) self.assertEqual('com', sc.interpret('com')) self.assertEqual('com_xxx', sc.interpret('c_x'))
def load(): """ adds split command to pymol """ cmd.extend('split', split) # tab completion cmd.auto_arg[0]['split'] = [ lambda: cmd.Shortcut(['groups', 'molecules']), 'rule', '' ] cmd.auto_arg[1]['split'] = [cmd.selection_sc, 'selection', '']
def testShortcutMode1(self): # build shortcut sc = cmd.Shortcut(words) # full/prefix hits self.assertEqual('foo', sc.interpret('f', 1)) self.assertItemsEqual(coms, sc.interpret('com', 1)) # add one sc.append('foo_new') self.assertItemsEqual(['foo', 'foo_new'], sc.interpret('foo', 1))
def load(): """ adds cheese command to pymol """ cmd.extend('cheese', cheese) # tab completion cmd.auto_arg[0]['cheese'] = [ lambda: cmd.Shortcut(['set', 'snap', 'traj', 'bullettime']), 'render type', '' ]
def load(): """ adds nice, nicesele and nicecolor commands to pymol """ nice_settings() cmd.extend('nicesele', nicesele) cmd.extend('nicecolor', nicecolor) cmd.extend('nice', nice) # tab completion cmd.auto_arg[0]['nice'] = [ lambda: cmd.Shortcut(['clean', 'rainbow', 'balls']), 'style', '' ] cmd.auto_arg[1]['nice'] = [cmd.selection_sc, 'selection', '']
def pymol_auto_arg_update(): aaindexkey_sc = cmd.Shortcut(_aaindex.keys()) cmd.auto_arg[0].update({ 'aaindex2b': [aaindexkey_sc, 'aaindexkey', ', '], 'pmf': [aaindexkey_sc, 'aaindexkey', ', '], }) cmd.auto_arg[1].update({ 'aaindex2b': [cmd.selection_sc, 'selection', ''], }) cmd.auto_arg[2].update({ 'pmf': [cmd.selection_sc, 'selection', ''], }) cmd.auto_arg[3].update({ 'pmf': [cmd.selection_sc, 'selection', ''], })
def testShortcut(self): # build shortcut sc = cmd.Shortcut(words) # get all keywords self.assertItemsEqual(words, sc.interpret('')) # full/prefix hits self.assertEqual('foo', sc.interpret('f')) self.assertEqual('foo', sc.interpret('fo')) self.assertEqual('foo', sc.interpret('foo')) self.assertItemsEqual(ba_s, sc.interpret('b')) self.assertItemsEqual(ba_s, sc.interpret('ba')) self.assertEqual('bar', sc.interpret('bar')) self.assertItemsEqual(coms, sc.interpret('c')) self.assertItemsEqual(coms, sc.interpret('co')) self.assertEqual('com', sc.interpret('com')) # add one sc.append('foo_new') self.assertItemsEqual(['foo', 'foo_new'], sc.interpret('f')) self.assertEqual('foo', sc.interpret('foo')) self.assertEqual('foo_new', sc.interpret('foo_')) self.assertEqual(False, sc.has_key('')) # abbreviations self.assertEqual('foo_new', sc.interpret('f_')) self.assertEqual('foo_new', sc.interpret('f_new')) self.assertEqual('foo_new', sc.interpret('fo_')) self.assertEqual('com_xxx', sc.interpret('c_x')) self.assertEqual('com_xxx', sc.interpret('c_xxx')) self.assertEqual('com_xxx', sc.interpret('co_x')) # missing key self.assertEqual(None, sc.interpret('missing_key')) # auto error self.assertEqual(None, sc.auto_err('')) self.assertEqual(None, sc.auto_err('missing_key')) self.assertItemsEqual(coms, sc.auto_err('co')) self.assertEqual('com', sc.auto_err('com'))
# # Obscure an object to protect property rights. # from __future__ import print_function from pymol import cmd hiding_sc = cmd.Shortcut(['low', 'medium', 'high']) @cmd.extendaa(cmd.auto_arg[1]['select'], [hiding_sc, 'hiding level', ', ']) def obscure(selection, hiding="medium", keep=0, state=-1, name_map='', name_iso='', quiet=0, _self=cmd): """ DESCRIPTION Given an object or selection, usually a small molecule, obscure it to protect its exact identity. USAGE obscure selection [, hiding [, keep ]] ARGUMENTS selection = str: atom selection to hide hiding = low|medium|high: level to which PyMOL obscures the object {default: medium} keep = 0/1: by default, PyMOL removes the obscured atoms from your file, this flag will keep the atoms in the file. Be careful!
for state in states: cmd.save(tmpfilepdb, selection, state) subprocess.check_call(args) cmd.load(tmpfiler3d, name, max(1, state), zoom=0) except subprocess.CalledProcessError: raise CmdException('"' + exe + '" failed') except OSError: raise CmdException('Cannot execute exe="' + exe + '"') finally: try: os.remove(tmpfilepdb) os.remove(tmpfiler3d) except OSError: pass cmd.extend('dssr_block', dssr_block) # tab-completion of arguments cmd.auto_arg[0].update({ 'dssr_block': cmd.auto_arg[0]['zoom'], }) cmd.auto_arg[2].update({ 'dssr_block': [ cmd.Shortcut(['face', 'edge', 'wc', 'equal', 'minor', 'gray']), 'block_file', '' ], }) # vi: expandtab:smarttab
if not preserve: shutil.rmtree(tmpdir) elif not quiet: print(' Notice: not deleting', tmpdir) if 'join_states' not in cmd.keyword: cmd.extend('join_states', join_states) cmd.extend('sidechaincenters', sidechaincenters) cmd.extend('ramp_levels', ramp_levels) cmd.extend('pdb2pqr', pdb2pqr) cmd.extend('corina', corina) cmd.extend('prepwizard', prepwizard) cmd.extend('fiber', fiber) cmd.auto_arg[0].update([ ('ramp_levels', [lambda: cmd.Shortcut(cmd.get_names_of_type('object:')), 'ramp object', '']), ]) cmd.auto_arg[1].update([ ('join_states' , cmd.auto_arg[0]['zoom']), ('sidechaincenters' , cmd.auto_arg[0]['zoom']), ('pdb2pqr' , cmd.auto_arg[0]['zoom']), ('corina' , cmd.auto_arg[0]['zoom']), ('prepwizard' , cmd.auto_arg[0]['zoom']), ]) cmd.auto_arg[2].update([ ('sidechaincenters', [cmd.Shortcut(sidechaincentermethods), 'method', '']), ('pdb2pqr', [cmd.Shortcut(['AMBER', 'CHARMM', 'PARSE', 'TYL06']), 'forcefield', '']), ]) # vi: ts=4:sw=4:smarttab:expandtab
CTERM_tuple: [CTERM_bonds_all, CTERM_bonds_double], ARG_tuple: [ARG_bonds_all, ARG_bonds_double] } if bonds != 2: lines = 4 print "Formating as delocalized bonds" else: lines = 1 print "Formating as double bonds" # for all tuples (i.e format_dict.keys()) for p in format_dict.keys(): # go through list except ID at pos 1 for q in p[1:]: # format bonds for r in format_dict[p][0]: cmd.unbond('%s and name %s' % (q, r[0]), '%s and name %s' % (q, r[1])) cmd.bond('%s and name %s' % (q, r[0]), '%s and name %s' % (q, r[1]), lines) if lines == 1: # add double bonds for r in format_dict[p][1]: cmd.unbond('%s and name %s' % (q, r[0]), '%s and name %s' % (q, r[1])) cmd.bond('%s and name %s' % (q, r[0]), '%s and name %s' % (q, r[1]), 2) return bonds cmd.extend("format_bonds", format_bonds) cmd.auto_arg[0]['format_bonds'] = [lambda: cmd.Shortcut(['all', 'resn PHE+TYR+PTR+NIY+PNIY+TRP+NIW+HIS', 'resn GLU+ASP', 'resn ARG', 'last all']), 'selection=', ', '] cmd.auto_arg[1]['format_bonds'] = [lambda: cmd.Shortcut(['4', '2', '1']), 'bonds=', ''] ################################################################################
colors = get_color_family(first_color) col_it = itertools.cycle(colors) else: col_it = itertools.count(int(first_color)) segi_colors = dict() def callback(segi): if segi not in segi_colors: segi_colors[segi] = next(col_it) return segi_colors[segi] cmd.alter(selection, 'color = callback(segi)', space=locals()) cmd.rebuild() expression_sc = cmd.Shortcut([ 'count', 'resi', 'b', 'q', 'pc', ]) def spectrumany(expression, color_list, selection='(all)', minimum=None, maximum=None, quiet=1): ''' DESCRIPTION Define a color spectrum with as many color-stops as you like (at least 2). USAGE spectrumany expression, color_list [, selection [, minimum [, maximum ]]] ARGUMENTS
cmd.set("cartoon_oval_length", 0.8, obj) cmd.set("cartoon_oval_width", 0.2, obj) if fancy == "on": cmd.set("cartoon_transparency", 0.5, "invSele") cmd.set("cartoon_highlight_color", invcolor, obj) cmd.set("cartoon_fancy_helices", 1, obj) #Output for screen print("for help type: help bfactorRamp") print("") print("Minimum bfactor: %s | Maximum bfactor: %s" % (range[0], range[1])) print("") print("Following settings were taken:") print("- mol : %s" % (obj)) print("- color1,2,3 : %s, %s, %s" % (color1, color2, color3)) print("- cartoon : %s" % (cartoon)) print("- cartoon_putty : %s" % (cartoon_putty)) print("- invcolor : %s" % (invcolor)) print("- style : %s" % (style)) print("- fancy : %s" % (fancy)) return (color1, color2, color3) cmd.extend("bfactorRamp", bfactorRamp) import glob names_filenames_sc = lambda: cmd.Shortcut(cmd.get_names() + glob.glob('*')) cmd.auto_arg[0]['bfactorRamp'] = [ names_filenames_sc, 'filename or object name', '' ]
EXAMPLES: get_colors # basic colors get colors all # larger range with intermediates ''' import pymol pymol_color_list = [] for tuplepair in pymol.querying.get_color_indices(selection): pymol_color_list.append(tuplepair[0]) pymol_color_list.sort() if not int(quiet): print pymol_color_list return pymol_color_list cmd.extend('get_colors', get_colors) cmd.auto_arg[0]['get_colors'] = [ lambda: cmd.Shortcut(['""', 'all']), 'selection=', ',' ] cmd.auto_arg[1]['get_colors'] = [lambda: cmd.Shortcut(['0']), 'quiet=', ''] #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- #------------------------------------------------------------------------------- def get_random_color(selection='', quiet=1): ''' DESCRIPTION: returns a random color name available in pymol ! Requires get_colors !Indended mostly for use in Python
'Please remove the old pymolplugins module and delete ~/.pymolrc_plugins.py' ) if os.path.exists(PYMOLPLUGINSRC): from pymol import parsing try: parsing.run_file(PYMOLPLUGINSRC, {'__script__': PYMOLPLUGINSRC}, {}) except SyntaxError as e: colorprinting.warning(str(e)) autoload = (pmgapp != -2) for parent in [startup]: modules = findPlugins(parent.__path__) for name, filename in modules.items(): mod_name = parent.__name__ + '.' + name info = PluginInfo(name, filename, mod_name) if autoload and info.autoload: info.load(pmgapp) # pymol commands cmd.extend('plugin_load', plugin_load) cmd.extend('plugin_pref_save', pref_save) # autocompletion cmd.auto_arg[0]['plugin_load'] = [lambda: cmd.Shortcut(plugins), 'plugin', ''] # vi:expandtab:smarttab:sw=4
cmd.delete(mobile_tmp) return angle # methods for auto-completion methods = [ helix_orientation, loop_orientation, cafit_orientation, plane_orientation, ] methods_sc = cmd.Shortcut([func.__name__ for func in methods]) # commands and tab-completion of arguments for func in methods: cmd.extend(func.__name__, func) cmd.auto_arg[0][func.__name__] = cmd.auto_arg[0]['zoom'] for func in [angle_between_helices, angle_between_domains]: cmd.extend(func.__name__, func) cmd.auto_arg[0][func.__name__] = cmd.auto_arg[0]['align'] cmd.auto_arg[1][func.__name__] = cmd.auto_arg[0]['align'] cmd.auto_arg[2].update([ ('angle_between_helices', [methods_sc, 'method', '']), ])
for frame in range(startframe, endframe + 1): # calculate intermediates frac = float(frame - startframe) / (endframe - startframe) endcolor = [a * frac for a in diffcolor] endcolor = map(sum, zip(startcolor, endcolor)) colorname = selection + "_" + str(frame) # define new color cmd.set_color(colorname, endcolor) cmd.mappend(frame, "/cmd.color(%s, %s)" % (repr(colorname), repr(selection))) cmd.extend("movie_color_fade", movie_color_fade) cmd.auto_arg[0]['movie_color_fade'] = [ lambda: cmd.Shortcut(['auto', '1']), 'startframe=', ',' ] cmd.auto_arg[1]['movie_color_fade'] = [ lambda: cmd.Shortcut(['red', 'green', 'blue', 'yellow']), 'startcolor=', ',' ] cmd.auto_arg[2]['movie_color_fade'] = [ lambda: cmd.Shortcut(['auto']), 'endframe=', ',' ] cmd.auto_arg[3]['movie_color_fade'] = [ lambda: cmd.Shortcut(['red', 'green', 'blue', 'yellow']), 'endcolor= ... more see "help movie_color_fade"', ',' ] #cmd.auto_arg[4]['movie_color_fade']=[lambda: cmd.Shortcut(['all']), 'selection=', ''] #------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
def useful_file_sc(): return cmd.Shortcut( glob('**/*.tpr', recursive=True) + glob('**/*.top', recursive=True) + glob('**/*.itp', recursive=True))
except ValueError as e: msg = f"Malformed range {cut_range}" e.message = msg raise e # First align to principal axes princ_align(selection) cachedir = Path.home() / "mjtadema_pymol_cache" if len(cut_range) == 1: # symmetrically cut with thickness t t = cut_range[0] cut_select = f"{selection} and (y > {-t} and y < {t})" cmd.orient(cut_select) cmd.clip('slab', t * 2, cut_select) if view_key is not None: cmd.view(view_key, 'store') elif len(cut_range) == 2: # cut from start to end raise NotImplementedError("Didn't get to asymmetric cuts yet") pass else: # panic raise ValueError("range can be at most 2 integers") carve.__doc__ = __doc__ cmd.auto_arg[0]['carve'] = [cmd.selection_sc, 'selection', ', '] cmd.auto_arg[1]['carve'] = ['', 'slab thickness', ''] f_keys_sc = lambda: cmd.Shortcut([f"F{n}" for n in range(12)]) cmd.auto_arg[2]['carve'] = [f_keys_sc, 'F1 key to store', '']
def fix_aa(aa): aa = aa.upper() if len(aa) == 1: # Deal with a letter coding aa = aminos[aa].upper() elif len(aa) not in (1, 3): raise ValueError(f"""Amino acid encoding must be one or three letter, was {aa}""") return aa def mutate(selection, aa): aa = fix_aa(aa) cmd.set("retain_order", 0) cmd.wizard("mutagenesis") cmd.refresh_wizard() for single_res in iter_residues(selection): mutate_one(single_res, aa) cmd.set_wizard() cmd.sort() mutate.__doc__ = __doc__ cmd.extend('mutate', mutate) cmd.auto_arg[0]['mutate'] = [cmd.selection_sc, 'selection', ''] amino_sc = lambda: cmd.Shortcut( list(aminos.keys()) + list(aminos.values()) + extra) cmd.auto_arg[1]['mutate'] = [amino_sc, 'amino acid', '']
_self.frame(a) _self.sculpt_iterate(object_name, a, sculpt_ratio * (x + 1)) _self.refresh() # do main smoothing pass _self.smooth(object_name + " and not flag 3", x / 2 + 1, window, 1, n_state) # smooth out distortion near the ends... while window >= 3: _self.smooth(object_name + " and not flag 3", 1, 3, 1, 1 + window) _self.smooth(object_name + " and not flag 3", 1, 3, n_state - window, n_state) window = window - 1 y = y - 1 n_rep = n_rep + 1 x = x - int(((x - (x / dec_factor)) + 1)) pass_ = pass_ + 1 # don't stay in state N-1 _self.frame(1) cmd.auto_arg[0]['refine'] = [ cmd.Shortcut(['1', '2', '3', '4', '5']), 'level', ', ' ] cmd.auto_arg[1]['refine'] = cmd.auto_arg[0]['disable']
print(' Notice: not deleting', tmpdir) if not quiet: print(' corina: done') if 'join_states' not in cmd.keyword: cmd.extend('join_states', join_states) cmd.extend('sidechaincenters', sidechaincenters) cmd.extend('ramp_levels', ramp_levels) cmd.extend('pdb2pqr', pdb2pqr) cmd.extend('corina', corina) cmd.auto_arg[0].update([ ('ramp_levels', [ lambda: cmd.Shortcut(cmd.get_names_of_type('object:')), 'ramp object', '' ]), ]) cmd.auto_arg[1].update([ ('join_states', cmd.auto_arg[0]['zoom']), ('sidechaincenters', cmd.auto_arg[0]['zoom']), ('pdb2pqr', cmd.auto_arg[0]['zoom']), ('corina', cmd.auto_arg[0]['zoom']), ]) cmd.auto_arg[2].update([ ('sidechaincenters', [cmd.Shortcut(sidechaincentermethods), 'method', '']), ('pdb2pqr', [cmd.Shortcut(['amber', 'charmm', 'parse', 'tyl06']), 'forcefield', '']), ])
cmd.set('cartoon_dumbbell_length', 1.5, p) cmd.set('cartoon_dumbbell_width', 0.25, p) cmd.set('cartoon_dumbbell_radius', 0.2, p) # loops if color_l: print(cmd.do(color_l + '(ss l+"" and %s and %s)' % (selection, p))) cmd.set('cartoon_loop_radius', 0.25, p) if only: cmd.show_as('cartoon', '%s and %s' % (selection, p)) else: cmd.show('cartoon', '%s and %s' % (selection, p)) cmd.extend("disp_ss", disp_ss) cmd.auto_arg[0]['disp_ss'] = [lambda: cmd.Shortcut(['all']), 'selection=', ','] cmd.auto_arg[1]['disp_ss'] = [ lambda: cmd.Shortcut(['default', 'blue', 'yellow']), 'color_s=', ',' ] cmd.auto_arg[2]['disp_ss'] = [ lambda: cmd.Shortcut(['default', 'red', 'blue']), 'color_h=', ',' ] cmd.auto_arg[3]['disp_ss'] = [ lambda: cmd.Shortcut(['color_l=default, only=False']), 'remaining (defaults)...', '' ] #------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
sym = _self.get_symmetry(obj, state) if not sym: raise CmdException("no symmetry") basis = cellbasis(sym[3:6], sym[0:3])[:3,:3] cset = _self.get_coordset(obj, state, copy=0) cset += dot(basis, center) - selecenter _self.rebuild(selection) # all those have kwargs: mobile, target, mobile_state, target_state align_methods = ['align', 'super', 'cealign', 'tmalign', 'theseus', 'prosmart', 'xfit', 'mcsalign'] align_methods_sc = cmd.Shortcut(align_methods) # pymol commands cmd.extend('alignwithanymethod', alignwithanymethod) cmd.extend('tmalign', tmalign) cmd.extend('dyndom', dyndom) cmd.extend('gdt_ts', gdt_ts) cmd.extend('local_rms', local_rms) if 'extra_fit' not in cmd.keyword: cmd.extend('extra_fit', extra_fit) cmd.extend('intra_theseus', intra_theseus) cmd.extend('theseus', theseus) cmd.extend('prosmart', prosmart) cmd.extend('xfit', xfit) cmd.extend('intra_xfit', intra_xfit) cmd.extend('promix', promix)
print(' Selector: selection "%s" defined with %d atoms.' % (name, r)) return r # commands cmd.extend('select_pepseq', select_pepseq) cmd.extend('select_sspick', select_sspick) cmd.extend('symdiff', symdiff) cmd.extend('diff', diff) cmd.extend('collapse_resi', collapse_resi) cmd.extend('select_distances', select_distances) # autocompletion cmd.auto_arg[0].update([ ('select_sspick', cmd.auto_arg[0]['align']), ('symdiff', cmd.auto_arg[0]['align']), ('diff', cmd.auto_arg[0]['align']), ('collapse_resi', cmd.auto_arg[0]['zoom']), ('select_distances', [ lambda: cmd.Shortcut(cmd.get_names_of_type('object:measurement')), 'distance object', '' ]), ]) cmd.auto_arg[1].update([ ('select_pepseq', cmd.auto_arg[1]['select']), ('symdiff', cmd.auto_arg[1]['align']), ('diff', cmd.auto_arg[1]['align']), ]) # vi:expandtab:smarttab
def _aaindexkey_sc(): aaindex = _get_aaindex1() return cmd.Shortcut(aaindex.keys())
color = get_model_color(selection) if scatter: plt.scatter(x_values, y_values, c=color) else: plt.plot(x_values, y_values, c=color) _showfigure(fig, filename, quiet) # pymol commands cmd.extend('rms_plot', rms_plot) cmd.extend('pca_plot', pca_plot) cmd.extend('iterate_plot', iterate_plot) _auto_arg_aln_objects = [ lambda: cmd.Shortcut(cmd.get_names_of_type('object:alignment')), 'alignment object', ''] # autocompletion cmd.auto_arg[0].update([ ('pca_plot', _auto_arg_aln_objects), ('rms_plot', cmd.auto_arg[0]['align']), ('iterate_plot', cmd.auto_arg[0]['iterate']), ]) cmd.auto_arg[1].update([ ('pca_plot', cmd.auto_arg[0]['disable']), ('rms_plot', cmd.auto_arg[0]['align']), ]) cmd.auto_arg[2].update([ ('rms_plot', cmd.auto_arg[1]['align']), ])
# return list for potential use: if coordinates: if len(distance_list) > 2: # prevents crash if list is otherwise empty distance_list2 = list(map(distance_list.__getitem__, [1, 4])) return distance_list2 else: return distance_list else: return distance_list ################################################################################ cmd.extend('distancetoatom', distancetoatom) cmd.auto_arg[0]['distancetoatom'] = [ lambda: cmd.Shortcut(['all', '[0,0,0]', 'pk1']), 'origin=', ',' ] cmd.auto_arg[1]['distancetoatom'] = [ lambda: cmd.Shortcut(['7']), 'cutoff=', ',' ] cmd.auto_arg[2]['distancetoatom'] = [ lambda: cmd.Shortcut(['None', 'distancetoatom_report.txt']), 'filename=', ',' ] cmd.auto_arg[3]['distancetoatom'] = [ lambda: cmd.Shortcut([ 'selection=all, state=0, property_name=p.dist, coordinates=0, decimals=3, sort=1' ]), 'remaining (defaults)...', '' ] ################################################################################