Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
6da5a92
basepdfgenerator.py
cadenmyers13 Mar 18, 2026
090409e
characteristicfunctions.py
cadenmyers13 Mar 18, 2026
4118a1c
copy rest of modified srfit files here
cadenmyers13 Mar 18, 2026
67d8e7a
remove pdfparser in favor of ProfileParser
cadenmyers13 Mar 18, 2026
a0f55cd
setScatteringType --> set_scattering_type
cadenmyers13 Mar 18, 2026
f052128
getScatteringType --> get_scattering_type
cadenmyers13 Mar 18, 2026
7fe7f08
setQmax --> set_qmax
cadenmyers13 Mar 18, 2026
efae5b2
copy over test_pdf.py
cadenmyers13 Mar 18, 2026
f45e5cf
docstring improvement
cadenmyers13 Mar 18, 2026
dba8852
getQmax --> get_qmax
cadenmyers13 Mar 18, 2026
e27133a
setQmin --> set_qmin
cadenmyers13 Mar 18, 2026
4b41c42
getQmin --> get_qmin
cadenmyers13 Mar 18, 2026
fc56895
change stru to structure everywhere
cadenmyers13 Mar 18, 2026
d2dd56b
setPhase --> set_structure_from_parset
cadenmyers13 Mar 18, 2026
13abb50
spheroidalCF --> spheroidal_particle
cadenmyers13 Mar 19, 2026
f0851c3
lognormalSphericalCF --> lognormal_spherical_distribution
cadenmyers13 Mar 19, 2026
971fd7e
sheetCF --> sheet_particle
cadenmyers13 Mar 19, 2026
4c52841
shellCF --> spherical_shell
cadenmyers13 Mar 19, 2026
b742d4d
shellCF2 --> _calculate_shell_cf
cadenmyers13 Mar 19, 2026
70e8403
update parser testing
cadenmyers13 Mar 19, 2026
3c2073a
tests passing checkpoint 2
cadenmyers13 Mar 19, 2026
0f2ed66
all tests passing
cadenmyers13 Mar 19, 2026
f102f1b
rm unittest import
cadenmyers13 Mar 19, 2026
da8c24e
debyepdfpgenerator.py
cadenmyers13 Mar 19, 2026
768580b
pdfcontribution.py
cadenmyers13 Mar 19, 2026
10262a7
add method to generate a PDF from a structure
cadenmyers13 Mar 19, 2026
852ae74
break out tests into separate files
cadenmyers13 Mar 19, 2026
ed5b173
rm PDF generator functions, will put on another PR
cadenmyers13 Mar 19, 2026
3012727
news
cadenmyers13 Mar 19, 2026
688a5fa
add srreal srfit and structure to this conda.txt and pip.txt
cadenmyers13 Mar 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ci:
submodules: false
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v6.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
Expand All @@ -21,45 +21,45 @@ repos:
- id: check-toml
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 24.4.2
rev: 26.3.1
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
rev: 7.3.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
rev: 5.13.2
rev: 8.0.1
hooks:
- id: isort
args: ["--profile", "black"]
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
rev: 0.9.1
hooks:
- id: nbstripout
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v6.0.0
hooks:
- id: no-commit-to-branch
name: Prevent Commit to Main Branch
args: ["--branch", "main"]
stages: [pre-commit]
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.2
hooks:
- id: codespell
additional_dependencies:
- tomli
# prettier - multi formatter for .json, .yml, and .md files
- repo: https://github.com/pre-commit/mirrors-prettier
rev: f12edd9c7be1c20cfa42420fd0e6df71e42b51ea # frozen: v4.0.0-alpha.8
rev: v4.0.0-alpha.8
hooks:
- id: prettier
additional_dependencies:
- "prettier@^3.2.4"
# docformatter - PEP 257 compliant docstring formatter
- repo: https://github.com/s-weigand/docformatter
rev: 5757c5190d95e5449f102ace83df92e7d3b06c6c
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.7
hooks:
- id: docformatter
additional_dependencies: [tomli]
Expand Down
23 changes: 23 additions & 0 deletions news/migrate-changes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* No news added: updated all functions to be snake_case.

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
1 change: 1 addition & 0 deletions requirements/conda.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
numpy
diffpy.srreal
diffpy.srfit
diffpy.structure
3 changes: 3 additions & 0 deletions requirements/pip.txt
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
numpy
diffpy.srreal
diffpy.srfit
diffpy.structure
133 changes: 81 additions & 52 deletions src/diffpy/cmipdf/basepdfgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class BasePDFGenerator(ProfileGenerator):
the PDF.
_phase
The structure ParameterSet used to calculate the profile.
stru
structure
The structure objected adapted by _phase.
_lastr
The last value of r over which the PDF was calculated. This is
Expand All @@ -72,15 +72,15 @@ class BasePDFGenerator(ProfileGenerator):

Usable Metadata
---------------
stype
stype : str
The scattering type "X" for x-ray, "N" for neutron (see
'setScatteringType').
'set_scattering_type').
qmax
The maximum scattering vector used to generate the PDF (see
setQmax).
set_qmax).
qmin
The minimum scattering vector used to generate the PDF (see
setQmin).
set_qmin).
scale
See Managed Parameters.
delta1
Expand All @@ -98,7 +98,7 @@ def __init__(self, name="pdf"):
ProfileGenerator.__init__(self, name)

self._phase = None
self.stru = None
self.structure = None
self.meta = {}
self._lastr = numpy.empty(0)
self._calc = None
Expand All @@ -109,7 +109,7 @@ def __init__(self, name="pdf"):

_parnames = ["delta1", "delta2", "qbroad", "scale", "qdamp"]

def _setCalculator(self, calc):
def _set_calculator(self, calc):
"""Set the SrReal calculator instance.

Setting the calculator creates Parameters from the variable
Expand All @@ -118,13 +118,13 @@ def _setCalculator(self, calc):
self._calc = calc
for pname in self.__class__._parnames:
self.addParameter(ParameterAdapter(pname, self._calc, attr=pname))
self.processMetaData()
self._process_metadata()
return

def parallel(self, ncpu, mapfunc=None):
"""Run calculation in parallel.

Attributes
Parameters
----------
ncpu
Number of parallel processes. Revert to serial mode when 1.
Expand Down Expand Up @@ -155,130 +155,159 @@ def parallel(self, ncpu, mapfunc=None):
self._calc = createParallelCalculator(calc_serial, ncpu, mapfunc)
return

def processMetaData(self):
def _process_metadata(self):
"""Process the metadata once it gets set."""
ProfileGenerator.processMetaData(self)
ProfileGenerator._process_metadata(self)

stype = self.meta.get("stype")
if stype is not None:
self.setScatteringType(stype)
self.set_scattering_type(stype)

qmax = self.meta.get("qmax")
if qmax is not None:
self.setQmax(qmax)
self.set_qmax(qmax)

qmin = self.meta.get("qmin")
if qmin is not None:
self.setQmin(qmin)
self.set_qmin(qmin)

for name in self.__class__._parnames:
val = self.meta.get(name)
if val is not None:
par = self.get(name)
par.setValue(val)
par.set_value(val)

return

def setScatteringType(self, stype="X"):
def set_scattering_type(self, stype="X"):
"""Set the scattering type.

Attributes
Parameters
----------
stype
"X" for x-ray, "N" for neutron, "E" for electrons,
stype : str, optional
The scattering type. Default is `"X"`.
`"X"` for x-ray, `"N"` for neutron, `"E"` for electrons,
or any registered type from diffpy.srreal from
ScatteringFactorTable.getRegisteredTypes().

Raises ValueError for unknown scattering type.
Raises
------
ValueError
If the scattering type is unknown.
"""
self._calc.setScatteringFactorTableByType(stype)
# update the meta dictionary only if there was no exception
self.meta["stype"] = self.getScatteringType()
self.meta["stype"] = self.get_scattering_type()
return

def getScatteringType(self):
def get_scattering_type(self):
"""Get the scattering type.

See 'setScatteringType'.
See 'set_scattering_type'.
"""
return self._calc.getRadiationType()

def setQmax(self, qmax):
"""Set the qmax value."""
def set_qmax(self, qmax):
"""Set the qmax value.

Parameters
----------
qmax : float
The maximum scattering vector used to generate the PDF.
"""
self._calc.qmax = qmax
self.meta["qmax"] = self.getQmax()
self.meta["qmax"] = self.get_qmax()
return

def getQmax(self):
"""Get the qmax value."""
def get_qmax(self):
"""Get the qmax value.

Returns
-------
float
The maximum scattering vector used to generate the PDF.
"""
return self._calc.qmax

def setQmin(self, qmin):
"""Set the qmin value."""
def set_qmin(self, qmin):
"""Set the qmin value.

Parameters
----------
qmin : float
The minimum scattering vector used to generate the PDF.
"""
self._calc.qmin = qmin
self.meta["qmin"] = self.getQmin()
self.meta["qmin"] = self.get_qmin()
return

def getQmin(self):
"""Get the qmin value."""
def get_qmin(self):
"""Get the qmin value.

Returns
-------
float
The minimum scattering vector used to generate the PDF.
"""
return self._calc.qmin

def setStructure(self, stru, name="phase", periodic=True):
def set_structure(self, structure, name="phase", periodic=True):
"""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.
ObjCrystMoleculeParSet that adapts structure 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.

Attributes
Parameters
----------
stru
diffpy.structure.Structure, pyobjcryst.crystal.Crystal or
pyobjcryst.molecule.Molecule instance. Default None.
name
A name to give to the managed ParameterSet that adapts stru
structure : Structure or Crystal or Molecule
The diffpy.structure.Structure, pyobjcryst.crystal.Crystal or
pyobjcryst.molecule.Molecule instance.
name : str, optional
The name to give to the managed ParameterSet that adapts structure
(default "phase").
periodic
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.
"""

# Create the ParameterSet
parset = struToParameterSet(name, stru)
parset = struToParameterSet(name, structure)

# Set the phase
self.setPhase(parset, periodic)
self.set_structure_from_parset(parset, periodic)
return

def setPhase(self, parset, periodic=True):
def set_structure_from_parset(self, parset, periodic=True):
"""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.

Attributes
Parameters
----------
parset
A SrRealParSet that holds the structural information.
parset : SrRealParSet
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
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.
"""
# Store the ParameterSet for easy access
self._phase = parset
self.stru = self._phase.stru
self.structure = self._phase.stru

# Put this ParameterSet in the ProfileGenerator.
self.addParameterSet(parset)
self.add_parameter_set(parset)

# Set periodicity
self._phase.useSymmetry(periodic)
Expand Down Expand Up @@ -321,7 +350,7 @@ def __call__(self, r):
if not numpy.array_equal(r, self._lastr):
self._prepare(r)

rcalc, y = self._calc(self._phase._getSrRealStructure())
rcalc, y = self._calc(self._phase._get_srreal_structure())

if numpy.isnan(y).any():
y = numpy.zeros_like(r)
Expand Down
Loading
Loading