def test_make_calc_summary(mocker):
    defect_entry = mocker.Mock(spec=DefectEntry, autospec=True)
    defect_entry.name = "Va_O1"
    defect_entry.charge = 1
    defect_entry.full_name = "Va_O1_1"

    calc_results = mocker.Mock(spec=CalcResults, autospec=True)
    calc_results.structure = \
        IStructure(Lattice.cubic(1.0), ["Mg"], [[0.0]*3])
    calc_results.energy = 10.0 + defaults.abs_strange_energy - 0.1

    structure_info = mocker.Mock(spec=DefectStructureInfo, autospec=True)

    p_calc_results = mocker.Mock(spec=CalcResults, autospec=True)
    p_calc_results.structure = \
        IStructure(Lattice.cubic(1.0), ["Mg", "O"], [[0.0]*3]*2)
    p_calc_results.energy = 10.0

    actual = make_calc_summary(calc_set=[(calc_results, defect_entry,
                                          structure_info)],
                               p_calc_results=p_calc_results)
    single_summary = SingleCalcSummary(
        charge=1,
        atom_io={"O": -1},
        electronic_conv=calc_results.electronic_conv,
        ionic_conv=calc_results.ionic_conv,
        is_energy_strange=False,
        same_config_from_init=structure_info.same_config_from_init,
        defect_type=str(structure_info.defect_type),
        symm_relation=str(structure_info.symm_relation))
    expected = CalcSummary({"Va_O1_1": single_summary})

    assert actual == expected
    def test_get_supercell_size(self):
        l = Lattice.cubic(1)
        l2 = Lattice.cubic(0.9)
        s1 = Structure(l, ['Mg', 'Cu', 'Ag', 'Cu', 'Ag'], [[0]*3]*5)
        s2 = Structure(l2, ['Cu', 'Cu', 'Ag'], [[0]*3]*3)

        sm = StructureMatcher(supercell_size='volume')
        self.assertEqual(sm._get_supercell_size(s1, s2),
                         (1, True))
        self.assertEqual(sm._get_supercell_size(s2, s1),
                         (1, True))

        sm = StructureMatcher(supercell_size='num_sites')
        self.assertEqual(sm._get_supercell_size(s1, s2),
                         (2, False))
        self.assertEqual(sm._get_supercell_size(s2, s1),
                         (2, True))

        sm = StructureMatcher(supercell_size='Ag')
        self.assertEqual(sm._get_supercell_size(s1, s2),
                         (2, False))
        self.assertEqual(sm._get_supercell_size(s2, s1),
                         (2, True))

        sm = StructureMatcher(supercell_size='wfieoh')
        self.assertRaises(ValueError, sm._get_supercell_size, s1, s2)
Example #3
0
def test_judge_defect_type():
    """The structures remain as they could be used in the future"""
    perfect = Structure(Lattice.cubic(10), species=["H"]*4,
                        coords=[[0.0, 0.0, 0.0], [0.0, 0.5, 0.5],
                                [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]])
    defect = Structure(Lattice.cubic(10), species=["H"]*3,
                       coords=[[0.0, 0.0, 0.0], [0.25, 0.25, 0.5],
                               [0.5, 0.5, 0.0]])
    site_diff = SiteDiff(removed=[(1, "H", (0.0, 0.5, 0.5)),
                                  (2, "H", (0.5, 0.0, 0.5))],
                         inserted=[(1, "H", (0.25, 0.25, 0.5))],
                         removed_by_sub=[], inserted_by_sub=[])
    assert judge_defect_type(site_diff) == DefectType.vacancy_split

    defect_2 = Structure(Lattice.cubic(10), species=["H"]*5,
                         coords=[[0.0, 0.0, 0.0], [0.25, 0.25, 0.5],
                                 [0.75, 0.25, 0.5], [0.25, 0.75, 0.5],
                                 [0.5, 0.5, 0.0]])
    site_diff_2 = SiteDiff(removed=[(1, "H", (0.0, 0.5, 0.5)),
                                    (2, "H", (0.5, 0.0, 0.5))],
                           inserted=[(1, "H", (0.25, 0.25, 0.5)),
                                     (2, "H", (0.75, 0.25, 0.5)),
                                     (3, "H", (0.25, 0.75, 0.5))],
                           removed_by_sub=[], inserted_by_sub=[])
    assert judge_defect_type(site_diff_2) == DefectType.interstitial_split

    defect_3 = Structure(Lattice.cubic(10), species=["H", "He", "H"],
                         coords=[[0.0, 0.0, 0.0], [0.25, 0.25, 0.5],
                                 [0.5, 0.5, 0.0]])
    site_diff_3 = SiteDiff(removed=[(1, "H", (0.0, 0.5, 0.5)),
                                    (2, "H", (0.5, 0.0, 0.5))],
                           inserted=[(1, "He", (0.25, 0.25, 0.5))],
                           removed_by_sub=[], inserted_by_sub=[])

    assert judge_defect_type(site_diff_3) == DefectType.unknown
Example #4
0
def test_make_defect_entry(defect_entry):
    relaxed_coords = \
        [[0.25, 0.0, 0.0], [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5],
         [0.0, 0.0, 0.51], [0.0, 0.51, 0.0], [0.5, 0.0, 0.0], [0.5, 0.5, 0.5]]
    relaxed_defect = IStructure(Lattice.cubic(10.0),
                                ["Li"] + ["H"] * 3 + ["He"] * 4,
                                relaxed_coords)

    unrelaxed_coords = \
        [[0.25, 0.0, 0.0], [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5],
         [0.0, 0.0, 0.5], [0.0, 0.5, 0.0], [0.5, 0.0, 0.0], [0.5, 0.5, 0.5]]

    unrelaxed_defect = IStructure(Lattice.cubic(10.0),
                                  ["Li"] + ["H"] * 3 + ["He"] * 4,
                                  unrelaxed_coords)

    actual = make_defect_entry(name="Va_O1",
                               charge=1,
                               perfect_structure=perfect,
                               defect_structure=relaxed_defect)

    expected = DefectEntry(name="Va_O1",
                           charge=1,
                           structure=unrelaxed_defect,
                           perturbed_structure=None,
                           site_symmetry="4mm",
                           defect_center=(0.125, 0.0, 0.0))

    assert actual == expected
