// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
movq %rdi, %rbx
movq 0x173de(%rip), %rax     # 0x2d320
xorpd %xmm5, %xmm5
movq 0x173eb(%rip), %rcx     # 0x2d338
xorl %edx, %edx
cmpq $0x12, %rdx
ja 0x15f93
leaq (,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rdi
movq (%rax,%rdi), %rsi
movq (%rcx,%rdi), %rdi
movq %rdx, %r8
movapd %xmm5, %xmm1
movsd 0x8(%rdi,%r8,8), %xmm5
mulsd %xmm0, %xmm5
addsd 0x8(%rsi,%r8,8), %xmm5
maxsd %xmm1, %xmm5
incq %r8
movapd %xmm5, %xmm1
cmpq $0x13, %r8
jne 0x15f70
incq %rdx
cmpq $0x14, %rdx
jne 0x15f4f
cmpl $0x0, 0xe8(%rbx)
jle 0x1620c
movq 0x90(%rbx), %rdi
movq 0x10(%rdi), %rax
movq 0x8(%rax), %r12
movq 0x10(%rax), %rcx
xorl %r15d, %r15d
movq 0xe0(%rbx), %rax
imulq $0x188, %r15, %r14      # imm = 0x188
movsd 0x20(%rax,%r14), %xmm4
movsd (%r12), %xmm1
subsd %xmm5, %xmm1
ucomisd %xmm4, %xmm1
ja 0x161f9
leaq (%rax,%r14), %r13
addq $0x20, %r13
movsd 0x8(%r13), %xmm1
movsd 0x8(%r12), %xmm2
subsd %xmm5, %xmm2
ucomisd %xmm1, %xmm2
ja 0x161f9
movsd 0x10(%r13), %xmm2
movsd 0x10(%r12), %xmm3
subsd %xmm5, %xmm3
ucomisd %xmm2, %xmm3
ja 0x161f9
movsd (%rcx), %xmm3
addsd %xmm5, %xmm3
ucomisd %xmm3, %xmm4
ja 0x161f9
movsd 0x8(%rcx), %xmm3
addsd %xmm5, %xmm3
ucomisd %xmm3, %xmm1
ja 0x161f9
movsd 0x10(%rcx), %xmm1
addsd %xmm5, %xmm1
ucomisd %xmm1, %xmm2
ja 0x161f9
movq %rcx, 0x8(%rsp)
movsd %xmm0, (%rsp)
movq %rdi, 0x10(%rsp)
movq %r13, %rsi
movsd %xmm5, 0x18(%rsp)
movapd %xmm5, %xmm0
callq 0x17ef5
movq %rax, %rbp
movq %rax, %rdi
callq 0x181e8
testl %eax, %eax
jne 0x161dc
movq %r15, %rax
shlq $0x20, %rax
movq %rax, 0x20(%rsp)
movq %rbp, 0x30(%rsp)
movq %rbp, %rdi
leaq 0x40(%rsp), %rsi
callq 0x18208
movq 0x40(%rax), %rbp
movq 0x70(%rbx), %rax
movq 0xe0(%rbx), %rcx
subq %rax, %rbp
sarq $0x3, %rbp
movabsq $0x7d6343eb1a1f58d1, %rdx # imm = 0x7D6343EB1A1F58D1
imulq %rdx, %rbp
movslq %ebp, %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
movsbq (%rax,%rdx), %rax
cmpq $0x14, %rax
setl %dl
movb (%rcx,%r14), %cl
cmpb $0x14, %cl
setl %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x161bf
movsbq %cl, %rcx
movq 0x17213(%rip), %rdx     # 0x2d320
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq (%rdx,%rax), %rdx
movq 0x17218(%rip), %rsi     # 0x2d338
movq (%rsi,%rax), %rax
movsd (%rax,%rcx,8), %xmm3
mulsd (%rsp), %xmm3
addsd (%rdx,%rcx,8), %xmm3
movsd (%r13), %xmm1
movsd 0x8(%r13), %xmm2
subsd 0x40(%rsp), %xmm1
subsd 0x48(%rsp), %xmm2
movsd 0x10(%r13), %xmm0
subsd 0x50(%rsp), %xmm0
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
ucomisd 0xaf3d(%rip), %xmm0     # 0x210b0
jb 0x1617b
sqrtsd %xmm0, %xmm0
jmp 0x1618c
movsd %xmm3, 0x28(%rsp)
callq 0x21b0
movsd 0x28(%rsp), %xmm3
ucomisd %xmm0, %xmm3
jbe 0x161bf
movq 0x18(%rbx), %rax
movslq %ebp, %rcx
movb $0x1, %dl
movb %dl, (%rax,%rcx)
movq 0x20(%rbx), %rax
movb %dl, (%rax,%r15)
movl %ecx, %eax
orq 0x20(%rsp), %rax
movq %rax, 0x38(%rsp)
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
callq 0x16534
movq 0x30(%rsp), %rbp
movq %rbp, %rdi
callq 0x181f3
movq %rbp, %rdi
callq 0x181e8
testl %eax, %eax
je 0x160a3
movq %rbp, %rdi
callq 0x17c0b
movsd (%rsp), %xmm0
movsd 0x18(%rsp), %xmm5
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rcx
incq %r15
movslq 0xe8(%rbx), %rax
cmpq %rax, %r15
jl 0x15fbf
movq %rbx, %rdi
callq 0x15898
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop