calc = Vasp(**settings) atoms.set_calculator(calc) en1 = atoms.get_potential_energy() # Test JSON dumping and restarting works fi = 'json_test.json' calc.write_json(filename=fi) assert os.path.isfile(fi) calc2 = Vasp() calc2.read_json(fi) assert not calc2.calculation_required(atoms, ['energy', 'forces']) en2 = calc2.get_potential_energy() assert abs(en1 - en2) < 1e-8 os.remove(fi) # Clean up the JSON file # Check that the symbols remain in order (non-sorted) s2 = calc.atoms.get_chemical_symbols() assert s1 == s2 s3 = sorted(s2) assert s2 != s3 # Check that get_atoms() doesn't reset results r1 = dict(calc.results) # Force a copy atoms2 = calc.get_atoms() r2 = dict(calc.results) assert r1 == r2
def test_vasp2_wdir(require_vasp): """ Run tests to ensure that the VASP txt and label arguments function correctly, i.e. correctly sets the working directories and works in that directory. This is conditional on the existence of the ASE_VASP_COMMAND, VASP_COMMAND or VASP_SCRIPT environment variables """ import filecmp import os from ase.test.calculator.vasp import installed2 as installed from ase import Atoms from ase.calculators.vasp import Vasp2 as Vasp assert installed() def compare_paths(path1, path2): assert os.path.abspath(path1) == os.path.abspath(path2) # Test setup system, borrowed from vasp_co.py d = 1.14 atoms = Atoms('CO', positions=[(0, 0, 0), (0, 0, d)], pbc=True) atoms.center(vacuum=5.) file1 = '_vasp_dummy_str.out' file2 = '_vasp_dummy_io.out' file3 = '_vasp_dummy_2.out' testdir = '_dummy_txt_testdir' label = os.path.join(testdir, 'vasp') # Test settings = dict(label=label, xc='PBE', prec='Low', algo='Fast', ismear=0, sigma=1., istart=0, lwave=False, lcharg=False) # Make 2 copies of the calculator object calc = Vasp(**settings) calc2 = Vasp(**settings) # Check the calculator path is the expected path compare_paths(calc.directory, testdir) calc.set(txt=file1) atoms.calc = calc en1 = atoms.get_potential_energy() # Check that the output files are in the correct directory for fi in ['OUTCAR', 'CONTCAR', 'vasprun.xml']: fi = os.path.join(testdir, fi) assert os.path.isfile(fi) # We open file2 in our current directory, so we don't want it to write # in the label directory with open(file2, 'w') as f: calc2.set(txt=f) atoms.calc = calc2 atoms.get_potential_energy() # Make sure the two outputfiles are identical assert filecmp.cmp(os.path.join(calc.directory, file1), file2) # Test restarting from working directory in test directory label2 = os.path.join(testdir, file3) calc2 = Vasp(restart=label, label=label2) # Check the calculator path is the expected path compare_paths(calc2.directory, testdir) assert not calc2.calculation_required(calc2.atoms, ['energy', 'forces']) en2 = calc2.get_potential_energy() # Check that the restarted calculation didn't run, i.e. write to output file assert not os.path.isfile(os.path.join(calc.directory, file3)) # Check that we loaded energy correctly assert en1 == en2
def test_vasp2_check_state(): """ Run tests to ensure that the VASP check_state() function call works correctly, i.e. correctly sets the working directories and works in that directory. This is conditional on the existence of the VASP_COMMAND or VASP_SCRIPT environment variables """ from ase.test.vasp import installed2 as installed import os from ase import Atoms from ase.calculators.vasp import Vasp2 as Vasp assert installed() # Test setup system, borrowed from vasp_co.py d = 1.14 atoms = Atoms('CO', positions=[(0, 0, 0), (0, 0, d)], pbc=True) atoms.extend(Atoms('CO', positions=[(0, 2, 0), (0, 2, d)])) atoms.center(vacuum=5.) # Test settings = dict(xc='LDA', prec='Low', algo='Fast', ismear=0, sigma=1., istart=0, lwave=False, lcharg=False) s1 = atoms.get_chemical_symbols() calc = Vasp(**settings) atoms.set_calculator(calc) en1 = atoms.get_potential_energy() # Test JSON dumping and restarting works fi = 'json_test.json' calc.write_json(filename=fi) assert os.path.isfile(fi) calc2 = Vasp() calc2.read_json(fi) assert not calc2.calculation_required(atoms, ['energy', 'forces']) en2 = calc2.get_potential_energy() assert abs(en1 - en2) < 1e-8 os.remove(fi) # Clean up the JSON file # Check that the symbols remain in order (non-sorted) s2 = calc.atoms.get_chemical_symbols() assert s1 == s2 s3 = sorted(s2) assert s2 != s3 # Check that get_atoms() doesn't reset results r1 = dict(calc.results) # Force a copy calc.get_atoms() r2 = dict(calc.results) assert r1 == r2 # Make a parameter change to the calculator calc.set(sigma=0.5) # Check that we capture a change for float params assert calc.check_state(atoms) == ['float_params'] assert calc.calculation_required(atoms, ['energy', 'forces']) en2 = atoms.get_potential_energy() # The change in sigma should result in a small change in energy assert (en1 - en2) > 1e-7 # Now we make a change in input_params instead calc.kpts = 2 # Check that this requires a new calculation assert calc.check_state(atoms) == ['input_params'] assert calc.calculation_required(atoms, ['energy', 'forces']) # Clean up calc.clean()