Beispiel #1
0
    def setUp(self):
        self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5),
                                                   ["Ni"], [[0, 0, 0]])
        lattice = Lattice.cubic(3.010)
        frac_coords = [
            [0.00000, 0.00000, 0.00000],
            [0.00000, 0.50000, 0.50000],
            [0.50000, 0.00000, 0.50000],
            [0.50000, 0.50000, 0.00000],
            [0.50000, 0.00000, 0.00000],
            [0.50000, 0.50000, 0.50000],
            [0.00000, 0.00000, 0.50000],
            [0.00000, 0.50000, 0.00000],
        ]
        species = ["Mg", "Mg", "Mg", "Mg", "O", "O", "O", "O"]
        self.MgO = Structure(lattice, species, frac_coords)

        slabs = generate_all_slabs(
            self.structure,
            max_index=2,
            min_slab_size=6.0,
            min_vacuum_size=15.0,
            max_normal_search=1,
            center_slab=True,
        )
        self.slab_dict = {
            "".join([str(i) for i in slab.miller_index]): slab
            for slab in slabs
        }
        self.asf_211 = AdsorbateSiteFinder(self.slab_dict["211"])
        self.asf_100 = AdsorbateSiteFinder(self.slab_dict["100"])
        self.asf_111 = AdsorbateSiteFinder(self.slab_dict["111"])
        self.asf_110 = AdsorbateSiteFinder(self.slab_dict["110"])
        self.asf_struct = AdsorbateSiteFinder(
            Structure.from_sites(self.slab_dict["111"].sites))
Beispiel #2
0
    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)
def test_make_single_defect_energy(mocker):
    perfect = mocker.Mock(CalcResults, autospec=True)
    perfect.energy = 1.0
    perfect.structure = IStructure(Lattice.cubic(1), ["H"] * 2, [[0] * 3] * 2)

    defect = mocker.Mock(CalcResults, autospec=True)
    defect.energy = 3.0
    defect.structure = IStructure(Lattice.cubic(1), ["H"], [[0] * 3])

    name, charge = "Va_H1", 5
    defect_entry = mocker.Mock(DefectEntry, autospec=True)
    defect_entry.name = name
    defect_entry.charge = charge

    single_defect_energy = \
        make_single_defect_energy(perfect=perfect,
                                  defect=defect,
                                  defect_entry=defect_entry,
                                  abs_chem_pot={Element.H: 100},
                                  correction=ManualCorrection(7.0))
    energy = 3.0 - 1.0 + 100

    assert isinstance(single_defect_energy, SingleDefectEnergy)
    assert single_defect_energy == SingleDefectEnergy(name, charge, energy,
                                                      7.0)
Beispiel #4
0
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
Beispiel #5
0
    def setUp(self):
        self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5),
                                                   ["Ni"], [[0, 0, 0]])
        lattice = Lattice.cubic(3.010)
        frac_coords = [[0.00000, 0.00000, 0.00000],
                       [0.00000, 0.50000, 0.50000],
                       [0.50000, 0.00000, 0.50000],
                       [0.50000, 0.50000, 0.00000],
                       [0.50000, 0.00000, 0.00000],
                       [0.50000, 0.50000, 0.50000],
                       [0.00000, 0.00000, 0.50000],
                       [0.00000, 0.50000, 0.00000]]
        species = ['Mg', 'Mg', 'Mg', 'Mg', 'O', 'O', 'O', 'O']
        self.MgO = Structure(lattice, species, frac_coords)

        slabs = generate_all_slabs(self.structure, max_index=2,
                                   min_slab_size=6.0, min_vacuum_size=15.0,
                                   max_normal_search=1, center_slab=True)
        self.slab_dict = {''.join([str(i) for i in slab.miller_index]):
                              slab for slab in slabs}
        self.asf_211 = AdsorbateSiteFinder(self.slab_dict["211"])
        self.asf_100 = AdsorbateSiteFinder(self.slab_dict["100"])
        self.asf_111 = AdsorbateSiteFinder(self.slab_dict["111"])
        self.asf_110 = AdsorbateSiteFinder(self.slab_dict["110"])
        self.asf_struct = AdsorbateSiteFinder(
            Structure.from_sites(self.slab_dict["111"].sites))
