def test_unitcellfilterpressure():
    a0 = bulk('Cu', cubic=True)

    # perturb the atoms
    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.calc = LennardJones()
    ucf = UnitCellFilter(atoms, scalar_pressure=10.0 * GPa)

    # test all derivatives
    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.calc = LennardJones()
    ecf = ExpCellFilter(atoms, scalar_pressure=10.0 * GPa)

    # test all deritatives
    f, fn = gradient_test(ecf)
    assert abs(f - fn).max() < 1e-6

    opt = LBFGSLineSearch(ecf)
    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
Exemple #2
0
def change_concentration(ge_concentration=0):
    # Read in 1728 atom system
    atoms = read('structures/1728_atom/aSi.xyz', format='xyz')

    # Swap in Ge atoms
    if ge_concentration != 0:
        symbols = np.array(atoms.get_chemical_symbols())
        n_ge_atoms = int(np.round(ge_concentration * len(symbols), 0))
        rng = np.random.default_rng(seed=random_seed)
        id = rng.choice(len(atoms), size=n_ge_atoms, replace=False)
        symbols[id] = 'Ge'
        atoms.set_chemical_symbols(symbols.tolist())
    ge_concentration = str(int(ge_concentration * 100))
    folder_string = 'structures/1728_atom/aSiGe_C' + str(ge_concentration)
    if not os.path.exists(folder_string):
        os.makedirs(folder_string)

    # Minimize structure - LAMMPS + ASE
    lammps_inputs = {
        'lmpcmds': [
            "pair_style tersoff",
            "pair_coeff * * forcefields/SiCGe.tersoff Si(D) Ge"
        ],
        "log_file":
        "min.log",
        "keep_alive":
        True
    }
    calc = LAMMPSlib(**lammps_inputs)
    atoms.set_calculator(calc)
    atoms.pbc = True
    search = LBFGSLineSearch(atoms)
    search.run(fmax=.001)
    write('structures/1728_atom/aSiGe_C' + str(ge_concentration) +
          '/replicated_atoms.xyz',
          search.atoms,
          format='xyz')
Exemple #3
0
from ase.optimize import LBFGSLineSearch
from ase.constraints import UnitCellFilter

import pyjulip

bulk_at = bulk("Cu", cubic=True)
sigma = (bulk_at * 2).get_distance(0, 1) * (2.**(-1. / 6))
calc = LennardJones(sigma=sigma, epsilon=0.05)

N_cell = 3
at0 = bulk_at * N_cell
del at0[0]

at_ref = at0.copy()
at_ref.set_calculator(calc)
opt = LBFGSLineSearch(at_ref)
opt.run(fmax=1e-6)

at_ref_var_cell = at0.copy()
at_ref_var_cell.set_calculator(calc)
opt = LBFGSLineSearch(UnitCellFilter(at_ref_var_cell))
opt.run(fmax=1e-6)

for variable_cell in [False, True]:
    at = at0.copy()
    at.set_calculator(calc)
    opt = pyjulip.JulipOptimizer(at, variable_cell=variable_cell)
    opt.run(fmax=1e-6)

    if variable_cell:
        assert np.abs(at.positions - at_ref_var_cell.positions).max() < 1e-6
Exemple #4
0
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

opt = LBFGSLineSearch(ecf)
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