def test_make_defect_energy_info(mocker):
    defect_entry = mocker.Mock(DefectEntry, autospec=True)
    defect_entry.name = "Va_Mg1"
    defect_entry.charge = -1

    calc_results = mocker.Mock(CalcResults, autospec=True)
    calc_results.structure = IStructure(Lattice.cubic(1.0), ["O"], [[0.0]*3])
    calc_results.energy = 10.0
    calc_results.electronic_conv = False

    correction = mocker.Mock(Correction, autospec=True)
    correction.correction_dict = {"a": 10.0}

    p_calc_results = mocker.Mock(CalcResults, autospec=True)
    p_calc_results.structure = IStructure(Lattice.cubic(1.0),
                                          ["Mg", "O"], [[0.0]*3]*2)
    p_calc_results.energy = 1.0

    standard_energies = StandardEnergies({"Mg": 10.0, "O": 20.0})

    unitcell = mocker.Mock()
    unitcell.vbm = 100.0

    actual = make_defect_energy_info(defect_entry, calc_results, correction,
                                     p_calc_results, standard_energies, unitcell)
    energy = DefectEnergy(formation_energy=10.0 - 1.0 + 10 - 100.0,
                          energy_corrections={"a": 10.0},
                          is_shallow=None)
    expected = DefectEnergyInfo(name="Va_Mg1", charge=-1,
                                atom_io={"Mg": -1}, defect_energy=energy)
    assert actual == expected
    def test_get_supercell_size(self):
        l = Lattice.cubic(1)
        l2 = Lattice.cubic(0.9)
        s1 = Structure(l, ['Mg', 'Cu', 'Ag', 'Cu', 'Ag'], [[0]*3]*5)
        s2 = Structure(l2, ['Cu', 'Cu', 'Ag'], [[0]*3]*3)

        sm = StructureMatcher(supercell_size='volume')
        self.assertEqual(sm._get_supercell_size(s1, s2),
                         (1, True))
        self.assertEqual(sm._get_supercell_size(s2, s1),
                         (1, True))

        sm = StructureMatcher(supercell_size='num_sites')
        self.assertEqual(sm._get_supercell_size(s1, s2),
                         (2, False))
        self.assertEqual(sm._get_supercell_size(s2, s1),
                         (2, True))

        sm = StructureMatcher(supercell_size='Ag')
        self.assertEqual(sm._get_supercell_size(s1, s2),
                         (2, False))
        self.assertEqual(sm._get_supercell_size(s2, s1),
                         (2, True))

        sm = StructureMatcher(supercell_size='wfieoh')
        self.assertRaises(ValueError, sm._get_supercell_size, s1, s2)
Example #7
0
def structure_comparator():
    cu2o_perfect = IStructure(
        Lattice.cubic(5),
        species=["Cu"] * 4 + ["O"] * 2,
        coords=[
            [0.25, 0.25, 0.25],  # removed
            [0.25, 0.74, 0.74],  # removed
            [0.75, 0.75, 0.25],
            [0.75, 0.25, 0.75],
            [0, 0, 0],
            [0.5, 0.5, 0.5]
        ])
    cu2o_defect = IStructure(
        Lattice.cubic(5),
        species=["Cu"] * 3 + ["O"] * 2 + ["H"],
        coords=[
            [0.25, 0.5, 0.5],  # inserted
            [0.76, 0.73, 0.24],
            [0.75, 0.25, 0.73],
            [0.05, 0.95, 0],
            [0.5, 0.5, 0.5],
            [0.25] * 3
        ])  # inserted

    return DefectStructureComparator(defect_structure=cu2o_defect,
                                     perfect_structure=cu2o_perfect)
Example #8
0
    def get_unit_cell(specie, lattice, alat):
        """
        Get the unit cell from specie, lattice type and lattice constant.

        Args
            specie (str): Name of specie.
            lattice (str): The lattice type of structure. e.g. bcc or diamond.
            alat (float): The lattice constant of specific lattice and specie.
        """
        if lattice == "fcc":
            unit_cell = Structure.from_spacegroup(sg="Fm-3m",
                                                  lattice=Lattice.cubic(alat),
                                                  species=[specie],
                                                  coords=[[0, 0, 0]])
        elif lattice == "bcc":
            unit_cell = Structure.from_spacegroup(sg="Im-3m",
                                                  lattice=Lattice.cubic(alat),
                                                  species=[specie],
                                                  coords=[[0, 0, 0]])
        elif lattice == "diamond":
            unit_cell = Structure.from_spacegroup(sg="Fd-3m",
                                                  lattice=Lattice.cubic(alat),
                                                  species=[specie],
                                                  coords=[[0, 0, 0]])
        else:
            raise ValueError("Lattice type is invalid.")

        return unit_cell
Example #9
0
    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]))
        self.struct_list[1].apply_operation(op)
        self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))

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

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

        #Test anonymous fit.
        self.assertEqual(sm.fit_anonymous(lfp, nfp), True)
        self.assertAlmostEqual(sm.get_rms_anonymous(lfp, nfp)[0],
                               0.060895871160262717)

        #Test partial occupancies.
        s1 = Structure(Lattice.cubic(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(Lattice.cubic(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(Lattice.cubic(3),
                       [{"Mn": 0.5}, {"Mn": 0.5}, {"Mn": 0.5},
                        {"Mn": 0.5}],
                       [[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), True)

        self.assertAlmostEqual(sm.get_rms_anonymous(s1, s2)[0], 0)
    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]))
        self.struct_list[1].apply_operation(op)
        self.assertTrue(sm.fit(self.struct_list[0], self.struct_list[1]))

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

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

        #Test anonymous fit.
        self.assertEqual(sm.fit_anonymous(lfp, nfp), True)
        self.assertAlmostEqual(sm.get_rms_anonymous(lfp, nfp)[0],
                               0.060895871160262717)

        #Test partial occupancies.
        s1 = Structure(Lattice.cubic(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(Lattice.cubic(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(Lattice.cubic(3),
                       [{"Mn": 0.5}, {"Mn": 0.5}, {"Mn": 0.5},
                        {"Mn": 0.5}],
                       [[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), True)

        self.assertAlmostEqual(sm.get_rms_anonymous(s1, s2)[0], 0)
Example #11
0
    def setUp(self):

        self.maxDiff = None

        # trivial example, simple square lattice for testing
        structure = Structure(Lattice.tetragonal(5.0, 50.0), ["H"], [[0, 0, 0]])
        self.square_sg = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="")
        self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0))
        self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
        self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0))
        self.square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))
        # TODO: decorating still fails because the structure graph gives a CN of 8 for this square lattice
        # self.square_sg.decorate_structure_with_ce_info()

        # body-centered square lattice for testing
        structure = Structure(Lattice.tetragonal(5.0, 50.0), ["H", "He"], [[0, 0, 0], [0.5, 0.5, 0.5]])
        self.bc_square_sg = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="")
        self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0))
        self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
        self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0))
        self.bc_square_sg.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))
        self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, 0, 0))
        self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
        self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(-1, -1, 0))
        self.bc_square_sg.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))

        # body-centered square lattice for testing
        # directions reversed, should be equivalent to bc_square
        structure = Structure(Lattice.tetragonal(5.0, 50.0), ["H", "He"], [[0, 0, 0], [0.5, 0.5, 0.5]])
        self.bc_square_sg_r = StructureGraph.with_empty_graph(structure, edge_weight_name="", edge_weight_units="")
        self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(1, 0, 0))
        self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(-1, 0, 0))
        self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, 1, 0))
        self.bc_square_sg_r.add_edge(0, 0, from_jimage=(0, 0, 0), to_jimage=(0, -1, 0))
        self.bc_square_sg_r.add_edge(0, 1, from_jimage=(0, 0, 0), to_jimage=(0, 0, 0))
        self.bc_square_sg_r.add_edge(1, 0, from_jimage=(-1, 0, 0), to_jimage=(0, 0, 0))
        self.bc_square_sg_r.add_edge(1, 0, from_jimage=(-1, -1, 0), to_jimage=(0, 0, 0))
        self.bc_square_sg_r.add_edge(1, 0, from_jimage=(0, -1, 0), to_jimage=(0, 0, 0))

        # MoS2 example, structure graph obtained from critic2
        # (not ground state, from mp-1023924, single layer)
        stdout_file = os.path.join(PymatgenTest.TEST_FILES_DIR, "critic2/MoS2_critic2_stdout.txt")
        with open(stdout_file) as f:
            reference_stdout = f.read()
        self.structure = Structure.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "critic2/MoS2.cif"))
        c2o = Critic2Analysis(self.structure, reference_stdout)
        self.mos2_sg = c2o.structure_graph(include_critical_points=False)

        latt = Lattice.cubic(4.17)
        species = ["Ni", "O"]
        coords = [[0, 0, 0], [0.5, 0.5, 0.5]]
        self.NiO = Structure.from_spacegroup(225, latt, species, coords).get_primitive_structure()

        # BCC example.
        self.bcc = Structure(Lattice.cubic(5.0), ["He", "He"], [[0, 0, 0], [0.5, 0.5, 0.5]])

        warnings.simplefilter("ignore")
Example #12
0
 def setUp(self):
     self.gnd_real = Structure.from_file(TEST_FILES / 'POSCAR.C0.gz')
     self.exd_real = Structure.from_file(TEST_FILES / 'POSCAR.C-.gz')
     self.gnd_test = Structure(Lattice.cubic(1.), ['H'], [[0., 0., 0.]])
     self.exd_test = Structure(Lattice.cubic(1.), ['H'], [[0.5, 0.5, 0.5]])
     self.sct_test = Structure(Lattice.cubic(1.), ['H'],
                               [[0.25, 0.25, 0.25]])
     self.vrs = [TEST_FILES / 'vasprun.xml.0.gz'] + \
         glob.glob(str(TEST_FILES / 'lower' / '*' / 'vasprun.xml.gz'))
Example #13
0
 def setUp(self):
     c1 = [[0.5] * 3, [0.9] * 3]
     c2 = [[0.5] * 3, [0.9, 0.1, 0.1]]
     s1 = Structure(Lattice.cubic(5), ['Si', 'Si'], c1)
     s2 = Structure(Lattice.cubic(5), ['Si', 'Si'], c2)
     structs = []
     for s in s1.interpolate(s2, 3, pbc=True):
         structs.append(Structure.from_sites(s.sites, to_unit_cell=True))
     self.structures = structs
     self.vis = MITNEBSet(self.structures)
Example #14
0
 def setUp(self):
     c1 = [[0.5] * 3, [0.9] * 3]
     c2 = [[0.5] * 3, [0.9, 0.1, 0.1]]
     s1 = Structure(Lattice.cubic(5), ['Si', 'Si'], c1)
     s2 = Structure(Lattice.cubic(5), ['Si', 'Si'], c2)
     structs = []
     for s in s1.interpolate(s2, 3, pbc=True):
         structs.append(Structure.from_sites(s.sites, to_unit_cell=True))
     self.structures = structs
     self.vis = MITNEBSet(self.structures)
Example #15
0
def structure_comparator_periodic_issue():
    cu2o_perfect = IStructure(Lattice.cubic(5),
                              species=["Cu"] * 4 + ["O"] * 2,
                              coords=[[0.25, 0.25, 0.25], [0.25, 0.75, 0.75],
                                      [0.75, 0.75, 0.25], [0.75, 0.25, 0.75],
                                      [0, 0, 0], [0.5, 0.5, 0.5]])
    # defect center is ([1.0, 1.0, 1.0] + [0.99, 0.99, 0.99]) / 2 = [0.995]*3
    cu2o_defect = IStructure(Lattice.cubic(5),
                             species=["Cu"] * 4 + ["O"] + ["H"],
                             coords=[[0.25, 0.25, 0.25], [0.25, 0.75, 0.75],
                                     [0.75, 0.75, 0.25], [0.75, 0.25, 0.75],
                                     [0.5, 0.5, 0.5], [0.99, 0.99, 0.99]])

    return DefectStructureComparator(defect_structure=cu2o_defect,
                                     perfect_structure=cu2o_perfect)
def test_make_defect_structure_info2():
    perf = Structure(Lattice.cubic(1), ["H"], [[0., 0., 0.]])
    init = Structure(Lattice.cubic(1), ["H"] * 2,
                     [[0., 0., 0.], [0.5, 0.0, 0.0]])
    fin = Structure(Lattice.cubic(1), ["H"] * 2,
                    [[0., 0., 0.], [0.4, 0.0, 0.0]])

    info = MakeDefectStructureInfo(perf,
                                   init,
                                   fin,
                                   dist_tol=0.05,
                                   symprec=0.1,
                                   neighbor_cutoff_factor=1.2)
    actual = info.defect_structure_info
    print(actual)
Example #17
0
def test_make_poscars_from_query(tmpdir):
    mg_structure = Structure(Lattice.cubic(1), species=["Mg", "Mg"],
                             coords=[[0, 0, 0], [0.5, 0.5, 0.5]])

    query = [{"full_formula": "Mg2", "task_id": "mp-1",
              "total_magnetization": 0.1,
              "band_gap": 0.0,
              "structure": mg_structure},
             {"full_formula": "O16"}]
    make_poscars_from_query(query, path=Path(tmpdir))
    tmpdir.chdir()
    s_mg = Structure.from_file(Path("Mg_mp-1") / "POSCAR")
    assert s_mg == mg_structure

    actual = loadfn(Path("Mg_mp-1") / "prior_info.yaml")
    expected = {'band_gap': 0.0, 'data_source': 'mp-1', 'total_magnetization': 0.1}
    assert actual == expected

    actual = Structure.from_file(Path("mol_O2") / "POSCAR")
    expected = Structure.from_str("""Default POSCAR of O2 molecule
   1.00000000000000     
    10.0000000000000000    0.0000000000000000    0.0000000000000000
     0.0000000000000000   10.0000000000000000    0.0000000000000000
     0.0000000000000000    0.0000000000000000   10.0000000000000000
   O 
     2
Direct
  0.0145089778962415  0.0000000000000000  0.0000000000000000
  0.1354910221037571  0.0000000000000000  0.0000000000000000""", fmt="POSCAR")
    assert actual == expected
Example #18
0
 def test_two_targets(self):
     s = Structure(Lattice.cubic(3), ["Si"], [[0, 0, 0]])
     with ScratchDir("."):
         # initialize the model
         self.model2.train([s, s], [[0.1, 0.2], [0.1, 0.2]], epochs=1)
         pred = self.model2.predict_structure(s)
         self.assertEqual(len(pred.ravel()), 2)
Example #19
0
    def bi(self):
        """Return BCC Bi structure."""

        bcc_bi = Structure.from_spacegroup("Im-3m", Lattice.cubic(3.453),
                                           ["Bi"], [[0, 0, 0]])
        bcc_bi = bcc_bi.get_reduced_structure("niggli")
        return bcc_bi
Example #20
0
 def test_writestring(self):
     # Test for the string export of s atructure into the exciting input xml schema
     input_string = (
         '<input xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
         'xsi:noNamespaceSchemaLocation="http://xml.exciting-code.org/excitinginput'
         '.xsd">\n  <title>Na4 Cl4</title>\n  <structure speciespath="./">\n    '
         '<crystal scale="1.8897543768634038">\n      <basevect>      5.62000000'
         '       0.00000000       0.00000000</basevect>\n      <basevect>      '
         '0.00000000       5.62000000       0.00000000</basevect>\n      '
         '<basevect>      0.00000000       0.00000000       5.62000000</basevect>'
         '\n    </crystal>\n    <species speciesfile="Na.xml">\n      <atom coord='
         '"      0.00000000       0.00000000       0.00000000" />\n      <atom coor'
         'd="      0.50000000       0.50000000       0.00000000" />\n      <atom co'
         'ord="      0.50000000       0.00000000       0.50000000" />\n      <atom '
         'coord="      0.00000000       0.50000000       0.50000000" />\n    </spec'
         'ies>\n    <species speciesfile="Cl.xml">\n      <atom coord="      0.5000'
         '0000       0.00000000       0.00000000" />\n      <atom coord="      0.00'
         '000000       0.50000000       0.00000000" />\n      <atom coord="      0.'
         '00000000       0.00000000       0.50000000" />\n      <atom coord="      '
         '0.50000000       0.50000000       0.50000000" />\n    </species>\n  </str'
         'ucture>\n</input>\n')
     lattice = Lattice.cubic('5.62')
     structure = Structure(
         lattice, ['Na', 'Na', 'Na', 'Na', 'Cl', 'Cl', 'Cl', 'Cl'],
         [[0, 0, 0], [0.5, 0.5, 0.0], [0.5, 0.0, 0.5], [0.0, 0.5, 0.5],
          [0.5, 0.0, 0.0], [0.0, 0.5, 0.0], [0.0, 0.0, 0.5],
          [0.5, 0.5, 0.5]])
     excin = ExcitingInput(structure)
     for l1, l2 in zip(input_string.split("\n"),
                       excin.write_string('unchanged').split("\n")):
         if not l1.strip().startswith("<crystal scale"):
             self.assertEqual(l1.strip(), l2.strip())
Example #21
0
def test_equality_of_sqs_objects():
    """SQS structures with different underlying crystal structures are equivalent iff sublattice models are equivalent."""
    config = [['A', 'B'], ['A']]
    occupancy = [[0.5, 0.5], [1]]
    site_ratios = [3, 1]
    # Use same sublattice for different underlying structures. Should be equal
    s1 = PRLStructure(Lattice.hexagonal(1, 2), ['Mg', 'Mg'],
                      [[0, 0, 0], [0.3333, 0.66666, 0.5]],
                      sublattice_configuration=config,
                      sublattice_occupancies=occupancy,
                      sublattice_site_ratios=site_ratios)
    s2 = PRLStructure(Lattice.cubic(1), ['Fe'], [[0, 0, 0]],
                      sublattice_configuration=config,
                      sublattice_occupancies=occupancy,
                      sublattice_site_ratios=site_ratios)
    assert s1 == s2

    # Use same underlying crystal structures, but different sublattice configurations. Should be not equal
    s1.sublattice_site_ratios = [2, 1]
    assert s1 != s2
    s1.sublattice_site_ratios = site_ratios

    s1.sublattice_occupancies = [[0.25, 0.5], [1]]
    assert s1 != s2
    s1.sublattice_occupancies = occupancy

    s1.sublattice_configuration = [['A', 'A'], ['A']]
    assert s1 != s2
    s1.sublattice_configuration = config

    assert s1 == s2
Example #22
0
def make_atom_mp_relax_set():
    for element, potcar in PotcarSet.mp_relax_set.potcar_dict().items():
        if potcar is None:
            continue

        if is_target_element(element) is False:
            continue

        structure = Structure(Lattice.cubic(10),
                              coords=[[0.5] * 3],
                              species=[element])

        mp_set = MPRelaxSet(structure,
                            user_kpoints_settings=Kpoints(kpts=((1, 1, 1), )),
                            user_incar_settings={
                                "ALGO": "D",
                                "ISIF": 2,
                                "ISMEAR": 0,
                                "MAGMOM": {
                                    "H": 1.0
                                },
                                "NELM": 300
                            })
        Path(element).mkdir()
        mp_set.write_input(element)
Example #23
0
def simple_cubic_2x2x2():
    lattice = Lattice.cubic(2.0)
    coords = [[0.0, 0.0, 0.0], [0.5, 0.5, 0.0], [0.5, 0.0,
                                                 0.5], [0.0, 0.5, 0.5],
              [0.0, 0.0, 0.5], [0.0, 0.5, 0.0], [0.5, 0.0, 0.0],
              [0.5, 0.5, 0.5]]
    return IStructure(lattice=lattice, species=["H"] * 8, coords=coords)
Example #24
0
def def_str_info(displacements):
    site_diff = SiteDiff(removed=[(0, 'H', (0.25, 0.25, 0.25))],
                         inserted=[(0, 'H', (0.27, 0.25, 0.25))],
                         removed_by_sub=[(2, 'Li', (0.5, 0.5, 0.5))],
                         inserted_by_sub=[(2, 'Be', (0.5, 0.5, 0.5009))])
    site_diff_from_init = SiteDiff(removed=[(0, 'H', (0.25, 0.25, 0.25))],
                                   inserted=[(0, 'H', (0.27, 0.25, 0.25))],
                                   removed_by_sub=[(2, 'Li', (0.5, 0.5, 0.5))],
                                   inserted_by_sub=[(2, 'Be', (0.5, 0.5, 0.5))
                                                    ])
    shifted_final = Structure(Lattice.cubic(10),
                              species=["H", "He", "Be", "U"],
                              coords=[[0.27, 0.25, 0.25], [0.76, 0.75, 0.75],
                                      [0.5, 0.5, 0.5009], [0.0, 0.0, 0.0]])
    return DefectStructureInfo(shifted_final_structure=shifted_final,
                               initial_site_sym="3m",
                               final_site_sym="m",
                               site_diff=site_diff,
                               site_diff_from_initial=site_diff_from_init,
                               symprec=0.1,
                               dist_tol=0.2,
                               anchor_atom_idx=3,
                               neighbor_atom_indices=[0],
                               neighbor_cutoff_factor=1.2,
                               drift_vector=(0.0, 0.0, 0.0001),
                               drift_dist=0.001,
                               center=(0.38, 0.375, 0.375175),
                               displacements=displacements)
Example #25
0
def structures():
    perfect = Structure(Lattice.cubic(10),
                        species=["H", "He", "Li", "U"],
                        coords=[[0.25, 0.25, 0.25], [0.75, 0.75, 0.75],
                                [0.5, 0.5, 0.5], [0, 0, 0]])

    initial = Structure(Lattice.cubic(10),
                        species=["H", "He", "Be", "U"],
                        coords=[[0.25, 0.25, 0.25], [0.75, 0.75, 0.75],
                                [0.5, 0.5, 0.5], [0.0, 0.0, 0.0]])

    final = Structure(Lattice.cubic(10),
                      species=["H", "He", "Be", "U"],
                      coords=[[0.27, 0.25, 0.2501], [0.76, 0.75, 0.7501],
                              [0.5, 0.5, 0.501], [0.0, 0.0, 0.0001]])
    return perfect, initial, final
Example #26
0
 def test_writestring(self):
     # Test for the string export of s atructure into the exciting input xml schema
     input_string = (
         '<input xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
         'xsi:noNamespaceSchemaLocation="http://xml.exciting-code.org/excitinginput'
         '.xsd">\n  <title>Na4 Cl4</title>\n  <structure speciespath="./">\n    '
         '<crystal scale="1.8897543768634038">\n      <basevect>      5.62000000'
         '       0.00000000       0.00000000</basevect>\n      <basevect>      '
         '0.00000000       5.62000000       0.00000000</basevect>\n      '
         '<basevect>      0.00000000       0.00000000       5.62000000</basevect>'
         '\n    </crystal>\n    <species speciesfile="Na.xml">\n      <atom coord='
         '"      0.00000000       0.00000000       0.00000000" />\n      <atom coor'
         'd="      0.50000000       0.50000000       0.00000000" />\n      <atom co'
         'ord="      0.50000000       0.00000000       0.50000000" />\n      <atom '
         'coord="      0.00000000       0.50000000       0.50000000" />\n    </spec'
         'ies>\n    <species speciesfile="Cl.xml">\n      <atom coord="      0.5000'
         '0000       0.00000000       0.00000000" />\n      <atom coord="      0.00'
         '000000       0.50000000       0.00000000" />\n      <atom coord="      0.'
         '00000000       0.00000000       0.50000000" />\n      <atom coord="      '
         '0.50000000       0.50000000       0.50000000" />\n    </species>\n  </str'
         'ucture>\n</input>\n')
     lattice = Lattice.cubic('5.62')
     structure = Structure(lattice, ['Na', 'Na', 'Na', 'Na',
                                     'Cl', 'Cl', 'Cl', 'Cl'],
                           [[0, 0, 0], [0.5, 0.5, 0.0], [0.5, 0.0, 0.5],
                            [0.0, 0.5, 0.5],
                            [0.5, 0.0, 0.0], [0.0, 0.5, 0.0],
                            [0.0, 0.0, 0.5], [0.5, 0.5, 0.5]])
     excin = ExcitingInput(structure)
     for l1, l2 in zip(input_string.split("\n"),
                       excin.write_string('unchanged').split("\n")):
         if not l1.strip().startswith("<crystal scale"):
             self.assertEqual(l1, l2)
Example #27
0
def test_sqs_obj_correctly_serialized():
    """Tests that the as_dict method of the SQS object correctly includes metadata and is able to be seralized/unserialized."""
    sqs = AbstractSQS(Lattice.cubic(5), ['Xaa', 'Xab'],
                      [[0, 0, 0], [0.5, 0.5, 0.5]],
                      sublattice_model=[['a', 'b']],
                      sublattice_names=['a'])

    # first seralization
    s1 = AbstractSQS.from_dict(sqs.as_dict())
    assert sqs == s1
    assert s1.sublattice_model == [['a', 'b']]
    assert s1._sublattice_names == ['a']
    assert s1.normalized_sublattice_site_ratios == [[0.5, 0.5]]

    # second serialization
    s2 = AbstractSQS.from_dict(sqs.as_dict())
    assert sqs == s2
    assert s2.sublattice_model == [['a', 'b']]
    assert s2._sublattice_names == ['a']
    assert s2.normalized_sublattice_site_ratios == [[0.5, 0.5]]

    # test that we can make it concrete
    concrete_structure = s2.get_concrete_sqs([['Fe', 'Ni']])
    assert {s.symbol
            for s in concrete_structure.types_of_specie} == {'Fe', 'Ni'}
Example #28
0
 def test_model_load(self):
     s = Structure(Lattice.cubic(3.6), ["Mo", "Mo"], [[0.5, 0.5, 0.5], [0, 0, 0]])
     center_indices, neighbor_indices, images, distances = get_graphs_within_cutoff(s, 4)
     self.assertListEqual(
         center_indices.tolist(),
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
     )
 def test_out_of_cell_s2_like_s1(self):
     l = Lattice.cubic(5)
     s1 = Structure(l, ["Si", "Ag", "Si"], [[0, 0, -0.02], [0, 0, 0.001], [0.7, 0.4, 0.5]])
     s2 = Structure(l, ["Si", "Ag", "Si"], [[0, 0, 0.98], [0, 0, 0.99], [0.7, 0.4, 0.5]])
     new_s2 = StructureMatcher(primitive_cell=False).get_s2_like_s1(s1, s2)
     dists = np.sum((s1.cart_coords - new_s2.cart_coords) ** 2, axis=-1) ** 0.5
     self.assertLess(np.max(dists), 0.1)
Example #30
0
def calc_results():
    return CalcResults(structure=IStructure(Lattice.cubic(1.0), ["H"],
                                            [[0.0] * 3]),
                       energy=1.0,
                       magnetization=0.0,
                       potentials=[0.0],
                       electronic_conv=False,
                       ionic_conv=False)
Example #31
0
def test_sbond():
    s = Structure(Lattice.cubic(3.9), species=["Ba", "Ti"], coords=[[0.5]*3, [0.0]*3])
    actual = repr(SBond(s, bond_factor=1.2))
    expected = '''SBOND
1 Ba Ti 0.0  2.81  0  0  1  0  1
2 Ti Ba 0.0  2.81  0  0  1  0  1
 0 0 0 0 '''
    assert actual == expected
Example #32
0
def test_make_site_diff_wo_diff():
    s1 = IStructure(Lattice.cubic(10), species=["H"], coords=[[0] * 3])
    s2 = s1.copy()
    structure_comparator = DefectStructureComparator(s1, s2)
    site_diff = structure_comparator.make_site_diff()
    assert site_diff == SiteDiff([], [], [], [])
    assert site_diff.is_no_diff

    s1 = IStructure(Lattice.cubic(10),
                    species=["H", "He"],
                    coords=[[0] * 3, [0.5] * 3])
    s2 = IStructure(Lattice.cubic(10), species=["H"], coords=[[0] * 3])
    structure_comparator = DefectStructureComparator(defect_structure=s2,
                                                     perfect_structure=s1)
    site_diff = structure_comparator.make_site_diff()
    assert site_diff == SiteDiff([(1, "He", (0.5, 0.5, 0.5))], [], [], [])
    assert site_diff.is_no_diff is False
Example #33
0
    def setUp(self):
        parser = CifParser(os.path.join(PymatgenTest.TEST_FILES_DIR, "Fe.cif"))
        self.Fe = parser.get_structures()[0]

        parser = CifParser(
            os.path.join(PymatgenTest.TEST_FILES_DIR, "LiFePO4.cif"))
        self.LiFePO4 = parser.get_structures()[0]

        parser = CifParser(
            os.path.join(PymatgenTest.TEST_FILES_DIR, "Fe3O4.cif"))
        self.Fe3O4 = parser.get_structures()[0]

        parser = CifParser(
            os.path.join(PymatgenTest.TEST_FILES_DIR,
                         "magnetic.ncl.example.GdB4.mcif"))
        self.GdB4 = parser.get_structures()[0]

        parser = CifParser(
            os.path.join(PymatgenTest.TEST_FILES_DIR,
                         "magnetic.example.NiO.mcif"))
        self.NiO_expt = parser.get_structures()[0]

        latt = Lattice.cubic(4.17)
        species = ["Ni", "O"]
        coords = [[0, 0, 0], [0.5, 0.5, 0.5]]
        self.NiO = Structure.from_spacegroup(225, latt, species, coords)

        latt = Lattice([[2.085, 2.085, 0.0], [0.0, -2.085, -2.085],
                        [-2.085, 2.085, -4.17]])
        species = ["Ni", "Ni", "O", "O"]
        coords = [[0.5, 0, 0.5], [0, 0, 0], [0.25, 0.5, 0.25],
                  [0.75, 0.5, 0.75]]
        self.NiO_AFM_111 = Structure(latt,
                                     species,
                                     coords,
                                     site_properties={"magmom": [-5, 5, 0, 0]})

        latt = Lattice([[2.085, 2.085, 0], [0, 0, -4.17], [-2.085, 2.085, 0]])
        species = ["Ni", "Ni", "O", "O"]
        coords = [[0.5, 0.5, 0.5], [0, 0, 0], [0, 0.5, 0], [0.5, 0, 0.5]]
        self.NiO_AFM_001 = Structure(latt,
                                     species,
                                     coords,
                                     site_properties={"magmom": [-5, 5, 0, 0]})

        latt = Lattice([[2.085, 2.085, 0], [0, 0, -4.17], [-2.085, 2.085, 0]])
        species = ["Ni", "Ni", "O", "O"]
        coords = [[0.5, 0.5, 0.5], [0, 0, 0], [0, 0.5, 0], [0.5, 0, 0.5]]
        self.NiO_AFM_001_opposite = Structure(
            latt, species, coords, site_properties={"magmom": [5, -5, 0, 0]})

        latt = Lattice([[2.085, 2.085, 0], [0, 0, -4.17], [-2.085, 2.085, 0]])
        species = ["Ni", "Ni", "O", "O"]
        coords = [[0.5, 0.5, 0.5], [0, 0, 0], [0, 0.5, 0], [0.5, 0, 0.5]]
        self.NiO_unphysical = Structure(
            latt, species, coords, site_properties={"magmom": [-3, 0, 0, 0]})

        warnings.simplefilter("ignore")
Example #34
0
 def test_out_of_cell_s2_like_s1(self):
     l = Lattice.cubic(5)
     s1 = Structure(l, ['Si', 'Ag', 'Si'],
                    [[0, 0, -0.02], [0, 0, 0.001], [.7, .4, .5]])
     s2 = Structure(l, ['Si', 'Ag', 'Si'],
                    [[0, 0, 0.98], [0, 0, 0.99], [.7, .4, .5]])
     new_s2 = StructureMatcher(primitive_cell=False).get_s2_like_s1(s1, s2)
     dists = np.sum((s1.cart_coords - new_s2.cart_coords)**2, axis=-1)**0.5
     self.assertLess(np.max(dists), 0.1)
Example #35
0
def test_shift_distance_data2():
    grids = Grids(lattice=Lattice.cubic(10),
                  dim=(2, 2, 2),
                  distance_data=np.array([[[0.0, 5.0], [5.0, 7.07]],
                                          [[5.0, 7.07], [7.07, 8.66]]]))
    actual = grids.shifted_distance_data(center=[1, 1, 1])
    expected = np.array([[[8.66, 7.07], [7.07, 5.0]], [[7.07, 5.0], [5.0,
                                                                     0.0]]])
    np.testing.assert_array_almost_equal(actual, expected)
    def test_get_supercells(self):
        sm = StructureMatcher(comparator=ElementComparator())
        l = Lattice.cubic(1)
        l2 = Lattice.cubic(0.5)
        s1 = Structure(l, ['Mg', 'Cu', 'Ag', 'Cu'], [[0]*3]*4)
        s2 = Structure(l2, ['Cu', 'Cu', 'Ag'], [[0]*3]*3)
        scs = list(sm._get_supercells(s1, s2, 8, False))
        for x in scs:
            self.assertAlmostEqual(abs(np.linalg.det(x[3])), 8)
            self.assertEqual(len(x[0]), 4)
            self.assertEqual(len(x[1]), 24)
        self.assertEqual(len(scs), 48)

        scs = list(sm._get_supercells(s2, s1, 8, True))
        for x in scs:
            self.assertAlmostEqual(abs(np.linalg.det(x[3])), 8)
            self.assertEqual(len(x[0]), 24)
            self.assertEqual(len(x[1]), 4)
        self.assertEqual(len(scs), 48)
    def test_get_mask(self):
        sm = StructureMatcher(comparator=ElementComparator())
        l = Lattice.cubic(1)
        s1 = Structure(l, ['Mg', 'Cu', 'Ag', 'Cu'], [[0]*3]*4)
        s2 = Structure(l, ['Cu', 'Cu', 'Ag'], [[0]*3]*3)

        result = [[True, False, True, False],
                  [True, False, True, False],
                  [True, True, False, True]]
        m, inds, i = sm._get_mask(s1, s2, 1, True)
        self.assertTrue(np.all(m == result))
        self.assertTrue(i == 2)
        self.assertEqual(inds, [2])

        #test supercell with match
        result = [[1, 1, 0, 0, 1, 1, 0, 0],
                  [1, 1, 0, 0, 1, 1, 0, 0],
                  [1, 1, 1, 1, 0, 0, 1, 1]]
        m, inds, i = sm._get_mask(s1, s2, 2, True)
        self.assertTrue(np.all(m == result))
        self.assertTrue(i == 2)
        self.assertTrue(np.allclose(inds, np.array([4])))

        #test supercell without match
        result = [[1, 1, 1, 1, 1, 1],
                  [0, 0, 0, 0, 1, 1],
                  [1, 1, 1, 1, 0, 0],
                  [0, 0, 0, 0, 1, 1]]
        m, inds, i = sm._get_mask(s2, s1, 2, True)
        self.assertTrue(np.all(m == result))
        self.assertTrue(i == 0)
        self.assertTrue(np.allclose(inds, np.array([])))

        #test s2_supercell
        result = [[1, 1, 1], [1, 1, 1],
                  [0, 0, 1], [0, 0, 1],
                  [1, 1, 0], [1, 1, 0],
                  [0, 0, 1], [0, 0, 1]]
        m, inds, i = sm._get_mask(s2, s1, 2, False)
        self.assertTrue(np.all(m == result))
        self.assertTrue(i == 0)
        self.assertTrue(np.allclose(inds, np.array([])))

        #test for multiple translation indices
        s1 = Structure(l, ['Cu', 'Ag', 'Cu', 'Ag', 'Ag'], [[0]*3]*5)
        s2 = Structure(l, ['Ag', 'Cu', 'Ag'], [[0]*3]*3)
        result = [[1, 0, 1, 0, 0],
                  [0, 1, 0, 1, 1],
                  [1, 0, 1, 0, 0]]
        m, inds, i = sm._get_mask(s1, s2, 1, True)

        self.assertTrue(np.all(m == result))
        self.assertTrue(i == 1)
        self.assertTrue(np.allclose(inds, [0, 2]))
Example #38
0
    def test_nelect(self):
        coords = [[0] * 3, [0.5] * 3, [0.75] * 3]
        lattice = Lattice.cubic(4)
        s = Structure(lattice, ['Si', 'Si', 'Fe'], coords)
        self.assertAlmostEqual(MITRelaxSet(s).nelect, 16)

        # Check that it works even when oxidation states are present. Was a bug
        # previously.
        s = Structure(lattice, ['Si4+', 'Si4+', 'Fe2+'], coords)
        self.assertAlmostEqual(MITRelaxSet(s).nelect, 16)
        self.assertAlmostEqual(MPRelaxSet(s).nelect, 22)
    def test_get_supercell_size(self):
        l = Lattice.cubic(1)
        l2 = Lattice.cubic(0.9)
        s1 = Structure(l, ["Mg", "Cu", "Ag", "Cu", "Ag"], [[0] * 3] * 5)
        s2 = Structure(l2, ["Cu", "Cu", "Ag"], [[0] * 3] * 3)

        sm = StructureMatcher(supercell_size="volume")
        self.assertEqual(sm._get_supercell_size(s1, s2), (1, True))
        self.assertEqual(sm._get_supercell_size(s2, s1), (1, True))

        sm = StructureMatcher(supercell_size="num_sites")
        self.assertEqual(sm._get_supercell_size(s1, s2), (2, False))
        self.assertEqual(sm._get_supercell_size(s2, s1), (2, True))

        sm = StructureMatcher(supercell_size="Ag")
        self.assertEqual(sm._get_supercell_size(s1, s2), (2, False))
        self.assertEqual(sm._get_supercell_size(s2, s1), (2, True))

        sm = StructureMatcher(supercell_size="wfieoh")
        self.assertRaises(ValueError, sm._get_supercell_size, s1, s2)
Example #40
0
    def test_metal_check(self):
        structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3),
                                              ["Cu"], [[0, 0, 0]])

        with warnings.catch_warnings(record=True) as w:
            # Cause all warnings to always be triggered.
            warnings.simplefilter("always")
            # Trigger a warning.
            vis = MITRelaxSet(structure)
            incar = vis.incar
            # Verify some things
            self.assertIn("ISMEAR", str(w[-1].message))
    def test_get_supercell_size(self):
        l = Lattice.cubic(1)
        l2 = Lattice.cubic(0.9)
        s1 = Structure(l, ['Mg', 'Cu', 'Ag', 'Cu', 'Ag'], [[0]*3]*5)
        s2 = Structure(l2, ['Cu', 'Cu', 'Ag'], [[0]*3]*3)

        sm = StructureMatcher(supercell_size='volume')
        result = sm._get_supercell_size(s1, s2)
        self.assertEqual(result[0], 1)
        self.assertEqual(result[1], True)

        result = sm._get_supercell_size(s2, s1)
        self.assertEqual(result[0], 1)
        self.assertEqual(result[1], True)

        sm = StructureMatcher(supercell_size='num_sites')
        result = sm._get_supercell_size(s1, s2)
        self.assertEqual(result[0], 2)
        self.assertEqual(result[1], False)

        result = sm._get_supercell_size(s2, s1)
        self.assertEqual(result[0], 2)
        self.assertEqual(result[1], True)
Example #42
0
    def setUp(self):
        parser = CifParser(os.path.join(test_dir, 'Fe.cif'))
        self.Fe = parser.get_structures()[0]

        parser = CifParser(os.path.join(test_dir, 'LiFePO4.cif'))
        self.LiFePO4 = parser.get_structures()[0]

        parser = CifParser(os.path.join(test_dir, 'Fe3O4.cif'))
        self.Fe3O4 = parser.get_structures()[0]

        parser = CifParser(os.path.join(test_dir, 'magnetic.ncl.example.GdB4.mcif'))
        self.GdB4 = parser.get_structures()[0]

        parser = CifParser(os.path.join(test_dir, 'magnetic.example.NiO.mcif'))
        self.NiO_expt = parser.get_structures()[0]

        latt = Lattice.cubic(4.17)
        species = ["Ni", "O"]
        coords = [[0, 0, 0],
                  [0.5, 0.5, 0.5]]
        self.NiO = Structure.from_spacegroup(225, latt, species, coords)

        latt = Lattice([[2.085, 2.085, 0.0],
                        [0.0, -2.085, -2.085],
                        [-2.085, 2.085, -4.17]])
        species = ["Ni", "Ni", "O", "O"]
        coords = [[0.5, 0, 0.5],
                  [0, 0, 0],
                  [0.25, 0.5, 0.25],
                  [0.75, 0.5, 0.75]]
        self.NiO_AFM_111 = Structure(latt, species, coords, site_properties={'magmom': [-5, 5, 0, 0]})

        latt = Lattice([[2.085, 2.085, 0],
                        [0, 0, -4.17],
                        [-2.085, 2.085, 0]])
        species = ["Ni", "Ni", "O", "O"]
        coords = [[0.5, 0.5, 0.5],
                  [0, 0, 0],
                  [0, 0.5, 0],
                  [0.5, 0, 0.5]]
        self.NiO_AFM_001 = Structure(latt, species, coords, site_properties={'magmom': [-5, 5, 0, 0]})
Example #43
0
        if scan:
            wf_name += " - SCAN"
        wf = Workflow(fws, name=wf_name)

        wf = add_additional_fields_to_taskdocs(wf, {"wf_meta": self.wf_meta})

        tag = "magnetic_orderings group: >>{}<<".format(self.uuid)
        wf = add_tags(wf, [tag, ordered_structure_origins])

        return wf


if __name__ == "__main__":

    # for trying workflows

    from fireworks import LaunchPad

    latt = Lattice.cubic(4.17)
    species = ["Ni", "O"]
    coords = [[0.00000, 0.00000, 0.00000], [0.50000, 0.50000, 0.50000]]
    NiO = Structure.from_spacegroup(225, latt, species, coords)

    wf_deformation = get_wf_magnetic_deformation(NiO)

    wf_orderings = MagneticOrderingsWF(NiO).get_wf()

    lpad = LaunchPad.auto_load()
    lpad.add_wf(wf_orderings)
    lpad.add_wf(wf_deformation)