distance calculation for XYZ coordiantes

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 6
Reputation: annie_singh is an unknown quantity at this point 
Solved Threads: 0
annie_singh annie_singh is offline Offline
Newbie Poster

distance calculation for XYZ coordiantes

 
0
  #1
Oct 1st, 2008
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..
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: distance calculation for XYZ coordiantes

 
0
  #2
Oct 1st, 2008
> 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
  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);
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 6
Reputation: annie_singh is an unknown quantity at this point 
Solved Threads: 0
annie_singh annie_singh is offline Offline
Newbie Poster

Re: distance calculation for XYZ coordiantes

 
0
  #3
Oct 1st, 2008
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,
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: distance calculation for XYZ coordiantes

 
0
  #4
Oct 1st, 2008
Don't bother, they have been given the answer on another forum:

http://www.perlguru.com/gforum.cgi?post=32920
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1
Reputation: DineshDC is an unknown quantity at this point 
Solved Threads: 0
DineshDC DineshDC is offline Offline
Newbie Poster

Re: distance calculation for XYZ coordiantes

 
0
  #5
Oct 22nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 898
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 67
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: distance calculation for XYZ coordiantes

 
0
  #6
Oct 22nd, 2008
Link worked for me.....
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the Perl Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC