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

	/* search for interface residues */
	kdres *res;
	double pos[3];
	for (int i = 0; i < Ligand.nRes; i++) {

		for (int j = 0; j < Ligand.residue[i].nAtoms; j++) {

			Atom *A = &(Ligand.residue[i].atom[j]);

			if (A->type == 'H') { /* exclude hydrogens */
				continue;
			}

			/* check whether the current atom is within the bounding box
			 * of the Receptor */
			kdtree *kd = Receptor.kd;
			if (A->x < kd->rect->min[0] - d || A->y < kd->rect->min[1] - d
					|| A->z < kd->rect->min[2] - d
					|| A->x > kd->rect->max[0] + d
					|| A->y > kd->rect->max[1] + d
					|| A->z > kd->rect->max[2] + d) {

				continue;

			}

			/* find neighbors of A in the Receptor */
			res = kd_nearest_range3f(kd, A->x, A->y, A->z, d);
			while (!kd_res_end(res)) {

				Atom *B = *((Atom**) kd_res_item(res, pos));
				if (B->type != 'H') { /* exclude hydrogens */
					int idx = B->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 0x2b82f
movl $0x0, -0x38(%rbp)
movq -0x68(%rbp), %rcx
movl -0x38(%rbp), %eax
movq 0xe0(%rcx), %rcx
movslq -0x34(%rbp), %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
cmpl 0x18(%rcx), %eax
jge 0x2b81f
movq -0x68(%rbp), %rax
movq 0xe0(%rax), %rax
movslq -0x34(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
movq 0x10(%rax), %rax
movslq -0x38(%rbp), %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movsbl 0x58(%rax), %eax
cmpl $0x48, %eax
jne 0x2b62d
jmp 0x2b811
movq -0x68(%rbp), %rax
movq 0x80(%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 0x2b720
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 0x2b720
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 0x2b720
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 0x2b720
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 0x2b720
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 0x2b725
jmp 0x2b811
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 0x2b77c
jmp 0x2b808
movq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x32870
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movsbl 0x58(%rax), %eax
cmpl $0x48, %eax
je 0x2b7fa
movq -0x68(%rbp), %rcx
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 0x2b762
movq -0x18(%rbp), %rdi
callq 0x31d50
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2b5ca
jmp 0x2b821
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x2b5b0
movq -0x68(%rbp), %rdi
callq 0x2b840
addq $0x70, %rsp
popq %rbp
retq
nop