Contents

Scope and usage

Starting with VMD version 1.8.7 it is now possible to store the complete topology information, i.e. not only bonds, but also angle, dihedral, and improper definitions as well as their force field type labels (if available). This now allows to do a large variety of modifications to topology data or even building topologies from scratch. The focus lies hereby on being able to perform many operations manually or scripted and thus being less focused on and optimized for biomolecules like psfgen.

In combination with the new command mol new atoms <number> it is now also possible to do many operations directly that previously required writing and manipulating temporary files and reading them back into VMD, or even write complete molecule or simulation data readers in Tcl script. This is especially useful for file formats, where additional input from the user is required, for example reading LAMMPS format "data" (=topology) files, where the "style" of theAtoms section cannot be deduced from the data. Of course write support is also possible.

The underlying Tcl script API in VMD itself had been designed to be minimalistic, since most operations are not computationally demanding and could be programmed with scripting. The topotools packages is supposed to provide a middleware, i.e. more powerful and easy to use script commands that make combine multiple low lever commands in a way to solve common tasks conveniently and efficiently.

Finally topotools also contains some utilities and applications for more complex operations like combining multiple molecules (=different files) or multiple selections into one new molecule, or building larger systems by replicating a given unitcell.

Updates and bug fixes for topotools between VMD releases are available from http://sites.google.com/site/akohlmey/software/topotools. This page also links to a set of tutorial examples that demonstrate in more detail, how the commands in the plugin can be used to build topology data files for different kinds of MD simulation packages.

Version

This documentation describes the version of the topotools plugin that is displayed in the title.

Main command interface

This is the middleware part of the package that provides abstract operations on top of the low-level API. This is modeled after the example of the internal mol or molinfo commands, or the pbc command from the PBCTools package to provide a somewhat consistent interface to the functionality. All command lines start with the topo keyword and then take a subcommand name to determine the actual functionality that is requested.

topo <command> [args...] <flags>

Common flags

The following flags can be passed on to all subsequent topo commands. They will select the molecule to which the operation should be applied to and also the set of atoms. The -sel transparently handles both, previously defined selection functions or selection texts, as arguments. For operations on bonds, angles, dihedrals, and impropers selections will be applied in such a way that only topological data where all atoms are contained in the selection.

-molid <num>|top          molecule id (default: 'top')
-sel <selection>          atom selection function or text (default: 'all')

The following flags can be added to subsequently documented operations on bonds. Bond information is treated and stored differently from angles, dihedrals, and impropers in VMD, since bond information is used for visualization and the others not. This also results in performance differences in commands operating on the two groups.

-bondtype  <typename>   bond type name (default: unknown)
-bondorder <bondorder>  bond order parameter (default: 1)

numatoms

Returns the number of atoms.

numatomtypes

Returns the number of atom types as determined from the type property.

atomtypenames

Returns the list of unique atom types names. The list has topo numatomtypes entries.

guessatom <property> <from>

Resets per atom data through selected heuristics. This is most useful to recover some data when using a file format that doesn't set contain these properties, or when they cannot be reliably determined, so the user should choose which ones work. The following combinations are supported:

  • element from mass: this assigns the closest match in the periodic table of elements.
  • element from name: the atom name is looked up in the periodic table of elements, if no match is found the first two characters of the name are used and if there is still no match, then only the first character of the name is taken. The lookup is case insensitive since version 1.2 of the plugin.
  • element from type: the atom type is looked up in the periodic system of elements in the same way as described for name (added in version 1.2).
  • mass from element: the element name is compared against the periodic table of elements (case insensitively) and the mass looked up.
  • name from element: the name is set to the element name with all uppercase characters.
  • name from type: the atom type is copied to atom name.
  • radius from element: the radius is looked up by element name. van-der-Walls radii are used for most elements, ionic radii for elements that are commonly ionic and 2.0 is used for all other elements.
  • type from element: the type is set to the element name with all uppercase characters.
  • type from name: the atom name is copied to atom type.
  • lammps from data: this is a shortcut notation for guessing element from mass and then name and radius from the element. This is a combination that can be applied to many LAMMPS data files.

