def get_mutant(self, cluster): cluster.sort_type() atom_types = list(cluster.atom_types) swap0 = np.random.randint(0, get_composition(atom_types)[0]) swap1 = np.random.randint( get_composition(atom_types)[0], cluster.natoms) atom_types[swap0] = 1 atom_types[swap1] = 0 mutant = Cluster(cluster.natoms, np.array(cluster._coords), cluster.minimiser, atom_types=atom_types, labels=cluster.labels) mutant.sort_type() return mutant
def get_offspring(self, cluster_a, cluster_b): '''Generate an offspring structure from two parent structures.''' #Prepare clusters for cluster in [cluster_a, cluster_b]: cluster.centre() cluster.rotate_random() cluster.sort_z() #Choose cutting plane cut = np.random.randint(1, cluster_a.natoms) #Make new cluster coords = np.empty(shape=(cluster_a.natoms, 3)) atom_types = [] for i in range(0, cut): coords[i] = cluster_a.get_coords(i) atom_types.append(cluster_a.atom_types[i]) for i in range(cut, cluster_a.natoms): coords[i] = cluster_b.get_coords(i) atom_types.append(cluster_b.atom_types[i]) composition = get_composition(cluster_a.atom_types) atom_types = fix_composition(composition, atom_types) offspring = Cluster(cluster_a.natoms, coords, cluster_a.minimiser, atom_types=atom_types, labels=cluster_a.labels) offspring.quenched = False offspring.sort_type() cluster_a.sort_type() cluster_b.sort_type() return offspring
def minimise (self,cluster): '''Minimise a cluster parameters: cluster- a Cluster object from bcga.cluster Using this method will overwrite the coordinates and energy of the supplied Cluster object.''' # Fix overlapping atoms to avoid NWChem errors cluster.fix_overlaps(1.5) # Set up element labels for NWChem atom_string="" for i in range(0,len(cluster.labels)): atom_string+=cluster.labels[i]+str(get_composition(cluster.atom_types)[i]) print(atom_string) mol = Atoms(atom_string, positions=cluster._coords, cell=(6.0,6.0,6.0)) mol.center() # Run GPAW calculation calc = GPAW(**self.GPAWargs) mol.set_calculator(calc) opt = BFGSLineSearch(mol) try: opt.run(fmax=0.25) except: sys.exit() # Get back cluster properties from GPAW cluster.energy=mol.get_potential_energy() cluster.quenched=True return cluster
def get_offspring(self,cluster_a,cluster_b): '''Generate an offspring structure from two parent structures.''' #Prepare clusters for cluster in [cluster_a,cluster_b]: cluster.centre() cluster.rotate_random() cluster.sort_z() #Choose cutting plane cut=np.random.randint(1,cluster_a.natoms) #Make new cluster coords=np.empty(shape=(cluster_a.natoms,3)) atom_types=[] for i in range(0,cut): coords[i]=cluster_a.get_coords(i) atom_types.append(cluster_a.atom_types[i]) for i in range(cut,cluster_a.natoms): coords[i]=cluster_b.get_coords(i) atom_types.append(cluster_b.atom_types[i]) composition = get_composition(cluster_a.atom_types) atom_types=fix_composition(composition,atom_types) offspring=Cluster(cluster_a.natoms, coords, cluster_a.minimiser, atom_types=atom_types, labels=cluster_a.labels) offspring.quenched=False offspring.sort_type() cluster_a.sort_type() cluster_b.sort_type() return offspring
def minimise(self, cluster): '''Minimise a cluster parameters: cluster- a Cluster object from bcga.cluster Using this method will overwrite the coordinates and energy of the supplied Cluster object.''' # Fix overlapping atoms to avoid NWChem errors cluster.fix_overlaps(1.5) # Set up element labels for NWChem atom_string = "" for i in range(0, len(cluster.labels)): atom_string += cluster.labels[i] + str( get_composition(cluster.atom_types)[i]) print(atom_string) mol = Atoms(atom_string, positions=cluster._coords, cell=(6.0, 6.0, 6.0)) mol.center() # Run GPAW calculation calc = GPAW(**self.GPAWargs) mol.set_calculator(calc) opt = BFGSLineSearch(mol) try: opt.run(fmax=0.25) except: sys.exit() # Get back cluster properties from GPAW cluster.energy = mol.get_potential_energy() cluster.quenched = True return cluster
def get_mutant(self,cluster): cluster.sort_type() atom_types=list(cluster.atom_types) swap0=np.random.randint(0, get_composition(atom_types)[0]) swap1=np.random.randint(get_composition(atom_types)[0], cluster.natoms) atom_types[swap0]=1 atom_types[swap1]=0 mutant=Cluster(cluster.natoms, np.array(cluster._coords), cluster.minimiser, atom_types=atom_types, labels=cluster.labels) mutant.sort_type() return mutant