// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/nma.c
// Function: Output_modes
float Output_modes(int N,           //degrees of freedom
		   char *model,     // INM, ANM or TNM
		   char *REF_ATM,   // Reference atoms
		   atom *atoms, int N_atoms,
		   struct residue *seq, int N_res,
		   struct axe *axes, int N_axes,
		   float *B_CA, float *B_CA_exp,
		   int *weight, float *dist_CA,
		   float ***aniso_pred, float ***aniso_exp,
		   int N_MODES, float cutoff,
		   char *inter, char *prot_name,
		   FILE *file_B, FILE *file_sum,
		   float **eigen_vector, float *eigen_value, float *eigen_B,
		   float *Cart_collectivity, float *Tors_collectivity,
		   float **Cart_mode, int *atom_ref, int N_ref)
{
  char outfile[200], string[100]; int n_aniso=0;
  float r, slope, offset, dot_aniso=0, ov_aniso=0, delta_aniso=2.;
  float slope_calc, slope_dist, offset2, r2, chi;
  int neg=0, i;
  int nca=N_res;

  // B factors comparison
  // Model 1: B_exp = slope*B_calc + offset
  // r=Corr_coeff(B_CA, B_CA_exp, weight, nca, &slope, &offset, &newnorm);
  r=Corr_coeff(B_CA, B_CA_exp, nca, &slope, &offset);
  printf("cc(B, %s %s)=  %6.3f   ref: %s\n", model, inter, r, REF_ATM);

  fprintf(file_sum, "%3s\t%3s\t%4.1f", model, inter, cutoff);
  fprintf(file_sum, "\t%6.3f\t%8.5f\t%5.3f", r, slope, offset);
  if(FIT_ROT){
    // Model 2: B_exp = slope*B_calc + offset
    Bivariate_fit(nca, B_CA_exp, B_CA, dist_CA, weight,
		  &slope_calc, &slope_dist, &offset2, &r2, &chi);
    fprintf(file_sum, "\t%6.3f\t%8.5f\t%8.5f\t%5.3f ",
	    r2, slope_calc, slope_dist, offset2);
  }
  //fprintf(file_sum, "%8s  %3d  %4.1f", prot_name, N, cutoff);
  // Anisotropic B factors
  if(ANISOU){
    if(strncmp(model, "INM", 3)!=0){
      n_aniso=Compare_anisou(aniso_pred, aniso_exp, nca, model, inter,
			     file_aniso, prot_name, N, weight,
			     &dot_aniso, &ov_aniso, &delta_aniso);
    }
    fprintf(file_sum, "\t%3d\t%.3f\t%6.3f\t%.4f",
	    n_aniso, ov_aniso, dot_aniso, delta_aniso);
  }
  fprintf(file_sum, "\t%s\n", REF_ATM);
  fflush(file_sum);

  // Print isotropic B factors
  sprintf(string, "%s_%s", model, inter);
  Rescale(B_CA, nca, slope, offset);
  Print_B(B_CA, nca, file_B, string, r);

  // Normalize eigenvalues
  if(slope>0)for(i=0; i<N; i++)eigen_value[i]/=slope;
  // for(i=0; i<N; i++)eigen_value[i]*=100;
  // Print negative eigenvalues, if any
  for(i=0; i<N; i++){
    if(eigen_value[i]<-0.001){
      if(neg==0){printf("Negative eigenvalues:\n"); neg=1;}
      printf("%.4f\n", eigen_value[i]);
    }
  }

  // Print normal modes
  sprintf(outfile, "%s_%s_%s", prot_name, inter, model);
  Print_modes_old(eigen_value, eigen_vector, eigen_B,
		  Cart_collectivity, Tors_collectivity, N, N_MODES,
		  atoms, N_atoms, nca, seq, axes, N_axes, outfile, model,
		  Cart_mode, atom_ref, N_ref);

  return(r);

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movss %xmm0, 0x70(%rsp)
movq %r9, 0x90(%rsp)
movq %rcx, 0x98(%rsp)
movq %rdx, %r15
movq %rsi, %r12
movl %edi, 0x68(%rsp)
movq 0x278(%rsp), %r13
movq 0x260(%rsp), %rbx
movq 0x228(%rsp), %rdi
movl 0x210(%rsp), %edx
movq 0x230(%rsp), %rsi
andl $0x0, 0x80(%rsp)
andl $0x0, 0x7c(%rsp)
movl $0x40000000, 0x78(%rsp) # imm = 0x40000000
leaq 0x6c(%rsp), %rbp
leaq 0x84(%rsp), %r14
movq %rbp, %rcx
movq %r14, %r8
callq 0xfe18
movss %xmm0, 0x64(%rsp)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x88(%rsp)
leaq 0x2d827(%rip), %rdi     # 0x52e4a
movq %r12, %rsi
movq %rbx, %rdx
movq %r15, %rcx
movb $0x1, %al
callq 0x20f0
cvtss2sd 0x70(%rsp), %xmm0
leaq 0x2d82a(%rip), %rsi     # 0x52e6a
movq %r13, %rdi
movq %r12, %rdx
movq %rbx, %rcx
movb $0x1, %al
callq 0x2190
cvtss2sd (%rbp), %xmm1
cvtss2sd (%r14), %xmm2
leaq 0x2d817(%rip), %rsi     # 0x52e78
movq %r13, %rdi
movsd 0x88(%rsp), %xmm0
movb $0x3, %al
callq 0x2190
leaq 0x3ea85(%rip), %rax     # 0x64100
xorl %ebx, %ebx
cmpl %ebx, (%rax)
movq %r12, 0x70(%rsp)
je 0x25725
cmpb $0x49, (%r12)
jne 0x256b3
cmpb $0x4e, 0x1(%r12)
jne 0x256b3
cmpb $0x4d, 0x2(%r12)
jne 0x256b3
xorl %edx, %edx
xorps %xmm1, %xmm1
movsd 0x259ca(%rip), %xmm2    # 0x4b078
xorps %xmm0, %xmm0
jmp 0x25714
movq 0x250(%rsp), %rsi
movq 0x248(%rsp), %rdi
movq 0x238(%rsp), %rax
leaq 0x78(%rsp), %r14
movq %r14, 0x28(%rsp)
leaq 0x7c(%rsp), %r12
movq %r12, 0x20(%rsp)
leaq 0x80(%rsp), %rbp
movq %rbp, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movl 0x210(%rsp), %edx
callq 0x250bc
movl %eax, %edx
cvtss2sd (%r12), %xmm0
movq 0x70(%rsp), %r12
cvtss2sd (%rbp), %xmm1
cvtss2sd (%r14), %xmm2
leaq 0x2d770(%rip), %rsi     # 0x52e8b
movq %r13, %rdi
movb $0x3, %al
callq 0x2190
movq 0x288(%rsp), %rbp
leaq 0x31ea0(%rip), %rsi     # 0x575d4
movq %r13, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x2190
movq %r13, %rdi
callq 0x21e0
leaq 0x2d753(%rip), %rsi     # 0x52ea3
leaq 0xa0(%rsp), %r14
movq %r14, %rdi
movq %r12, %rdx
movq 0x260(%rsp), %rcx
xorl %eax, %eax
callq 0x2260
movss 0x6c(%rsp), %xmm0
movss 0x84(%rsp), %xmm1
movq 0x228(%rsp), %r12
movq %r12, %rdi
movl 0x210(%rsp), %r15d
movl %r15d, %esi
callq 0x254b4
movq %r12, %rdi
movl %r15d, %esi
movq 0x270(%rsp), %rdx
movq %r14, %rcx
movss 0x64(%rsp), %xmm0
callq 0x2591a
movl 0x68(%rsp), %eax
testl %eax, %eax
cmovgl %eax, %ebx
movss 0x6c(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x257e6
xorl %eax, %eax
cmpq %rax, %rbx
je 0x257e6
movss (%rbp,%rax,4), %xmm1
divss %xmm0, %xmm1
movss %xmm1, (%rbp,%rax,4)
incq %rax
jmp 0x257cc
xorl %r15d, %r15d
movsd 0x2d2cf(%rip), %xmm1    # 0x52ac0
leaq 0x2dc90(%rip), %r13     # 0x53488
leaq 0x2f0cd(%rip), %r14     # 0x548cc
pushq $0x1
popq %r12
xorl %eax, %eax
cmpq %r15, %rbx
je 0x25844
cvtss2sd (%rbp,%r15,4), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x2583f
testl %eax, %eax
jne 0x2582a
movq %r13, %rdi
callq 0x2090
cvtss2sd (%rbp,%r15,4), %xmm0
movq %r14, %rdi
movb $0x1, %al
callq 0x20f0
movl %r12d, %eax
movsd 0x2d281(%rip), %xmm1    # 0x52ac0
incq %r15
jmp 0x25805
leaq 0x2d655(%rip), %rsi     # 0x52ea0
leaq 0x110(%rsp), %r14
movq %r14, %rdi
movq 0x268(%rsp), %rdx
movq 0x260(%rsp), %rcx
movq 0x70(%rsp), %rbx
movq %rbx, %r8
xorl %eax, %eax
callq 0x2260
movl 0x2b8(%rsp), %eax
movl %eax, 0x58(%rsp)
movq 0x2b0(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x2a8(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %rbx, 0x40(%rsp)
movq %r14, 0x38(%rsp)
movq 0x218(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x258(%rsp), %eax
movl %eax, (%rsp)
movq %rbp, %rdi
movq 0x280(%rsp), %rsi
movq 0x290(%rsp), %rdx
movq 0x298(%rsp), %rcx
movq 0x2a0(%rsp), %r8
movl 0x68(%rsp), %r9d
callq 0x2599b
movss 0x64(%rsp), %xmm0
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq