// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb0(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x14, -0x1c(%rbp)
jge 0x2bc08
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
cmpl $0x14, -0x20(%rbp)
jge 0x2bbf8
movslq -0x1c(%rbp), %rcx
leaq 0x10dde(%rip), %rax     # 0x3c970
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x10(%rbp), %xmm0
movslq -0x1c(%rbp), %rcx
leaq 0x11a3b(%rip), %rax     # 0x3d5f0
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x2bbeb
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x2bbed
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2bb81
jmp 0x2bbfa
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2bb6e
movl $0x0, -0x74(%rbp)
movq -0xb0(%rbp), %rcx
movl -0x74(%rbp), %eax
cmpl 0xe8(%rcx), %eax
jge 0x2bf9c
movq -0xb0(%rbp), %rax
movq 0xe0(%rax), %rax
movslq -0x74(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
movq 0x168(%rax), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x2bc58
jmp 0x2bf8e
movq -0xb0(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x88(%rbp)
movq -0x80(%rbp), %rax
movsd 0x10(%rax), %xmm1
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
subsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2bd63
movq -0x80(%rbp), %rax
movsd 0x18(%rax), %xmm1
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movsd 0x8(%rax), %xmm0
subsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2bd63
movq -0x80(%rbp), %rax
movsd 0x20(%rax), %xmm1
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movsd 0x10(%rax), %xmm0
subsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2bd63
movq -0x80(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movsd (%rax), %xmm1
addsd -0x18(%rbp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2bd63
movq -0x80(%rbp), %rax
movsd 0x18(%rax), %xmm0
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movsd 0x8(%rax), %xmm1
addsd -0x18(%rbp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2bd63
movq -0x80(%rbp), %rax
movsd 0x20(%rax), %xmm0
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movsd 0x10(%rax), %xmm1
addsd -0x18(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2bd68
jmp 0x2bf8e
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rax
movsd 0x10(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x80(%rbp), %rax
movsd 0x18(%rax), %xmm1
cvtsd2ss %xmm1, %xmm1
movq -0x80(%rbp), %rax
movsd 0x20(%rax), %xmm2
cvtsd2ss %xmm2, %xmm2
movsd -0x18(%rbp), %xmm3
cvtsd2ss %xmm3, %xmm3
callq 0x32730
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x32820
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2bdc2
jmp 0x2bf85
movq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x32870
movq -0xb0(%rbp), %rcx
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
movq 0x40(%rax), %rax
movq 0x70(%rcx), %rcx
subq %rcx, %rax
movl $0x188, %ecx            # imm = 0x188
cqto
idivq %rcx
movq %rax, %rcx
movq -0xb0(%rbp), %rax
movl %ecx, -0x94(%rbp)
movq -0x90(%rbp), %rcx
movq 0x40(%rcx), %rcx
movsbl (%rcx), %ecx
movl %ecx, -0x98(%rbp)
movq 0xe0(%rax), %rax
movslq -0x74(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
movsbl (%rax), %eax
movl %eax, -0x9c(%rbp)
cmpl $0x14, -0x98(%rbp)
jge 0x2bf77
cmpl $0x14, -0x9c(%rbp)
jge 0x2bf77
movslq -0x98(%rbp), %rcx
leaq 0x10b0d(%rip), %rax     # 0x3c970
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movslq -0x9c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x10(%rbp), %xmm0
movslq -0x98(%rbp), %rcx
leaq 0x11764(%rip), %rax     # 0x3d5f0
imulq $0xa0, %rcx, %rcx
addq %rcx, %rax
movslq -0x9c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movq -0x80(%rbp), %rax
movsd 0x10(%rax), %xmm0
subsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x80(%rbp), %rax
movsd 0x18(%rax), %xmm0
subsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x80(%rbp), %rax
movsd 0x20(%rax), %xmm0
subsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x58(%rbp), %xmm1
movsd -0x58(%rbp), %xmm2
movsd -0x60(%rbp), %xmm0
mulsd -0x60(%rbp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd -0x68(%rbp), %xmm0
movsd -0x68(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x3220
movaps %xmm0, %xmm1
movsd -0x70(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2bf75
movq -0xb0(%rbp), %rax
movq 0x18(%rax), %rcx
movslq -0x94(%rbp), %rdx
movb $0x1, (%rcx,%rdx)
movq 0x20(%rax), %rax
movslq -0x74(%rbp), %rcx
movb $0x1, (%rax,%rcx)
leaq -0x94(%rbp), %rdi
leaq -0x74(%rbp), %rsi
callq 0x2cc10
movq -0xb0(%rbp), %rdi
movq %rax, -0xa4(%rbp)
leaq -0xa4(%rbp), %rsi
callq 0x2cbe0
jmp 0x2bf77
movq -0x30(%rbp), %rdi
callq 0x32840
jmp 0x2bda8
movq -0x30(%rbp), %rdi
callq 0x31d50
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x2bc0f
movq -0xb0(%rbp), %rdi
callq 0x2b840
addq $0xb0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)