Example #1
0
    def run(self, calc, filename):
        """
        Runs NEB calculations.
        Parameters
        ----------
        calc: object. Calculator to be used to run method.
        filename: str. Label to save generated trajectory files."""

        initial = self.starting_images[0].copy()
        final = self.starting_images[-1].copy()
        if self.ml2relax:
            # Relax initial and final images
            ml_initial = initial
            ml_initial.set_calculator(calc)
            ml_final = final
            ml_final.set_calculator(calc)
            print("BUILDING INITIAL")
            qn = BFGS(ml_initial,
                      trajectory="initial.traj",
                      logfile="initial_relax_log.txt")
            qn.run(fmax=0.01, steps=100)
            print("BUILDING FINAL")
            qn = BFGS(ml_final,
                      trajectory="final.traj",
                      logfile="final_relax_log.txt")
            qn.run(fmax=0.01, steps=100)
            initial = ml_initial.copy()
            final = ml_final.copy()

        initial.set_calculator(calc)
        final.set_calculator(calc)

        images = [initial]
        for i in range(self.intermediate_samples):
            image = initial.copy()
            image.set_calculator(calc)
            images.append(image)
        images.append(final)

        print("NEB BEING BUILT")
        neb = SingleCalculatorNEB(images)
        neb.interpolate()
        print("NEB BEING OPTIMISED")
        opti = BFGS(neb,
                    trajectory=filename + ".traj",
                    logfile="al_neb_log.txt")
        opti.run(fmax=0.01, steps=100)
        print("NEB DONE")
        """
      The following code is used to visualise the NEB at every iteration
      """

        built_neb = NEBTools(images)
        barrier, dE = built_neb.get_barrier()
        # max_force = built_neb.get_fmax()
        # fig = built_neb.plot_band()
        plt.show()
Example #2
0
    def run(self, calc, filename):
        """
        Runs NEB calculations.
        Parameters
        ----------
        calc: object. Calculator to be used to run method.
        filename: str. Label to save generated trajectory files."""

        initial = self.starting_images[0].copy()
        final = self.starting_images[-1].copy()
        # Relax initial and final images
        ml_initial = initial
        ml_initial.set_calculator(calc)
        ml_final = final
        ml_final.set_calculator(calc)
        print("BUILDING INITIAL")
        qn = BFGS(ml_initial,
                  trajectory="initial.traj",
                  logfile="initial_relax_log.txt")
        qn.run(fmax=0.01, steps=100)
        print("BUILDING FINAL")
        qn = BFGS(ml_final,
                  trajectory="final.traj",
                  logfile="final_relax_log.txt")
        qn.run(fmax=0.01, steps=100)
        initial = ml_initial.copy()
        final = ml_final.copy()

        initial.set_calculator(calc)
        final.set_calculator(calc)

        images = [initial]
        for i in range(self.intermediate_samples):
            image = initial.copy()
            image.set_calculator(calc)
            images.append(image)
        images.append(final)

        print("NEB BEING BUILT")
        neb = SingleCalculatorNEB(images)
        neb.interpolate()
        print("NEB BEING OPTIMISED")
        opti = BFGS(neb,
                    trajectory=filename + ".traj",
                    logfile="al_neb_log.txt")
        opti.run(fmax=0.01, steps=100)
        print("NEB DONE")
Example #3
0
def neural_neb_ase(reactantxyzfile,
                   productxyzfile,
                   nff_dir,
                   rxn_name,
                   steps=500,
                   n_images=24,
                   fmax=0.004,
                   isclimb=False):

    #reactant and products as ase Atoms
    initial = AtomsBatch(xyz_to_ase_atoms(reactantxyzfile),
                         cutoff=5.5,
                         nbr_torch=True,
                         directed=True)

    final = AtomsBatch(xyz_to_ase_atoms(productxyzfile),
                       cutoff=5.5,
                       nbr_torch=True,
                       directed=True)

    # Make a band consisting of n_images:
    images = [initial]
    images += [initial.copy() for i in range(n_images)]
    images += [final]
    neb = SingleCalculatorNEB(images, k=0.02, climb=isclimb)
    neb.method = 'improvedtangent'

    # Interpolate linearly the potisions of the n_images:
    neb.interpolate()
    neb.idpp_interpolate(optimizer=BFGS, steps=steps)

    images = read('idpp.traj@-{}:'.format(str(n_images + 2)))

    # # Set calculators:
    nff_ase = NeuralFF.from_file(nff_dir, device='cuda:0')
    neb.set_calculators(nff_ase)

    # # Optimize:
    optimizer = BFGS(neb, trajectory='{}/{}.traj'.format(nff_dir, rxn_name))
    optimizer.run(fmax=fmax, steps=steps)

    # Read NEB images from File
    images = read('{}/{}.traj@-{}:'.format(nff_dir, rxn_name,
                                           str(n_images + 2)))

    return images
