Skip to content

pymatgen

Full documentation pages are generated for docstring reference only and may contain symbols imported from other modules. Imported symbols are not distinguished from locally defined symbols and will appear in any module that they are imported into. For better information on where symbols should be imported from, review the sourcecode on the github.

FoSpy.plotting.diffraction.engines.pymatgen

cfg module-attribute

cfg = None

CIF_engine

Source code in FoSpy/plotting/diffraction/engines/_base.py
class CIF_engine:
    def _to_frame(self, two_theta, intensity):
        from ....config import values as cfg
        x_label = cfg.diffraction.x_label
        return pd.DataFrame({x_label:two_theta, 'int':intensity})

    def get_pattern(self, **kwargs):
        from ....config import values as cfg

        params = cfg.diffraction.pattern_parameters().copy()
        params.update(kwargs)
        return params

_to_frame

_to_frame(two_theta, intensity)
Source code in FoSpy/plotting/diffraction/engines/_base.py
4
5
6
7
def _to_frame(self, two_theta, intensity):
    from ....config import values as cfg
    x_label = cfg.diffraction.x_label
    return pd.DataFrame({x_label:two_theta, 'int':intensity})

get_pattern

get_pattern(**kwargs)
Source code in FoSpy/plotting/diffraction/engines/_base.py
def get_pattern(self, **kwargs):
    from ....config import values as cfg

    params = cfg.diffraction.pattern_parameters().copy()
    params.update(kwargs)
    return params

Engine

Bases: CIF_engine

Source code in FoSpy/plotting/diffraction/engines/pymatgen.py
class Engine(CIF_engine):
    def __init__(self, cif_path, **kwargs):
        from pymatgen.analysis.diffraction.xrd import XRDCalculator
        from pymatgen.core.structure import Structure
        self.structure = Structure.from_file(cif_path)
        self.sim = XRDCalculator()

    def get_pattern(self,**kwargs):
        import numpy as np

        pattern_config = cfg.get("diffraction.pattern_parameters")
        pattern_config.update(kwargs)

        step = pattern_config.pop('two_theta_step')
        tth_range = pattern_config['two_theta_range']

        peaks = self.get_peaks(**pattern_config)

        two_theta = []
        intensity = []
        for (x,y) in peaks:
            two_theta.append(step*round(x/step))
            intensity.append(y)


        frame =  self._to_frame(two_theta, intensity)
        x_min, x_max = tth_range
        grid = np.arange(x_min, x_max+step, step)

        frame = (frame.
                 set_index(cfg.diffraction.x_label).
                 reindex(grid).
                 fillna(0).
                 reset_index())
        return frame

    def get_peaks(self,two_theta_range=None, normalize=None):

        if two_theta_range is None:
            two_theta_range = cfg.get("diffraction.pattern_parameters.two_theta_range")

        if normalize is None:
            normalize = cfg.get("diffraction.pattern_parameters.normalize")


        pattern = self.sim.get_pattern(self.structure, two_theta_range=two_theta_range, scaled = False)

        if normalize:
            pattern.y = pattern.y / max(pattern.y)

        peaks = tuple((x, y) for x, y in zip(pattern.x, pattern.y))
        return peaks

sim instance-attribute

sim = XRDCalculator()

structure instance-attribute

structure = Structure.from_file(cif_path)

__init__

__init__(cif_path, **kwargs)
Source code in FoSpy/plotting/diffraction/engines/pymatgen.py
5
6
7
8
9
def __init__(self, cif_path, **kwargs):
    from pymatgen.analysis.diffraction.xrd import XRDCalculator
    from pymatgen.core.structure import Structure
    self.structure = Structure.from_file(cif_path)
    self.sim = XRDCalculator()

get_pattern

get_pattern(**kwargs)
Source code in FoSpy/plotting/diffraction/engines/pymatgen.py
def get_pattern(self,**kwargs):
    import numpy as np

    pattern_config = cfg.get("diffraction.pattern_parameters")
    pattern_config.update(kwargs)

    step = pattern_config.pop('two_theta_step')
    tth_range = pattern_config['two_theta_range']

    peaks = self.get_peaks(**pattern_config)

    two_theta = []
    intensity = []
    for (x,y) in peaks:
        two_theta.append(step*round(x/step))
        intensity.append(y)


    frame =  self._to_frame(two_theta, intensity)
    x_min, x_max = tth_range
    grid = np.arange(x_min, x_max+step, step)

    frame = (frame.
             set_index(cfg.diffraction.x_label).
             reindex(grid).
             fillna(0).
             reset_index())
    return frame

get_peaks

get_peaks(two_theta_range=None, normalize=None)
Source code in FoSpy/plotting/diffraction/engines/pymatgen.py
def get_peaks(self,two_theta_range=None, normalize=None):

    if two_theta_range is None:
        two_theta_range = cfg.get("diffraction.pattern_parameters.two_theta_range")

    if normalize is None:
        normalize = cfg.get("diffraction.pattern_parameters.normalize")


    pattern = self.sim.get_pattern(self.structure, two_theta_range=two_theta_range, scaled = False)

    if normalize:
        pattern.y = pattern.y / max(pattern.y)

    peaks = tuple((x, y) for x, y in zip(pattern.x, pattern.y))
    return peaks