/src/harmonicrestraintenergy.F

http://protoms.googlecode.com/ · FORTRAN Legacy · 79 lines · 52 code · 10 blank · 17 comment · 6 complexity · d2f40fda9b5ac37517602062c148d55a MD5 · raw file

  1. double precision function harmonicRestraintEnergy(savenrg,inrgb,inrgf)
  2. include 'dimensions.inc'
  3. include 'movelist.inc'
  4. include 'printer.inc'
  5. include 'constants.inc'
  6. include 'enums.inc'
  7. include 'extraenergies.inc'
  8. c###############################################################################
  9. c
  10. c This function calculates the total harmonic restraint energy
  11. c for all of the atoms that have moved.
  12. c
  13. c (C) Christopher Woods, November 2004
  14. c
  15. c###############################################################################
  16. integer savenrg
  17. integer i
  18. double precision inrgb,inrgf
  19. double precision ic(3),icb(3),icf(3),dist,distb,distf
  20. logical hasAtomMoved
  21. harmonicRestraintEnergy = ZERO
  22. inrgb = ZERO
  23. inrgf = ZERO
  24. if (nHarmonicRestraints.le.0) return
  25. if (allmoved) then
  26. c everything has moved - evaluate all of the harmonic energies
  27. do i=1,nHarmonicRestraints
  28. c get the coordinates of the restrained atom
  29. call getCoordinates(HarmAtom(i,1),HarmAtom(i,2),HarmAtom(i,3),ic,icb,icf)
  30. c calculate the distance to the restrained point
  31. dist = (ic(1)-HarmPoint(i,1))**2 + (ic(2)-HarmPoint(i,2))**2 + (ic(3)-HarmPoint(i,3))**2
  32. distb = (icb(1)-HarmPoint(i,1))**2 + (icb(2)-HarmPoint(i,2))**2 + (icb(3)-HarmPoint(i,3))**2
  33. distf = (icf(1)-HarmPoint(i,1))**2 + (icf(2)-HarmPoint(i,2))**2 + (icf(3)-HarmPoint(i,3))**2
  34. harmonicRestraintEnergy = harmonicRestraintEnergy + HarmConst(i)*dist
  35. inrgb = inrgb + HarmConst(i)*distb
  36. inrgf = inrgf + HarmConst(i)*distf
  37. enddo
  38. else
  39. c loop through all of the restraints and see if they need updating
  40. do i=1,nHarmonicRestraints
  41. if (hasAtomMoved(HarmAtom(i,1),HarmAtom(i,2),HarmAtom(i,3))) then
  42. call getCoordinates(HarmAtom(i,1),HarmAtom(i,2),HarmAtom(i,3),ic,icb,icf)
  43. c calculate the distance to the restrained point
  44. dist = (ic(1)-HarmPoint(i,1))**2 + (ic(2)-HarmPoint(i,2))**2 + (ic(3)-HarmPoint(i,3))**2
  45. distb = (icb(1)-HarmPoint(i,1))**2 + (icb(2)-HarmPoint(i,2))**2 + (icb(3)-HarmPoint(i,3))**2
  46. distf = (icf(1)-HarmPoint(i,1))**2 + (icf(2)-HarmPoint(i,2))**2 + (icf(3)-HarmPoint(i,3))**2
  47. harmonicRestraintEnergy = harmonicRestraintEnergy + HarmConst(i)*dist
  48. inrgb = inrgb + HarmConst(i)*distb
  49. inrgf = inrgf + HarmConst(i)*distf
  50. endif
  51. enddo
  52. endif
  53. if (savenrg.eq.OLD) then
  54. oldHarmEnergyPart = harmonicRestraintEnergy
  55. oldHarmEnergyPartB = inrgb
  56. oldHarmEnergyPartF = inrgf
  57. write(printstring,*) 'old harmNrg ?',oldHarmEnergyPart,' F ',oldHarmEnergyPartF,
  58. . ' B ',oldHarmEnergyPartB
  59. call printLine(DEBUG,printstring)
  60. else if (savenrg.eq.NEW) then
  61. newHarmEnergyPart = harmonicRestraintEnergy
  62. newHarmEnergyPartB = inrgb
  63. newHarmEnergyPartF = inrgf
  64. write(printstring,*) 'new harmNrg ?',newHarmEnergyPart,' F ',newHarmEnergyPartF,
  65. . ' B ',newHarmEnergyPartB
  66. call printLine(DEBUG,printstring)
  67. endif
  68. return
  69. end