News
News

\(my\) \(pymol\) \(settings\)

The settings files for making your pymol life easier
Current version: 2026.01 (shared with CC-0 public domain license). See also all python tools
Update: February 17, 2026: Bugfix in .pymol/pymolrc-ms*.py, indicated with bold in the code below
Installation: cd $HOME ; tar xfz $HOME/Download/pymolrc-ms.tgz (see also below)
Based on a "Biomolecular design" (DIB) course I'm teaching with Sílvia Osuna, I have been playing with the pymol settings files. The implementation is simple.
  • You can generate different settings files (pymolrc.pml), with dfferent alias names, e.g. one for each type of molecule, or one for each collaboration.
    • The settings files can be given extensions such as pymolrc-ms.pml or pymolrc-dib.pml; the former is for my research, the latter for the DIB course.
    • These pymolrc*.pml files must be placed in the correct directory ($HOME on Mac/Linux, C:\Users\YOURUSERNAME on Windows).
  • Within the pymol settings file (pymolrc*.pml) you can call a python script to perform some actions, such as adding bonds, coloring, etc.
    • These python scripts pymolrc.py can again be given extensions such as pymolrc-ms.py.
    • These pymolrc*.py files must be placed in the correct directory ($HOME/.pymol on Mac/Linux, C:\Users\YOURUSERNAME\.pymol on Windows).
  • Now you can just type e.g. \(msshowH\) to show all atoms with bonds, metals as spheres, etc. and showing also the hydrogens
    • Or you can just type \(mshideH\) to do the same but hide the hydrogens
    • Or you can just type \(mslabelH\) to show the hydrogens and indicate their IDs.
