// File: /workspace/github_c_makefile_star2_O2/ugobas[P]tnm/force2confchange.c
// Function: Force2Confchange
int Force2Confchange(float *atom_move, char *FILE_FORCE,
		     int naxe1, int N_ref, atom *atoms1, int natoms1,
		     int *atom_num1, float **Jacobian_ar, float *eigen_value,
		     float **Tors_mode, int *select, struct axe *axe1,
		     char *chain1, int nres1, struct residue *seq1,
		     struct bond *bonds)
{
  int N_cart=3*N_ref, i, ia, j, k;
  double Delta_theta[naxe1];
  float Force_input_cart[N_cart];
  float Force_input_tors[naxe1];
  float Force_input_coef[naxe1];
  double sum;

  //i=Read_force(Force_input_cart, atoms1, atom_num1, N_ref, FILE_FORCE);

  // Read force
  int nres, nmr, ANISOU;
  //~ int natoms;
  atom atom_read[natoms1], *atom;
  struct residue seq[nres1];
  printf("Reading force in file %s\n", FILE_FORCE);
  nres=Read_coord(FILE_FORCE, &nmr, seq, atom_read, chain1, &ANISOU, NULL);
  if(nres<0)return(-1); // file not found
  if(nres!=nres1){
    printf("ERROR, wrong number of residues in force file:");
    printf(" %d instead of %d\n", nres, nres1); return(-1);
  }
  for(i=0; i<nres; i++){
    if(seq[i].amm!=seq1[i].amm){
      printf("ERROR, wrong amino acid in force file\n");
      printf("Position %d, %c instead of %c\n", i, seq[i].amm, seq1[i].amm);
      return(-1);
    }
  }
  for(i=0; i<3*N_ref; i++)Force_input_cart[i]=0;
  for(i=0; i<N_ref; i++){
    atom=Find_atom_seq(seq, nres, atoms1[atom_num1[i]]);
    if(atom==NULL)continue;
    k=3*i; for(j=0; j<3; j++){Force_input_cart[k]=atom->r[j]; k++;}
  }
  // End read force

  for(i=0; i<naxe1; i++){  // Torsional force F^tors_a = sum_i F_i*J_ia
    sum=0; for(j=0; j<N_cart; j++)sum+=Jacobian_ar[i][j]*Force_input_cart[j];
    Force_input_tors[i]=sum;
  }
  for(ia=0; ia<naxe1; ia++){  // c^alpha =(F^tors,u^alpha)
    if(select[ia]==0)continue;
    float *ua=Tors_mode[ia];
    sum=0; for(i=0; i<naxe1; i++)sum+=ua[i]*Force_input_tors[i];
    Force_input_coef[ia]=sum;
  }
  for(i=0; i<naxe1; i++)Delta_theta[i]=0;
  for(ia=0; ia<naxe1; ia++){  // Delta_theta= H^{-1} F^tors
    if(select[ia]==0)continue;
    float *ua=Tors_mode[ia];
    float w=Force_input_coef[ia]/eigen_value[ia];
    for(i=0; i<naxe1; i++)Delta_theta[i]+=w*ua[i];
  }

