I am trying to find the distance between objects in 3D from a Protein Data Base file (PDB). A PDB file looks like this.
Example:
ATOM 1 N GLU 1 -19.992 -2.816 36.359 0.00 0.00 PROT
ATOM 2 HT1 GLU 1 -19.781 -1.880 35.958 0.00 0.00 PROT
ATOM 3 HT2 GLU 1 -19.713 -2.740 37.358 0.00 0.00 PROT
ATOM 4 HT3 GLU 1 -21.027 -2.910 36.393 0.00 0.00 PROT
ATOM 5 CA GLU 1 -19.344 -3.944 35.652 0.00 0.00 PROT
ATOM 6 HA GLU 1 -19.817 -4.852 35.998 0.00 0.00 PROT
ATOM 7 CB GLU 1 -19.501 -3.795 34.119 0.00 0.00 PROT
I am trying to take the first row of 5 digit numbers the x coordinates and make them into an array. The Final column that says PROT
changes to MEM1
later in the PDB file. I am trying to subtract all the MEM1
x coordinates from the Prot
x coordinates by putting them into two arrays.
I currently have:
#!/usr/bin/perl
use warnings;
my $inputfile = '8ns_emb_alt_101.pdb';
open( INPUTFILE, "<", $inputfile ) or die $!;
my @array = <INPUTFILE>;
$protein = 'PROT';
for ( $line = 0; $line <= $#array; ++$line ) {
if ( $array[$line] =~ m/\s+$protein\s+/ ) {
chomp $array[$line];
@splitline = ( split /\s+/, $array[$line] );
@protx = $splitline[5];
} #if 1
} # for 1
print "@protx \n";
print "$splitline[5] \n";
The only thing that @protx
and $splitline[5]
prints is the last x coordinate of the PROT
section of the PDB. I need all of them printed. My overall objective is to find the distance between each atom of the protein PROT
against each atom of the membrane MEM
by using d = sqrt((deltaX)^2+(deltay)^2+(deltaz)^2)
. Then when d < 5
it will print the resID, which is 1 in this case and corresponds with GLU
.
Instead of assigning a value to the array (which in fact assigns it to its first element, overwriting the previously assigned value)
@protx = $splitline[5];
push the value into it:
push @protx, $splitline[5];