import numpy as np from ase.ga.population import RankFitnessPopulation from ase.ga.data import DataConnection from ase.ga.offspring_creator import OperationSelector from ase.ga.slab_operators import (CutSpliceSlabCrossover, RandomSlabPermutation, RandomCompositionMutation) from ase.ga import set_raw_score from ase.calculators.emt import EMT # Connect to the database containing all candidates db = DataConnection('hull.db') # Retrieve saved parameters pop_size = db.get_param('population_size') refs = db.get_param('reference_energies') metals = db.get_param('metals') lattice_constants = db.get_param('lattice_constants') def get_mixing_energy(atoms): # Set the correct cell size from the lattice constant new_a = get_avg_lattice_constant(atoms.get_chemical_symbols()) # Use the orthogonal fcc cell to find the current lattice constant current_a = atoms.cell[0][0] / np.sqrt(2) atoms.set_cell(atoms.cell * new_a / current_a, scale_atoms=True) # Calculate the energy atoms.set_calculator(EMT()) e = atoms.get_potential_energy()
from ase.ga.element_mutations import RandomElementMutation from ase.ga.element_crossovers import OnePointElementCrossover from ase.ga.offspring_creator import OperationSelector from ase.ga.population import Population from ase.ga.convergence import GenerationRepetitionConvergence from ga_fcc_alloys_relax import relax # Specify the number of generations this script will run num_gens = 40 db = DataConnection('fcc_alloys.db') ref_db = 'refs.db' # Retrieve saved parameters population_size = db.get_param('population_size') metals = db.get_param('metals') # Specify the procreation operators for the algorithm # Try and play with the mutation operators that move to nearby # places in the periodic table oclist = ([1, 1], [RandomElementMutation(metals), OnePointElementCrossover(metals)]) operation_selector = OperationSelector(*oclist) # Pass parameters to the population instance pop = Population(data_connection=db, population_size=population_size) # We form generations in this algorithm run and can therefore set # a convergence criteria based on generations