Coverage for ase / optimize / test / neb.py: 20.00%

30 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-04 10:20 +0000

1from ase.build import add_adsorbate, fcc100 

2from ase.calculators.emt import EMT 

3from ase.constraints import FixAtoms 

4from ase.mep import NEB 

5from ase.optimize import QuasiNewton 

6 

7 

8def main(): 

9 # 2x2-Al(001) surface with 3 layers and an 

10 # Au atom adsorbed in a hollow site: 

11 slab = fcc100('Al', size=(2, 2, 3)) 

12 add_adsorbate(slab, 'Au', 1.7, 'hollow') 

13 slab.center(axis=2, vacuum=4.0) 

14 

15 # Fix second and third layers: 

16 mask = [atom.tag > 1 for atom in slab] 

17 slab.set_constraint(FixAtoms(mask=mask)) 

18 

19 # Use EMT potential: 

20 slab.calc = EMT() 

21 

22 # Initial state: 

23 qn = QuasiNewton(slab, logfile=None) 

24 qn.run(fmax=0.05) 

25 initial = slab.copy() 

26 

27 # Final state: 

28 slab[-1].x += slab.get_cell()[0, 0] / 2 

29 qn = QuasiNewton(slab, logfile=None) 

30 qn.run(fmax=0.05) 

31 final = slab.copy() 

32 

33 # Setup a NEB calculation 

34 constraint = FixAtoms(mask=[atom.tag > 1 for atom in initial]) 

35 

36 images = [initial] 

37 for _ in range(3): 

38 image = initial.copy() 

39 image.set_constraint(constraint) 

40 images.append(image) 

41 

42 images.append(final) 

43 

44 neb = NEB(images) 

45 neb.interpolate() 

46 

47 for image in neb.images[1:-1]: 

48 image.calc = EMT() 

49 

50 

51if __name__ == '__main__': 

52 main()