def test_particle_comparators(): from ase.cluster import Icosahedron from ase.ga.particle_comparator import NNMatComparator from ase.ga.utilities import get_nnmat from ase.ga.particle_mutations import RandomPermutation ico1 = Icosahedron('Cu', 4) ico1.info['confid'] = 1 ico2 = Icosahedron('Ni', 4) ico1.numbers[:55] = [28] * 55 ico2.numbers[:92] = [29] * 92 ico1.info['data'] = {} ico1.info['data']['nnmat'] = get_nnmat(ico1) ico2.info['data'] = {} ico2.info['data']['nnmat'] = get_nnmat(ico2) comp = NNMatComparator() assert not comp.looks_like(ico1, ico2) op = RandomPermutation() a3, desc = op.get_new_individual([ico1]) assert a3.get_chemical_formula() == ico1.get_chemical_formula() hard_comp = NNMatComparator(d=100) assert hard_comp.looks_like(ico1, a3) soft_comp = NNMatComparator(d=.0001) assert not soft_comp.looks_like(ico1, a3)
def test_particle_operators(): from ase.cluster import Icosahedron from ase.ga.particle_crossovers import CutSpliceCrossover from random import shuffle ico1 = Icosahedron('Cu', 3) ico1.info['confid'] = 1 ico2 = Icosahedron('Ni', 3) ico2.info['confid'] = 2 # TODO: Change this crossover to one for fixed particles # op = CutSpliceCrossover({(28, 29): 2.0, (28, 28): 2.0, (29, 29): 2.0}, # keep_composition=False) # a3, desc = op.get_new_individual([ico1, ico2]) # assert len(set(a3.get_chemical_symbols())) == 2 # assert len(a3) == 55 ico1.numbers[:20] = [28] * 20 shuffle(ico1.numbers) ico2.numbers[:35] = [29] * 35 shuffle(ico2.numbers) op = CutSpliceCrossover({(28, 29): 2.0, (28, 28): 2.0, (29, 29): 2.0}) a3, desc = op.get_new_individual([ico1, ico2]) assert a3.get_chemical_formula() == 'Cu35Ni20' from ase.ga.particle_mutations import COM2surfPermutation # from ase.ga.particle_mutations import RandomPermutation # from ase.ga.particle_mutations import Poor2richPermutation # from ase.ga.particle_mutations import Rich2poorPermutation op = COM2surfPermutation(min_ratio=0.05) a3, desc = op.get_new_individual([ico1]) a3.info['confid'] = 3 assert a3.get_chemical_formula() == 'Cu35Ni20' aconf = op.get_atomic_configuration(a3) core = aconf[1] shell = aconf[-1] for i, sym in zip(core, 6 * ['Ni'] + 6 * ['Cu']): a3[i].symbol = sym for i, sym in zip(shell, 6 * ['Ni'] + 6 * ['Cu']): a3[i].symbol = sym atomic_conf = op.get_atomic_configuration(a3, elements=['Cu'])[-2:] cu3 = len([item for sublist in atomic_conf for item in sublist]) a4, desc = op.get_new_individual([a3]) atomic_conf = op.get_atomic_configuration(a4, elements=['Cu'])[-2:] cu4 = len([item for sublist in atomic_conf for item in sublist]) assert abs(cu4 - cu3) == 1
def test_relax(): """ Test that a static relaxation that requires multiple neighbor list rebuilds can be carried out successfully. This is verified by relaxing an icosahedral cluster of atoms and checking that the relaxed energy matches a known precomputed value for an example model. """ import numpy as np from ase.cluster import Icosahedron from pytest import importorskip importorskip('kimpy') from ase.calculators.kim import KIM from ase.optimize import BFGS energy_ref = -0.5420939378624228 # eV # Create structure and calculator atoms = Icosahedron("Ar", latticeconstant=3.0, noshells=2) calc = KIM("ex_model_Ar_P_Morse_07C") atoms.calc = calc opt = BFGS(atoms, logfile=None) opt.run(fmax=0.05) assert np.isclose(atoms.get_potential_energy(), energy_ref)
def test_utilities(): eps = 1e-5 atoms = Icosahedron('Cu', 3) atoms.numbers[[0, 13, 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30]] = 79 atoms.center(vacuum=0.0) atoms.calc = EMT() with FIRE(atoms, logfile=None) as opt: opt.run(fmax=0.05) rmax = 8. nbins = 5 rdf, dists = get_rdf(atoms, rmax, nbins) calc_dists = np.arange(rmax / (2 * nbins), rmax, rmax / nbins) assert all(abs(dists - calc_dists) < eps) calc_rdf = [0., 0.84408157, 0.398689, 0.23748934, 0.15398546] assert all(abs(rdf - calc_rdf) < eps) dm = atoms.get_all_distances() s = np.zeros(5) for c in [(29, 29), (29, 79), (79, 29), (79, 79)]: inv_norm = len(np.where(atoms.numbers == c[0])[0]) / len(atoms) s += get_rdf(atoms, rmax, nbins, elements=c, distance_matrix=dm, no_dists=True) * inv_norm assert all(abs(s - calc_rdf) < eps) AuAu = get_rdf(atoms, rmax, nbins, elements=(79, 79), distance_matrix=dm, no_dists=True) assert all(abs(AuAu[-2:] - [0.12126445, 0.]) < eps) bulk = L1_2(['Au', 'Cu'], size=(3, 3, 3), latticeconstant=2 * np.sqrt(2)) rdf = get_rdf(bulk, 4.2, 5)[0] calc_rdf = [0., 0., 1.43905094, 0.36948605, 1.34468694] assert all(abs(rdf - calc_rdf) < eps)
def atoms_no_pbc(): ref_atoms = Icosahedron('Ag', 2, 3.82975) ref_atoms.calc = EMT() atoms = ref_atoms.copy() atoms.calc = EMT() atoms.rattle(stdev=0.1, seed=7) e_unopt = atoms.get_potential_energy() assert e_unopt > 7 # it's 7.318 as of writing this test return atoms, ref_atoms
def test_relax(KIM): """ Test that a static relaxation that requires multiple neighbor list rebuilds can be carried out successfully. This is verified by relaxing an icosahedral cluster of atoms and checking that the relaxed energy matches a known precomputed value for an example model. """ from ase.optimize import BFGS energy_ref = -0.56 # eV # Create structure and calculator atoms = Icosahedron("Ar", latticeconstant=3.0, noshells=2) calc = KIM("ex_model_Ar_P_Morse_07C") atoms.calc = calc opt = BFGS(atoms, maxstep=0.04, alpha=70.0, logfile=None) opt.run(fmax=0.01) # eV/angstrom assert np.isclose(atoms.get_potential_energy(), energy_ref, atol=0.05)
from ase.cluster import Octahedron, Icosahedron, Decahedron from ase.visualize import view from ase.io import write atoms = Octahedron('Au', length=5, cutoff=2) com = atoms.get_center_of_mass() atoms.set_cell([20, 20, 20]) atoms.center() write('Au55-cuboctahedron.xyz', atoms) atoms = Decahedron('Au', p=3, q=3, r=0) com = atoms.get_center_of_mass() atoms.set_cell([20, 20, 20]) atoms.center() write('Au55-decahedron.xyz', atoms) atoms = Icosahedron('Au', noshells=3) com = atoms.get_center_of_mass() atoms.set_cell([20, 20, 20]) atoms.center() write('Au55-icosahedron.xyz', atoms)
from __future__ import division import numpy as np from ase.cluster import Icosahedron from ase.calculators.emt import EMT from ase.optimize.fire import FIRE from ase.lattice.compounds import L1_2 from ase.ga.utilities import get_rdf eps = 1e-5 atoms = Icosahedron('Cu', 3) atoms.numbers[[0, 13, 15, 16, 18, 19, 21, 22, 24, 25, 27, 28, 30]] = 79 atoms.set_calculator(EMT()) opt = FIRE(atoms, logfile=None) opt.run(fmax=0.05) rmax = 8. nbins = 5 rdf, dists = get_rdf(atoms, rmax, nbins) calc_dists = np.arange(rmax / (2 * nbins), rmax, rmax / nbins) assert all(abs(dists - calc_dists) < eps) calc_rdf = [0., 0.84408157, 0.398689, 0.23748934, 0.15398546] assert all(abs(rdf - calc_rdf) < eps) dm = atoms.get_all_distances() s = np.zeros(5) for c in [(29, 29), (29, 79), (79, 29), (79, 79)]: inv_norm = len(np.where(atoms.numbers == c[0])[0]) / len(atoms) s += get_rdf(
from ase.cluster import Icosahedron from ase.ga.particle_comparator import NNMatComparator from ase.ga.utilities import get_nnmat from ase.ga.particle_mutations import RandomPermutation ico1 = Icosahedron('Cu', 4) ico1.info['confid'] = 1 ico2 = Icosahedron('Ni', 4) ico1.numbers[:55] = [28] * 55 ico2.numbers[:92] = [29] * 92 ico1.info['data'] = {} ico1.info['data']['nnmat'] = get_nnmat(ico1) ico2.info['data'] = {} ico2.info['data']['nnmat'] = get_nnmat(ico2) comp = NNMatComparator() assert not comp.looks_like(ico1, ico2) op = RandomPermutation() a3, desc = op.get_new_individual([ico1]) assert a3.get_chemical_formula() == ico1.get_chemical_formula() hard_comp = NNMatComparator(d=100) assert hard_comp.looks_like(ico1, a3) soft_comp = NNMatComparator(d=.0001) assert not soft_comp.looks_like(ico1, a3)
""" Test that a static relaxation that requires multiple neighbor list rebuilds can be carried out successfully. This is verified by relaxing an icosahedral cluster of atoms and checking that the relaxed energy matches a known precomputed value for an example model. """ import numpy as np from ase.cluster import Icosahedron from ase.calculators.kim import KIM from ase.optimize import BFGS energy_ref = -0.5420939378624228 # eV # Create structure and calculator atoms = Icosahedron("Ar", latticeconstant=3.0, noshells=2) calc = KIM("ex_model_Ar_P_Morse_07C") atoms.set_calculator(calc) opt = BFGS(atoms, logfile=None) opt.run(fmax=0.05) assert np.isclose(atoms.get_potential_energy(), energy_ref)
write('Zr45Cu10-cuboctahedron.xyz', atoms) atoms = Decahedron('Zr', latticeconstant=a, p=3, q=3, r=0) indices = list(range(len(atoms))) random.shuffle(indices) for i in indices[:10]: atoms[i].symbol = 'Cu' com = atoms.get_center_of_mass() atoms.set_cell([20, 20, 20]) atoms.center() write('Zr45Cu10-decahedron.xyz', atoms) atoms = Icosahedron('Zr', latticeconstant=a, noshells=3) indices = list(range(len(atoms))) random.shuffle(indices) for i in indices[:10]: atoms[i].symbol = 'Cu' com = atoms.get_center_of_mass() atoms.set_cell([20, 20, 20]) atoms.center() write('Zr45Cu10-icosahedron.xyz', atoms) view(atoms)
layers, latticeconstant=lc, vacuum=10) add_to_dict(AseAtomsAdaptor.get_structure(atoms), 'Cu_cluster') from ase.cluster import Octahedron atoms = Octahedron(['Pt', 'Au'], length=3, alloy=True, latticeconstant=4) atoms.set_cell([15] * 3) atoms.center() add_to_dict(AseAtomsAdaptor.get_structure(atoms), 'PtAu_cluster') from ase.cluster import Icosahedron atoms = Icosahedron( 'Pt', noshells=3, ) atoms.set_cell([21] * 3) atoms.center() add_to_dict(AseAtomsAdaptor.get_structure(atoms), 'Pt_cluster') surfaces = [(1, 0, 0), (1, 1, 1), (1, -1, 1)] layers = [3, 1, -1] atoms = FaceCenteredCubic('Au', surfaces, layers) atoms.set_cell([10] * 3) add_to_dict(AseAtomsAdaptor.get_structure(atoms), 'Au_cluster') atoms.center() """ from ase.cluster import Decahedron surfaces = [(1, 0, 0), (1, 1, 1), (1, -1, 1)]
def make_ico(sym): atoms = Icosahedron(sym, 4) atoms.center(vacuum=4.0) return atoms