예제 #1
0
 def test_rdf_coordination_number(self):
     # create a simple cubic lattice
     coords = np.array([[0.5, 0.5, 0.5]])
     atom_list = ['S']
     lattice = Lattice.from_parameters(a=1.0, b=1.0, c=1.0, alpha=90,
                                       beta=90, gamma=90)
     structure = Structure(lattice, atom_list, coords)
     rdf = RadialDistributionFunction.from_species(
         structures=[structure], species=['S'],
         rmax=5.0, sigma=0.1, ngrid=500)
     self.assertEqual(rdf.coordination_number[100], 6.0)
예제 #2
0
    def test_rdf(self):
        # Parse the DiffusionAnalyzer object from json file directly
        obj = loadfn(os.path.join(tests_dir, "cNa3PS4_pda.json"))

        structure_list = []
        for i, s in enumerate(obj.get_drift_corrected_structures()):
            structure_list.append(s)
            if i == 9: break
        species = ["Na", "P", "S"]

        # Test from_species
        obj = RadialDistributionFunction.from_species(
            structures=structure_list, ngrid=101, rmax=10.0, cell_range=1,
            sigma=0.1, species=species, reference_species=species)

        check = np.shape(obj.rdf)[0] == 101 and np.argmax(obj.rdf) == 34
        self.assertTrue(check)
        self.assertAlmostEqual(obj.rdf.max(), 1.634448, 4)

        # Test init
        s = structure_list[0]
        indices = [i for (i, site) in enumerate(s) if
                   site.species_string in species]
        obj = RadialDistributionFunction(
            structures=structure_list, ngrid=101, rmax=10.0, cell_range=1,
            sigma=0.1, indices=indices, reference_indices=indices)

        check = np.shape(obj.rdf)[0] == 101 and np.argmax(obj.rdf) == 34
        self.assertTrue(check)
        self.assertAlmostEqual(obj.rdf.max(), 1.634448, 4)

        # Test init using structures w/ different lattices
        s0 = deepcopy(structure_list[0])
        sl_1 = [s0, s0, s0 * [1, 2, 1]]
        sl_2 = [s0 * [2, 1, 1], s0, s0]

        obj_1 = RadialDistributionFunction(
            structures=sl_1, ngrid=101, rmax=10.0, cell_range=1,
            sigma=0.1, indices=indices, reference_indices=indices)
        obj_2 = RadialDistributionFunction(
            structures=sl_2, ngrid=101, rmax=10.0, cell_range=1,
            sigma=0.1, indices=indices, reference_indices=indices)

        self.assertEqual(obj_1.rho, obj_2.rho)
        self.assertEqual(obj_1.rdf[0], obj_2.rdf[0])
예제 #3
0
    def test_rdf(self):
        data_file = os.path.join(tests_dir, "cNa3PS4_pda.json")
        with open(data_file, "r") as j:
            data = json.load(j)
        obj = DiffusionAnalyzer.from_dict(data)

        structure_list = []
        for i, s in enumerate(obj.get_drift_corrected_structures()):
            structure_list.append(s)
            if i == 9: break
        species = ["Na", "P", "S"]

        # Test from_species
        obj = RadialDistributionFunction.from_species(
            structures=structure_list,
            ngrid=101,
            rmax=10.0,
            cell_range=1,
            sigma=0.1,
            species=species,
            reference_species=species)

        check = np.shape(obj.rdf)[0] == 101 and np.argmax(obj.rdf) == 34
        self.assertTrue(check)
        self.assertAlmostEqual(obj.rdf.max(), 1.634448, 4)

        # Test init
        s = structure_list[0]
        indices = [
            i for (i, site) in enumerate(s) if site.species_string in species
        ]
        obj = RadialDistributionFunction(structures=structure_list,
                                         ngrid=101,
                                         rmax=10.0,
                                         cell_range=1,
                                         sigma=0.1,
                                         indices=indices,
                                         reference_indices=indices)

        check = np.shape(obj.rdf)[0] == 101 and np.argmax(obj.rdf) == 34
        self.assertTrue(check)
        self.assertAlmostEqual(obj.rdf.max(), 1.634448, 4)
 def test_rdf_two_species_coordination_number(self):
     # create a structure with interpenetrating simple cubic lattice
     coords = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]])
     atom_list = ["S", "Zn"]
     lattice = Lattice.from_parameters(a=1.0,
                                       b=1.0,
                                       c=1.0,
                                       alpha=90,
                                       beta=90,
                                       gamma=90)
     structure = Structure(lattice, atom_list, coords)
     rdf = RadialDistributionFunction.from_species(
         structures=[structure],
         species=["S"],
         reference_species=["Zn"],
         rmax=5.0,
         sigma=0.1,
         ngrid=500,
     )
     self.assertEqual(rdf.coordination_number[100], 8.0)
예제 #5
0
 def test_raises_ValueError_if_reference_species_not_in_structure(self):
     with self.assertRaises(ValueError):
         rdf = RadialDistributionFunction.from_species(
             structures=[self.structure],
             species=['S'],
             reference_species=['Cl'])
예제 #6
0
 def test_raises_ValueError_if_sigma_is_not_positive(self):
     with self.assertRaises(ValueError):
         rdf = RadialDistributionFunction.from_species(
             structures=[self.structure], sigma=0)
예제 #7
0
 def test_raises_valueerror_if_ngrid_is_less_than_2(self):
     with self.assertRaises(ValueError):
         rdf = RadialDistributionFunction.from_species(
             structures=[self.structure], ngrid=1)