def test_apply_transformation_fast(self):
     t = PartialRemoveSitesTransformation([tuple(range(4)), tuple(range(4, 8))], [0.5, 0.5], PartialRemoveSitesTransformation.ALGO_FAST)
     s = t.apply_transformation(self.struct)
     self.assertEqual(s.formula, "Li2 O2")
     t = PartialRemoveSitesTransformation([tuple(range(8))], [0.5], PartialRemoveSitesTransformation.ALGO_FAST)
     s = t.apply_transformation(self.struct)
     self.assertEqual(s.formula, "Li2 O2")
Esempio n. 2
0
    def apply_transformation(self, structure, return_ranked_list=False):
        """
        Apply the transformation.

        Args:
            structure:
                input structure
            return_ranked_list:
                Boolean stating whether or not multiple structures are
                returned. If return_ranked_list is an int, that number of
                structures is returned.

        Returns:
            Depending on returned_ranked list, either a transformed structure
            or
            a list of dictionaries, where each dictionary is of the form
            {"structure" = .... , "other_arguments"}
            the key "transformation" is reserved for the transformation that
            was actually applied to the structure.
            This transformation is parsed by the alchemy classes for generating
            a more specific transformation history. Any other information will
            be stored in the transformation_parameters dictionary in the
            transmuted structure class.
        """
        sp = smart_element_or_specie(self._specie)
        specie_indices = [i for i in xrange(len(structure)) if structure[i].species_and_occu == Composition({sp: 1})]
        trans = PartialRemoveSitesTransformation([specie_indices], [self._frac], algo=self._algo)
        return trans.apply_transformation(structure, return_ranked_list)
Esempio n. 3
0
    def apply_transformation(self, structure, return_ranked_list=False):
        """
        Apply the transformation.

        Args:
            structure: input structure
            return_ranked_list (bool/int): Boolean stating whether or not
                multiple structures are returned. If return_ranked_list is
                an int, that number of structures is returned.

        Returns:
            Depending on returned_ranked list, either a transformed structure
            or a list of dictionaries, where each dictionary is of the form
            {"structure" = .... , "other_arguments"}
            the key "transformation" is reserved for the transformation that
            was actually applied to the structure.
            This transformation is parsed by the alchemy classes for generating
            a more specific transformation history. Any other information will
            be stored in the transformation_parameters dictionary in the
            transmuted structure class.
        """
        sp = get_el_sp(self.specie_to_remove)
        specie_indices = [i for i in range(len(structure)) if structure[i].species == Composition({sp: 1})]
        trans = PartialRemoveSitesTransformation([specie_indices], [self.fraction_to_remove], algo=self.algo)
        return trans.apply_transformation(structure, return_ranked_list)
Esempio n. 4
0
 def test_apply_transformation_enumerate(self):
     t = PartialRemoveSitesTransformation(
         [tuple(range(4)), tuple(range(4, 8))], [0.5, 0.5],
         PartialRemoveSitesTransformation.ALGO_ENUMERATE)
     s = t.apply_transformation(self.struct)
     self.assertEqual(s.formula, "Li2 O2")
     s = t.apply_transformation(self.struct, 12)
     self.assertEqual(len(s), 12)
 def test_apply_transformation_best_first(self):
     t = PartialRemoveSitesTransformation(
         [tuple(range(4)), tuple(range(4, 8))],
         [0.5, 0.5],
         PartialRemoveSitesTransformation.ALGO_BEST_FIRST,
     )
     s = t.apply_transformation(self.struct)
     self.assertEqual(s.formula, "Li2 O2")
 def test_apply_transformation_enumerate(self):
     t = PartialRemoveSitesTransformation(
         [tuple(range(4)), tuple(range(4, 8))],
         [0.5, 0.5],
         PartialRemoveSitesTransformation.ALGO_ENUMERATE
     )
     s = t.apply_transformation(self.struct)
     self.assertEqual(s.formula, "Li2 O2")
     s = t.apply_transformation(self.struct, 12)
     self.assertEqual(len(s), 12)
 def test_apply_transformation_enumerate(self):
     if not enumlib_present:
         raise SkipTest("enumlib not present. "
                        "Skipping ALGO.ENUMERATE "
                        "PartialRemoveSitesTransformationTest...")
     t = PartialRemoveSitesTransformation(
         [tuple(range(4)), tuple(range(4, 8))],
         [0.5, 0.5],
         PartialRemoveSitesTransformation.ALGO_ENUMERATE
     )
     s = t.apply_transformation(self.struct)
     self.assertEqual(s.formula, "Li2 O2")
     s = t.apply_transformation(self.struct, 12)
     self.assertEqual(len(s), 12)
Esempio n. 8
0
 def test_str(self):
     d = PartialRemoveSitesTransformation([tuple(range(4))],
                                          [0.5]).as_dict()
     self.assertIsNotNone(str(d))
Esempio n. 9
0
 def test_to_from_dict(self):
     d = PartialRemoveSitesTransformation([tuple(range(4))],
                                          [0.5]).as_dict()
     t = PartialRemoveSitesTransformation.from_dict(d)
     s = t.apply_transformation(self.struct)
     self.assertEqual(s.formula, "Li2 O4")
Esempio n. 10
0
 def test_to_from_dict(self):
     d = PartialRemoveSitesTransformation([tuple(range(4))], [0.5]).as_dict()
     t = PartialRemoveSitesTransformation.from_dict(d)
     s = t.apply_transformation(self.struct)
     self.assertEqual(s.formula, "Li2 O4")
Esempio n. 11
0
from pymatgen import Structure
from pymatgen.transformations.site_transformations import PartialRemoveSitesTransformation

estrutura = Structure.from_file("POSCAR")

remove = PartialRemoveSitesTransformation([range(0, 63)], [1 / 63], algo=1)

result = remove.apply_transformation(estrutura, return_ranked_list=63)

for i, item in enumerate(result):
    item["structure"].to(filename="POSCAR{:02d}".format(i), tmp="POSCAR")