diffpy.srfit.structure package

Submodules

diffpy.srfit.structure.basestructureparset module

Base class for adapting structures to a ParameterSet interface.

The BaseStructureParSet is a ParameterSet with functionality required by all structure adapters.

class diffpy.srfit.structure.basestructureparset.BaseStructureParSet(name)[source]

Bases: ParameterSet

Base class for structure adapters.

BaseStructureParSet derives from ParameterSet and provides methods that help interface the ParameterSet with the space group constraint methods in the sgconstraints module and to ProfileGenerators.

stru

The adapted object

classmethod canAdapt(stru)[source]

Return whether the structure can be adapted by this class.

getLattice()[source]

Get a ParameterSet containing the lattice Parameters.

The returned ParameterSet may contain other Parameters than the lattice Parameters. It is assumed that the lattice parameters are named “a”, “b”, “c”, “alpha”, “beta”, “gamma”.

Lattice must also have the “angunits” attribute, which is either “deg” or “rad”, to signify degrees or radians.

getScatterers()[source]

Get a list of ParameterSets that represents the scatterers.

The site positions must be accessible from the list entries via the names “x”, “y”, and “z”. The ADPs must be accessible as well, but the name and nature of the ADPs (U-factors, B-factors, isotropic, anisotropic) depends on the adapted structure.

diffpy.srfit.structure.bvsrestraint module

Bond-valence sum calculator from SrReal wrapped as a Restraint.

This can be used as an addition to a cost function during a structure refinement to keep the bond-valence sum within tolerable limits.

class diffpy.srfit.structure.bvsrestraint.BVSRestraint(parset, sig=1, scaled=False)[source]

Bases: Restraint

Wrapping of BVSCalculator.bvmsdiff as a Restraint.

The restraint penalty is the root-mean-square deviation of the theoretical and calculated bond-valence sum of a structure.

_calc

The SrReal BVSCalculator instance.

_parset

The SrRealParSet that created this BVSRestraint.

sig

The uncertainty on the BVS (default 1).

scaled

A flag indicating if the restraint is scaled (multiplied) by the unrestrained point-average chi^2 (chi^2/numpoints) (default False).

penalty(w=1.0)[source]

Calculate the penalty of the restraint.

w

The point-average chi^2 which is optionally used to scale the penalty (float, default 1.0).

diffpy.srfit.structure.cctbxparset module

Wrappers for interfacing cctbx crystal with SrFit.

This wraps a cctbx.crystal as a ParameterSet with a similar hierarchy, which can then be used within a FitRecipe. Note that all manipulations to the cctbx.crystal should be done before wrapping. Changes made to the cctbx.crystal object after wrapping may not be reflected within the wrapper, which can have unpredictable results during a structure refinement.

Classes:

CCTBXCrystalParSet – Wrapper for cctbx.crystal CCTBXUnitCellParSet – Wrapper for the unit cell of cctbx.crystal CCTBXScattererParSet – Wrapper for cctbx.xray.scatterer

class diffpy.srfit.structure.cctbxparset.CCTBXCrystalParSet(name, stru)[source]

Bases: BaseStructureParSet

A wrapper for CCTBX structure.

stru

The adapted cctbx structure object.

scatterers

The list of ScattererParSets.

unitcell

The CCTBXUnitCellParSet for the structure.

classmethod canAdapt(stru)[source]

Return whether the structure can be adapted by this class.

getLattice()[source]

Get the ParameterSet containing the lattice Parameters.

getScatterers()[source]

Get a list of ParameterSets that represents the scatterers.

The site positions must be accessible from the list entries via the names “x”, “y”, and “z”. The ADPs must be accessible as well, but the name and nature of the ADPs (U-factors, B-factors, isotropic, anisotropic) depends on the adapted structure.

getSpaceGroup()[source]

Get the HM space group symbol for the structure.

update()[source]

Update the unit_cell to a change in lattice parameters.

This remakes the unit cell according to a change in the lattice parameters. Call this function before using the CCTBXCrystalParSet. The unit_cell will only be remade if necessary.

class diffpy.srfit.structure.cctbxparset.CCTBXScattererParSet(name, strups, idx)[source]

Bases: ParameterSet

A wrapper for cctbx.xray.scatterer.

This class derives from ParameterSet.

name

Name of the scatterer. The name is always of the form “%s%i” % (element, number), where the number is the running index of that element type (starting at 0). x (y, z) – Atom position in crystal coordinates (ParameterAdapter)

occupancy

Occupancy of the atom on its crystal location (ParameterAdapter)

Uiso

Isotropic scattering factor (ParameterAdapter).

property element
class diffpy.srfit.structure.cctbxparset.CCTBXUnitCellParSet(strups)[source]

Bases: ParameterSet

A wrapper for cctbx unit_cell object.

name

Always “unitcell”.

a

Unit cell parameters (ParameterAdapter).

b

Unit cell parameters (ParameterAdapter).

c

Unit cell parameters (ParameterAdapter).

alpha

Unit cell parameters (ParameterAdapter).

beta

Unit cell parameters (ParameterAdapter).

gamma

Unit cell parameters (ParameterAdapter).

diffpy.srfit.structure.diffpyparset module

Adapters for interfacing a diffpy.structure.Structure with SrFit.

A diffpy.structure.Structure object is meant to be passed to a DiffpyStructureParSet object from this module, which can then be used as a ParameterSet. (It has other methods for interfacing with SrReal calculator adapters.) Any change to the lattice or existing atoms will be registered with the Structure. Changes in the number of atoms will not be recognized. Thus, the diffpy.structure.Structure object should be fully configured before passing it to DiffpyStructureParSet.

DiffpyStructureParSet – Adapter for diffpy.structure.Structure DiffpyLatticeParSet – Adapter for diffpy.structure.Lattice DiffpyAtomParSet – Adapter for diffpy.structure.Atom

class diffpy.srfit.structure.diffpyparset.DiffpyStructureParSet(name, stru)[source]

Bases: SrRealParSet

A wrapper for diffpy.structure.Structure.

This class derives from diffpy.srfit.fitbase.parameterset.ParameterSet. See this class for base attributes.

atoms

The list of DiffpyAtomParSets, provided for convenience.

stru

The diffpy.structure.Structure this is adapting

lattice

The managed DiffpyLatticeParSet

<el><idx>

A managed DiffpyAtomParSets. <el> is the atomic element and <idx> is the index of that element in the structure, starting from zero. Thus, for nickel in P1 symmetry, the managed DiffpyAtomParSets will be named “Ni0”, “Ni1”, “Ni2” and “Ni3”.

classmethod canAdapt(stru)[source]

Return whether the structure can be adapted by this class.

getLattice()[source]

Get the ParameterSet containing the lattice Parameters.

getScatterers()[source]

Get a list of ParameterSets that represents the scatterers.

The site positions must be accessible from the list entries via the names “x”, “y”, and “z”. The ADPs must be accessible as well, but the name and nature of the ADPs (U-factors, B-factors, isotropic, anisotropic) depends on the adapted structure.

diffpy.srfit.structure.objcrystparset module

diffpy.srfit.structure.sgconstraints module

Code to set space group constraints for a crystal structure.

diffpy.srfit.structure.sgconstraints.constrainAsSpaceGroup(phase, spacegroup, scatterers=None, sgoffset=[0, 0, 0], constrainlat=True, constrainadps=True, adpsymbols=None, isosymbol='Uiso')[source]

Constrain the structure to the space group.

This applies space group constraints to a StructureParSet with P1 symmetry. Passed scatterers are explicitly constrained to the specified space group. The ADPs and lattice may be constrained as well.

Parameters:
  • phase – A BaseStructure object.

  • spacegroup – The space group number, symbol or an instance of SpaceGroup class from diffpy.structure package.

  • sgoffset – Optional offset for sg origin (default [0, 0, 0]).

  • scatterers – The scatterer ParameterSets to constrain. If scatterers is None (default), then all scatterers accessible from phase.getScatterers will be constrained.

  • constrainlat – Flag indicating whether to constrain the lattice (default True).

  • constrainadps – Flag indicating whether to constrain the ADPs (default True).

  • adpsymbols – A list of the ADP names. By default this is equal to diffpy.structure.symmetryutilities.stdUsymbols (U11, U22, etc.). The names must be given in the same order as stdUsymbols.

  • isosymbol – Symbol for isotropic ADP (default “Uiso”). If None, isotropic ADPs will be constrained via the anisotropic ADPs.

New Parameters that are used in constraints are created within a SpaceGroupParameters object, which is returned from this function. Constraints are created in ParameterSet that contains the constrained Parameter. This will erase any constraints or constant flags on the scatterers, lattice or ADPs if they are to be constrained.

The lattice constraints are applied as following.

Crystal System
Triclinic

No constraints.

Monoclinic

alpha and beta are fixed to 90 unless alpha != beta and alpha == gamma, in which case alpha and gamma are fixed to 90.

Orthorhombic

alpha, beta and gamma are fixed to 90.

Tetragonal

b is constrained to a and alpha, beta and gamma are fixed to 90.

Trigonal

If gamma == 120, then b is constrained to a, alpha and beta are fixed to 90 and gamma is fixed to 120. Otherwise, b and c are constrained to a, beta and gamma are fixed to alpha.

Hexagonal

b is constrained to a, alpha and beta are fixed to 90 and gamma is fixed to 120.

Cubic

b and c are constrained to a, and alpha, beta and gamma are fixed to 90.

diffpy.srfit.structure.srrealparset module

Structure wrapper class for structures compatible with SrReal.

class diffpy.srfit.structure.srrealparset.SrRealParSet(*args, **kw)[source]

Bases: BaseStructureParSet

Base class for SrReal-compatible structure adapters.

This derives from BaseStructureParSet and provides some extended functionality provided by SrReal.

stru

The adapted object

_usesymmetry

A flag indicating if SrReal calculators that operate on this object should use symmetry. By default this is True.

restrainBVS(sig=1, scaled=False)[source]

Restrain the bond-valence sum to zero.

This adds a penalty to the cost function equal to bvmsdiff / sig**2 where bvmsdiff is the mean-squared difference between the calculated and expected bond valence sums for the structure. If scaled is True, this is also scaled by the current point-averaged chi^2 value so the restraint is roughly equally weighted in the fit.

sig

The uncertainty on the BVS (default 1).

scaled

A flag indicating if the restraint is scaled (multiplied) by the unrestrained point-average chi^2 (chi^2/numpoints) (default False).

Returns the BVSRestraint object for use with the 'unrestrain' method.
useSymmetry(use=True)[source]

Set this structure to use symmetry.

This determines how the structure is treated by SrReal calculators.

usingSymmetry()[source]

Check if symmetry is being used.

Module contents

Modules and classes that adapt structure representations to the ParameterSet interface and automatic structure constraint generation from space group information.

diffpy.srfit.structure.struToParameterSet(name, stru)[source]

Creates a ParameterSet from an structure.

This returns a ParameterSet adapted for the structure depending on its type.

diffpy.srfit.structure.stru

a structure object known by this module

diffpy.srfit.structure.name

A name to give the structure.

Raises TypeError if stru cannot be adapted