  // Initialize build up
  Set_bonds_measure(bonds, natoms1, atoms1);
  // Build up Cartesian coordinates from Delta_theta
  Build_up(bonds, natoms1, Delta_theta, naxe1);
  k=3;
  for(i=1;i<N_ref;i++){
    struct bond *bond=bonds+atom_num1[i];
    for(j=0; j<3; j++){
      atom_move[k]=bond->r[j]; k++;
    }
  }
  return(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %r8, -0x68(%rbp)
movq %rsi, %r13
movq %rdi, -0x90(%rbp)
movl 0x48(%rbp), %edi
movq %rcx, -0x58(%rbp)
leal (%rcx,%rcx,2), %r12d
movl %edx, -0x2c(%rbp)
movl %edx, %edx
movq %rsp, %rcx
leaq 0xf(,%rdx,8), %rax
andq $-0x10, %rax
subq %rax, %rcx
movq %rcx, -0x88(%rbp)
movq %rcx, %rsp
leaq 0xf(,%r12,4), %rax
andq $-0x10, %rax
movq %rsp, %r14
subq %rax, %r14
movq %r14, %rsp
movq %rsp, %rbx
movq %rdx, -0x80(%rbp)
leaq 0xf(,%rdx,4), %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x78(%rbp)
movq %rcx, %rsp
movl %r9d, -0x4c(%rbp)
movl %r9d, %eax
movq %rsp, %rcx
imulq $0x70, %rax, %rax
subq %rax, %rcx
movq %rcx, -0x48(%rbp)
movq %rcx, %rsp
movq %rsp, %r15
movq %rdi, %rax
shlq $0x5, %rax
subq %rax, %r15
movq %r15, %rsp
leaq 0x1fb0c(%rip), %rdi     # 0x55dfc
xorl %eax, %eax
callq 0x20f0
subq $0x8, %rsp
leaq -0xa0(%rbp), %rsi
leaq -0x9c(%rbp), %r9
movq %r13, %rdi
movq %r15, %rdx
movq -0x48(%rbp), %rcx
movq 0x40(%rbp), %r8
pushq $0x0
callq 0xc74e
addq $0x10, %rsp
pushq $-0x1
popq %r9
testl %eax, %eax
js 0x36667
movl %eax, %r13d
movl 0x48(%rbp), %ecx
cmpl %ecx, %eax
jne 0x36362
movq %rbx, -0x38(%rbp)
movq 0x50(%rbp), %r13
pushq $0x13
popq %rbx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x3638e
movb (%r15,%rbx), %al
cmpb (%r13,%rbx), %al
jne 0x36636
incq %rdx
addq $0x20, %rbx
jmp 0x36345
leaq 0x1faad(%rip), %rdi     # 0x55e16
xorl %eax, %eax
movq %rcx, %rbx
movq %r9, %r14
callq 0x20f0
leaq 0x1fac8(%rip), %rdi     # 0x55e45
movl %r13d, %esi
movl %ebx, %edx
xorl %eax, %eax
callq 0x20f0
jmp 0x36664
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
movq -0x38(%rbp), %r9
cmpq %rax, %r12
je 0x363aa
andl $0x0, (%r14,%rax,4)
incq %rax
jmp 0x3639b
xorl %ecx, %ecx
movq -0x58(%rbp), %rax
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
movq %rdx, -0x98(%rbp)
pushq $0x3
popq %rax
movq %rax, -0x40(%rbp)
xorl %ebx, %ebx
movq %r15, -0x60(%rbp)
cmpq -0x98(%rbp), %rcx
je 0x364b1
movq 0x10(%rbp), %rax
movq %rcx, -0x70(%rbp)
movslq (%rax,%rcx,4), %rax
imulq $0x70, %rax, %rsi
addq -0x68(%rbp), %rsi
leaq -0x110(%rbp), %rdi
pushq $0x70
popq %rdx
callq 0x21a0
movslq -0xac(%rbp), %rax
shlq $0x5, %rax
movb 0x13(%r15,%rax), %cl
cmpb -0xa8(%rbp), %cl
movl %ebx, -0x30(%rbp)
jne 0x3645a
movl %ebx, %ecx
leaq (%r14,%rcx,4), %rcx
movq %rcx, -0x48(%rbp)
addq %r15, %rax
movq (%rax), %r13
movl 0x8(%rax), %ebx
xorl %r15d, %r15d
testl %ebx, %ebx
cmovlel %r15d, %ebx
cmpl %ebx, %r15d
je 0x36466
leaq 0x18(%r13), %rdi
leaq -0xf8(%rbp), %rsi
pushq $0x3
popq %rdx
callq 0x2070
testl %eax, %eax
je 0x36480
addq $0x70, %r13
incl %r15d
jmp 0x36435
leaq 0x1fa7b(%rip), %rdi     # 0x55edc
callq 0x2090
movq -0x38(%rbp), %r9
movq -0x60(%rbp), %r15
movq -0x70(%rbp), %rcx
movl -0x30(%rbp), %ebx
incq %rcx
addl $0x3, %ebx
jmp 0x363ce
testq %r13, %r13
movq -0x38(%rbp), %r9
movq -0x60(%rbp), %r15
movq -0x70(%rbp), %rcx
movl -0x30(%rbp), %ebx
je 0x36475
xorl %eax, %eax
cmpq $0x3, %rax
je 0x36475
cvtsd2ss (%r13,%rax,8), %xmm0
movq -0x48(%rbp), %rdx
movss %xmm0, (%rdx,%rax,4)
incq %rax
jmp 0x36496
xorl %ecx, %ecx
movl -0x2c(%rbp), %edx
testl %edx, %edx
movl $0x0, %eax
cmovgl %edx, %eax
movq 0x18(%rbp), %rdi
cmpq %rax, %rcx
je 0x364ff
xorpd %xmm0, %xmm0
xorl %edx, %edx
cmpq %rdx, %r12
je 0x364f0
movq (%rdi,%rcx,8), %rsi
movss (%rsi,%rdx,4), %xmm1
mulss (%r14,%rdx,4), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rdx
jmp 0x364cf
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r9,%rcx,4)
incq %rcx
jmp 0x364c4
xorl %ecx, %ecx
movq -0x88(%rbp), %r14
movq -0x80(%rbp), %rdi
movq 0x58(%rbp), %r15
movq -0x78(%rbp), %r8
movq 0x30(%rbp), %r10
movq 0x28(%rbp), %r11
cmpq %rax, %rcx
je 0x3655d
cmpl $0x0, (%r10,%rcx,4)
je 0x36558
movq (%r11,%rcx,8), %rdx
xorps %xmm0, %xmm0
xorl %esi, %esi
cmpq %rsi, %rdi
je 0x3654e
movss (%rdx,%rsi,4), %xmm1
mulss (%r9,%rsi,4), %xmm1
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rsi
jmp 0x36531
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%r8,%rcx,4)
incq %rcx
jmp 0x3651c
xorl %ecx, %ecx
movq 0x20(%rbp), %r9
cmpq %rcx, %rax
je 0x36572
andq $0x0, (%r14,%rcx,8)
incq %rcx
jmp 0x36563
xorl %ecx, %ecx
cmpq %rax, %rcx
je 0x365ba
cmpl $0x0, (%r10,%rcx,4)
je 0x365b5
movq (%r11,%rcx,8), %rdx
movss (%r8,%rcx,4), %xmm0
divss (%r9,%rcx,4), %xmm0
xorl %esi, %esi
cmpq %rsi, %rdi
je 0x365b5
movss (%rdx,%rsi,4), %xmm1
mulss %xmm0, %xmm1
cvtss2sd %xmm1, %xmm1
addsd (%r14,%rsi,8), %xmm1
movsd %xmm1, (%r14,%rsi,8)
incq %rsi
jmp 0x36592
incq %rcx
jmp 0x36574
movq %r15, %rdi
movl -0x4c(%rbp), %ebx
movl %ebx, %esi
movq -0x68(%rbp), %rdx
callq 0x139f6
movq %r15, %rdi
movl %ebx, %esi
movq %r14, %rdx
movl -0x2c(%rbp), %ecx
callq 0x13d70
movslq -0x58(%rbp), %rax
addq $0x8, %r15
pushq $0x1
popq %rcx
xorl %r9d, %r9d
movq -0x90(%rbp), %r8
cmpq %rax, %rcx
jge 0x36667
movq 0x10(%rbp), %rdx
movslq (%rdx,%rcx,4), %rdx
movq -0x40(%rbp), %rsi
movslq %esi, %rsi
imulq $0xc0, %rdx, %rdx
addq %r15, %rdx
movq %rsi, -0x40(%rbp)
leaq (%r8,%rsi,4), %rdi
xorl %esi, %esi
cmpq $0x3, %rsi
je 0x3662d
cvtsd2ss (%rdx,%rsi,8), %xmm0
movss %xmm0, (%rdi,%rsi,4)
incq %rsi
jmp 0x36618
incq %rcx
addq %rsi, -0x40(%rbp)
jmp 0x365f0
leaq 0x1f879(%rip), %rdi     # 0x55eb6
movq %r9, %r14
movq %rdx, %r12
callq 0x2090
movsbl (%r15,%rbx), %edx
movsbl (%r13,%rbx), %ecx
leaq 0x1f7fe(%rip), %rdi     # 0x55e58
movl %r12d, %esi
xorl %eax, %eax
callq 0x20f0
movq %r14, %r9
movl %r9d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq