Esempio n. 1
0
    def test_init(self):
        """Test initialising MoleculeNamer."""
        mn = MoleculeNamer()
        self.assertTrue(mn)

        mn = MoleculeNamer(use_online_pubchem=False)
        self.assertTrue(mn)
Esempio n. 2
0
    def test_get_name_from_molecule_graph(self):
        """Test getting a molecule name from the molecule graph."""
        mn = MoleculeNamer()
        name = mn.get_name_from_molecule_graph(self.methylammonium)
        self.assertEqual(name, "methylammonium")

        # test iupac naming source
        mn = MoleculeNamer(name_preference=("iupac", ))
        name = mn.get_name_from_molecule_graph(self.methylammonium)
        self.assertEqual(name, "methylazanium")
    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
Esempio n. 4
0
 def test_get_name_from_pubchem(self):
     """Test downloading the molecule name from Pubchem."""
     mn = MoleculeNamer()
     name = mn.get_name_from_pubchem("C[NH3]")
     self.assertEqual(name, "methylammonium")
Esempio n. 5
0
 def test_molecule_graph_to_smiles(self):
     """Test converting a molecule graph to SMILES string."""
     smiles = MoleculeNamer.molecule_graph_to_smiles(self.methylammonium)
     self.assertEqual(smiles, "C[NH3]")