// File: /workspace/github_c_makefile_star2_O2/josch[P]stride/hbenergy.c
// Function: GRID_Energy
void GRID_Energy(float *CA2, float *C, float *O, float *H, float *N, COMMAND *Cmd, HBOND *HBond)
{

  float ProjH[3];

 /***** Distance dependence ( 8-6 potential ) ****/

  if( Cmd->Truncate && HBond->AccDonDist < RmGRID ) 
    HBond->AccDonDist = RmGRID;
  HBond->Er = CGRID/pow(HBond->AccDonDist,8.0) - DGRID/pow(HBond->AccDonDist,6.0);

 /************** Angular dependance ****************/

 /* Find projection of the hydrogen on the O-C-CA plane */
  Project4_123(O,C,CA2,H,ProjH); 


 /* Three angles determining the direction of the hydrogen bond */
  HBond->ti = fabs(180.0 - Ang(ProjH,O,C)); 
  HBond->to = Ang(H,O,ProjH);             
  HBond->p  = Ang(N,H,O);

 /* Calculate both angle-dependent HB energy components Et and Ep */ 
  if( HBond->ti >= 0.0 && HBond->ti < 90.0 )   
    HBond->Et = cos(RAD(HBond->to))*(0.9+0.1*sin(RAD(2*HBond->ti)));
  else
  if( HBond->ti >= 90.0 && HBond->ti < 110.0 ) 
    HBond->Et = K1GRID*cos(RAD(HBond->to))*
      (pow((K2GRID-pow(cos(RAD(HBond->ti)),2.0)),3.0));
  else
    HBond->Et = 0.0;

  if( HBond->p > 90.0 && HBond->p < 270.0 )
    HBond->Ep = pow(cos(RAD(HBond->p)),2.0);
  else
    HBond->Ep = 0.0;

    /******** Full hydrogen bond energy *********************/
  HBond->Energy = 1000.0*HBond->Er*HBond->Et*HBond->Ep;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x8(%rsp)
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r13
movq 0x60(%rsp), %r15
cmpl $0x0, 0x1d64(%r9)
movss 0x38(%r15), %xmm0
je 0x4e08
movss 0x13d08(%rip), %xmm1    # 0x18b00
ucomiss %xmm0, %xmm1
jbe 0x4e08
movl $0x40400000, 0x38(%r15) # imm = 0x40400000
movaps %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x13d04(%rip), %xmm1    # 0x18b18
callq 0x2090
movsd 0x13cff(%rip), %xmm1    # 0x18b20
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
cvtss2sd 0x38(%r15), %xmm0
movsd 0x13cef(%rip), %xmm1    # 0x18b28
callq 0x2090
movsd 0x13cea(%rip), %xmm1    # 0x18b30
divsd %xmm0, %xmm1
addsd 0x10(%rsp), %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x20(%r15)
leaq 0x1c(%rsp), %rbp
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rbp, %r8
callq 0x41b4
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x3aef
movss 0x13c7b(%rip), %xmm1    # 0x18b04
subss %xmm0, %xmm1
andps 0x13a4c(%rip), %xmm1    # 0x188e0
movss %xmm1, 0x2c(%r15)
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x3aef
movss %xmm0, 0x30(%r15)
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x3aef
movss %xmm0, 0x34(%r15)
movss 0x2c(%r15), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jb 0x4f35
movss 0x13c2e(%rip), %xmm2    # 0x18b08
ucomiss %xmm1, %xmm2
jbe 0x4f35
cvtss2sd 0x30(%r15), %xmm0
mulsd 0x1399b(%rip), %xmm0    # 0x18888
divsd 0x1398b(%rip), %xmm0    # 0x18880
callq 0x2100
movsd %xmm0, 0x8(%rsp)
movss 0x2c(%r15), %xmm0
addss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x13972(%rip), %xmm0    # 0x18888
divsd 0x13962(%rip), %xmm0    # 0x18880
callq 0x21e0
mulsd 0x13c25(%rip), %xmm0    # 0x18b50
addsd 0x13c25(%rip), %xmm0    # 0x18b58
jmp 0x4fb0
ucomiss 0x13bcc(%rip), %xmm1    # 0x18b08
jb 0x4fba
movss 0x13bc6(%rip), %xmm2    # 0x18b0c
ucomiss %xmm1, %xmm2
jbe 0x4fba
cvtss2sd 0x30(%r15), %xmm0
mulsd 0x1392f(%rip), %xmm0    # 0x18888
divsd 0x1391f(%rip), %xmm0    # 0x18880
callq 0x2100
mulsd 0x13bca(%rip), %xmm0    # 0x18b38
movsd %xmm0, 0x8(%rsp)
cvtss2sd 0x2c(%r15), %xmm0
mulsd 0x13906(%rip), %xmm0    # 0x18888
divsd 0x138f6(%rip), %xmm0    # 0x18880
callq 0x2100
mulsd %xmm0, %xmm0
movsd 0x13ba5(%rip), %xmm2    # 0x18b40
subsd %xmm0, %xmm2
movsd 0x13ba1(%rip), %xmm1    # 0x18b48
movapd %xmm2, %xmm0
callq 0x2090
mulsd 0x8(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%r15)
movss 0x34(%r15), %xmm2
ucomiss 0x13b3b(%rip), %xmm2    # 0x18b08
xorps %xmm1, %xmm1
jbe 0x5006
movss 0x13b36(%rip), %xmm3    # 0x18b10
ucomiss %xmm2, %xmm3
jbe 0x5006
cvtss2sd %xmm2, %xmm0
mulsd 0x1389d(%rip), %xmm0    # 0x18888
divsd 0x1388d(%rip), %xmm0    # 0x18880
callq 0x2100
mulsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm1
movss 0x24(%r15), %xmm0
movss %xmm1, 0x28(%r15)
cvtss2sd 0x20(%r15), %xmm2
mulsd 0x13b46(%rip), %xmm2    # 0x18b60
cvtss2sd %xmm0, %xmm0
mulsd %xmm2, %xmm0
cvtss2sd %xmm1, %xmm1
mulsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x1c(%r15)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq