//select sign combination with minimum standard deviation
if(var5<var6){
if(var5<var7){value=0;}
else{value=2;}
}
elseif(var6<var7){value=1;}
else{value=2;}
//BPV is average of cross products of all neighbor vectors which are part of 180 degree angles
BPV[i][0]=0;
BPV[i][1]=0;
BPV[i][2]=0;
for(k=0;k<count;k++){
if(value==0){
BPV[i][0]=BPV[i][0]+x5[k];
BPV[i][1]=BPV[i][1]+y5[k];
BPV[i][2]=BPV[i][2]+z5[k];
}
elseif(value==1){
BPV[i][0]=BPV[i][0]+x6[k];
BPV[i][1]=BPV[i][1]+y6[k];
BPV[i][2]=BPV[i][2]+z6[k];
}
else{
BPV[i][0]=BPV[i][0]+x7[k];
BPV[i][1]=BPV[i][1]+y7[k];
BPV[i][2]=BPV[i][2]+z7[k];
}
}
}
//for atoms with more than three 180 degree bond angles:
elseif(chi[0]>3){
doublex44[3],y44[3],z44[3],S0;
intl,m;
count=value=0;
S0=100000;
k2[0]=0;
k2[1]=0;
k2[2]=1;
j1[0]=1;
j1[1]=2;
j1[2]=2;
//algorithm is as above, but now all combinations of three 180 degree angles are compared, and the combination with minimum standard deviation is chosen
for(j=0;j<chi[0];j++){
for(k=j+1;k<chi[0];k++){
for(l=k+1;l<chi[0];l++){
if(k>=chi[0]||l>=chi[0])continue;
//get unique combination of three neighbor vectors