本文整理汇总了Python中Constants.boltzmann方法的典型用法代码示例。如果您正苦于以下问题:Python Constants.boltzmann方法的具体用法?Python Constants.boltzmann怎么用?Python Constants.boltzmann使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Constants
的用法示例。
在下文中一共展示了Constants.boltzmann方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: metropolis
# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import boltzmann [as 别名]
def metropolis( self, new, curr, phys ):
"""
Metropolis function which computes an acceptance probability
for sets of positions depending on energy change dE.
P = e^-dE/kt
@type new: float
@param new: Hypothetical new energy with flip.
@type curr: float
@param curr: Current energy.
@type phys: Physical
@param phys: The physical system.
@rtype: int
@return: 0 for reject, 1 for accept
"""
deltaE = new - curr
if( deltaE < 0 ):
return 1
acceptProb = exp( -deltaE / ( Constants.boltzmann() * phys.getTemperature() ) )
randNum = random()
if( randNum < acceptProb ):
print "\n**** Move accepted\n"
return 1
else:
print "\n**** Move rejected\n"
return 0
示例2: init
# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import boltzmann [as 别名]
def init(self, phys, forces, prop):
"""
Initialize propagator.
@type phys: Physical
@param phys: The physical system.
@type forces: Forces
@param forces: MDL Forces object.
@type prop: Propagator
@param prop: MDL Propagator object.
"""
self.bathPold = self.bathP #: Old thermostat value as system stores rescaled velocity number of Dof of system, momentum conserved so atoms*3D-3
self.gkT = 3.0*(phys.numAtoms()-1.0)*Constants.boltzmann()*self.temp #: Product of degrees of freedom, boltzmann constant and Kelvin temperature
self.KEtoT = 2.0 / (3.0*(phys.numAtoms()-1.0)*Constants.boltzmann()) #: Kinetic to temp. conversion
prop.calculateForces(forces)
self.Potnl = forces.energies.potentialEnergy(phys) #: Potential energy
self.h0 = self.Potnl + forces.energies.kineticEnergy(phys) #: Initial 'internal' Hamiltonian value so that total Hamiltonian allways 0
self.stepsdone = 0 #: Number of steps completed
self.avTemp = 0 #: Average Kelvin temperature
self.tempers = [] #: Holds pairs of step numbers and average temperatures
self.Hamiltonian = [] #: Holds pairs of step numbers and total energies
示例3: run
# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import boltzmann [as 别名]
def run(self, phys, forces, prop):
"""
Execute the propagator.
@type phys: Physical
@param phys: The physical system.
@type forces: Forces
@param forces: MDL Forces object
@type prop: Propagator
@param prop: MDL Propagator object
"""
forceconstant = 2*Constants.boltzmann()*self.temp*self.gamma/self.dt # assign random force
forces.force += forces.randomForce(phys,self.seed)*numpy.sqrt(forceconstant*phys.masses)
phys.velocities *= (1.0-0.5*self.dt*self.gamma) # first half kick
phys.velocities += forces.force*0.5*self.dt*phys.invmasses
phys.positions += phys.velocities*self.dt # drift
prop.calculateForces(forces)
forceconstant = 2*Constants.boltzmann()*self.temp*self.gamma/self.dt # assign random force
forces.force += forces.randomForce(phys,self.seed)*numpy.sqrt(forceconstant*phys.masses)
phys.velocities += forces.force*0.5*self.dt*phys.invmasses # second first kick
phys.velocities *= (1.0/(1.0+0.5*self.dt*self.gamma))
示例4: init
# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import boltzmann [as 别名]
def init(self, phys, forces, prop):
"""
Initialize propagator.
@type phys: Physical
@param phys: The physical system.
@type forces: Forces
@param forces: MDL Forces object.
@type prop: Propagator
@param prop: MDL Propagator object.
"""
prop.calculateForces(forces)
self.Potnl = forces.energies.potentialEnergy(phys) #: Potential energy
self.gkT = 3.0*(phys.numAtoms()-1.0)*Constants.boltzmann()*self.temp #: Number of Dof*kT, momentum conserved so number of atoms * 3D - 3
self.KEtoT = 2.0 / (3.0*(phys.numAtoms()-1.0)*Constants.boltzmann()) #: Convertion of kinetic energy to temperature
self.Nf = 3.0*(phys.numAtoms()-1.0) #: number of Dof
self.kT = Constants.boltzmann()*self.temp #: Boltzmann constant times Kelvin temperature
self.h0 = self.totalEnergy(0,phys,forces) #: Initial total energy
self.stepsdone = 0 #: Number of steps completed
self.avTemp = 0 #: Average Kelvin temperature
self.tempers = [] #: Holds pairs of step numbers and average temperatures
self.Hamiltonian = [] #: Holds pairs of step numbers and total energies
示例5: metropolis
# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import boltzmann [as 别名]
def metropolis( u_i, u_j, t_i, t_j ):
# Metropolis for replicas i with potential energy u_i
# temperature t_i
# and j with potential energy u_j
# temperature t_j
K_b = Constants.boltzmann()
deltaE = (1 / (K_b * t_i) - 1/ (K_b * t_j) ) - (u_j - u_i)
if( deltaE < 0 ):
return True
acceptProb = np.exp( -deltaE )
randNum = nr.random()
if( randNum < acceptProb ):
return True
else:
return False
示例6: friction
# 需要导入模块: import Constants [as 别名]
# 或者: from Constants import boltzmann [as 别名]
def friction(phys, forces, prop, obj):
"""
Modify the force vector to include a frictional force.
This can be used for incorporation of Langevin dynamics.
@type phys: Physical
@param phys: The physical system.
@type forces: Forces
@param forces: MDL Forces object
@type prop: Propagator
@param prop: MDL Propagator object
@type obj: STS/MTS
@param obj: Prototyped propagator object
"""
targetKE = 3.0/2.0*phys.numAtoms()*Constants.boltzmann()*obj.temp
obj.thermal = 0
obj.bathpos = (forces.energies.kineticEnergy(phys) - targetKE)*obj.thermal/(obj.dt*phys.numAtoms())
forces.force -= phys.velocities*obj.bathpos*phys.masses