Imagine now, I have 5 structures, and I want to estimate the time when the 5 structures are closer to each other at the same time. I thought I could extract the distance between the different structures and structure number 1 (i.e., the distance between structure 1 and 2, the distance between 1 and 3, 1 and 4, etc.). At the end, I will have 4 files that contain the time and distance between these structures with respect to structure number 1. But when I plotted these different files, I couldn't know when the 5 structures were closer to each other at the same time.

Does anyone have any suggestions?

  • $\begingroup$ Can you please clarify what are you looking for? Are you trying to see the pairwise distance between the residues as a function of time? $\endgroup$ Apr 27, 2023 at 11:51
  • $\begingroup$ @HemanthHaridas Yes. For example, the full time is 10 ps, but not during the full time, the residues are close to each other, so I want to estimate how much time they stay closer. $\endgroup$ Apr 27, 2023 at 13:25
  • $\begingroup$ You can calculate the autocorrelation between the pairwise distances to figure out how does residue 1 affect the motion of residue 2. If you fit it with a two term exponential, it will give you the autocorrelation time which is how much time is required for the association to break. $\endgroup$ Apr 27, 2023 at 13:31
  • $\begingroup$ Ok. But in this case it will be only pairs. I want to see the 5 residues. One thing, these residues are not linked. so they are moving in different position, but at some point, they become closer and more or less form sphere. So I want to estimate the time in which this formed sphere persist during simulation. $\endgroup$ Apr 27, 2023 at 13:58

1 Answer 1


Let the centre of mass of each residue be denoted as $r_i$ and is evaluated at every frame. Let the centre of mass of the combined system be $r_c$ where c denotes combined. You can evaluate the distance between each $r_i$ and $r_c$ at every frame. This will give you 5 distance values for each frame. Now the task is to minimize the function $f(d_i) = \Sigma d_i$. If you evaluate that function at every frame, you should get the lowest values when all your residues are close to one another.

Here is a Tcl script that can do that

set psf adenine.psf
set dcd adenine.dcd
set output  [open distance.dat w]

mol load psf $psf
mol addfile type dcd $dcd waitfor all

set numframes [molinfo top get numframes]

for { set framecounter 0 } { $framecounter < $numframes } { incr framecounter } {
    molinfo top set frame $framecounter 
set total [atomselect top "resname ADE"]            # selects all the adenine molecules
set tcom [measure center $total weight mass]        # gets the centre of mass for the combined adenine system
    set segnames [lsort -unique [$total get segname]]   # gets the segnames for each adenine molecule
set dist {}
foreach segname $segnames {
        set sel [atomselect top "resname ADE and segname $segname"]
    set rcom [measure center $sel weight mass]
        set distance [veclength [vecsub $rcom $tcom]]   # calculate the distance between each residue COM and total COM
        lappend dist $distance                  # append it to a list
    set totaldistance 0
    foreach distance $dist {
    set totaldistance [expr $totaldistance + $distance]
puts $output "$totaldistance"

close $output
mol delete all
  • $\begingroup$ Ok, Nice idea. but how can I do that? $\endgroup$ Apr 27, 2023 at 14:34
  • $\begingroup$ Does the edited version answer your question? $\endgroup$ Apr 27, 2023 at 16:15
  • $\begingroup$ I will check now, it seems that the output will contain distance not time so how can I know the time $\endgroup$ Apr 27, 2023 at 16:46
  • $\begingroup$ The code prints out the calculated value of the function at every frame, so the line number would correspond to the frame that you are interested in. Multiply that with your time step and that will give you the time. If your query is addressed, please consider upvoting the answer and marking it as accepted. $\endgroup$ Apr 27, 2023 at 16:48
  • $\begingroup$ I am trying to check the code, if it worked well. I will put accepted. I have a question in the code, we didn't select the number of the other 4 residues because there is solvent, but I am only interested in these 5 residues only $\endgroup$ Apr 27, 2023 at 17:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .