Advertisement
Guest User

Untitled

a guest
Sep 28th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. from VMCHelp import *
  2. import numpy
  3. import random
  4. import CalcStatistics
  5.  
  6.  
  7. class H2Class:
  8. def SetParams(self,params):
  9. self.params=copy(params)
  10. self.BondLength = copy(params)
  11. def SetIons(self,ions):
  12. self.ions=ions.copy()
  13. def SetBondLength(self,BondLength):
  14. self.BondLength=BondLength
  15. TempIon=numpy.zeros((2,3),float)
  16. TempIon[0][0]=-BondLength/2.0
  17. TempIon[1][0]=BondLength/2.0
  18. self.SetIons(TempIon)
  19. def WaveFunction(self,R):
  20. alpha=self.params[0]
  21. # write code to evaluate your wavefunction here
  22. ionOne = self.ions[0]
  23. ionTwo = self.ions[1]
  24. electronOne = R[0]
  25. electronTwo = R[1]
  26. # attempt to calculate the midpoint:
  27. vecSumOne = numpy.add(ionOne, electronOne)
  28. midPOne = numpy.divide(vecSumOne,2)
  29. vecSumTwo = numpy.add(ionTwo,electronTwo)
  30. midPTwo = numpy.divide(vecSumTwo,2)
  31. ### Get the vector between the electron and the center of the bond:
  32. vecOne = numpy.subtract(electronOne,midPOne)
  33. vecTwo = numpy.subtract(electronTwo,midPTwo)
  34. #### Get the magnitudes of those vectors:
  35. elecOneAbs = numpy.dot(vecOne,vecOne)
  36. elecTwoAbs = numpy.dot(vecTwo,vecTwo)
  37. wfc = math.exp (-alpha*(elecOneAbs + elecTwoAbs))
  38. return wfc
  39.  
  40. def LocalEnergy(self,R):
  41. KE=-0.5*LaplacianPsiOverPsi(R,self.WaveFunction)
  42. #print "This is K.E.", KE
  43. V = potentialE(self.ions,R) #change this to actually calculate V
  44. #print "This is V", V
  45. return V+KE
  46.  
  47.  
  48. def VMC(WF,numSteps):
  49. seed=5 ### my random number seed
  50. EnergyList=[] #### dont know
  51. R=numpy.zeros((2,3),float) ### positions of two particles
  52. movesAttempted=0.0
  53. movesAccepted=0.0
  54. print "num-steps: ",numSteps
  55. for i in range(numSteps): ##### performing all the required number of steps #for step in xrange(0,numSteps)
  56.  
  57. OldPos= R.copy()
  58. oldWfc= WF.WaveFunction(R)
  59. for ptcl in xrange(0,len(R)): #### looping over the partices
  60. R[ptcl] = numpy.add( R[ptcl], (numpy.random.rand(3) - 0.5)*3.0 ) ## new pos?
  61. newWfc= WF.WaveFunction(R) #### finding wavefunction for the new pos
  62. # print "newWfc:" , newWfc, " oldWfc:", oldWfc
  63. ratio = (newWfc**2/oldWfc**2)
  64. # print "ratio: ", ratio
  65. rander = numpy.random.rand(1)
  66. if ratio > rander:
  67. Eloc = WF.LocalEnergy(R)
  68. EnergyList.append(Eloc)
  69. movesAttempted+=1
  70. movesAccepted+=1
  71. else:
  72. movesAttempted+=1
  73. R = OldPos # restore R to before the now rejected move
  74. print "movesAcepted: ", movesAccepted, ", movesAttempted: ", movesAttempted
  75. print "Acceptance Ratio", movesAccepted/movesAttempted
  76. return EnergyList
  77.  
  78.  
  79. def Optimize(H2):
  80. optimizeList=[]
  81. #add things here to loop over alpha and do optimization
  82. return (optimizeList,bestAlpha)
  83.  
  84.  
  85. def BondLength(H2):
  86. bondList=[]
  87. # add things here to loop over bondlengths
  88. return (bondList,bestBond)
  89.  
  90. ############added by me
  91.  
  92. def potentialE(ions, elecs):
  93. ionOne=ions[0]
  94. ionTwo=ions[1]
  95. elecOne=elecs[0]
  96. elecTwo=elecs[1]
  97. ionElec = -invDistance(ionOne,elecOne) - invDistance(ionOne,elecTwo) -invDistance(ionTwo,elecOne) - invDistance(ionTwo,elecTwo)
  98. elecElec= invDistance(elecOne,elecTwo)
  99. ionIon = invDistance(ionOne,ionTwo)
  100. v = ionElec + elecElec + ionIon
  101. return v
  102.  
  103. def invDistance(posa, posb):
  104. diff = numpy.subtract(posb,posa)
  105. dis = numpy.dot(diff,diff)
  106. inv = numpy.divide(1,dis)
  107. return dis
  108.  
  109.  
  110. class H2JastrowClass:
  111. def SetParams(self,params):
  112. self.params=copy(params)
  113. self.alpha = params[0]
  114. self.beta = params[1]
  115. self.a_ee = 0.5
  116. self.a_ep = 1.0
  117. self.b_ee = sqrt(self.a_ee/self.beta)
  118. self.b_ep = sqrt(self.a_ep/self.beta)
  119. def SetIons(self,ions):
  120. self.ions=ions.copy()
  121. def LocalEnergy(self,R):
  122. KE=-0.5*LaplacianPsiOverPsi(R,self.WaveFunction)
  123. def WaveFunction(self, R):
  124. return 0.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement