def test_ge__(self):
     pse = PeriodicTable()
     pse.add_element("O", "O_up", spin="up")
     o_1 = pse.element("O")
     o_2 = pse.element("O")
     self.assertTrue(o_1 <= o_2)
     self.assertTrue(o_1 >= o_2)
예제 #2
0
 def setUpClass(cls):
     cls.file_location = os.path.dirname(os.path.abspath(__file__))
     cls.project = Project(
         os.path.join(cls.file_location, "../static/sphinx"))
     pt = PeriodicTable()
     pt.add_element(parent_element="Fe", new_element="Fe_up", spin="0.5")
     Fe_up = pt.element("Fe_up")
     cls.basis = Atoms(
         elements=[Fe_up, Fe_up],
         scaled_positions=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]],
         cell=2.6 * np.eye(3),
     )
     cls.sphinx = cls.project.create_job("Sphinx", "job_sphinx")
     cls.sphinx_band_structure = cls.project.create_job(
         "Sphinx", "sphinx_test_bs")
     cls.sphinx_2_3 = cls.project.create_job("Sphinx", "sphinx_test_2_3")
     cls.sphinx_2_5 = cls.project.create_job("Sphinx", "sphinx_test_2_5")
     cls.sphinx_aborted = cls.project.create_job("Sphinx",
                                                 "sphinx_test_aborted")
     cls.sphinx.structure = cls.basis
     cls.sphinx.fix_spin_constraint = True
     cls.sphinx_band_structure.structure = cls.project.create_structure(
         "Fe", "bcc", 2.81)
     cls.sphinx_band_structure.structure = cls.sphinx_band_structure.structure.create_line_mode_structure(
     )
     cls.sphinx_2_3.structure = Atoms(
         elements=["Fe", "Fe"],
         scaled_positions=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]],
         cell=2.6 * np.eye(3),
     )
     cls.sphinx_2_5.structure = Atoms(
         elements=["Fe", "Ni"],
         scaled_positions=[[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]],
         cell=2.83 * np.eye(3),
     )
     cls.sphinx_2_5.structure.set_initial_magnetic_moments([2, 2])
     cls.sphinx_aborted.structure = Atoms(
         elements=32 * ["Fe"],
         scaled_positions=np.arange(32 * 3).reshape(-1, 3) / (32 * 3),
         cell=3.5 * np.eye(3),
     )
     cls.sphinx_aborted.status.aborted = True
     cls.current_dir = os.path.abspath(os.getcwd())
     cls.sphinx._create_working_directory()
     cls.sphinx_2_3._create_working_directory()
     cls.sphinx.input["VaspPot"] = False
     cls.sphinx.structure.add_tag(selective_dynamics=(True, True, True))
     cls.sphinx.structure.selective_dynamics[1] = (False, False, False)
     cls.sphinx.load_default_groups()
     cls.sphinx.fix_symmetry = False
     cls.sphinx.write_input()
     cls.sphinx_2_3.to_hdf()
     cls.sphinx_2_3.decompress()
     cls.sphinx_2_5.decompress()
     cls.sphinx_2_5.collect_output()
 def test__eq__(self):
     pse = PeriodicTable()
     pse.add_element("O", "O_up", spin="up")
     o_up = pse.element("O_up")
     o_1 = pse.element("O")
     o_2 = pse.element("O")
     h_1 = pse.element("H")
     self.assertNotEqual(o_up, o_1)
     self.assertNotEqual(o_up, o_2)
     self.assertEqual(o_1, o_2)
     self.assertNotEqual(o_1, h_1)
 def test_gt__(self):
     pse = PeriodicTable()
     pse.add_element("O", "O_up", spin="up")
     o_up = pse.element("O_up")
     o_1 = pse.element("O")
     o_2 = pse.element("O")
     h_1 = pse.element("H")
     self.assertTrue(o_up > o_1)
     self.assertFalse(o_up < o_2)
     self.assertFalse(o_1 > o_2)
     self.assertFalse(o_1 < o_2)
     self.assertTrue(o_1 > h_1)
     self.assertTrue(o_up > h_1)
예제 #5
0
    def element(parent_element,
                new_element_name=None,
                spin=None,
                potential_file=None):
        """

        Args:
            parent_element (str, int): The parent element eq. "N", "O", "Mg" etc.
            new_element_name (str): The name of the new parent element (can be arbitrary)
            spin (float): Value of the magnetic moment (with sign)
            potential_file (str): Location of the new potential file if necessary

        Returns:
            atomistics.structure.periodic_table.ChemicalElement instance
        """
        periodic_table = PeriodicTable()
        if new_element_name is None:
            if spin is not None:
                new_element_name = (parent_element + "_spin_" +
                                    str(spin).replace(".", "_"))
            else:
                new_element_name = parent_element + "_1"
        if potential_file is not None:
            if spin is not None:
                periodic_table.add_element(
                    parent_element=parent_element,
                    new_element=new_element_name,
                    spin=str(spin),
                    pseudo_potcar_file=potential_file,
                )
            else:
                periodic_table.add_element(
                    parent_element=parent_element,
                    new_element=new_element_name,
                    pseudo_potcar_file=potential_file,
                )
        elif spin is not None:
            periodic_table.add_element(
                parent_element=parent_element,
                new_element=new_element_name,
                spin=str(spin),
            )
        else:
            periodic_table.add_element(parent_element=parent_element,
                                       new_element=new_element_name)
        return periodic_table.element(new_element_name)
예제 #6
0
    def parse_atom_information_to_dict(self, node, d):
        """
        Parses atom information from a node to a dictionary

        Args:
            node (xml.etree.Element instance): The node to parse
            d (dict): The dictionary to which data is to be parsed
        """
        if not (node.tag == "atominfo"):
            raise AssertionError()
        species_dict = OrderedDict()
        for leaf in node:
            if leaf.tag == "atoms":
                d["n_atoms"] = self._parse_vector(leaf)[0]
            if leaf.tag == "types":
                d["n_species"] = self._parse_vector(leaf)[0]
            if leaf.tag == "array":
                if leaf.attrib["name"] == "atomtypes":
                    for item in leaf:
                        if item.tag == "set":
                            for sp in item:
                                elements = sp
                                if elements[1].text in species_dict.keys():
                                    pse = PeriodicTable()
                                    count = 1
                                    not_unique = True
                                    species_key = None
                                    while not_unique:
                                        species_key = "_".join(
                                            [elements[1].text,
                                             str(count)])
                                        if species_key not in species_dict.keys(
                                        ):
                                            not_unique = False
                                        else:
                                            count += 1
                                    if species_key is not None:
                                        pse.add_element(
                                            clean_character(elements[1].text),
                                            species_key,
                                        )
                                        special_element = pse.element(
                                            species_key)
                                        species_dict[special_element] = dict()
                                        species_dict[special_element][
                                            "n_atoms"] = int(elements[0].text)
                                        species_dict[special_element][
                                            "valence"] = float(
                                                elements[3].text)
                                else:
                                    species_key = elements[1].text
                                    species_dict[species_key] = dict()
                                    species_dict[species_key]["n_atoms"] = int(
                                        elements[0].text)
                                    species_dict[species_key][
                                        "valence"] = float(elements[3].text)
        d["species_dict"] = species_dict
        species_list = list()
        for key, val in species_dict.items():
            for sp in np.tile([key], species_dict[key]["n_atoms"]):
                species_list.append(clean_character(sp))
        d["species_list"] = species_list