Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   Distance between XYZ coordinates in pdb file (http://www.go4expert.com/forums/distance-xyz-coordinates-pdb-file-t28299/)

stellaparallax 29Apr2012 17:13

Distance between XYZ coordinates in pdb file
 
Hi,

I am creating a program that calculates the disance between the x, y, z coordinates of atoms listed in a pdb file.

When I run the program i get this message popping up for some of the lines and I don't know what to do to fix it:

"Use of uninitialized value in subtraction (-) at ./gas.pl line 42, <> line 14368"

The line that it states is the last line of the pdb file, however i don't see why this line is involved in my calculations as this is not present in any of my arrays.

The pdb file I'm using is 3PBL.pdb (attached)

Any help would be much appreciated as I am VERY new to Perl. I also am aware that my code isn't very pretty, but I am really only concered with getting it to work at this stage.

Thanks



Code:


#!/usr/bin/perl -w

$num = 0;
$count = 0;


while (<>) { 
   

# Find x, y, z coordinates and store in separate arrays
 

if ($_ =~ /^ATOM/) {
 

        @line = $_ =~ m/^(.....).(.....).(....).(...)..(....)....(........)(........)(........)/;


        $x = $line[5];
         
        $arrayx[$num] = $x;


        $y = $line[6];
                           
        $arrayy[$num] = $y;


        $z = $line[7];
         
        $arrayz[$num] = $z;


        ++$num;       
         
    }   


# Count number of atoms
 

    if ($_ =~ /^ATOM/) {
     
        ++$count;

    }

}


# Calculate distance between all atom coordinates
 

foreach $i (0..$count) {
 
    foreach $j ($i + 1..$count) {
 

    $dist = sqrt(
     
                ($arrayx[$i] - $arrayx[$j])**2 +

                ($arrayy[$i] - $arrayy[$j])**2 +

                ($arrayz[$i] - $arrayz[$j])**2

            );


    print "$dist\n"
     
    }
     
}




All times are GMT +5.5. The time now is 15:43.