// File: /workspace/github_c_makefile_star2_O3/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 0x5570
movss 0x145a0(%rip), %xmm1    # 0x19b00
ucomiss %xmm0, %xmm1
jbe 0x5570
movl $0x40400000, 0x38(%r15) # imm = 0x40400000
movaps %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x1459c(%rip), %xmm1    # 0x19b18
callq 0x2090
movsd 0x14597(%rip), %xmm1    # 0x19b20
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x38(%r15), %xmm0
movsd 0x14584(%rip), %xmm1    # 0x19b28
callq 0x2090
movsd 0x1457f(%rip), %xmm1    # 0x19b30
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 0x4888
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x40f4
movss 0x1450d(%rip), %xmm1    # 0x19b04
subss %xmm0, %xmm1
andps 0x142de(%rip), %xmm1    # 0x198e0
movss %xmm1, 0x2c(%r15)
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x40f4
movss %xmm0, 0x30(%r15)
movq 0x8(%rsp), %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x40f4
movss %xmm0, 0x34(%r15)
movss 0x2c(%r15), %xmm1
xorps %xmm0, %xmm0
ucomiss %xmm0, %xmm1
jb 0x56a9
movss 0x144c0(%rip), %xmm2    # 0x19b08
ucomiss %xmm1, %xmm2
jbe 0x56a9
xorps %xmm0, %xmm0
cvtss2sd 0x30(%r15), %xmm0
mulsd 0x1422a(%rip), %xmm0    # 0x19888
divsd 0x1421a(%rip), %xmm0    # 0x19880
callq 0x2100
movsd %xmm0, 0x8(%rsp)
movss 0x2c(%r15), %xmm0
addss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
mulsd 0x14201(%rip), %xmm0    # 0x19888
divsd 0x141f1(%rip), %xmm0    # 0x19880
callq 0x21d0
mulsd 0x144b4(%rip), %xmm0    # 0x19b50
addsd 0x144b4(%rip), %xmm0    # 0x19b58
jmp 0x572e
ucomiss 0x14458(%rip), %xmm1    # 0x19b08
jb 0x5738
movss 0x1444e(%rip), %xmm2    # 0x19b0c
ucomiss %xmm1, %xmm2
jbe 0x5738
xorps %xmm0, %xmm0
cvtss2sd 0x30(%r15), %xmm0
mulsd 0x141b4(%rip), %xmm0    # 0x19888
divsd 0x141a4(%rip), %xmm0    # 0x19880
callq 0x2100
mulsd 0x1444f(%rip), %xmm0    # 0x19b38
movsd %xmm0, 0x8(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x2c(%r15), %xmm0
mulsd 0x14188(%rip), %xmm0    # 0x19888
divsd 0x14178(%rip), %xmm0    # 0x19880
callq 0x2100
mulsd %xmm0, %xmm0
movsd 0x14427(%rip), %xmm2    # 0x19b40
subsd %xmm0, %xmm2
movsd 0x14423(%rip), %xmm1    # 0x19b48
movapd %xmm2, %xmm0
callq 0x2090
mulsd 0x8(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%r15)
movss 0x34(%r15), %xmm2
ucomiss 0x143bd(%rip), %xmm2    # 0x19b08
xorps %xmm1, %xmm1
jbe 0x578a
movss 0x143b8(%rip), %xmm3    # 0x19b10
ucomiss %xmm2, %xmm3
jbe 0x578a
xorps %xmm0, %xmm0
cvtss2sd %xmm2, %xmm0
mulsd 0x1411c(%rip), %xmm0    # 0x19888
divsd 0x1410c(%rip), %xmm0    # 0x19880
callq 0x2100
mulsd %xmm0, %xmm0
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
movss 0x24(%r15), %xmm0
movss %xmm1, 0x28(%r15)
xorps %xmm2, %xmm2
cvtss2sd 0x20(%r15), %xmm2
mulsd 0x143bf(%rip), %xmm2    # 0x19b60
cvtss2sd %xmm0, %xmm0
mulsd %xmm2, %xmm0
cvtss2sd %xmm1, %xmm1
mulsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x1c(%r15)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq