// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkaccessibility.cc
// Function: AccessibilityClass::setupAndFindChannels(ATOM_NETWORK*, ATOM_NETWORK*, bool, double, double)
void AccessibilityClass::setupAndFindChannels(ATOM_NETWORK *atmnet, ATOM_NETWORK *orgatmnet, bool highAccuracy, double r_probe_chan, double r_probe_sampl){

 r_probe = r_probe_sampl;

 highAccuracyFlag = highAccuracy;

 // Create a temporary copy of the atomic network in which each atom's radius has been increased by the probe radius
 if(highAccuracy)
   {
   atmnet->copy(&analyzedAtomNet);
   orgatmnet->copy(&orgAtomNet);
   }else{
   orgatmnet->copy(&analyzedAtomNet);
   orgatmnet->copy(&orgAtomNet);
   };
 for(unsigned int i = 0; i < orgAtomNet.atoms.size(); i++){ orgAtomNet.atoms[i].radius += r_probe; }
 for(unsigned int i = 0; i < analyzedAtomNet.atoms.size(); i++){ analyzedAtomNet.atoms[i].radius += r_probe; }

 // Calculate and store the Voronoi network for this new atomic network

 new_rad_con = (container_periodic_poly *)performVoronoiDecomp(true, &analyzedAtomNet, &vornet, advCells, false, vorcells);

//  Print vornet summary
 int noAccVorNodes = 0;
 for(unsigned int i = 0; i < vornet.nodes.size(); i++)
    {
    if(vornet.nodes.at(i).rad_stat_sphere > 0) noAccVorNodes++;
    };
 cout << "Voronoi network with " << vornet.nodes.size() << " nodes. " << noAccVorNodes << " of them are accessible. " << endl;

// CHANNEL::findChannels(&vornet, max(0.0, r_probe_chan - r_probe), &accessInfo, &channels);

 PORE::findChannelsAndPockets(&vornet, max(0.0, r_probe_chan - r_probe), &accessInfo, &pores);

 channelMapping.resize(accessInfo.size(),-1);
 pocketMapping.resize(accessInfo.size(),-1);
 n_channels = 0; n_pockets = 0; // number of channels and pockets
 for(unsigned int i = 0; i < pores.size(); i++)
   {
   if(pores[i].dimensionality>0)
    { // Channels
     for(unsigned int j = 0; j < pores[i].nodes.size(); j++)
       {
       channelMapping[pores[i].reverseIDMappings.find(j)->second] = n_channels;
       };
     n_channels++;
    }else
     { // Pockets
     for(unsigned int j = 0; j < pores[i].nodes.size(); j++)
       {
       pocketMapping[pores[i].reverseIDMappings.find(j)->second] = n_pockets;
       };
     n_pockets++;
    };

   };

/* DEBUG

for(unsigned int i = 0; i < accessInfo.size(); i++)
  {
  cout << "DEBUG: NodeID, radius, channelID, pocketID = " << i << "  ,   " << vornet.nodes.at(i).rad_stat_sphere << " ,  " << channelMapping[i] << "  ,  " << pocketMapping[i] << endl;
  };

END DEBUG */

// cout << "Accessibility setup: no channels = " << n_channels << " and no pockets = " << n_pockets << "/n";

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movsd %xmm0, 0x18(%rsp)
movq %rdx, %r15
movq %rdi, %rbx
movsd %xmm1, 0x9e8(%rdi)
movb %cl, 0x8c0(%rdi)
leaq 0x460(%rdi), %r14
testl %ecx, %ecx
cmoveq %rdx, %rsi
movq %rsi, %rdi
movq %r14, %rsi
callq 0x3eada
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3eada
movq 0x2f0(%rbx), %rcx
movq 0x2f8(%rbx), %rax
subq %rcx, %rax
movl $0x98, %esi
cqto
idivq %rsi
movq %rbx, 0x10(%rsp)
movsd 0x9e8(%rbx), %xmm0
xorl %edx, %edx
movl %edx, %edx
cmpq %rdx, %rax
jbe 0x6e443
imulq $0x98, %rdx, %rsi
movsd 0x30(%rcx,%rsi), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rcx,%rsi)
incl %edx
jmp 0x6e421
movq 0x10(%rsp), %rdi
movq 0x750(%rdi), %rcx
movq 0x758(%rdi), %rax
subq %rcx, %rax
movl $0x98, %esi
cqto
idivq %rsi
movsd 0x9e8(%rdi), %xmm0
xorl %edx, %edx
movl %edx, %edx
cmpq %rdx, %rax
jbe 0x6e48f
imulq $0x98, %rdx, %rsi
movsd 0x30(%rcx,%rsi), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rcx,%rsi)
incl %edx
jmp 0x6e46d
movq 0x10(%rsp), %rbx
leaq 0x8c8(%rbx), %r15
leaq 0x958(%rbx), %rcx
leaq 0x940(%rbx), %r9
pushq $0x1
popq %rdi
xorl %ebp, %ebp
movq %r14, %rsi
movq %r15, %rdx
xorl %r8d, %r8d
callq 0x52ae
movq %rax, 0x9f0(%rbx)
leaq 0x910(%rbx), %r14
xorl %eax, %eax
movl %eax, %r12d
movq 0x10(%rsp), %rcx
movq 0x918(%rcx), %rax
subq 0x910(%rcx), %rax
sarq $0x6, %rax
cmpq %r12, %rax
jbe 0x6e511
movq %r14, %rdi
movq %r12, %rsi
callq 0xa848
movsd 0x18(%rax), %xmm0
xorl %eax, %eax
ucomisd 0x91ddb(%rip), %xmm0    # 0x1002e0
seta %al
addl %eax, %ebp
leal 0x1(%r12), %eax
jmp 0x6e4cc
movq 0xe1aa8(%rip), %rdi     # 0x14ffc0
leaq 0x96981(%rip), %rsi     # 0x104ea0
callq 0x4480
movq 0x10(%rsp), %rbx
movq 0x918(%rbx), %rsi
subq 0x910(%rbx), %rsi
sarq $0x6, %rsi
movq %rax, %rdi
callq 0x42e0
leaq 0x904cf(%rip), %rsi     # 0xfea19
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
movl %ebp, %esi
callq 0x4760
leaq 0x96953(%rip), %rsi     # 0x104eb6
movq %rax, %rdi
callq 0x4480
movq %rax, %rdi
callq 0x4230
movsd 0x18(%rsp), %xmm0
subsd 0x9e8(%rbx), %xmm0
xorpd %xmm1, %xmm1
maxsd %xmm1, %xmm0
leaq 0x990(%rbx), %rsi
leaq 0x970(%rbx), %r14
movq %r15, %rdi
movq %r14, %rdx
callq 0x536c2
leaq 0x9b8(%rbx), %r15
movq 0x9a0(%rbx), %rax
movl 0x9a8(%rbx), %ecx
subq 0x990(%rbx), %rax
leaq (%rcx,%rax,8), %rsi
leaq 0xc(%rsp), %r12
orl $-0x1, (%r12)
movq %r15, %rdi
movq %r12, %rdx
callq 0x36f18
leaq 0x9d0(%rbx), %rdi
movq 0x9a0(%rbx), %rax
movl 0x9a8(%rbx), %ecx
subq 0x990(%rbx), %rax
leaq (%rcx,%rax,8), %rsi
orl $-0x1, (%r12)
leaq 0xc(%rsp), %rdx
movq %rdi, 0x18(%rsp)
callq 0x36f18
andq $0x0, 0x988(%rbx)
movq 0x970(%rbx), %rdi
xorl %ecx, %ecx
pushq $0x48
popq %rbp
movl %ecx, %ecx
movq 0x10(%rsp), %rax
movq 0x978(%rax), %rax
subq %rdi, %rax
cqto
movl $0x130, %esi            # imm = 0x130
idivq %rsi
cmpq %rcx, %rax
jbe 0x6e71f
movq %rcx, 0x20(%rsp)
imulq $0x130, %rcx, %r13      # imm = 0x130
cmpl $0x0, 0x108(%rdi,%r13)
jle 0x6e6b4
xorl %r12d, %r12d
movl %r12d, %ecx
movq 0x68(%rdi,%r13), %rax
subq 0x60(%rdi,%r13), %rax
cqto
idivq %rbp
movq 0x10(%rsp), %rdx
movl 0x988(%rdx), %ebx
cmpq %rcx, %rax
jbe 0x6e6a5
addq %r13, %rdi
addq $0x30, %rdi
movl %r12d, 0xc(%rsp)
leaq 0xc(%rsp), %rsi
callq 0x10996
movslq 0x24(%rax), %rax
movq (%r15), %rcx
movl %ebx, (%rcx,%rax,4)
incl %r12d
movq (%r14), %rdi
jmp 0x6e65b
incl %ebx
movq 0x10(%rsp), %rax
movl %ebx, 0x988(%rax)
jmp 0x6e713
xorl %r12d, %r12d
movl %r12d, %ecx
movq 0x68(%rdi,%r13), %rax
subq 0x60(%rdi,%r13), %rax
cqto
idivq %rbp
movq 0x10(%rsp), %rdx
movl 0x98c(%rdx), %ebx
cmpq %rcx, %rax
jbe 0x6e706
addq %r13, %rdi
addq $0x30, %rdi
movl %r12d, 0xc(%rsp)
leaq 0xc(%rsp), %rsi
callq 0x10996
movslq 0x24(%rax), %rax
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
movl %ebx, (%rcx,%rax,4)
incl %r12d
movq (%r14), %rdi
jmp 0x6e6b7
incl %ebx
movq 0x10(%rsp), %rax
movl %ebx, 0x98c(%rax)
movq 0x20(%rsp), %rcx
incl %ecx
jmp 0x6e61d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq