Distance between XYZ coordinates in pdb file

Discussion in 'Perl' started by stellaparallax, Apr 29, 2012.

  1. stellaparallax

    stellaparallax New Member

    Joined:
    Apr 29, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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:
    [FONT=Courier New]
    #!/usr/bin/perl -w
    
    $num = 0;
    $count = 0;
    
    
    while (<>) {  [/FONT]    [FONT=Courier New]
    
    # Find x, y, z coordinates and store in separate arrays[/FONT]   [FONT=Courier New]
    
    if ($_ =~ /^ATOM/) {[/FONT]   [FONT=Courier New]
    
            @line = $_ =~ m/^(.....).(.....).(....).(...)..(....)....(........)(........)(........)/;[/FONT] [FONT=Courier New]
    
            $x = $line[5];[/FONT]           [FONT=Courier New]
            $arrayx[$num] = $x;[/FONT] [FONT=Courier New]
    
            $y = $line[6];[/FONT]                            [FONT=Courier New]
            $arrayy[$num] = $y;[/FONT] [FONT=Courier New]
    
            $z = $line[7];[/FONT]           [FONT=Courier New]
            $arrayz[$num] = $z;[/FONT] [FONT=Courier New]
    
            ++$num;        [/FONT]           [FONT=Courier New]
        }    [/FONT] [FONT=Courier New]
    
    # Count number of atoms[/FONT]   [FONT=Courier New]
    
        if ($_ =~ /^ATOM/) {[/FONT]       [FONT=Courier New]
            ++$count;[/FONT] [FONT=Courier New]
        }[/FONT] [FONT=Courier New]
    }[/FONT] [FONT=Courier New]
    
    # Calculate distance between all atom coordinates[/FONT]   [FONT=Courier New]
    
    foreach $i (0..$count) {[/FONT]   [FONT=Courier New]
        foreach $j ($i + 1..$count) {[/FONT]   [FONT=Courier New]
    
        $dist = sqrt([/FONT]       [FONT=Courier New]
                    ($arrayx[$i] - $arrayx[$j])**2 + [/FONT] [FONT=Courier New]
                    ($arrayy[$i] - $arrayy[$j])**2 + [/FONT] [FONT=Courier New]
                    ($arrayz[$i] - $arrayz[$j])**2[/FONT] [FONT=Courier New]
                );[/FONT] [FONT=Courier New]
    
        print "$dist\n"[/FONT]       [FONT=Courier New]
        }[/FONT]       [FONT=Courier New]
    }[/FONT] [FONT=Courier New]
    [/FONT]
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice