Пример #1
0
    def get_target_and_edge(cls, values: Dict):
        print("Validations")
        # Only do this if neither target not edge is defined
        if "target" not in values and "edge" not in values:
            print("Are we even getting here?")
            try:
                pymatgen_wavelength = next(
                    k
                    for k, v in WAVELENGTHS.items()
                    if np.allclose(values["wavelength"], v)
                )
                values["target"] = pymatgen_wavelength[:2]
                values["edge"] = pymatgen_wavelength[2:]

            except Exception:
                return values
        return values
Пример #2
0
    def _sub_layouts(self):

        state = {
            "peak_profile": "G",
            "shape_factor": 0.94,
            "rad_source": "CuKa",
            "x_axis": "twotheta",
            "crystallite_size": 0.1,
        }

        # Main plot
        graph = Loading([
            dcc.Graph(
                figure=go.Figure(
                    layout=XRayDiffractionComponent.empty_plot_style),
                id=self.id("xrd-plot"),
                config={
                    "displayModeBar": False,  # or "hover",
                    "plotGlPixelRatio": 2,
                    "displaylogo": False,
                    # "modeBarButtons": [["toImage"]],  # to only add an image download button
                    "toImageButtonOptions": {
                        "format": "png",
                        "filename": "xrd",
                        "scale": 4,
                        "width": 600,
                        "height": 400,
                    },
                    "editable": True,
                },
                responsive=True,
                animate=False,
            )
        ])

        # Radiation source selector
        rad_source = self.get_choice_input(
            kwarg_label="rad_source",
            state=state,
            label="Radiation source",
            help_str=
            "This defines the wavelength of the incident X-ray radiation.",
            options=[{
                "label":
                f'{name.replace("a", "α").replace("b", "β")} ({wavelength:.3f} Å)',
                "value": name,
            } for name, wavelength in WAVELENGTHS.items()],
            style={"width": "10rem"},
        )

        # Shape factor input
        shape_factor = self.get_numerical_input(
            kwarg_label="shape_factor",
            state=state,
            label="Shape Factor",
            help_str=
            """The peak profile determines what distribute characterizes the broadening of an XRD pattern. 
Two extremes are Gaussian distributions, which are useful for peaks with more rounded tops (typically due to strain 
broadening) and Lorentzian distributions, which are useful for peaks with sharper top (typically due to size 
distributions and dislocations). In reality, peak shapes usually follow a Voigt distribution, which is a convolution of 
Gaussian and Lorentzian peak shapes, with the contribution to both Gaussian and Lorentzian components sample and instrument 
dependent. Here, both contributions are equally weighted if Voigt is chosen.""",
        )

        # Peak profile selector (Gaussian, Lorentzian, Voigt)
        peak_profile = self.get_choice_input(
            kwarg_label="peak_profile",
            state=state,
            label="Peak Profile",
            help_str=
            """The shape factor K, also known as the “Scherrer constant” is a dimensionless 
        quantity to obtain an actual particle size from an apparent particle size determined from XRD. The discrepancy is 
        because the shape of an individual crystallite will change the resulting diffraction broadening. Commonly, a value 
        of 0.94 for isotropic crystals in a spherical shape is used. However, in practice K can vary from 0.62 to 2.08.""",
            options=[
                {
                    "label": "Gaussian",
                    "value": "G"
                },
                {
                    "label": "Lorentzian",
                    "value": "L"
                },
                {
                    "label": "Voigt",
                    "value": "V"
                },
            ],
            style={"width": "10rem"},
        )

        # 2Theta or Q for x-axis
        x_axis_choice = html.Div(
            [
                self.get_choice_input(
                    kwarg_label="x_axis",
                    state=state,
                    label="Choice of 𝑥 axis",
                    help_str=
                    "Can choose between 2𝜃 or Q, where Q is the magnitude of the reciprocal lattice and "
                    "independent of radiation source.",  # TODO: improve
                    options=[
                        {
                            "label": "2𝜃",
                            "value": "twotheta"
                        },
                        {
                            "label": "Q",
                            "value": "Q"
                        },
                    ],
                )
            ],
            style={"display": "none"
                   },  # TODO: this is buggy! let's fix it before we share
        )

        # Crystallite size selector (via Scherrer Equation)
        crystallite_size = self.get_slider_input(
            kwarg_label="crystallite_size",
            label="Scherrer crystallite size / nm",
            state=state,
            help_str=
            "Simulate a real diffraction pattern by applying Scherrer broadening, which estimates the "
            "full width at half maximum (FWHM) resulting from a finite, rather than infinite, crystallite "
            "size.",
            domain=[-1, 2],
            step=0.01,
            isLogScale=True)

        static_image = self.get_figure_placeholder("xrd-plot")

        return {
            "x_axis": x_axis_choice,
            "graph": graph,
            "rad_source": rad_source,
            "peak_profile": peak_profile,
            "shape_factor": shape_factor,
            "crystallite_size": crystallite_size,
            "static_image": static_image,
        }