def generate_diffraction_plot(args): s = Structure.from_file(args.filenames[0]) c = XRDCalculator() if args.outfile: c.get_xrd_plot(s).savefig(args.outfile[0]) else: c.show_xrd_plot(s)
def test_get_xrd_data(self): s = self.get_structure("CsCl") c = XRDCalculator() xrd = c.get_xrd_pattern(s, two_theta_range=(0, 90)) # Check the first two peaks self.assertAlmostEqual(xrd.x[0], 21.107738329639844) self.assertAlmostEqual(xrd.y[0], 36.483184003748946) self.assertEqual(xrd.hkls[0], {(1, 0, 0): 6}) self.assertAlmostEqual(xrd.d_hkls[0], 4.2089999999999996) self.assertAlmostEqual(xrd.x[1], 30.024695921112777) self.assertAlmostEqual(xrd.y[1], 100) self.assertEqual(xrd.hkls[1], {(1, 1, 0): 12}) self.assertAlmostEqual(xrd.d_hkls[1], 2.976212442014178) s = self.get_structure("LiFePO4") xrd = c.get_xrd_pattern(s, two_theta_range=(0, 90)) self.assertAlmostEqual(xrd.x[1], 17.03504233621785) self.assertAlmostEqual(xrd.y[1], 50.400928948337075) s = self.get_structure("Li10GeP2S12") xrd = c.get_xrd_pattern(s, two_theta_range=(0, 90)) self.assertAlmostEqual(xrd.x[1], 14.058274883353876) self.assertAlmostEqual(xrd.y[1], 4.4111123641667671) # Test a hexagonal structure. s = self.get_structure("Graphite") xrd = c.get_xrd_pattern(s, two_theta_range=(0, 90)) self.assertAlmostEqual(xrd.x[0], 26.21057350859598) self.assertAlmostEqual(xrd.y[0], 100) self.assertAlmostEqual(len(list(xrd.hkls[0].keys())[0]), 4) # Add test case with different lengths of coefficients. # Also test d_hkl. coords = [[0.25, 0.25, 0.173], [0.75, 0.75, 0.827], [0.75, 0.25, 0], [0.25, 0.75, 0], [0.25, 0.25, 0.676], [0.75, 0.75, 0.324]] sp = ["Si", "Si", "Ru", "Ru", "Pr", "Pr"] s = Structure(Lattice.tetragonal(4.192, 6.88), sp, coords) xrd = c.get_xrd_pattern(s) self.assertAlmostEqual(xrd.x[0], 12.86727341476735) self.assertAlmostEqual(xrd.y[0], 31.448239816769796) self.assertAlmostEqual(xrd.d_hkls[0], 6.88) self.assertEqual(len(xrd), 42) xrd = c.get_xrd_pattern(s, two_theta_range=[0, 60]) self.assertEqual(len(xrd), 18) # Test with and without Debye-Waller factor tungsten = Structure(Lattice.cubic(3.1653), ["W"] * 2, [[0, 0, 0], [0.5, 0.5, 0.5]]) xrd = c.get_xrd_pattern(tungsten, scaled=False) self.assertAlmostEqual(xrd.x[0], 40.294828554672264) self.assertAlmostEqual(xrd.y[0], 2414237.5633093244) self.assertAlmostEqual(xrd.d_hkls[0], 2.2382050944897789) c = XRDCalculator(debye_waller_factors={"W": 0.1526}) xrd = c.get_xrd_pattern(tungsten, scaled=False) self.assertAlmostEqual(xrd.x[0], 40.294828554672264) self.assertAlmostEqual(xrd.y[0], 2377745.2296686019) self.assertAlmostEqual(xrd.d_hkls[0], 2.2382050944897789) c.get_xrd_plot(tungsten)
def calculate_xrd(request): results = {} xrd = XRDCalculator(symprec=0.01) for name, f in request.FILES.items(): name, s = get_structure(f) plt = xrd.get_xrd_plot(s, annotate_peaks=False) fig = plt.gcf() fig.set_dpi(100) fig.set_size_inches(8, 6) ax = plt.gca() plt.setp(ax.get_xticklabels(), fontsize=16) plt.setp(ax.get_yticklabels(), fontsize=16) ax.xaxis.label.set_size(16) ax.yaxis.label.set_size(16) si = StringIO() plt.savefig(si, format="svg") results[name] = si.getvalue() return results
# wave = One of [Cuka, AgKa, MoKa, FeKa] p = Poscar.from_file(os.path.join(poscar_dir, "POSCAR"), check_for_POTCAR=False) lattice = p.structure.lattice species = p.structure.species frac_coords = p.structure.frac_coords structure = Structure(lattice, species, frac_coords) plt = pretty_plot(16, 14) ax = plt.gca() c_cuka = XRDCalculator("CuKa") d1 = c_cuka.get_xrd_plot(structure, two_theta_range=(0, 100), annotate_peaks=False, ax=ax) d1.savefig(os.path.join(dest_dir, "xrd_CuKa.png")) c_agka = XRDCalculator("AgKa") d2 = c_agka.get_xrd_plot(structure, two_theta_range=(0, 100), annotate_peaks=False, ax=ax) d2.savefig(os.path.join(dest_dir, "xrd_AgKa.png")) c_moka = XRDCalculator("MoKa") d3 = c_moka.get_xrd_plot(structure, two_theta_range=(0, 100), annotate_peaks=False, ax=ax)
def get_xrd_plot(args): s = Structure.from_file(args.xrd_structure_file) c = XRDCalculator() return c.get_xrd_plot(s)
def get_xrd_plot(args): s = Structure.from_file(args.xrd) c = XRDCalculator() return c.get_xrd_plot(s)