Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.


Tcl script to bin a pair (phi,psi)

Tcl script to bin a pair (phi,psi)

I currently have data of this form

frame number       phi     psi
1                  -87      65
2                  -65      45
3                  ...      ...

Now, I can sort this data so that phi, psi values are ordered (from -180 to 180) and then convert this data to a histogram of the form

phi      count (number of times seen)
-180      234
-179      132
-178      456

psi      count (number of times seen)
-180      122
-179      154
-178      176

But this is bad, for I have two 'uncorrelated' histograms. I would like a correlated version.

Now, I would like to input the original data and output an NxN array where I bin pair values (phi,psi)

phi   psi   count
-180 -180   464
-180 -179   324
-179 -180   133

any ideas on how to start this sort of Tcl program?


RE: Tcl script to bin a pair (phi,psi)

I don't understand.  If phi/psi are grouped by frame how can they be individually sorted?

Anyway, a list (of lists) can be sorted with "lsort"


% set lst1 {{4 22} {-12 88} {24 94}}
{4 22} {-12 88} {24 94}
% lsort $lst1
{-12 88} {24 94} {4 22}
Note that the sorting is on the first elements of the sub-lists.
If you need to sort on the 2nd element:


% lsort -index 1 $lst1
{4 22} {-12 88} {24 94}

Bob Rashkin

RE: Tcl script to bin a pair (phi,psi)

I sorted phi and psi individually in Xmgrace and plotted two histograms. That is how I obtained the individual data.

However, I would not like to look at the occurrence of dihedral pairs (phi, psi) and see the distribution of the pair.

My data looks like this:
frame phi    psi
0 68.466774 -58.170494
1 75.128593 -51.646816
2 76.083946 -64.300102
3 77.578056 -76.464218
4 63.180199 -76.067680
5 77.203979 -58.560757
6 66.574913 -60.000214
7 73.218269 -70.978203
8 70.956879 -76.096558
9 65.538872 -76.716568
10 57.107117 -67.572067
11 63.389595 -49.936893
12 83.935219 -65.073227
13 78.492310 -69.225609
14 58.567463 -77.028725
15 60.258656 -85.608917
16 80.604012 -68.479416
17 79.839516 -58.189476
18 68.693405 -66.911407
19 48.195873 -56.744625
20 75.479187 -48.657692
21 80.180649 -69.976234
22 71.216110 -70.213730
23 67.672768 -50.655262
24 55.870106 -63.952560
25 65.091850 -59.066532
26 64.395363 -40.585659
27 80.011673 -56.789768
28 74.003281 -69.651680
29 65.848534 -60.928204
30 65.260933 -78.133301

I would like to bin this data following the criteria of a bin for phi and one for psi.

I.e. my desired output data would be of the form

phi   psi   count
-180 -180   464
-180 -179   324
-179 -180   133

RE: Tcl script to bin a pair (phi,psi)

My task is essentially to count the pairs and put the in the appropriate intervals. Maybe tcl is not the best language for this task.  

RE: Tcl script to bin a pair (phi,psi)

Been watching this post hoping someone would add in something just like the above.  This may be the rest of the puzzle you are after.

CODE --> fill an array similar to

# Split up a line of data into $PhiVal and $PsiVal or its equivelant)
# then use this to record the data, adding the generic
# 'if info exists' to divert errors when PhiPsiArr(xxx) doesn't exist.
incr PhiPsiArr([list $PhiVal $PsiVal])
Then when your ready to print use


foreach phi_psi [lsort -integer -index 0 [array names PhiPsiArr]] {
   puts "$phi_psi $PhiPsiArr($phi_psi)"
You may want to emblish by spliting the phi_psi var into seperate vars and using the 'format' command to clean up your output.  By changing the 0 qualifier on the -index to a variable, you can make it easier to sort on either column.

Thanks Bong: I was spacing on the -index option (dont use it much)

RE: Tcl script to bin a pair (phi,psi)

Just reviewed the posts - change the list sort option from '-integer' to '-real' as needed above.

RE: Tcl script to bin a pair (phi,psi)

Could this be done in AWK?  

RE: Tcl script to bin a pair (phi,psi)

Sure - AWK, perl, ruby, PL1, assembler, PDP11; if you're not bound by the language you are to use, pick one you're comfortable with and have at it.  Was I too obsecure in the details above?  This has more or less been solved in TCL.

...OK, this may be pretty tough in PDP11.

RE: Tcl script to bin a pair (phi,psi)

Hi there,

thanks, no it was really helpful as an outline.

I will definitely give it a stab!


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close