Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tcl script to bin a pair (phi,psi)

Status
Not open for further replies.

programmerc

Programmer
Oct 29, 2010
10
GB
I currently have data of this form

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

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)

e.g.
phi psi count
-180 -180 464
-180 -179 324
-179 -180 133
...


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

 
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"
Code:
% 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:
Code:
% lsort -index 1 $lst1
{4 22} {-12 88} {24 94}

_________________
Bob Rashkin
 
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
...
 
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.
 
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:
# 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
Code:
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)
 
Just reviewed the posts - change the list sort option from '-integer' to '-real' as needed above.
 
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.
 
Hi there,

thanks, no it was really helpful as an outline.

I will definitely give it a stab!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top