Skip to content
9 changes: 6 additions & 3 deletions docs/examples/coreshellnp.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,13 @@ def makeRecipe(stru1, stru2, datname):
# and a spherical shell CF for the shell. Since this is set up as two
# phases, we implicitly assume that the core-shell correlations contribute
# very little to the PDF.
from diffpy.srfit.pdf.characteristicfunctions import shellCF, sphericalCF
from diffpy.srfit.pdf.characteristicfunctions import (
shell_particle,
spherical_particle,
)

contribution.register_function(sphericalCF, name="f_CdS")
contribution.register_function(shellCF, name="f_ZnS")
contribution.register_function(spherical_particle, name="f_CdS")
contribution.register_function(shell_particle, name="f_ZnS")

# Write the fitting equation. We want to sum the PDFs from each phase and
# multiply it by a scaling factor.
Expand Down
17 changes: 9 additions & 8 deletions docs/examples/crystalpdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,16 +93,17 @@ def makeRecipe(ciffile, datname):

# We start by constraining the phase to the known space group. We could do
# this by hand, but there is a method in diffpy.srfit.structure named
# 'constrainAsSpaceGroup' for this purpose. The constraints will by default
# be applied to the sites, the lattice and to the ADPs. See the method
# documentation for more details. The 'constrainAsSpaceGroup' method may
# create new Parameters, which it returns in a SpaceGroupParameters object.
from diffpy.srfit.structure import constrainAsSpaceGroup
# 'constrain_as_space_group' for this purpose. The constraints will by
# default be applied to the sites, the lattice and to the ADPs. See the
# method documentation for more details. The 'constrain_as_space_group'
# method may create new Parameters, which it returns in a
# SpaceGroupParameters object.
from diffpy.srfit.structure import constrain_as_space_group

sgpars = constrainAsSpaceGroup(phase, "Fm-3m")
sgpars = constrain_as_space_group(phase, "Fm-3m")

# The SpaceGroupParameters object returned by 'constrainAsSpaceGroup' holds
# the free Parameters allowed by the space group constraints. Once a
# The SpaceGroupParameters object returned by 'constrain_as_space_group'
# holds the free Parameters allowed by the space group constraints. Once a
# structure is constrained, we need (should) only use the Parameters
# provided in the SpaceGroupParameters, as the relevant structure
# Parameters are constrained to these.
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/crystalpdfobjcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def makeRecipe(ciffile, datname):
# constraints get enforced within the ObjCrystCrystalParSet. Free
# Parameters are stored within the 'sgpars' member of the
# ObjCrystCrystalParSet, which is the same as the object returned from
# 'constrainAsSpaceGroup'.
# 'constrain_as_space_group'.
#
# As before, we have one free lattice parameter ('a'). We can simplify
# things by iterating through all the sgpars.
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/nppdfcrystal.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ def makeRecipe(ciffile, grdata):
pdfcontribution.add_profile_generator(pdfgenerator)

# Register the nanoparticle shape factor.
from diffpy.srfit.pdf.characteristicfunctions import sphericalCF
from diffpy.srfit.pdf.characteristicfunctions import spherical_particle

pdfcontribution.register_function(sphericalCF, name="f")
pdfcontribution.register_function(spherical_particle, name="f")

# Now we set up the fitting equation.
pdfcontribution.set_equation("f * G")
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/simplepdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ def makeRecipe(ciffile, datname):
# Configure the fit variables
phase = contribution.nickel.phase

from diffpy.srfit.structure import constrainAsSpaceGroup
from diffpy.srfit.structure import constrain_as_space_group

sgpars = constrainAsSpaceGroup(phase, "Fm-3m")
sgpars = constrain_as_space_group(phase, "Fm-3m")

for par in sgpars.latpars:
recipe.add_variable(par)
Expand Down
27 changes: 27 additions & 0 deletions news/cf-non-physical-input.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
**Added:**

* <news item>

**Changed:**

* Change the characteristic functions in ``diffpy.srfit.pdf.characteristicfunctions`` to emit a ``RuntimeWarning`` when a non-physical shape parameter makes them return zero, since a zero return flattens the fit residual and stalls a refinement without any other sign to the user. The warning is issued once per process for each distinct problem so a refinement loop does not repeat it.
* Change ``lognormal_spherical_particle`` in ``diffpy.srfit.pdf.characteristicfunctions`` to return zero for a negative ``particle_diameter_sigma`` instead of silently returning ``spherical_particle``. A ``particle_diameter_sigma`` of zero is still the sphere limit.
* Change ``sheet_particle`` in ``diffpy.srfit.pdf.characteristicfunctions`` to return an array of zeros for a non-positive ``sheet_thickness`` when ``r`` is an array, instead of a scalar zero.

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* Fix ``shell_particle`` in ``diffpy.srfit.pdf.characteristicfunctions`` returning a smoothly varying branch of unphysical values, some below negative one, for a negative ``thickness`` or ``radius``, which a refinement could mistake for a real solution. It now returns zero.
* Fix ``shell_particle`` in ``diffpy.srfit.pdf.characteristicfunctions`` returning one at every ``r`` for a zero ``thickness``, where the normalizing denominator vanishes. It now returns zero.
* Fix ``spheroidal_particle`` in ``diffpy.srfit.pdf.characteristicfunctions`` raising ``ZeroDivisionError`` for a zero ``equatorial_radius``. It now returns zero.

**Security:**

* <news item>
25 changes: 25 additions & 0 deletions news/characteristicfunctions-dep.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**Added:**

* Add ``spherical_particle``, ``spheroidal_particle``, ``lognormal_spherical_particle``, ``sheet_particle``, and ``shell_particle`` to ``diffpy.srfit.pdf.characteristicfunctions``, replacing ``sphericalCF``, ``spheroidalCF``, ``lognormalSphericalCF``, ``sheetCF``, and ``shellCF``.
* Add ``constrain_as_space_group`` to ``diffpy.srfit.structure.sgconstraints``, replacing ``constrainAsSpaceGroup``.

**Changed:**

* Change ``spheroidalCF2`` and ``shellCF2`` in ``diffpy.srfit.pdf.characteristicfunctions`` to be deprecated aliases that convert their arguments and call ``spheroidal_particle`` and ``shell_particle``, instead of separate implementations.

**Deprecated:**

* Deprecate ``sphericalCF``, ``spheroidalCF``, ``spheroidalCF2``, ``lognormalSphericalCF``, ``sheetCF``, ``shellCF``, and ``shellCF2`` in ``diffpy.srfit.pdf.characteristicfunctions``.
* Deprecate ``constrainAsSpaceGroup`` in ``diffpy.srfit.structure.sgconstraints``.

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
3 changes: 3 additions & 0 deletions src/diffpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@
# See LICENSE.rst for license information.
#
##############################################################################
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)
Loading
Loading