def test_site_index_mapping_two(self): a = 6.19399 lattice = Lattice.from_parameters(a, a, a, 90, 90, 90) coords1 = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]) coords2 = np.array([[0.4, 0.6, 0.4], [0.1, 0.1, 0.1]]) sites1 = [ PeriodicSite(species='Na', coords=c, lattice=lattice) for c in coords1 ] sites2 = [ PeriodicSite(species='Na', coords=c, lattice=lattice) for c in coords2 ] structure1 = Structure.from_sites(sites1) structure2 = Structure.from_sites(sites2) mapping = site_index_mapping(structure1, structure2) np.testing.assert_array_equal(mapping, np.array([1, 0])) mapping = site_index_mapping(structure1, structure2) np.testing.assert_array_equal(mapping, np.array([1, 0]))
def test_site_index_mapping_with_one_to_one_mapping_raises_ValueError_one( self): a = 6.19399 lattice = Lattice.from_parameters(a, a, a, 90, 90, 90) coords1 = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]) coords2 = np.array([[0.4, 0.6, 0.4], [0.1, 0.1, 0.1]]) species2 = ['Na', 'Cl'] sites1 = [ PeriodicSite(species='Na', coords=c, lattice=lattice) for c in coords1 ] sites2 = [ PeriodicSite(species=s, coords=c, lattice=lattice) for s, c in zip(species2, coords2) ] structure1 = Structure.from_sites(sites1) structure2 = Structure.from_sites(sites2) with self.assertRaises(ValueError): site_index_mapping(structure1, structure2, species2='Na')
def test_site_index_mapping_with_species_1_as_string(self): a = 6.19399 lattice = Lattice.from_parameters(a, a, a, 90, 90, 90) coords1 = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]) coords2 = np.array([[0.4, 0.6, 0.4], [0.1, 0.1, 0.1]]) species1 = ['Na', 'Cl'] sites1 = [ PeriodicSite(species=s, coords=c, lattice=lattice) for s, c in zip(species1, coords1) ] sites2 = [ PeriodicSite(species='Na', coords=c, lattice=lattice) for c in coords2 ] structure1 = Structure.from_sites(sites1) structure2 = Structure.from_sites(sites2) mapping = site_index_mapping(structure1, structure2, species1='Na') np.testing.assert_array_equal(mapping, np.array([1]))
def test_site_index_mapping_with_return_mapping_distances(self): a = 6.19399 lattice = Lattice.from_parameters(a, a, a, 90, 90, 90) coords1 = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]]) coords2 = np.array([[0.1, 0.1, 0.1], [0.4, 0.6, 0.4]]) sites1 = [ PeriodicSite(species='Na', coords=c, lattice=lattice) for c in coords1 ] sites2 = [ PeriodicSite(species='Na', coords=c, lattice=lattice) for c in coords2 ] structure1 = Structure.from_sites(sites1) structure2 = Structure.from_sites(sites2) mapping, distances = site_index_mapping(structure1, structure2, return_mapping_distances=True) np.testing.assert_array_equal(mapping, np.array([0, 1])) expected_distance = np.sqrt(3 * ((0.1 * a)**2)) np.testing.assert_array_almost_equal( distances, np.array([expected_distance, expected_distance]))