Coverage for gpaw/test/solvation/test_sjm_fdt.py: 31%

35 statements  

« prev     ^ index     » next       coverage.py v7.7.1, created at 2025-07-14 00:18 +0000

1import pytest 

2from ase.build import fcc111, molecule 

3from ase.constraints import FixAtoms 

4from ase.md.langevin import Langevin 

5from ase.units import Pascal, fs, m 

6 

7from gpaw.solvation import (EffectivePotentialCavity, GradientSurface, 

8 LinearDielectric, SurfaceInteraction) 

9from gpaw.solvation.sjm import SJM, SJMPower12Potential 

10 

11 

12@pytest.mark.skip('Too slow: 11 min.') 

13@pytest.mark.slow 

14@pytest.mark.old_gpaw_only 

15def test_sjm_fdt_true(in_tmp_dir): 

16 """Test if fdt dictionary is correctly set in the calculator. 

17 Test if fdt initial excess electron value is correctly 

18 set in the calculator. 

19 """ 

20 atoms = fcc111('Au', size=(1, 1, 3)) 

21 atoms.center(axis=2, vacuum=10.2) 

22 atoms.translate([0.0, 0.0, -4.0]) 

23 

24 water = molecule('H2O') 

25 water.rotate('y', 90.0) 

26 water.positions += atoms[2].position + (0.0, 0.0, 4.4) - water[0].position 

27 

28 atoms.extend(water) 

29 atoms.set_constraint(FixAtoms(indices=[0, 1])) 

30 atoms.pbc = [True, True, False] 

31 

32 # Solvated jellium parameters. 

33 sj_input = { 

34 'target_potential': 4.5, 

35 'fdt': { 

36 'dt': 0.5, 

37 'po_time': 1000.0, 

38 'th_temp': 300}} 

39 

40 # Implicit solvent parameters (to SolvationGPAW). 

41 epsinf = 78.36 

42 gamma = 18.4 * 1e-3 * Pascal * m 

43 cavity = EffectivePotentialCavity( 

44 effective_potential=SJMPower12Potential(H2O_layer=True), 

45 temperature=298.15, # K 

46 surface_calculator=GradientSurface()) 

47 dielectric = LinearDielectric(epsinf=epsinf) 

48 interactions = [SurfaceInteraction(surface_tension=gamma)] 

49 

50 # The calculator 

51 calc = SJM( 

52 mode='lcao', 

53 basis='szp(dzp)', 

54 txt='test_fdt_true.txt', 

55 gpts=(16, 16, 136), 

56 kpts=(1, 1, 1), 

57 xc='PBE', 

58 maxiter=1000, 

59 sj=sj_input, 

60 cavity=cavity, 

61 dielectric=dielectric, 

62 interactions=interactions, 

63 symmetry={'point_group': False}) 

64 atoms.calc = calc 

65 

66 atoms.get_potential_energy() 

67 atoms.get_forces() 

68 

69 # Run 10 steps of Langevin dynamics. 

70 traj = 'md_fdt_true.traj' 

71 dyn = Langevin(atoms, 0.5 * fs, temperature_K=300, 

72 friction=0.005, trajectory=traj) 

73 dyn.run(5) 

74 

75 assert sj_input['fdt'] == atoms.calc.parameters['sj']['fdt'] 

76 assert abs(atoms.calc.parameters['sj']['previous_electrons'][0]) < 1e-6