Beispiel #1
0
    def test_get_pattern(self):
        s = self.get_structure("CsCl")
        c = NDCalculator(wavelength=1.54184)  # CuKa radiation
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        # Check the first two peaks
        self.assertAlmostEqual(nd.x[0], 21.107738329639844)
        self.assertEqual(nd.hkls[0], [{'hkl': (1, 0, 0), 'multiplicity': 6}])
        self.assertAlmostEqual(nd.d_hkls[0], 4.2089999999999996)
        self.assertAlmostEqual(nd.x[1], 30.024695921112777)
        self.assertEqual(nd.hkls[1], [{'hkl': (1, 1, 0), 'multiplicity': 12}])
        self.assertAlmostEqual(nd.d_hkls[1], 2.976212442014178)

        s = self.get_structure("LiFePO4")
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[1], 17.03504233621785)
        self.assertAlmostEqual(nd.y[1], 46.2985965)

        s = self.get_structure("Li10GeP2S12")
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[1], 14.058274883353876)
        self.assertAlmostEqual(nd.y[1], 3.60588013)

        # Test a hexagonal structure.
        s = self.get_structure("Graphite")
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[0], 26.21057350859598)
        self.assertAlmostEqual(nd.y[0], 100)
        self.assertAlmostEqual(nd.x[2], 44.39599754)
        self.assertAlmostEqual(nd.y[2], 42.62382267)
        self.assertAlmostEqual(len(nd.hkls[0][0].keys()), 2)

        # Test an exception in case of the input element is
        # not in scattering length table.
        # This curium structure is just for test, not the actual structure.
        something = Structure(Lattice.cubic(a=1), ["Cm"], [[0, 0, 0]])
        with self.assertRaises(ValueError):
            nd = c.get_pattern(something, two_theta_range=(0, 90))

        # Test with Debye-Waller factor
        s = self.get_structure("Graphite")
        c = NDCalculator(wavelength=1.54184, debye_waller_factors={'C': 1})
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[0], 26.21057350859598)
        self.assertAlmostEqual(nd.y[0], 100)
        self.assertAlmostEqual(nd.x[2], 44.39599754)
        self.assertAlmostEqual(nd.y[2], 39.471514740)
Beispiel #2
0
    def test_get_pattern(self):
        s = self.get_structure("CsCl")
        c = NDCalculator(wavelength=1.54184)  # CuKa radiation
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        # Check the first two peaks
        self.assertAlmostEqual(nd.x[0], 21.107738329639844)
        self.assertEqual(nd.hkls[0], {(1, 0, 0): 6})
        self.assertAlmostEqual(nd.d_hkls[0], 4.2089999999999996)
        self.assertAlmostEqual(nd.x[1], 30.024695921112777)
        self.assertEqual(nd.hkls[1], {(1, 1, 0): 12})
        self.assertAlmostEqual(nd.d_hkls[1], 2.976212442014178)

        s = self.get_structure("LiFePO4")
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[1], 17.03504233621785)
        self.assertAlmostEqual(nd.y[1], 46.2985965)

        s = self.get_structure("Li10GeP2S12")
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[1], 14.058274883353876)
        self.assertAlmostEqual(nd.y[1], 3.60588013)

        # Test a hexagonal structure.
        s = self.get_structure("Graphite")
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[0], 26.21057350859598)
        self.assertAlmostEqual(nd.y[0], 100)
        self.assertAlmostEqual(nd.x[2], 44.39599754)
        self.assertAlmostEqual(nd.y[2], 42.62382267)
        self.assertAlmostEqual(len(list(nd.hkls[0].keys())[0]), 4)

        # Test an exception in case of the input element is
        # not in scattering length table.
        # This curium structure is just for test, not the actual structure.
        something = Structure(Lattice.cubic(a=1), ["Cm"], [[0, 0, 0]])
        with self.assertRaises(ValueError):
            nd = c.get_pattern(something, two_theta_range=(0, 90))

        # Test with Debye-Waller factor
        s = self.get_structure("Graphite")
        c = NDCalculator(wavelength=1.54184, debye_waller_factors={'C': 1})
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[0], 26.21057350859598)
        self.assertAlmostEqual(nd.y[0], 100)
        self.assertAlmostEqual(nd.x[2], 44.39599754)
        self.assertAlmostEqual(nd.y[2], 39.471514740)
    def test_get_pattern(self):
        s = self.get_structure("CsCl")
        c = NDCalculator(wavelength=1.54184)  # CuKa radiation
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        # Check the first two peaks
        self.assertAlmostEqual(nd.x[0], 21.107738329639844)
        # self.assertAlmostEqual(nd.y[0], 36.483184003748946)
        self.assertEqual(nd.hkls[0], {(1, 0, 0): 6})
        self.assertAlmostEqual(nd.d_hkls[0], 4.2089999999999996)
        self.assertAlmostEqual(nd.x[1], 30.024695921112777)
        # self.assertAlmostEqual(nd.y[1], 100)
        self.assertEqual(nd.hkls[1], {(1, 1, 0): 12})
        self.assertAlmostEqual(nd.d_hkls[1], 2.976212442014178)

        s = self.get_structure("LiFePO4")
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[1], 17.03504233621785)
        self.assertAlmostEqual(nd.y[1], 46.2985965)

        s = self.get_structure("Li10GeP2S12")
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[1], 14.058274883353876)
        self.assertAlmostEqual(nd.y[1], 3.60588013)

        # Test a hexagonal structure.
        s = self.get_structure("Graphite")
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[0], 26.21057350859598)
        self.assertAlmostEqual(nd.y[0], 100)
        self.assertAlmostEqual(nd.x[2], 44.39599754)
        self.assertAlmostEqual(nd.y[2], 42.62382267)
        self.assertAlmostEqual(len(list(nd.hkls[0].keys())[0]), 4)

        # Test with Debye-Waller factor
        s = self.get_structure("Graphite")
        c = NDCalculator(wavelength=1.54184, debye_waller_factors={'C': 1})
        nd = c.get_pattern(s, two_theta_range=(0, 90))
        self.assertAlmostEqual(nd.x[0], 26.21057350859598)
        self.assertAlmostEqual(nd.y[0], 100)
        self.assertAlmostEqual(nd.x[2], 44.39599754)
        self.assertAlmostEqual(nd.y[2], 39.471514740)
Beispiel #4
0
 def test_get_plot(self):
     s = self.get_structure("Graphite")
     c = NDCalculator(wavelength=1.54184, debye_waller_factors={'C': 1})
     c.get_plot(s, two_theta_range=(0, 90))
Beispiel #5
0
def list_get_pattern(list_struc):
    ls = []
    for structure in list_struc:
        i = NDCalculator()
        ls.append(i.get_pattern(structure))
    return ls
Beispiel #6
0

"""
  implemented for debugging purpose
"""
import pandas as pd
from pymatgen.core.periodic_table import Element
from pymatgen.core.structure import Structure
from pymatgen.analysis.diffraction.neutron import NDCalculator
if __name__ == "__main__":
    # obtain material cif file
    filenames = pd.read_csv('../MPdata_all/MPdata_all.csv', sep=';', header=0, index_col=None)['material_id']
    for ifile in filenames.sample(n=500):
        cif_file = '../MPdata_all/' + ifile + '.cif'
        assert(os.path.isfile(cif_file))
        struct = Structure.from_file(cif_file)
        if (Element('Ac') in struct.species) or (Element('Pu') in struct.species):
            continue
        sga = SpacegroupAnalyzer(struct, symprec=0.1)
        conventional_struct = sga.get_conventional_standard_structure()
            
        # compute neutron diffraction pattern and compare outputs
        pattern, _, _ = NDSimulator().get_pattern(conventional_struct, two_theta_range=None)
        pattern_pymatgen = NDCalculator().get_pattern(conventional_struct, two_theta_range=None)
        abs_error = max(abs(np.array(pattern.x) - np.array(pattern_pymatgen.x)))
        if abs_error > 1E-12:
            print('{} did not pass the test, error: {:.6f}'.format(ifile, abs_error))
    print('finished checking the implementation..')