def structure_analyzer():
    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]
        ])

    # add [0.1, -0.1, 0]
    # 3rd -- 6th
    # [0.85, 0.65, 0.25] - [0.76, 0.73, 0.24] = [0.09, -0.08, 0.01]
    # [0.85, 0.15, 0.75] - [0.75, 0.25, 0.73] = [0.10, -0.10, 0.02]
    # [0.1, -0.1, 0] -[0.1, -0.1, 0] = [0, 0, 0]
    # [0.6, 0.4, 0.5] - [0.5, 0.5, 0.5] = [0.1, -0.1, 0]
    cu2o_defect = IStructure(
        Lattice.cubic(5),
        species=["Cu"] * 3 + ["O"] * 2 + ["H"],
        coords=[
            [0.25, 0.5, 0.5],  # defect
            [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
        ])  # defect

    return DefectStructureComparator(defect_structure=cu2o_defect,
                                     perfect_structure=cu2o_perfect)
Beispiel #7
0
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=structure_info.defect_type,
        symm_relation=structure_info.symm_relation)
    expected = CalcSummary({"Va_O1_1": single_summary})

    assert actual == expected
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
Beispiel #9
0
    def get_unit_cell(self, 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
Beispiel #10
0
 def setUp(self):
     self.structure1 = Structure.from_spacegroup("Fd-3m", Lattice.cubic(5.46873),
                                                 ["Si"], [[0, 0, 0]])
     self.structure2 = Structure.from_spacegroup("Fm-3m", Lattice.cubic(5.69169),
                                                 ['Na', 'Cl'], [[0, 0, 0], [0, 0, 0.5]])
     self.structure3 = Structure.from_spacegroup("Pm-3m", Lattice.cubic(3.88947),
                                                 ['Ca', 'Ti', 'O'], [[0.5, 0.5, 0.5], [0, 0, 0], [0, 0, 0.5]])
Beispiel #11
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)
Beispiel #12
0
    def test_validate(self):
        s1 = Structure(Lattice.cubic(3.61), ['Mo', 'Mo'],
                       [[0., 0., 0.], [0.5, 0.5, 0.5]])
        s2 = Structure(Lattice.cubic(3.61), ['Mo', 'Mo'],
                       [[0., 0., 0.], [0.6, 0.6, 0.5]])
        s3 = Structure(Lattice.cubic(3.1), ['Mo', 'Mo'],
                       [[0., 0., 0.], [0.6, 0.6, 0.5]])

        self.assertTrue(validate_structures([s1, s2]))
        self.assertFalse(validate_structures([s1, s3]))
Beispiel #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)
 def setUp(self):
     self.unary_struct = Structure.from_spacegroup('Im-3m',
                                                   Lattice.cubic(3.4268),
                                                   [{
                                                       "Li": 1
                                                   }], [[0, 0, 0]])
     self.binary_struct = Structure.from_spacegroup(
         225, Lattice.cubic(5.69169), ['Na', 'Cl'],
         [[0, 0, 0], [0, 0, 0.5]])
     self.describer = SOAPDescriptor(cutoff=4.8, l_max=8, n_max=8)
Beispiel #15
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)
Beispiel #16
0
 def setUp(self):
     self.unary_struct = Structure.from_spacegroup("Im-3m",
                                                   Lattice.cubic(3.4268),
                                                   ["Li"], [[0, 0, 0]])
     self.binary_struct = Structure.from_spacegroup(
         "Fm-3m", Lattice.cubic(5.69169), ['Na', 'Cl'],
         [[0, 0, 0], [0, 0, 0.5]])
     self.describer = SmoothOverlapAtomicPosition(cutoff=4.8,
                                                  l_max=8,
                                                  n_max=8)
Beispiel #17
0
    def test_write_inputs(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))

        fc = self.vis._process_structures(structs)[2].frac_coords
        self.assertTrue(np.allclose(fc, [[0.5]*3,[0.9, 1.033333, 1.0333333]]))
Beispiel #18
0
 def setUp(self):
     self.structure1 = Structure.from_spacegroup("Fd-3m",
                                                 Lattice.cubic(5.46873),
                                                 ["Si"], [[0, 0, 0]])
     self.structure2 = Structure.from_spacegroup("Fm-3m",
                                                 Lattice.cubic(5.69169),
                                                 ["Na", "Cl"],
                                                 [[0, 0, 0], [0, 0, 0.5]])
     self.structure3 = Structure.from_spacegroup(
         "Pm-3m", Lattice.cubic(3.88947), ["Ca", "Ti", "O"],
         [[0.5, 0.5, 0.5], [0, 0, 0], [0, 0, 0.5]])
Beispiel #19
0
    def test_write_inputs(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))

        fc = self.vis._process_structures(structs)[2].frac_coords
        self.assertTrue(
            np.allclose(fc, [[0.5] * 3, [0.9, 1.033333, 1.0333333]]))
Beispiel #20
0
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)
 def test_apply_transformation(self):
     l = Lattice.cubic(4)
     s_orig = Structure(l, [{"Li": 0.19, "Na": 0.19, "K": 0.62}, {"O": 1}],
                   [[0, 0, 0], [0.5, 0.5, 0.5]])
     cct = ChargedCellTransformation(charge=3)
     s = cct.apply_transformation(s_orig)
     self.assertEqual(s.charge, 3)
    def test_apply_transformation(self):
        l = Lattice.cubic(4)
        s_orig = Structure(l, [{"Li": 0.19, "Na": 0.19, "K": 0.62}, {"O": 1}],
                      [[0, 0, 0], [0.5, 0.5, 0.5]])
        dot = DiscretizeOccupanciesTransformation(max_denominator=5, tol=0.5)
        s = dot.apply_transformation(s_orig)
        self.assertEqual(dict(s[0].species_and_occu), {Element("Li"): 0.2,
                                                       Element("Na"): 0.2,
                                                       Element("K"): 0.6})

        dot = DiscretizeOccupanciesTransformation(max_denominator=5, tol=0.01)
        self.assertRaises(RuntimeError, dot.apply_transformation, s_orig)

        s_orig_2 = Structure(l, [{"Li": 0.5, "Na": 0.25, "K": 0.25}, {"O": 1}],
                      [[0, 0, 0], [0.5, 0.5, 0.5]])

        dot = DiscretizeOccupanciesTransformation(max_denominator=9, tol=0.25,
                                                  fix_denominator=False)

        s = dot.apply_transformation(s_orig_2)
        self.assertEqual(dict(s[0].species_and_occu), {Element("Li"): Fraction(1/2),
                                                       Element("Na"): Fraction(1/4),
                                                       Element("K"): Fraction(1/4)})

        dot = DiscretizeOccupanciesTransformation(max_denominator=9, tol=0.05,
                                                  fix_denominator=True)
        self.assertRaises(RuntimeError, dot.apply_transformation, s_orig_2)
