def calculate(name, system, **kwargs): print('Calculate', name, system) label = 'ink-%s' % name kwargs0 = dict(stdout="'stdout.txt'", FromScratch=True, RestartWrite=False, command='mpirun -np 4 octopus') kwargs.update(**kwargs0) calc = Octopus(label=label, **kwargs) system.calc = calc E = system.get_potential_energy() eig = calc.get_eigenvalues() check_interface(calc) restartcalc = Octopus(label) check_interface(restartcalc) # Check reconstruction of Atoms object new_atoms = restartcalc.get_atoms() print('new') print(new_atoms.positions) calc2 = Octopus(label='ink-restart-%s' % name, **kwargs) new_atoms.calc = calc2 E2 = new_atoms.get_potential_energy() #print('energy', E, E2) eig2 = calc2.get_eigenvalues() eig_err = np.abs(eig - eig2).max() e_err = abs(E - E2) print('Restart E err', e_err) print('Restart eig err', eig_err) assert e_err < 5e-5 assert eig_err < 5e-5 return calc
def test_restart_octopus(): from ase.calculators.octopus import Octopus from ase.calculators.interfacechecker import check_interface from ase.build import molecule system = molecule('H2') system.center(vacuum=2.0) directory = 'ink' calc0 = Octopus(directory=directory, check_keywords=False, FromScratch=True, stdout="'stdout.txt'", stderr="'stderr.txt'", Spacing='0.25 * Angstrom', OutputFormat='cube + xcrysden') system.set_calculator(calc0) system.get_potential_energy() # Must make one test with well-defined cell and one without. calc1 = Octopus(directory) system = calc1.get_atoms() E = system.get_potential_energy() print('energy', E) check_interface(calc1) # view(system) atoms = Octopus.read_atoms(directory) check_interface(atoms.calc) changes = calc1.check_state(atoms) print('changes', changes) assert len(changes) == 0
label = 'ink' calc0 = Octopus(label=label, FromScratch=True, stdout="'stdout.txt'", stderr="'stderr.txt'", Spacing='0.15 * Angstrom', Output='density + wfs + potential', OutputFormat='cube + xcrysden') system.set_calculator(calc0) system.get_potential_energy() # Must make one test with well-defined cell and one without. calc1 = Octopus(label) system = calc1.get_atoms() E = system.get_potential_energy() print('energy', E) errs = check_interface(calc1) # view(system) atoms = Octopus.read_atoms(label) errs = check_interface(atoms.calc) changes = calc1.check_state(atoms) print('changes', changes) assert len(changes) == 0
label = 'ink' calc0 = Octopus(label=label, FromScratch=True, stdout="'stdout.txt'", stderr="'stderr.txt'", Spacing=0.15, Output='density + wfs + potential', OutputHow='cube + xcrysden') system.set_calculator(calc0) system.get_potential_energy() # Must make one test with well-defined cell and one without. calc1 = Octopus(label) system = calc1.get_atoms() E = system.get_potential_energy() print('energy', E) errs = check_interface(calc1) #view(system) atoms = Octopus.read_atoms(label) errs = check_interface(atoms.calc) changes = calc1.check_state(atoms) print('changes', changes) assert len(changes) == 0