// File: /workspace/github_cpp_makefile_star2_O2/gjoni[P]iPot/src/Complex.cpp
// Function: Complex::SetInterface5(double)
void Complex::SetInterface5(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 = CENTROID_DIST[i][j] + ksi * CENTROID_STD[i][j];
			if (d > dmax) {
				dmax = d;
			}
		}
	}

	/* search for interface residues */
	double pos[3];
	kdtree *kd = Receptor.kdCent;
	double *min = kd->rect->min;
	double *max = kd->rect->max;
	for (int i = 0; i < Ligand.nRes; i++) {

		double *xyz = Ligand.residue[i].centroid;

		/* check whether the current atom is within the bounding box
		 * of the Receptor */
		if (xyz[0] < min[0] - dmax || xyz[1] < min[1] - dmax
				|| xyz[2] < min[2] - dmax || xyz[0] > max[0] + dmax
				|| xyz[1] > max[1] + dmax || xyz[2] > max[2] + dmax) {

			continue;

		}

		/* find neighbors of A in the Receptor */
		kdres *res = kd_nearest_range(kd, xyz, dmax);
		while (!kd_res_end(res)) {
			//int idxRec = (Residue*) kd_res_item(res, pos) - Receptor.residues;
			Atom *A = (Atom*) kd_res_item(res, pos);
			int idxRec = A->residue - Receptor.residue;
			int type1 = Receptor.residue[idxRec].type;
			int type2 = Ligand.residue[i].type;

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

				/* calculate residue-dependent cut-off */
				double d = CENTROID_DIST[type1][type2]
						+ ksi * CENTROID_STD[type1][type2];

				/* find actual Ca-Ca distance */
				double x = xyz[0] - pos[0];
				double y = xyz[1] - pos[1];
				double z = xyz[2] - 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
movq 0x17758(%rip), %rax     # 0x2c330
xorpd %xmm5, %xmm5
pushq $0x1
popq %rcx
movq 0x17762(%rip), %rdx     # 0x2c348
xorl %esi, %esi
cmpq $0x14, %rsi
je 0x14c2d
imulq $0x18, %rsi, %rdi
leaq (%rax,%rdi), %r8
addq %rdx, %rdi
movq %rcx, %r9
cmpq $0x14, %r9
je 0x14c25
movq (%r8), %r10
movq (%rdi), %r11
movsd (%r11,%r9,8), %xmm1
mulsd %xmm0, %xmm1
addsd (%r10,%r9,8), %xmm1
maxsd %xmm5, %xmm1
incq %r9
movapd %xmm1, %xmm5
jmp 0x14bfc
incq %rsi
incq %rcx
jmp 0x14be8
movq 0x90(%rbx), %rdi
movq 0x10(%rdi), %rax
movq 0x8(%rax), %r12
movq 0x10(%rax), %rcx
xorl %r14d, %r14d
movslq 0xe8(%rbx), %rax
cmpq %rax, %r14
jge 0x14e58
movq 0xe0(%rbx), %rax
imulq $0x188, %r14, %r15      # imm = 0x188
movsd 0x20(%rax,%r15), %xmm4
movsd (%r12), %xmm1
subsd %xmm5, %xmm1
ucomisd %xmm4, %xmm1
ja 0x14e50
leaq (%rax,%r15), %r13
addq $0x20, %r13
movsd 0x8(%r13), %xmm1
movsd 0x8(%r12), %xmm2
subsd %xmm5, %xmm2
ucomisd %xmm1, %xmm2
ja 0x14e50
movsd 0x10(%r13), %xmm2
movsd 0x10(%r12), %xmm3
subsd %xmm5, %xmm3
ucomisd %xmm2, %xmm3
ja 0x14e50
movsd (%rcx), %xmm3
addsd %xmm5, %xmm3
ucomisd %xmm3, %xmm4
ja 0x14e50
movsd 0x8(%rcx), %xmm3
addsd %xmm5, %xmm3
ucomisd %xmm3, %xmm1
ja 0x14e50
movsd 0x10(%rcx), %xmm1
addsd %xmm5, %xmm1
ucomisd %xmm1, %xmm2
ja 0x14e50
movq %rcx, 0x8(%rsp)
movsd %xmm0, (%rsp)
movq %rdi, 0x10(%rsp)
movq %r13, %rsi
movsd %xmm5, 0x18(%rsp)
movapd %xmm5, %xmm0
callq 0x16af2
movq %rax, %rbp
movq %r14, %rax
shlq $0x20, %rax
movq %rax, 0x20(%rsp)
movq %rbp, %rdi
callq 0x16db1
testl %eax, %eax
jne 0x14e33
movq %rbp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x16dd1
movq 0x40(%rax), %rax
movq 0x70(%rbx), %rsi
movq 0xe0(%rbx), %rdi
subq %rsi, %rax
cqto
movl $0x188, %ecx            # imm = 0x188
idivq %rcx
movslq %eax, %rcx
imulq $0x188, %rcx, %rdx      # imm = 0x188
movsbq (%rsi,%rdx), %rdx
cmpq $0x14, %rdx
setl %r8b
movb (%rdi,%r15), %sil
cmpb $0x14, %sil
setl %dil
andb %r8b, %dil
cmpb $0x1, %dil
jne 0x14e26
movsbq %sil, %rsi
movq 0x1759a(%rip), %rdi     # 0x2c330
imulq $0x18, %rdx, %rdx
movq (%rdi,%rdx), %rdi
movq 0x175a3(%rip), %r8      # 0x2c348
movq (%r8,%rdx), %rdx
movsd (%rdx,%rsi,8), %xmm0
mulsd (%rsp), %xmm0
addsd (%rdi,%rsi,8), %xmm0
movsd (%r13), %xmm1
movsd 0x8(%r13), %xmm2
subsd 0x30(%rsp), %xmm1
subsd 0x38(%rsp), %xmm2
movsd 0x10(%r13), %xmm3
subsd 0x40(%rsp), %xmm3
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm3, %xmm3
addsd %xmm1, %xmm3
sqrtsd %xmm3, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x14e26
movq 0x18(%rbx), %rdx
movb $0x1, %sil
movb %sil, (%rdx,%rcx)
movq 0x20(%rbx), %rcx
movb %sil, (%rcx,%r14)
movl %eax, %eax
orq 0x20(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
callq 0x151fa
movq %rbp, %rdi
callq 0x16dbc
jmp 0x14d22
movq %rbp, %rdi
callq 0x167ec
movsd (%rsp), %xmm0
movsd 0x18(%rsp), %xmm5
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rcx
incq %r14
jmp 0x14c43
movq %rbx, %rdi
callq 0x145dc
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop