diffpy.srfit.structure package

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.

Parameters:
  • stru – a structure object known by this module

  • name – A name to give the structure.

  • adapted (Raises TypeError if stru cannot be)

Submodules

diffpy.srfit.structure.objcrystparset module

Wrappers for adapting pyobjcryst.crystal.Crystal to a srfit ParameterSet.

This will adapt a Crystal or Molecule object from pyobjcryst into the ParameterSet interface. The following classes are adapted:

  • ObjCrystCrystalParSet: adapter for pyobjcryst.crystal.Crystal.

  • ObjCrystAtomParSet: adapter for pyobjcryst.atom.Atom.

  • ObjCrystMoleculeParSet: adapter for pyobjcryst.molecule.Molecule.

  • ObjCrystMolAtomParSet: adapter for pyobjcryst.molecule.MolAtom.

Related to the adaptation of Molecule and MolAtom, there are adaptors for specifying molecule restraints:

  • ObjCrystBondLengthRestraint

  • ObjCrystBondAngleRestraint

  • ObjCrystDihedralAngleRestraint

There are also Parameters for encapsulating and modifying atoms via their relative positions. These Parameters can also act like constraints, and can modify the positions of multiple MolAtoms:

  • ObjCrystBondLengthParameter

  • ObjCrystBondAngleParameter

  • ObjCrystDihedralAngleParameter

class diffpy.srfit.structure.objcrystparset.ObjCrystCrystalParSet(name, cryst)[source]

Bases: SrRealParSet

A adaptor for pyobjcryst.crystal.Crystal instance.

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

stru

The adapted pyobjcryst.Crystal.

scatterers

The list of aggregated ScattererParSets (either ObjCrystAtomParSet or ObjCrystMoleculeParSet), provided for convenience.

_sgpars

A BaseSpaceGroupParameters object containing free structure Parameters. See the diffpy.srfit.structure.sgconstraints module.

sgpars

property that creates _sgpars when it is needed.

angunits

“rad”, the units of angle

Parameters:
  • x – Scatterer position in crystal coordinates (ParameterWraper)

  • y – Scatterer position in crystal coordinates (ParameterWraper)

  • z – Scatterer position in crystal coordinates (ParameterWraper)

  • occ – Occupancy of the scatterer on its crystal site (ParameterWraper)

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.

property sgpars

Constrain the space group.

class diffpy.srfit.structure.objcrystparset.ObjCrystMoleculeParSet(name, molecule, parent=None)[source]

Bases: ObjCrystScattererParSet

A adaptor for a pyobjcryst.Molecule.

This class derives from ObjCrystScattererParSet.

scat

The adapted pyobjcryst.molecule.Molecule.

stru

The adapted pyobjcryst.molecule.Molecule.

parent

The ObjCrystCrystalParSet this belongs to. ObjCrystMoleculeParSets can be used on their own, in which case this is None.

occ

Occupancy of the molecule on its crystal location (ParameterAdapter) q0, q1, q2, q3 – Orientational quaternion (ParameterAdapter)

Other attributes are inherited from diffpy.srfit.fitbase.parameterset.ParameterSet

addBondAngleParameter(name, atom1, atom2, atom3, value=None, const=False)[source]

Add a bond angle to the Molecule.

This creates a ObjCrystBondAngleParameter to the ObjCrystMoleculeParSet that can be adjusted during the fit.

Parameters:
  • name – The name of the ObjCrystBondAngleParameter

  • atom1 – The first atom (ObjCrystMolAtomParSet) in the bond angle

  • atom2 – The second (central) atom (ObjCrystMolAtomParSet) in the bond angle

  • atom3 – The third (mutated) atom (ObjCrystMolAtomParSet) in the bond angle

  • value – An initial value for the bond angle. If this is None (default), then the current bond angle between the atoms will be used.

  • const – A flag indicating whether the Parameter is constant (default False).

Returns:

Returns the new ObjCrystBondAngleParameter.

Return type:

ObjCrystBondAngleParameter object

addBondLengthParameter(name, atom1, atom2, value=None, const=False)[source]

Add a bond length to the Molecule.

This creates a ObjCrystBondLengthParameter to the ObjCrystMoleculeParSet that can be adjusted during the fit.

Parameters:
  • name – The name of the ObjCrystBondLengthParameter

  • atom1 – The first atom (ObjCrystMolAtomParSet) in the bond

  • atom2 – The second (mutated) atom (ObjCrystMolAtomParSet) in the bond

  • value – An initial value for the bond length. If this is None (default), then the current distance between the atoms will be used.

  • const – A flag indicating whether the Parameter is constant (default False)

Returns:

Returns the new ObjCrystBondLengthParameter.

Return type:

ObjCrystBondLengthParameter object

addDihedralAngleParameter(name, atom1, atom2, atom3, atom4, value=None, const=False)[source]

Add a dihedral angle to the Molecule.

This creates a ObjCrystDihedralAngleParameter to the ObjCrystMoleculeParSet that can be adjusted during the fit.

Parameters:
  • name – The name of the ObjCrystDihedralAngleParameter.

  • atom1 – The first atom (ObjCrystMolAtomParSet) in the dihderal angle.

  • atom2 – The second (central) atom (ObjCrystMolAtomParSet) in the dihderal angle

  • atom3 – The third (central) atom (ObjCrystMolAtomParSet) in the dihderal angle

  • atom4 – The fourth (mutated) atom (ObjCrystMolAtomParSet) in the dihderal angle

  • value – An initial value for the dihedral angle. If this is None (default), then the current dihedral angle between atoms will be used.

  • const – A flag indicating whether the Parameter is constant (default False).

Returns:

Returns the new ObjCrystDihedralAngleParameter.

Return type:

ObjCrystDihedralAngleParameter object

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.

restrainBondAngle(atom1, atom2, atom3, angle, sigma, delta, scaled=False)[source]

Add a bond angle restraint.

This creates an instance of ObjCrystBondAngleRestraint and adds it to the ObjCrystMoleculeParSet.

Parameters:
  • atom1 – First atom (ObjCrystMolAtomParSet) in the bond angle

  • atom2 – Second (central) atom (ObjCrystMolAtomParSet) in the bond angle

  • atom3 – Third atom (ObjCrystMolAtomParSet) in the bond angle

  • angle – The bond angle (radians)

  • sigma – The uncertainty of the bond angle (radians)

  • delta – The width of the bond angle (radians)

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

Returns:

Returns the ObjCrystBondAngleRestraint object for use with the ‘unrestrain’ method.

Return type:

ObjCrystBondAngleRestraint object

restrainBondAngleParameter(par, angle, sigma, delta, scaled=False)[source]

Add a bond angle restraint.

This creates an instance of ObjCrystBondAngleRestraint and adds it to the ObjCrystMoleculeParSet.

Parameters:
  • par – A ObjCrystBondAngleParameter (see addBondAngleParameter)

  • angle – The bond angle (radians)

  • sigma – The uncertainty of the bond angle (radians)

  • delta – The width of the bond angle (radians)

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

Returns:

Returns the ObjCrystBondAngleRestraint object for use with the ‘unrestrain’ method.

Return type:

ObjCrystBondAngleRestraint object

restrainBondLength(atom1, atom2, length, sigma, delta, scaled=False)[source]

Add a bond length restraint.

This creates an instance of ObjCrystBondLengthRestraint and adds it to the ObjCrystMoleculeParSet.

Parameters:
  • atom1 – First atom (ObjCrystMolAtomParSet) in the bond

  • atom2 – Second atom (ObjCrystMolAtomParSet) in the bond

  • length – The length of the bond (Angstroms)

  • sigma – The uncertainty of the bond length (Angstroms)

  • delta – The width of the bond (Angstroms)

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

Returns:

The ObjCrystBondLengthRestraint object for use with the ‘unrestrain’ method.

Return type:

res

restrainBondLengthParameter(par, length, sigma, delta, scaled=False)[source]

Add a bond length restraint.

This creates an instance of ObjCrystBondLengthRestraint and adds it to the ObjCrystMoleculeParSet.

Parameters:
  • par – A ObjCrystBondLengthParameter (see addBondLengthParameter)

  • length – The length of the bond (Angstroms)

  • sigma – The uncertainty of the bond length (Angstroms)

  • delta – The width of the bond (Angstroms)

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

Returns:

Returns the ObjCrystBondLengthRestraint object for use with the ‘unrestrain’ method.

Return type:

ObjCrystBondLengthRestraint object

restrainDihedralAngle(atom1, atom2, atom3, atom4, angle, sigma, delta, scaled=False)[source]

Add a dihedral angle restraint.

This creates an instance of ObjCrystDihedralAngleRestraint and adds it to the ObjCrystMoleculeParSet.

Parameters:
  • atom1 – First atom (ObjCrystMolAtomParSet) in the angle

  • atom2 – Second (central) atom (ObjCrystMolAtomParSet) in the angle

  • atom3 – Third (central) atom (ObjCrystMolAtomParSet) in the angle

  • atom4 – Fourth atom in the angle (ObjCrystMolAtomParSet)

  • angle – The dihedral angle (radians)

  • sigma – The uncertainty of the dihedral angle (radians)

  • delta – The width of the dihedral angle (radians)

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

Returns:

Returns the ObjCrystDihedralAngleRestraint object for use with the ‘unrestrain’ method.

Return type:

ObjCrystDihedralAngleRestraint object

restrainDihedralAngleParameter(par, angle, sigma, delta, scaled=False)[source]

Add a dihedral angle restraint.

This creates an instance of ObjCrystDihedralAngleRestraint and adds it to the ObjCrystMoleculeParSet.

Parameters:
  • par – A ObjCrystDihedralAngleParameter (see addDihedralAngleParameter)

  • angle – The dihedral angle (radians)

  • sigma – The uncertainty of the dihedral angle (radians)

  • delta – The width of the dihedral angle (radians)

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

Returns:

Returns the ObjCrystDihedralAngleRestraint object for use with the ‘unrestrain’ method.

Return type:

ObjCrystDihedralAngleRestraint object

useSymmetry(use=True)[source]

Set this structure to use symmetry.

This structure object does not support symmetry.

usingSymmetry()[source]

Check if symmetry is being used.

This structure object does not support symmetry.

wrapRestraints()[source]

Wrap the restraints implicit to the molecule.

This will wrap MolBonds, MolBondAngles and MolDihedralAngles of the Molecule as ObjCrystMoleculeRestraint objects.

wrapStretchModeParameters()[source]

Wrap the stretch modes implicit to the Molecule as Parameters.

This will wrap StretchModeBondLengths and StretchModeBondAngles of the Molecule as Parameters. Note that this requires that the MolBondAtoms in the Molecule came in with unique names. Torsion angles are not wrapped, as there is not enough information to determine each MolAtom in the angle.

The Parameters will be given the concatenated name of its constituents. bond lengths: “bl_aname1_aname2” bond angles: “ba_aname1_aname2_aname3”

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

Parameters:
  • 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).

  • method. (Returns the BVSRestraint object for use with the 'unrestrain')

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.

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.

The following classes are adapted:

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

The following classes are adapted:

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

Parameters:

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

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]

This function is deprecated and will be removed in version 4.0.0.

Please use diffpy.srfit.structure.sgconstraints.constrain_as_space_group instead.

diffpy.srfit.structure.sgconstraints.constrain_as_space_group(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.