// File: gjoni[P]iPot/src/Complex.cpp
// Function: Complex::SetInterface4(double)
void Complex::SetInterface4(double 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] - d || xyz[1] < min[1] - d || xyz[2] < min[2] - d
				|| xyz[0] > max[0] + d || xyz[1] > max[1] + d
				|| xyz[2] > max[2] + d) {

			continue;

		}

		/* find neighbors of A in the Receptor */
		kdres *res = kd_nearest_range(kd, xyz, d);
		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;
			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 $0x80, %rsp
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq 0x90(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x80(%rbp), %rcx
movl -0x4c(%rbp), %eax
cmpl 0xe8(%rcx), %eax
jge 0x2c1b5
movq -0x80(%rbp), %rax
movq 0xe0(%rax), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
addq $0x20, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movsd (%rax), %xmm1
movq -0x40(%rbp), %rax
movsd (%rax), %xmm0
subsd -0x10(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2c0f0
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm1
movq -0x40(%rbp), %rax
movsd 0x8(%rax), %xmm0
subsd -0x10(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2c0f0
movq -0x58(%rbp), %rax
movsd 0x10(%rax), %xmm1
movq -0x40(%rbp), %rax
movsd 0x10(%rax), %xmm0
subsd -0x10(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2c0f0
movq -0x58(%rbp), %rax
movsd (%rax), %xmm0
movq -0x48(%rbp), %rax
movsd (%rax), %xmm1
addsd -0x10(%rbp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2c0f0
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x48(%rbp), %rax
movsd 0x8(%rax), %xmm1
addsd -0x10(%rbp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2c0f0
movq -0x58(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x48(%rbp), %rax
movsd 0x10(%rax), %xmm1
addsd -0x10(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2c0f5
jmp 0x2c1a7
movq -0x38(%rbp), %rdi
movq -0x58(%rbp), %rsi
movsd -0x10(%rbp), %xmm0
callq 0x32290
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x32820
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2c122
jmp 0x2c19e
movq -0x60(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x32870
movq -0x80(%rbp), %rcx
movq %rax, -0x68(%rbp)
movq -0x68(%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 -0x80(%rbp), %rax
movl %ecx, -0x6c(%rbp)
movq 0x18(%rax), %rcx
movslq -0x6c(%rbp), %rdx
movb $0x1, (%rcx,%rdx)
movq 0x20(%rax), %rax
movslq -0x4c(%rbp), %rcx
movb $0x1, (%rax,%rcx)
leaq -0x6c(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x2cc10
movq -0x80(%rbp), %rdi
movq %rax, -0x74(%rbp)
leaq -0x74(%rbp), %rsi
callq 0x2cbe0
movq -0x60(%rbp), %rdi
callq 0x32840
jmp 0x2c10b
movq -0x60(%rbp), %rdi
callq 0x31d50
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2c00e
movq -0x80(%rbp), %rdi
callq 0x2b840
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)