For the DIB course we have separate files (pymolrc-dib.pml and pymolrc-dib.py), which are focused on the combination of Caverweb and NCIplot-web. And we have adapted the script by rmera on GitHub to make the life of the DIB students easier (see below for our adapted version).
The Pymol file from CaverWeb results in a directory with a "data" directory, commands.txt and a "pymol.pml" file. Go into the directory, and open the pymol.pml file (pymol pymol.pml). Then type dibclean and you will have a nice view of the enzyme (see \(after\) \(dibclean\) image) and the substrate inside the tunnel leading towards the active site (including a \(tunnel\) object with all amino acid residues of the tunnel in ball/sticks).
Making nice pictures
Type ray 2000 within the command line in Python.
Then save the PNG file with png MYFILE.png.
NB. This will overwrite any file already with that name, without warning.
The contents of the $HOME/pymolrc-ms.pml file
#_ feedback disable,all,everything from pymol import cmd alias ms, hide; set dash_gap, 0.2; set dash_length, 0.15; set dash_width=4; \ set antialias=2; set seq_view, off; set virtual_trackball, off; set all_states=off; \ set label_color, black; set label_size, 16; set label_font_id, 9; \ set label_position,(0,1.5,0); set label_distance_digits, 3; \ set bg_rgb, [1.0,1.0,1.0]; set ray_opaque_background, 0; set movie_loop, 1; \ set stick_radius, 0.15; set sphere_scale=0.2; set valence, 1; \ color atomic; color grey40, elem C; color gold, elem Fe; color cyan, elem Sc;color smudge, elem S; \ hide everything; set os.environ['mswart'], 0;\ set movie_fps = 10;\ show sticks; \ show spheres, elem Sc or elem Ti or elem V or elem Cr or elem Mn or elem Fe or elem Co or elem Ni or elem Cu or elem Zn or elem Ga;\ show spheres, elem Y or elem Zr or elem Mo or elem Ru or elem Rh or elem Pd or elem Ag or elem Cd;\ show spheres, elem Hf or elem W or elem Re or elem Os or elem Ir or elem Pt or elem Au or elem Hg;\ color atomic; color grey40, elem C; color gold, elem Fe; color cyan, elem Sc; color smudge, elem S;\ run ~/.pymol/pymolrc-ms.py ;\ deselect; zoom all,1 alias msshowH, hide; ms; show sticks, elem H alias mshideH, hide; ms; hide everything, elem H ;\ run ~/.pymol/pymolrc-ms-noH.py ;\ deselect; zoom all,1 alias labelH, hide; msshowH; select Hs, elem H; deselect; label Hs, " %s" % ID alias ms4larry, hide; ms; hide everything, elem H; set sphere_scale=0.35; set stick_radius=0.3; \ run ~/.pymol/pymolrc-ms-noH.py ;\ deselect; zoom all,1 alias thinner, hide; msshowH; set stick_radius, 0.05; label all, " %s" % ID
The contents of the $HOME/.pymol/pymolrc-ms.py file
for n in cmd.get_names("objects"): elems = ['Sc','Ti','V','Cr','Mn','Fe','Co','Ni','Cu','Zn','Ga'] for el in elems: atoms = cmd.get_model("elem "+el+" and "+n) for at in atoms.atom: cmd.bond("id "+str(at.index)+" and "+n,n+" and id "+str(at.index)+" around 2.6 and not elem H") cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem O") # cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem N") cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem S") hvelems = ['Y','Zr','Mo','Ru','Rh','Pd','Ag','Cd','Hf','W','Re','Os','Ir','Pt','Au','Hg'] for el in hvelems: atoms = cmd.get_model("elem "+el+" and "+n) for at in atoms.atom: cmd.bond("id "+str(at.index)+" and "+n,n+" and id "+str(at.index)+" around 2.6 and not elem H") cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem O") # cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem N") cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem S") atoms = cmd.get_model("not bonded and "+n) for at in atoms.atom: cmd.show("spheres","id "+str(at.index)+" and "+n)
The contents of the $HOME/.pymol/pymolrc-ms-noH.py file
for n in cmd.get_names("objects"): elems = ['Sc','Ti','V','Cr','Mn','Fe','Co','Ni','Cu','Zn','Ga'] for el in elems: atoms = cmd.get_model("elem "+el+" and "+n) for at in atoms.atom: cmd.bond("id "+str(at.index)+" and "+n,n+" and id "+str(at.index)+" around 2.6 and not elem H") cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem O") # cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem N") cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem S") hvelems = ['Y','Zr','Mo','Ru','Rh','Pd','Ag','Cd','Hf','W','Re','Os','Ir','Pt','Au','Hg'] for el in hvelems: atoms = cmd.get_model("elem "+el+" and "+n) for at in atoms.atom: cmd.bond("id "+str(at.index)+" and "+n,n+" and id "+str(at.index)+" around 2.6 and not elem H") cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem O") # cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem N") cmd.show("spheres","id "+str(at.index)+" and "+n+" around 2.5 and elem S") atoms = cmd.get_model("not bonded and "+n) for at in atoms.atom: cmd.show("spheres","id "+str(at.index)+" and "+n) # atoms = cmd.get_model("bonded and not elem H") for at in atoms.atom: mybonded = cmd.select("not elem H "+" and "+n+" and bound_to id "+str(at.index)) if mybonded == 0: cmd.show("spheres","id "+str(at.index))
The contents of the $HOME/pymolrc-dib.pml file
#_ feedback disable,all,everything from pymol import cmd alias dib, hide; set seq_view, on; set virtual_trackball, off; set dash_gap, 0.2; \ set dash_length, 0.15; set dash_width=4; set all_states=off \ set label_color, black; set label_size, 16; set label_font_id, 9; \ set label_position,(0,1.5,0); set label_distance_digits, 3; \ set bg_rgb, [1.0,1.0,1.0]; set ray_opaque_background, 0; \ set movie_loop, 1; set all_states, off; set ray_trace_frames=false; \ color red, ss s; color gray, ss l; color blue, ss h; show cartoon; \ select waters, resnam HOH; color red, waters; show spheres, waters; \ set sphere_scale=0.2; set stick_radius=0.15; \ zoom all,1; deselect alias dibclean, hide; dib; delete origins or v_origins or receptor_simple; \ delete pocket_1:pocket_9 ;\ delete tun_cl_1:tun_cl_9 ;\ run ~/.pymol/pymolrc-dib.py; \ util.cbaw("trj"); color grey40, elem C; \ show cartoon; show sticks, trj; \ select tunnel, byres( structure w. 4A of trj ); show_as sticks, tunnel; \ util.cbaw("tunnel"); color grey40, elem C; \ extract tunobj, tunnel; set virtual_trackball, off; \ split_states trj; zoom tunobj,1; set seq_view, off; delete simple alias dibaas, hide; color atomic; color grey40, elem C; show sticks ; set virtual_trackball, off; \ set bg_rgb, [1.0,1.0,1.0]; set ray_opaque_background, 0; \ set seq_view, off alias dibnci, hide; dib; dibaas; color atomic; color grey40, elem C; show sticks ; run ~/.pymol/nci.py
The contents of the $HOME/.pymol/pymolrc-dib.py file
for n in cmd.get_names("objects"): if 'traj' in n: cmd.set_name(n, 'trj')
The contents of the $HOME/.pymol/nci.py file
# # nci.py, a script to display plots from Nciplot in PyMOL # Original version: https://github.com/rmera/ncipy # # NCI-Plot references: # J. Contreras-Garcia, E. Johnson, S. Keinan, R. Chaudret, J-P Piquemal, D. Beratan, W. Yang, J. Chem. Theor. Comp. 7, 625 (2011). # E R. Johnson, S. Keinan, P. Mori-Sanchez, J. Contreras-Garcia, A J. Cohen, and W. Yang, J. Am. Chem. Soc., 132, 6498 (2010). # # Usage: # # The adapted version is geared towards use with the NCI-web server in Paris. # Results from there are given in tar.gz files that need to be unpacked (tar xfz 68f75c0301108.tar.gz). # It will provide the following files in the 68f75c0301108 directory: # # 68f75c0301108_int_bars.png # 68f75c0301108_scolor.png # 68f75c0301108-dens.cube.gz # 68f75c0301108-grad.cube.gz # 68f75c0301108.dat # 68f75c0301108.log # 68f75c0301108.nci # 68f75c0301108.out # 68f75c0301108.slurm # 68f75c0301108.vmd # A_chain.xyz # fragment1.xyz # fragment2.xyz # int.dat # integrals.dat # plot_interval_bars.gp # plot_s_colored.gp # UNL_1.xyz # # (shown in bold are the ones which we use) # # Go into the directory (cd 68f75c0301108) and open the fragment*xyz with Pymol: # pymol fragment*xyz # # and then type dibnci (if you have installed pymolrc-dib.pml and .pymol/nci.py properly) # (the script will gunzip the cube files) import os import gzip import shutil from pymol import cmd, stored densf='not-present' gradf='not-present' densl='dens.cube' gradl='grad.cube' densz='dens.cube.gz' gradz='grad.cube.gz' for file in os.listdir(): if file.endswith(densl): densf=file elif file.endswith(densz): with gzip.open(file, 'rb') as f_in: densf=file.replace(".gz","") with open(densf, 'wb') as f_out: shutil.copyfileobj(f_in, f_out) if file.endswith(gradl): gradf=file elif file.endswith(gradz): with gzip.open(file, 'rb') as f_in: gradf=file.replace(".gz","") with open(gradf, 'wb') as f_out: shutil.copyfileobj(f_in, f_out) if densf == 'not-present': filelist = [] rootdir = os.getcwd() for subdir, dirs, files in os.walk(rootdir): for file in files: filepath = subdir + os.sep + file if filepath.endswith(densl): filelist.append(filepath) if len(filelist) == 1: densf = filelist[0] elif len(filelist) > 0: print("possible ***dens.cube files to choose from:") for i in range(len(filelist)): print(filelist[i]) else: print("Missing file ***"+densl) sys.exit("No *.dens.cube file present") if gradf == 'not-present': filelist = [] rootdir = os.getcwd() for subdir, dirs, files in os.walk(rootdir): for file in files: filepath = subdir + os.sep + file if filepath.endswith(gradl): filelist.append(filepath) if len(filelist) == 1: gradf = filelist[0] elif len(filelist) > 0: print("possible ***grad.cube files to choose from:") for i in range(len(filelist)): print(filelist[i]) else: print("Missing file ***"+gradl) sys.exit("No *.grad.cube file present") print("Using "+densf+" and "+gradf) cmd.load(densf,densl) cmd.load(gradf,gradl) cmd.isosurface("NCI",gradl, 0.4) cmd.ramp_new("ramp", densl, [-5,5], "rainbow") cmd.set("surface_color", "ramp", "NCI") cmd.set('two_sided_lighting',value=1) cmd.set('transparency', '0.1', 'NCI')
\(at\) \(the\) \(start\)
blog \(msshowH\)
blog \(mshideH\)
blog \(mslabelH\)
blog \(after\) \(dibclean\)
blog \(tunnel\)
blog
Installation