From: Axel Kohlmeyer (
Date: Mon Mar 30 2015 - 10:59:18 CDT

On Mon, Mar 30, 2015 at 11:13 AM, Samuel Jobbins
<> wrote:
> Hi both,
> Thanks for your prompt responses and the help you've posted so far.
> Sadly I'm still struggling to get VMD to do what I want. I don't need to
> compute the first coordination sphere as I already have that data in a
> separate file. I've used that data to generate a trajectory of 3200 frames,
> each with 2400 atoms, where the atom label has an integer after it denoting
> its CN. For example, Zn3 would correspond to a zinc atom coordinates to
> three other atoms.
> As this is a trajectory of a phase transition, the coordination of each
> atomic site changes through the trajectory, such that Zn3 might be Zn6 in
> the final frame. I just want to be able to colour coordinate each atom in my
> xyz by its label - i.e. for the label to be read each frame, rather than
> just from the initial frame. This way, I can observe how the coordination
> changes in local parts of the structure during the transition.
> Is this possible in this way, or do I have to calculate the CN in VMD? I am
> really sorry if this is a silly question, but I am relatively inexperienced
> with the finer workings of VMD. I may very well be over simplifying (or over
> complicating!) the problem.

as explained in the pdf that i pointed out to you (and in the VMD
user's guide), most per-atom properties cannot changed over the course
of a trajectory. that is a design decision of VMD and no matter how
much you insist, it cannot be changed.

thus storing the information you are after into the atom name is a bad idea.

so you have to work around this:
- one option is to read the trajectory without paying attention to the
changing labels and then read and parse it a second time via Tcl
scripting and then extract the numbers from the labels and store them
into the user field.
- another option is to read the label information into your own data
structure and then replace the label data on the fly using a variable
- the third option would indeed be to do the analysis from within VMD
(again), however, that may be very inefficient compared to the other
two solutions, since Tcl is not efficient at math. the result can,
again, be stored in the user field.

the cpmd-vmd.pdf file has examples for how to do each of these steps
in general. how to compute the coordination number is a bit tricky. i
might create a list of atom selections, one for each atom, using a
selection text like "exwithin <cutoff> of index <atomindex>" and then
loop over all frames and for each selection then reposition the frame
number, update the selection and use the "num" operation to return the
number of atoms within the cutoff of the central atom and then store
this in the user field.

in any case, the first option should have you reach your goal the
fastest as it requires the least amount of Tcl scripting and knowledge
of Tcl and VMD internal features.


> Thanks so much,
> Sam
> ________________________________
> From: Josh Vermaas <>
> Sent: 26 March 2015 17:12
> To: Samuel Jobbins;
> Subject: Re: vmd-l: Colour coordinating atoms in a trajectory by
> Coordination Number
> Hi Sam,
> Set the per frame user field. For instance, if your coordination numbers for
> 5 atoms never changed, here is what you might do:
> set CN [list 1 2 3 4 5]
> set sel [atomselect top "index 0 to 4"]
> for { set f 0 } { $f < [molinfo top get numframes] } { incr f } {
> $sel frame $f
> $sel set user $CN
> }
> There are also 3 more per-atom user fields if you need them (user2, user3,
> and user4). Naturally you'd want to calculate the coordination number within
> the loop.
> -Josh Vermaas
> On 3/26/15 9:57 AM, Samuel Jobbins wrote:
> Hello everyone,
> I have a trajectory of a phase transition in XYZ format, along with
> coordination sphere data for each atom in each frame of the trajectory.
> I am trying to visualise the trajectory on VMD and I would like to colour
> coordinate the atoms by their coordination number. I was planning to do this
> by changing the labels of the atoms in each frame corresponding to their CN,
> such that one could interactively see the evolution of each atom's CN.
> However, I've noticed that VMD seems to only take the labels from the first
> frame of the trajectory, and keep them constant throughout the simulation.
> I have tried using different 'real' atomic labels (such as replacing Zn with
> Cu, Fe, Co etc, depending on CN) as well as dummy labels (eg Zn3, Zn4, Zn5
> to indicate CN). I've also tried using different file types (e.g. pdb).
> However, every time VMD only takes the label from the first frame.
> Does anyone know a way around this?
> Sorry if this is a very mundane question, but I cannot find a solution to
> this problem!
> Thanks for your time,
> Sam

Dr. Axel Kohlmeyer
College of Science & Technology, Temple University, Philadelphia PA, USA
International Centre for Theoretical Physics, Trieste. Italy.