Coverage for ase / _4 / symopt / runrelax.py: 18.18%

22 statements  

« prev     ^ index     » next       coverage.py v7.14.0, created at 2026-05-21 15:52 +0000

1"""Test on structures from C2DB.""" 

2 

3from sys import argv 

4 

5from ase._4.symopt.relax import Relax 

6from ase.parallel import world 

7 

8 

9def main(): 

10 # Tests: 

11 # Wurtzite, distorted structure, nice logging, quick convergence 

12 

13 if world.rank == 0: 

14 import requests 

15 

16 url = f'https://c2db.fysik.dtu.dk/material/{argv[1]}/download/xyz' 

17 print(url) 

18 request = requests.get(url) 

19 with open('atoms.xyz', 'wb') as f: 

20 f.write(request.content) 

21 print('Written to atoms.xyz') 

22 world.barrier() 

23 # atoms = bulk("NaCl", "rocksalt", a=5.2) 

24 # atoms = bulk("ZnO", crystalstructure="wurtzite", a=3.24, c=5.20) 

25 # atoms = bulk("ZnO", crystalstructure="wurtzite", a=3.14, c=5.30) 

26 # Avoid rotating the cell (making it symmetric) 

27 # eps = np.array([[0,1,0], [1,0,0], [0,0, 0]]) * 0.02 

28 # atoms.set_cell(atoms.get_cell() @ (np.eye(3) + eps + eps.T)) 

29 # atoms.rattle(0.1) 

30 from ase.io import read 

31 

32 # atoms = read('2AlCl3-1.xyz').copy() 

33 atoms = read('atoms.xyz').copy() 

34 atoms.center() 

35 

36 def calc(): 

37 from gpaw.new.ase_interface import GPAW 

38 

39 return GPAW( 

40 mode={'name': 'pw', 'ecut': 800}, 

41 kpts={'density': 4, 'gamma': True}, 

42 symmetry={'symmorphic': False}, 

43 txt='ZnO.txt', 

44 xc='PBE', 

45 convergence={'density': 1e-7}, 

46 ) 

47 

48 from ase.optimize.bfgs import BFGS 

49 

50 relax = Relax( 

51 atoms=atoms, 

52 calc=calc, 

53 optimizer_factory=lambda atoms: BFGS( 

54 atoms, maxstep=0.5, logfile='bfgs.log', trajectory='a.traj' 

55 ), 

56 symprec=0.003, 

57 logfile='relax.log', 

58 teelog=True, 

59 comm=world, 

60 ) 

61 

62 relax.run(fmax=0.01, smax=0.0005) 

63 

64 

65if __name__ == '__main__': 

66 main()