def solve(self): #Create the initial particle from the defining string/number atoms self.particle = NanoClass.genParticle(self.definingString, int(self.numberOfAtoms)) self.reCenter() self.bestEnergy = self.particle.get_potential_energy() self.bestParticle = deepcopy(self.particle) # berendsen = NVTBerendsen(self.particle, 2.5 * units.fs, 2000, taut=0.5*100*units.fs) berendsen = Langevin(self.particle, 5 * units.fs, units.kB * 2000, 0.005) dyn = FIRE(atoms=self.particle) MaxwellBoltzmannDistribution(self.particle,2000*units.kB) CALCULATIONS=100 for i in range(CALCULATIONS): if i%1==0: pDone=float(i)/CALCULATIONS self.setStatusDone(str(math.floor(pDone*100))+"% | "+self.remainingTime(pDone)) self.checkTimeout() self.setSolution(self.getAnswer()) MaxwellBoltzmannDistribution(self.particle,2000*units.kB) self.particle.get_potential_energy() berendsen.run(500) dyn.run() self.reCenter() testEnergy = self.particle.get_potential_energy() if (testEnergy < self.bestEnergy): self.bestEnergy = testEnergy self.bestParticle = deepcopy(self.particle) elif ((testEnergy + .5) > self.bestEnergy): self.particle = NanoClass.genParticle(self.definingString, int(self.numberOfAtoms)) MaxwellBoltzmannDistribution(self.particle,2000*units.kB) self.particle.get_potential_energy() if (testEnergy < self.bestEnergy): self.bestEnergy = testEnergy self.bestParticle = deepcopy(self.particle) return self.getAnswer()
def solve(self): self.setStatusDone("Initializing configuration...") self.particle = NanoClass.genParticle(self.definingString, int(self.numberOfAtoms)) self.reCenter() self.bestEnergy = self.particle.get_potential_energy() self.bestParticle = self.particle.copy() berendsen = Langevin(self.particle, 5*units.fs, units.kB*2000,0.005) dyn = FIRE(atoms=self.particle) dyn.run(500) MaxwellBoltzmannDistribution(self.particle,2000*units.kB) MAXIMUM_ITERATIONS = 20 ITERATION = 0 BEST_POTENTIAL_ENERGY = 999999 BEST_PARTICLE = None queue = [( self.particle.get_potential_energy(), self.particle)] pDone=float(ITERATION)/MAXIMUM_ITERATIONS self.setStatusDone(str(math.floor(pDone*100))+"% | "+self.remainingTime(pDone)) self.checkTimeout() current_particle = self.bestParticle.copy() calc = EMT() current_particle.set_calculator(calc) self.setSolution(self.getAnswer(current_particle, current_particle.get_potential_energy())) while ITERATION < MAXIMUM_ITERATIONS: new_parent = heappop(queue)[1].copy() calc = EMT() new_parent.set_calculator(calc) #print new_parent.get_positions() #print new_parent.get_potential_energy() for x in range(5): new_child = self.create_child_from(new_parent) potential_energy = copy.deepcopy(new_child.get_potential_energy()) heappush(queue, (potential_energy, new_child)) if potential_energy < BEST_POTENTIAL_ENERGY: #print "--------------- NEW BEST FOUND ---------------" #print "POTENTIAL ENERGY = ", potential_energy BEST_POTENTIAL_ENERGY = potential_energy self.bestParticle = new_child #print new_child.positions pDone=float(ITERATION)/MAXIMUM_ITERATIONS self.setStatusDone(str(math.floor(pDone*100))+"% | "+self.remainingTime(pDone)) self.checkTimeout() self.setSolution(self.getAnswer(self.bestParticle, BEST_POTENTIAL_ENERGY)) ITERATION += 1 return self.getAnswer(self.bestParticle, BEST_POTENTIAL_ENERGY)