def test_morse_cluster(internal, order, trajectory=None): rng = np.random.RandomState(4) nat = 4 atoms = Atoms(['Xe'] * nat, rng.normal(size=(nat, 3), scale=3.0)) # parameters from DOI: 10.1515/zna-1987-0505 atoms.calc = MorsePotential(alpha=226.9 * kB, r0=4.73, rho0=4.73 * 1.099) cons = Constraints(atoms) cons.fix_translation() cons.fix_rotation() opt = Sella( atoms, order=order, internal=internal, trajectory=trajectory, gamma=1e-3, constraints=cons, ) opt.run(fmax=1e-3) Ufree = opt.pes.get_Ufree() np.testing.assert_allclose(opt.pes.get_g() @ Ufree, 0, atol=5e-3) opt.pes.diag(gamma=1e-16) H = opt.pes.get_HL().project(Ufree) assert np.sum(H.evals < 0) == order, H.evals
def test_water_dimer(internal, order): internal = True order = 0 rng = np.random.RandomState(1) atoms = atoms_ref.copy() atoms.calc = TIP3P() atoms.rattle(0.01, rng=rng) nwater = len(atoms) // 3 cons = Constraints(atoms) for i in range(nwater): cons.fix_bond((3 * i, 3 * i + 1), target=rOH) cons.fix_bond((3 * i, 3 * i + 2), target=rOH) cons.fix_angle((3 * i + 1, 3 * i, 3 * i + 2), target=angleHOH) # Remove net translation and rotation try: cons.fix_translation() except DuplicateConstraintError: pass try: cons.fix_rotation() except DuplicateConstraintError: pass sella_kwargs = dict( order=order, trajectory='test.traj', eta=1e-6, delta0=1e-2, ) if internal: sella_kwargs['internal'] = Internals(atoms, cons=cons, allow_fragments=True) else: sella_kwargs['constraints'] = cons opt = Sella(atoms, **sella_kwargs) opt.delta = 0.05 opt.run(fmax=1e-3) print("First run done") atoms.rattle() opt.run(fmax=1e-3) Ufree = opt.pes.get_Ufree() g = opt.pes.get_g() @ Ufree np.testing.assert_allclose(g, 0, atol=1e-3) opt.pes.diag(gamma=1e-16) H = opt.pes.get_HL().project(Ufree) assert np.sum(H.evals < 0) == order, H.evals
from ase.optimize import QuasiNewton from sella import Sella, Constraints # Set up your system as an ASE atoms object test = Atoms([Atom('Cu', [0, 0, 0]), Atom('Cu', [2, 2, 2])]) test.set_cell([20, 20, 20]) test.set_pbc(True) # Optionally, create and populate a Constraints object. #cons = Constraints(slab) #for atom in slab: # if atom.position[2] < slab.cell[2, 2] / 2.: # cons.fix_translation(atom.index) # Set up your calculator test.calc = EMT() # Optimize system #opt = QuasiNewton(test) #opt.run() # Set up a Sella Dynamics object py_fname = os.path.splitext(sys.argv[0])[0] dyn = Sella( test, #constraints=cons, trajectory='{}.traj'.format(py_fname), ) dyn.run(1e-3, 1000)
label=prefix) # kpts={repeats}, # jobs_args='-nk {n_kpts}', balsamcalc_module = __import__('pynta.balsamcalc', fromlist=[socket_calculator]) sock_calc = getattr(balsamcalc_module, socket_calculator) ts_atom.calc = sock_calc(workflow='QE_Socket', job_kwargs=balsam_exe_settings, **calc_keywords) ts_atom.calc.set(**extra_calc_keywords) opt = Sella(ts_atom, order=1, delta0=1e-2, gamma=1e-3, trajectory=trajdir) opt.run(fmax=0.01, steps=70) ts_atom.calc.close() write_dir = os.path.join(prefix, prefix + '_' + facetpath + '_' + rxn_name) write(write_dir + '_ts_final.png', read(trajdir)) write(write_dir + '_ts_final.xyz', read(trajdir)) end = datetime.datetime.now() with open(label + '_time.log', 'a+') as f: f.write(str(end)) f.write("\n") f.write(str(end - start)) f.write("\n") f.close()