示例#1
0
  public Organism doVariation(Generation parents, Generation offspring, Selection sel) {
    GAParameters params = GAParameters.getParams();
    Random rand = params.getRandom();

    // pick a parent randomly
    StructureOrg p = (StructureOrg) (sel.doSelection(parents, 1)[0]);
    Cell pStruct = p.getCell();

    // copy the parent's data into new structures
    List<Site> pSites = pStruct.getSites();
    List<Site> newSites = new LinkedList<Site>();

    // perturbing the lattice parameters
    double[][] strain = new double[3][3];
    // initialize the strain matrix to the identity
    // then add some zero mean Gaussian random variables
    for (int i = 0; i < strain.length; i++)
      for (int j = 0; j < strain.length; j++) {
        strain[i][j] = rand.nextGaussian() * sigmaLattice;
        // allow strain matrix perturbations to be only between -1 and 1
        if (strain[i][j] > 1) strain[i][j] = 1;
        if (strain[i][j] < -1) strain[i][j] = -1;
        // add the identity
        if (i == j) strain[i][j] += 1;
      }

    // modify the basis to make newBasis
    double[][] newVectsD = new double[Constants.numDimensions][Constants.numDimensions];
    for (int i = 0; i < Constants.numDimensions; i++)
      for (int j = 0; j < Constants.numDimensions; j++)
        newVectsD[i][j] = pStruct.getLatticeVectors().get(i).getCartesianComponents().get(j);
    // newVects = MatrixMath.SquareMatrixMult(strain, newVects);
    newVectsD = (new Matrix(strain)).times(new Matrix(newVectsD)).getArray();

    List<Vect> newVects = new LinkedList<Vect>();
    for (int i = 0; i < Constants.numDimensions; i++) newVects.add(new Vect(newVectsD[i]));

    // perturb atomic positions
    for (int i = 0; i < pSites.size(); i++) {
      // perturb each site's location with probability mutRate
      List<Double> fracCoords =
          pSites.get(i).getCoords().getComponentsWRTBasis(pStruct.getLatticeVectors());
      if (rand.nextDouble() < mutRate) {
        // perturb by a Gaussian of stddev mutRadius along each axis
        for (int k = 0; k < Constants.numDimensions; k++)
          fracCoords.set(
              k, GAUtils.renormZeroOne(fracCoords.get(k) + rand.nextGaussian() * sigmaAtoms));
      }
      newSites.add(new Site(pSites.get(i).getElement(), new Vect(fracCoords, newVects)));
    }

    // make the new offspring
    StructureOrg result = new StructureOrg(new Cell(newVects, newSites));

    GAOut.out().stdout("StructureMut created new StructureOrg:", GAOut.DEBUG, result.getID());
    GAOut.out().stdout(result.toString(), GAOut.DEBUG, result.getID());

    return result;
  }
示例#2
0
 public String getLabel() {
   return cell.getLabel();
 }
示例#3
0
 public Composition getComposition() {
   return cell.getComposition();
 }
示例#4
0
 public double getEnergyPerAtom() {
   return getTotalEnergy() / cell.getNumSites();
 }