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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |