Example #1
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')
    def create_child_from(self, parent):
      child = parent.copy()
      calc = EMT()
      child.set_calculator(calc)
      if (random.random() > 0.25):
        child.rattle(0.02, random.randint(0, 50))
      else:
        child.rattle(0.2, random.randint(0, 50))
      dyn = LBFGSLineSearch(atoms=child)
      dyn.run(steps=20000)
      dyn = FIRE(atoms=child)
      dyn.run(fmax=0.05)

      return child
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
Example #4
0
def genParticle(definingString, number):
    """definingString should be something like " 'Pt80' ", for example.
  number should be the number of atoms that will be in the molecule."""
    dummyAtom = ase.io.read("InputGeom.vasp", format="vasp")
    while len(dummyAtom) > number:
        dummyAtom.pop(-1)
    coords = dummyAtom.get_positions().tolist()
    shuffledCoords = []
    while len(coords) > 0:  # THIS IS SCREWED UP!
        R = random.randint(0, len(coords) - 1)
        item = coords.pop(R)
        shuffledCoords.append(item)
    newAtom = Atoms(definingString, shuffledCoords)
    calc = EMT()
    newAtom.set_calculator(calc)
    newAtom.set_cell(dummyAtom.get_cell() * 10.0)
    dyn = LBFGSLineSearch(atoms=newAtom)
    dyn.run(steps=20000)
    dyn = FIRE(atoms=newAtom)
    dyn.run(fmax=0.05)
    return newAtom
Example #5
0
def nearlySphericalAtom(definingString, inRadius, number):
    """definingString should be something like " 'Pt80' ", for example.
  inRadius should be the radius that you wish to have for the atom.
  number should be the number of atoms that will be in the molecule."""
    positionList = []
    for x in range(number):
        xDistance = random.uniform(0, inRadius) * plusOrMinus()
        remainingX = ((inRadius ** 2) - (xDistance ** 2)) ** 0.5
        yDistance = random.uniform(0, remainingX) * plusOrMinus()
        zDistance = random.uniform(
            0, (((remainingX ** 2) - (yDistance ** 2)) ** 0.5) * plusOrMinus() + random.normal(0, 0.1)
        )
        coordinates = (xDistance, yDistance, zDistance)
        positionList.append(coordinates)
    newAtom = Atoms(definingString, positionList)
    calc = EMT()
    newAtom.set_calculator(calc)
    dyn = LBFGSLineSearch(atoms=newAtom)
    dyn.run(steps=200000)
    dyn = FIRE(atoms=newAtom)
    dyn.run(fmax=0.01)
    return newAtom
Example #6
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
Example #7
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