diffpy.srfit.pdf package

PDF calculation tools.

class diffpy.srfit.pdf.DebyePDFGenerator(name='pdf')[source]

Bases: BasePDFGenerator

A class for calculating the PDF from an isolated scatterer.

This works with diffpy.structure.Structure, pyobjcryst.crystal.Crystal and pyobjcryst.molecule.Molecule instances. Note that the managed Parameters are not created until the structure is added.

_calc

DebyePDFCalculator instance for calculating the PDF

_phase

The structure ParameterSets used to calculate the profile.

stru

The structure objected adapted by _phase.

_lastr

The last value of r over which the PDF was calculated. This is used to configure the calculator when r changes.

scale

Scale factor

delta1

Linear peak broadening term

delta2

Quadratic peak broadening term

qbroad

Resolution peak broadening term

qdamp

Resolution peak dampening term

Managed ParameterSets

The structure ParameterSet (SrRealStructure instance) used to calculate the profile is named by the user.

stype

The scattering type “X” for x-ray, “N” for neutron (see ‘setScatteringType’).

qmax

The maximum scattering vector used to generate the PDF (see setQmax).

qmin

The minimum scattering vector used to generate the PDF (see setQmin).

scale

See Managed Parameters.

delta1

See Managed Parameters.

delta2

See Managed Parameters.

qbroad

See Managed Parameters.

qdamp

See Managed Parameters.

setPhase(parset, periodic=False)[source]

Set the phase that will be used to calculate the PDF.

Set the phase directly with a DiffpyStructureParSet, ObjCrystCrystalParSet or ObjCrystMoleculeParSet that adapts a structure object (from diffpy or pyobjcryst). The passed ParameterSet will be managed by this generator.

Parameters:
  • parset – The SrRealParSet that holds the structural information. This can be used to share the phase between multiple BasePDFGenerators, and have the changes in one reflect in another.

  • periodic (bool, optional) – The structure should be treated as periodic (default True). Note that some structures do not support periodicity, in which case this will be ignored.

setStructure(stru, name='phase', periodic=False)[source]

Set the structure that will be used to calculate the PDF.

This creates a DiffpyStructureParSet, ObjCrystCrystalParSet or ObjCrystMoleculeParSet that adapts stru to a ParameterSet interface. See those classes (located in diffpy.srfit.structure) for how they are used. The resulting ParameterSet will be managed by this generator.

Parameters:
  • stru – The diffpy.structure.Structure, pyobjcryst.crystal.Crystal or pyobjcryst.molecule.Molecule instance to adapt (default None).

  • name (str, optional) – The name to give to the managed ParameterSet that adapts stru (default “phase”).

  • periodic (bool, optional) – The structure should be treated as periodic (default False). Note that some structures do not support periodicity, in which case this will have no effect on the PDF calculation.

class diffpy.srfit.pdf.PDFContribution(name)[source]

Bases: FitContribution

A FitContribution that is customized for PDF fits.

Data and phases can be added directly to the PDFContribution. Setup of constraints and restraints requires direct interaction with the generator attributes (see setPhase).

name

A name for this FitContribution.

profile

A Profile that holds the measured (and calculated) signal.

_meta

Metadata dictionary. This is specific to this object, and not shared with the profile. This is used to record configuration options, like qmax.

_calculators

A managed dictionary of Calculators, indexed by name.

_constraints

A set of constrained Parameters. Constraints can be added using the ‘constrain’ methods.

_generators

A managed dictionary of ProfileGenerators.

_parameters

A managed OrderedDict of parameters.

_restraints

A set of Restraints. Restraints can be added using the ‘restrain’ or ‘confine’ methods.

_parsets

A managed dictionary of ParameterSets.

_eqfactory

A diffpy.srfit.equation.builder.EquationFactory instance that is used to create constraints and restraints from string

_eq

The FitContribution equation that will be optimized.

_reseq

The residual equation.

_xname

Name of the x-variable

_yname

Name of the y-variable

_dyname

Name of the dy-variable

scale

Scale factor

qbroad

Resolution peak broadening term

qdamp

Resolution peak dampening term

addPhase(name, parset, periodic=True)[source]

Add a phase that goes into the PDF calculation.

