// File: /workspace/github_cpp_makefile_star2_O2/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 0xc210(%rip), %rax      # 0x209d0
leaq 0xce89(%rip), %rcx      # 0x21650
xorl %edx, %edx
pushq $0x1
popq %rsi
movl $0xa8, %edi
cmpq $0x14, %rdx
je 0x1480c
movq %rsi, %r8
leaq (%rdx,%r8), %r9
cmpq $0x14, %r9
je 0x14801
movsd (%rcx,%r8,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%rax,%r8,8), %xmm1
maxsd %xmm5, %xmm1
incq %r8
movapd %xmm1, %xmm5
jmp 0x147da
incq %rdx
addq %rdi, %rax
addq %rdi, %rcx
jmp 0x147d1
cvtsd2ss %xmm5, %xmm3
xorl %r13d, %r13d
movslq 0xe8(%rbx), %rax
cmpq %rax, %r13
jge 0x14a25
movq 0xe0(%rbx), %rax
imulq $0x188, %r13, %r15      # imm = 0x188
movq 0x168(%rax,%r15), %rbp
testq %rbp, %rbp
je 0x14a1d
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 0x14a1d
movsd 0x18(%rbp), %xmm1
movsd 0x8(%rcx), %xmm2
subsd %xmm5, %xmm2
ucomisd %xmm1, %xmm2
ja 0x14a1d
movsd 0x20(%rbp), %xmm2
movsd 0x10(%rcx), %xmm6
subsd %xmm5, %xmm6
ucomisd %xmm2, %xmm6
ja 0x14a1d
movq 0x10(%rax), %rax
movsd (%rax), %xmm6
addsd %xmm5, %xmm6
ucomisd %xmm6, %xmm4
ja 0x14a1d
movsd 0x8(%rax), %xmm6
addsd %xmm5, %xmm6
ucomisd %xmm6, %xmm1
ja 0x14a1d
movsd 0x10(%rax), %xmm6
addsd %xmm5, %xmm6
ucomisd %xmm6, %xmm2
ja 0x14a1d
movsd %xmm5, 0x10(%rsp)
movsd %xmm0, 0x8(%rsp)
cvtsd2ss %xmm4, %xmm0
cvtsd2ss %xmm1, %xmm1
cvtsd2ss %xmm2, %xmm2
movss %xmm3, 0x4(%rsp)
callq 0x16d86
movq %rax, %r12
movq %r13, %r14
shlq $0x20, %r14
movq %r12, %rdi
callq 0x16db1
testl %eax, %eax
jne 0x14a03
movq %r12, %rdi
leaq 0x20(%rsp), %rsi
callq 0x16dd1
movq 0x40(%rax), %rcx
movq %rcx, %rax
subq 0x70(%rbx), %rax
cqto
movl $0x188, %esi            # imm = 0x188
idivq %rsi
movsbq (%rcx), %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 0x149f6
movsbq %dl, %rdx
imulq $0xa0, %rcx, %rcx
leaq 0xc060(%rip), %rsi      # 0x209d0
addq %rcx, %rsi
leaq 0xccd6(%rip), %rdi      # 0x21650
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
sqrtsd %xmm3, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x149f6
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 0x151fa
movq %r12, %rdi
callq 0x16dbc
jmp 0x14901
movq %r12, %rdi
callq 0x167ec
movsd 0x8(%rsp), %xmm0
movsd 0x10(%rsp), %xmm5
movss 0x4(%rsp), %xmm3
incq %r13
jmp 0x14813
movq %rbx, %rdi
callq 0x145dc
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq