4

In VMD I want to load every new file with the drawing method CPK. This doesn't seem not to be an option in the .vmdrc file for some technical reasons.

How can I do this from the VMD command line (so that I can make a script)? Or is there some other solution/workaround/hack to make this work?

Jonatan Öström
  • 2,428
  • 1
  • 16
  • 27

2 Answers2

8

There are several ways to achieve what you want:

(1) put the following line in the correct location of your .vmdrc

    mol default style CPK

(2) use the VMD Preferences Panel (last item in the Extensions menu of the main window) to generate a .vmdrc file that meets your expectations(s). The setting you're looking for is in the Representations tab.

(3) for more advanced settings (i.e. default settings applied to molecules already loaded when vmd read the startup .vmdrc file), you can use the following (works for me on VMD 1.9.2):

proc reset_viz {molid} {
  # operate only on existing molecules
  if {[lsearch [molinfo list] $molid] >= 0} {
    # delete all representations
    set numrep [molinfo $molid get numreps]
    for {set i 0} {$i < $numrep} {incr i} {
      mol delrep $i $molid
    }
    # add new representations
    mol representation CPK
    # add other representation stuff you want here
    mol addrep $molid
  } 
}

proc reset_viz_proxy {args} {
  foreach {fname molid rw} $args {}
  eval "after idle {reset_viz $molid}"
}

## put a trace on vmd_initialize_structure
trace variable vmd_initialize_structure w reset_viz_proxy

after idle {
  if { 1 } {
    foreach molid [molinfo list] {
      reset_viz $molid
    }
  }
}

This piece of code is adapted from this Axel Kohlmeyer website.

HTH,

Eiffel
  • 153
  • 4
  • I tried adding `mol default style CPK` to my `.vmdrc` file but it does not change anything. I know the file is being read as later commands in the file are executed (defining color, turning off the axes, etc.). I am running VMD 1.9.2 on Linux. What version and system are you using that this works on? – Steven C. Howell Apr 28 '17 at 13:30
  • I left the setting in and just realized that while it does not work when loading a structure directly from the command line, e.g., `$> vmd my.pdb my.dcd`, it does work when loading a structure after opening the application. This is better than nothing, but most of the time I open files directly from the command line so it is not that helpful. – Steven C. Howell Apr 28 '17 at 17:42
  • 3
    @StevenC.Howell: You're right. VMD first loads the structure file from your command line and only after that, loads your vmdrc file. Thus the first two options won't work. But the last solution is what your looking for: it adds a function to your vmdrc that modifies the representation of the molecule(s) **already** loaded. You just have to modify the `mol representation CPK` line (or add other commands below) to fit your favorite representation(s). – Eiffel Apr 29 '17 at 06:59
  • As is, dropping this into my `.vmdrc` file did not completely work. It removed the view of files loaded from the command line but did not redraw them. I tried debugging it for a few minutes but had to move on. Hopefully I can revisit this. – Steven C. Howell May 01 '17 at 14:03
  • @StevenC.Howell: I edited my answer (`mol addrep $molid` in the reset_viz function). – Eiffel May 10 '17 at 10:59
0

I found a convenient solution. In .bashrc add:

vmda () {
    echo -e "
    mol default style CPK
    user add key Control-w quit
    " > /tmp/vmdstartup
    echo "mol new $1" > /tmp/vmdcommand
    vmd -e /tmp/vmdcommand -startup /tmp/vmdstartup
}

Look at a structure with

vmda file.pdb

and close the window (quit the application) with Ctrl+w, like other windows.

Jonatan Öström
  • 2,428
  • 1
  • 16
  • 27