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 optimize_lammpslib(struc, lmp, parameters=None, path='tmp', calc_type=None, lmp_file=None, molecule=False, strain=np.ones([3, 3]), method='FIRE', fmax=0.01): if lmp_file is not None: lammps = LAMMPSlib(lmp=lmp, lmp_file=lmp_file, log_file='lammps.log', \ molecule=molecule, path=path) elif calc_type is not None: lammps = LAMMPSlib(lmp=lmp, lmpcmds=parameters, calc_type=calc_type, \ log_file='lammps.log', molecule=molecule, path=path) else: lammps = LAMMPSlib(lmp=lmp, lmpcmds=parameters, log_file='lammps.log', \ molecule=molecule, path=path) struc.set_calculator(lammps) box = mushybox(struc, fixstrain=strain) if method == 'FIRE': dyn = FIRE(box) else: dyn = LBFGS(box) dyn.run(fmax=fmax, steps=500) return struc
def opt_lammpslib(struc, lmp, parameters=None, mask=None, logfile='-', path='tmp', calc_type=None, lmp_file=None, molecule=False, method='FIRE', fmax=0.01, opt_cell=False, a=0.1, steps=500): """ mask: [1, 1, 1, 1, 1, 1], a, b, c, alpha, beta, gamma [1, 1, 0, 0, 0, 1] """ if lmp_file is not None: lammps = LAMMPSlib(lmp=lmp, lmp_file=lmp_file, log_file='lammps.log', \ molecule=molecule, path=path) elif calc_type is not None: lammps = LAMMPSlib(lmp=lmp, lmpcmds=parameters, calc_type=calc_type, \ log_file='lammps.log', molecule=molecule, path=path) else: lammps = LAMMPSlib(lmp=lmp, lmpcmds=parameters, log_file='lammps.log', \ molecule=molecule, path=path) #check_symmetry(si, 1.0e-6, verbose=True) struc.set_calculator(lammps) struc.set_constraint(FixSymmetry(struc)) if opt_cell: ecf = ExpCellFilter(struc, mask) if method == 'FIRE': dyn = FIRE(ecf, logfile=logfile, a=a) else: dyn = LBFGS(ecf, logfile=logfile) else: if method == 'FIRE': dyn = FIRE(struc, logfile=logfile) else: dyn = LBFGS(struc, logfile=logfile) dyn.run(fmax=fmax, steps=steps) return struc
def optimize(atoms, sym=True, box=False, method='FIRE', fmax=0.01, steps=1000, logfile='ase.log'): if sym: atoms.set_constraint(FixSymmetry(atoms)) if box: ecf = ExpCellFilter(atoms) if method == 'FIRE': dyn = FIRE(ecf, logfile=logfile) else: dyn = LBFGS(ecf, logfile=logfile) else: if method == 'FIRE': dyn = FIRE(atoms, logfile=logfile) else: dyn = FIRE(atoms, logfile=logfile) dyn.run(fmax=fmax, steps=steps) atoms.set_constraint() return atoms
def optimize_lammpslib(pbcgb, lmp, parameters, path, method='FIRE', fmax=0.1): lammps = LAMMPSlib(lmp=lmp, lmpcmds=parameters, log_file='lammps.log', path=path) pbcgb.set_calculator(lammps) cell0 = pbcgb.cell fixstrain = np.zeros((3, 3)) fixstrain[2][2] = 1 box = mushybox(pbcgb, fixstrain=fixstrain) if method == 'FIRE': dyn = FIRE(box) else: dyn = BFGS(box) dyn.run(fmax=fmax, steps=500) return pbcgb
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(
at.set_calculator(SubdirCalculator(quip_pot, opt.chdir, opt.calc_args)) if rank == 0: print 'Starting NEB run with %d images' % len(neb.images) if not os.path.exists('%s-initial.xyz' % basename): neb.write('%s-initial.xyz' % basename) if opt.eval: # actually evaluate end forces as well neb.get_forces(all=True) neb.write('%s-eval.xyz' % basename) elif not opt.dry_run: # Optimize: if opt.optimizer == 'FIRE': from ase.optimize.fire import FIRE optimizer = FIRE(neb) elif opt.optimizer == 'MDMin': from ase.optimize import MDMin optimizer = MDMin(neb) else: p.error('Unknown optimizer %s' % opt.optimizer) if opt.write_traj is not None: def write_traj(): global neb n = 0 while os.path.exists('%s-band-%d.xyz' % (basename, n)): n += 1 neb.write('%s-band-%d.xyz' % (basename, n))
'J': 0 }, 'Ir': { 'L': 2, 'U': 3.75, 'J': 1.0 }, 'O': { 'L': -1, 'U': 0, 'J': 0 } }, lmaxmix=4) p1.set_calculator(calc) pstress = p1.get_cell() * 0.0 pstress[2][0] = 3.0 p1box = mushybox(p1, express=pstress) # for ase.3.15 and later dyn = FIRE(p1box, maxmove=0.1, dt=0.1, dtmax=0.1, force_consistent=False) #dyn = MDMin(p1box, dt=0.1, force_consistent = False) # for ase.3.12 and earlier #dyn = FIRE(p1box,maxmove = 0.1, dt = 0.1, dtmax = 0.1) #dyn = MDMin(p1box, dt=0.1) dyn.run(fmax=0.01, steps=100) write("CONTCAR", p, format='vasp')
s = a0.get_scaled_positions() s[:, 0] *= 0.995 a0.set_scaled_positions(s) # perturb the cell a0.cell[...] += np.random.uniform(-1e-2, 1e-2, size=9).reshape((3, 3)) atoms = a0.copy() atoms.set_calculator(LennardJones()) ucf = UnitCellFilter(atoms, scalar_pressure=10.0 * GPa) # test all deritatives f, fn = gradient_test(ucf) assert abs(f - fn).max() < 1e-6 opt = FIRE(ucf) opt.run(1e-3) # check pressure is within 0.1 GPa of target sigma = atoms.get_stress() / GPa pressure = -(sigma[0] + sigma[1] + sigma[2]) / 3.0 assert abs(pressure - 10.0) < 0.1 atoms = a0.copy() atoms.set_calculator(LennardJones()) ecf = ExpCellFilter(atoms, scalar_pressure=10.0 * GPa) # test all deritatives f, fn = gradient_test(ecf) assert abs(f - fn).max() < 1e-6
sg = randint(2, 230) crystal = molecular_crystal(sg, ['H2O'], [randint(1, 4)], 1.0) #, lattice=para) if crystal.valid: struc = Atoms( crystal.spg_struct[2], cell=crystal.spg_struct[0], scaled_positions=crystal.spg_struct[1], ) break #struc = struc.repeat((2,2,2)) lammps = LAMMPSlib(lmp=lmp, lmpcmds=parameters, mol=True) struc.set_calculator(lammps) box = mushybox(struc) dyn = FIRE(box) dyn.run(fmax=0.00, steps=1100) #dyn = BFGS(box) #dyn.run(fmax=0.01, steps=200) #dyn = BFGS(box) #dyn.run(fmax=0.01, steps=200) Eng = struc.get_potential_energy() * 96 / len(struc) * 3 Vol = struc.get_volume() / len(struc) * 3 stress = np.max(struc.get_stress()) struc = sort(struc) try: spg = get_symmetry_dataset(struc, symprec=1e-1)['number'] except: spg = 1
final.positions[2:5] = initial.positions[[3, 4, 2]] # Generate blank images. images = [initial] for i in range(9): images.append(initial.copy()) for image in images: image.calc = EMT() images.append(final) neb = NEB(images, climb=True) neb.interpolate(method='idpp') #idpp插值,设置初猜 # set calculator for atoms in images: atoms.calc = EMT() atoms.get_potential_energy() # Optimize: py_fname = os.path.splitext(sys.argv[0])[0] traj_fname = "{}.traj".format(py_fname) log_fname = "{}.log".format(py_fname) optimizer = FIRE(neb, trajectory=traj_fname, logfile=log_fname) optimizer.run(fmax=0.04) neb_result = list(iread(traj_fname)) for i in neb_result: #print(i.get_potential_energy()) pass neb_result = NEBTools(neb_result) neb_result.plot_bands(True, True, label=py_fname) print(neb_result.get_barrier(), neb_result.get_fmax())
from ase.build import molecule from ase.neb import NEB from ase.calculators.emt import EMT from ase.optimize.fire import FIRE from mlpot.mlneb import run_mla_neb from mlpot.calculators.gprcalculator import GPRCalculator from mlpot.kernels import RBFKernel # Optimise molecule initial = molecule('C2H6') initial.set_calculator(EMT()) relax = FIRE(initial) relax.run(fmax=0.05) # Create final state final = initial.copy() final.positions[2:5] = initial.positions[[3, 4, 2]] # Generate blank images images = [initial] for i in range(9): images.append(initial.copy()) images.append(final) for image in images: image.set_calculator(EMT()) # Run IDPP interpolation neb = NEB(images)
from ase.build import molecule from ase.neb import NEB from ase.calculators.emt import EMT from ase.optimize.fire import FIRE # Optimise molecule initial = molecule('C2H6') initial.set_calculator(EMT()) relax = FIRE(initial) relax.run(fmax=0.05) # Create final state final = initial.copy() final.positions[2:5] = initial.positions[[3, 4, 2]] # Generate blank images images = [initial] for i in range(9): images.append(initial.copy()) images.append(final) for image in images: image.set_calculator(EMT()) # Run IDPP interpolation neb = NEB(images) neb.interpolate('idpp') # Run NEB calculation
from ann import ATOMModel, Ann from ase.io import read from ase.optimize.fire import FIRE p1 = read('au55.xyz', index=0, format='xyz') model = ATOMModel(restore='atom_model', n=55) p1.set_calculator(Ann(atoms=p1, ann_model=model)) opt = FIRE(atoms=p1, maxmove=1.0, dt=0.2, dtmax=1.0, logfile='geo_opt.dat', trajectory='geo_opt.traj') opt.run(fmax=0.05, steps=1000)