numbonds

Returns the number of bonds.

numbondtypes

Returns the number of unique bond types.

bondtypenames

Returns a list of all unique bond types. The list has topo numbondtypes entries.

clearbonds

Delete all bonds.

retypebonds

Assign new bond types composed of the atom type strings connected with a '-' character. Bond types are canonicalized so that the atom type with the lower dictionary sort value will be placed on the left and the other on the right.

addbond <id1> <id2> [-bondtype <type>] [-bondorder <order>]

Defines a bond bone between the two specified atoms. This does nothing if one of the two atom indices is outside the selection. You can specify the bond type and order via the optional flags -bondtype or -bondorder.

delbond <id1> <id2>

Deletes a bond between the two specified atoms. This does nothing if the bond does not exist or one of the two atom indices is outside the selection.

getbondlist [type|order|both|none]

Returns a list of unique bonds, the individual bond is a list of the atom indices forming the bond and optionally added the bond type name and/or the bond order value.

setbondlist [type|order|both|none] <list>

Defines bonds from a list in a format as returned by topo getbondlist. This is essentially a shortcut for calling topo clearbonds and a sequence of topo addbond commands with some optimization for the case of a selection encompassing all atoms.

num(angle|dihedral|improper|crossterm)s

Returns the number of angles, dihedrals, impropers or crossterms.

num(angle|dihedral|improper)types

Returns the number of unique angle-, dihedral-, or improper-types.

(angle|dihedral|improper)typenames

Returns a list of all unique angles, dihedrals, or impropers. The list has topo num(angle|dihedral|improper)types entries.

clear(angle|dihedral|improper|crossterm)s

Deletes the currently defined angles, dihedrals, impropers, or crossterms.

sort(angle|dihedral|improper)s

Sorts and canonicalizes the list of angles, dihedrals, or impropers. Duplicates are removed and the list is sorted by atom types.

retype(angle|dihedral|improper)s

Assign new angle, dihedral, or improper types composed of the atom type strings connected with a '-' character. The resulting types are canonicalized and sorted.

guess(angle|dihedral)s

Guess angle or dihedral definitions from the bond topology. An angle is defined by two bonds sharing an atom and a dihedral by two bonds sharing a bond. Types are assigned in the same way as in the corresponging retype command.

guessimpropers [tolerance <degrees>]

Guess improper angles. Are defined for atoms that are bonded to exactly 3 atoms when they form a near flat structure. The tolerance flag can be used as a cutoff for what is to be considered as "flat" and what not.

addangle <type> <id1> <id2> <id3> <type>

Defines an angle of type <type> between the three specified atoms. All three atoms have to be contained in the specified atom selection ('all' if none is given) or else the command is ignored. No further checks are being performed on the input.

delangle <id1> <id2> <id3>

Deletes an angle between the three specified atoms. Does nothing if not all three atom indices are contained within the given selection (default 'all').

getanglelist

Returns a list of defined angles with each entry in the format {type <index 1> <index 2> <index 3>}. The type name may be set to {}, if no angletype has been set. The list is printed unsorted as it is stored in VMD.

setanglelist <list>

Resets the angle definitions from a list in a format as returned by topo getanglelist. This is essentially a shortcut for calling topo clearbonds and a sequence of topo addangle commands with some optimization for the case of a selection encompassing all atoms.

adddihedral <id1> <id2> <id3> <id4> <type>

Defines a dihedral of type <type> between the four specified atoms. All four atoms have to be contained in the specified atom selection ('all' if none is given) or else the command is ignored. No further checks are being performed on the input.

deldihedral <idx1> <id2> <id3> <id4>

Deletes the dihedral between the four specified atoms. Does nothing if not all four atom indices are contained within the given selection (default 'all').

addimproper <id1> <id2> <id3> <id4> <type>

