Hi, I am creating a program that calculates the distance between the x, y, z coordinates of atoms listed in a pdb file. So far i have this :
#!/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"; } }
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 (sorry wasn't able to attach or post link but easy to find if u put that name into google). Any help would be much appreciated as I am VERY new to Perl. Thanks

In reply to Calc distance between atoms in pdb file by stellaparallax

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.