Parameters:
  • name (str) – A name to give the generator that will manage the PDF calculation from the passed parameter phase. The parset will be accessible via the name “phase” as an attribute of the generator, e.g., contribution.name.phase, where ‘contribution’ is this contribution and ‘name’ is passed name.

  • parset – The SrRealParSet that holds the structural information. This can be used to share the phase between multiple BasePDFGenerators, and have the changes in one reflect in another.

  • periodic (bool, optional) – The structure should be treated as periodic. If this is True (default), then a PDFGenerator will be used to calculate the PDF from the phase. Otherwise, a DebyePDFGenerator will be used. Note that some structures do not support periodicity, in which case this may be ignored.

Returns:

The new phase, of the type appropriate for what was passed in parset.

Return type:

ParameterSet

addStructure(name, stru, periodic=True)[source]

Add a phase that goes into the PDF calculation.

Parameters:
  • name (str) – A name to give the generator that will manage the PDF calculation from the passed structure. The adapted structure will be accessible via the name “phase” as an attribute of the generator, e.g. contribution.name.phase, where ‘contribution’ is this contribution and ‘name’ is passed name. (default), then the name will be set as “phase”.

  • stru – The diffpy.structure.Structure, pyobjcryst.crystal.Crystal or pyobjcryst.molecule.Molecule instance to adapt (default None).

  • periodic (bool, optional) – The structure should be treated as periodic. If this is True (default), then a PDFGenerator will be used to calculate the PDF from the phase. Otherwise, a DebyePDFGenerator will be used. Note that some structures do not support periodicity, in which case this may be ignored.

Returns:

The new phase, of the type appropriate for what was passed in stru.

Return type:

ParameterSet

getQmax()[source]

Get the qmax value.

Returns:

The maximum scattering vector used to generate the PDF.

Return type:

float

getQmin()[source]

Get the qmin value.

Returns:

The minimum scattering vector used to generate the PDF.

Return type:

float

getScatteringType()[source]

Get the scattering type.

See setScatteringType.

Returns:

The scattering type used to calculate the PDF.

Return type:

str

loadData(datafile)[source]

Load the data from a data file.

This uses the PDFParser to load the data and then passes it to the built-in profile with load_parsed_data.

Parameters:

datafile (str or Path) – The path to the file that contains the data.

savetxt(fname, **kwargs)[source]

Call numpy.savetxt with x, ycalc, y, dy.

This calls on the built-in Profile.

Parameters:
  • fname (str or Path) – The file or filename to which the data is saved.

  • **kwargs – Additional arguments passed to numpy.savetxt.

setCalculationRange(xmin=None, xmax=None, dx=None)[source]

Set epsilon-inclusive calculation range.

Adhere to the observed xobs points when dx is the same as in the data. xmin and xmax are clipped at the bounds of the observed data.

