Example #1
0
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
Example #2
0
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
Example #3
0
def ase_saddle(embedder,
               coords,
               atomnos,
               constrained_indexes=None,
               mols_graphs=None,
               title='temp',
               logfile=None,
               traj=None,
               freq=False,
               maxiterations=200):
    '''
    Runs a first order saddle optimization through the ASE package
    '''
    atoms = Atoms(atomnos, positions=coords)

    atoms.calc = get_ase_calc(embedder)

    t_start = time.perf_counter()
    with HiddenPrints():
        with Sella(atoms, logfile=None, order=1, trajectory=traj) as opt:

            opt.run(fmax=0.05, steps=maxiterations)
            iterations = opt.nsteps

    if logfile is not None:
        t_end_berny = time.perf_counter()
        elapsed = t_end_berny - t_start
        exit_str = 'converged' if iterations < maxiterations else 'stopped'
        logfile.write(
            f'{title} - {exit_str} in {iterations} steps ({time_to_string(elapsed)})\n'
        )

    new_structure = atoms.get_positions()
    energy = atoms.get_total_energy() * 23.06054194532933  #eV to kcal/mol

    if mols_graphs is not None:
        success = scramble_check(new_structure,
                                 atomnos,
                                 constrained_indexes,
                                 mols_graphs,
                                 max_newbonds=embedder.options.max_newbonds)
    else:
        success = molecule_check(coords,
                                 new_structure,
                                 atomnos,
                                 max_newbonds=embedder.options.max_newbonds)

    return new_structure, energy, success
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)
Example #5
0
import os
from ase.calculators.vasp.vasp2 import Vasp2 as vasp_calculator
from ase.io import read

from sella import Sella

atoms = read('path to transitions state CONTCAR')

calc = vasp_calculator(istart=1,
                       prec='Accurate',
                       encut=400,
                       xc='PBE',
                       lcharg=False,
                       directory='path to sell run folder')

atoms.set_calculator(calc)

dyn = Sella(atoms, trajectory='test_vasp2.traj')

dyn.run(1e-3, 1000)
Example #6
0
                           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()