Defines an improper of type <type> between the four specified atoms. All four atoms have to be contained in the specified atom selection ('all' if none is given) or else the command is ignored. No further checks are being performed on the input.

delimproper <id1> <id2> <id3> <id4>

Deletes the improper between the four specified atoms. Does nothing if not all four atom indices are contained within the given selection (default 'all').

get(dihedral|improper)list

Returns a list of defined dihedrals or impropers with each entry in the format {type <index 1> <index 2> <index 3> <index 4>}. The type name may be set to {}, if no type has been set. The list is printed unsorted as it is stored in VMD.

set(dihedral|improper)list <list>

Resets the dihedral or improper definitions from a list in a format as returned by topo getdihedrallist or topo getimproperlist. This is essentially a shortcut notation for clearing and then resetting them individually.

addcrossterm <id1> <id2> <id3> <id4> <id5> <id6> <id7> <id8>

Defines a crossterm between the eight specified atoms. All eight atoms have to be contained in the specified atom selection ('all' if none is given) or else the command is ignored. No further checks are being performed on the input.

delcrossterm <id1> <id2> <id3> <id4> <id5> <id6> <id7> <id8>

Deletes the crossterm between the eight specified atoms. Does nothing if not all eight atom indices are contained within the given selection (default 'all').

getcrosstermlist

Returns a list of defined crossterms with each entry in the format {<index 1> <index 2> <index 3> <index 4> <index 5> <index 6> <index 7> <index 8>}. The list is printed unsorted as it is stored in VMD.

setcrosstermlist <list>

Resets the crossterm definitions from a list in a format as returned by topo getcrosstermlist. This is essentially a shortcut notations for clearing and then resetting them individually.

File I/O Commands

TopoTools provides a number of file I/O commands that contrast from the molfile plugins in such that they use Tcl scripting to read and write files. This provides additional flexibility and allows to easily pass flags to the reader or writer, that are not available in the molfile plugin API, however, it may also results in reduced reading performance. All of the file I/O commands also use the topo prefix and support the commonly supported optional flags for specifying molecule id and atom selection.

readlammpsdata <file name> [<atom style>]

Read in atom coordinates, properties, bond, angle, dihedral and other related topology info from a LAMMPS data file, i.e. a file suitable for the read_data command. This can be used to check a data file for its validity (e.g. after using restart2data), for manipulations from within VMD, or to generate a .psf file to be used for visualization of .dcd or .xtc format trajectory files in VMD. The 'atom style' is the value given to the atom_style command in the LAMMPS input file (by default TopoTools will try to infer the atom style from information embedded in the data file as comments; if no such hints are present, it will use 'full'). This subcommand creates a new molecule in VMD and returns its molecule id or -1 in case of failure. The -sel parameter is currently ignored.

writelammpsdata <file name> [<atom style>]

Write out atom coordinates, properties, bond, angle, dihedral and other related topology info stored inside VMD to a LAMMPS data file, i.e. a file suitable for the read_data command. This this way VMD can be used to build LAMMPS input with Tcl scripting and convert existing inputs from other MD codes to be used in LAMMPS. For some examples, please see the TopoTools tutorials. The 'atom style' is the value you want to give to the atom_style command in the LAMMPS input file (default is 'full'). Only data that is present will be written and non-zero box sizes are required.

readvarxyz <file name>

Read in an xyz-format trajectory file (in xmol style) with a varying number of atoms per frame. This format is normally not supported in VMD and the script circumvents the restriction by automatically adding a sufficient number of dummy particles. Whether an atom is actually present in a given frame or not is flagged by the value of the corresponding user field, which is set to either 1.0 or -1.0, respectively. For efficiency reasons the atoms are sorted by type, thus atom order and bonding is not preserved. This subcommand creates a new molecule and returns its molecule id or -1, in case of failure.

writevarxyz <file name> [selmod <sel>] [first|last|step <frame]