Parameters:
  • xmin (float or obs, optional) – The minimum value of the independent variable. Keep the current minimum when not specified. If specified as “obs” reset to the minimum observed value.

  • xmax (float or obs, optional) – The maximum value of the independent variable. Keep the current maximum when not specified. If specified as “obs” reset to the maximum observed value.

  • dx (float or obs, optional) – The sample spacing in the independent variable. When different from the data, resample the x as anchored at xmin.

  • clipped). (Note that xmin is always inclusive (unless)

  • data. (xmax is inclusive if it is within the bounds of the observed)

Raises:
  • AttributeError – If there is no observed data.

  • ValueError – When xmin > xmax or if dx <= 0. Also if dx > xmax - xmin.

setQmax(qmax)[source]

Set the qmax value.

Parameters:

qmax (float) – The maximum scattering vector used to generate the PDF.

setQmin(qmin)[source]

Set the qmin value.

Parameters:

qmin (float) – The minimum scattering vector used to generate the PDF.

setScatteringType(type='X')[source]

Set the scattering type.

Parameters:

type (str, optional) – “X” for x-ray or “N” for neutron (default “X”).

Raises:

ValueError – If type is not “X” or “N”.

class diffpy.srfit.pdf.PDFGenerator(name='pdf')[source]

Bases: BasePDFGenerator

A class for calculating the PDF from a single crystal structure.

This works with diffpy.structure.Structure, pyobjcryst.crystal.Crystal and pyobjcryst.molecule.Molecule instances. Note that the managed Parameters are not created until the structure is added.

_calc

PDFCalculator instance for calculating the PDF

_phase

The structure ParameterSet used to calculate the profile.

_lastr

The last value of r over which the PDF was calculated. This is used to configure the calculator when r changes.

scale

Scale factor

delta1

Linear peak broadening term

delta2

Quadratic peak broadening term

qbroad

Resolution peak broadening term

qdamp

Resolution peak dampening term

Managed ParameterSets

The structure ParameterSet (SrRealStructure instance) used to calculate the profile is named by the user.

stype

The scattering type “X” for x-ray, “N” for neutron (see ‘setScatteringType’).

qmax

The maximum scattering vector used to generate the PDF (see setQmax).

qmin

The minimum scattering vector used to generate the PDF (see setQmin).

scale

See Managed Parameters.

delta1

See Managed Parameters.

delta2

See Managed Parameters.

qbroad

See Managed Parameters.

qdamp

See Managed Parameters.

class diffpy.srfit.pdf.PDFParser[source]

Bases: ProfileParser

Parser for PDF diffraction pattern data.

PDFgetX and PDFgetN write their header as plain name = value pairs, including stype = X or stype = N for the scattering type, so this class parses files identically to ProfileParser for those. Some facilities instead prepend a free-text instrument comment, so this class also falls back to scanning that comment for the scattering type, qmin, qmax, qdamp, and qbroad when they are not already present as name = value pairs.

_format

The name of the data format that this parses (string, default ""). The format string is a unique identifier for the data format handled by the parser.

_banks

The data from each bank. Each bank contains a (x, y, dx, dy) tuple:

x

A numpy array containing the independent variable read from the file.

y

A numpy array containing the profile from the file.

dx

A numpy array containing the uncertainty in x read from the file. This is None if the uncertainty cannot be read.

dy

A numpy array containing the uncertainty read from the file. This is None if the uncertainty cannot be read.

_x

The independent variable from the chosen bank.

_y

The profile from the chosen bank.

_dx

The uncertainty in independent variable from the chosen bank.

_dy

The uncertainty in profile from the chosen bank.

_meta

A dictionary containing metadata read from the file.

General Metadata:
  • filename – The name of the file from which data was parsed. This key will not exist if data was not read from file.

  • nbanks – The number of banks parsed.

  • bank – The chosen bank number.

stype

The scattering type (“X”, “N”).

qmin

The minimum scattering vector (float).

qmax

The maximum scattering vector (float).

qdamp

The Q-resolution damping factor (float).

qbroad

The Q-resolution broadening factor (float).

These, along with any other ``name = value`` pairs in the header,
may appear in the metadata dictionary.

Submodules

diffpy.srfit.pdf.debyepdfgenerator module

PDF profile generator using the Debye equation.

The DebyePDFGenerator class can take a diffpy.structure, pyobjcryst.crystal.Crystal or pyobjcryst.molecule.Molecule object and calculate the PDF from it. This generator is especially appropriate for isolated scatterers, such as nanoparticles and molecules.

class diffpy.srfit.pdf.debyepdfgenerator.DebyePDFGenerator(name='pdf')[source]

Bases: BasePDFGenerator

A class for calculating the PDF from an isolated scatterer.

This works with diffpy.structure.Structure, pyobjcryst.crystal.Crystal and pyobjcryst.molecule.Molecule instances. Note that the managed Parameters are not created until the structure is added.

_calc

DebyePDFCalculator instance for calculating the PDF

_phase

The structure ParameterSets used to calculate the profile.

stru

The structure objected adapted by _phase.

_lastr

The last value of r over which the PDF was calculated. This is used to configure the calculator when r changes.

scale

Scale factor

delta1

Linear peak broadening term

delta2

Quadratic peak broadening term

qbroad

Resolution peak broadening term

qdamp

Resolution peak dampening term

Managed ParameterSets

The structure ParameterSet (SrRealStructure instance) used to calculate the profile is named by the user.

stype

The scattering type “X” for x-ray, “N” for neutron (see ‘setScatteringType’).

qmax

The maximum scattering vector used to generate the PDF (see setQmax).

qmin

The minimum scattering vector used to generate the PDF (see setQmin).

scale

See Managed Parameters.

delta1

See Managed Parameters.

delta2

See Managed Parameters.

qbroad

See Managed Parameters.

qdamp

See Managed Parameters.

setPhase(parset, periodic=False)[source]

Set the phase that will be used to calculate the PDF.

Set the phase directly with a DiffpyStructureParSet, ObjCrystCrystalParSet or ObjCrystMoleculeParSet that adapts a structure object (from diffpy or pyobjcryst). The passed ParameterSet will be managed by this generator.

Parameters:
  • parset – The SrRealParSet that holds the structural information. This can be used to share the phase between multiple BasePDFGenerators, and have the changes in one reflect in another.

  • periodic (bool, optional) – The structure should be treated as periodic (default True). Note that some structures do not support periodicity, in which case this will be ignored.

setStructure(stru, name='phase', periodic=False)[source]

Set the structure that will be used to calculate the PDF.

This creates a DiffpyStructureParSet, ObjCrystCrystalParSet or ObjCrystMoleculeParSet that adapts stru to a ParameterSet interface. See those classes (located in diffpy.srfit.structure) for how they are used. The resulting ParameterSet will be managed by this generator.

Parameters:
  • stru – The diffpy.structure.Structure, pyobjcryst.crystal.Crystal or pyobjcryst.molecule.Molecule instance to adapt (default None).

  • name (str, optional) – The name to give to the managed ParameterSet that adapts stru (default “phase”).

  • periodic (bool, optional) – The structure should be treated as periodic (default False). Note that some structures do not support periodicity, in which case this will have no effect on the PDF calculation.

diffpy.srfit.pdf.characteristicfunctions module

Form factors (characteristic functions) used in PDF nanoshape fitting.

These are used to calculate the attenuation of the PDF due to a finite size. For a crystal-like nanoparticle, one can calculate the PDF via Gnano(r) = f(r) Gcryst(r), where f(r) is the nanoparticle characteristic function and Gcryst(f) is the crystal PDF.

These functions are meant to be imported and added to a FitContribution using the ‘register_function’ method of that class.

class diffpy.srfit.pdf.characteristicfunctions.SASCF(name, model)[source]

Bases: Calculator

Calculator class for characteristic functions from sas-models.

This class wraps a sas.models.BaseModel to calculate I(Q) related to nanoparticle shape. This I(Q) is inverted to f(r) according to: f(r) = 1 / (4 pi r) * SINFT(I(Q)), where “SINFT” represents the sine Fourier transform.

_model

BaseModel object this adapts.

Managed Parameters

These depend on the parameters of the BaseModel object held by _model. They are created from the ‘params’ attribute of the BaseModel. If a dispersion is set for the BaseModel, the dispersion “width” will be accessible under “<parname>_width”, where <parname> is the name a parameter adjusted by dispersion.

diffpy.srfit.pdf.characteristicfunctions.lognormalSphericalCF(r, psize, psig)[source]

This function has been deprecated and will be removed in version 4.0.0.

Please use diffpy.srfit.pdf.characteristicfunctions.lognormal_spherical_particle instead.

diffpy.srfit.pdf.characteristicfunctions.lognormal_spherical_particle(r, particle_diameter, particle_diameter_sigma)[source]

Compute the spherical nanoparticle characteristic function with lognormal size distribution.

Here, r is the independent variable, mu is the mean of the distribution (not of the particle size), and s is the width of the distribution. This is the characteristic function for the lognormal distribution of particle diameter:

F(r, mu, s) = (
    0.5*Erfc((-mu-3*s^2+Log(r))/(sqrt(2)*s))
    + 0.25*r^3*Erfc((-mu+Log(r))/(sqrt(2)*s))*exp(-3*mu-4.5*s^2)
    - 0.75*r*Erfc((-mu-2*s^2+Log(r))/(sqrt(2)*s))*exp(-mu-2.5*s^2)
)

The expectation value of the distribution gives the average particle diameter, particle_diameter. The variance of the distribution gives particle_diameter_sigma^2. mu and s can be expressed in terms of these as:

s^2 = log((particle_diameter_sigma/particle_diameter)^2 + 1)
mu = log(particle_diameter) - s^2/2

Source unknown.

Parameters:
  • r (array_like) – The distance of interaction.

  • particle_diameter (float) – The mean particle diameter.

  • particle_diameter_sigma (float) – The log-normal width of the particle diameter.

Returns:

The characteristic function values evaluated at r.

Return type:

numpy.ndarray

Warns:

RuntimeWarning – If particle_diameter is not positive, if particle_diameter_sigma is negative, or if particle_diameter is too small for particle_diameter_sigma for the closed form to hold, in which case the characteristic function is zero everywhere. The warning is issued only once per process. A particle_diameter_sigma of zero is the sphere limit rather than an error and does not warn.

diffpy.srfit.pdf.characteristicfunctions.sheetCF(r, sthick)[source]

This function has been deprecated and will be removed in version 4.0.0.

Please use diffpy.srfit.pdf.characteristicfunctions.sheet_particle instead.

diffpy.srfit.pdf.characteristicfunctions.sheet_particle(r, sheet_thickness)[source]

Compute the nanosheet characteristic function.

From Kodama et al., Acta Cryst. A, 62, 444-453.

Parameters:
  • r (array_like) – The distance of interaction.

  • sheet_thickness (float) – The thickness of the nanosheet.

Returns:

The characteristic function values evaluated at r.

Return type:

numpy.ndarray

Warns:

RuntimeWarning – If sheet_thickness is not positive, in which case the characteristic function is zero everywhere. The warning is issued only once per process.

diffpy.srfit.pdf.characteristicfunctions.shellCF(r, radius, thickness)[source]

This function has been deprecated and will be removed in version 4.0.0.

Please use diffpy.srfit.pdf.characteristicfunctions.shell_particle instead.

diffpy.srfit.pdf.characteristicfunctions.shellCF2(r, a, delta)[source]

This function has been deprecated and will be removed in version 4.0.0.

Please use diffpy.srfit.pdf.characteristicfunctions.shell_particle instead.

diffpy.srfit.pdf.characteristicfunctions.shell_particle(r, radius, thickness)[source]

Compute the spherical shell characteristic function.

The outer radius equals radius + thickness. From Lei et al., Phys. Rev. B, 80, 024118 (2009).

Parameters:
  • r (array_like) – The distance of interaction.

  • radius (float) – The inner radius.

  • thickness (float) – The thickness of the shell.

Returns:

The characteristic function values evaluated at r.

Return type:

numpy.ndarray

Warns:

RuntimeWarning – If thickness is not positive or radius is negative, in which case the characteristic function is zero everywhere. The warning is issued only once per process. A radius of zero is the solid sphere limit rather than an error and does not warn.

diffpy.srfit.pdf.characteristicfunctions.sphericalCF(r, psize)[source]

This function has been deprecated and will be removed in version 4.0.0.

Please use diffpy.srfit.pdf.characteristicfunctions.spherical_particle instead.

diffpy.srfit.pdf.characteristicfunctions.spherical_particle(r, particle_diameter)[source]

Compute the spherical nanoparticle characteristic function.

From Kodama et al., Acta Cryst. A, 62, 444-453 (converted from radius to diameter).

Parameters:
  • r (array_like) – The distance of interaction.

  • particle_diameter (float) – The particle diameter.

Returns:

The characteristic function values evaluated at r.

Return type:

numpy.ndarray

Warns:

RuntimeWarning – If particle_diameter is not positive, in which case the characteristic function is zero everywhere. The warning is issued only once per process.

diffpy.srfit.pdf.characteristicfunctions.spheroidalCF(r, erad, prad)[source]

This function has been deprecated and will be removed in version 4.0.0.

Please use diffpy.srfit.pdf.characteristicfunctions.spheroidal_particle instead.

diffpy.srfit.pdf.characteristicfunctions.spheroidalCF2(r, psize, axrat)[source]

This function has been deprecated and will be removed in version 4.0.0.

Please use diffpy.srfit.pdf.characteristicfunctions.spheroidal_particle instead.

diffpy.srfit.pdf.characteristicfunctions.spheroidal_particle(r, equatorial_radius, polar_radius)[source]

Compute the spheroidal nanoparticle characteristic function.

Spheroid with radii (equatorial_radius, equatorial_radius, polar_radius). equatorial_radius < polar_radius equates to a prolate spheroid, equatorial_radius > polar_radius equates to an oblate spheroid, and equatorial_radius == polar_radius is a sphere. From Lei et al., Phys. Rev. B, 80, 024118 (2009).

Parameters:
  • r (array_like) – The distance of interaction.

  • equatorial_radius (float) – The equatorial radius.

  • polar_radius (float) – The polar radius.

Returns:

The characteristic function values evaluated at r.

Return type:

numpy.ndarray

Warns:

RuntimeWarning – If equatorial_radius or polar_radius is not positive, in which case the characteristic function is zero everywhere. The warning is issued only once per process.

diffpy.srfit.pdf.pdfparser module

This module contains parsers for PDF data.

PDFParser is suitable for parsing data generated from PDFGetN and PDFGetX.

See the class documentation for more information.

class diffpy.srfit.pdf.pdfparser.PDFParser[source]

Bases: ProfileParser

Parser for PDF diffraction pattern data.

PDFgetX and PDFgetN write their header as plain name = value pairs, including stype = X or stype = N for the scattering type, so this class parses files identically to ProfileParser for those. Some facilities instead prepend a free-text instrument comment, so this class also falls back to scanning that comment for the scattering type, qmin, qmax, qdamp, and qbroad when they are not already present as name = value pairs.

_format

The name of the data format that this parses (string, default ""). The format string is a unique identifier for the data format handled by the parser.

_banks

The data from each bank. Each bank contains a (x, y, dx, dy) tuple:

x

A numpy array containing the independent variable read from the file.

y

A numpy array containing the profile from the file.

dx

A numpy array containing the uncertainty in x read from the file. This is None if the uncertainty cannot be read.

dy

A numpy array containing the uncertainty read from the file. This is None if the uncertainty cannot be read.

_x

The independent variable from the chosen bank.

_y

The profile from the chosen bank.

_dx

The uncertainty in independent variable from the chosen bank.

_dy

The uncertainty in profile from the chosen bank.

_meta

A dictionary containing metadata read from the file.

General Metadata:
  • filename – The name of the file from which data was parsed. This key will not exist if data was not read from file.

  • nbanks – The number of banks parsed.

  • bank – The chosen bank number.

stype

The scattering type (“X”, “N”).

qmin

The minimum scattering vector (float).

qmax

The maximum scattering vector (float).

qdamp

The Q-resolution damping factor (float).

qbroad

The Q-resolution broadening factor (float).

These, along with any other ``name = value`` pairs in the header,
may appear in the metadata dictionary.

diffpy.srfit.pdf.pdfgenerator module

PDF profile generator.

The PDFGenerator class can take a diffpy.structure, pyobjcryst.crystal.Crystal or pyobjcryst.molecule.Molecule object and calculate the crystal PDF from it. The passed structure object is wrapped in a StructureParameter set, which makes its attributes refinable. See the class definition for more details and the examples for its use.

class diffpy.srfit.pdf.pdfgenerator.PDFGenerator(name='pdf')[source]

Bases: BasePDFGenerator

A class for calculating the PDF from a single crystal structure.

This works with diffpy.structure.Structure, pyobjcryst.crystal.Crystal and pyobjcryst.molecule.Molecule instances. Note that the managed Parameters are not created until the structure is added.

_calc

PDFCalculator instance for calculating the PDF

_phase

The structure ParameterSet used to calculate the profile.

_lastr

The last value of r over which the PDF was calculated. This is used to configure the calculator when r changes.

scale

Scale factor

delta1

Linear peak broadening term

delta2

Quadratic peak broadening term

qbroad

Resolution peak broadening term

qdamp

Resolution peak dampening term

Managed ParameterSets

The structure ParameterSet (SrRealStructure instance) used to calculate the profile is named by the user.

stype

The scattering type “X” for x-ray, “N” for neutron (see ‘setScatteringType’).

qmax

The maximum scattering vector used to generate the PDF (see setQmax).

qmin

The minimum scattering vector used to generate the PDF (see setQmin).

scale

See Managed Parameters.

delta1

See Managed Parameters.

delta2

See Managed Parameters.

qbroad

See Managed Parameters.

qdamp

See Managed Parameters.

diffpy.srfit.pdf.basepdfgenerator module

PDF profile generator base class.

The BasePDFGenerator class interfaces with SrReal PDF calculators and is used as a base for the PDFGenerator and DebyePDFGenerator classes.

class diffpy.srfit.pdf.basepdfgenerator.BasePDFGenerator(name='pdf')[source]

Bases: ProfileGenerator

Base class for calculating PDF profiles using SrReal.

This works with diffpy.structure.Structure, pyobjcryst.crystal.Crystal and pyobjcryst.molecule.Molecule instances. Note that the managed Parameters are not created until the structure is added.

_calc

PDFCalculator or DebyePDFCalculator instance for calculating the PDF.

_phase

The structure ParameterSet used to calculate the profile.

stru

The structure objected adapted by _phase.

_lastr

The last value of r over which the PDF was calculated. This is used to configure the calculator when r changes.

_pool

A multiprocessing.Pool for managing parallel computation.

scale

Scale factor

delta1

Linear peak broadening term

delta2

Quadratic peak broadening term

qbroad

Resolution peak broadening term

qdamp

Resolution peak dampening term

Managed ParameterSets

The structure ParameterSet (SrRealParSet instance) used to calculate the profile is named by the user.

stype

The scattering type “X” for x-ray, “N” for neutron (see ‘setScatteringType’).

qmax

The maximum scattering vector used to generate the PDF (see setQmax).

qmin

The minimum scattering vector used to generate the PDF (see setQmin).

scale

See Managed Parameters.

delta1

See Managed Parameters.

delta2

See Managed Parameters.

qbroad

See Managed Parameters.

qdamp

See Managed Parameters.

getQmax()[source]

Get the qmax value.

Returns:

The maximum scattering vector used to generate the PDF.

Return type:

float

getQmin()[source]

Get the qmin value.

Returns:

The minimum scattering vector used to generate the PDF.

Return type:

float

getScatteringType()[source]

Get the scattering type.

See setScatteringType.

Returns:

The scattering type used to calculate the PDF.

Return type:

str

parallel(ncpu, mapfunc=None)[source]

Run calculation in parallel.

Parameters:
  • ncpu (int) – The number of parallel processes. Revert to serial mode when 1.

  • mapfunc (callable, optional) – The mapping function to use. If this is None (default), multiprocessing.Pool.imap_unordered will be used.

setPhase(parset, periodic=True)[source]

Set the phase that will be used to calculate the PDF.

Set the phase directly with a DiffpyStructureParSet, ObjCrystCrystalParSet or ObjCrystMoleculeParSet that adapts a structure object (from diffpy or pyobjcryst). The passed ParameterSet will be managed by this generator.

Parameters:
  • parset – The SrRealParSet that holds the structural information. This can be used to share the phase between multiple BasePDFGenerators, and have the changes in one reflect in another.

  • periodic (bool, optional) – The structure should be treated as periodic (default True). Note that some structures do not support periodicity, in which case this will be ignored.

setQmax(qmax)[source]

Set the qmax value.

Parameters:

qmax (float) – The maximum scattering vector used to generate the PDF.

setQmin(qmin)[source]

Set the qmin value.

Parameters:

qmin (float) – The minimum scattering vector used to generate the PDF.

setScatteringType(stype='X')[source]

Set the scattering type.

Parameters:

stype (str, optional) – “X” for x-ray, “N” for neutron, “E” for electrons, or any registered type from diffpy.srreal from ScatteringFactorTable.getRegisteredTypes() (default “X”).

Raises:

ValueError – If stype is not a recognized scattering type.

setStructure(stru, name='phase', periodic=True)[source]

Set the structure that will be used to calculate the PDF.

This creates a DiffpyStructureParSet, ObjCrystCrystalParSet or ObjCrystMoleculeParSet that adapts stru to a ParameterSet interface. See those classes (located in diffpy.srfit.structure) for how they are used. The resulting ParameterSet will be managed by this generator.

Parameters:
  • stru – The diffpy.structure.Structure, pyobjcryst.crystal.Crystal or pyobjcryst.molecule.Molecule instance to adapt (default None).

  • name (str, optional) – The name to give to the managed ParameterSet that adapts stru (default “phase”).

  • periodic (bool, optional) – The structure should be treated as periodic (default True). Note that some structures do not support periodicity, in which case this will have no effect on the PDF calculation.

diffpy.srfit.pdf.pdfcontribution module

PDFContribution class.

This is a custom FitContribution that simplifies the creation of PDF fits.

class diffpy.srfit.pdf.pdfcontribution.PDFContribution(name)[source]

Bases: FitContribution

A FitContribution that is customized for PDF fits.

Data and phases can be added directly to the PDFContribution. Setup of constraints and restraints requires direct interaction with the generator attributes (see setPhase).

name

A name for this FitContribution.

profile

A Profile that holds the measured (and calculated) signal.

_meta

Metadata dictionary. This is specific to this object, and not shared with the profile. This is used to record configuration options, like qmax.

_calculators

A managed dictionary of Calculators, indexed by name.

_constraints

A set of constrained Parameters. Constraints can be added using the ‘constrain’ methods.

_generators

A managed dictionary of ProfileGenerators.

_parameters

A managed OrderedDict of parameters.

_restraints

A set of Restraints. Restraints can be added using the ‘restrain’ or ‘confine’ methods.

_parsets

A managed dictionary of ParameterSets.

_eqfactory

A diffpy.srfit.equation.builder.EquationFactory instance that is used to create constraints and restraints from string

_eq

The FitContribution equation that will be optimized.

_reseq

The residual equation.

_xname

Name of the x-variable

_yname

Name of the y-variable

_dyname

Name of the dy-variable

scale

Scale factor

qbroad

Resolution peak broadening term

qdamp

Resolution peak dampening term

addPhase(name, parset, periodic=True)[source]

Add a phase that goes into the PDF calculation.

Parameters:
  • name (str) – A name to give the generator that will manage the PDF calculation from the passed parameter phase. The parset will be accessible via the name “phase” as an attribute of the generator, e.g., contribution.name.phase, where ‘contribution’ is this contribution and ‘name’ is passed name.

  • parset – The SrRealParSet that holds the structural information. This can be used to share the phase between multiple BasePDFGenerators, and have the changes in one reflect in another.

  • periodic (bool, optional) – The structure should be treated as periodic. If this is True (default), then a PDFGenerator will be used to calculate the PDF from the phase. Otherwise, a DebyePDFGenerator will be used. Note that some structures do not support periodicity, in which case this may be ignored.

Returns:

The new phase, of the type appropriate for what was passed in parset.

Return type:

ParameterSet

addStructure(name, stru, periodic=True)[source]

Add a phase that goes into the PDF calculation.

Parameters:
  • name (str) – A name to give the generator that will manage the PDF calculation from the passed structure. The adapted structure will be accessible via the name “phase” as an attribute of the generator, e.g. contribution.name.phase, where ‘contribution’ is this contribution and ‘name’ is passed name. (default), then the name will be set as “phase”.

  • stru – The diffpy.structure.Structure, pyobjcryst.crystal.Crystal or pyobjcryst.molecule.Molecule instance to adapt (default None).

  • periodic (bool, optional) – The structure should be treated as periodic. If this is True (default), then a PDFGenerator will be used to calculate the PDF from the phase. Otherwise, a DebyePDFGenerator will be used. Note that some structures do not support periodicity, in which case this may be ignored.

Returns:

The new phase, of the type appropriate for what was passed in stru.

Return type:

ParameterSet

getQmax()[source]

Get the qmax value.

Returns:

The maximum scattering vector used to generate the PDF.

Return type:

float

getQmin()[source]

Get the qmin value.

Returns:

The minimum scattering vector used to generate the PDF.

Return type:

float

getScatteringType()[source]

Get the scattering type.

See setScatteringType.

Returns:

The scattering type used to calculate the PDF.

Return type:

str

loadData(datafile)[source]

Load the data from a data file.

This uses the PDFParser to load the data and then passes it to the built-in profile with load_parsed_data.

Parameters:

datafile (str or Path) – The path to the file that contains the data.

savetxt(fname, **kwargs)[source]

Call numpy.savetxt with x, ycalc, y, dy.

This calls on the built-in Profile.

Parameters:
  • fname (str or Path) – The file or filename to which the data is saved.

  • **kwargs – Additional arguments passed to numpy.savetxt.

setCalculationRange(xmin=None, xmax=None, dx=None)[source]

Set epsilon-inclusive calculation range.

Adhere to the observed xobs points when dx is the same as in the data. xmin and xmax are clipped at the bounds of the observed data.

Parameters:
  • xmin (float or obs, optional) – The minimum value of the independent variable. Keep the current minimum when not specified. If specified as “obs” reset to the minimum observed value.

  • xmax (float or obs, optional) – The maximum value of the independent variable. Keep the current maximum when not specified. If specified as “obs” reset to the maximum observed value.

  • dx (float or obs, optional) – The sample spacing in the independent variable. When different from the data, resample the x as anchored at xmin.

  • clipped). (Note that xmin is always inclusive (unless)

  • data. (xmax is inclusive if it is within the bounds of the observed)

Raises:
  • AttributeError – If there is no observed data.

  • ValueError – When xmin > xmax or if dx <= 0. Also if dx > xmax - xmin.

setQmax(qmax)[source]

Set the qmax value.

Parameters:

qmax (float) – The maximum scattering vector used to generate the PDF.

setQmin(qmin)[source]

Set the qmin value.

Parameters:

qmin (float) – The minimum scattering vector used to generate the PDF.

setScatteringType(type='X')[source]

Set the scattering type.

Parameters:

type (str, optional) – “X” for x-ray or “N” for neutron (default “X”).

Raises:

ValueError – If type is not “X” or “N”.