def setUpClass(cls) -> None: initial_structure = Icosahedron("Cu", 2) initial_structure.rattle(0.1) initial_structure.set_pbc(True) initial_structure.set_cell([20, 20, 20]) EMT_initial_structure = initial_structure.copy() parent_calc = EMT() cls.emt_counter = CounterCalc(parent_calc) EMT_initial_structure.set_calculator(cls.emt_counter) cls.EMT_structure_optim = Relaxation( EMT_initial_structure, BFGS, fmax=0.01, steps=30 ) cls.EMT_structure_optim.run(cls.emt_counter, "CuNP_emt") offline_initial_structure = compute_with_calc( [initial_structure.copy()], parent_calc )[0] Offline_relaxation = Relaxation( offline_initial_structure, BFGS, fmax=0.01, steps=30, maxstep=0.05 ) cls.offline_learner, cls.trained_calc, cls.Offline_traj = run_offline_al( Offline_relaxation, [offline_initial_structure], "CuNP_offline_al", parent_calc, ) cls.EMT_image = cls.EMT_structure_optim.get_trajectory("CuNP_emt")[-1] cls.EMT_image.set_calculator(parent_calc) cls.offline_final_structure_AL = cls.Offline_traj[-1] cls.offline_final_structure_AL.set_calculator(cls.trained_calc) cls.offline_final_structure_EMT = cls.Offline_traj[-1] cls.offline_final_structure_EMT.set_calculator(parent_calc) cls.description = "CuNP" return super().setUpClass()
def setUpClass(cls) -> None: # Set up parent calculator and image environment initial_structure = Icosahedron("Cu", 2) initial_structure.rattle(0.1) initial_structure.set_pbc(True) initial_structure.set_cell([20, 20, 20]) # Run relaxation with the parent calc EMT_initial_structure = initial_structure.copy() cls.emt_counter = CounterCalc(EMT()) EMT_initial_structure.set_calculator(cls.emt_counter) cls.EMT_structure_optim = Relaxation(EMT_initial_structure, BFGS, fmax=FORCE_THRESHOLD, steps=30) cls.EMT_structure_optim.run(cls.emt_counter, "CuNP_emt") # Run relaxation with active learning chemical_formula = initial_structure.get_chemical_formula() al_config = cls.get_al_config() al_config["links"]["traj"] = "CuNP_emt.traj" cls.oal_results_dict = active_learning(al_config) dbname = (str(al_config["links"]["ml_potential"]) + "_" + str(chemical_formula) + "_oal") cls.OAL_image = Trajectory(dbname + ".traj")[-1] cls.OAL_image.set_calculator(EMT()) # Retain images of the final structure from both relaxations cls.EMT_image = cls.EMT_structure_optim.get_trajectory("CuNP_emt")[-1] cls.EMT_image.set_calculator(EMT()) cls.description = "CuNP" return super().setUpClass()
def test_fake_ase_opt(): atoms = Icosahedron("Ar", noshells=2, latticeconstant=3) atoms.set_calculator(FakeASE(LennardJones())) dyn = BFGS(atoms) dyn.run(fmax=0.0005) assert dyn.converged() assert dyn.get_number_of_steps() == 14 assert np.linalg.norm(dyn.f0) == pytest.approx(0.0041872094)
def test_place_and_preoptimize_adsorbates(self): """Tests the function place_and_preoptimize_adsorbates""" ### Make a cluskit object from ase ### import random cluster_atoms = Icosahedron('Cu', noshells=3) cluster = cluskit.Cluster(cluster_atoms) sitepositions = cluster.get_sites(1) sitedescmatrix = cluster.get_sites_descriptor(sitetype=1) ## create molecule with anchor ## test_molecules = [ 'butadiene', 'CH3CH2OCH3', 'C2H6CHOH', 'C6H6', 'isobutane', 'C3H8', 'C2H6', 'trans-butane' ] # select only one molecule because of time-intensive function adsorbate_x = molecule(random.choice(test_molecules)) ch_sym = adsorbate_x.get_chemical_symbols() ch_sym[-1] = 'X' adsorbate_x.set_chemical_symbols(ch_sym) adsorbates = cluskit.utils.place_and_preoptimize_adsorbates( cluster, adsorbate_x, 1, max_distance=1.5, n_remaining=40, is_reduce=False, is_reset=True, n_lj_steps=2)
def test_connectivities(self): """Tests both voronoi and maximum bond length connectivity by comparing them to each other. """ atoms = Icosahedron('Cu', noshells=2) scaffold_from_ase1 = cluskit.build.Scaffold(atoms, max_bondlength=2.9) scaffold_from_ase2 = cluskit.build.Scaffold(atoms, max_bondlength=None) #print("#################") #print(scaffold_from_ase1.bond_matrix) #print("#################") #print(scaffold_from_ase2.bond_matrix) #print("#################") #print(np.sum(scaffold_from_ase1.bond_matrix, axis = 0), np.sum(scaffold_from_ase1.bond_matrix, axis = 1), np.sum(scaffold_from_ase1.bond_matrix)) #print(np.sum(scaffold_from_ase2.bond_matrix, axis = 0), np.sum(scaffold_from_ase2.bond_matrix, axis = 1), np.sum(scaffold_from_ase2.bond_matrix)) #print(np.where(scaffold_from_ase1.bond_matrix != scaffold_from_ase2.bond_matrix)) self.assertTrue( np.all(scaffold_from_ase1.bond_matrix == scaffold_from_ase2.bond_matrix)) scaffold1 = cluskit.build.get_scaffold(shape="ico", i=3, latticeconstant=3.0, max_bondlength=2.9) scaffold2 = cluskit.build.get_scaffold(shape="ico", i=3, latticeconstant=3.0, max_bondlength=None) self.assertTrue(np.all(scaffold1.bond_matrix == scaffold2.bond_matrix)) return
def test_icosa(shells): atoms = Icosahedron(sym, shells) assert len(atoms) == ico_cubocta_sizes[shells - 1] coordination = coordination_numbers(atoms) if shells == 1: return assert min(coordination) == ico_corner_coordination ncorners = sum(coordination == ico_corner_coordination) assert ncorners == ico_corners
def setUpClass(cls) -> None: # Set up parent calculator and image environment initial_structure = Icosahedron("Cu", 2) initial_structure.rattle(0.1) initial_structure.set_pbc(True) initial_structure.set_cell([20, 20, 20]) # Run relaxation with the parent calc EMT_initial_structure = initial_structure.copy() cls.emt_counter = CounterCalc(EMT()) EMT_initial_structure.set_calculator(cls.emt_counter) cls.EMT_structure_optim = Relaxation(EMT_initial_structure, BFGS, fmax=FORCE_THRESHOLD, steps=30) cls.EMT_structure_optim.run(cls.emt_counter, "CuNP_emt") # Run relaxation with active learning OAL_initial_structure = initial_structure.copy() OAL_initial_structure.set_calculator(EMT()) OAL_relaxation = Relaxation(OAL_initial_structure, BFGS, fmax=0.05, steps=60, maxstep=0.04) cls.OAL_learner, cls.OAL_structure_optim = run_online_al( OAL_relaxation, [OAL_initial_structure], ["Cu"], "CuNP_oal", EMT(), ) # Retain images of the final structure from both relaxations cls.EMT_image = cls.EMT_structure_optim.get_trajectory("CuNP_emt")[-1] cls.EMT_image.set_calculator(EMT()) cls.OAL_image = cls.OAL_structure_optim.get_trajectory("CuNP_oal")[-1] cls.OAL_image.set_calculator(EMT()) cls.description = "CuNP" return super().setUpClass()
def test_Ar_minimize(): from ase.calculators.lammpsrun import LAMMPS from ase.cluster.icosahedron import Icosahedron from ase.data import atomic_numbers, atomic_masses from numpy.testing import assert_allclose from ase.optimize import LBFGS ar_nc = Icosahedron('Ar', noshells=2) ar_nc.cell = [[300, 0, 0], [0, 300, 0], [0, 0, 300]] ar_nc.pbc = True params = {} params['pair_style'] = 'lj/cut 8.0' params['pair_coeff'] = ['1 1 0.0108102 3.345'] params['masses'] = ['1 {}'.format(atomic_masses[atomic_numbers['Ar']])] with LAMMPS(specorder=['Ar'], **params) as calc: ar_nc.set_calculator(calc) assert_allclose(ar_nc.get_potential_energy(), -0.468147667942117, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), calc.calculate_numerical_forces(ar_nc), atol=1e-4, rtol=1e-4) dyn = LBFGS(ar_nc, force_consistent=False) dyn.run(fmax=1E-6) assert_allclose(ar_nc.get_potential_energy(), -0.4791815886953914, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), calc.calculate_numerical_forces(ar_nc), atol=1e-4, rtol=1e-4)
def makeMotif(motif_inputs, latticeconstant, remove_atoms=[]): if isinstance(motif_inputs, int) or len(motif_inputs) == 1: if isinstance(motif_inputs, int): motif_inputs = [motif_inputs] cluster = Icosahedron(symbol, motif_inputs[0], latticeconstant=latticeconstant) name = 'Ico' elif len(motif_inputs) == 2: cluster = Octahedron(symbol, motif_inputs[0], motif_inputs[1], latticeconstant=latticeconstant) name = 'Octa' elif len(motif_inputs) == 3: cluster = Decahedron(symbol, motif_inputs[0], motif_inputs[1], motif_inputs[2], latticeconstant=latticeconstant) name = 'Deca' else: print "Error" import pdb pdb.set_trace() exit() remove_atoms.sort(reverse=True) if any(remove_atoms.count(x) > 1 for x in remove_atoms): print 'You have got two of the same atom entered in to this list, check this.' print 'remove_atoms = ' + str(remove_atoms) import pdb pdb.set_trace() exit() for remove_atom_index in remove_atoms: del cluster[remove_atom_index] name += '_' + symbol + str(len(cluster)) motif_details = '' for motif_input in motif_inputs: motif_details += str(motif_input) + '_' motif_details = motif_details[:-1] name += '_' + motif_details if not remove_atoms == []: name += '_atoms_removed_' + str(len(remove_atoms)) + '_cluster_' counter = 1 while True: if not name + str(counter) + '.traj' in os.listdir('.'): name += str(counter) break counter += 1 ASE_write(name + '.traj', cluster, 'traj') return name
def get_scaffold(shape = "ico", i = 3, latticeconstant = 3.0, energies = [0.5,0.4,0.3], surfaces = [(1, 0, 0), (1, 1, 1), (1, 1, 0)], max_bondlength = None): """Builds a scaffold of ghost atoms in icosahedral, octahedral or wulff-shape. Takes a shape argument (string can be ico, octa or wulff) as well as the size argument i (int) and a latticeconstant. When shape = 'wulff', it is required to give energies and surfaces as lists of equal length. Returns a Cluster object with atom type 'X'. Args: shape (str) : nanocluster shape such as "ico" (default), "octa", "wulff" i (float) : size of the nanocluster. Has different implications depending on the shape latticeconstant (float) : lattice constant of the fcc crystal structure defining the scaling of the nanocluster energies (list) : Defines Wulff-shape, ignored otherwise. The proportions of the surface energies defining the prominence of certain slabs defined by surface (energies and corresponding surfaces must be in the same order) surfaces (list) : Defines Wulff-shape, ignored otherwise. The Miller-indices of the surface slabs. Their energies define the prominence of certain slabs (energies and corresponding surfaces must be in the same order) max_bondlength (float) : distance up to which two atoms are considered bound. If None, the minimum distance is used as a guess with a tolerance factor of 0.1. Works well with equidistant atoms. Returns: cluskit.Scaffold : Scaffold object, an enhanced ase.Atoms object with additional attributes such as bond_matrix """ if shape == "ico": atoms = Icosahedron('X', noshells = i, latticeconstant = latticeconstant) elif shape == "octa": atoms = Octahedron('X', length = i, latticeconstant = latticeconstant) elif shape == "wulff": # i gives size in atoms atoms = wulff_construction('X', latticeconstant = latticeconstant, surfaces=surfaces, energies=energies, size=i, structure='fcc', rounding='above') else: raise NameError("shape argument unknown! Use ico, octa or wulff") return Scaffold(atoms, max_bondlength = max_bondlength)
def icosahedron_grid(element, lattice_constant, size): atoms = Icosahedron(symbol=element, noshells=size, latticeconstant=lattice_constant) atoms.set_pbc(True) atoms.center(vacuum=5.) return atoms
def test_lennard_jones(): atoms = Icosahedron("Ar", noshells=2, latticeconstant=3) atoms.set_calculator(ase_LJ()) ase_forces = atoms.get_forces() ase_energy = atoms.get_potential_energy() coords = atoms.positions.flatten() geom = Geometry(atoms.get_chemical_symbols(), coords / BOHR2ANG) geom.set_calculator(LennardJones()) pysis_energy = geom.energy assert pysis_energy == pytest.approx(ase_energy) pysis_forces = geom.forces / BOHR2ANG np.testing.assert_allclose(pysis_forces, ase_forces.flatten(), atol=1e-15)
def test_fake_ase(): # pysisyphus pysis_calc = LennardJones() ase_calc = FakeASE(pysis_calc) # ASE atoms, pysisyphus calculator atoms_pysis = Icosahedron("Ar", noshells=2, latticeconstant=3) # ASE atoms, ASE calculator atoms_ase = atoms_pysis.copy() atoms_pysis.set_calculator(ase_calc) atoms_ase.set_calculator(ase_LJ()) pysis_forces = atoms_pysis.get_forces() ase_forces = atoms_ase.get_forces() np.testing.assert_allclose(pysis_forces, ase_forces, atol=1e-15)
def run(A, B, num_jobs): A = A[0] B = B[0] num_jobs = num_jobs[0] for s in [A, B]: if s not in chemical_symbols: raise ValueError("{0} is not a valid chemical species.".format(s)) zA = atomic_numbers[A] zB = atomic_numbers[B] (zA, A), (zB, B) = sorted([(zA, A), (zB, B)]) atoms = Icosahedron(A, 5) graph = build_neighbor_graph(atoms, cutoff=3.7) order, site_types = get_site_types(graph) atoms, _ = relax_structure(atoms) m = len(np.unique(site_types)) cs = list(itertools.product([zA, zB], repeat=m)) db = connect('symmetric_{0}{1}.db'.format(A, B), append=False) Parallel(n_jobs=num_jobs)(delayed(worker)(i, db, site_types, atoms, c) for i, c in enumerate(cs))
def write_icosahedral_cluster(element,e_coh,maximum_size,manual_mode,filename_suffix,input_information_file,folder,sort_manual_mode_by='base details'): print('============================================================') print('Starting Obtaining Icosahedral Delta Energies') print('no atoms\tno of shells') noshells = 2 all_ico_details = [] while True: no_atoms = no_of_atoms_to_make_ico(noshells) if no_atoms > maximum_size: break #--------------------------------------------------------------------------------- # Make cluster print('Make icosahedral cluster: '+str(no_atoms) + ' \tnoshells: ' + str(noshells)) cluster = Icosahedron(element,noshells=noshells) post_creating_cluster(cluster) name = 'Ico_'+str(no_atoms) save_cluster_to_folder(folder,name,filename_suffix,manual_mode,cluster) #--------------------------------------------------------------------------------- # make data for details no_atoms = len(cluster) ico_details = (no_atoms, noshells) all_ico_details.append(ico_details) #--------------------------------------------------------------------------------- noshells += 1 #--------------------------------------------------------------------------------- print('============================================================') with open(input_information_file,'a') as input_file: input_file.write('Icosahedron\n') if sort_manual_mode_by == 'no of atoms': all_ico_details.sort(key=lambda x:x[0]) elif sort_manual_mode_by == 'base details': all_ico_details.sort(key=lambda x:x[1]) for no_atoms, noshells in all_ico_details: no_atoms = str(no_atoms) noshells = str(noshells) input_file.write(no_atoms+' '*(atom_writing-len(no_atoms))+noshells+' '*(details_writing-len(noshells))+'\n')
def test_place_molecule_on_site(self): """Tests the function place_molecule_on_site""" atoms = Icosahedron('Cu', noshells=3) cluster = cluskit.Cluster(atoms) zero_site = cluster.get_positions()[53] arbitrary_vector = [-2, -2, -2] adsorbate_x = ase.Atoms('HHCX', positions=[[2, 0, 0], [0, 2, 0], [0, 0, 0], [-1.4, -1.4, 0]]) adsorbate = cluskit.utils.place_molecule_on_site( molecule=adsorbate_x, zero_site=zero_site, adsorption_vector=arbitrary_vector) clus_ads = atoms + adsorbate adsorbate_vector_ase = ase.Atoms( 'OO', positions=[ zero_site + arbitrary_vector, zero_site + np.multiply(arbitrary_vector, 2) ]) return
#!/usr/bin/env python from ase import Atoms, Atom from ase.calculators.aims import Aims, AimsCube from ase.cluster.icosahedron import Icosahedron from ase.io import write import numpy as np import os np.set_printoptions(precision=3, suppress=True) atoms = Icosahedron('Pt', noshells=2) calc = Aims(label='cluster/pt-isosahedron-2-relax', xc='pbe', spin='none', relativistic = 'atomic_zora scalar', sc_accuracy_rho=1e-4, sc_accuracy_eev=1e-2, sc_accuracy_etot=1e-5, sc_iter_limit=100, relax_geometry = 'bfgs 1.e-2') atoms.set_calculator(calc) print('energy = {0} eV'.format(atoms.get_potential_energy())) print('Forces') print('=======') print(atoms.get_forces())
eAB (list of 2 floats): pseudo-energy of A-B interaction eBB (list of 2 floats): pseudo-energy of B-B interaction eEA (list of 2 floats): pseudo-energy of segregation of A into the core. eEB (list of 2 floats): pseudo-energy of segregation of A into the core. typeA (int): element of type A in atomic number of PSE. typeB (int): element of type B in atomic number of PSE. ntype (int): number of atoms of type B in cluster. This argument controls the composition. n_clus (int): number of cluster to be returned. Returns: list (Cluster): Most dissimilar clusters in the given Pseudo-energy range. """ # two ways to create a scaffold (required for cluster generator) atoms = Icosahedron('Cu', noshells=3) # or other ase object e.g. structure from file scaffold_from_ase = Scaffold(atoms) scaffold = get_scaffold(shape = "ico", i = 3, latticeconstant = 3.0, energies = [0.5,0.4,0.3], surfaces = [(1, 0, 0), (1, 1, 1), (1, 1, 0)]) # setup descriptor scaffold_from_ase.descriptor_setup = dscribe.descriptors.SOAP( species=[28, 78], periodic=False, rcut=5.0, nmax=8, lmax=6, sparse=False, average=True
from ase.calculators.lammpsrun import LAMMPS from ase.cluster.icosahedron import Icosahedron from ase.data import atomic_numbers, atomic_masses from numpy.testing import assert_allclose from ase.optimize import LBFGS ar_nc = Icosahedron('Ar', noshells=2) ar_nc.cell = [[300, 0, 0], [0, 300, 0], [0, 0, 300]] ar_nc.pbc = True params = {} params['pair_style'] = 'lj/cut 8.0' params['pair_coeff'] = ['1 1 0.0108102 3.345'] params['masses'] = ['1 {}'.format(atomic_masses[atomic_numbers['Ar']])] calc = LAMMPS(specorder=['Ar'], **params) ar_nc.set_calculator(calc) assert_allclose(ar_nc.get_potential_energy(), -0.468147667942117, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), calc.calculate_numerical_forces(ar_nc), atol=1e-4, rtol=1e-4) dyn = LBFGS(ar_nc, force_consistent=False) dyn.run(fmax=1E-6)
def test_Ar_minimize_multistep(): from ase.calculators.lammpsrun import LAMMPS from ase.cluster.icosahedron import Icosahedron from ase.data import atomic_numbers, atomic_masses from numpy.testing import assert_allclose ar_nc = Icosahedron('Ar', noshells=2) ar_nc.cell = [[300, 0, 0], [0, 300, 0], [0, 0, 300]] ar_nc.pbc = True params = {} params['pair_style'] = 'lj/cut 8.0' params['pair_coeff'] = ['1 1 0.0108102 3.345'] params['masses'] = ['1 {}'.format(atomic_masses[atomic_numbers['Ar']])] with LAMMPS(specorder=['Ar'], **params) as calc: ar_nc.calc = calc F1_numer = calc.calculate_numerical_forces(ar_nc) assert_allclose(ar_nc.get_potential_energy(), -0.468147667942117, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), F1_numer, atol=1e-4, rtol=1e-4) params['minimize'] = '1.0e-15 1.0e-6 2000 4000' # add minimize calc.parameters = params # set_atoms=True to read final coordinates after minimization calc.run(set_atoms=True) # get final coordinates after minimization ar_nc.set_positions(calc.atoms.positions) assert_allclose(ar_nc.get_potential_energy(), -0.4791815887032201, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), calc.calculate_numerical_forces(ar_nc), atol=1e-4, rtol=1e-4)
import torch import os import copy # Set up ensemble parallelization if __name__ == "__main__": # import make_ensemble and dask for setting parallelization from al_mlp.ensemble_calc import EnsembleCalc from dask.distributed import Client, LocalCluster cluster = LocalCluster(processes=True, threads_per_worker=1) client = Client(cluster) EnsembleCalc.set_executor(client) # Set up parent calculator and image environment initial_structure = Icosahedron("Cu", 2) initial_structure.rattle(0.1) initial_structure.set_pbc(True) initial_structure.set_cell([20, 20, 20]) images = [] elements = ["Cu"] parent_calc = EMT() # Run relaxation with active learning OAL_initial_structure = initial_structure.copy() OAL_initial_structure.set_calculator(copy.deepcopy(parent_calc)) OAL_relaxation = Relaxation(OAL_initial_structure, BFGS, fmax=0.05, steps=60, maxstep=0.04)
from ase.cluster.icosahedron import Icosahedron from ase.io import write ns = 36 atoms = Icosahedron('Cu', noshells=ns) print('#atoms = {}'.format(len(atoms))) write('icosahedron-%03d.xyz' % ns, atoms)
from ase.io import write from ase.cluster.icosahedron import Icosahedron import matplotlib.cm as cmx import os system = Icosahedron('Ag', 3) for j in range(3): d = max(system.positions[:, j]) - min(system.positions[:, j]) system.cell[j, j] = d + 15. system.center() center = (system.cell[0, 0] / 2., system.cell[1, 1] / 2., system.cell[2, 2] / 2.) width = max(system.positions[:, 0]) - min(system.positions[:, 0]) height = max(system.positions[:, 1]) - min(system.positions[:, 1]) xmin = min(system.positions[:, 0]) xmax = max(system.positions[:, 0]) colors = [] map = cmx.rainbow for i, at in enumerate(system): code = int((at.position[0] - xmin) / width * 255) color_ = map(code) color = (color_[0], color_[1], color_[2], 0.5) colors.append(color) pad = 3 xmin = center[0] - width / 2. - pad ymin = center[1] - height / 2. - pad xmax = center[0] + width / 2. + pad
def getatoms(): return Icosahedron('Au', 3)
import torch import os import copy # Set up ensemble parallelization if __name__ == "__main__": # import make_ensemble and dask for setting parallelization from al_mlp.ml_potentials.amptorch_ensemble_calc import AmptorchEnsembleCalc from dask.distributed import Client, LocalCluster cluster = LocalCluster(processes=True, threads_per_worker=1) client = Client(cluster) AmptorchEnsembleCalc.set_executor(client) # Set up parent calculator and image environment initial_structure = Icosahedron("Cu", 2) initial_structure.rattle(0.1) initial_structure.set_pbc(True) initial_structure.set_cell([20, 20, 20]) images = [] elements = ["Cu"] parent_calc = EMT() # Run relaxation with active learning OAL_initial_structure = initial_structure.copy() OAL_initial_structure.set_calculator(copy.deepcopy(parent_calc)) OAL_relaxation = Relaxation(OAL_initial_structure, BFGS, fmax=0.05, steps=200, maxstep=0.04)
from ase.calculators.lammpsrun import LAMMPS from ase.cluster.icosahedron import Icosahedron from ase.data import atomic_numbers, atomic_masses import numpy as np from ase.optimize import LBFGS ar_nc = Icosahedron('Ar', noshells=2) ar_nc.cell = [[300, 0, 0], [0, 300, 0], [0, 0, 300]] ar_nc.pbc = True params = {} params['pair_style'] = 'lj/cut 8.0' params['pair_coeff'] = ['1 1 0.0108102 3.345'] params['mass'] = ['1 {}'.format(atomic_masses[atomic_numbers['Ar']])] calc = LAMMPS(specorder=['Ar'], parameters=params) ar_nc.set_calculator(calc) E = ar_nc.get_potential_energy() F = ar_nc.get_forces() assert abs(E - -0.47) < 1E-2 assert abs(np.linalg.norm(F) - 0.0574) < 1E-4 dyn = LBFGS(ar_nc, force_consistent=False) dyn.run(fmax=1E-6) E = round(ar_nc.get_potential_energy(), 2) F = ar_nc.get_forces()
def __init__(self, motif, motif_details, element=None, local_optimiser=None, e_coh=None, no_atoms=None, delta_energy=None, debug=False, get_energy=False): if debug: print('cluster: ' + str(cluster)) print('no_atoms: ' + str(no_atoms)) print('local_optimiser: ' + str(local_optimiser)) print('e_coh: ' + str(e_coh)) print('delta_energy: ' + str(delta_energy)) self.motif = motif self.motif_details = motif_details self.get_energy = get_energy # Calculate the delta energy of the clusters if not (element is None and local_optimiser is None and e_coh is None) and (no_atoms is None and delta_energy is None): if motif == 'Icosahedron': if isinstance(motif_details, list): noshells = motif_details[0] else: noshells = motif_details from ase.cluster.icosahedron import Icosahedron cluster = Icosahedron(element, noshells=noshells) elif motif == 'Octahedron': length = motif_details[0] cutoff = motif_details[1] from ase.cluster.octahedron import Octahedron cluster = Octahedron(element, length=length, cutoff=cutoff) elif motif == 'Decahedron': p = motif_details[0] q = motif_details[1] r = motif_details[2] from ase.cluster.decahedron import Decahedron cluster = Decahedron(element, p=p, q=q, r=r) else: print( 'Error in Get_Interpolation_Data.py, in class Cluster, in def __init__' ) print( 'No valid motif type has been entered, must be either Icosahedron, Octahedron, Decahedron.' ) print('Check this.') print('motif = ' + str(motif)) import pdb pdb.set_trace() exit() self.post_creating_cluster(cluster) self.no_atoms = len(cluster) cluster = local_optimiser(cluster) if self.get_energy: energy = cluster.get_potential_energy() self.delta_energy = get_Delta_Energy(energy, cluster, e_coh) elif (element is None and local_optimiser is None and e_coh is None ) and not (no_atoms is None and delta_energy is None): self.no_atoms = no_atoms self.delta_energy = delta_energy else: print( 'Error in Get_Interpolation_Data.py, in class Cluster, in def __init__' ) print('Error in Cluster') print('motif: ' + str(motif)) print('motif_details: ' + str(motif_details)) print('element: ' + str(element)) print('local_optimiser: ' + str(local_optimiser)) print('e_coh: ' + str(e_coh)) print('no_atoms: ' + str(no_atoms)) print('delta_energy: ' + str(delta_energy)) exit()
def test_Ar_minimize_multistep(factory, ar_nc, params): ar_nc = Icosahedron('Ar', noshells=2) ar_nc.cell = [[300, 0, 0], [0, 300, 0], [0, 0, 300]] ar_nc.pbc = True with factory.calc(specorder=['Ar'], **params) as calc: ar_nc.calc = calc F1_numer = calc.calculate_numerical_forces(ar_nc) assert_allclose(ar_nc.get_potential_energy(), -0.468147667942117, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), F1_numer, atol=1e-4, rtol=1e-4) params['minimize'] = '1.0e-15 1.0e-6 2000 4000' # add minimize calc.parameters = params # set_atoms=True to read final coordinates after minimization calc.run(set_atoms=True) # get final coordinates after minimization ar_nc.set_positions(calc.atoms.positions) assert_allclose(ar_nc.get_potential_energy(), -0.4791815887032201, atol=1e-4, rtol=1e-4) assert_allclose(ar_nc.get_forces(), calc.calculate_numerical_forces(ar_nc), atol=1e-4, rtol=1e-4)
def ar_nc(): ar_nc = Icosahedron('Ar', noshells=2) ar_nc.cell = [[300, 0, 0], [0, 300, 0], [0, 0, 300]] ar_nc.pbc = True return ar_nc
#!/usr/bin/env python from ase import Atoms, Atom from ase.calculators.aims import Aims, AimsCube from ase.cluster.icosahedron import Icosahedron from ase.io.aims import read_aims from ase.optimize.basin import BasinHopping from ase.optimize import LBFGS import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt atoms = Icosahedron('Pt', noshells=1) calc = Aims(label='cluster/pt-isosahedron-1-bh', xc='pbe', spin='none', relativistic = 'atomic_zora scalar', sc_accuracy_etot=1e-5, sc_accuracy_eev=1e-3, sc_accuracy_rho=1e-4, sc_accuracy_forces=1e-3) atoms.set_calculator(calc) bh = BasinHopping(atoms) bh.run(temperature=100 * kB, # 'temperature' to overcome barriers dr=0.5, # maximal stepwidth optimizer=LBFGS, # optimizer to find local minima fmax=0.1# maximal force for the optimizer )
from ase.calculators.lammpsrun import LAMMPS from ase.cluster.icosahedron import Icosahedron from ase.data import atomic_numbers, atomic_masses from numpy.linalg import norm ar_nc = Icosahedron('Ar', noshells=2) ar_nc.cell = [[300, 0, 0], [0, 300, 0], [0, 0, 300]] ar_nc.pbc = True params = {} params['pair_style'] = 'lj/cut 8.0' params['pair_coeff'] = ['1 1 0.0108102 3.345'] params['mass'] = ['1 {}'.format(atomic_masses[atomic_numbers['Ar']])] calc = LAMMPS(specorder=['Ar'], parameters=params) ar_nc.set_calculator(calc) E = ar_nc.get_potential_energy() F = ar_nc.get_forces() assert abs(E - -0.47) < 1E-2 assert abs(norm(F) - 0.0574) < 1E-4 assert abs(norm(ar_nc.positions) - 23.588) < 1E-3 params['minimize'] = '1.0e-15 1.0e-6 2000 4000' # add minimize calc.params = params # set_atoms=True to read final coordinates after minimization calc.run(set_atoms=True)
def clusters(): yield Icosahedron(sym, 2) yield Octahedron(sym, length=3, cutoff=1) yield Decahedron(sym, 2, 3, 3)
atoms = ase.Atoms('NH2CH3') # Define connectivity. atoms_bonds = [ [0,1], [0,2], [0,3], [3,4], [3,5], [3,6] ] # Displace atoms so that they aren't on top of each other. atoms.rattle(0.001) # Construct VSEPR calculator. calculator = VSEPR(atoms, atoms_bonds) atoms.set_calculator(calculator) atoms.center() # Run optimization. opt = FIRE(atoms) opt.run() return atoms ligand = make_methylamine() nanoparticle = Icosahedron(symbol='Au', noshells=4) nanoparticle.center(20) atoms = add_ligands(nanoparticle, ligand, corner_sites=True, edge_sites=[.5], facet_111_sites=[]) write('POSCAR_Ih', atoms)