def test_curvature2(testdir): '''This test has two atoms spinning counter-clockwise around eachother. the The radius (1/curvature) is less obviously pair_distance*sqrt(2)/2. This is the simplest multi-body analytic curvature test.''' name = 'test_curvature2' radius = pair_distance * np.sqrt(2) / 2 atoms = Al_atom_pair(pair_distance) atoms.set_velocities([[0, -1, 0], [0, 1, 0]]) dyn = ContourExploration( atoms, maxstep=1.0, parallel_drift=0.0, angle_limit=30, trajectory=name + '.traj', logfile=name + '.log', ) print("Target Radius (1/curvature) {: .6f} Ang".format(radius)) for i in range(5): dyn.run(30) print('Radius (1/curvature) {: .6f} Ang'.format(1 / dyn.curvature)) assert radius == pytest.approx(1.0 / dyn.curvature, abs=2e-3)
def test_curvature1(testdir): '''This basic test has an atom spinning counter-clockwise around a fixed atom. The radius (1/curvature) must therefore be very close the pair_distance.''' name = 'test_curvature1' radius = pair_distance atoms = Al_atom_pair(pair_distance) atoms.set_constraint(FixAtoms(indices=[0])) atoms.set_velocities([[0, 0, 0], [0, 1, 0]]) dyn = ContourExploration( atoms, maxstep=1.5, parallel_drift=0.0, angle_limit=30, trajectory=name + '.traj', logfile=name + '.log', ) print("Target Radius (1/curvature) {: .6f} Ang".format(radius)) for i in range(5): dyn.run(30) print('Radius (1/curvature) {: .6f} Ang'.format(1 / dyn.curvature)) assert radius == pytest.approx(1.0 / dyn.curvature, abs=2e-3)
def test_potentiostat(testdir): '''This is very realistic and stringent test of the potentiostatic accuracy with 32 atoms at ~235 meV/atom above the ground state.''' name = 'test_potentiostat' seed = 19460926 atoms = Al_block() E0 = atoms.get_potential_energy() atoms.rattle(stdev=0.18, seed=seed) initial_energy = atoms.get_potential_energy() rng = np.random.RandomState(seed) MaxwellBoltzmannDistribution(atoms, temperature_K=300, rng=rng) dyn = ContourExploration( atoms, **bulk_Al_settings, energy_target=initial_energy, rng=rng, trajectory=name + '.traj', logfile=name + '.log', ) print("Energy Above Ground State: {: .4f} eV/atom".format( (initial_energy - E0) / len(atoms))) for i in range(5): dyn.run(5) energy_error = (atoms.get_potential_energy() - initial_energy) / len(atoms) print('Potentiostat Error {: .4f} eV/atom'.format(energy_error)) assert 0 == pytest.approx(energy_error, abs=0.01)
def test_potentiostat_no_fs(testdir): '''This test ensures that the potentiostat is working even when curvature extrapolation (use_fs) is turned off.''' name = 'test_potentiostat_no_fs' atoms = Al_atom_pair() atoms.set_momenta([[0, -1, 0], [0, 1, 0]]) initial_energy = atoms.get_potential_energy() dyn = ContourExploration( atoms, maxstep=0.2, parallel_drift=0.0, remove_translation=False, energy_target=initial_energy, potentiostat_step_scale=None, use_frenet_serret=False, trajectory=name + '.traj', logfile=name + '.log', ) for i in range(5): dyn.run(10) energy_error = (atoms.get_potential_energy() - initial_energy) / len(atoms) print('Potentiostat Error {: .4f} eV/atom'.format(energy_error)) assert 0 == pytest.approx(energy_error, abs=0.01)
def test_logging(testdir): seed = 19460926 atoms = Al_block() atoms.rattle(stdev=0.18, seed=seed) rng = np.random.RandomState(seed) initial_energy = atoms.get_potential_energy() name = 'test_logging' traj_name = name + '.traj' log_name = name + '.log' with ContourExploration( atoms, **bulk_Al_settings, rng=rng, trajectory=traj_name, logfile=log_name, ) as dyn: energy_target = initial_energy dev = (atoms.get_potential_energy() - energy_target) / len(atoms) energy_targets = [energy_target] curvatures = [dyn.curvature] stepsizes = [dyn.step_size] deviation_per_atom = [dev] # we shift the target_energy to ensure it's actaully being logged when it # changes. de = 0.001 * len(atoms) # these print statements, mirror the log file. # print(energy_target, dyn.curvature, dyn.step_size, dev) for i in range(0, 5): energy_target = initial_energy + de * i dyn.energy_target = energy_target dyn.run(1) dev = (atoms.get_potential_energy() - energy_target) / len(atoms) # print(energy_target, dyn.curvature, dyn.step_size, dev) energy_targets.append(energy_target) curvatures.append(dyn.curvature) stepsizes.append(dyn.step_size) deviation_per_atom.append(dev) # Now we check the contents of the log file # assert log file has correct length with open(log_name) as fd: length = len(fd.readlines()) assert length == 7, length with io.Trajectory(traj_name, 'r') as traj, open(log_name, 'r') as fd: # skip the first line because it's a small initialization step lines = fd.readlines()[1:] for i, (im, line) in enumerate(zip(traj, lines)): lineparts = [float(part) for part in line.split()] log_energy_target = lineparts[1] assert 0 == pytest.approx(log_energy_target - energy_targets[i], abs=1e-5) log_energy = lineparts[2] assert 0 == pytest.approx(log_energy - im.get_potential_energy(), abs=1e-5) log_curvature = lineparts[3] assert 0 == pytest.approx(log_curvature - curvatures[i], abs=1e-5) log_step_size = lineparts[4] assert 0 == pytest.approx(log_step_size - stepsizes[i], abs=1e-5) log_dev = lineparts[5] assert 0 == pytest.approx(log_dev - deviation_per_atom[i], abs=1e-5)