// File: Luthaf[P]zeopp/grid.cc
// Function: GaussianCube::calculateDistanceGridWithAccessibilityInfo(ATOM_NETWORK*, ATOM_NETWORK*, bool, double)
void GaussianCube::calculateDistanceGridWithAccessibilityInfo(ATOM_NETWORK *atmnet, ATOM_NETWORK *orgatmnet, bool highAccuracy, double probe_radius){

 AccessibilityClass accessAnalysis;
 if(highAccuracy) accessAnalysis.setupAndFindChannels(atmnet, orgatmnet, highAccuracy, probe_radius, probe_radius);
   else accessAnalysis.setupAndFindChannels(atmnet, atmnet, highAccuracy, probe_radius, probe_radius);

 for(int x=0; x<na; x++)
   for(int y=0; y<nb; y++)
     for(int z=0; z<nc; z++)
       {
       bool overlaps = false;
       bool inside = false;
       Point point(o.x+x*va.x+y*vb.x+z*vc.x,
                 o.y+x*va.y+y*vb.y+z*vc.y,
                 o.z+x*va.z+y*vb.z+z*vc.z);
       double dist_var;
       pair<bool,bool> answer = (accessAnalysis.isVPointInsideAtomAndNotAccessible(point, dist_var));
       inside = answer.first; overlaps = answer.second;

       if(accessAnalysis.needToResample() == true)
          {
          cout << "Need to resample in grid calc. Abort." << "Contact the author" << endl;
          abort();
          };

       double dist;

//       dist = accessAnalysis.lastMinDist();
//       if(inside == false && overlaps == true) dist = dist * -1.0;
  
       if(inside == true)
         {
         dist = 0.0;
         } else
         {
         dist = accessAnalysis.lastMinDist()-probe_radius;
         if(overlaps == true) dist = dist * -1.0;
         };

       cube[x][y][z]=dist;
       };

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb20, %rsp            # imm = 0xB20
movb %cl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
andb $0x1, %al
movb %al, -0x19(%rbp)
movsd %xmm0, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xae0(%rbp)
leaq -0xa68(%rbp), %rdi
callq 0x84640
testb $0x1, -0x19(%rbp)
je 0xf18da
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
movsd -0x28(%rbp), %xmm1
movzbl -0x19(%rbp), %ecx
andl $0x1, %ecx
leaq -0xa68(%rbp), %rdi
movaps %xmm1, %xmm0
callq 0xfd200
jmp 0xf18b5
jmp 0xf1900
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa70(%rbp)
movl %eax, -0xa74(%rbp)
leaq -0xa68(%rbp), %rdi
callq 0x84a30
jmp 0xf1c22
movq -0x10(%rbp), %rdx
movsd -0x28(%rbp), %xmm1
movzbl -0x19(%rbp), %ecx
andl $0x1, %ecx
leaq -0xa68(%rbp), %rdi
movq %rdx, %rsi
movaps %xmm1, %xmm0
callq 0xfd200
jmp 0xf18fe
jmp 0xf1900
movl $0x0, -0xa78(%rbp)
movq -0xae0(%rbp), %rcx
movl -0xa78(%rbp), %eax
cmpl 0x78(%rcx), %eax
jge 0xf1c0d
movl $0x0, -0xa7c(%rbp)
movq -0xae0(%rbp), %rcx
movl -0xa7c(%rbp), %eax
cmpl 0x7c(%rcx), %eax
jge 0xf1bf7
movl $0x0, -0xa80(%rbp)
movq -0xae0(%rbp), %rcx
movl -0xa80(%rbp), %eax
cmpl 0x80(%rcx), %eax
jge 0xf1be1
movq -0xae0(%rbp), %rax
movb $0x0, -0xa81(%rbp)
movb $0x0, -0xa82(%rbp)
cvtsi2sdl -0xa78(%rbp), %xmm4
movsd 0x18(%rax), %xmm1
movaps %xmm4, %xmm0
mulsd %xmm1, %xmm0
movsd (%rax), %xmm1
movsd 0x8(%rax), %xmm5
addsd %xmm1, %xmm0
cvtsi2sdl -0xa7c(%rbp), %xmm3
movsd 0x30(%rax), %xmm2
movaps %xmm3, %xmm1
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
cvtsi2sdl -0xa80(%rbp), %xmm2
movsd 0x48(%rax), %xmm6
movaps %xmm2, %xmm0
mulsd %xmm6, %xmm0
addsd %xmm1, %xmm0
movsd 0x20(%rax), %xmm6
movaps %xmm4, %xmm1
mulsd %xmm6, %xmm1
addsd %xmm5, %xmm1
movsd 0x38(%rax), %xmm6
movaps %xmm3, %xmm5
mulsd %xmm6, %xmm5
addsd %xmm1, %xmm5
movsd 0x50(%rax), %xmm6
movaps %xmm2, %xmm1
mulsd %xmm6, %xmm1
addsd %xmm5, %xmm1
movsd 0x10(%rax), %xmm5
movsd 0x28(%rax), %xmm6
mulsd %xmm6, %xmm4
addsd %xmm5, %xmm4
movsd 0x40(%rax), %xmm5
mulsd %xmm5, %xmm3
addsd %xmm4, %xmm3
movsd 0x58(%rax), %xmm4
mulsd %xmm4, %xmm2
addsd %xmm3, %xmm2
leaq -0xaa0(%rbp), %rdi
callq 0xe9c70
jmp 0xf1a33
movq -0xa90(%rbp), %rax
movq %rax, -0xac0(%rbp)
movups -0xaa0(%rbp), %xmm0
movaps %xmm0, -0xad0(%rbp)
movq -0xac0(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movaps -0xad0(%rbp), %xmm0
movups %xmm0, (%rax)
leaq -0xa68(%rbp), %rdi
leaq -0xaa8(%rbp), %rsi
callq 0xfd890
movw %ax, -0xae2(%rbp)
jmp 0xf1a83
movw -0xae2(%rbp), %ax
movw %ax, -0xaaa(%rbp)
movb -0xaaa(%rbp), %al
andb $0x1, %al
movb %al, -0xa82(%rbp)
movb -0xaa9(%rbp), %al
andb $0x1, %al
movb %al, -0xa81(%rbp)
leaq -0xa68(%rbp), %rdi
callq 0x847d0
movb %al, -0xae3(%rbp)
jmp 0xf1ac1
movb -0xae3(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0xf1b23
movq 0x1814e8(%rip), %rdi    # 0x272fc0
leaq 0x10ab95(%rip), %rsi    # 0x1fc674
callq 0x5540
movq %rax, -0xaf0(%rbp)
jmp 0xf1aed
movq -0xaf0(%rbp), %rdi
leaq 0x10ab9f(%rip), %rsi    # 0x1fc69a
callq 0x5540
movq %rax, -0xaf8(%rbp)
jmp 0xf1b09
movq -0xaf8(%rbp), %rdi
movq 0x181481(%rip), %rsi    # 0x272f98
callq 0x55b0
jmp 0xf1b1e
callq 0x52b0
movb -0xa82(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0xf1b40
xorps %xmm0, %xmm0
movsd %xmm0, -0xad8(%rbp)
jmp 0xf1b95
leaq -0xa68(%rbp), %rdi
callq 0x849b0
movsd %xmm0, -0xb00(%rbp)
jmp 0xf1b56
movsd -0xb00(%rbp), %xmm0
subsd -0x28(%rbp), %xmm0
movsd %xmm0, -0xad8(%rbp)
movb -0xa81(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x1, %eax
jne 0xf1b93
movsd 0x100bf5(%rip), %xmm0   # 0x1f2778
mulsd -0xad8(%rbp), %xmm0
movsd %xmm0, -0xad8(%rbp)
jmp 0xf1b95
movq -0xae0(%rbp), %rax
movsd -0xad8(%rbp), %xmm0
movq 0x88(%rax), %rax
movslq -0xa78(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xa7c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0xa80(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0xa80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa80(%rbp)
jmp 0xf194a
jmp 0xf1be3
movl -0xa7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa7c(%rbp)
jmp 0xf192a
jmp 0xf1bf9
movl -0xa78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xa78(%rbp)
jmp 0xf190a
leaq -0xa68(%rbp), %rdi
callq 0x84a30
addq $0xb20, %rsp            # imm = 0xB20
popq %rbp
retq
movq -0xa70(%rbp), %rdi
callq 0x58f0
nop