// File: /workspace/github_cpp_makefile_star2_O3/gjoni[P]iPot/src/Complex.cpp
// Function: Complex::SetInterface3(double)
void Complex::SetInterface3(double ksi) {

	/* maximal cut-off at a given ksi */
	double dmax = 0.0;
	for (int i = 0; i < 20; i++) {
		for (int j = i + 1; j < 20; j++) {
			double d = PCALIGN_DIST[i][j] + ksi * PCALIGN_STD[i][j];
			if (d > dmax) {
				dmax = d;
			}
		}
	}

	/* search for interface residues */
	kdres *res;
	double pos[3];
	double x, y, z, d;
	for (int i = 0; i < Ligand.nRes; i++) {

		Atom *A = Ligand.residue[i].CA;

		if (A == NULL) {
			continue;
		}

		/* check whether the current atom is within the bounding box
		 * of the Receptor */
		kdtree *kdCA = Receptor.kdCA;
		if (A->x < kdCA->rect->min[0] - dmax || A->y < kdCA->rect->min[1] - dmax
				|| A->z < kdCA->rect->min[2] - dmax
				|| A->x > kdCA->rect->max[0] + dmax
				|| A->y > kdCA->rect->max[1] + dmax
				|| A->z > kdCA->rect->max[2] + dmax) {

			continue;

		}

		/* find neighbors of A in the Receptor */
		res = kd_nearest_range3f(kdCA, A->x, A->y, A->z, dmax);
		while (!kd_res_end(res)) {
			Atom *A2 = (Atom*) kd_res_item(res, pos);
			int idxRec = A2->residue - Receptor.residue;
			int type1 = A2->residue->type;
			int type2 = Ligand.residue[i].type;

			if (type1 < 20 && type2 < 20) { /* process standard residues only */

				/* calculate residue-dependent cut-off */
				d = PCALIGN_DIST[type1][type2]
						+ ksi * PCALIGN_STD[type1][type2];

				/* find actual Ca-Ca distance */
				x = A->x - pos[0];
				y = A->y - pos[1];
				z = A->z - pos[2];

				if (sqrt(x * x + y * y + z * z) < d) {
					intRec[idxRec] = true;
					intLig[i] = true;
					contacts.push_back(std::make_pair(idxRec, i));
				}
			}

			kd_res_next(res);
		}
		kd_res_free(res);

	}

	ArrangeContatcs();

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
xorpd %xmm5, %xmm5
leaq 0xd05a(%rip), %rax      # 0x229d0
leaq 0xdcd3(%rip), %rcx      # 0x23650
xorl %edx, %edx
movl $0xa8, %esi
cmpq $0x12, %rdx
ja 0x159b9
movl $0x1, %edi
movapd %xmm5, %xmm1
movsd (%rcx,%rdi,8), %xmm5
mulsd %xmm0, %xmm5
addsd (%rax,%rdi,8), %xmm5
maxsd %xmm1, %xmm5
leaq (%rdx,%rdi), %r8
incq %r8
incq %rdi
movapd %xmm5, %xmm1
cmpq $0x14, %r8
jne 0x15993
incq %rdx
addq %rsi, %rax
addq %rsi, %rcx
cmpq $0x14, %rdx
jne 0x15984
movl 0xe8(%rbx), %eax
testl %eax, %eax
jle 0x15c03
cvtsd2ss %xmm5, %xmm3
xorl %r13d, %r13d
movq 0xe0(%rbx), %rcx
imulq $0x188, %r13, %r15      # imm = 0x188
movq 0x168(%rcx,%r15), %rbp
testq %rbp, %rbp
je 0x15bf4
movq 0x88(%rbx), %rdi
movsd 0x10(%rbp), %xmm4
movq 0x10(%rdi), %rcx
movq 0x8(%rcx), %rdx
movsd (%rdx), %xmm1
subsd %xmm5, %xmm1
ucomisd %xmm4, %xmm1
ja 0x15bf4
movsd 0x18(%rbp), %xmm1
movsd 0x8(%rdx), %xmm2
subsd %xmm5, %xmm2
ucomisd %xmm1, %xmm2
ja 0x15bf4
movsd 0x20(%rbp), %xmm2
movsd 0x10(%rdx), %xmm6
subsd %xmm5, %xmm6
ucomisd %xmm2, %xmm6
ja 0x15bf4
movq 0x10(%rcx), %rcx
movsd (%rcx), %xmm6
addsd %xmm5, %xmm6
ucomisd %xmm6, %xmm4
ja 0x15bf4
movsd 0x8(%rcx), %xmm6
addsd %xmm5, %xmm6
ucomisd %xmm6, %xmm1
ja 0x15bf4
movsd 0x10(%rcx), %xmm6
addsd %xmm5, %xmm6
ucomisd %xmm6, %xmm2
ja 0x15bf4
movsd %xmm5, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtsd2ss %xmm4, %xmm0
cvtsd2ss %xmm1, %xmm1
cvtsd2ss %xmm2, %xmm2
movss %xmm3, 0x4(%rsp)
callq 0x17fd5
movq %rax, %r12
movq %rax, %rdi
callq 0x18006
testl %eax, %eax
jne 0x15bd4
movq %r13, %r14
shlq $0x20, %r14
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x18026
movq 0x40(%rax), %rax
movsbq (%rax), %rcx
cmpq $0x14, %rcx
setl %sil
movq 0xe0(%rbx), %rdx
movb (%rdx,%r15), %dl
cmpb $0x14, %dl
setl %dil
andb %sil, %dil
cmpb $0x1, %dil
jne 0x15bbc
movsbq %dl, %rdx
shlq $0x5, %rcx
leaq (%rcx,%rcx,4), %rcx
leaq 0xceb3(%rip), %rsi      # 0x229d0
addq %rcx, %rsi
leaq 0xdb29(%rip), %rdi      # 0x23650
addq %rdi, %rcx
movsd (%rcx,%rdx,8), %xmm0
mulsd 0x8(%rsp), %xmm0
addsd (%rsi,%rdx,8), %xmm0
movsd 0x10(%rbp), %xmm1
movsd 0x18(%rbp), %xmm2
subsd 0x20(%rsp), %xmm1
subsd 0x28(%rsp), %xmm2
movsd 0x20(%rbp), %xmm3
subsd 0x30(%rsp), %xmm3
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm3, %xmm3
addsd %xmm1, %xmm3
xorps %xmm1, %xmm1
sqrtsd %xmm3, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x15bbc
subq 0x70(%rbx), %rax
sarq $0x3, %rax
movabsq $0x7d6343eb1a1f58d1, %rcx # imm = 0x7D6343EB1A1F58D1
imulq %rcx, %rax
movq 0x18(%rbx), %rcx
cltq
movb $0x1, %dl
movb %dl, (%rcx,%rax)
movq 0x20(%rbx), %rcx
movb %dl, (%rcx,%r13)
movl %eax, %eax
orq %r14, %rax
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
leaq 0x18(%rsp), %rsi
callq 0x1639c
movq %r12, %rdi
callq 0x18011
movq %r12, %rdi
callq 0x18006
testl %eax, %eax
je 0x15ace
movq %r12, %rdi
callq 0x17a3c
movl 0xe8(%rbx), %eax
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm5
movss 0x4(%rsp), %xmm3
incq %r13
movslq %eax, %rcx
cmpq %rcx, %r13
jl 0x159dd
movq %rbx, %rdi
callq 0x1573a
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq