// File: /workspace/github_c_makefile_star2_O0/ugobas[P]tnm/simulation.c
// Function: Make_conformations
int Make_conformations(char type, int N_frames, double *d_phi, float *d_Cart,
		       float factor, float coeff, float rmsd0,
		       float *coord_all_f, float *coord_opt_f,
		       float *coord_ref, float *coord_ref2,
		       int PRINT_SIMUL_PDB, FILE *file_out, FILE *file_pdb,
		       float *coord_str1, float *coord_str2,
		       struct Para_simul Para_simul,
		       atom *atoms, int natoms,
		       struct axe *axe, int naxes,
		       struct bond *bonds,
		       struct residue *seq, int nres,
		       int N_diso, struct Normal_Mode NM,
		       struct Jacobian J, struct Reference Ref,
		       struct interaction *Int_list, int N_int,
		       char *INT_TYPE, float s0, char *nameout,
		       int anhar)
{
  /* type: C= Cartesian interpolation T= torsional interpolation R= random */
  float *sigma2;
  if(anhar){sigma2=NM.sigma2_anhar;}
  else{sigma2=NM.sigma2;}

  float Ene=Energy_clashes(coord_str1, Ref.N_ref), Ene_thr=40*Ene;

  // Initialization

  char summary3[400]; sprintf(summary3, "Summary_%s_simul.dat", nameout);
  int k, i; 
  Set_bonds_measure(bonds, natoms, atoms);
  Put_coord(coord_all_f, bonds, natoms);
  Write_ref_coord(coord_ref2, Ref.N_ref, coord_all_f, Ref.atom_num);

  float *sigma=NULL;
  if(type=='R'){
    if(Ini_ch){
      Allocate_tors(&Diff_s, naxes, NM.N_Cart, NM.N);
      ali_sim.alignres=malloc(nres*sizeof(int));
      Ini_ch=0;
      ali_sim.seq_id=100; ali_sim.mammoth=0;
      for(i=0; i<nres; i++)ali_sim.alignres[i]=i;
      idum=IDUM;
    }
    sigma=malloc(NM.N*sizeof(float));
    for(k=0; k<NM.N; k++){
      if(sigma2[k]>0){sigma[k]=sqrt(sigma2[k]);}
      else{sigma[k]=0;}
    }
  }else if(type=='T'){
    float d_thr=0.01, d_max=0;
    for(i=0; i<naxes; i++)if(fabs(d_phi[i])>d_max)d_max=fabs(d_phi[i]);
    if(d_max>d_thr){
      float f=d_thr/d_max; for(i=0; i<naxes; i++)d_phi[i]*=f;
      printf("Reducing angular changes by a factor %.3f\n", f);
    }
  }


  int k_opt=0, nn=N_frames; if(type!='R')nn=1000;
  float rmsd_sim=0, rmsd1=0, rmsd2=rmsd0, rmsd_min=1000, rmsd1_min=0;

  for(k=0; k<=nn; k++){

    if(k==0)goto Print;
    if(type=='C'){
      float ck=k*coeff;
      for(i=0; i<Ref.N_Cart; i++)coord_ref[i]=coord_str1[i]+ck*d_Cart[i];
    }else{
      if(type=='R'){ // Random simulation starting from PDB
	Extract_dphi(d_phi, NM.Tors, sigma, NM.N, naxes, factor, &idum);
      }
      Build_up(bonds, natoms, d_phi, naxes);
      Put_coord(coord_all_f, bonds, natoms);
      Write_ref_coord(coord_ref, Ref.N_ref, coord_all_f, Ref.atom_num);
    }
    Ene=Energy_clashes(coord_ref, Ref.N_ref);

    // RMSD computation
    rmsd_sim=rmsd_mclachlan_f(coord_ref2, coord_ref, Ref.mass_atom, Ref.N_ref);
    for(i=0; i<Ref.N_Cart; i++)coord_ref2[i]=coord_ref[i];
    rmsd1=rmsd_mclachlan_f(coord_str1, coord_ref, Ref.mass_atom, Ref.N_ref);
    if(coord_str2){
      rmsd2=rmsd_mclachlan_f(coord_str2, coord_ref, Ref.mass_atom, Ref.N_ref);
      if(rmsd2<rmsd_min){
	Put_coord(coord_opt_f, bonds, natoms); 
	rmsd_min=rmsd2; rmsd1_min=rmsd1; k_opt=k;
      }
    }

    /*if(type=='R'){     // Projection of conformation change on normal modes
      atom atoms_sim[natoms]; int cc;
      for(i=0; i<natoms; i++)atoms_sim[i]=atoms[i];
      Examine_confchange(&Diff_s, bonds, axe, NULL, 0, summary3, nameout, "", 
			 atoms, coord_str1, seq, nres, N_diso, natoms,
			 atoms_sim, coord_ref, seq, nres, N_diso, natoms,
			 Int_list, N_int, INT_TYPE, s0, NM.N, Ref, NM, //&J, 
			 k, ali_sim, Para_simul, k, 
			 NULL, NULL, NULL, 0, anhar);
			 }*/

  Print:
    fprintf(file_out, "%d %.3f %.3f %.4f %.3g\n",
	    k, rmsd_sim, rmsd1, rmsd2, Ene);
    if((PRINT_SIMUL_PDB)&&((type=='R')||((k==0)&&(type=='T')))){
      if(Ene < Ene_thr){
	Print_PDB(file_pdb, atoms, natoms, coord_all_f, seq, k, rmsd_sim);
      }
    }
    if((type!='R')&&(rmsd2>rmsd_min))break;
  }
  char str[1000];
  sprintf(str, "# Min.RMSD= %.2f Starting_RMSD= %.2f"
	  " Opt_coeff=%.3f factor= %.3f type=%c\n",
	  rmsd_min, rmsd0, coeff*k_opt, factor, type);
  fprintf(file_out, "%s", str); printf("%s", str);
  fprintf(file_out, "&\n");
  if((PRINT_SIMUL_PDB)&&(type!='R')&&(k_opt>=0)){
    if(type=='C'){
      fprintf(file_pdb, "REMARK: predicted Cartesian mutation\n");
    }else{
      fprintf(file_pdb, "REMARK: predicted Torsional mutation\n");
    }
    Print_PDB(file_pdb, atoms, natoms, coord_opt_f, seq, k, rmsd1_min);
  }
  if(sigma)free(sigma);
  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x620, %rsp            # imm = 0x620
movb %dil, %al
movl 0x230(%rbp), %edi
movq 0x228(%rbp), %rdi
movq 0x220(%rbp), %rdi
movl 0x218(%rbp), %edi
movq 0x210(%rbp), %rdi
leaq 0x1e0(%rbp), %rdi
movq %rdi, -0x620(%rbp)
leaq 0xc8(%rbp), %rdi
movq %rdi, -0x618(%rbp)
movl 0xc0(%rbp), %edi
movl 0xb8(%rbp), %edi
movq 0xb0(%rbp), %rdi
movq 0xa8(%rbp), %rdi
movl 0xa0(%rbp), %edi
movq 0x98(%rbp), %rdi
movl 0x90(%rbp), %edi
movq 0x88(%rbp), %rdi
movq 0x40(%rbp), %rdi
movq 0x38(%rbp), %rdi
movq 0x30(%rbp), %rdi
movq 0x28(%rbp), %rdi
movl 0x20(%rbp), %edi
movq 0x18(%rbp), %rdi
movq 0x10(%rbp), %rdi
movb %al, -0x1(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
movss %xmm1, -0x20(%rbp)
movss %xmm2, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movss %xmm3, -0x3c(%rbp)
cmpl $0x0, 0x230(%rbp)
je 0x4fdd1
movq -0x618(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x4fde0
movq -0x618(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x620(%rbp), %rax
movq 0x38(%rbp), %rdi
movl (%rax), %esi
callq 0x49810
movss %xmm0, -0x4c(%rbp)
movss 0x30259(%rip), %xmm0    # 0x80058
mulss -0x4c(%rbp), %xmm0
movss %xmm0, -0x50(%rbp)
leaq -0x1e0(%rbp), %rdi
movq 0x228(%rbp), %rdx
leaq 0x30b88(%rip), %rsi     # 0x809a6
movb $0x0, %al
callq 0x1200
movq 0xa8(%rbp), %rdi
movl 0x90(%rbp), %esi
movq 0x88(%rbp), %rdx
callq 0x1bf00
movq -0x30(%rbp), %rdi
movq 0xa8(%rbp), %rsi
movl 0x90(%rbp), %edx
callq 0x49770
movq -0x620(%rbp), %rax
movq 0x18(%rbp), %rdi
movl (%rax), %esi
movq -0x30(%rbp), %rdx
movq 0x28(%rax), %rcx
callq 0x4a1d0
movq $0x0, -0x1f0(%rbp)
movsbl -0x1(%rbp), %eax
cmpl $0x52, %eax
jne 0x4ffe7
cmpl $0x0, 0x3bff7(%rip)     # 0x8be84
je 0x4ff37
movq -0x618(%rbp), %rax
movl 0xa0(%rbp), %esi
movl 0xc(%rax), %edx
movl (%rax), %ecx
leaq 0x4c62c(%rip), %rdi     # 0x9c4d8
callq 0x163a0
movslq 0xb8(%rbp), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, 0x4c668(%rip)     # 0x9c530
movl $0x0, 0x3bfb2(%rip)     # 0x8be84
movss 0x261d6(%rip), %xmm0    # 0x760b0
movss %xmm0, 0x4c636(%rip)    # 0x9c518
movl $0x0, 0x4c64c(%rip)     # 0x9c538
movl $0x0, -0x1e8(%rbp)
movl -0x1e8(%rbp), %eax
cmpl 0xb8(%rbp), %eax
jge 0x4ff2c
movl -0x1e8(%rbp), %edx
movq 0x4c61f(%rip), %rax     # 0x9c530
movslq -0x1e8(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x1e8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e8(%rbp)
jmp 0x4fef6
movq $-0xb2a3, 0x4c599(%rip) # imm = 0xFFFF4D5D
movq -0x618(%rbp), %rax
movslq (%rax), %rdi
shlq $0x2, %rdi
callq 0x1180
movq %rax, -0x1f0(%rbp)
movl $0x0, -0x1e4(%rbp)
movq -0x618(%rbp), %rcx
movl -0x1e4(%rbp), %eax
cmpl (%rcx), %eax
jge 0x4ffe2
movq -0x48(%rbp), %rax
movslq -0x1e4(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x4ffb6
movq -0x48(%rbp), %rax
movslq -0x1e4(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
callq 0x1220
cvtsd2ss %xmm0, %xmm0
movq -0x1f0(%rbp), %rax
movslq -0x1e4(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
jmp 0x4ffcc
movq -0x1f0(%rbp), %rax
movslq -0x1e4(%rbp), %rcx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
jmp 0x4ffce
movl -0x1e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e4(%rbp)
jmp 0x4ff5b
jmp 0x5011f
movsbl -0x1(%rbp), %eax
cmpl $0x54, %eax
jne 0x5011d
movss 0x2c3ec(%rip), %xmm0    # 0x7c3e8
movss %xmm0, -0x1f4(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x1f8(%rbp)
movl $0x0, -0x1e8(%rbp)
movl -0x1e8(%rbp), %eax
cmpl 0xa0(%rbp), %eax
jge 0x5008e
movq -0x10(%rbp), %rax
movslq -0x1e8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movaps 0x2c452(%rip), %xmm1    # 0x7c490
pand %xmm1, %xmm0
movss -0x1f8(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x5007b
movq -0x10(%rbp), %rax
movslq -0x1e8(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movaps 0x2c425(%rip), %xmm1    # 0x7c490
pand %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x1f8(%rbp)
jmp 0x5007d
movl -0x1e8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e8(%rbp)
jmp 0x50019
movss -0x1f8(%rbp), %xmm0
ucomiss -0x1f4(%rbp), %xmm0
jbe 0x5011b
movss -0x1f4(%rbp), %xmm0
divss -0x1f8(%rbp), %xmm0
movss %xmm0, -0x1fc(%rbp)
movl $0x0, -0x1e8(%rbp)
movl -0x1e8(%rbp), %eax
cmpl 0xa0(%rbp), %eax
jge 0x50101
movss -0x1fc(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movq -0x10(%rbp), %rax
movslq -0x1e8(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl -0x1e8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e8(%rbp)
jmp 0x500c1
movss -0x1fc(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x308a7(%rip), %rdi     # 0x809bb
movb $0x1, %al
callq 0x10d0
jmp 0x5011d
jmp 0x5011f
movl $0x0, -0x200(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x204(%rbp)
movsbl -0x1(%rbp), %eax
cmpl $0x52, %eax
je 0x50145
movl $0x3e8, -0x204(%rbp)    # imm = 0x3E8
xorps %xmm0, %xmm0
movss %xmm0, -0x208(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x20c(%rbp)
movss -0x24(%rbp), %xmm0
movss %xmm0, -0x210(%rbp)
movss 0x2c270(%rip), %xmm0    # 0x7c3e0
movss %xmm0, -0x214(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x218(%rbp)
movl $0x0, -0x1e4(%rbp)
movl -0x1e4(%rbp), %eax
cmpl -0x204(%rbp), %eax
jg 0x504d7
cmpl $0x0, -0x1e4(%rbp)
jne 0x501ad
jmp 0x503fe
movsbl -0x1(%rbp), %eax
cmpl $0x43, %eax
jne 0x50241
cvtsi2ssl -0x1e4(%rbp), %xmm0
mulss -0x20(%rbp), %xmm0
movss %xmm0, -0x21c(%rbp)
movl $0x0, -0x1e8(%rbp)
movq -0x620(%rbp), %rcx
movl -0x1e8(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0x5023c
movq 0x38(%rbp), %rax
movslq -0x1e8(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
movss -0x21c(%rbp), %xmm0
movq -0x18(%rbp), %rax
movslq -0x1e8(%rbp), %rcx
movss (%rax,%rcx,4), %xmm2
mulss %xmm2, %xmm0
addss %xmm1, %xmm0
movq 0x10(%rbp), %rax
movslq -0x1e8(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x1e8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e8(%rbp)
jmp 0x501d9
jmp 0x502c6
movsbl -0x1(%rbp), %eax
cmpl $0x52, %eax
jne 0x5027a
movq -0x618(%rbp), %rax
movq -0x10(%rbp), %rdi
movq 0x40(%rax), %rsi
movq -0x1f0(%rbp), %rdx
movl (%rax), %ecx
movl 0xa0(%rbp), %r8d
movss -0x1c(%rbp), %xmm0
leaq 0x4c25b(%rip), %r9      # 0x9c4d0
callq 0x49d30
movq 0xa8(%rbp), %rdi
movl 0x90(%rbp), %esi
movq -0x10(%rbp), %rdx
movl 0xa0(%rbp), %ecx
callq 0x1c4f0
movq -0x30(%rbp), %rdi
movq 0xa8(%rbp), %rsi
movl 0x90(%rbp), %edx
callq 0x49770
movq -0x620(%rbp), %rax
movq 0x10(%rbp), %rdi
movl (%rax), %esi
movq -0x30(%rbp), %rdx
movq 0x28(%rax), %rcx
callq 0x4a1d0
movq -0x620(%rbp), %rax
movq 0x10(%rbp), %rdi
movl (%rax), %esi
callq 0x49810
movq -0x620(%rbp), %rax
movss %xmm0, -0x4c(%rbp)
movq 0x18(%rbp), %rdi
movq 0x10(%rbp), %rsi
movq 0x10(%rax), %rdx
movl (%rax), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x208(%rbp)
movl $0x0, -0x1e8(%rbp)
movq -0x620(%rbp), %rcx
movl -0x1e8(%rbp), %eax
cmpl 0x4(%rcx), %eax
jge 0x50350
movq 0x10(%rbp), %rax
movslq -0x1e8(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movq 0x18(%rbp), %rax
movslq -0x1e8(%rbp), %rcx
movss %xmm0, (%rax,%rcx,4)
movl -0x1e8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e8(%rbp)
jmp 0x5030d
movq -0x620(%rbp), %rax
movq 0x38(%rbp), %rdi
movq 0x10(%rbp), %rsi
movq 0x10(%rax), %rdx
movl (%rax), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x20c(%rbp)
cmpq $0x0, 0x40(%rbp)
je 0x503fc
movq -0x620(%rbp), %rax
movq 0x40(%rbp), %rdi
movq 0x10(%rbp), %rsi
movq 0x10(%rax), %rdx
movl (%rax), %ecx
callq 0x70af0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x210(%rbp)
movss -0x210(%rbp), %xmm1
movss -0x214(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x503fa
movq -0x38(%rbp), %rdi
movq 0xa8(%rbp), %rsi
movl 0x90(%rbp), %edx
callq 0x49770
movss -0x210(%rbp), %xmm0
movss %xmm0, -0x214(%rbp)
movss -0x20c(%rbp), %xmm0
movss %xmm0, -0x218(%rbp)
movl -0x1e4(%rbp), %eax
movl %eax, -0x200(%rbp)
jmp 0x503fc
jmp 0x503fe
movq 0x28(%rbp), %rdi
movl -0x1e4(%rbp), %edx
movss -0x208(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x20c(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x210(%rbp), %xmm2
cvtss2sd %xmm2, %xmm2
movss -0x4c(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
leaq 0x305aa(%rip), %rsi     # 0x809e6
movb $0x4, %al
callq 0x1150
cmpl $0x0, 0x20(%rbp)
je 0x504a5
movsbl -0x1(%rbp), %eax
cmpl $0x52, %eax
je 0x50464
cmpl $0x0, -0x1e4(%rbp)
jne 0x504a5
movsbl -0x1(%rbp), %eax
cmpl $0x54, %eax
jne 0x504a5
movss -0x4c(%rbp), %xmm1
movss -0x50(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x504a3
movq 0x30(%rbp), %rdi
movq 0x88(%rbp), %rsi
movl 0x90(%rbp), %edx
movq -0x30(%rbp), %rcx
movq 0xb0(%rbp), %r8
movl -0x1e4(%rbp), %r9d
movss -0x208(%rbp), %xmm0
callq 0x49a60
jmp 0x504a5
movsbl -0x1(%rbp), %eax
cmpl $0x52, %eax
je 0x504c1
movss -0x210(%rbp), %xmm0
ucomiss -0x214(%rbp), %xmm0
jbe 0x504c1
jmp 0x504d7
jmp 0x504c3
movl -0x1e4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1e4(%rbp)
jmp 0x5018d
leaq -0x610(%rbp), %rdi
movss -0x214(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
movss -0x24(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
movss -0x20(%rbp), %xmm2
cvtsi2ssl -0x200(%rbp), %xmm3
mulss %xmm3, %xmm2
cvtss2sd %xmm2, %xmm2
movss -0x1c(%rbp), %xmm3
cvtss2sd %xmm3, %xmm3
movsbl -0x1(%rbp), %edx
leaq 0x304e2(%rip), %rsi     # 0x809fe
movb $0x4, %al
callq 0x1200
movq 0x28(%rbp), %rdi
leaq -0x610(%rbp), %rdx
leaq 0x2be69(%rip), %rsi     # 0x7c39e
movb $0x0, %al
callq 0x1150
leaq -0x610(%rbp), %rsi
leaq 0x2be54(%rip), %rdi     # 0x7c39e
movb $0x0, %al
callq 0x10d0
movq 0x28(%rbp), %rdi
leaq 0x2ce38(%rip), %rsi     # 0x7d394
movb $0x0, %al
callq 0x1150
cmpl $0x0, 0x20(%rbp)
je 0x505da
movsbl -0x1(%rbp), %eax
cmpl $0x52, %eax
je 0x505da
cmpl $0x0, -0x200(%rbp)
jl 0x505da
movsbl -0x1(%rbp), %eax
cmpl $0x43, %eax
jne 0x50598
movq 0x30(%rbp), %rdi
leaq 0x304b9(%rip), %rsi     # 0x80a48
movb $0x0, %al
callq 0x1150
jmp 0x505aa
movq 0x30(%rbp), %rdi
leaq 0x304cb(%rip), %rsi     # 0x80a6e
movb $0x0, %al
callq 0x1150
movq 0x30(%rbp), %rdi
movq 0x88(%rbp), %rsi
movl 0x90(%rbp), %edx
movq -0x38(%rbp), %rcx
movq 0xb0(%rbp), %r8
movl -0x1e4(%rbp), %r9d
movss -0x218(%rbp), %xmm0
callq 0x49a60
cmpq $0x0, -0x1f0(%rbp)
je 0x505f0
movq -0x1f0(%rbp), %rdi
callq 0x1040
xorl %eax, %eax
addq $0x620, %rsp            # imm = 0x620
popq %rbp
retq
nopl (%rax,%rax)