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
« prev ^ index » next coverage.py v7.14.0, created at 2026-05-21 15:52 +0000
1"""Test on structures from C2DB."""
3from sys import argv
5from ase._4.symopt.relax import Relax
6from ase.parallel import world
9def main():
10 # Tests:
11 # Wurtzite, distorted structure, nice logging, quick convergence
13 if world.rank == 0:
14 import requests
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
32 # atoms = read('2AlCl3-1.xyz').copy()
33 atoms = read('atoms.xyz').copy()
34 atoms.center()
36 def calc():
37 from gpaw.new.ase_interface import GPAW
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 )
48 from ase.optimize.bfgs import BFGS
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 )
62 relax.run(fmax=0.01, smax=0.0005)
65if __name__ == '__main__':
66 main()