Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Co-ordinate distance calculation



Vindhyaauri1
New User

Dec 17, 2009, 3:04 AM


Views: 4852
Co-ordinate distance calculation

I require a program which should function as follows:

Consider 2 files A and B.
File A has info as follows:
ATOM 1 CD LYS A 257 -2.221 -32.646 -27.517 1.00 47.26 C
ATOM 2 CE LYSA 257 -2.752 -33.378 -26.284 1.00 48.60 C

Similarly File B has info like:
ATOM 9 NZ LYS A 257 -4.132 -33.887 -26.508 1.00 48.85 N
ATOM 10 N ASP A 258 -2.950 -27.664 -25.250 1.00 38.42 N

Task 1:
Now i need a program which can capture the *complete* data (all the columns) above into 2 arrays and then calculate distances bw the co-ordinates picked from col (6,7,8). Co-ordinates of the form (x,y,z)i.e, col (-2.221, -32.646, -27.517) for A and (a,b,c)i.e., col (-4.132,-33.887, -26.508) for B.
Calculate :my $dist = sqrt( ($x-$a)**2 + ($y-$b)**2 + ($z-$c)**2 );

This calculation has to happen for all the rows from A with all rows from B.

Task 2: After calc all distances, pick out those dist which have a value bw 2.5 and 3. Now, this value needs to be printed out as :

Distance bw atom 1(CD) of A and atom 10 (N) of B is $dist.

Code



      
    


FishMonger
Veteran / Moderator

Dec 17, 2009, 4:31 AM


Views: 4846
Re: [Vindhyaauri1] Co-ordinate distance calculation

How much are you willing to pay someone to do your homework assignment? My fee is $1,000,000.


Vindhyaauri1
New User

Dec 17, 2009, 6:27 PM


Views: 4800
Re: [FishMonger] Co-ordinate distance calculation

Haha!! thats a lot of money!! Actually have tried to get some part of it ...

use strict;

my @pdb=();
my @atoms;

open(IN, "/home/subs/vindytest/PDB.pl") or die "Could not open file!";

while (my $line = <IN>) {

my @array = (split (/\s+/, $line))[6, 7, 8];

print ("@array\n");

push @pdb,[@array] ;

}
close (IN);

for my $i1 ( 0 .. $#pdb-1 ){
my ( $x1, $y1, $z1 ) = @{ $pdb[$i1] };

for my $i2 ( 1 .. $#pdb ){
my ( $x2, $y2, $z2 ) = @{ $pdb[$i2] };
my $dist = sqrt( ($x2-$x1)**2 + ($y2-$y1)**2 + ($z2-$z1)**2 );
print "distance from ( $x1, $y1, $z1 ) to ( $x2, $y2, $z2 ) is $dist\n";
}
}

Im completely stuck when it comes to picking all the elements in a row from file A and B ... i mean since i am picking from 6,7,8 only.. also the output should have all the details... Im new to perl and just so lost!! Any help would be really appreciated



lifesaver
Novice

Dec 19, 2009, 8:58 AM


Views: 4712
Re: [Vindhyaauri1] Co-ordinate distance calculation


In Reply To
Haha!! thats a lot of money!! Actually have tried to get some part of it ...

use strict;

my @pdb=();
my @atoms;

open(IN, "/home/subs/vindytest/PDB.pl") or die "Could not open file!";

while (my $line = <IN>) {

my @array = (split (/\s+/, $line))[6, 7, 8];

print ("@array\n");

push @pdb,[@array] ;

}
close (IN);

for my $i1 ( 0 .. $#pdb-1 ){
my ( $x1, $y1, $z1 ) = @{ $pdb[$i1] };

for my $i2 ( 1 .. $#pdb ){
my ( $x2, $y2, $z2 ) = @{ $pdb[$i2] };
my $dist = sqrt( ($x2-$x1)**2 + ($y2-$y1)**2 + ($z2-$z1)**2 );
print "distance from ( $x1, $y1, $z1 ) to ( $x2, $y2, $z2 ) is $dist\n";
}
}

Im completely stuck when it comes to picking all the elements in a row from file A and B ... i mean since i am picking from 6,7,8 only.. also the output should have all the details... Im new to perl and just so lost!! Any help would be really appreciated




We can do it within your budget,if interested contact our programmer live or put your requirement in our messegebord @ http://www.livefreelancer.net/