Coverage for ase/optimize/test/systems.py: 16.07%

56 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-11-27 15:21 +0000

1from math import cos, pi, sin 

2 

3from ase import Atoms 

4from ase.build import add_adsorbate, fcc100, fcc111 

5from ase.cluster import wulff_construction 

6from ase.constraints import FixAtoms 

7from ase.db import connect 

8from ase.lattice.cubic import FaceCenteredCubic 

9 

10 

11def get_systems(): 

12 systems = [] 

13 

14 cell = (5, 5, 5) 

15 atoms = Atoms('H2', [(0, 0, 0), (0, 0, 1.4)], cell=cell) 

16 atoms.center() 

17 systems.append((atoms, 'Hydrogen molecule')) 

18 

19 atoms = FaceCenteredCubic( 

20 directions=[[1, -1, 0], [1, 1, 0], [0, 0, 1]], 

21 size=(2, 2, 2), 

22 symbol='Cu', 

23 pbc=(1, 1, 1), 

24 ) 

25 atoms.rattle(stdev=0.1, seed=42) 

26 systems.append((atoms, 'Shaken bulk copper')) 

27 

28 a = 2.70 

29 c = 1.59 * a 

30 

31 slab = Atoms( 

32 '2Cu', 

33 [(0.0, 0.0, 0.0), (1 / 3.0, 1 / 3.0, -0.5 * c)], 

34 tags=(0, 1), 

35 pbc=(1, 1, 0), 

36 ) 

37 slab.set_cell([(a, 0, 0), (a / 2, 3**0.5 * a / 2, 0), (0, 0, 1)]) 

38 slab.center(vacuum=3, axis=2) 

39 mask = [a.tag == 1 for a in slab] 

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

41 systems.append((slab, 'Distorted Cu(111) surface')) 

42 

43 zpos = cos(134.3 / 2.0 * pi / 180.0) * 1.197 

44 xpos = sin(134.3 / 2.0 * pi / 180.0) * 1.19 

45 co = Atoms( 

46 'CO', positions=[(-xpos + 1.2, 0, -zpos), (-xpos + 1.2, -1.1, -zpos)] 

47 ) 

48 slab = fcc111('Au', size=(2, 2, 2), orthogonal=True) 

49 add_adsorbate(slab, co, 1.5, 'bridge') 

50 slab.center(vacuum=6, axis=2) 

51 slab.set_pbc((True, True, False)) 

52 constraint = FixAtoms(mask=[a.tag == 2 for a in slab]) 

53 slab.set_constraint(constraint) 

54 systems.append((slab, 'CO on Au(111) surface')) 

55 

56 atoms = Atoms( 

57 symbols='C5H12', 

58 cell=[16.83752497, 12.18645905, 11.83462179], 

59 positions=[ 

60 [5.90380523, 5.65545388, 5.91569796], 

61 [7.15617518, 6.52907738, 5.91569796], 

62 [8.41815022, 5.66384716, 5.92196554], 

63 [9.68108996, 6.52891016, 5.91022362], 

64 [10.93006206, 5.65545388, 5.91569796], 

65 [5.00000011, 6.30002353, 5.9163716], 

66 [5.88571848, 5.0122839, 6.82246859], 

67 [5.88625613, 5.01308931, 5.01214155], 

68 [7.14329342, 7.18115393, 6.81640316], 

69 [7.14551332, 7.17200869, 5.00879027], 

70 [8.41609966, 5.00661165, 5.02355167], 

71 [8.41971183, 5.0251482, 6.83462168], 

72 [9.69568096, 7.18645894, 6.8078633], 

73 [9.68914668, 7.16663649, 5.00000011], 

74 [10.95518898, 5.02163182, 6.8289018], 

75 [11.83752486, 6.29836826, 5.90274952], 

76 [10.94464142, 5.00000011, 5.01802495], 

77 ], 

78 ) 

79 systems.append((atoms, 'Pentane molecule')) 

80 

81 slab = fcc100('Cu', size=(2, 2, 2), vacuum=3.5) 

82 add_adsorbate(slab, 'C', 1.5, 'hollow') 

83 mask = [a.tag > 1 for a in slab] 

84 constraint = FixAtoms(mask=mask) 

85 slab.set_constraint(constraint) 

86 systems.append((slab, 'C/Cu(100)')) 

87 

88 surfaces = [(1, 0, 0), (1, 1, 0), (1, 1, 1)] 

89 esurf = [0.9151, 0.9771, 0.7953] # Surface energies 

90 size = 10 # number of atoms 

91 atoms = wulff_construction( 

92 'Al', surfaces, esurf, size, 'fcc', rounding='above' 

93 ) 

94 atoms.center(vacuum=6) 

95 atoms.rattle(0.2) 

96 systems.append((atoms, 'Alumninum cluster')) 

97 return systems 

98 

99 

100def create_database(): 

101 systems = get_systems() 

102 db = connect('systems.db', append=False) 

103 for atoms, description in systems: 

104 name = atoms.get_chemical_formula() 

105 db.write(atoms, description=description, name=name) 

106 

107 

108if __name__ == '__main__': 

109 create_database()