Пример #1
0
 def total_profile(self):
     if self.bkgd_refine:
         return RietveldPhases.background_polynomial() \
             + self.raw_profile_state
     else:
         return RietveldPhases.background_polynomial() \
             + np.sum( x.phase_profile() for x in self.phase_list)
Пример #2
0
def test_set_profile():
    xyepath = os.path.join(os.path.dirname(__file__),
                           '..\\data\\profiles\\cement_15_03_11_0028.xye')
    Rp.set_profile(xyepath, min_two_theta=50, max_two_theta=52)
    assert Rp.two_theta is not None
    print(repr(Rp.two_theta))
    assert np.all(
        np.isclose(
            Rp.two_theta,
            np.array([
                50.0051, 50.0253, 50.0454, 50.0655, 50.0857, 50.1058, 50.1259,
                50.1461, 50.1662, 50.1864, 50.2065, 50.2266, 50.2468, 50.2669,
                50.2871, 50.3072, 50.3273, 50.3475, 50.3676, 50.3877, 50.4079,
                50.428, 50.4482, 50.4683, 50.4884, 50.5086, 50.5287, 50.5489,
                50.569, 50.5891, 50.6093, 50.6294, 50.6495, 50.6697, 50.6898,
                50.71, 50.7301, 50.7502, 50.7704, 50.7905, 50.8107, 50.8308,
                50.8509, 50.8711, 50.8912, 50.9113, 50.9315, 50.9516, 50.9718,
                50.9919, 51.012, 51.0322, 51.0523, 51.0725, 51.0926, 51.1127,
                51.1329, 51.153, 51.1731, 51.1933, 51.2134, 51.2336, 51.2537,
                51.2738, 51.294, 51.3141, 51.3343, 51.3544, 51.3745, 51.3947,
                51.4148, 51.4349, 51.4551, 51.4752, 51.4954, 51.5155, 51.5356,
                51.5558, 51.5759, 51.5961, 51.6162, 51.6363, 51.6565, 51.6766,
                51.6967, 51.7169, 51.737, 51.7572, 51.7773, 51.7974, 51.8176,
                51.8377, 51.8579, 51.878, 51.8981, 51.9183, 51.9384, 51.9585,
                51.9787, 51.9988
            ])))
Пример #3
0
def test_LP_intensity_scaling(set_profile):
    assert len(Rp.two_theta) == len(Rp.LP_intensity_scaling())

    two_theta = Rp.two_theta
    assert np.all(np.isclose(Rp.LP_intensity_scaling(),
        (1+np.cos(np.pi/180*two_theta)**2) \
            /np.sin(np.pi/360*two_theta) \
            /np.sin(np.pi/180*two_theta)))
def exercise_Rietveld_Refinery_SinglePhase():
    RietveldPhases.global_params_from_string(global_input_string,
                                             tst_two_theta, tst_y)

    RR = RietveldRefinery(Rt,
                          minimizer_input_string,
                          store_intermediate_state=True)
    RR.display(RR.minimize_Scale_Offset)
    RR.display(RR.minimize_All)
    RietveldPhases.empty_x()
def test_phase_list():
    RietveldPhases.set_profile(r".//data//profiles//Jade-Al2O3-Sim.xye",
                               number_of_columns=2)
    cifs = ["1000032.cif", "1507774.cif"]
    test_phase_list = []
    test_phase_list.append(
        RietveldPhases(r".//data//cifs//" + cifs[0],
                       delta_theta=2.0,
                       intensity_cutoff=0.005))
    return test_phase_list
Пример #6
0
def test_background_polynomial():
    Rp.assemble_global_x()
    Rp.bkgd[0] = 1
    assert np.all(
        np.isclose(Rp.background_polynomial(),
                   np.ones(len(Rp.two_theta), dtype=float)))

    Rp.bkgd = np.array([1, 2, 3], dtype=float)
    assert np.all(
        np.isclose(Rp.background_polynomial(),
                   1.0 + 2.0 * Rp.two_theta + 3.0 * Rp.two_theta_powers[2, :]))

    Rp.bkgd = np.array([0, 0, 0], dtype=float)
    assert np.all(
        np.isclose(Rp.background_polynomial(),
                   np.zeros(len(Rp.two_theta), dtype=float)))
def exercise_Rietveld_Refinery_Multiphase():
    RietveldPhases.global_params_from_string(global_input_string,
                                             tst_two_theta, tst_y)

    Rt = []
    for cif, input_string in zip(cifs, input_strings):
        Rt.append(
            RietveldPhases(r"..//data//cifs//" + cif,
                           d_min,
                           d_max,
                           input_string_or_file_name=input_string,
                           delta_theta=2.0,
                           Intensity_Cutoff=0.005))

    RR = RietveldRefinery(Rt,
                          minimizer_input_string,
                          store_intermediate_state=True)
    RR.display(RR.minimize_Scale_Offset)
    RR.display(RR.minimize_All)
    RietveldPhases.empty_x()
Пример #8
0
def test_rietveld_phase_as_dict_with_cubic_crystal_system():
    cub_phase = RietveldPhases('./data/cifs/Cement/1000039-AluminateCubic.cif')
    assert len(cub_phase.phase_parameters.lattice_parameters) == 1
    phase_dict = cub_phase.as_dict()
    assert len(phase_dict['lattice_parameters']) == 6