Example #4
0
dyn.run(fmax=0.05)
#view(initial)

# create final
final = initial.copy()
final.set_calculator(EMT())
final.set_constraint(constraint)
final[-2].position = final[-1].position
final[-1].x = d
final[-1].y = d / sqrt(3)
dyn = Optimizer(final)
dyn.run(fmax=0.1)
#view(final)

# create 2 intermediate step neb
neb = SingleCalculatorNEB([initial, final])
neb.refine(2)
neb.set_calculators(EMT())
assert neb.n() == 4

dyn = Optimizer(neb, maxstep=0.04, trajectory='mep_2coarse.traj')
dyn.run(fmax=0.1)
#dyn.run(fmax=39.1)

# read from the trajectory
neb = SingleCalculatorNEB('mep_2coarse.traj@-4:')

# refine in the important region
neb.refine(2, 1, 3)
neb.set_calculators(EMT())
dyn = Optimizer(neb, maxstep=0.04, trajectory='mep_2fine.traj')
Example #5
0

def set_calculators(all=False):
    c = GPAW(h=.3,
             convergence={
                 'eigenstates': 0.1,
                 'energy': 0.1,
                 'density': 0.01
             },
             txt=txt)
    #    c = EMT()
    n = len(images)
    if not all:
        n -= 2
    neb.set_calculators([c] * n)


images = [mol]
for i in range(4):
    images.append(images[0].copy())
images[-1].positions[2, 1] = 2 - images[0].positions[2, 1]
neb = SingleCalculatorNEB(images)
neb.interpolate()
for image in images:
    print(image[2].position)
set_calculators(True)

dyn = FIRE(neb, trajectory='mep.traj')
dyn.insert_observer(set_calculators)
print(dyn.run(fmax=8.))
Example #6
0
dyn.run(fmax=0.05)
#view(initial)

# create final
final = initial.copy()
final.set_calculator(EMT())
final.set_constraint(constraint)
final[-2].position = final[-1].position
final[-1].x = d
final[-1].y = d / sqrt(3)
dyn = Optimizer(final)
dyn.run(fmax=0.1)
#view(final)

# create 2 intermediate step neb
neb = SingleCalculatorNEB([initial, final])
neb.refine(2)
neb.set_calculators(EMT())
assert neb.n() == 4

dyn = Optimizer(neb, maxstep=0.04, trajectory='mep_2coarse.traj')
dyn.run(fmax=0.1)
#dyn.run(fmax=39.1)

# read from the trajectory
neb = SingleCalculatorNEB('mep_2coarse.traj@-4:')

# refine in the important region
neb.refine(2, 1, 3)
neb.set_calculators(EMT())
dyn = Optimizer(neb, maxstep=0.04, trajectory='mep_2fine.traj')
Example #7
0
mol = Cluster([Atom('H'),
               Atom('H',[1,0,0]),
               Atom('H',[.5,.5,.5])],
              cell = [2,2,2],
              pbc=True)

def set_calculators(all=False):
    c=GPAW(h=.3, convergence={'eigenstates':0.1, 
                              'energy' : 0.1,
                              'density' : 0.01}, txt=txt)
#    c = EMT()
    n = len(images)
    if not all:
        n -= 2
    neb.set_calculators([c] * n)

images = [mol]
for i in range(4):
    images.append(images[0].copy())
images[-1].positions[2, 1] = 2 - images[0].positions[2, 1]
neb = SingleCalculatorNEB(images)
neb.interpolate()
for image in images:
    print(image[2].position)
set_calculators(True)

