1import pytest 2from ase.spacegroup import crystal 3from ase.data import atomic_numbers, atomic_masses 4from ase.optimize import QuasiNewton 5from ase.constraints import UnitCellFilter 6from numpy.testing import assert_allclose 7 8 9@pytest.mark.calculator_lite 10@pytest.mark.calculator('lammpsrun') 11def test_NaCl_minimize(factory): 12 a = 6.15 13 n = 4 14 nacl = crystal(['Na', 'Cl'], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225, 15 cellpar=[a, a, a, 90, 90, 90]).repeat((n, n, n)) 16 17 # Buckingham parameters from 18 # https://physics.stackexchange.com/questions/250018 19 20 pair_style = 'buck/coul/long 12.0' 21 pair_coeff = ['1 1 3796.9 0.2603 124.90'] 22 pair_coeff += ['2 2 1227.2 0.3214 124.90'] 23 pair_coeff += ['1 2 4117.9 0.3048 0.0'] 24 masses = ['1 {}'.format(atomic_masses[atomic_numbers['Na']]), 25 '2 {}'.format(atomic_masses[atomic_numbers['Cl']])] 26 27 with factory.calc( 28 specorder=['Na', 'Cl'], 29 pair_style=pair_style, 30 pair_coeff=pair_coeff, 31 masses=masses, 32 atom_style='charge', 33 kspace_style='pppm 1.0e-5', 34 keep_tmp_files=True, 35 ) as calc: 36 37 for a in nacl: 38 if a.symbol == 'Na': 39 a.charge = +1. 40 else: 41 a.charge = -1. 42 43 nacl.calc = calc 44 45 assert_allclose(nacl.get_potential_energy(), -1896.216737561538, 46 atol=1e-4, rtol=1e-4) 47 48 nacl.get_potential_energy() 49 50 ucf = UnitCellFilter(nacl) 51 with QuasiNewton(ucf, force_consistent=False) as dyn: 52 dyn.run(fmax=1.0E-2) 53 54 assert_allclose(nacl.get_potential_energy(), -1897.208861729178, 55 atol=1e-4, rtol=1e-4) 56