def step_multi(self, step_num, SHOW_MODE=0): step_to_go = step_num hundredth = step_num / 100 if step_num <= 0: print "step number should be positve integer" else: while step_to_go > 0: # pick a molecule and its new random position and angle ind, x, y, theta = self.get_new_conf() # get its old position and angle x_old, y_old, theta_old, typ_old = self.mol.conf[ind, :] # compute the energy of the old and new configuration, # respectively state_old, energy_old = inter_energy_multi( ind, x_old, y_old, theta_old, typ_old, self.mol, self.e_tables) state_new, energy_new = inter_energy_multi( -1, x, y, theta, typ_old, self.mol, self.e_tables) if state_new: p = min(math.exp(-(energy_new - energy_old)), 1) if p > rd.random(): # TODO: finish the metropolis part self.mol.update(ind, x, y, theta) step_to_go = step_to_go - 1 if step_to_go % hundredth == 0: if step_to_go != step_num: print "%d / %d done" % (100 - step_to_go / hundredth, 100)
def step_multi(self, step_num, SHOW_MODE=0): step_to_go = step_num hundredth = step_num/100 if step_num <= 0: print "step number should be positve integer" else: while step_to_go > 0: # pick a molecule and its new random position and angle ind,x,y,theta = self.get_new_conf() # get its old position and angle x_old,y_old,theta_old,typ_old = self.mol.conf[ind,:] # compute the energy of the old and new configuration, # respectively state_old, energy_old = inter_energy_multi(ind,x_old,y_old,theta_old,typ_old,self.mol,self.e_tables) state_new, energy_new = inter_energy_multi(-1,x,y,theta,typ_old,self.mol,self.e_tables) if state_new: p = min(math.exp(-(energy_new-energy_old)),1) if p > rd.random(): # TODO: finish the metropolis part self.mol.update(ind,x,y,theta) step_to_go = step_to_go - 1 if step_to_go%hundredth == 0: if step_to_go != step_num: print "%d / %d done" % (100-step_to_go/hundredth,100)
def init_multi(self,setting = None): if setting: self.element_settings = setting self.element_type_num = len(setting) while self.mol.num_init < self.mol.num: for typ,num in enumerate(self.element_settings): print "type # %d has %d element" % (typ, num) i = 0 while i < num: ind,x,y,theta = self.get_new_conf() state, energy = inter_energy_multi(self.mol.num_init,x,y,theta,typ+1,self.mol,self.e_tables) if state: self.mol.update(self.mol.num_init,x,y,0,typ+1) self.mol.num_init = self.mol.num_init + 1 i = i + 1 #print x,y,theta,self.mol.conf #print state, energy #self.show() else: continue
def init_multi(self, setting=None): if setting: self.element_settings = setting self.element_type_num = len(setting) while self.mol.num_init < self.mol.num: for typ, num in enumerate(self.element_settings): print "type # %d has %d element" % (typ, num) i = 0 while i < num: ind, x, y, theta = self.get_new_conf() state, energy = inter_energy_multi(self.mol.num_init, x, y, theta, typ + 1, self.mol, self.e_tables) if state: self.mol.update(self.mol.num_init, x, y, 0, typ + 1) self.mol.num_init = self.mol.num_init + 1 i = i + 1 #print x,y,theta,self.mol.conf #print state, energy #self.show() else: continue