Hi,
I want to check for overlap of two files.
In both files the lines look this way:
ATOM 1 K+ K+ 1 27.261 7.934 32.141 1.0000 1.000
ATOM 1 N ALA 1 -12.149 -11.899 13.144 0.1414 1.550
Columns 6-8 contain the x.y,z coordinates, and the last column
contains the radius. I want to remove from <SOLVFILE> all the entries that
overlap with the <STRUCTFILE>. The overlap criteria is that
the distance between entries in SOLVFILE and entries in STRUCTFILE
should be larger than the sum of the radii. If d<R1+R2 consider an overlap and remove the line from the <SOLVFILE>
Here is the code
#!/usr/bin/perl -w @desBooli = (); @ATOM = (); @atmnb1 = (); @atmname1 = (); @resname1 = (); @resnb1 = (); @rest1 = (); @x1 = (); @y1 = (); @z1 = (); @q1 = (); @rad1 = (); @atmnb2 = (); @atmname2 = (); @resname2 = (); @resnb2 = (); @x2 = (); @y2 = (); @z2 = (); @q2 = (); @rad2 = (); print "Please type the filename with the solvent: "; $file1 = <STDIN>; chomp $file1; #Does the file exist? unless ( -e $file1) { print "File \"$file1\" doesn\'t seem to exist!!\n"; exit; } #Can we open the file? open(SOLVFILE, $file1) || die("Couldn't open file $file1\n"); print "Please type the filename with the structure: "; $file2 = <STDIN>; chomp $file2; #Does the file exist? unless ( -e $file2) { print "File \"$file2\" doesn\'t seem to exist!!\n"; exit; } #Can we open the file? open(STRUCTFILE, $file2) || die ("Couldn't open file $file2\n"); open(test1, ">Solvent.pdb"); open(test2, ">OverL.txt"); $i=0; while ($line=<SOLVFILE>) { chop($line); $rest1[$i] = $line; ($ATOM, $atomnb1[$i], $atmname1[$i],$resname1[$i],$resnb1[$i],$x1[$i], +$y1[$i],$z1[$i],$q1[$i],$rad1[$i])= split(/\s+/, $line); $i++; } $Nsolv = $i; print "Number of atoms in solvent file is $Nsolv \n"; $i = 0; while ($line=<STRUCTFILE>) { chop($line); ($ATOM, $atomnb2[$i], $atmname2[$i],$resname2[$i],$resnb2[$i],$x2[$i], +$y2[$i],$z2[$i],$q2[$i],$rad2[$i])= split(/\s+/, $line); $i++; } $Nstruct = $i; print "Number of atoms in structure file is $Nstruct \n"; for ($i = 0; $i <=$Nsolv-1; $i++) { $desBooli[$i] = 0; } for ($i = 0; $i <=$Nsolv-1; $i++) { for ($j = 0; $j <=$Nstruct-1; $j++) { $dist = sqrt(($x1[$i]-$x2[$j])*($x1[$i]-$x2[$j])+($z1[$i]-$z2[$j])*($z +1[$i]-$z2[$j])+($z1[$i]-$z2[$j])*($z1[$i]-$z2[$j])); $radSum = $rad1[$i] +$rad2[$j]; if($dist < $radSum) { print test2 "Overlap for atoms $atomnb1[$i] and $atomnb2[$j]\n"; $desBooli[$i] = 1; } } } $i = 0; for ($i = 0; $i <=$Nsolv-1; $i++) { if ($desBooli[$i] == 0){ print test1 "$rest1[$i]\n" } } close STRUCTFILE; close SOLVFILE; close test1; close test2; exit;

In reply to 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.