Пример #1
0
    def test_get_inequivalent_site_indices(self):
        sa = SiteAnalyzer(self.ba_n, use_symmetry_equivalent_sites=False)
        inequiv_indices = sa.get_inequivalent_site_indices(list(range(6)))
        self.assertEqual(inequiv_indices, [0, 0, 0, 0, 4, 4])

        # test using symmetry to determine inequivalent sites.
        sa = SiteAnalyzer(self.ba_n, use_symmetry_equivalent_sites=True)
        inequiv_indices = sa.get_inequivalent_site_indices(list(range(6)))
        self.assertEqual(inequiv_indices, [0, 0, 0, 0, 4, 4])

        # test symprec option
        sa = SiteAnalyzer(self.ba_n,
                          use_symmetry_equivalent_sites=True,
                          symprec=0.000001)
        inequiv_indices = sa.get_inequivalent_site_indices(list(range(6)))
        self.assertEqual(inequiv_indices, [0, 1, 1, 0, 4, 4])
    def _condense_components(
        self,
        components: List[Component],
        spacegroup_analyzer: SpacegroupAnalyzer,
        site_analyzer: SiteAnalyzer,
    ) -> Tuple[Dict[int, Any], List[int]]:
        """Condenses the component data.

        Args:
            components: A list of structure components, generated using
                :obj:`pymatgen.analysis.dimensionality.get_structure_components`
            site_analyzer: A site analyzer object for the structure containing
                the components.
            spacegroup_analyzer: A space group analyzer object for the structure
                containing the components.

        Returns:
            The condensed component data and the component makeup of the
            structure. The condensed components have the form::

                {
                    0: {
                        'formula': 'MoS2',
                        'sites': [0, 2]
                        'dimensionality': 2,
                        'molecule_name': None,
                        'orientation': (0, 0, 1)
                    }
                }

            Where the ``0`` key is the component identifier. The ``sites``
            key gives a :obj:`list` of the indexes of the inequivalent sites
            in the structure. If the component is zero-dimensional and
            is a known molecule, the ``molecule_name`` key will be a :obj:`str`
            with the molecule name. The ``orientation`` key is the miller
            index (for two-dimensional components) or direction of propagation
            (for one-dimensional components).
        """
        if self.use_symmetry_equivalent_sites:
            inequiv_components = get_sym_inequiv_components(
                components, spacegroup_analyzer)
        else:
            inequiv_components = get_structure_inequiv_components(components)

        molecule_namer = MoleculeNamer()

        components = {}
        component_makeup = []
        for i, component in enumerate(inequiv_components):
            formula = get_component_formula(
                component,
                use_iupac_formula=self.use_iupac_formula,
                use_common_formulas=self.use_common_formulas,
            )

            sites = site_analyzer.get_inequivalent_site_indices(
                component["site_ids"])

            if component["dimensionality"] == 0:
                molecule_name = molecule_namer.get_name_from_molecule_graph(
                    component["molecule_graph"])
            else:
                molecule_name = None

            components[i] = {
                "formula": formula,
                "dimensionality": component["dimensionality"],
                "orientation": component["orientation"],
                "molecule_name": molecule_name,
                "sites": sites,
            }
            component_makeup.extend([i] * component["count"])

        return components, component_makeup