Beispiel #23
0
 def setUp(self):
     with open(os.path.join(test_dir, 'test_toec_data.json')) as f:
         self.data_dict = json.load(f)
     self.strains = [Strain(sm) for sm in self.data_dict['strains']]
     self.pk_stresses = [Stress(d) for d in self.data_dict['pk_stresses']]
     self.c2 = self.data_dict["C2_raw"]
     self.c3 = self.data_dict["C3_raw"]
     self.exp = ElasticTensorExpansion.from_voigt([self.c2, self.c3])
     self.cu = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.623),
                                         ["Cu"], [[0] * 3])
     indices = [(0, 0), (0, 1), (3, 3)]
     values = [167.8, 113.5, 74.5]
     cu_c2 = ElasticTensor.from_values_indices(values,
                                               indices,
                                               structure=self.cu,
                                               populate=True)
     indices = [(0, 0, 0), (0, 0, 1), (0, 1, 2), (0, 3, 3), (0, 5, 5),
                (3, 4, 5)]
     values = [-1507., -965., -71., -7., -901., 45.]
     cu_c3 = Tensor.from_values_indices(values,
                                        indices,
                                        structure=self.cu,
                                        populate=True)
     self.exp_cu = ElasticTensorExpansion([cu_c2, cu_c3])
     cu_c4 = Tensor.from_voigt(self.data_dict["Cu_fourth_order"])
     self.exp_cu_4 = ElasticTensorExpansion([cu_c2, cu_c3, cu_c4])
     warnings.simplefilter("ignore")
Beispiel #24
0
    def test_apply_transformation(self):
        trans = SubstituteSurfaceSiteTransformation("Au")
        pt = Structure(Lattice.cubic(5), ["Pt"], [[0, 0, 0]])  # fictitious
        slab = SlabTransformation([0, 0, 1], 20, 10).apply_transformation(pt)
        out = trans.apply_transformation(slab)

        self.assertEqual(out.composition.reduced_formula, "Pt3Au")
Beispiel #25
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],
     )
Beispiel #26
0
    def test_structure(self):
        quartz = self.quartz.structure
        np.testing.assert_array_almost_equal(
            quartz.lattice.matrix,
            [[4.913400, 0, 0], [-2.456700, 4.255129, 0], [0, 0, 5.405200]])
        self.assertEqual(quartz.formula, "Si3 O6")
        self.assertNotIn("molecule-ID", self.quartz.atoms.columns)

        ethane = self.ethane.structure
        np.testing.assert_array_almost_equal(ethane.lattice.matrix,
                                             np.diag([10.0] * 3))
        lbounds = np.array(self.ethane.box.bounds)[:, 0]
        coords = self.ethane.atoms[["x", "y", "z"]].values - lbounds
        np.testing.assert_array_almost_equal(ethane.cart_coords, coords)
        np.testing.assert_array_almost_equal(ethane.site_properties["charge"],
                                             self.ethane.atoms["q"])
        tatb = self.tatb.structure
        frac_coords = tatb.frac_coords[381]
        real_frac_coords = frac_coords - np.floor(frac_coords)
        np.testing.assert_array_almost_equal(
            real_frac_coords, [0.01553397, 0.71487872, 0.14134139])

        co = Structure.from_spacegroup(194,
                                       Lattice.hexagonal(2.50078, 4.03333),
                                       ["Co"], [[1 / 3, 2 / 3, 1 / 4]])
        ld_co = LammpsData.from_structure(co)
        self.assertEqual(ld_co.structure.composition.reduced_formula, "Co")
        ni = Structure.from_spacegroup(225, Lattice.cubic(3.50804), ["Ni"],
                                       [[0, 0, 0]])
        ld_ni = LammpsData.from_structure(ni)
        self.assertEqual(ld_ni.structure.composition.reduced_formula, "Ni")
    def test_apply_transformation(self):
        l = Lattice.cubic(4)
        s_orig = Structure(l, [{"Li": 0.19, "Na": 0.19, "K": 0.62}, {"O": 1}],
                      [[0, 0, 0], [0.5, 0.5, 0.5]])
        dot = DiscretizeOccupanciesTransformation(max_denominator=5, tol=0.5)
        s = dot.apply_transformation(s_orig)
        self.assertEqual(dict(s[0].species), {Element("Li"): 0.2,
                                                       Element("Na"): 0.2,
                                                       Element("K"): 0.6})

        dot = DiscretizeOccupanciesTransformation(max_denominator=5, tol=0.01)
        self.assertRaises(RuntimeError, dot.apply_transformation, s_orig)

        s_orig_2 = Structure(l, [{"Li": 0.5, "Na": 0.25, "K": 0.25}, {"O": 1}],
                      [[0, 0, 0], [0.5, 0.5, 0.5]])

        dot = DiscretizeOccupanciesTransformation(max_denominator=9, tol=0.25,
                                                  fix_denominator=False)

        s = dot.apply_transformation(s_orig_2)
        self.assertEqual(dict(s[0].species), {Element("Li"): Fraction(1/2),
                                                       Element("Na"): Fraction(1/4),
                                                       Element("K"): Fraction(1/4)})

        dot = DiscretizeOccupanciesTransformation(max_denominator=9, tol=0.05,
                                                  fix_denominator=True)
        self.assertRaises(RuntimeError, dot.apply_transformation, s_orig_2)
def structure_analyzer_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)
Beispiel #29
0
    def test_unordered_site(self):
        s = Structure(Lattice.cubic(3), ['Mo', 'S'],
                      [[0, 0, 0], [0.5, 0.5, 0.5]])
        udescriber = SiteElementProperty()
        np.testing.assert_array_almost_equal(udescriber.transform_one(s),
                                             np.array([[42, 16]]).T)

        udescriber2 = SiteElementProperty(feature_dict={
            16: [16, 16],
            42: [42, 42]
        })
        np.testing.assert_array_almost_equal(udescriber2.transform_one(s),
                                             np.array([[42, 42], [16, 16]]))

        self.assertTrue(udescriber.describer_type == 'site')

        udescriber = SiteElementProperty(output_weights=True)
        vec, weight = udescriber.transform_one(s)
        np.testing.assert_array_almost_equal(vec, np.array([[42, 16]]).T)
        np.testing.assert_array_almost_equal(weight, np.array([1, 1]))

        s2 = s.copy()
        s2.replace_species({"Mo": {"S": 0.1, "Mo": 0.9}})
        self.assertRaises(ValueError, udescriber2.transform_one, s2)
        vec, weight = udescriber.transform_one(s2)
        np.testing.assert_array_almost_equal(vec, np.array([[16, 42, 16]]).T)
        np.testing.assert_array_almost_equal(weight, np.array([0.1, 0.9, 1]))
Beispiel #30
0
    def setUp(self):
        element_profile = {"Ni": {"r": 0.5, "w": 1}}
        describer1 = BispectrumCoefficients(rcutfac=4.1,
                                            twojmax=8,
                                            element_profile=element_profile,
                                            quadratic=False,
                                            pot_fit=True)
        model1 = SKLModel(describer=describer1, model=LinearRegression())
        model1.model.coef_ = coeff
        model1.model.intercept_ = intercept
        snap1 = SNAPotential(model=model1)
        self.ff_settings1 = snap1

        describer2 = BispectrumCoefficients(rcutfac=4.1,
                                            twojmax=8,
                                            element_profile=element_profile,
                                            quadratic=True,
                                            pot_fit=True)
        model2 = SKLModel(describer=describer2, model=LinearRegression())
        model2.model.coef_ = coeff
        model2.model.intercept_ = intercept
        snap2 = SNAPotential(model=model2)
        self.ff_settings2 = snap2

        self.struct = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.506),
                                                ["Ni"], [[0, 0, 0]])
Beispiel #31
0
    def setUp(self):
        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)
        self.NiO_AFM_111.add_spin_by_site([-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)
        self.NiO_AFM_001.add_spin_by_site([-5, 5, 0, 0])

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

        parser = CifParser(os.path.join(test_dir, 'Li8Fe2NiCoO8.cif'))
        self.Li8Fe2NiCoO8 = parser.get_structures()[0]
        self.Li8Fe2NiCoO8.remove_oxidation_states()
        warnings.simplefilter("ignore")
Beispiel #32
0
    def test_sulfide_type(self):
        # NaS2 -> polysulfide
        latt = Lattice.tetragonal(9.59650, 11.78850)
        species = ["Na"] * 2 + ["S"] * 2
        coords = [[0.00000, 0.00000, 0.17000], [0.27600, 0.25000, 0.12500],
                  [0.03400, 0.25000, 0.29600], [0.14700, 0.11600, 0.40000]]
        struct = Structure.from_spacegroup(122, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "polysulfide")

        # NaCl type NaS -> sulfide
        latt = Lattice.cubic(5.75)
        species = ["Na", "S"]
        coords = [[0.00000, 0.00000, 0.00000], [0.50000, 0.50000, 0.50000]]
        struct = Structure.from_spacegroup(225, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "sulfide")

        # Na2S2O3 -> None (sulfate)
        latt = Lattice.monoclinic(6.40100, 8.10000, 8.47400, 96.8800)
        species = ["Na"] * 2 + ["S"] * 2 + ["O"] * 3
        coords = [[0.29706, 0.62396, 0.08575], [0.37673, 0.30411, 0.45416],
                  [0.52324, 0.10651, 0.21126], [0.29660, -0.04671, 0.26607],
                  [0.17577, 0.03720, 0.38049], [0.38604, -0.20144, 0.33624],
                  [0.16248, -0.08546, 0.11608]]
        struct = Structure.from_spacegroup(14, latt, species, coords)
        self.assertEqual(sulfide_type(struct), None)

        # Na3PS3O -> sulfide
        latt = Lattice.orthorhombic(9.51050, 11.54630, 5.93230)
        species = ["Na"] * 2 + ["S"] * 2 + ["P", "O"]
        coords = [[0.19920, 0.11580, 0.24950], [0.00000, 0.36840, 0.29380],
                  [0.32210, 0.36730, 0.22530], [0.50000, 0.11910, 0.27210],
                  [0.50000, 0.29400, 0.35500], [0.50000, 0.30300, 0.61140]]
        struct = Structure.from_spacegroup(36, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "sulfide")
Beispiel #33
0
    def setUp(self):

        element_profile = {'Ni': {'r': 0.5, 'w': 1}}
        describer1 = BispectrumCoefficients(rcutfac=4.1,
                                            twojmax=8,
                                            element_profile=element_profile,
                                            quadratic=False,
                                            pot_fit=True)
        model1 = LinearModel(describer=describer1)
        model1.model.coef_ = coeff
        model1.model.intercept_ = intercept
        snap1 = SNAPotential(model=model1)
        snap1.specie = Element('Ni')
        self.ff_settings1 = snap1

        describer2 = BispectrumCoefficients(rcutfac=4.1,
                                            twojmax=8,
                                            element_profile=element_profile,
                                            quadratic=True,
                                            pot_fit=True)
        model2 = LinearModel(describer=describer2)
        model2.model.coef_ = coeff
        model2.model.intercept_ = intercept
        snap2 = SNAPotential(model=model2)
        snap2.specie = Element('Ni')
        self.ff_settings2 = snap2

        self.struct = Structure.from_spacegroup('Fm-3m', Lattice.cubic(3.506),
                                                ['Ni'], [[0, 0, 0]])
Beispiel #34
0
 def test_init(self):
     filepath = os.path.join(test_dir, 'PROCAR.simple')
     p = Procar(filepath)
     self.assertAlmostEqual(p.get_occupation(0, 'd')[Spin.up], 0)
     self.assertAlmostEqual(
         p.get_occupation(0, 's')[Spin.up], 0.35381249999999997)
     self.assertAlmostEqual(p.get_occupation(0, 'p')[Spin.up], 1.19540625)
     self.assertRaises(ValueError, p.get_occupation, 1, 'm')
     self.assertEqual(p.nbands, 10)
     self.assertEqual(p.nkpoints, 10)
     self.assertEqual(p.nions, 3)
     lat = Lattice.cubic(3.)
     s = Structure(lat, ["Li", "Na", "K"],
                   [[0., 0., 0.], [0.25, 0.25, 0.25], [0.75, 0.75, 0.75]])
     d = p.get_projection_on_elements(s)
     self.assertAlmostEqual(d[Spin.up][2][2], {
         'Na': 0.042,
         'K': 0.646,
         'Li': 0.042
     })
     filepath = os.path.join(test_dir, 'PROCAR')
     p = Procar(filepath)
     self.assertAlmostEqual(
         p.get_occupation(0, 'dxy')[Spin.up], 0.96214813853000025)
     self.assertAlmostEqual(
         p.get_occupation(0, 'dxy')[Spin.down], 0.85796295426000124)
 def test_apply_transformation(self):
     l = Lattice.cubic(4)
     s_orig = Structure(l, [{"Li": 0.19, "Na": 0.19, "K": 0.62}, {"O": 1}],
                   [[0, 0, 0], [0.5, 0.5, 0.5]])
     cct = ChargedCellTransformation(charge=3)
     s = cct.apply_transformation(s_orig)
     self.assertEqual(s.charge, 3)
Beispiel #36
0
    def test_structure(self):
        quartz = self.quartz.structure
        np.testing.assert_array_equal(quartz.lattice.matrix,
                                      [[4.913400, 0, 0],
                                       [-2.456700, 4.255129, 0],
                                       [0, 0, 5.405200]])
        self.assertEqual(quartz.formula, "Si3 O6")
        self.assertNotIn("molecule-ID", self.quartz.atoms.columns)

        ethane = self.ethane.structure
        np.testing.assert_array_equal(ethane.lattice.matrix,
                                      np.diag([10.0] * 3))
        lbounds = np.array(self.ethane.box.bounds)[:, 0]
        coords = self.ethane.atoms[["x", "y", "z"]].values - lbounds
        np.testing.assert_array_equal(ethane.cart_coords, coords)
        np.testing.assert_array_equal(ethane.site_properties["charge"],
                                      self.ethane.atoms["q"])
        tatb = self.tatb.structure
        frac_coords = tatb.frac_coords[381]
        real_frac_coords = frac_coords - np.floor(frac_coords)
        np.testing.assert_array_almost_equal(real_frac_coords,
                                             [0.01553397,
                                              0.71487872,
                                              0.14134139])

        co = Structure.from_spacegroup(194,
                                       Lattice.hexagonal(2.50078, 4.03333),
                                       ["Co"], [[1/3, 2/3, 1/4]])
        ld_co = LammpsData.from_structure(co)
        self.assertEqual(ld_co.structure.composition.reduced_formula, "Co")
        ni = Structure.from_spacegroup(225, Lattice.cubic(3.50804),
                                       ["Ni"], [[0, 0, 0]])
        ld_ni = LammpsData.from_structure(ni)
        self.assertEqual(ld_ni.structure.composition.reduced_formula, "Ni")
 def test_max_disordered_sites(self):
     l = Lattice.cubic(4)
     s_orig = Structure(l, [{"Li": 0.2, "Na": 0.2, "K": 0.6}, {"O": 1}],
                   [[0, 0, 0], [0.5, 0.5, 0.5]])
     est = EnumerateStructureTransformation(max_cell_size=None,
                                            max_disordered_sites=5)
     s = est.apply_transformation(s_orig)
     self.assertEqual(len(s), 8)
 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)
    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_max_disordered_sites(self):
     l = Lattice.cubic(4)
     s_orig = Structure(l, [{"Li": 0.2, "Na": 0.2, "K": 0.6}, {"O": 1}],
                        [[0, 0, 0], [0.5, 0.5, 0.5]])
     est = EnumerateStructureTransformation(max_cell_size=None,
                                            max_disordered_sites=5)
     dd = est.apply_transformation(s_orig, return_ranked_list=100)
     self.assertEqual(len(dd), 9)
     for d in dd:
         self.assertEqual(len(d["structure"]), 10)
    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]))
 def test_no_oxidation(self):
     specie = {"Cu1+": 0.5, "Au2+": 0.5}
     cuau = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.677),
                                      [specie], [[0, 0, 0]])
     trans = OrderDisorderedStructureTransformation()
     ss = trans.apply_transformation(cuau, return_ranked_list=100)
     self.assertEqual(ss[0]["structure"].composition["Cu+"], 2)
     trans = OrderDisorderedStructureTransformation(no_oxi_states=True)
     ss = trans.apply_transformation(cuau, return_ranked_list=100)
     self.assertEqual(ss[0]["structure"].composition["Cu+"], 0)
     self.assertEqual(ss[0]["structure"].composition["Cu"], 2)
Beispiel #43
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)
Beispiel #44
0
 def test_properties(self):
     self.assertEqual(self.kpoint.frac_coords[0], 0.1)
     self.assertEqual(self.kpoint.frac_coords[1], 0.4)
     self.assertEqual(self.kpoint.frac_coords[2], -0.5)
     self.assertEqual(self.kpoint.a, 0.1)
     self.assertEqual(self.kpoint.b, 0.4)
     self.assertEqual(self.kpoint.c, -0.5)
     self.assertEqual(self.lattice, Lattice.cubic(10.0))
     self.assertEqual(self.kpoint.cart_coords[0], 1.0)
     self.assertEqual(self.kpoint.cart_coords[1], 4.0)
     self.assertEqual(self.kpoint.cart_coords[2], -5.0)
     self.assertEqual(self.kpoint.label, "X")
Beispiel #45
0
 def setUp(self):
     self.structure = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.5),
                                             ["Ni"], [[0, 0, 0]])
     slabs = generate_all_slabs(self.structure, max_index=2,
                                min_slab_size=6.0, min_vacuum_size=15.0,
                                max_normal_search=1, center_slab=True)
     self.slab_dict = {''.join([str(i) for i in slab.miller_index]):
                       slab for slab in slabs}
     self.asf_211 = AdsorbateSiteFinder(self.slab_dict["211"])
     self.asf_100 = AdsorbateSiteFinder(self.slab_dict["100"])
     self.asf_111 = AdsorbateSiteFinder(self.slab_dict["111"])
     self.asf_110 = AdsorbateSiteFinder(self.slab_dict["110"])
    def setUp(self):
        super(TestAdsorptionWorkflow, self).setUp()

        self.struct_ir = Structure.from_spacegroup(
            "Fm-3m", Lattice.cubic(3.875728), ["Ir"], [[0, 0, 0]])
        sgp = {"max_index": 1, "min_slab_size": 7.0, "min_vacuum_size": 20.0}
        self.slabs = generate_all_slabs(self.struct_ir, **sgp)
        self.slab_100 = [slab for slab in self.slabs
                         if slab.miller_index==(1, 0, 0)][0]
        self.wf_1 = get_wf_slab(self.slab_100, True,
                                [Molecule("H", [[0, 0, 0]])],
                               db_file=os.path.join(db_dir, "db.json"))
Beispiel #47
0
    def setUp(self):

        # 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))

        # 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 as 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(os.path.dirname(__file__), "..", "..", "..",
                                   'test_files/critic2/MoS2_critic2_stdout.txt')
        with open(stdout_file, 'r') as f:
            reference_stdout = f.read()
        self.structure = Structure.from_file(os.path.join(os.path.dirname(__file__), "..", "..", "..",
                                             'test_files/critic2/MoS2.cif'))
        c2o = Critic2Output(self.structure, reference_stdout)
        self.mos2_sg = c2o.structure_graph(edge_weight="bond_length", edge_weight_units="Å")

        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()
 def test_apply_transformation(self):
     Li_bulk = Structure.from_spacegroup("Im-3m", Lattice.cubic(2.96771),
                                         ["Li"], [[0, 0, 0]])
     gb_gen_params_s3 = {"rotation_axis": [1, 1, 1], "rotation_angle": 60.0,
                         "expand_times": 2, "vacuum_thickness": 0.0, "normal": True,
                         "ratio": None, "plane": None}
     gbg = GBGenerator(Li_bulk)
     gb_from_generator = gbg.gb_from_parameters(**gb_gen_params_s3)
     gbt_s3 = GrainBoundaryTransformation(**gb_gen_params_s3)
     gb_from_trans = gbt_s3.apply_transformation(Li_bulk)
     self.assertArrayAlmostEqual(gb_from_generator.lattice.matrix,
                                 gb_from_trans.lattice.matrix)
     self.assertArrayAlmostEqual(gb_from_generator.cart_coords,
                                 gb_from_trans.cart_coords)
Beispiel #49
0
    def test_md(self):
        s = Structure.from_spacegroup(225, Lattice.cubic(3.62126),
                                      ["Cu"], [[0, 0, 0]])
        ld = LammpsData.from_structure(s, atom_style="atomic")
        ff = "\n".join(["pair_style eam", "pair_coeff * * Cu_u3.eam"])
        md = LammpsRun.md(data=ld, force_field=ff, temperature=1600.0,
                          nsteps=10000)
        md.write_inputs(output_dir="md")
        with open(os.path.join("md", "in.md")) as f:
            md_script = f.read()
        script_string = """# Sample input script template for MD

# Initialization

units           metal
atom_style      atomic

# Atom definition

read_data       md.data
#read_restart    md.restart

# Force field settings (consult official document for detailed formats)

pair_style eam
pair_coeff * * Cu_u3.eam

# Create velocities
velocity        all create 1600.0 142857 mom yes rot yes dist gaussian

# Ensemble constraints
#fix             1 all nve
fix             1 all nvt temp 1600.0 1600.0 0.1
#fix             1 all npt temp 1600.0 1600.0 0.1 iso $pressure $pressure 1.0

# Various operations within timestepping
#fix             ...
#compute         ...

# Output settings
#thermo_style    custom ...  # control the thermo data type to output
thermo          100  # output thermo data every N steps
#dump            1 all atom 100 traj.*.gz  # dump a snapshot every 100 steps

# Actions
run             10000
"""
        self.assertEqual(md_script, script_string)
        self.assertTrue(os.path.exists(os.path.join("md", "md.data")))
    def test_sulfide_type(self):
        # NaS2 -> polysulfide
        latt = Lattice.tetragonal(9.59650, 11.78850)
        species = ["Na"] * 2 + ["S"] * 2
        coords = [[0.00000, 0.00000, 0.17000],
                  [0.27600, 0.25000, 0.12500],
                  [0.03400, 0.25000, 0.29600],
                  [0.14700, 0.11600, 0.40000]]
        struct = Structure.from_spacegroup(122, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "polysulfide")

        # NaCl type NaS -> sulfide
        latt = Lattice.cubic(5.75)
        species = ["Na", "S"]
        coords = [[0.00000, 0.00000, 0.00000],
                  [0.50000, 0.50000, 0.50000]]
        struct = Structure.from_spacegroup(225, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "sulfide")

        # Na2S2O3 -> None (sulfate)
        latt = Lattice.monoclinic(6.40100, 8.10000, 8.47400, 96.8800)
        species = ["Na"] * 2 + ["S"] * 2 + ["O"] * 3
        coords = [[0.29706, 0.62396, 0.08575],
                  [0.37673, 0.30411, 0.45416],
                  [0.52324, 0.10651, 0.21126],
                  [0.29660, -0.04671, 0.26607],
                  [0.17577, 0.03720, 0.38049],
                  [0.38604, -0.20144, 0.33624],
                  [0.16248, -0.08546, 0.11608]]
        struct = Structure.from_spacegroup(14, latt, species, coords)
        self.assertEqual(sulfide_type(struct), None)

        # Na3PS3O -> sulfide
        latt = Lattice.orthorhombic(9.51050, 11.54630, 5.93230)
        species = ["Na"] * 2 + ["S"] * 2 + ["P", "O"]
        coords = [[0.19920, 0.11580, 0.24950],
                  [0.00000, 0.36840, 0.29380],
                  [0.32210, 0.36730, 0.22530],
                  [0.50000, 0.11910, 0.27210],
                  [0.50000, 0.29400, 0.35500],
                  [0.50000, 0.30300, 0.61140]]
        struct = Structure.from_spacegroup(36, latt, species, coords)
        self.assertEqual(sulfide_type(struct), "sulfide")
        
        # test for unphysical cells
        struct.scale_lattice(struct.volume*10)
        self.assertEqual(sulfide_type(struct), "sulfide")
Beispiel #51
0
 def test_init(self):
     filepath = os.path.join(test_dir, "PROCAR.simple")
     p = Procar(filepath)
     self.assertAlmostEqual(p.get_occupation(0, "d")[Spin.up], 0)
     self.assertAlmostEqual(p.get_occupation(0, "s")[Spin.up], 0.35381249999999997)
     self.assertAlmostEqual(p.get_occupation(0, "p")[Spin.up], 1.19540625)
     self.assertRaises(ValueError, p.get_occupation, 1, "m")
     self.assertEqual(p.nbands, 10)
     self.assertEqual(p.nkpoints, 10)
     self.assertEqual(p.nions, 3)
     lat = Lattice.cubic(3.0)
     s = Structure(lat, ["Li", "Na", "K"], [[0.0, 0.0, 0.0], [0.25, 0.25, 0.25], [0.75, 0.75, 0.75]])
     d = p.get_projection_on_elements(s)
     self.assertAlmostEqual(d[Spin.up][2][2], {"Na": 0.042, "K": 0.646, "Li": 0.042})
     filepath = os.path.join(test_dir, "PROCAR")
     p = Procar(filepath)
     self.assertAlmostEqual(p.get_occupation(0, "dxy")[Spin.up], 0.96214813853000025)
     self.assertAlmostEqual(p.get_occupation(0, "dxy")[Spin.down], 0.85796295426000124)
    def test_cluster(self):
        lattice = Lattice.cubic(4)

        pts = []
        initial = [[0, 0, 0], [0.5, 0.5, 0.5], [0.25, 0.25, 0.25], [0.5, 0, 0]]
        for c in initial:
            for i in range(100):
                pts.append(np.array(c) + np.random.randn(3) * 0.01 +
                           np.random.randint(3))
        pts = np.array(pts)
        k = KmeansPBC(lattice)
        centroids, labels, ss = k.cluster(pts, 4)
        for c1 in centroids:
            found = False
            for c2 in centroids:
                if np.allclose(pbc_diff(c1, c2), [0, 0, 0], atol=0.1):
                    found = True
                    break
            self.assertTrue(found)
 def test_init(self):
     filepath = os.path.join(test_dir, 'PROCAR.simple')
     p = Procar(filepath)
     self.assertAlmostEqual(p.get_occupation(1, 'd'), 0)
     self.assertAlmostEqual(p.get_occupation(1, 's'), 0.3538125)
     self.assertAlmostEqual(p.get_occupation(1, 'p'), 1.19540625)
     self.assertRaises(ValueError, p.get_occupation, 1, 'm')
     self.assertEqual(p.nb_bands, 10)
     self.assertEqual(p.nb_kpoints, 10)
     lat = Lattice.cubic(3.)
     s = Structure(lat, ["Li", "Na", "K"], [[0., 0., 0.],
                                            [0.25, 0.25, 0.25],
                                            [0.75, 0.75, 0.75]])
     d = p.get_projection_on_elements(s)
     self.assertAlmostEqual(d[1][2][2], {'Na': 0.042, 'K': 0.646, 'Li': 0.042})
     filepath = os.path.join(test_dir, 'PROCAR')
     p = Procar(filepath)
     self.assertAlmostEqual(p.get_occupation(0, 'd'), 4.3698147704200059)
     self.assertAlmostEqual(p.get_occupation(0, 'dxy'), 0.85796295426000124)
 def test_symmetrized_structure(self):
     t = OrderDisorderedStructureTransformation(symmetrized_structures=True)
     c = []
     sp = []
     c.append([0.5, 0.5, 0.5])
     sp.append('Si4+')
     c.append([0.45, 0.45, 0.45])
     sp.append({"Si4+": 0.5})
     c.append([0.56, 0.56, 0.56])
     sp.append({"Si4+": 0.5})
     c.append([0.25, 0.75, 0.75])
     sp.append({"Si4+": 0.5})
     c.append([0.75, 0.25, 0.25])
     sp.append({"Si4+": 0.5})
     l = Lattice.cubic(5)
     s = Structure(l, sp, c)
     test_site = PeriodicSite("Si4+", c[2], l)
     s = SymmetrizedStructure(s, 'not_real', [0, 1, 1, 2, 2])
     output = t.apply_transformation(s)
     self.assertTrue(test_site in output.sites)
    def test_apply_transformation(self):
        s = self.get_structure("LiFePO4")
        trans = SlabTransformation([0, 0, 1], 10, 10, shift = 0.25)
        gen = SlabGenerator(s, [0, 0, 1], 10, 10)
        slab_from_gen = gen.get_slab(0.25)
        slab_from_trans = trans.apply_transformation(s)
        self.assertArrayAlmostEqual(slab_from_gen.lattice.matrix, 
                                    slab_from_trans.lattice.matrix)
        self.assertArrayAlmostEqual(slab_from_gen.cart_coords, 
                                    slab_from_trans.cart_coords)

        fcc = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3), ["Fe"],
                                        [[0, 0, 0]])
        trans = SlabTransformation([1, 1, 1], 10, 10)
        slab_from_trans = trans.apply_transformation(fcc)
        gen = SlabGenerator(fcc, [1, 1, 1], 10, 10)
        slab_from_gen = gen.get_slab()
        self.assertArrayAlmostEqual(slab_from_gen.lattice.matrix,
                                    slab_from_trans.lattice.matrix)
        self.assertArrayAlmostEqual(slab_from_gen.cart_coords, 
                                    slab_from_trans.cart_coords)
Beispiel #56
0
 def setUp(self):
     with open(os.path.join(test_dir, 'test_toec_data.json')) as f:
         self.data_dict = json.load(f)
     self.strains = [Strain(sm) for sm in self.data_dict['strains']]
     self.pk_stresses = [Stress(d) for d in self.data_dict['pk_stresses']]
     self.c2 = self.data_dict["C2_raw"]
     self.c3 = self.data_dict["C3_raw"]
     self.exp = ElasticTensorExpansion.from_voigt([self.c2, self.c3])
     self.cu = Structure.from_spacegroup("Fm-3m", Lattice.cubic(3.623),
                                         ["Cu"], [[0]*3])
     indices = [(0, 0), (0, 1), (3, 3)]
     values = [167.8, 113.5, 74.5]
     cu_c2 = ElasticTensor.from_values_indices(values, indices, structure=self.cu,
                                               populate=True)
     indices = [(0, 0, 0), (0, 0, 1), (0, 1, 2),
                (0, 3, 3), (0, 5, 5), (3, 4, 5)]
     values = [-1507., -965., -71., -7., -901., 45.]
     cu_c3 = Tensor.from_values_indices(values, indices, structure=self.cu, 
                                        populate=True)
     self.exp_cu = ElasticTensorExpansion([cu_c2, cu_c3])
     cu_c4 = Tensor.from_voigt(self.data_dict["Cu_fourth_order"])
     self.exp_cu_4 = ElasticTensorExpansion([cu_c2, cu_c3, cu_c4])
    def setUp(self):

        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)
        self.NiO_AFM_111.add_spin_by_site([-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)
        self.NiO_AFM_001.add_spin_by_site([-5, 5, 0, 0])

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

        parser = CifParser(os.path.join(test_dir, 'Li8Fe2NiCoO8.cif'))
        self.Li8Fe2NiCoO8 = parser.get_structures()[0]
        self.Li8Fe2NiCoO8.remove_oxidation_states()
        warnings.simplefilter("ignore")
Beispiel #58
0
 def setUp(self):
     self.lattice = Lattice.cubic(10.0)
     self.kpoint = Kpoint([0.1, 0.4, -0.5], self.lattice, label="X")