def __init__(self, slab, n_top, blmin, number_of_variable_cell_vectors=0, p1=1, p2=0.05, minfrac=None, cellbounds=None, test_dist_to_slab=True, use_tags=False, rng=np.random, verbose=False): OffspringCreator.__init__(self, verbose, rng=rng) self.slab = slab self.n_top = n_top self.blmin = blmin assert number_of_variable_cell_vectors in range(4) self.number_of_variable_cell_vectors = number_of_variable_cell_vectors self.p1 = p1 self.p2 = p2 self.minfrac = minfrac self.cellbounds = cellbounds self.test_dist_to_slab = test_dist_to_slab self.use_tags = use_tags self.scaling_volume = None self.descriptor = 'CutAndSplicePairing' self.min_inputs = 2
def __init__(self, element_pool, verbose=False, num_muts=1): OffspringCreator.__init__(self, verbose, num_muts=num_muts) self.descriptor = 'FullElementMutation' if not isinstance(element_pool[0], (list, np.ndarray)): self.element_pools = [element_pool] else: self.element_pools = element_pool
def __init__(self, slab, n_top, blmin, verbose=False): OffspringCreator.__init__(self, verbose) self.blmin = blmin self.slab = slab self.n_top = n_top self.descriptor = 'CutAndSplicePairing' self.min_inputs = 2
def __init__(self, blmin, n_top, reflect=False, verbose=False): OffspringCreator.__init__(self, verbose) self.blmin = blmin self.n_top = n_top self.reflect = reflect self.descriptor = 'MirrorMutation' self.min_inputs = 1
def __init__(self, element_pool, max_diff_elements, min_percentage_elements, verbose): OffspringCreator.__init__(self, verbose) if not isinstance(element_pool[0], (list, np.ndarray)): self.element_pools = [element_pool] else: self.element_pools = element_pool if max_diff_elements is None: self.max_diff_elements = [None for _ in self.element_pools] elif isinstance(max_diff_elements, int): self.max_diff_elements = [max_diff_elements] else: self.max_diff_elements = max_diff_elements assert len(self.max_diff_elements) == len(self.element_pools) if min_percentage_elements is None: self.min_percentage_elements = [0 for _ in self.element_pools] elif isinstance(min_percentage_elements, (int, float)): self.min_percentage_elements = [min_percentage_elements] else: self.min_percentage_elements = min_percentage_elements assert len(self.min_percentage_elements) == len(self.element_pools) self.min_inputs = 2
def __init__(self, element_pool, max_diff_elements, min_percentage_elements, verbose, rng=np.random): OffspringCreator.__init__(self, verbose, rng=rng) if not isinstance(element_pool[0], (list, np.ndarray)): self.element_pools = [element_pool] else: self.element_pools = element_pool if max_diff_elements is None: self.max_diff_elements = [None for _ in self.element_pools] elif isinstance(max_diff_elements, int): self.max_diff_elements = [max_diff_elements] else: self.max_diff_elements = max_diff_elements assert len(self.max_diff_elements) == len(self.element_pools) if min_percentage_elements is None: self.min_percentage_elements = [0 for _ in self.element_pools] elif isinstance(min_percentage_elements, (int, float)): self.min_percentage_elements = [min_percentage_elements] else: self.min_percentage_elements = min_percentage_elements assert len(self.min_percentage_elements) == len(self.element_pools) self.min_inputs = 2
def test_add_candidates(): import pytest from ase.build import fcc111 from ase.ga.data import PrepareDB from ase.ga.data import DataConnection from ase.ga.offspring_creator import OffspringCreator from ase.ga import set_raw_score import os db_file = 'gadb.db' if os.path.isfile(db_file): os.remove(db_file) db = PrepareDB(db_file) slab1 = fcc111('Ag', size=(2, 2, 2)) db.add_unrelaxed_candidate(slab1) slab2 = fcc111('Cu', size=(2, 2, 2)) set_raw_score(slab2, 4) db.add_relaxed_candidate(slab2) assert slab2.info['confid'] == 3 db = DataConnection(db_file) assert db.get_number_of_unrelaxed_candidates() == 1 slab3 = db.get_an_unrelaxed_candidate() old_confid = slab3.info['confid'] slab3[0].symbol = 'Au' db.add_unrelaxed_candidate(slab3, 'mutated: Parent {0}'.format(old_confid)) new_confid = slab3.info['confid'] # confid should update when using add_unrelaxed_candidate assert old_confid != new_confid slab3[1].symbol = 'Au' db.add_unrelaxed_step(slab3, 'mutated: Parent {0}'.format(new_confid)) # confid should not change when using add_unrelaxed_step assert slab3.info['confid'] == new_confid with pytest.raises(AssertionError): db.add_relaxed_step(slab3) set_raw_score(slab3, 3) db.add_relaxed_step(slab3) slab4 = OffspringCreator.initialize_individual(slab1, fcc111('Au', size=(2, 2, 2))) set_raw_score(slab4, 67) db.add_relaxed_candidate(slab4) assert slab4.info['confid'] == 7 more_slabs = [] for m in ['Ni', 'Pd', 'Pt']: slab = fcc111(m, size=(2, 2, 2)) slab = OffspringCreator.initialize_individual(slab1, slab) set_raw_score(slab, sum(slab.get_masses())) more_slabs.append(slab) db.add_more_relaxed_candidates(more_slabs) assert more_slabs[1].info['confid'] == 9 os.remove(db_file)
def __init__(self, adsorbate, adsorption_sites=None, num_muts=1): OffspringCreator.__init__(self, num_muts=num_muts) self.adsorbate = self.convert_adsorbate(adsorbate) self.adsorbate_set = set(self.adsorbate.get_chemical_symbols()) if adsorption_sites is None: raise NotImplementedError self.adsorption_sites = adsorption_sites self.descriptor = 'AdsorbateOperator'
def __init__(self, blmin, n_top, rattle_strength=0.8, rattle_prop=0.4, verbose=False): OffspringCreator.__init__(self, verbose) self.blmin = blmin self.n_top = n_top self.rattle_strength = rattle_strength self.rattle_prop = rattle_prop self.descriptor = 'RattleMutation'
def __init__(self, blmin, n_top, rattle_prop=0.4, verbose=False, descriptor='RattleMutation_new'): OffspringCreator.__init__(self, verbose) self.blmin = blmin self.n_top = n_top self.rattle_prop = rattle_prop self.descriptor = descriptor self.min_inputs = 1
def __init__(self, blmin, n_top, probability=0.33, verbose=False, descriptor='PermutationMutation'): OffspringCreator.__init__(self, verbose) self.blmin = blmin self.n_top = n_top self.probability = probability self.descriptor = descriptor self.min_inputs = 1
def __init__(self, verbose=False, num_muts=1, allowed_compositions=None, distribution_correction_function=None, element_pools=None): OffspringCreator.__init__(self, verbose, num_muts=num_muts) self.allowed_compositions = allowed_compositions self.element_pools = element_pools if distribution_correction_function is None: self.dcf = dummy_func else: self.dcf = distribution_correction_function
def __init__(self, blmin, cellbounds=None, stddev=0.7, use_tags=False, verbose=False): OffspringCreator.__init__(self, verbose) self.blmin = blmin self.cellbounds = cellbounds self.stddev = stddev self.use_tags = use_tags self.scaling_volume = None self.descriptor = 'StrainMutation' self.min_inputs = 1
def __init__(self, n_top, probability=0.33, test_dist_to_slab=True, use_tags=False, blmin=None, verbose=False): OffspringCreator.__init__(self, verbose) self.n_top = n_top self.probability = probability self.test_dist_to_slab = test_dist_to_slab self.use_tags = use_tags self.blmin = blmin self.descriptor = 'PermutationMutation' self.min_inputs = 1
def __init__(self, blmin, n_top, rattle_strength=0.8, rattle_prop=0.4, min_z=None, verbose=False, descriptor='RattleMutation'): OffspringCreator.__init__(self, verbose) self.blmin = blmin self.n_top = n_top self.rattle_strength = rattle_strength self.rattle_prop = rattle_prop self.min_z = min_z self.descriptor = descriptor self.min_inputs = 1
def __init__(self, slab, n_top, blmin, n_clusters, n_parents=3, r_cut=11.9, verbose=False): OffspringCreator.__init__(self, verbose) self.slab = slab self.n_top = n_top self.blmin = blmin self.n_clusters = n_clusters self.r_cut = r_cut self.descriptor = 'ClusterDistanceMutation' self.min_inputs = n_parents
def __init__(self, blmin, n_top=None, fraction=0.33, tags=None, min_angle=1.57, test_dist_to_slab=True, verbose=False): OffspringCreator.__init__(self, verbose) self.blmin = blmin self.n_top = n_top self.fraction = fraction self.tags = tags self.min_angle = min_angle self.test_dist_to_slab = test_dist_to_slab self.descriptor = 'RotationalMutation' self.min_inputs = 1
def __init__(self, blmin, n_top, rattle_strength=0.8, rattle_prop=0.4, test_dist_to_slab=True, use_tags=False, verbose=False): OffspringCreator.__init__(self, verbose) self.blmin = blmin self.n_top = n_top self.rattle_strength = rattle_strength self.rattle_prop = rattle_prop self.test_dist_to_slab = test_dist_to_slab self.use_tags = use_tags self.descriptor = 'RattleMutation' self.min_inputs = 1
def __init__(self, blmin, cellbounds=None, stddev=0.7, number_of_variable_cell_vectors=3, use_tags=False, rng=np.random, verbose=False): OffspringCreator.__init__(self, verbose, rng=rng) self.blmin = blmin self.cellbounds = cellbounds self.stddev = stddev self.number_of_variable_cell_vectors = number_of_variable_cell_vectors self.use_tags = use_tags self.scaling_volume = None self.descriptor = 'StrainMutation' self.min_inputs = 1
def initialize_individual(cls, parent, indi=None): indi = OffspringCreator.initialize_individual(parent, indi=indi) if 'unrelaxed_adsorbates' in parent.info['data']: unrelaxed = list(parent.info['data']['unrelaxed_adsorbates']) else: unrelaxed = [] indi.info['data']['unrelaxed_adsorbates'] = unrelaxed return indi
def __init__(self, blmin, n_top=None, p1=1., p2=0.05, minfrac=None, cellbounds=None, use_tags=False, test_dist_to_slab=True, verbose=False): OffspringCreator.__init__(self, verbose) self.blmin = blmin self.n_top = n_top self.p1 = p1 self.p2 = p2 self.minfrac = minfrac self.cellbounds = cellbounds self.use_tags = use_tags self.test_dist_to_slab = test_dist_to_slab self.scaling_volume = None self.descriptor = 'CutAndSplicePairing' self.min_inputs = 1
def __init__(self, blmin, bounds=[0.5, 2.0], calculator=BondElectroNegativityModel, rcut=10., used_modes_file='used_modes.json', use_tags=False, verbose=False): OffspringCreator.__init__(self, verbose) self.blmin = blmin self.bounds = bounds self.calc = calculator self.rcut = rcut self.used_modes_file = used_modes_file self.use_tags = use_tags self.descriptor = 'SoftMutation' self.used_modes = {} if self.used_modes_file is not None: try: self.read_used_modes(self.used_modes_file) except IOError: # file doesn't exist (yet) pass
def __init__(self, num_muts): OffspringCreator.__init__(self) self.descriptor = 'Mutation' self.num_muts = num_muts
def __init__(self, n_top, probability=0.33, verbose=False): OffspringCreator.__init__(self, verbose) self.n_top = n_top self.probability = probability self.descriptor = 'PermutationMutation'
def __init__(self): OffspringCreator.__init__(self) self.descriptor = 'Crossover'
def finalize_individual(self, indi): atoms_string = ''.join(indi.get_chemical_symbols()) indi.info['key_value_pairs']['atoms_string'] = atoms_string return OffspringCreator.finalize_individual(self, indi)
def __init__(self, adsorbate): OffspringCreator.__init__(self) self.adsorbate = self.convert_adsorbate(adsorbate) self.descriptor = 'AdsorbateOperator'
def __init__(self, num_muts=1, rng=np.random): OffspringCreator.__init__(self, num_muts=num_muts, rng=rng) self.descriptor = 'Mutation' self.min_inputs = 1
def __init__(self, rng=np.random): OffspringCreator.__init__(self, rng=rng) self.descriptor = 'Crossover' self.min_inputs = 2
def __init__(self): OffspringCreator.__init__(self) self.descriptor = "Crossover" self.min_inputs = 2
slab3[0].symbol = 'Au' db.add_unrelaxed_candidate(slab3, 'mutated: Parent {0}'.format(old_confid)) new_confid = slab3.info['confid'] # confid should update when using add_unrelaxed_candidate assert old_confid != new_confid slab3[1].symbol = 'Au' db.add_unrelaxed_step(slab3, 'mutated: Parent {0}'.format(new_confid)) # confid should not change when using add_unrelaxed_step assert slab3.info['confid'] == new_confid with must_raise(AssertionError): db.add_relaxed_step(slab3) set_raw_score(slab3, 3) db.add_relaxed_step(slab3) slab4 = OffspringCreator.initialize_individual(slab1, fcc111('Au', size=(2, 2, 2))) set_raw_score(slab4, 67) db.add_relaxed_candidate(slab4) assert slab4.info['confid'] == 7 more_slabs = [] for m in ['Ni', 'Pd', 'Pt']: slab = fcc111(m, size=(2, 2, 2)) slab = OffspringCreator.initialize_individual(slab1, slab) set_raw_score(slab, sum(slab.get_masses())) more_slabs.append(slab) db.add_more_relaxed_candidates(more_slabs) assert more_slabs[1].info['confid'] == 9 os.remove(db_file)