Esempio n. 1
0
    def calculate(self, atoms, name):
        args = self.args
        if args.constrain_tags:
            tags = [int(t) for t in args.constrain_tags.split(',')]
            mask = [t in tags for t in atoms.get_tags()]
            atoms.constraints = FixAtoms(mask=mask)
        
        trajectory = PickleTrajectory(self.get_filename(name, 'traj'), 'w',
                                      atoms)
        if args.maximum_stress:
            optimizer = LBFGS(UnitCellFilter(atoms), logfile=self.logfile)
            fmax = args.maximum_stress
        else:
            optimizer = LBFGS(atoms, logfile=self.logfile)
            fmax = args.maximum_force

        optimizer.attach(trajectory)
        optimizer.run(fmax=fmax)

        data = RunCommand.calculate(self, atoms, name)

        if hasattr(optimizer, 'force_calls'):
            data['force calls'] = optimizer.force_calls

        return data
Esempio n. 2
0
def test_unitcellfilter(asap3):
    cu = bulk('Cu') * (6, 6, 6)
    cu.calc = asap3.EMT()
    f = UnitCellFilter(cu, [1, 1, 1, 0, 0, 0])
    opt = LBFGS(f)
    t = Trajectory('Cu-fcc.traj', 'w', cu)
    opt.attach(t)
    opt.run(5.0)
def relax_atoms(atoms,
                tol=1e-3,
                method='lbfgs_precon',
                max_steps=1000,
                traj_file=None,
                **kwargs):
    import model
    atoms.set_calculator(model.calculator)
    if hasattr(model, 'Optimizer'):
        method = 'model_optimizer'
        opt = model.Optimizer(atoms)
        opt.run(tol, max_steps)
    elif method.startswith('lbfgs') or method == 'fire' or method == 'cg_n':
        if method == 'lbfgs_ASE':
            from ase.optimize import LBFGS
            opt = LBFGS(atoms, **kwargs)
        elif method == 'cg_n':
            from quippy import Minim
            opt = Minim(atoms,
                        relax_positions=True,
                        relax_cell=False,
                        method='cg_n')
        else:
            from ase.optimize.precon.precon import Exp
            from ase.optimize.precon.lbfgs import PreconLBFGS
            precon = None
            if method.endswith('precon'):
                precon = Exp(3.0, recalc_mu=True)
            if method.startswith('lbfgs'):
                opt = PreconLBFGS(atoms, precon=precon, **kwargs)
            else:
                opt = FIRE(atoms, **kwargs)
        if traj_file is not None and method != 'cg_n':
            traj = open(traj_file, 'w')

            def write_trajectory():
                write(traj, atoms, format='extxyz')

            opt.attach(write_trajectory)
        opt.run(tol, max_steps)
        try:
            traj.close()
        except:
            pass
    else:
        raise ValueError('unknown method %s!' % method)

    return atoms
Esempio n. 4
0
    def optimize(self, atoms, name):
        args = self.args
        if args.constrain_tags:
            tags = [int(t) for t in args.constrain_tags.split(',')]
            mask = [t in tags for t in atoms.get_tags()]
            atoms.constraints = FixAtoms(mask=mask)

        logfile = self.get_filename(name, 'log')
        if args.maximum_stress:
            optimizer = LBFGS(UnitCellFilter(atoms), logfile=logfile)
            fmax = args.maximum_stress
        else:
            optimizer = LBFGS(atoms, logfile=logfile)
            fmax = args.maximum_force

        trajectory = Trajectory(self.get_filename(name, 'traj'), 'w', atoms)
        optimizer.attach(trajectory)
        optimizer.run(fmax=fmax)
Esempio n. 5
0
    def optimize(self, atoms, name):
        args = self.args
        if args.constrain_tags:
            tags = [int(t) for t in args.constrain_tags.split(',')]
            mask = [t in tags for t in atoms.get_tags()]
            atoms.constraints = FixAtoms(mask=mask)

        trajectory = Trajectory(self.get_filename(name, 'traj'), 'w', atoms)
        if args.maximum_stress:
            optimizer = LBFGS(UnitCellFilter(atoms), logfile=self.logfile)
            fmax = args.maximum_stress
        else:
            optimizer = LBFGS(atoms, logfile=self.logfile)
            fmax = args.maximum_force

        optimizer.attach(trajectory)
        optimizer.run(fmax=fmax)

        data = {}
        if hasattr(optimizer, 'force_calls'):
            data['force_calls'] = optimizer.force_calls

        return data
Esempio n. 6
0
def test_unitcellfilter(asap3):
    a = 3.6
    b = a / 2
    cu = Atoms('Cu', cell=[(0, b, b), (b, 0, b), (b, b, 0)], pbc=1) * (6, 6, 6)
    cu.calc = asap3.EMT()
    f = UnitCellFilter(cu, [1, 1, 1, 0, 0, 0])
    opt = LBFGS(f)
    t = Trajectory('Cu-fcc.traj', 'w', cu)
    opt.attach(t)
    opt.run(5.0)

    # HCP:
    from ase.build import bulk
    cu = bulk('Cu', 'hcp', a=a / sqrt(2))
    cu.cell[1, 0] -= 0.05
    cu *= (6, 6, 3)
    cu.calc = asap3.EMT()
    print(cu.get_forces())
    print(cu.get_stress())
    f = UnitCellFilter(cu)
    opt = MDMin(f, dt=0.01)
    t = Trajectory('Cu-hcp.traj', 'w', cu)
    opt.attach(t)
    opt.run(0.2)
