I am trying to use your suggestion, but also at the same time, create an array of "Atoms" such that I can calculate the distance between the Zinc atom and all other OD2 and NE2 atoms. So I am trying to use ++$num to tally up the number of OD2s and NE2s It would appear that the problem is in the this line

push $Atoms$num, unpack $xyz_fmt, $pdbline;

#!/usr/bin/perl -W #subroutines for calculations use strict; sub distanceAB($$$$$$) { my ($x1,$y1,$z1,$x2,$y2,$z2) = @_; $distance = sqrt (($x2-$x1)**2 + ($y2 -$y1)**2 + ($z2-$z1)**2); return sprintf("%4.2f", $distance); } #open files for calculations and modify distance cutoff for target res +idues $input=$ARGV[0]; open(IN, "$input"); $num = 0; $count = 0; my $xyz_fmt = '@30a8 @38a8 @46a8'; while ($pdbline = <IN>) { if ($pdbline =~ m/ZN1 LG1 X/) { @ZN = unpack $xyz_fmt, $pdbline; next; } #find xyz coordinates for other atoms and store in array if ($pdbline =~ /^ATOM.*(OD2 ASP|NE2 HIS)/) { push $Atoms[$num], [unpack $xyz_fmt, $pdbline]; $resname[$num] = substr($pdbline, 16, 3); $resnumber[$num] = substr($pdbline, 22, 3); ++$num; } } #count number of potential coordinating atoms if ($pdbline =~ /OD2 ASP/ or $pdbline =~ /NE2 HIS/) { ++$count; } #calculate Zn to each atom distance foreach $i (0..$count) { $Zndistance=distanceAB($x1[$ZN[0]],$y1[$ZN[1]],$z1[$ZN[2]],$x2[$At +oms[$i][0]],$y2[$Atoms[$i][1]],$z2[$Atoms[$i][2]]); if ($Zndistance < 2.5) { $distanceAB=$Zndistance; print "$distanceAB \n"; print "$resname[$i] $resnumber[$i] \n"; } }

In reply to Re^2: calculate distance between atoms and a target atom by mishimakaz
in thread calculate distance between atoms and a target atom by mishimakaz

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.