// File: /workspace/github_cpp_makefile_star2_O3/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 0x1753a(%rip), %rax     # 0x2d310
xorpd %xmm5, %xmm5
movq 0x17547(%rip), %rcx     # 0x2d328
xorl %edx, %edx
cmpq $0x12, %rdx
ja 0x15e27
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 0x15e04
incq %rdx
cmpq $0x14, %rdx
jne 0x15de3
movl 0xe8(%rbx), %eax
testl %eax, %eax
jle 0x16080
movq 0x90(%rbx), %rdi
movq 0x10(%rdi), %rcx
movq 0x8(%rcx), %r12
movq 0x10(%rcx), %rdx
xorl %r15d, %r15d
movq 0xe0(%rbx), %rcx
imulq $0x188, %r15, %r14      # imm = 0x188
movsd 0x20(%rcx,%r14), %xmm4
movsd (%r12), %xmm1
subsd %xmm5, %xmm1
ucomisd %xmm4, %xmm1
ja 0x16071
leaq (%rcx,%r14), %r13
addq $0x20, %r13
movsd 0x8(%r13), %xmm1
movsd 0x8(%r12), %xmm2
subsd %xmm5, %xmm2
ucomisd %xmm1, %xmm2
ja 0x16071
movsd 0x10(%r13), %xmm2
movsd 0x10(%r12), %xmm3
subsd %xmm5, %xmm3
ucomisd %xmm2, %xmm3
ja 0x16071
movsd (%rdx), %xmm3
addsd %xmm5, %xmm3
ucomisd %xmm3, %xmm4
ja 0x16071
movsd 0x8(%rdx), %xmm3
addsd %xmm5, %xmm3
ucomisd %xmm3, %xmm1
ja 0x16071
movsd 0x10(%rdx), %xmm1
addsd %xmm5, %xmm1
ucomisd %xmm1, %xmm2
ja 0x16071
movq %rdx, 0x8(%rsp)
movsd %xmm0, (%rsp)
movq %rdi, 0x10(%rsp)
movq %r13, %rsi
movsd %xmm5, 0x18(%rsp)
movapd %xmm5, %xmm0
callq 0x17d1a
movq %rax, %rbp
movq %rax, %rdi
callq 0x18006
testl %eax, %eax
jne 0x1604e
movq %r15, %rax
shlq $0x20, %rax
movq %rax, 0x20(%rsp)
movq %rbp, %rdi
leaq 0x30(%rsp), %rsi
callq 0x18026
movq 0x40(%rax), %rax
movq 0x70(%rbx), %rdx
movq 0xe0(%rbx), %rsi
subq %rdx, %rax
sarq $0x3, %rax
movabsq $0x7d6343eb1a1f58d1, %rcx # imm = 0x7D6343EB1A1F58D1
imulq %rcx, %rax
movslq %eax, %rcx
imulq $0x188, %rcx, %rdi      # imm = 0x188
movsbq (%rdx,%rdi), %rdx
cmpq $0x14, %rdx
setl %dil
movb (%rsi,%r14), %sil
cmpb $0x14, %sil
setl %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0x16036
movsbq %sil, %rsi
movq 0x17371(%rip), %rdi     # 0x2d310
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
movq (%rdi,%rdx), %rdi
movq 0x17376(%rip), %r8      # 0x2d328
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
xorps %xmm1, %xmm1
sqrtsd %xmm3, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16036
movq 0x18(%rbx), %rdx
movb $0x1, %sil
movb %sil, (%rdx,%rcx)
movq 0x20(%rbx), %rcx
movb %sil, (%rcx,%r15)
movl %eax, %eax
orq 0x20(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
leaq 0x28(%rsp), %rsi
callq 0x1639c
movq %rbp, %rdi
callq 0x18011
movq %rbp, %rdi
callq 0x18006
testl %eax, %eax
je 0x15f33
movq %rbp, %rdi
callq 0x17a3c
movl 0xe8(%rbx), %eax
movsd (%rsp), %xmm0
movsd 0x18(%rsp), %xmm5
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rdx
incq %r15
movslq %eax, %rcx
cmpq %rcx, %r15
jl 0x15e54
movq %rbx, %rdi
callq 0x1573a
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop