// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/simulation.c
// Function: Switch_bonds
float Switch_bonds(struct bond *bonds, int naxes, char *prots,
		   struct ali_atoms ali_a,
		   atom *atoms1, int natoms1, struct residue *seq1,
		   atom *atoms2, int natoms2, struct residue *seq2)
{
  // Compute chimera conformations switching internal degrees of freedom
  Set_bonds_measure(bonds, natoms1, atoms1);

  struct bond *bonds2=Set_bonds_topology(natoms2, atoms2, seq2);
  Set_bonds_measure(bonds2, natoms2, atoms2);

  int i, k, N_ref=ali_a.N_ref;
  printf("Switching internal coordinates for %d (all) and %d (ref) atoms ",
	 natoms1, N_ref);
  printf("to match %d (all) atoms of str.2\n", natoms2);

  // Compute differences of internal coordinates
  Internal_differences(bonds, bonds2, natoms1, prots);

  // RMSD all atoms
  int ncart1=3*natoms1, ncart2=3*natoms2;
  float coord1[ncart1]; Put_coord(coord1, bonds, natoms1);
  float coord2[ncart2]; Put_coord(coord2, bonds2, natoms2);
  float coord_new[ncart1];
  int natom=natoms1; if(natoms2<natom)natom=natoms2;
  float mass[natom]; for(i=0; i<natom; i++)mass[i]=1;
  float RMSD=rmsd_mclachlan_f(coord1, coord2, mass, natom);

  // Reference coordinates
  int Ncart=3*N_ref;
  float coord_ref1[Ncart], coord_ref2[Ncart], coord_ref[Ncart];
  Write_ref_coord(coord_ref2, N_ref, coord2, ali_a.ali2);
  Write_ref_coord(coord_ref1, N_ref, coord1, ali_a.ali1);
  RMSD=rmsd_mclachlan_f(coord_ref1, coord_ref2, ali_a.mass, N_ref);
  printf("RMSD ini end: %.3f\n", RMSD);

  char name_pdb[100]; sprintf(name_pdb, "Chimera_%s.pdb", prots);
  FILE *file_pdb=fopen(name_pdb, "w");
  Print_PDB(file_pdb,atoms1,natoms1,coord1,seq1,0,0.00);

  int same=1;
  for(k=1; k<=3; k++){
    printf("Switching internal coordinates of type <= %d\n", k);
    Set_bonds_measure(bonds, natoms1, atoms1);
    Change_internal(NULL, 0, bonds, bonds2, natoms1, k, same);
    Build_up(bonds, natoms1, NULL, naxes);
    Put_coord(coord_new, bonds, natoms1);
    Write_ref_coord(coord_ref, N_ref, coord_new, ali_a.ali1);
    RMSD=rmsd_mclachlan_f(coord_ref1, coord_ref, mass, N_ref);
    printf("RMSD with struct 1: %.3f\n", RMSD);
    RMSD=rmsd_mclachlan_f(coord_ref2, coord_ref, mass, N_ref);
    printf("RMSD with struct 2: %.3f\n", RMSD);
    rmsd_mclachlan_f(coord1, coord_new, mass, natom);
    Print_PDB(file_pdb, atoms1, natoms1, coord_new, seq1, k, RMSD);
  }
  //Print_PDB(file_pdb, atoms2, natoms2, coord2, seq2, k, 0.00);
  printf("Writing %s\n", name_pdb);
  fclose(file_pdb);

  //Compare_build_up(bonds, natoms1, NULL, naxes, bonds2);
  free(bonds2);
  return(RMSD);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %r9, -0x80(%rbp)
movl %r8d, %r14d
movq %rdx, -0x30(%rbp)
movl %esi, -0x54(%rbp)
movq %rdi, %r13
movl 0x38(%rbp), %ebx
movq 0x30(%rbp), %r12
movq 0x40(%rbp), %r15
movl %r8d, %esi
movq %rcx, -0x50(%rbp)
movq %rcx, %rdx
callq 0x139f6
movl %ebx, %edi
movq %r12, %rsi
movq %r15, %rdx
callq 0x14356
movq %rax, %r15
movq %rax, %rdi
movq %rax, -0x48(%rbp)
movl %ebx, %esi
movq %r12, %rdx
callq 0x139f6
leaq 0x10(%rbp), %rax
movl 0x18(%rax), %edx
leaq 0x21253(%rip), %rdi     # 0x556df
xorl %r12d, %r12d
movl %r14d, %esi
movq %rdx, -0x68(%rbp)
xorl %eax, %eax
callq 0x20f0
leaq 0x2127b(%rip), %rdi     # 0x5571f
movl %ebx, %esi
xorl %eax, %eax
callq 0x20f0
movq %r13, %rdi
movq %r15, %rsi
movl %r14d, %edx
movq -0x30(%rbp), %rcx
callq 0x347de
leal (%r14,%r14,2), %eax
leal (%rbx,%rbx,2), %ecx
movq %rcx, -0x38(%rbp)
leaq 0xf(,%rax,4), %r15
andq $-0x10, %r15
movq %rsp, %rdi
subq %r15, %rdi
movq %rdi, %rsp
movq %rdi, -0x40(%rbp)
movq %r13, -0xb8(%rbp)
movq %r13, %rsi
movl %r14d, %edx
callq 0x2f358
movq -0x38(%rbp), %rax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
movq %r13, %rdi
movq -0x48(%rbp), %rsi
movl %ebx, %edx
callq 0x2f358
movq %rsp, %rax
subq %r15, %rax
movq %rax, -0xb0(%rbp)
movq %rax, %rsp
cmpl %r14d, %ebx
movq %r14, -0x78(%rbp)
cmovgel %r14d, %ebx
leaq 0xf(,%rbx,4), %rax
andq $-0x10, %rax
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, %rsp
testl %ebx, %ebx
movl $0x0, %eax
movq %rbx, -0x70(%rbp)
cmovgl %ebx, %eax
cmpq %r12, %rax
je 0x3456c
movl $0x3f800000, (%rdx,%r12,4) # imm = 0x3F800000
incq %r12
jmp 0x3455a
movq -0x40(%rbp), %rdi
movq %r13, %rsi
movq %rdx, -0xa8(%rbp)
movq -0x70(%rbp), %rcx
callq 0x47a64
movq -0x68(%rbp), %rbx
leal (%rbx,%rbx,2), %eax
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %r15
subq %rax, %r15
movq %r15, %rsp
movq %rsp, %r12
subq %rax, %r12
movq %r12, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x90(%rbp)
movq %rcx, %rsp
leaq 0x10(%rbp), %r14
movq 0x8(%r14), %rcx
movq %r12, %rdi
movl %ebx, %esi
movq %r13, %rdx
callq 0x2f9b8
movq (%r14), %rcx
movq %r15, %rdi
movl %ebx, %esi
movq -0x40(%rbp), %rdx
movq %rcx, -0x88(%rbp)
callq 0x2f9b8
movq 0x10(%r14), %rdx
movq %r15, -0xa0(%rbp)
movq %r15, %rdi
movq %r12, -0x98(%rbp)
movq %r12, %rsi
movl %ebx, %ecx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
cvtss2sd %xmm0, %xmm0
leaq 0x21129(%rip), %rdi     # 0x55741
movb $0x1, %al
callq 0x20f0
leaq 0x2112f(%rip), %rsi     # 0x55755
leaq -0x120(%rbp), %r13
movq %r13, %rdi
movq -0x30(%rbp), %rdx
xorl %eax, %eax
callq 0x2260
leaq 0x1cb0e(%rip), %rsi     # 0x51150
movq %r13, %rdi
callq 0x2210
xorps %xmm0, %xmm0
movq %rax, -0x60(%rbp)
movq %rax, %rdi
movq -0x50(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x40(%rbp), %rcx
movq -0x80(%rbp), %r8
xorl %r9d, %r9d
callq 0x2f4bd
pushq $0x1
popq %rsi
movq -0x78(%rbp), %r12
movq -0xb0(%rbp), %r15
movq -0x90(%rbp), %r13
movq -0xa8(%rbp), %r14
cmpl $0x4, %esi
je 0x347a3
leaq 0x210cc(%rip), %rdi     # 0x55764
xorl %eax, %eax
movl %esi, -0x30(%rbp)
callq 0x20f0
movq -0xb8(%rbp), %rbx
movq %rbx, %rdi
movl %r12d, %esi
movq -0x50(%rbp), %rdx
callq 0x139f6
subq $0x8, %rsp
xorl %edi, %edi
xorl %esi, %esi
movq %rbx, %rdx
movq -0x48(%rbp), %rcx
movl %r12d, %r8d
movl -0x30(%rbp), %r9d
pushq $0x1
callq 0x35418
popq %rcx
popq %rdx
movq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
movl -0x54(%rbp), %ecx
callq 0x13d70
movq %r15, %rdi
movq %rbx, %rsi
movl %r12d, %edx
callq 0x2f358
movq %r13, %rdi
movq -0x68(%rbp), %rbx
movl %ebx, %esi
movq %r15, %rdx
movq -0x88(%rbp), %rcx
callq 0x2f9b8
movq -0xa0(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x21062(%rip), %rdi     # 0x55792
movb $0x1, %al
callq 0x20f0
movq -0x98(%rbp), %rdi
movq %r13, %rsi
movq %r14, %rdx
movl %ebx, %ecx
callq 0x47a64
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x38(%rbp)
cvtss2sd %xmm0, %xmm0
leaq 0x2104d(%rip), %rdi     # 0x557ac
movb $0x1, %al
callq 0x20f0
movq -0x40(%rbp), %rdi
movq %r15, %rsi
movq %r14, %rdx
movq -0x70(%rbp), %rcx
callq 0x47a64
movq -0x60(%rbp), %rdi
movq -0x50(%rbp), %rsi
movl %r12d, %edx
movq %r15, %rcx
movq -0x80(%rbp), %r8
movl -0x30(%rbp), %r9d
movss -0x38(%rbp), %xmm0
callq 0x2f4bd
movl -0x30(%rbp), %esi
incl %esi
jmp 0x34688
leaq 0x174fd(%rip), %rdi     # 0x4bca7
leaq -0x120(%rbp), %rsi
xorl %eax, %eax
callq 0x20f0
movq -0x60(%rbp), %rdi
callq 0x20c0
movq -0x48(%rbp), %rdi
callq 0x2050
movss -0x38(%rbp), %xmm0
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq