RSS Forums RSS

distance calculation for XYZ coordiantes

Please support our Perl advertiser: Programming Forums
Reply
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

  #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..
AddThis Social Bookmark Button
Reply With Quote  
Posts: 5,116
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: 630
Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: distance calculation for XYZ coordiantes

  #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
my @old;
open (IN, "filename.pdb") or die "$!";
while (my $line = <IN>) {
   chomp($line);
   my @array = (split(/\s+/,$line))[6,7,8];
   print "@array\n";
   if ( $. > 1 ) {
      # now work out distance between @old and @array
   }
   @old = @array;
}
close (IN);
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
UK Voter? Please send a message to Incapability Brown and the rest of Zanu-Labour
Up to 8Mb PlusNet broadband from only £5.99 a month!
Reply With Quote  
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

  #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  
Posts: 843
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 63
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: distance calculation for XYZ coordiantes

  #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  
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

  #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 12:46 pm. Reason: Keep it on site.
Reply With Quote  
Posts: 843
Reputation: KevinADC has a spectacular aura about KevinADC has a spectacular aura about 
Solved Threads: 63
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Posting Shark

Re: distance calculation for XYZ coordiantes

  #6  
Oct 22nd, 2008
Link worked for me.....
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Other Threads in the Perl Forum
Views: 1391 | Replies: 5 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 6:13 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC