我有两个阵列,每个阵列都有一组3D点的坐标。我通过应用翻译叠加了两者。我想从阵列中消除一些点(红球)与第二阵列(棒)的某个截止距离。
use List::Util 'max';
open(FILE,"1L2Y.pdb");
@pro_cont=<FILE>;
######################## CENTROID OF sticks ##########################################
foreach (@pro_cont){
if (/^ATOM/){
$lines++;
@array=split('',$_);
@x=@array[31..38];
$x=join('',@x);
$x=~s/\s//g;
@y=@array[39..46];
$y=join('',@y);
$y=~s/\s//g;
@z=@array[47..54];
$z=join('',@z);
$z=~s/\s//g;
$sum_x+=$x;
$sum_y+=$y;
$sum_z+=$z;
}}
$avg_x=sprintf "%.3f",($sum_x/$lines);
$avg_y=sprintf "%.3f",($sum_y/$lines);
$avg_z=sprintf "%.3f",($sum_z/$lines);
print "The centroid of protein is $avg_x, $avg_y, $avg_z \n";
################################################################################################
######################RADIUS OF sticks######################################
foreach (@pro_cont){
if (/^ATOM/){
$lines++;
@array=split('',$_);
@x=@array[31..38];
$x=join('',@x);
$x=~s/\s//g;
@y=@array[39..46];
$y=join('',@y);
$y=~s/\s//g;
@z=@array[47..54];
$z=join('',@z);
$z=~s/\s//g;
$dx=$avg_x-$x;
$dy=$avg_y-$y;
$dz=$avg_z-$z;
$distance=sqrt(($dx**2)+($dy**2)+($dz**2));
push(@array_distance,$distance);
}}
$max=max(@array_distance);
$radius=sprintf "%.1f",$max;
print "The Radius of protein is $radius \n";
###############################################################################
################ points GRID ###########################
@arr_grid=();
$g=0;
$diameter=$radius*2;
for($i=0.000;$i<=$diameter;$i+=2.000){
for($j=0.000;$j<=$diameter;$j+=2.000){
for($k=0.000;$k<=$diameter;$k+=2.000){
$i=~ s/(....).*/$1/g;
$j=~ s/(....).*/$1/g;
$k=~ s/(....).*/$1/g;
@arr_grid[$g]=$i." ".$j." ".$k."\n";
$g++;
}}}
$c=scalar @arr_grid;
for($l=0;$l<$c;$l++){
#print "HETATM O @arr_grid[$l]\n";
}
foreach (@arr_grid){
@line=split('\s+',$_);
@x_grid=@line[0];
$x_grid=join('',@x_grid);
$x_grid=~s/\s//g;
@y_grid=@line[1];
$y_grid=join('',@y_grid);
$y_grid=~s/\s//g;
@z_grid=@line[2];
$z_grid=join('',@z_grid);
$z_grid=~s/\s//g;
$sum_x_grid+=$x_grid;
$sum_y_grid+=$y_grid;
$sum_z_grid+=$z_grid;
}
$avg_x_grid=sprintf "%.3f",($sum_x_grid/$c);
$avg_y_grid=sprintf "%.3f",($sum_y_grid/$c);
$avg_z_grid=sprintf "%.3f",($sum_z_grid/$c);
print "Centroid of grid is $avg_x_grid,$avg_y_grid,$avg_z_grid";
$diff_x=sprintf"%.0f",($avg_x_grid-$avg_x);
$diff_y=sprintf"%.0f",($avg_y_grid-$avg_y);
$diff_z=sprintf"%.0f",($avg_z_grid-$avg_z);
foreach (@arr_grid){
@line=split('\s+',$_);
@x_grid=@line[0];
$x_grid=join('',@x_grid);
$x_grid=~s/\s//g;
@y_grid=@line[1];
$y_grid=join('',@y_grid);
$y_grid=~s/\s//g;
@z_grid=@line[2];
$z_grid=join('',@z_grid);
$z_grid=~s/\s//g;
$i=$x_grid-$diff_x;
$j=$y_grid-$diff_y;
$k=$z_grid-$diff_z;
print "HETATM O $i $j $k\n";
}
foreach (@arr_grid){
@line=split('\s+',$_);
@x_grid=@line[0];
$x_grid=join('',@x_grid);
$x_grid=~s/\s//g;
@y_grid=@line[1];
$y_grid=join('',@y_grid);
$y_grid=~s/\s//g;
@z_grid=@line[2];
$z_grid=join('',@z_grid);
$z_grid=~s/\s//g;
$dx_grid=$avg_x_grid-$x_grid;
$dy_grid=$avg_y_grid-$y_grid;
$dz_grid=$avg_z_grid-$z_grid;
$distance_grid=sqrt(($dx_grid**2)+($dy_grid**2)+($dz_grid**2));
if($distance_grid <=10){
#print "HETATM O $x_grid $y_grid $z_grid\n";
}}
并且代码继续,我在没有做任何家庭工作的情况下发布了这个问题,我做了我可以做的事情,为什么我得到了新的投票,我明白了。
答案 0 :(得分:1)
foreach my $s (@sticks) {
my @keepers=();
foreach my $p (@points) {
push @keepers, $p if $s->distance($p) > $cutoff;
}
@points=@keepers;
}
上面的伪代码是二次的并且进行了大量的复制(我不知道如果你将当前的点拼接出来,内部循环将会做什么,而且我太懒了看它。它应该做什么你说但是。