File: fire.py

package info (click to toggle)
python-ase 3.17.0-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 16,340 kB
  • sloc: python: 117,348; makefile: 91
file content (40 lines) | stat: -rwxr-xr-x 749 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import numpy as np

from ase.calculators.emt import EMT
from ase.build import bulk
from ase.optimize import FIRE

a = bulk('Au')
a *= (2, 2, 2)

a[0].x += 0.5

a.set_calculator(EMT())

opt = FIRE(a, dtmax=1.0, dt=1.0, maxmove=100.0, downhill_check=False)
opt.run(fmax=0.001)
e1 = a.get_potential_energy()
n1 = opt.nsteps

a = bulk('Au')
a *= (2, 2, 2)

a[0].x += 0.5

a.set_calculator(EMT())

reset_history = []


def callback(a, r, e, e_last):
    reset_history.append([e - e_last])

opt = FIRE(a, dtmax=1.0, dt=1.0, maxmove=100.0, downhill_check=True,
           position_reset_callback=callback)
opt.run(fmax=0.001)
e2 = a.get_potential_energy()
n2 = opt.nsteps

assert abs(e1 - e2) < 1e-6
assert n2 < n1
assert (np.array(reset_history) > 0).all