Ejemplo n.º 1
0
  def solve(self):
    #Create the initial particle from the defining string/number atoms
    self.particle = genParticle(self.definingString,int(self.numberOfAtoms))

    # self.definingString looks like: "Pt50Au30"
    #print "my defining string is " + self.definingString

    # self.numberOfAtoms looks like: "80" (you'll need to call int(self.numberOfAtoms))
    #print "my number of atoms is " + self.numberOfAtoms

    #do all of your solving stuff you want...

    #FINAL_SOLUTION = IMPLEMENT_FINAL_SOLUTION()

    a = {"symbol": "Pt", "x": 1, "y": 2, "z": 3}
    b = {"symbol": "Au", "x": 2, "y": 1, "z": -2}
    c = {"symbol": "Pt", "x": 1, "y": 1, "z": -2}
    listOfAtoms = [a, b, c]
    potentialEnergy = -325.43
    dictionary_to_be_turned_into_json = {"atoms": listOfAtoms, "potentialEnergy": potentialEnergy}
    actually_json = json.dumps(dictionary_to_be_turned_into_json)

    # this gets returned to the parent class and shoved into the database as a string, then
    # parsed as JSON on the page and displayed/drawn for the user
    return actually_json
    def solve(self):
    #Create the initial particle from the defining string/number atoms

        temp = 1750
        mintemp = 150
        self.particle = genParticle(self.definingString,int(self.numberOfAtoms))
        if (len(self.particle) < 16):
          temp = 1250
        maxtemp = temp
        berendsen = Langevin(self.particle, 2.5 * units.fs, units.kB * temp, 0.02)
        # the 5.0 * units.fs is used instead of 0.1 * units.fs b/c it makes the program run faster
        MaxwellBoltzmannDistribution(self.particle,units.kB * temp)
        self.bestEnergy = self.particle.get_potential_energy()
        self.bestParticle = deepcopy(self.particle)
        self.reCenter()
        self.getAnswer()

        while (temp > mintemp):
            berendsen = Langevin(self.particle, 2.5 * units.fs, units.kB * temp, 0.02)
            berendsen.run(100)
            testEnergy = self.particle.get_potential_energy()
            self.bestEnergy = self.particle.get_potential_energy()
            self.bestParticle = deepcopy(self.particle)
            self.reCenter()
            self.getAnswer()
            temp -= 10
            if (temp % 50 == 0):
              self.bestEnergy = self.particle.get_potential_energy()
              self.bestParticle = deepcopy(self.particle)
              self.reCenter()
              self.checkTimeout()
              self.setSolution(self.getAnswer())
              pDone=float(maxtemp - temp)/(maxtemp-mintemp)
              self.setStatusDone(str(math.floor(pDone*100))+"% | "+self.remainingTime(pDone))
            elif (temp <= mintemp):
              dyn = FIRE(atoms=self.particle)
              dyn.run(fmax=0.01)
              self.bestEnergy = self.particle.get_potential_energy()
              self.bestParticle = deepcopy(self.particle)
              self.reCenter()
              self.setSolution(self.getAnswer())
              pDone=float(temp)/(maxtemp-mintemp)
              self.setStatusDone(str(math.floor(pDone*100))+"% | "+self.remainingTime(pDone))

        return self.getAnswer()
Ejemplo n.º 3
0
 def solve(self):
   #Create the initial particle from the defining string/number atoms
   self.particle = genParticle(self.definingString,int(self.numberOfAtoms)); #Generates the base particle
   self.bestParticles = []; #Initializes the list of bestParticles
   self.bestEnergy = self.particle.get_potential_energy(); #Initializes best energy
   self.bestParticle = deepcopy(self.particle); #Best particle is a copy of particle
   heapq.heappush(self.bestParticles, (self.particle.get_potential_energy(), self.particle)); #Pushes particle to bestParticles
   self.startTime = self.millis()
   for i in range(100): #Mutates particle 100 times and pushes results into a heap
       if i%5==0:
           pDone=float(i)/100
           self.setStatusDone(str(math.floor(pDone*100))+"% | Stage 1 | "+self.remainingTime(pDone))
           self.checkTimeout()
       self.bestParticle = self.mutate(self.particle);
       heapq.heappush(self.bestParticles, (self.bestParticle.get_potential_energy(), self.bestParticle));
   self.currentEnergy = 0;
   self.currentParticle = None;
   self.startTime = self.millis()
   CALCULATIONS=2;
   self.setStatusDone("100% | Stage 1 | Starting stage 2")
   for i in range(CALCULATIONS):
       if i%1==0 and i>0:
           pDone=float(i)/CALCULATIONS
           self.setStatusDone(str(math.floor(pDone*100))+"% | Stage 2  | "+self.remainingTime(pDone))
           self.checkTimeout()
           self.setSolution(self.getAnswer())
       self.currentEnergy = 1000000;
       self.newBestParticles = [];
       for l in range(5):
           self.newBestParticles.append(heapq.heappop(self.bestParticles));
       self.bestParticles = deepcopy(self.newBestParticles);
       self.children = self.breed(self.bestParticles);
       for j in range(len(self.bestParticles)):
           newparticle = self.mutate((self.bestParticles[j])[1]);
           self.bestParticles[j] = (newparticle.get_potential_energy(), newparticle);
           if((self.bestParticles[j])[0] < self.currentEnergy):
               self.currentParticle = (self.bestParticles[j])[1];
               self.currentEnergy = (self.bestParticles[j])[0];
       for index in range(len(self.children)):
           newparticle = (self.children[index]);
           heapq.heappush(self.bestParticles, (newparticle.get_potential_energy(), newparticle));
       self.veryBestParticle = heapq.heappop(self.bestParticles);
   return self.getAnswer();