Skip to content

cif2xrd

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.cif2xrd

available module-attribute

available = True

Engine

Bases: Engine_pymatgen

Source code in FoSpy/plotting/diffraction/engines/cif2xrd.py
class Engine(Engine_pymatgen):
    def __init__(self, cif_path, **kwargs):
        if not available:
            raise ImportError("Diffraction engine cif2xrd is not installed. Install it with `pip install cif2xrd`")
        self.sim = simPattern(cif_path, **kwargs)
    def get_pattern(self,two_theta_range:tuple=None, **kwargs):
        self.sim.set_parameters(**kwargs)
        return self._to_frame(self.sim.two_theta, self.sim.intensity)

sim instance-attribute

sim = simPattern(cif_path, **kwargs)

__init__

__init__(cif_path, **kwargs)
Source code in FoSpy/plotting/diffraction/engines/cif2xrd.py
def __init__(self, cif_path, **kwargs):
    if not available:
        raise ImportError("Diffraction engine cif2xrd is not installed. Install it with `pip install cif2xrd`")
    self.sim = simPattern(cif_path, **kwargs)

get_pattern

get_pattern(two_theta_range=None, **kwargs)
Source code in FoSpy/plotting/diffraction/engines/cif2xrd.py
def get_pattern(self,two_theta_range:tuple=None, **kwargs):
    self.sim.set_parameters(**kwargs)
    return self._to_frame(self.sim.two_theta, self.sim.intensity)

Engine_pymatgen

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