from ase_ext import Atom, Atoms
from ase_ext.calculators.lj import LennardJones
from ase_ext.constraints import FixBondLength

dimer = Atoms([Atom('X',
                    (0, 0, 0)), Atom('X', (0, 0, 1))],
              calculator=LennardJones(),
              constraint=FixBondLength(0, 1))
print(dimer.get_forces())
print(dimer.positions)
dimer.positions[:] += 0.1
print(dimer.positions)
dimer.positions[:, 2] += 5.1
print(dimer.positions)
dimer.positions[:] = [(1, 2, 3), (4, 5, 6)]
print(dimer.positions)
dimer.set_positions([(1, 2, 3), (4, 5, 6.2)])
print(dimer.positions)
from ase_ext.optimize.lbfgs import LBFGS
from ase_ext.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_ext.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)
import numpy as np
from ase_ext import Atoms
from ase_ext.units import fs
from ase_ext.calculators.test import TestPotential
from ase_ext.calculators.emt import EMT
from ase_ext.md import VelocityVerlet
from ase_ext.io import PickleTrajectory, read
from ase_ext.optimize import QuasiNewton

np.seterr(all='raise')
a = Atoms('4X',
          masses=[1, 2, 3, 4],
          positions=[(0, 0, 0), (1, 0, 0), (0, 1, 0), (0.1, 0.2, 0.7)],
          calculator=TestPotential())
print(a.get_forces())
md = VelocityVerlet(a, dt=0.5 * fs, logfile='-', loginterval=500)
traj = PickleTrajectory('4N.traj', 'w', a)
md.attach(traj.write, 100)
e0 = a.get_total_energy()
md.run(steps=10000)
del traj
assert abs(read('4N.traj').get_total_energy() - e0) < 0.0001

qn = QuasiNewton(a)
qn.run(0.001)
assert abs(a.get_potential_energy() - 1.0) < 0.000002
Exemple #4
0
from ase_ext import Atoms
from ase_ext.calculators.emt import EMT

h2 = Atoms('H2', positions=[(0, 0, 0), (0, 0, 1.1)], calculator=EMT())
print(h2.calc.get_numeric_forces(h2))
print(h2.get_forces())