Пример #9
0
    def __init__(self, phase_list,
        rietveld_plot=None,
        bkgd_refine=False,
        store_intermediate_state=False,
        show_plots=False,
        factr=DEFAULT_FACTR,
        mask=None,
        iprint=DEFAULT_IPRINT,
        maxiter=DEFAULT_MAXITER,
        m=DEFAULT_M,
        pgtol=DEFAULT_PGTOL,
        epsilon=DEFAULT_EPSILON,
        method=DEFAULT_METHOD,
        display=DEFAULT_DISPLAY,
        # input_weights=None,
        # composition_cutoff=default_composition_cutoff,
        ):
        """
            Given some list of phases, an instance of the refinery is initialized
            to readily run a refinement process.
        """
        self.phase_list = phase_list
        self.rietveld_plot = rietveld_plot
        self.bkgd_refine = bkgd_refine
        self.store_intermediate_state = store_intermediate_state
        self.show_plots = show_plots
        self.factr = factr
        self.iprint = iprint
        self.maxiter = maxiter
        self.m = m
        self.pgtol = pgtol
        self.epsilon = epsilon
        self.method = method
        self.display = display
        # self.composition_cutoff = composition_cutoff

        self.weighted_sum_of_I_squared = np.sum(
            RietveldPhases.I**2/RietveldPhases.sigma**2)

        for key in refinement_parameters.keys:
            if key in ("labels", "values", "uround", "l_limits", "u_limits"):
                if len(self.phase_list) > 0:
                    # self.x = np.hstack((RietveldPhases.global_x,
                    #    np.hstack((x.phase_x for x in self.phase_list))))
                    if key == "uround":
                        # print(RietveldPhases.global_parameters.x[key])
                        # print([phase.phase_parameters.x[key]
                        #             for phase in self.phase_list])
                        tmp = np.concatenate((
                            RietveldPhases.global_parameters.x[key],
                            np.concatenate(
                                [phase.phase_parameters.x[key]
                                    for phase in self.phase_list], axis=0))
                            , axis=0)
                    else:
                        tmp = np.hstack((RietveldPhases.global_parameters.x[key],
        np.hstack((phase.phase_parameters.x[key] for phase in self.phase_list))))
                else:
                    RietveldPhases.assemble_global_x()
                    tmp = RietveldPhases.global_parameters.x[key]
            setattr(self, "x_" + key, tmp)
        self.x = self.x_values
            # for key in refinement_parameters.keys:
            #    setattr(self, key, RietveldPhases.global_parameters.x[key])

        if self.bkgd_refine:
            if len(self.phase_list) > 0:
                self.raw_profile_state = np.sum(x.phase_profile() for x in
                    self.phase_list)
            else:
                self.raw_profile_state = np.zeros(len(RietveldPhases.two_theta))

        self.global_mask = np.isin(np.array(xrange(len(self.x))),
            np.array(xrange(len(RietveldPhases.global_x))))
        self.bkgd_mask = self.make_mask(["bkgd"])
        self.global_mask_no_bkgd = np.logical_xor(
            self.global_mask, self.bkgd_mask)
        self.scale_mask = self.make_mask(["sca"])

        if mask is not None:
            self.mask = mask
        elif self.bkgd_refine:
            self.mask = self.bkgd_mask
        else:
            self.mask = np.zeros(len(self.x),dtype=bool)

        self.set_compositions()

        # self.composition_by_volume = np.zeros(len(self.phase_list))
        # if input_weights is not None:
        #    self.composition_by_weight = input_weights
        # else: self.composition_by_weight = 100*np.ones(len(self.phase_list))


        n=len(RietveldPhases.global_x)
        self.phase_masks = []
        self.global_and_phase_masks = []
        for phase in self.phase_list:
            self.phase_masks.append(np.isin(np.array(xrange(len(self.x))),
                np.array(xrange(n,n+len(phase.phase_x)))))
            self.global_and_phase_masks.append(np.logical_or(
                self.global_mask_no_bkgd, self.phase_masks[-1]))
            n+=len(phase.phase_x)

        self.update_state()
        if self.rietveld_plot is not None:
            self.rietveld_plot.setplotdata()
            self.rietveld_plot.updateplotprofile(self.total_profile_state,
                wse=self.relative_differences_state)
Пример #10
0
def test_phase():
    RietveldPhases.set_profile('')
    return RietveldPhases("./data/cifs/1000032.cif")
Пример #11
0
def rutile_phase():
    return RietveldPhases("./data/cifs/9015662-rutile.cif")
Пример #12
0
def test_set_bkgd_order(test_phase):
    Rp.global_parameters.set_bkgd_order(3)
    Rp.assemble_global_x()
    assert len(Rp.bkgd) == 3
    assert len(test_phase.bkgd) == 3
Пример #13
0
def test_set_profile_empty_path():
    Rp.set_profile('')
    assert len(Rp.two_theta) == 1000
Пример #14
0
def set_profile():
    return Rp.set_profile(r"./data/profiles/Jade-Al2O3-Sim.xye",
                          number_of_columns=2)