// File: gjoni[P]iPot/src/Complex.cpp
// Function: Complex::SetInterface2(double)
void Complex::SetInterface2(double d) {

	/* search for interface residues */
	kdres *res;
	double pos[3];
	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] - d || A->y < kdCA->rect->min[1] - d
				|| A->z < kdCA->rect->min[2] - d
				|| A->x > kdCA->rect->max[0] + d
				|| A->y > kdCA->rect->max[1] + d
				|| A->z > kdCA->rect->max[2] + d) {

			continue;

		}

		/* find neighbors of A in the Receptor */
		res = kd_nearest_range3f(kdCA, A->x, A->y, A->z, d);
		while (!kd_res_end(res)) {
			//int idx = (Residue*) kd_res_item(res, pos) - Receptor.residues;
			Atom *A = (Atom*) kd_res_item(res, pos);
			int idx = A->residue - Receptor.residue;
			intRec[idx] = true;
			intLig[i] = true;
			contacts.push_back(std::make_pair(idx, i));
			kd_res_next(res);
		}
		kd_res_free(res);

	}

	ArrangeContatcs();

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x34(%rbp)
movq -0x68(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0xe8(%rcx), %eax
jge 0x2bb22
movq -0x68(%rbp), %rax
movq 0xe0(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
movq 0x168(%rax), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x2b943
jmp 0x2bb14
movq -0x68(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movsd 0x10(%rax), %xmm1
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
subsd -0x10(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2ba36
movq -0x40(%rbp), %rax
movsd 0x18(%rax), %xmm1
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movsd 0x8(%rax), %xmm0
subsd -0x10(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2ba36
movq -0x40(%rbp), %rax
movsd 0x20(%rax), %xmm1
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movsd 0x10(%rax), %xmm0
subsd -0x10(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2ba36
movq -0x40(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movsd (%rax), %xmm1
addsd -0x10(%rbp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2ba36
movq -0x40(%rbp), %rax
movsd 0x18(%rax), %xmm0
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movsd 0x8(%rax), %xmm1
addsd -0x10(%rbp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2ba36
movq -0x40(%rbp), %rax
movsd 0x20(%rax), %xmm0
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movsd 0x10(%rax), %xmm1
addsd -0x10(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2ba3b
jmp 0x2bb14
movq -0x48(%rbp), %rdi
movq -0x40(%rbp), %rax
movsd 0x10(%rax), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x40(%rbp), %rax
movsd 0x18(%rax), %xmm1
cvtsd2ss %xmm1, %xmm1
movq -0x40(%rbp), %rax
movsd 0x20(%rax), %xmm2
cvtsd2ss %xmm2, %xmm2
movsd -0x10(%rbp), %xmm3
cvtsd2ss %xmm3, %xmm3
callq 0x32730
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x32820
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2ba8f
jmp 0x2bb0b
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x32870
movq -0x68(%rbp), %rcx
movq %rax, -0x50(%rbp)
movq -0x50(%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 -0x68(%rbp), %rax
movl %ecx, -0x54(%rbp)
movq 0x18(%rax), %rcx
movslq -0x54(%rbp), %rdx
movb $0x1, (%rcx,%rdx)
movq 0x20(%rax), %rax
movslq -0x34(%rbp), %rcx
movb $0x1, (%rax,%rcx)
leaq -0x54(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x2cc10
movq -0x68(%rbp), %rdi
movq %rax, -0x5c(%rbp)
leaq -0x5c(%rbp), %rsi
callq 0x2cbe0
movq -0x18(%rbp), %rdi
callq 0x32840
jmp 0x2ba78
movq -0x18(%rbp), %rdi
callq 0x31d50
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2b900
movq -0x68(%rbp), %rdi
callq 0x2b840
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)