// File: 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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movsd %xmm0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x14, -0x1c(%rbp)
jge 0x2c2c3
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
cmpl $0x14, -0x20(%rbp)
jge 0x2c2b3
movslq -0x1c(%rbp), %rsi
leaq 0x2216a(%rip), %rdi     # 0x4e390
callq 0x23370
movq %rax, %rdi
movslq -0x20(%rbp), %rsi
callq 0x23390
movsd (%rax), %xmm0
movsd %xmm0, -0xc0(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movslq -0x1c(%rbp), %rsi
leaq 0x2214d(%rip), %rdi     # 0x4e3a8
callq 0x23370
movq %rax, %rdi
movslq -0x20(%rbp), %rsi
callq 0x23390
movsd -0xc8(%rbp), %xmm0
movsd -0xc0(%rbp), %xmm1
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movsd -0x28(%rbp), %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0x2c2a3
movsd -0x28(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
jmp 0x2c2a5
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2c211
jmp 0x2c2b5
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2c1fe
movq -0xb8(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0xb8(%rbp), %rcx
movl -0x5c(%rbp), %eax
cmpl 0xe8(%rcx), %eax
jge 0x2c623
movq -0xb8(%rbp), %rax
movq 0xe0(%rax), %rax
movslq -0x5c(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
addq $0x20, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movsd (%rax), %xmm1
movq -0x50(%rbp), %rax
movsd (%rax), %xmm0
subsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2c3e4
movq -0x68(%rbp), %rax
movsd 0x8(%rax), %xmm1
movq -0x50(%rbp), %rax
movsd 0x8(%rax), %xmm0
subsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2c3e4
movq -0x68(%rbp), %rax
movsd 0x10(%rax), %xmm1
movq -0x50(%rbp), %rax
movsd 0x10(%rax), %xmm0
subsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2c3e4
movq -0x68(%rbp), %rax
movsd (%rax), %xmm0
movq -0x58(%rbp), %rax
movsd (%rax), %xmm1
addsd -0x18(%rbp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2c3e4
movq -0x68(%rbp), %rax
movsd 0x8(%rax), %xmm0
movq -0x58(%rbp), %rax
movsd 0x8(%rax), %xmm1
addsd -0x18(%rbp), %xmm1
ucomisd %xmm1, %xmm0
ja 0x2c3e4
movq -0x68(%rbp), %rax
movsd 0x10(%rax), %xmm0
movq -0x58(%rbp), %rax
movsd 0x10(%rax), %xmm1
addsd -0x18(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2c3e9
jmp 0x2c615
movq -0x48(%rbp), %rdi
movq -0x68(%rbp), %rsi
movsd -0x18(%rbp), %xmm0
callq 0x32290
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rdi
callq 0x32820
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x2c419
jmp 0x2c60c
movq -0x70(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x32870
movq -0xb8(%rbp), %rcx
movq %rax, -0x78(%rbp)
movq -0x78(%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 -0xb8(%rbp), %rax
movl %ecx, -0x7c(%rbp)
movq 0x70(%rax), %rcx
movslq -0x7c(%rbp), %rdx
imulq $0x188, %rdx, %rdx      # imm = 0x188
addq %rdx, %rcx
movsbl (%rcx), %ecx
movl %ecx, -0x80(%rbp)
movq 0xe0(%rax), %rax
movslq -0x5c(%rbp), %rcx
imulq $0x188, %rcx, %rcx      # imm = 0x188
addq %rcx, %rax
movsbl (%rax), %eax
movl %eax, -0x84(%rbp)
cmpl $0x14, -0x80(%rbp)
jge 0x2c5fe
cmpl $0x14, -0x84(%rbp)
jge 0x2c5fe
movslq -0x80(%rbp), %rsi
leaq 0x21ee1(%rip), %rdi     # 0x4e390
callq 0x23370
movq %rax, %rdi
movslq -0x84(%rbp), %rsi
callq 0x23390
movsd (%rax), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movslq -0x80(%rbp), %rsi
leaq 0x21ec1(%rip), %rdi     # 0x4e3a8
callq 0x23370
movq %rax, %rdi
movslq -0x84(%rbp), %rsi
callq 0x23390
movsd -0xd8(%rbp), %xmm0
movsd -0xd0(%rbp), %xmm1
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x90(%rbp)
movq -0x68(%rbp), %rax
movsd (%rax), %xmm0
subsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x98(%rbp)
movq -0x68(%rbp), %rax
movsd 0x8(%rax), %xmm0
subsd -0x38(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movq -0x68(%rbp), %rax
movsd 0x10(%rax), %xmm0
subsd -0x30(%rbp), %xmm0
movsd %xmm0, -0xa8(%rbp)
movsd -0x98(%rbp), %xmm1
movsd -0x98(%rbp), %xmm2
movsd -0xa0(%rbp), %xmm0
mulsd -0xa0(%rbp), %xmm0
mulsd %xmm2, %xmm1
addsd %xmm0, %xmm1
movsd -0xa8(%rbp), %xmm0
movsd -0xa8(%rbp), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
callq 0x3220
movaps %xmm0, %xmm1
movsd -0x90(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x2c5fc
movq -0xb8(%rbp), %rax
movq 0x18(%rax), %rcx
movslq -0x7c(%rbp), %rdx
movb $0x1, (%rcx,%rdx)
movq 0x20(%rax), %rax
movslq -0x5c(%rbp), %rcx
movb $0x1, (%rax,%rcx)
leaq -0x7c(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x2cc10
movq -0xb8(%rbp), %rdi
movq %rax, -0xb0(%rbp)
leaq -0xb0(%rbp), %rsi
callq 0x2cbe0
jmp 0x2c5fe
movq -0x70(%rbp), %rdi
callq 0x32840
jmp 0x2c3ff
movq -0x70(%rbp), %rdi
callq 0x31d50
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x2c2fc
movq -0xb8(%rbp), %rdi
callq 0x2b840
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax,%rax)