dyn = FIRE(neb, trajectory='mep.traj')
dyn.insert_observer(set_calculators)
print(dyn.run(fmax=8.))
Example #8
0
dyn.run(fmax=0.05)
# view(initial)

print('Relax final image')
final = initial.copy()
final.set_calculator(EMT())
final.set_constraint(constraint)
final[-2].position = final[-1].position
final[-1].x = d
final[-1].y = d / sqrt(3)
dyn = Optimizer(final)
dyn.run(fmax=0.1)
# view(final)

print('Create neb with 2 intermediate steps')
neb = SingleCalculatorNEB([initial, final])
neb.refine(2)
assert neb.n() == 4

print('Optimize neb using a single calculator')
neb.set_calculators(EMT())
# print('0001', id(neb.images[0]), id(neb.images[0].get_calculator().atoms))
dyn = Optimizer(neb, maxstep=0.04, trajectory='mep_2coarse.traj')
dyn.run(fmax=0.1)
# dyn.run(fmax=39.1)

print('Optimize neb using a many calculators')
neb = SingleCalculatorNEB([initial, final])
neb.refine(2)
neb.set_calculators([EMT() for i in range(neb.n())])
dyn = Optimizer(neb, maxstep=0.04, trajectory='mep_2coarse.traj')
Example #9
0
def test_COCu111_2():
    Optimizer = BFGS

    # Distance between Cu atoms on a (111) surface:
    a = 3.6
    d = a / sqrt(2)
    fcc111 = Atoms(symbols='Cu',
                   cell=[(d, 0, 0), (d / 2, d * sqrt(3) / 2, 0),
                         (d / 2, d * sqrt(3) / 6, -a / sqrt(3))],
                   pbc=True)
    initial = fcc111 * (2, 2, 4)
    initial.set_cell([2 * d, d * sqrt(3), 1])
    initial.set_pbc((1, 1, 0))
    initial.calc = EMT()
    Z = initial.get_positions()[:, 2]
    indices = [i for i, z in enumerate(Z) if z < Z.mean()]
    constraint = FixAtoms(indices=indices)
    initial.set_constraint(constraint)

    print('Relax initial image')
    dyn = Optimizer(initial)
    dyn.run(fmax=0.05)
    Z = initial.get_positions()[:, 2]
    print(Z[0] - Z[1])
    print(Z[1] - Z[2])
    print(Z[2] - Z[3])

    b = 1.2
    h = 1.5
    initial += Atom('C', (d / 2, -b / 2, h))
    initial += Atom('O', (d / 2, +b / 2, h))
    dyn = Optimizer(initial)
    dyn.run(fmax=0.05)
    # view(initial)

    print('Relax final image')
    final = initial.copy()
    final.calc = EMT()
    final.set_constraint(constraint)
    final[-2].position = final[-1].position
    final[-1].x = d
    final[-1].y = d / sqrt(3)
    dyn = Optimizer(final)
    dyn.run(fmax=0.1)
    # view(final)

    print('Create neb with 2 intermediate steps')
    neb = SingleCalculatorNEB([initial, final])
    neb.refine(2)
    assert neb.n() == 4

    print('Optimize neb using a single calculator')
    neb.set_calculators(EMT())
    # print('0001', id(neb.images[0]), id(neb.images[0].calc.atoms))
    dyn = Optimizer(neb, maxstep=0.04, trajectory='mep_2coarse.traj')
    dyn.run(fmax=0.1)
    # dyn.run(fmax=39.1)

    print('Optimize neb using a many calculators')
    neb = SingleCalculatorNEB([initial, final])
    neb.refine(2)
    neb.set_calculators([EMT() for i in range(neb.n())])
    dyn = Optimizer(neb, maxstep=0.04, trajectory='mep_2coarse.traj')
    dyn.run(fmax=0.1)
    # dyn.run(fmax=39.1)

    # read from the trajectory
    neb = SingleCalculatorNEB('mep_2coarse.traj', index='-4:')

    # refine in the important region
    neb.refine(2, 1, 3)
    neb.set_calculators(EMT())
    print('Optimize refined neb using a single calculator')
    dyn = Optimizer(neb, maxstep=0.04, trajectory='mep_2fine.traj')
    dyn.run(fmax=0.1)
    assert len(neb.images) == 8