// File: /workspace/github_c_makefile_star2_O1/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)
je 0x564d
movss 0x144b2(%rip), %xmm0    # 0x19af0
ucomiss 0x38(%r15), %xmm0
jbe 0x564d
movl $0x40400000, 0x38(%r15) # imm = 0x40400000
xorps %xmm0, %xmm0
cvtss2sd 0x38(%r15), %xmm0
movsd 0x144aa(%rip), %xmm1    # 0x19b08
callq 0x2090
movsd 0x144a5(%rip), %xmm1    # 0x19b10
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x38(%r15), %xmm0
movsd 0x14492(%rip), %xmm1    # 0x19b18
callq 0x2090
movsd 0x1448d(%rip), %xmm1    # 0x19b20
divsd %xmm0, %xmm1
addsd 0x10(%rsp), %xmm1
xorps %xmm0, %xmm0
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 0x4932
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x4106
movss 0x1441b(%rip), %xmm1    # 0x19af4
subss %xmm0, %xmm1
andps 0x141ec(%rip), %xmm1    # 0x198d0
movss %xmm1, 0x2c(%r15)
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x4106
movss %xmm0, 0x30(%r15)
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x4106
movss %xmm0, 0x34(%r15)
movss 0x2c(%r15), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jb 0x578b
movss 0x143ce(%rip), %xmm2    # 0x19af8
ucomiss %xmm1, %xmm2
jbe 0x578b
xorps %xmm0, %xmm0
cvtss2sd 0x30(%r15), %xmm0
mulsd 0x14148(%rip), %xmm0    # 0x19888
divsd 0x14138(%rip), %xmm0    # 0x19880
callq 0x2100
movsd %xmm0, 0x8(%rsp)
movss 0x2c(%r15), %xmm0
addss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x1411f(%rip), %xmm0    # 0x19888
divsd 0x1410f(%rip), %xmm0    # 0x19880
callq 0x21d0
mulsd 0x143c2(%rip), %xmm0    # 0x19b40
addsd 0x143c2(%rip), %xmm0    # 0x19b48
jmp 0x5810
ucomiss 0x14366(%rip), %xmm1    # 0x19af8
jb 0x581a
movss 0x1435c(%rip), %xmm2    # 0x19afc
ucomiss %xmm1, %xmm2
jbe 0x581a
xorps %xmm0, %xmm0
cvtss2sd 0x30(%r15), %xmm0
mulsd 0x140d2(%rip), %xmm0    # 0x19888
divsd 0x140c2(%rip), %xmm0    # 0x19880
callq 0x2100
mulsd 0x1435d(%rip), %xmm0    # 0x19b28
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x2c(%r15), %xmm0
mulsd 0x140a6(%rip), %xmm0    # 0x19888
divsd 0x14096(%rip), %xmm0    # 0x19880
callq 0x2100
mulsd %xmm0, %xmm0
movsd 0x14335(%rip), %xmm2    # 0x19b30
subsd %xmm0, %xmm2
movsd 0x14331(%rip), %xmm1    # 0x19b38
movapd %xmm2, %xmm0
callq 0x2090
mulsd 0x8(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%r15)
movss 0x34(%r15), %xmm1
ucomiss 0x142cb(%rip), %xmm1    # 0x19af8
xorps %xmm0, %xmm0
jbe 0x5863
movss 0x142c6(%rip), %xmm2    # 0x19b00
ucomiss %xmm1, %xmm2
jbe 0x5863
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
mulsd 0x1403a(%rip), %xmm0    # 0x19888
divsd 0x1402a(%rip), %xmm0    # 0x19880
callq 0x2100
mulsd %xmm0, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x28(%r15)
xorps %xmm1, %xmm1
cvtss2sd 0x20(%r15), %xmm1
mulsd 0x142d6(%rip), %xmm1    # 0x19b50
xorps %xmm2, %xmm2
cvtss2sd 0x24(%r15), %xmm2
mulsd %xmm1, %xmm2
cvtss2sd %xmm0, %xmm0
mulsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x1c(%r15)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq