• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python structure_modifier.StructureEditor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pymatgen.core.structure_modifier.StructureEditor的典型用法代码示例。如果您正苦于以下问题:Python StructureEditor类的具体用法?Python StructureEditor怎么用?Python StructureEditor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了StructureEditor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: apply_transformation

 def apply_transformation(self, structure):
     editor = StructureEditor(structure)
     for i, sp in enumerate(self._species):
         editor.insert_site(i, sp, self._coords[i],
                            coords_are_cartesian=self._cartesian,
                            validate_proximity=self._validate_proximity)
     return editor.modified_structure.get_sorted_structure()
开发者ID:materialsgenome,项目名称:pymatgen,代码行数:7,代码来源:site_transformations.py


示例2: _get_host

def _get_host(structure, species_to_remove):
    if species_to_remove:
        editor = StructureEditor(structure)
        editor.remove_species(species_to_remove)
        return editor.modified_structure
    else:
        return structure
开发者ID:isayev,项目名称:pymatgen,代码行数:7,代码来源:entry_tools.py


示例3: complete_ordering

    def complete_ordering(self, structure, num_remove_dict):
        self.logger.debug("Performing complete ordering...")
        all_structures = []
        from pymatgen.symmetry.finder import SymmetryFinder
        symprec = 0.2
        s = SymmetryFinder(structure, symprec=symprec)
        self.logger.debug("Symmetry of structure is determined to be {}."
                          .format(s.get_spacegroup_symbol()))
        sg = s.get_spacegroup()
        tested_sites = []
        starttime = time.time()
        self.logger.debug("Performing initial ewald sum...")
        ewaldsum = EwaldSummation(structure)
        self.logger.debug("Ewald sum took {} seconds."
                          .format(time.time() - starttime))
        starttime = time.time()

        allcombis = []
        for ind, num in num_remove_dict.items():
            allcombis.append(itertools.combinations(ind, num))

        count = 0
        for allindices in itertools.product(*allcombis):
            sites_to_remove = []
            indices_list = []
            for indices in allindices:
                sites_to_remove.extend([structure[i] for i in indices])
                indices_list.extend(indices)

            mod = StructureEditor(structure)
            mod.delete_sites(indices_list)
            s_new = mod.modified_structure
            energy = ewaldsum.compute_partial_energy(indices_list)
            already_tested = False
            for i, tsites in enumerate(tested_sites):
                tenergy = all_structures[i]["energy"]
                if abs((energy - tenergy) / len(s_new)) < 1e-5 and \
                        sg.are_symmetrically_equivalent(sites_to_remove, tsites,
                                                        symm_prec=symprec):
                    already_tested = True

            if not already_tested:
                tested_sites.append(sites_to_remove)
                all_structures.append({"structure": s_new, "energy": energy})

            count += 1
            if count % 10 == 0:
                timenow = time.time()
                self.logger.debug("{} structures, {:.2f} seconds."
                                  .format(count, timenow - starttime))
                self.logger.debug("Average time per combi = {} seconds"
                                  .format((timenow - starttime) / count))
                self.logger.debug("{} symmetrically distinct structures found."
                                  .format(len(all_structures)))

        self.logger.debug("Total symmetrically distinct structures found = {}"
                          .format(len(all_structures)))
        all_structures = sorted(all_structures, key=lambda s: s["energy"])
        return all_structures
开发者ID:materialsgenome,项目名称:pymatgen,代码行数:59,代码来源:site_transformations.py


示例4: apply_transformation

 def apply_transformation(self, structure):
     species_map = {}
     for k, v in self._species_map.items():
         if isinstance(v, dict):
             value = {smart_element_or_specie(x): y for x, y in v.items()}
         else:
             value = smart_element_or_specie(v)
         species_map[smart_element_or_specie(k)] = value
     editor = StructureEditor(structure)
     editor.replace_species(species_map)
     return editor.modified_structure
开发者ID:materialsgenome,项目名称:pymatgen,代码行数:11,代码来源:standard_transformations.py


示例5: test_add_site_property

    def test_add_site_property(self):
        self.modifier.add_site_property("charge", [4.1, 5])
        s = self.modifier.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[1].charge, 5)

        #test adding multiple properties.
        mod2 = StructureEditor(s)
        mod2.add_site_property("magmom", [3, 2])
        s = mod2.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[0].magmom, 3)
开发者ID:chenweis,项目名称:pymatgen,代码行数:12,代码来源:test_structure_modifier.py


示例6: setUp

 def setUp(self):
     p = Poscar.from_file(os.path.join(test_dir, 'POSCAR'))
     self.structure = p.struct
     self.sg = SymmetryFinder(self.structure, 0.001)
     parser = CifParser(os.path.join(test_dir, 'Li10GeP2S12.cif'))
     self.disordered_structure = parser.get_structures()[0]
     self.disordered_sg = SymmetryFinder(self.disordered_structure, 0.001)
     s = p.struct
     editor = StructureEditor(p.struct)
     site = s[0]
     editor.delete_site(0)
     editor.append_site(site.species_and_occu, site.frac_coords)
     self.sg3 = SymmetryFinder(editor.modified_structure, 0.001)
开发者ID:chenweis,项目名称:pymatgen,代码行数:13,代码来源:test_spglib_adaptor.py


示例7: test_init

    def test_init(self):
        fitter = StructureFitter(self.b, self.a)
        self.assertTrue(fitter.mapping_op != None, "No fit found!")

        #Now to try with rotated structure
        op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, False, np.array([0, 0, 1]))
        editor = StructureEditor(self.a)
        editor.apply_operation(op)
        fitter = StructureFitter(self.b, editor.modified_structure)

        self.assertTrue(fitter.mapping_op != None, "No fit found!")

        #test with a supercell
        mod = SupercellMaker(self.a, scaling_matrix=[[2, 0, 0], [0, 1, 0], [0, 0, 1]])
        a_super = mod.modified_structure
        fitter = StructureFitter(self.b, a_super)
        self.assertTrue(fitter.mapping_op != None, "No fit found!")

        # Test with a structure with a translated point

        editor = StructureEditor(self.a)
        site = self.a[0]
        editor.delete_site(0)
        trans = np.random.randint(0, 1000, 3)
        editor.insert_site(0, site.species_and_occu, site.frac_coords + trans, False, False)
        fitter = StructureFitter(self.b, editor.modified_structure)
        self.assertTrue(fitter.mapping_op != None, "No fit found for translation {}!".format(trans))

        parser = CifParser(os.path.join(test_dir, "FePO4a.cif"))
        a = parser.get_structures()[0]
        parser = CifParser(os.path.join(test_dir, "FePO4b.cif"))
        b = parser.get_structures()[0]
        fitter = StructureFitter(b, a)
        self.assertTrue(fitter.mapping_op != None, "No fit found!")
开发者ID:chenweis,项目名称:pymatgen,代码行数:34,代码来源:test_structure_fitter.py