Write out an xyz-format trajectory file with a varying number of atoms per frame. This is the counterpart to the readvarxyz subcommand. The optional selection string defines how atoms for each frame have to be selected. If not given, as selection string of "user > 0" is assumed.

writegmxtop <file name> [<list of CHARMM parameter files>]

Write a gromacs-style topology file that can be used in combination with a .gro or .pdb file to generate a .tpr file with the gromacs grompp tool. Such .tpr files are used to run simulations and for some of the more advanced gromacs analysis tools. If one or more parameter files (in CHARMM format) are provided, the resulting topology file is suitable for running MD simulations using the provided parameters. This allows the preparation of systems with CHARMM tools and to run the simulations with gromacs instead. A paper describing this TopoGromacs functionality is available at doi:10.1021/acs.jcim.6b00103. If the parameter files are omitted, dummy values are included instead so that the generated incomplete topology (and the from it generated .tpr file) are still sufficient to analyze trajectories, since analysis tools do not need force field parameters. This is useful for using gromacs tools to analyse trajectories that were not generated with gromacs and thus no .tpr file exists. Such a topology/.tpr file with dummy parameters is in no way suitable to start a correct MD simulation, though. Usage example:

package require topotools 1.6
# Load the structure into VMD.
mol new structure.psf
mol addfile structure.pdb
# Pass along a list of parameters to generate structure.top, suitable for preparing gromacs simulations.
topo writegmxtop structure.top [list parameterfile1.prm parameterfile2.prm]
# This would be prepared for simulation using grompp to create a tpr file
# gmx grompp -f simulationsetup.mdp -c structure.pdb -p structure.top -o simulation.tpr

Utility Functions

These are useful and convenient tools written on top of the topotools API. You can access them directly with their ::TopoTools:: namespace prefix or use namespace import ::TopoTools::<pattern> to import some or all of them (with the pattern '*') into your current namespace.

mergemols <list of molecule ids>

Combines multiple separate molecules into one file. This is non-destructive and will create a new molecule. The molecule id of the new molecule is returned, or -1 in case of a failure. Usage example:

package require topotools 1.6
# load to be merged molecules into VMD
set midlist {}
set mol [mol new part1.psf waitfor all]
mol addfile part1.pdb
lappend midlist $mol
set mol [mol new part2.psf waitfor all]
mol addfile part2.pdb $mol
lappend midlist $mol
# do the magic
set mol [::TopoTools::mergemols $midlist]
animate write psf merged.psf $mol
animate write pdb merged.pdb $mol

selections2mol <list of atom selections>

This is very similar to the previous mergemols command. It combines one or multiple atom selections, which can be taken from different molecules, into one new molecule. This is also non-destructive and will create a new molecule. The molecule id of the new molecule is returned, or -1 in case of a failure. Usage example:

package require topotools 1.6
set sellist {}
set sel [atomselect 0 protein]
lappend sellist $sel
set sel [atomselect 0 protein]
$sel frame 200 
$sel moveby {50.0 50.0 0.0}
lappend sellist $sel
set sel [atomselect 1 "same residue as (within 3.0 of chain L)"]
lappend sellist $sel
# do the magic
set mol [::TopoTools::selections2mol $sellist]
animate write psf combinedsel.psf $mol
animate write pdb combinedsel.pdb $mol

replicatemol <mol> <nx> <ny> <nz>

Replicate the current unitcell according to integer replicate counts. Usage example:

package require topotools 1.5
# load a molecule
set mol [mol new pegc12e8-small.xml type hoomd waitfor all]
# do the magic
set newmol [::TopoTools::replicatemol $mol 2 2 1 ]
animate write hoomd replicated.xml $newmol

Author

Axel Kohlmeyer with contributions from Josh Vermaas (TopoGromacs, i.e. fully working gromacs topology files for CHARMM style parameter files) and Konstantin W (replicatemols for non-orthogonal cells)

Funded by a grant from
the National Institute of
General Medical Sciences
of the National Institutes
of Health