Yasc scripts for Vmd

VMD is one of the best and more powerful software to visualize and analyze molecular systems, not necessarily bio-stuffs like protein, DNA, drugs, lipids and so on. Plus, it has a TCL console, to allow to write and execute scripts. In the TCL console, you have access to almost all the VMD features available via the graphic interface, and you can combine them with TCL commands to create powerful scripts.

Here all the script I'm making for VMD. As usually, those are free and without any warranty.

nosolincnt.tcl: remove atoms from inside a CNT

This tcl script for VMD writes a Gromacs index file without the atoms that are inside a carbon nanotube. The index file created can be used with Gromacs editconf to create a system with an empty CNT. This is useful when you solvate a CNT using the Gromacs utility genbox and a solvent box.
The script assumes the CNT can be selected as a fragment, that it is infinite and that it is oriented along X-, Y- or Z-axis. This is the case for periodic SWNT or MWNT created by buildcstruct.
The script asks for the number of the CNT fragment, its orientation, the radius (in Å) of the cylindrical selection and the name of the index file. Please mind that there is no control to avoid overwriting old index files. The script calculates the center of mass of the CNT and use if as center of the cylindrical selection. The radius is used to perform the following selection:

not fragment sqrt(sqr(x-xcom)+(sqr(z-zcom))<radius

where xcom and zcom are the X- and Z-coords for the center of mass of the carbon nanotube. When ready, press W when the view window is active to write the index file.

Load the script in the VMD Tk console typing:

source /the/path/of/the/script/nosolincnt.tcl

The script will ask for the CNT fragment number, the radius of the selection and the name of the index file. Furthermore, there are a number of commands available:

  • when the view window is active:
    1. C: apply the selection;
    2. I: inverse the selection: displays only the atoms that will be removed;
    3. R: reset the view;
    4. W: write the index file;
  • in the tk console:
    1. new: reset the script, i.e. reprompt the initial questions (fragment, radius and index file name);
    2. rad: set a new radius

You can download the script here.

Here a small video tutorial on what you can do with the script:

You may ask why not to do a perl or python script instead: to be honest I have tried if, but those scripts are slow with loops of hundreds of thousands of atoms, while with VMD everything is already loaded in ram, so fast fast fast (more than 160000 atoms have been used in the video tutorial). Plus, there is the bonus of interactively see what we are going to remove… which is not bad at all ;)

select.tcl: select fragments in a spherical or cylindrical region

Here a tcl script useful to select all the fragments that are in a particular spherical region of your system, and save them as pdb file.
The region is selected given a radius (10 ang by default) and a center (0,0,0 by default). The selection is based on the fragment definition, so to avoid to break molecules.


type: choose between spherical or cylindrical region
rad: change/set the radius of the spherical selection
shift: change the center of the spherical selection
select /S: update view and make the selection
reset / R: reset view
write / W: write the index file
help or H: show this help

Till you don't decide to save the fragments, you can change the radius and the center of the selection as much as you need without reload the script. At the moment, the selected fragments can be saved only as pdb and no inverse selection is possible. But it is not difficult to expand the script.

Download the script here.

rgyr.tcl: polymer gyration radius

This script calculates the gyration radius of a selected polymer and save it in a file. The gyration radius is calculated for each frame in the loaded trajectory.

Please not that if you have turned on periodic boundary conditions (pbc) in your calculations, the polymer, or part of it, could have moved out of the simulation box. This will result in a "broken" polymer, therefore the calculated gyration radius could be wrong. If you have done your simulation with gromacs, you can use the utility trjconv to fix the problem:

trjconv -f original_trj.xtc -pbc nojump -o nojump.xtc

this command will generate a new trajectory keeping the polymer altogether, avoiding the jumps due to the pbc.

Download the script here.

pbc.tcl: display periodic image with xyz files

VMD can display periodic images, but need to know the size of the unit cell. Some file formats, like gromacs .gro and pdb files, contains such information, therefore you don't need this script. To the other hand, if you work with XYZ of TINKER arc files, you will need to define the unit cell by yourself, 'cause is not defined in those file formats.
The script will ask for the length of the three vectors a, b and c (in Angstrom) and the angles alpha, beta and gamma (in degrees). The cell will be set for each frame in the trajectory.

Download the script here.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License