Exemple #1
0
    def rattle_calc(self, atoms, calc):
        try:
            os.remove('checkpoints.db')
        except OSError:
            pass

        orig_atoms = atoms.copy()

        # first do a couple of calculations
        np.random.seed(0)
        atoms.rattle()
        cp_calc_1 = CheckpointCalculator(calc)
        atoms.set_calculator(cp_calc_1)
        e11 = atoms.get_potential_energy()
        f11 = atoms.get_forces()
        atoms.rattle()
        e12 = atoms.get_potential_energy()
        f12 = atoms.get_forces()

        # then re-read them from checkpoint file
        atoms = orig_atoms
        np.random.seed(0)
        atoms.rattle()
        cp_calc_2 = CheckpointCalculator(calc)
        atoms.set_calculator(cp_calc_2)
        e21 = atoms.get_potential_energy()
        f21 = atoms.get_forces()
        atoms.rattle()
        e22 = atoms.get_potential_energy()
        f22 = atoms.get_forces()

        self.assertAlmostEqual(e11, e21)
        self.assertAlmostEqual(e12, e22)
        self.assert_(np.abs(f11 - f21).max() < 1e-5)
        self.assert_(np.abs(f12 - f22).max() < 1e-5)
Exemple #2
0
def rattle_calc(atoms, calc):
    try:
        os.remove('checkpoints.db')
    except OSError:
        pass

    orig_atoms = atoms.copy()

    # first do a couple of calculations
    np.random.seed(0)
    atoms.rattle()
    cp_calc_1 = CheckpointCalculator(calc)
    atoms.calc = cp_calc_1
    e11 = atoms.get_potential_energy()
    f11 = atoms.get_forces()
    atoms.rattle()
    e12 = atoms.get_potential_energy()
    f12 = atoms.get_forces()

    # then re-read them from checkpoint file
    atoms = orig_atoms
    np.random.seed(0)
    atoms.rattle()
    cp_calc_2 = CheckpointCalculator(calc)
    atoms.calc = cp_calc_2
    e21 = atoms.get_potential_energy()
    f21 = atoms.get_forces()
    atoms.rattle()
    e22 = atoms.get_potential_energy()
    f22 = atoms.get_forces()

    assert e11 == e21
    assert e12 == e22
    assert(np.abs(f11 - f21).max() < 1e-5)
    assert(np.abs(f12 - f22).max() < 1e-5)
sys.stdout.write(open(test_file).read())
print('=' * 60)

import model  # import and run the current model

# adapt model to test, e.g. to set output directory name
if hasattr(model, 'start'):
    model.start(test_name)

# create a checkpoint file for this specific (model, test) combination
if ('GAP_TESTER_CHECKPOINT' in os.environ
        and os.environ['GAP_TESTER_CHECKPOINT'] != "") or not hasattr(
            model, 'no_checkpoint') or not model.no_checkpoint:
    checkpoint_file = run_root + '.db'
    print('Using checkpoint file', checkpoint_file)
    model.calculator = CheckpointCalculator(model.calculator,
                                            db=checkpoint_file)

import test  # import and run the current test

print('=' * 60)
print('Property calculation output:')
print('')

# serialise results in machine readable JSON format
json_file = open(json_file_name, 'w')
json.dump(test.properties, json_file)
json_file.close()

print('')
print('Summary of computed properties:')
print(test.properties)