示例#1
0
    def test_smactStruc_comp_key(self):
        """Test generation of a composition key for `SmactStructure`s."""
        s1 = SmactStructure(*self._gen_empty_structure([('Ba', 2,
                                                         2), ('O', -2,
                                                              1), ('F', -1,
                                                                   2)]))
        s2 = SmactStructure(*self._gen_empty_structure([('Fe', 2,
                                                         1), ('Fe', 3,
                                                              2), ('O', -2,
                                                                   4)]))

        Ba = Species('Ba', 2)
        O = Species('O', -2)
        F = Species('F', -1)
        Fe2 = Species('Fe', 2)
        Fe3 = Species('Fe', 3)

        s3 = SmactStructure(*self._gen_empty_structure([(Ba, 2), (O, 1), (F,
                                                                          2)]))
        s4 = SmactStructure(*self._gen_empty_structure([(Fe2, 1), (Fe3,
                                                                   2), (O,
                                                                        4)]))

        Ba_2OF_2 = "Ba_2_2+F_2_1-O_1_2-"
        Fe_3O_4 = "Fe_2_3+Fe_1_2+O_4_2-"
        self.assertEqual(s1.composition(), Ba_2OF_2)
        self.assertEqual(s2.composition(), Fe_3O_4)
        self.assertEqual(s3.composition(), Ba_2OF_2)
        self.assertEqual(s4.composition(), Fe_3O_4)
示例#2
0
 def test_oxidation_states(self):
     ox = smact.oxidation_states.Oxidation_state_probability_finder()
     self.assertAlmostEqual(
         ox.compound_probability([Specie('Fe', +3),
                                  Specie('O', -2)]), 0.74280230326)
     self.assertAlmostEqual(
         ox.pair_probability(Species('Fe', +3), Species('O', -2)),
         0.74280230326)
     self.assertEqual(len(ox.get_included_species()), 173)
示例#3
0
    def compound_probability(self, structure, ignore_stoichiometry=True):
        '''
        calculate overall probability for structure or composition.

        Args:
            structure (pymatgen.Structure): Compound for which the probability score will be generated.
                Can also be a list of pymatgen or SMACT Species.
            ignore_stoichiometry (bool): Whether to weight probabilities by stoichiometry.
                Defaults to false as decribed in the original paper.

        Returns:
            compound_prob (float): Compound probability
        '''

        # Convert input to list of SMACT Species
        if type(structure) == list:
            if all(isinstance(i, Species) for i in structure):
                pass
            elif all(isinstance(i, pmgSpecies) for i in structure):
                structure = [Species(i.symbol, i.oxi_state) for i in structure]
            else:
                raise TypeError(
                    "Input requires a list of SMACT or Pymatgen species.")
        elif type(structure) == Structure:
            species = structure.species
            if not all(isinstance(i, pmgSpecies) for i in species):
                raise TypeError("Structure must have oxidation states.")
            else:
                structure = [Species(i.symbol, i.oxi_state) for i in structure]
        else:
            raise TypeError(
                "Input requires a list of SMACT or Pymatgen Species or a Structure."
            )

        # Put most electonegative element last in list by sorting by electroneg
        structure.sort(key=lambda x: x.pauling_eneg)

        # Define necessary species pairs
        anion = structure[-1]
        cations = [i for i in structure if i.oxidation > 0]
        species_pairs = [(anion, cation) for cation in cations]

        # Reduce down to unique pairs if ignoring stoichiometry
        if ignore_stoichiometry:
            species_pairs = list(set(species_pairs))

        # Do the maths
        pair_probs = [
            self.pair_probability(pair[0], pair[1]) for pair in species_pairs
        ]
        compound_prob = mean(pair_probs)
        return compound_prob