Esempio n. 7
0
def test_unitcellfilter():
    from math import sqrt
    from ase import Atoms
    from ase.optimize import LBFGS
    from ase.constraints import UnitCellFilter
    from ase.io import Trajectory
    from ase.optimize.mdmin import MDMin
    try:
        from asap3 import EMT
    except ImportError:
        pass
    else:
        a = 3.6
        b = a / 2
        cu = Atoms('Cu', cell=[(0, b, b), (b, 0, b),
                               (b, b, 0)], pbc=1) * (6, 6, 6)
        cu.set_calculator(EMT())
        f = UnitCellFilter(cu, [1, 1, 1, 0, 0, 0])
        opt = LBFGS(f)
        t = Trajectory('Cu-fcc.traj', 'w', cu)
        opt.attach(t)
        opt.run(5.0)

        # HCP:
        from ase.build import bulk
        cu = bulk('Cu', 'hcp', a=a / sqrt(2))
        cu.cell[1, 0] -= 0.05
        cu *= (6, 6, 3)
        cu.set_calculator(EMT())
        print(cu.get_forces())
        print(cu.get_stress())
        f = UnitCellFilter(cu)
        opt = MDMin(f, dt=0.01)
        t = Trajectory('Cu-hcp.traj', 'w', cu)
        opt.attach(t)
        opt.run(0.2)
Esempio n. 8
0
from ase.constraints import UnitCellFilter
from ase.io import Trajectory
from ase.optimize.mdmin import MDMin
try:
    from asap3 import EMT
except ImportError:
    pass
else:
    a = 3.6
    b = a / 2
    cu = Atoms('Cu', cell=[(0, b, b), (b, 0, b), (b, b, 0)], pbc=1) * (6, 6, 6)
    cu.set_calculator(EMT())
    f = UnitCellFilter(cu, [1, 1, 1, 0, 0, 0])
    opt = LBFGS(f)
    t = Trajectory('Cu-fcc.traj', 'w', cu)
    opt.attach(t)
    opt.run(5.0)

    # HCP:
    from ase.build import hcp0001
    cu = hcp0001('Cu', (1, 1, 2), a=a / sqrt(2))
    cu.cell[1, 0] += 0.05
    cu *= (6, 6, 3)
    cu.set_calculator(EMT())
    print(cu.get_forces())
    print(cu.get_stress())
    f = UnitCellFilter(cu)
    opt = MDMin(f, dt=0.01)
    t = Trajectory('Cu-hcp.traj', 'w', cu)
    opt.attach(t)
    opt.run(0.2)
Esempio n. 9
0
        str(d.get_number_of_steps()) + ' ' + str(d.get_time()) + ' ' +
        str(ekin / (1.5 * units.kB)) + ' ' + str(epot) + ' ' + str(ekin) +
        ' ' + str(epot + ekin) + '\n')

    if d.get_number_of_steps() > 0:
        b.write(
            str(len(a)) + '\n       Temp: ' + str(T) + ' Step: ' +
            str(d.get_number_of_steps()) + '\n')
        c = a.get_positions(wrap=True)
        for j, i in zip(a, c):
            b.write(
                str(j.symbol) + ' ' + str(i[0]) + ' ' + str(i[1]) + ' ' +
                str(i[2]) + '\n')


dyn.attach(printenergy, interval=50)
#dyn.attach(MDLogger(dyn, bz, 'bz_md_NVT_10ps_1fs.log', header=True, stress=False,
#           peratom=False, mode="w"), interval=50)

#traj = Trajectory('killerapp.traj', 'w', atoms=bz)
#dyn.attach(traj.write, interval=100)

printenergy()

dyn.set_temperature(300.0 * units.kB)
start_time2 = time.time()
dyn.run(20000)  # Do 5ps of MD
end_time2 = time.time()
print('Post-heat Total Time:', end_time2 - start_time2)

#dyn = LBFGS(bz)
Esempio n. 10
0
from ase.optimize.mdmin import MDMin
try:
    from asap3 import EMT
except ImportError:
    pass
else:
    a = 3.6
    b = a / 2
    cu = Atoms('Cu',
               cell=[(0, b, b), (b, 0, b), (b, b, 0)],
               pbc=1) * (6, 6, 6)
    cu.set_calculator(EMT())
    f = UnitCellFilter(cu, [1, 1, 1, 0, 0, 0])
    opt = LBFGS(f)
    t = Trajectory('Cu-fcc.traj', 'w', cu)
    opt.attach(t)
    opt.run(5.0)

    # HCP:
    from ase.build import hcp0001
    cu = hcp0001('Cu', (1, 1, 2), a=a / sqrt(2))
    cu.cell[1, 0] += 0.05
    cu *= (6, 6, 3)
    cu.set_calculator(EMT())
    print(cu.get_forces())
    print(cu.get_stress())
    f = UnitCellFilter(cu)
    opt = MDMin(f, dt=0.01)
    t = Trajectory('Cu-hcp.traj', 'w', cu)
    opt.attach(t)
    opt.run(0.2)