Debian Codegraph @

doc/tutorialsexercises/magnetic/zfs/diamond_nv_minus.py

raw
1 import json
2 from ase.parallel import paropen
3 from ase.build import bulk
4 from ase.optimize import BFGS
5 from gpaw import GPAW, PW
6 from gpaw.zero_field_splitting import zfs
7
8
9 def nv_minus(n: int, relax: bool = False) -> None:
10 atoms = bulk('C', 'diamond', cubic=True) * n
11 atoms.numbers[0] = 7
12 del atoms[1]
13 atoms.set_initial_magnetic_moments([1] * len(atoms))
14 name = f'NC{8 * n**3 - 2}'
15 atoms.calc = GPAW(xc='PBE',
16 mode=PW(ecut=400),
17 charge=-1,
18 txt=name + '.txt')
19 atoms.get_forces()
20 # atoms.calc.write(name + '.gpw', 'all')
21 D1 = zfs(atoms.calc)
22
23 if relax:
24 BFGS(atoms,
25 logfile=name + '.log').run(fmax=0.05)
26 # atoms.calc.write(name + '.relaxed.gpw', 'all')
27
28 D2 = zfs(atoms.calc)
29 with paropen(name + '.json', 'w') as fd:
30 json.dump(dict(D1=D1.tolist(), D2=D2.tolist()), fd)
31
32
33 if __name__ == '__main__':
34 for n in range(2, 4):
35 nv_minus(n, relax=True)