943,774 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 3231
  • Perl RSS
Oct 1st, 2008
0

distance calculation for XYZ coordiantes

Expand Post »
Hello,

I am a beginner in perl. I am stuck with a problem. I have an array which looks like this

6.324 32.707 50.379
5.197 32.618 46.826
4.020 36.132 46.259
7.131 38.210 45.919
6.719 38.935 42.270
2.986 39.221 41.892
-0.269 37.184 41.565

These are the X, Y and Z coordinates from a pdb file. I want to calculate the distance using these three coordinate values. First i want to know how to assign variable names to these values in the array. I have to use this formula to calculate the distance:

$dist = sqrt(($x1-$x2)**2+($y1-$y2)**2+($z1-$z2)**2);

Till now I have written the script shown below to obtain the three columns which is shown above. I am stuck. I need help to calculate distance using 'for loop' or i guess its two for loops within which would look something like this:

for($AAi = 1; $AAi<= 7; $AAi++){ #here $AAi shud take the first three values(x1, y1, z1)
for ($AAj = 2; $AAj<= 7; $AAj++){ #similarly $AAj shud take 2nd 3 values(x2, y2, z2)
my $dist = sqrt(($x1-$x2)**2+($y1-$y2)**2+($z1-$z2)**2);

and do an iterative distance calculation. am stuck....

my exiting code:

open(IN, "/Users/anu/out.pl") or die "$!";
while (my $line = <IN>) {
chomp($line);
my @array = (split (/\s+/, $line))[6, 7, 8];
print "@array\n";
}
close(IN);

Thank you..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
annie_singh is offline Offline
6 posts
since Sep 2008
Oct 1st, 2008
0

Re: distance calculation for XYZ coordiantes

> my exiting code:
Really....
http://www.daniweb.com/forums/post702120-2.html
Try to reply to existing threads which cover basically the same topic as before.

In your loop, having worked out the distance between
6.324 32.707 50.379
5.197 32.618 46.826
ie, lines 1 and 2

Would you then need to work out the distance between
5.197 32.618 46.826
4.020 36.132 46.259
ie, lines 2 and 3

Something like
Perl Syntax (Toggle Plain Text)
  1. my @old;
  2. open (IN, "filename.pdb") or die "$!";
  3. while (my $line = <IN>) {
  4. chomp($line);
  5. my @array = (split(/\s+/,$line))[6,7,8];
  6. print "@array\n";
  7. if ( $. > 1 ) {
  8. # now work out distance between @old and @array
  9. }
  10. @old = @array;
  11. }
  12. close (IN);
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Oct 1st, 2008
0

Re: distance calculation for XYZ coordiantes

hi,

Well, I did get extract the three columns with the script, but i wanted to know how to calculate the distance and put them in an output file.

The distance calculation is between row1_row2, then row1_row3, row1_row4, row1_row5.... so on... till row6_row7.

This was the problem. I do not know how to do this iterative distance calcultion.

Thank you,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
annie_singh is offline Offline
6 posts
since Sep 2008
Oct 1st, 2008
0

Re: distance calculation for XYZ coordiantes

Don't bother, they have been given the answer on another forum:

http://www.perlguru.com/gforum.cgi?post=32920
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Oct 22nd, 2008
0

Re: distance calculation for XYZ coordiantes

distance calculation for XYZ coordiantes
I cant reach the link perlguru???
Can any one help me?? Even i have similar type of problem as annie_singe..
thank sin advance..
<<email id snipped>>
Last edited by ~s.o.s~; Oct 22nd, 2008 at 1:46 pm. Reason: Keep it on site.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
DineshDC is offline Offline
1 posts
since Oct 2008
Oct 22nd, 2008
0

Re: distance calculation for XYZ coordiantes

Link worked for me.....
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: How to install PERL
Next Thread in Perl Forum Timeline: Where do I start?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC