示例#1
0
 def calculate(self, filename):
     """Run calculation and write results to file."""
     self.log('Calculating', self.name, '...')
     config = self.atoms.copy()
     self.set_calculator(config, filename)
     traj = PickleTrajectory(filename, 'w', backup=False)
     cell = config.get_cell()
     self.energies = []
     if self.fmax is not None:
         if (not config.constraints and
             not config.positions.any(axis=1).all()):
             # one atom is at (0,0,0) - fix it:
             mask = np.logical_not(config.positions.any(axis=1))
             config.constraints = FixAtoms(mask=mask)
         dyn = LBFGS(config)
         dyn.attach(traj, 1, config)
         dyn.run(fmax=self.fmax)
         e = config.get_potential_energy()
         self.post_process(config)
         self.energies.append(e)
     elif not config.pbc.any() and len(config) == 2:
         # This is a dimer.
         self.bondlengths = []
         d0 = config.get_distance(0, 1)
         for strain in self.strains:
             d = d0 * strain
             config.set_distance(0, 1, d)
             self.bondlengths.append(d)
             e = config.get_potential_energy()
             self.energies.append(e)
             self.post_process(config)
             traj.write(config)
     else:
         self.volumes = []
         for strain in self.strains:
             config.set_cell(strain * cell, scale_atoms=True)
             self.volumes.append(config.get_volume())
             e = config.get_potential_energy()
             self.energies.append(e)
             self.post_process(config)
             traj.write(config)
     return config
示例#2
0
from ase.io import PickleTrajectory
from ase.optimize.lbfgs import LBFGS
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 = PickleTrajectory('Cu-fcc.traj', 'w', cu)
    opt.attach(t)
    opt.run(5.0)

    # HCP:
    from ase.lattice.surface 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 = PickleTrajectory('Cu-hcp.traj', 'w', cu)
    opt.attach(t)
    opt.run(0.2)
示例#3
0
from ase.io import Trajectory
from ase.optimize.lbfgs import LBFGS
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.lattice.surface 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)