def test_potential_infinite_gpu(graphene_atoms): potential = Potential(atoms=graphene_atoms, sampling=.1, projection='infinite', parametrization='kirkland', device='gpu') potential.build(pbar=False)
def test_potential_storage(): atoms = Atoms('CO', positions=[(2, 3, 1), (3, 2, 3)], cell=(4, 6, 4.3)) potential = Potential(atoms=atoms, sampling=.1, device='gpu') assert type(potential.build().array) is cp.ndarray potential = Potential(atoms=atoms, sampling=.1, device='gpu', storage='cpu') assert type(potential.build().array) is np.ndarray
def test_potential_to_hyperspy(): import hyperspy.api as hs atoms = Atoms('CO', positions=[(2, 3, 1), (3, 2, 3)], cell=(4, 6, 4.3)) potential = Potential(atoms=atoms, sampling=.1) array_potential = potential.build() sig = array_potential.to_hyperspy() assert isinstance(sig, hs.signals.BaseSignal)
def test_potential_build_gpu(): atoms = Atoms('CO', positions=[(2, 3, 1), (3, 2, 3)], cell=(4, 6, 4.3)) potential = Potential(atoms=atoms, sampling=.1, device='gpu') array_potential = potential.build() assert np.all(asnumpy(array_potential[2].array) == asnumpy(potential[2].array)) potential = Potential(atoms=atoms, sampling=.1, device='cpu') assert np.allclose(asnumpy(array_potential[2].array), potential[2].array)
def test_export_import_potential(tmp_path, graphene_atoms): d = tmp_path / 'sub' d.mkdir() path = d / 'potential.hdf5' potential = Potential(graphene_atoms, sampling=.05) precalculated_potential = potential.build(pbar=False) precalculated_potential.write(path) imported_potential = PotentialArray.read(path) assert np.allclose(imported_potential.array, precalculated_potential.array) assert np.allclose(imported_potential.extent, precalculated_potential.extent) assert np.allclose(imported_potential._slice_thicknesses, precalculated_potential._slice_thicknesses)
def test_potential_build(): atoms = Atoms('CO', positions=[(2, 3, 1), (3, 2, 3)], cell=(4, 6, 4.3)) potential = Potential(atoms=atoms, sampling=.1) array_potential = potential.build() assert np.all(array_potential[2].array == potential[2].array)