示例8: fast_ordering

    def fast_ordering(self, structure, num_remove_dict, num_to_return=1):
        """
        This method uses the matrix form of ewaldsum to calculate the ewald
        sums of the potential structures. This is on the order of 4 orders of
        magnitude faster when there are large numbers of permutations to
        consider. There are further optimizations possible (doing a smarter
        search of permutations for example), but this wont make a difference
        until the number of permutations is on the order of 30,000.
        """
        self.logger.debug("Performing fast ordering")
        starttime = time.time()
        self.logger.debug("Performing initial ewald sum...")

        ewaldmatrix = EwaldSummation(structure).total_energy_matrix
        self.logger.debug("Ewald sum took {} seconds."
                          .format(time.time() - starttime))
        starttime = time.time()
        m_list = []
        for indices, num in num_remove_dict.items():
            m_list.append([0, num, list(indices), None])

        self.logger.debug("Calling EwaldMinimizer...")
        minimizer = EwaldMinimizer(ewaldmatrix, m_list, num_to_return,
                                   PartialRemoveSitesTransformation.ALGO_FAST)
        self.logger.debug("Minimizing Ewald took {} seconds."
                          .format(time.time() - starttime))

        all_structures = []

        lowest_energy = minimizer.output_lists[0][0]
        num_atoms = sum(structure.composition.values())

        for output in minimizer.output_lists:
            se = StructureEditor(structure)
            del_indices = []

            for manipulation in output[1]:
                if manipulation[1] is None:
                    del_indices.append(manipulation[0])
                else:
                    se.replace_site(manipulation[0], manipulation[1])
            se.delete_sites(del_indices)
            struct = se.modified_structure.get_sorted_structure()
            all_structures.append({"energy": output[0],
                                   "energy_above_minimum": (output[0]
                                                            - lowest_energy)
                                   / num_atoms,
                                   "structure": struct})

        return all_structures
开发者ID:materialsgenome,项目名称:pymatgen,代码行数:50,代码来源:site_transformations.py


示例9: enumerate_ordering

 def enumerate_ordering(self, structure):
     # Generate the disordered structure first.
     editor = StructureEditor(structure)
     for indices, fraction in zip(self._indices, self._fractions):
         for ind in indices:
             new_sp = {sp: occu * fraction
                       for sp, occu
                       in structure[ind].species_and_occu.items()}
             editor.replace_site(ind, new_sp)
     mod_s = editor.modified_structure
     # Perform enumeration
     from pymatgen.transformations.advanced_transformations import \
         EnumerateStructureTransformation
     trans = EnumerateStructureTransformation()
     return trans.apply_transformation(mod_s, 10000)
开发者ID:materialsgenome,项目名称:pymatgen,代码行数:15,代码来源:site_transformations.py


示例10: test_remove_oxidation_states

 def test_remove_oxidation_states(self):
     co_elem = Element("Co")
     o_elem = Element("O")
     co_specie = Specie("Co", 2)
     o_specie = Specie("O", -2)
     coords = list()
     coords.append([0, 0, 0])
     coords.append([0.75, 0.5, 0.75])
     lattice = Lattice.cubic(10)
     s_elem = Structure(lattice, [co_elem, o_elem], coords)
     s_specie = Structure(lattice, [co_specie, o_specie], coords)
     mod = StructureEditor(s_specie)
     mod.remove_oxidation_states()
     mod_s = mod.modified_structure
     self.assertEqual(s_elem, mod_s, "Oxidation state remover failed")
开发者ID:jesuansito,项目名称:pymatgen,代码行数:15,代码来源:test_structure_modifier.py


示例11: test_fit

    def test_fit(self):
        """
        Take two known matched structures
            1) Ensure match
            2) Ensure match after translation and rotations
            3) Ensure no-match after large site translation
            4) Ensure match after site shuffling
            """
        sm = StructureMatcher()

        self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))

        # Test rotational/translational invariance
        op = SymmOp.from_axis_angle_and_translation([0, 0, 1], 30, False,
                                                    np.array([0.4, 0.7, 0.9]))
        editor = StructureEditor(self.struct_list[1])
        editor.apply_operation(op)
        self.assertTrue(sm.fit(self.struct_list[0], editor.modified_structure))

        #Test failure under large atomic translation
        editor.translate_sites([0], [.4, .4, .2], frac_coords=True)
        self.assertFalse(sm.fit(self.struct_list[0],
                                editor.modified_structure))

        editor.translate_sites([0], [-.4, -.4, -.2], frac_coords=True)
        # random.shuffle(editor._sites)
        self.assertTrue(sm.fit(self.struct_list[0], editor.modified_structure))
        #Test FrameworkComporator
        sm2 = StructureMatcher(comparator=FrameworkComparator())
        lfp = read_structure(os.path.join(test_dir, "LiFePO4.cif"))
        nfp = read_structure(os.path.join(test_dir, "NaFePO4.cif"))
        self.assertTrue(sm2.fit(lfp, nfp))
        self.assertFalse(sm.fit(lfp, nfp))

        #Test anonymous fit.
        self.assertEqual(sm.fit_anonymous(lfp, nfp),
                         {Composition("Li"): Composition("Na")})
        self.assertAlmostEqual(sm.get_minimax_rms_anonymous(lfp, nfp)[0],
                               0.096084154118549828)

        #Test partial occupancies.
        s1 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]],
                       [{"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.5}],
                       [[0, 0, 0], [0.25, 0.25, 0.25],
                        [0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
        s2 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]],
                       [{"Fe": 0.25}, {"Fe": 0.5}, {"Fe": 0.5}, {"Fe": 0.75}],
                       [[0, 0, 0], [0.25, 0.25, 0.25],
                        [0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
        self.assertFalse(sm.fit(s1, s2))
        self.assertFalse(sm.fit(s2, s1))
        s2 = Structure([[3, 0, 0], [0, 3, 0], [0, 0, 3]],
                       [{"Fe": 0.25}, {"Fe": 0.25}, {"Fe": 0.25},
                        {"Fe": 0.25}],
                       [[0, 0, 0], [0.25, 0.25, 0.25],
                        [0.5, 0.5, 0.5], [0.75, 0.75, 0.75]])
        self.assertEqual(sm.fit_anonymous(s1, s2),
                         {Composition("Fe0.5"): Composition("Fe0.25")})

        self.assertAlmostEqual(sm.get_minimax_rms_anonymous(s1, s2)[0], 0)
开发者ID:materialsgenome,项目名称:pymatgen,代码行数:60,代码来源:test_structure_matcher.py


示例12: setUp

 def setUp(self):
     self.si = Element("Si")
     self.fe = Element("Fe")
     self.ge = Element("Ge")
     coords = list()
     coords.append(np.array([0, 0, 0]))
     coords.append(np.array([0.75, 0.5, 0.75]))
     lattice = Lattice.cubic(10)
     s = Structure(lattice, ["Si", "Fe"], coords)
     self.modifier = StructureEditor(s)
开发者ID:jesuansito,项目名称:pymatgen,代码行数:10,代码来源:test_structure_modifier.py


示例13: get_oxi_state_decorated_structure

    def get_oxi_state_decorated_structure(self, structure):
        """
        Get an oxidation state decorated structure. This currently works only
        for ordered structures only.

        Args:
            structure:
                Structure to analyze

        Returns:
            A modified structure that is oxidation state decorated.

        Raises:
            A ValueError is the valences cannot be determined.
        """
        valences = self.get_valences(structure)
        editor = StructureEditor(structure)
        editor.add_oxidation_state_by_site(valences)
        return editor.modified_structure
开发者ID:jesuansito,项目名称:pymatgen,代码行数:19,代码来源:bond_valence.py


示例14: best_first_ordering

    def best_first_ordering(self, structure, num_remove_dict):
        self.logger.debug("Performing best first ordering")
        starttime = time.time()
        self.logger.debug("Performing initial ewald sum...")
        ewaldsum = EwaldSummation(structure)
        self.logger.debug("Ewald sum took {} seconds."
                          .format(time.time() - starttime))
        starttime = time.time()

        ematrix = ewaldsum.total_energy_matrix
        to_delete = []

        totalremovals = sum(num_remove_dict.values())
        removed = {k: 0 for k in num_remove_dict.keys()}
        for i in xrange(totalremovals):
            maxindex = None
            maxe = float("-inf")
            maxindices = None
            for indices in num_remove_dict.keys():
                if removed[indices] < num_remove_dict[indices]:
                    for ind in indices:
                        if ind not in to_delete:
                            energy = sum(ematrix[:, ind]) + \
                                sum(ematrix[:, ind]) - ematrix[ind, ind]
                            if energy > maxe:
                                maxindex = ind
                                maxe = energy
                                maxindices = indices
            removed[maxindices] += 1
            to_delete.append(maxindex)
            ematrix[:, maxindex] = 0
            ematrix[maxindex, :] = 0
        mod = StructureEditor(structure)
        mod.delete_sites(to_delete)
        self.logger.debug("Minimizing Ewald took {} seconds."
                          .format(time.time() - starttime))
        return [{"energy": sum(sum(ematrix)),
                 "structure": mod.modified_structure.get_sorted_structure()}]
开发者ID:materialsgenome,项目名称:pymatgen,代码行数:38,代码来源:site_transformations.py


示例15: test_add_oxidation_states

 def test_add_oxidation_states(self):
     si = Element("Si")
     fe = Element("Fe")
     coords = list()
     coords.append([0, 0, 0])
     coords.append([0.75, 0.5, 0.75])
     lattice = Lattice.cubic(10)
     s = Structure(lattice, [si, fe], coords)
     oxidation_states = {"Fe": 2, "Si": -4}
     mod = StructureEditor(s)
     mod.add_oxidation_state_by_element(oxidation_states)
     mod_s = mod.modified_structure
     for site in mod_s:
         for k in site.species_and_occu.keys():
             self.assertEqual(k.oxi_state, oxidation_states[k.symbol],
                              "Wrong oxidation state assigned!")
     oxidation_states = {"Fe": 2}
     self.assertRaises(ValueError, mod.add_oxidation_state_by_element,
                       oxidation_states)
     mod.add_oxidation_state_by_site([2, -4])
     mod_s = mod.modified_structure
     self.assertEqual(mod_s[0].specie.oxi_state, 2)
     self.assertRaises(ValueError, mod.add_oxidation_state_by_site,
                       [1])
开发者ID:jesuansito,项目名称:pymatgen,代码行数:24,代码来源:test_structure_modifier.py


示例16: test_init

    def test_init(self):
        filepath = os.path.join(test_dir, 'POSCAR')
        p = Poscar.from_file(filepath)
        original_s = p.structure

        modifier = StructureEditor(original_s)
        modifier.add_oxidation_state_by_element({"Li": 1, "Fe": 2,
                                                 "P": 5, "O":-2})
        s = modifier.modified_structure
        ham = EwaldSummation(s)
        self.assertAlmostEqual(ham.real_space_energy, -354.91294268, 4,
                               "Real space energy incorrect!")
        self.assertAlmostEqual(ham.reciprocal_space_energy, 25.475754801, 4)
        self.assertAlmostEqual(ham.point_energy, -790.463835033, 4,
                               "Point space energy incorrect!")
        self.assertAlmostEqual(ham.total_energy, -1119.90102291, 2,
                               "Total space energy incorrect!")
        self.assertAlmostEqual(ham.forces[0,0], -1.98818620e-01, 4,
                               "Forces incorrect")
        self.assertAlmostEqual(sum(sum(abs(ham.forces))), 915.925354346, 4,
                               "Forces incorrect")
        self.assertAlmostEqual(sum(sum(ham.real_space_energy_matrix)),
                               - 354.91294268, 4,
                               "Real space energy matrix incorrect!")
        self.assertAlmostEqual(sum(sum(ham.reciprocal_space_energy_matrix)),
                               25.475754801, 4,
                               "Reciprocal space energy matrix incorrect!")
        self.assertAlmostEqual(sum(ham.point_energy_matrix), -790.463835033,
                               4, "Point space energy matrix incorrect!")
        self.assertAlmostEqual(sum(sum(ham.total_energy_matrix)),
                               - 1119.90102291, 2,
                               "Total space energy matrix incorrect!")
        #note that forces are not individually tested, but should work fine.

        self.assertRaises(ValueError, EwaldSummation, original_s)
        #try sites with charge.
        charges = []
        for site in original_s:
            if site.specie.symbol == "Li":
                charges.append(1)
            elif site.specie.symbol == "Fe":
                charges.append(2)
            elif site.specie.symbol == "P":
                charges.append(5)
            else:
                charges.append(-2)

        editor = StructureEditor(original_s)
        editor.add_site_property('charge', charges)
        ham2 = EwaldSummation(editor.modified_structure)
        self.assertAlmostEqual(ham2.real_space_energy, -354.91294268, 4,
                               "Real space energy incorrect!")
开发者ID:jesuansito,项目名称:pymatgen,代码行数:52,代码来源:test_ewald.py


示例17: StructureEditorTest

class StructureEditorTest(unittest.TestCase):

    def setUp(self):
        self.si = Element("Si")
        self.fe = Element("Fe")
        self.ge = Element("Ge")
        coords = list()
        coords.append(np.array([0, 0, 0]))
        coords.append(np.array([0.75, 0.5, 0.75]))
        lattice = Lattice.cubic(10)
        s = Structure(lattice, ["Si", "Fe"], coords)
        self.modifier = StructureEditor(s)

    def test_to_unit_cell(self):
        self.modifier.append_site(self.fe, [1.75, 0.5, 0.75],
                                  validate_proximity=False)
        self.modifier.to_unit_cell()
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si1",
                         "Wrong formula!")

    def test_to_unit_cell(self):
        self.modifier.apply_strain(0.01)
        self.assertEqual(self.modifier.modified_structure.lattice.abc,
                         (10.1, 10.1, 10.1))

    def test_translate_sites(self):
        self.modifier.translate_sites([0, 1], [0.5, 0.5, 0.5],
                                      frac_coords=True)
        self.assertTrue(np.array_equal(self.modifier.modified_structure
                                       .frac_coords[0],
                                       np.array([0.5, 0.5, 0.5])))

        self.modifier.translate_sites([0], [0.5, 0.5, 0.5], frac_coords=False)
        self.assertTrue(np.array_equal(self.modifier.modified_structure
                                       .cart_coords[0],
                                       np.array([5.5, 5.5, 5.5])))

    def test_append_site(self):
        self.modifier.append_site(self.si, [0, 0.5, 0])
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si2",
                         "Wrong formula!")
        self.assertRaises(ValueError, self.modifier.append_site, self.si,
                          np.array([0, 0.5, 0]))

    def test_modified_structure(self):
        self.modifier.insert_site(1, self.si, [0, 0.25, 0])
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si2",
                         "Wrong formula!")

        self.modifier.delete_site(0)
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si1",
                         "Wrong formula!")

        self.modifier.replace_site(0, self.ge)
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Ge1",
                         "Wrong formula!")

        self.modifier.append_site(self.si, [0, 0.75, 0])
        self.modifier.replace_species({self.si: self.ge})
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Ge2",
                         "Wrong formula!")

        self.modifier.replace_species({self.ge: {self.ge: 0.5, self.si: 0.5}})
        self.assertEqual(self.modifier.modified_structure.formula,
                         "Fe1 Si1 Ge1", "Wrong formula!")

        #this should change the .5Si .5Ge sites to .75Si .25Ge
        self.modifier.replace_species({self.ge: {self.ge: 0.5, self.si: 0.5}})
        self.assertEqual(self.modifier.modified_structure.formula,
                         "Fe1 Si1.5 Ge0.5", "Wrong formula!")

        d = 0.1
        pre_perturbation_sites = self.modifier.modified_structure.sites
        self.modifier.perturb_structure(distance=d)
        post_perturbation_sites = self.modifier.modified_structure.sites

        for i, x in enumerate(pre_perturbation_sites):
            self.assertAlmostEqual(x.distance(post_perturbation_sites[i]), d,
                                   3, "Bad perturbation distance")

    def test_add_site_property(self):
        self.modifier.add_site_property("charge", [4.1, 5])
        s = self.modifier.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[1].charge, 5)

        #test adding multiple properties.
        mod2 = StructureEditor(s)
        mod2.add_site_property("magmom", [3, 2])
        s = mod2.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[0].magmom, 3)

    def test_add_oxidation_states(self):
        si = Element("Si")
        fe = Element("Fe")
        coords = list()
        coords.append([0, 0, 0])
        coords.append([0.75, 0.5, 0.75])
        lattice = Lattice.cubic(10)
#.........这里部分代码省略.........
开发者ID:jesuansito,项目名称:pymatgen,代码行数:101,代码来源:test_structure_modifier.py


示例18: _calc_rms

    def _calc_rms(self, struct1, struct2, break_on_match):
        """
        Calculate RMS displacement between two structures

        Args:
            struct1:
                1st structure
            struct2:
                2nd structure
            break_on_match:
                True or False. Will break if the maximum
                    distance found is less than the
                    provided stol

        Returns:
            rms displacement normalized by (Vol / nsites) ** (1/3) and
            maximum distance found between two paired sites
        """
        stol = self.stol
        comparator = self._comparator
        #initial stored rms
        stored_rms = None

        if comparator.get_structure_hash(struct1) != \
                comparator.get_structure_hash(struct2):
            return None

        #primitive cell transformation
        if self._primitive_cell and struct1.num_sites != struct2.num_sites:
            struct1 = struct1.get_primitive_structure()
            struct2 = struct2.get_primitive_structure()

        # Same number of sites
        if struct1.num_sites != struct2.num_sites:
            return None

        # Get niggli reduced cells. Though technically not necessary, this
        # minimizes cell lengths and speeds up the matching of skewed
        # cells considerably.
        struct1 = struct1.get_reduced_structure(reduction_algo="niggli")
        struct2 = struct2.get_reduced_structure(reduction_algo="niggli")

        nl1 = struct1.lattice
        nl2 = struct2.lattice

        #rescale lattice to same volume
        if self._scale:
            scale_vol = (nl2.volume / nl1.volume) ** (1 / 6)
            se1 = StructureEditor(struct1)
            nl1 = Lattice(nl1.matrix * scale_vol)
            se1.modify_lattice(nl1)
            struct1 = se1.modified_structure
            se2 = StructureEditor(struct2)
            nl2 = Lattice(nl2.matrix / scale_vol)
            se2.modify_lattice(nl2)
            struct2 = se2.modified_structure

        #Volume to determine invalid lattices
        vol_tol = nl2.volume / 2

        #fractional tolerance of atomic positions (2x for initial fitting)
        frac_tol = \
            np.array([stol / ((1 - self.ltol) * np.pi) * i for
                      i in struct1.lattice.reciprocal_lattice.abc]) * \
            ((nl1.volume + nl2.volume) /
             (2 * struct1.num_sites)) ** (1.0 / 3)

        #generate structure coordinate lists
        species_list = []
        s1 = []
        for site in struct1:
            found = False
            for i, species in enumerate(species_list):
                if comparator.are_equal(site.species_and_occu, species):
                    found = True
                    s1[i].append(site.frac_coords)
                    break
            if not found:
                s1.append([site.frac_coords])
                species_list.append(site.species_and_occu)

        zipped = sorted(zip(s1, species_list), key=lambda x: len(x[0]))

        s1 = [x[0] for x in zipped]
        species_list = [x[1] for x in zipped]
        s2_cart = [[] for i in s1]

        for site in struct2:
            found = False
            for i, species in enumerate(species_list):
                if comparator.are_equal(site.species_and_occu, species):
                    found = True
                    s2_cart[i].append(site.coords)
                    break
                #if no site match found return None
            if not found:
                return None

        #check that sizes of the site groups are identical
        for f1, c2 in zip(s1, s2_cart):
#.........这里部分代码省略.........
开发者ID:thuwangming,项目名称:pymatgen,代码行数:101,代码来源:structure_matcher.py


示例19: StructureEditorTest

class StructureEditorTest(unittest.TestCase):

    def setUp(self):

        self.si = Element("Si")
        self.fe = Element("Fe")
        self.ge = Element("Ge")
        coords = list()
        coords.append(np.array([0, 0, 0]))
        coords.append(np.array([0.75, 0.5, 0.75]))
        lattice = Lattice.cubic(10)
        s = Structure(lattice, [self.si, self.fe], coords)
        self.modifier = StructureEditor(s)

    def test_translate_sites(self):
        self.modifier.translate_sites([0, 1], [0.5, 0.5, 0.5], frac_coords=True)
        self.assertTrue(np.array_equal(self.modifier.modified_structure.frac_coords[0], np.array([ 0.5, 0.5, 0.5])))

        self.modifier.translate_sites([0], [0.5, 0.5, 0.5], frac_coords=False)
        self.assertTrue(np.array_equal(self.modifier.modified_structure.cart_coords[0], np.array([ 5.5, 5.5, 5.5])))

    def test_append_site(self):
        self.modifier.append_site(self.si, [0, 0.5, 0])
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si2", "Wrong formula!")
        self.assertRaises(ValueError, self.modifier.append_site, self.si, np.array([0, 0.5, 0]))

    def test_modified_structure(self):
        self.modifier.insert_site(1, self.si, [0, 0.25, 0])
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si2", "Wrong formula!")

        self.modifier.delete_site(0)
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si1", "Wrong formula!")

        self.modifier.replace_site(0, self.ge)
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Ge1", "Wrong formula!")

        self.modifier.append_site(self.si, [0, 0.75, 0])
        self.modifier.replace_species({self.si: self.ge})
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Ge2", "Wrong formula!")

        self.modifier.replace_species({self.ge: {self.ge:0.5, self.si:0.5}})
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si1 Ge1", "Wrong formula!")

        #this should change the .5Si .5Ge sites to .75Si .25Ge
        self.modifier.replace_species({self.ge: {self.ge:0.5, self.si:0.5}})
        self.assertEqual(self.modifier.modified_structure.formula, "Fe1 Si1.5 Ge0.5", "Wrong formula!")

        d = 0.1
        pre_perturbation_sites = self.modifier.modified_structure.sites
        self.modifier.perturb_structure(distance=d)
        post_perturbation_sites = self.modifier.modified_structure.sites

        for i, x in enumerate(pre_perturbation_sites):
            self.assertAlmostEqual(x.distance(post_perturbation_sites[i]), d, 3, "Bad perturbation distance")

    def test_add_site_property(self):
        self.modifier.add_site_property("charge", [4.1, 5])
        s = self.modifier.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[1].charge, 5)

        #test adding multiple properties.
        mod2 = StructureEditor(s)
        mod2.add_site_property("magmom", [3, 2])
        s = mod2.modified_structure
        self.assertEqual(s[0].charge, 4.1)
        self.assertEqual(s[0].magmom, 3)
开发者ID:chenweis,项目名称:pymatgen,代码行数:67,代码来源:test_structure_modifier.py


示例20: apply_operation

def apply_operation(structure, symmop):
    editor = StructureEditor(structure)
    editor.apply_operation(symmop)
    return editor.modified_structure
开发者ID:chenweis,项目名称:pymatgen,代码行数:4,代码来源:structure_fitter.py



注:本文中的pymatgen.core.structure_modifier.StructureEditor类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python surface.SlabGenerator类代码示例发布时间:2022-05-25
下一篇:
Python structure.Structure类代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap