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)

Bases: diffpy.srfit.fitbase.parameterset.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.

Attributes: stru – The adapted object

classmethod canAdapt(stru)

Return whether the structure can be adapted by this class.

getLattice()

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()

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)

Bases: diffpy.srfit.fitbase.restraint.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.

Attributes: _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)

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.CCTBXScattererParSet(name, strups, idx)

Bases: diffpy.srfit.fitbase.parameterset.ParameterSet

A wrapper for cctbx.xray.scatterer

This class derives from ParameterSet.

Attributes: 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).

element
class diffpy.srfit.structure.cctbxparset.CCTBXUnitCellParSet(strups)

Bases: diffpy.srfit.fitbase.parameterset.ParameterSet

A wrapper for cctbx unit_cell object.

Attributes: name – Always “unitcell”. a, b, c, alpha, beta, gamma – Unit cell parameters (ParameterAdapter).

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

Bases: diffpy.srfit.structure.basestructureparset.BaseStructureParSet

A wrapper for CCTBX structure.

Attributes: stru – The adapted cctbx structure object. scatterers – The list of ScattererParSets. unitcell – The CCTBXUnitCellParSet for the structure.

classmethod canAdapt(stru)

Return whether the structure can be adapted by this class.

getLattice()

Get the ParameterSet containing the lattice Parameters.

getScatterers()

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()

Get the HM space group symbol for the structure.

update()

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.

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)

Bases: diffpy.srfit.structure.srrealparset.SrRealParSet

A wrapper for diffpy.structure.Structure.

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

Attributes: atoms – The list of DiffpyAtomParSets, provided for convenience. stru – The diffpy.structure.Structure this is adapting

Managed ParameterSets: 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)

Return whether the structure can be adapted by this class.

getLattice()

Get the ParameterSet containing the lattice Parameters.

getScatterers()

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

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.ObjCrystMoleculeParSet(name, molecule, parent=None)

Bases: diffpy.srfit.structure.objcrystparset.ObjCrystScattererParSet

A adaptor for a pyobjcryst.Molecule.

This class derives from ObjCrystScattererParSet.

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

Managed Parameters: x, y, z – Molecule position in crystal coordinates (ParameterAdapter) 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)

Add a bond angle to the Molecule.

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

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 the new ObjCrystBondAngleParameter.

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

Add a bond length to the Molecule.

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

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 the new ObjCrystBondLengthParameter.

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

Add a dihedral angle to the Molecule.

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

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 the new ObjCrystDihedralAngleParameter.

classmethod canAdapt(stru)

Return whether the structure can be adapted by this class.

getLattice()

Get the ParameterSet containing the lattice Parameters.

getScatterers()

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)

Add a bond angle restraint.

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

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 the ObjCrystBondAngleRestraint object for use with the ‘unrestrain’ method.

restrainBondAngleParameter(par, angle, sigma, delta, scaled=False)

Add a bond angle restraint.

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

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 the ObjCrystBondAngleRestraint object for use with the ‘unrestrain’ method.

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

Add a bond length restraint.

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

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.

restrainBondLengthParameter(par, length, sigma, delta, scaled=False)

Add a bond length restraint.

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

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 the ObjCrystBondLengthRestraint object for use with the ‘unrestrain’ method.

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

Add a dihedral angle restraint.

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

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 the ObjCrystDihedralAngleRestraint object for use with the ‘unrestrain’ method.

restrainDihedralAngleParameter(par, angle, sigma, delta, scaled=False)

Add a dihedral angle restraint.

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

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 the ObjCrystDihedralAngleRestraint object for use with the ‘unrestrain’ method.

useSymmetry(use=True)

Set this structure to use symmetry.

This structure object does not support symmetry.

usingSymmetry()

Check if symmetry is being used.

This structure object does not support symmetry.

wrapRestraints()

Wrap the restraints implicit to the molecule.

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

wrapStretchModeParameters()

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”

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

Bases: diffpy.srfit.structure.srrealparset.SrRealParSet

A adaptor for pyobjcryst.crystal.Crystal instance.

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

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

Managed Parameters: a, b, c, alpha, beta, gamma – Lattice parameters (ParameterAdapter)

Managed ParameterSets: <sname> – A ObjCrystScattererParSet (either ObjCrystAtomParSet or

ObjCrystMoleculeParSet), where <sname> is the name of the adapted pyobjcryst.atom.Atom or pyobjcryst.molecule.Molecule.
classmethod canAdapt(stru)

Return whether the structure can be adapted by this class.

getLattice()

Get the ParameterSet containing the lattice Parameters.

getScatterers()

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.

sgpars

Constrain the space group.

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')

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.

Arguments: 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 constrainted 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)

Bases: diffpy.srfit.structure.basestructureparset.BaseStructureParSet

Base class for SrReal-compatible structure adapters.

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

Attributes: 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)

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)

Set this structure to use symmetry.

This determines how the structure is treated by SrReal calculators.

usingSymmetry()

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)

Creates a ParameterSet from an structure.

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

stru – a structure object known by this module name – A name to give the structure.

Raises TypeError if stru cannot be adapted