// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq %rdi, %rbx
xorpd %xmm5, %xmm5
leaq 0xcf16(%rip), %rax      # 0x229e0
leaq 0xdb8f(%rip), %rcx      # 0x23660
xorl %edx, %edx
movl $0xa8, %esi
cmpq $0x12, %rdx
ja 0x15b0d
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 0x15ae7
incq %rdx
addq %rsi, %rax
addq %rsi, %rcx
cmpq $0x14, %rdx
jne 0x15ad8
cmpl $0x0, 0xe8(%rbx)
jle 0x15d75
cvtsd2ss %xmm5, %xmm3
xorl %r13d, %r13d
movq 0xe0(%rbx), %rax
imulq $0x188, %r13, %r15      # imm = 0x188
movq 0x168(%rax,%r15), %rbp
testq %rbp, %rbp
je 0x15d62
movq 0x88(%rbx), %rdi
movsd 0x10(%rbp), %xmm4
movq 0x10(%rdi), %rax
movq 0x8(%rax), %rcx
movsd (%rcx), %xmm1
subsd %xmm5, %xmm1
ucomisd %xmm4, %xmm1
ja 0x15d62
movsd 0x18(%rbp), %xmm1
movsd 0x8(%rcx), %xmm2
subsd %xmm5, %xmm2
ucomisd %xmm1, %xmm2
ja 0x15d62
movsd 0x20(%rbp), %xmm2
movsd 0x10(%rcx), %xmm6
subsd %xmm5, %xmm6
ucomisd %xmm2, %xmm6
ja 0x15d62
movq 0x10(%rax), %rax
movsd (%rax), %xmm6
addsd %xmm5, %xmm6
ucomisd %xmm6, %xmm4
ja 0x15d62
movsd 0x8(%rax), %xmm6
addsd %xmm5, %xmm6
ucomisd %xmm6, %xmm1
ja 0x15d62
movsd 0x10(%rax), %xmm6
addsd %xmm5, %xmm6
ucomisd %xmm6, %xmm2
ja 0x15d62
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 0x181ac
movq %rax, %r12
movq %rax, %rdi
callq 0x181e8
testl %eax, %eax
jne 0x15d48
movq %r13, %rax
shlq $0x20, %rax
movq %rax, 0x18(%rsp)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
callq 0x18208
movq 0x40(%rax), %r14
movsbq (%r14), %rax
cmpq $0x14, %rax
setl %dl
movq 0xe0(%rbx), %rcx
movb (%rcx,%r15), %cl
cmpb $0x14, %cl
setl %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x15d30
movsbq %cl, %rcx
shlq $0x5, %rax
leaq (%rax,%rax,4), %rax
leaq 0xcd6c(%rip), %rdx      # 0x229e0
addq %rax, %rdx
leaq 0xd9e2(%rip), %rsi      # 0x23660
addq %rsi, %rax
movsd (%rax,%rcx,8), %xmm3
mulsd 0x8(%rsp), %xmm3
addsd (%rdx,%rcx,8), %xmm3
movsd 0x10(%rbp), %xmm1
movsd 0x18(%rbp), %xmm2
subsd 0x30(%rsp), %xmm1
subsd 0x38(%rsp), %xmm2
movsd 0x20(%rbp), %xmm0
subsd 0x40(%rsp), %xmm0
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
subq 0x70(%rbx), %r14
ucomisd 0xb3de(%rip), %xmm0     # 0x210b0
jb 0x15cda
sqrtsd %xmm0, %xmm0
jmp 0x15ceb
movsd %xmm3, 0x20(%rsp)
callq 0x21b0
movsd 0x20(%rsp), %xmm3
ucomisd %xmm0, %xmm3
jbe 0x15d30
sarq $0x3, %r14
movabsq $0x7d6343eb1a1f58d1, %rax # imm = 0x7D6343EB1A1F58D1
imulq %rax, %r14
movq 0x18(%rbx), %rax
movslq %r14d, %rcx
movb $0x1, %dl
movb %dl, (%rax,%rcx)
movq 0x20(%rbx), %rax
movb %dl, (%rax,%r13)
movl %ecx, %eax
orq 0x18(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
callq 0x16534
movq %r12, %rdi
callq 0x181f3
movq %r12, %rdi
callq 0x181e8
testl %eax, %eax
je 0x15c26
movq %r12, %rdi
callq 0x17c0b
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm5
movss 0x4(%rsp), %xmm3
incq %r13
movslq 0xe8(%rbx), %rax
cmpq %rax, %r13
jl 0x15b30
movq %rbx, %rdi
callq 0x15898
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq