Пример #1
0
Файл: xas.py Проект: utf/emmet
def feff_task_to_spectrum(doc):
    energy = doc["spectrum"][0]  # (eV)
    intensity = doc["spectrum"][3]  # (mu)
    structure: Structure = Structure.from_dict(doc["structure"])
    # Clean site properties
    for site_prop in structure.site_properties.keys():
        structure.remove_site_property(site_prop)

    absorbing_index = doc["absorbing_atom"]
    absorbing_element = structure[absorbing_index].specie
    edge = doc["edge"]
    spectrum_type = doc["spectrum_type"]

    spectrum = XAS(
        x=energy,
        y=intensity,
        structure=structure,
        absorbing_element=absorbing_element,
        absorbing_index=absorbing_index,
        edge=edge,
        spectrum_type=spectrum_type,
    )
    # Adding a attr is not a robust process
    # Figure out better solution later
    spectrum.last_updated = doc["last_updated"]
    spectrum.task_ids = [doc["xas_id"]]
    return spectrum
Пример #2
0
 def test_stitch_l23(self):
     self.l2_xanes.y[0] = 0.1
     with warnings.catch_warnings(record=True) as w:
         warnings.simplefilter("always")
         XAS.stitch(self.l2_xanes, self.l3_xanes, 100, mode="L23")
         self.assertEqual(len(w), 1)
         self.assertIs(w[-1].category, UserWarning)
         self.assertIn("jump", str(w[-1].message))
     self.l2_xanes = XAS.from_dict(l2_xanes_dict)
     l23 = XAS.stitch(self.l2_xanes, self.l3_xanes, 100, mode="L23")
     self.assertIsInstance(l23, XAS)
     self.assertEqual("L23", l23.edge)
     self.assertAlmostEqual(min(l23.x), min(self.l3_xanes.x), 3)
     self.assertAlmostEqual(max(l23.x), max(self.l3_xanes.x), 3)
     self.assertTrue(np.greater_equal(l23.y, self.l2_xanes.y).all())
     self.assertEqual(len(l23.x), 100)
     self.l2_xanes.spectrum_type = "EXAFS"
     self.assertRaises(ValueError,
                       XAS.stitch,
                       self.l2_xanes,
                       self.l3_xanes,
                       mode="L23")
     self.l2_xanes.absorbing_element = Element("Pt")
     self.assertRaises(ValueError,
                       XAS.stitch,
                       self.l2_xanes,
                       self.l3_xanes,
                       mode="L23")
     self.assertRaises(ValueError,
                       XAS.stitch,
                       self.k_xanes,
                       self.l3_xanes,
                       mode="L23")
    def setUp(self):
        self.Al2O3_xane_1 = XAS(Al2O3_spect['x'], Al2O3_spect['y'], Al2O3_stru, Element('Al'), 'K')

        self.Al2O3_xane_2 = deepcopy(self.Al2O3_xane_1)
        self.Al2O3_xane_2.x = self.Al2O3_xane_2.x - 40

        self.Al2O3_xane_left_shift5 = deepcopy(self.Al2O3_xane_1)
        self.Al2O3_xane_left_shift5.x = self.Al2O3_xane_left_shift5.x - 5

        self.Al2O3_xane_right_shift5 = deepcopy(self.Al2O3_xane_1)
        self.Al2O3_xane_right_shift5.x = self.Al2O3_xane_right_shift5.x + 5

        self.LiCoO2_xane = XAS(LiCoO2_spect['x'], LiCoO2_spect['y'], LiCoO2_stru, Element('Co'), 'K')
Пример #4
0
 def test_stitch_xafs(self):
     self.assertRaises(ValueError,
                       XAS.stitch,
                       self.k_xanes,
                       self.k_exafs,
                       mode="invalid")
     xafs = XAS.stitch(self.k_xanes, self.k_exafs, mode="XAFS")
     self.assertIsInstance(xafs, XAS)
     self.assertEqual("XAFS", xafs.spectrum_type)
     self.assertEqual(len(xafs.x), 500)
     self.assertAlmostEqual(min(xafs.x), min(self.k_xanes.x), 2)
     self.assertAlmostEqual(max(xafs.y), max(self.k_xanes.y), 2)
     self.assertAlmostEqual(
         xafs.x[np.argmax(np.gradient(xafs.y) / np.gradient(xafs.x))],
         self.k_xanes.e0,
         2,
     )
     self.assertRaises(ValueError,
                       XAS.stitch,
                       self.k_xanes,
                       self.l2_xanes,
                       mode="XAFS")
     self.k_xanes.x = np.zeros(100)
     self.assertRaises(ValueError, XAS.stitch, self.k_xanes, self.k_exafs)
     self.k_xanes.absorbing_element = Element("Pt")
     self.assertRaises(ValueError,
                       XAS.stitch,
                       self.k_xanes,
                       self.k_exafs,
                       mode="XAFS")
Пример #5
0
 def test_stitch_l23(self):
     l23 = XAS.stitch(self.l2_xanes, self.l3_xanes, 100, mode="L23")
     self.assertIsInstance(l23, XAS)
     self.assertEqual("L23", l23.edge)
     self.assertAlmostEqual(min(l23.x), min(self.l3_xanes.x), 3)
     self.assertAlmostEqual(max(l23.x), max(self.l2_xanes.x), 3)
     self.assertTrue(np.greater_equal(l23.y, self.l2_xanes.y).all())
     self.assertEqual(len(l23.x), 100)
     self.l2_xanes.spectrum_type = "EXAFS"
     self.assertRaises(ValueError,
                       XAS.stitch,
                       self.l2_xanes,
                       self.l3_xanes,
                       mode="L23")
     self.l2_xanes.absorbing_element = Element("Pt")
     self.assertRaises(ValueError,
                       XAS.stitch,
                       self.l2_xanes,
                       self.l3_xanes,
                       mode="L23")
     self.assertRaises(ValueError,
                       XAS.stitch,
                       self.k_xanes,
                       self.l3_xanes,
                       mode="L23")
Пример #6
0
 def setUp(self):
     self.k_xanes = XAS.from_dict(k_xanes_dict)
     self.k_exafs = XAS.from_dict(k_exafs_dict)
     self.l2_xanes = XAS.from_dict(l2_xanes_dict)
     self.l3_xanes = XAS.from_dict(l3_xanes_dict)
     self.site1_xanes = XAS.from_dict(site1_xanes_dict)
     self.site2_xanes = XAS.from_dict(site2_xanes_dict)
Пример #7
0
 def setUp(self):
     self.xanes = XAS.from_dict(spect_data_dict)
Пример #8
0
 def test_to_from_dict(self):
     s = XAS.from_dict(self.k_xanes.as_dict())
     self.assertArrayAlmostEqual(s.y, self.k_xanes.y)