I hard-coded the input file names for my own convenience while testing.

somewhat optimised - I like to think of it as a good mix between obvious and efficient.

#!/usr/bin/perl -w use strict; my @solvents; my @structs; my @fields = qw(atom number name resname resnumber xpos ypos zpos q ra +dius); slurp_file(\@solvents, "solv.txt"); slurp_file(\@structs, "struct.txt"); print "Atoms in solvent file is ", scalar(@solvents), "\n"; print "Atoms in structure file is ", scalar(@structs), "\n"; my @desBooli = map {0} @solvents; # could be done other ways open(test2, ">OverL.txt") or die ("Couldn't open file OverL.txt :: $!\n"); for (my $i = 0; $i < @solvents; $i++) { for (my $j = 0; $j < @structs; $j++) { # I am sure there is a better way my $dist = sqrt(($solvents[$i]->{xpos} - $structs[$j]->{xpos})**2+ ($solvents[$i]->{ypos} - $structs[$j]->{ypos})**2+ ($solvents[$i]->{zpos} - $structs[$j]->{zpos})**2) +; my $radSum = $solvents[$i]->{radius} + $structs[$j]->{radius}; if($dist < $radSum) { print test2 "$i - Overlap for atoms solvent $solvents[$i]->{resn +umber} and structure $structs[$j]->{resnumber}\n"; $desBooli[$i] = 1; } } } close test2; open(test1, ">Solvent.pdb") or die ("Couldn't open file Solvent.pdb :: $!\n"); for (my $i = 0; $i < @solvents; $i++) { if ($desBooli[$i] == 0){ # no overlap print test1 dump_solvent($solvents[$i]), "\n"; } } close test1; exit; sub slurp_file { my ($array, $name) = @_; open(FILE, $name) or die ("Couldn't open file $name:: $!\n"); while (<FILE>) { chomp; # trim line endings next if /^\s*$/; # strip blank lines my %hash = (); @hash{@fields} = split /\s+/; # hash slice push @{$array}, \%hash; } use Data::Dumper; close FILE; } sub dump_solvent { my ($solvent) = @_; join ' ', @{$solvent}{@fields}; }

In reply to Re: checking for overlap by leriksen
in thread checking for overlap by ioana

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.