Skip to content

Commit e76258d

Browse files
authored
Merge pull request #2 from cadenmyers13/migrate-changes
deprecated: Migrate changes made from srfit deprecation and change function names in `pdf` module
2 parents 227db6c + 688a5fa commit e76258d

16 files changed

Lines changed: 677 additions & 1040 deletions

.pre-commit-config.yaml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ci:
1111
submodules: false
1212
repos:
1313
- repo: https://github.com/pre-commit/pre-commit-hooks
14-
rev: v4.6.0
14+
rev: v6.0.0
1515
hooks:
1616
- id: check-yaml
1717
- id: end-of-file-fixer
@@ -21,45 +21,45 @@ repos:
2121
- id: check-toml
2222
- id: check-added-large-files
2323
- repo: https://github.com/psf/black
24-
rev: 24.4.2
24+
rev: 26.3.1
2525
hooks:
2626
- id: black
2727
- repo: https://github.com/pycqa/flake8
28-
rev: 7.0.0
28+
rev: 7.3.0
2929
hooks:
3030
- id: flake8
3131
- repo: https://github.com/pycqa/isort
32-
rev: 5.13.2
32+
rev: 8.0.1
3333
hooks:
3434
- id: isort
3535
args: ["--profile", "black"]
3636
- repo: https://github.com/kynan/nbstripout
37-
rev: 0.7.1
37+
rev: 0.9.1
3838
hooks:
3939
- id: nbstripout
4040
- repo: https://github.com/pre-commit/pre-commit-hooks
41-
rev: v4.4.0
41+
rev: v6.0.0
4242
hooks:
4343
- id: no-commit-to-branch
4444
name: Prevent Commit to Main Branch
4545
args: ["--branch", "main"]
4646
stages: [pre-commit]
4747
- repo: https://github.com/codespell-project/codespell
48-
rev: v2.3.0
48+
rev: v2.4.2
4949
hooks:
5050
- id: codespell
5151
additional_dependencies:
5252
- tomli
5353
# prettier - multi formatter for .json, .yml, and .md files
5454
- repo: https://github.com/pre-commit/mirrors-prettier
55-
rev: f12edd9c7be1c20cfa42420fd0e6df71e42b51ea # frozen: v4.0.0-alpha.8
55+
rev: v4.0.0-alpha.8
5656
hooks:
5757
- id: prettier
5858
additional_dependencies:
5959
- "prettier@^3.2.4"
6060
# docformatter - PEP 257 compliant docstring formatter
61-
- repo: https://github.com/s-weigand/docformatter
62-
rev: 5757c5190d95e5449f102ace83df92e7d3b06c6c
61+
- repo: https://github.com/PyCQA/docformatter
62+
rev: v1.7.7
6363
hooks:
6464
- id: docformatter
6565
additional_dependencies: [tomli]

news/migrate-changes.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
**Added:**
2+
3+
* No news added: updated all functions to be snake_case.
4+
5+
**Changed:**
6+
7+
* <news item>
8+
9+
**Deprecated:**
10+
11+
* <news item>
12+
13+
**Removed:**
14+
15+
* <news item>
16+
17+
**Fixed:**
18+
19+
* <news item>
20+
21+
**Security:**
22+
23+
* <news item>

requirements/conda.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
numpy
2+
diffpy.srreal
23
diffpy.srfit
34
diffpy.structure

requirements/pip.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
numpy
2+
diffpy.srreal
3+
diffpy.srfit
4+
diffpy.structure

src/diffpy/cmipdf/basepdfgenerator.py

Lines changed: 81 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class BasePDFGenerator(ProfileGenerator):
4646
the PDF.
4747
_phase
4848
The structure ParameterSet used to calculate the profile.
49-
stru
49+
structure
5050
The structure objected adapted by _phase.
5151
_lastr
5252
The last value of r over which the PDF was calculated. This is
@@ -72,15 +72,15 @@ class BasePDFGenerator(ProfileGenerator):
7272
7373
Usable Metadata
7474
---------------
75-
stype
75+
stype : str
7676
The scattering type "X" for x-ray, "N" for neutron (see
77-
'setScatteringType').
77+
'set_scattering_type').
7878
qmax
7979
The maximum scattering vector used to generate the PDF (see
80-
setQmax).
80+
set_qmax).
8181
qmin
8282
The minimum scattering vector used to generate the PDF (see
83-
setQmin).
83+
set_qmin).
8484
scale
8585
See Managed Parameters.
8686
delta1
@@ -98,7 +98,7 @@ def __init__(self, name="pdf"):
9898
ProfileGenerator.__init__(self, name)
9999

100100
self._phase = None
101-
self.stru = None
101+
self.structure = None
102102
self.meta = {}
103103
self._lastr = numpy.empty(0)
104104
self._calc = None
@@ -109,7 +109,7 @@ def __init__(self, name="pdf"):
109109

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

112-
def _setCalculator(self, calc):
112+
def _set_calculator(self, calc):
113113
"""Set the SrReal calculator instance.
114114
115115
Setting the calculator creates Parameters from the variable
@@ -118,13 +118,13 @@ def _setCalculator(self, calc):
118118
self._calc = calc
119119
for pname in self.__class__._parnames:
120120
self.addParameter(ParameterAdapter(pname, self._calc, attr=pname))
121-
self.processMetaData()
121+
self._process_metadata()
122122
return
123123

124124
def parallel(self, ncpu, mapfunc=None):
125125
"""Run calculation in parallel.
126126
127-
Attributes
127+
Parameters
128128
----------
129129
ncpu
130130
Number of parallel processes. Revert to serial mode when 1.
@@ -155,130 +155,159 @@ def parallel(self, ncpu, mapfunc=None):
155155
self._calc = createParallelCalculator(calc_serial, ncpu, mapfunc)
156156
return
157157

158-
def processMetaData(self):
158+
def _process_metadata(self):
159159
"""Process the metadata once it gets set."""
160-
ProfileGenerator.processMetaData(self)
160+
ProfileGenerator._process_metadata(self)
161161

162162
stype = self.meta.get("stype")
163163
if stype is not None:
164-
self.setScatteringType(stype)
164+
self.set_scattering_type(stype)
165165

166166
qmax = self.meta.get("qmax")
167167
if qmax is not None:
168-
self.setQmax(qmax)
168+
self.set_qmax(qmax)
169169

170170
qmin = self.meta.get("qmin")
171171
if qmin is not None:
172-
self.setQmin(qmin)
172+
self.set_qmin(qmin)
173173

174174
for name in self.__class__._parnames:
175175
val = self.meta.get(name)
176176
if val is not None:
177177
par = self.get(name)
178-
par.setValue(val)
178+
par.set_value(val)
179179

180180
return
181181

182-
def setScatteringType(self, stype="X"):
182+
def set_scattering_type(self, stype="X"):
183183
"""Set the scattering type.
184184
185-
Attributes
185+
Parameters
186186
----------
187-
stype
188-
"X" for x-ray, "N" for neutron, "E" for electrons,
187+
stype : str, optional
188+
The scattering type. Default is `"X"`.
189+
`"X"` for x-ray, `"N"` for neutron, `"E"` for electrons,
189190
or any registered type from diffpy.srreal from
190191
ScatteringFactorTable.getRegisteredTypes().
191192
192-
Raises ValueError for unknown scattering type.
193+
Raises
194+
------
195+
ValueError
196+
If the scattering type is unknown.
193197
"""
194198
self._calc.setScatteringFactorTableByType(stype)
195199
# update the meta dictionary only if there was no exception
196-
self.meta["stype"] = self.getScatteringType()
200+
self.meta["stype"] = self.get_scattering_type()
197201
return
198202

199-
def getScatteringType(self):
203+
def get_scattering_type(self):
200204
"""Get the scattering type.
201205
202-
See 'setScatteringType'.
206+
See 'set_scattering_type'.
203207
"""
204208
return self._calc.getRadiationType()
205209

206-
def setQmax(self, qmax):
207-
"""Set the qmax value."""
210+
def set_qmax(self, qmax):
211+
"""Set the qmax value.
212+
213+
Parameters
214+
----------
215+
qmax : float
216+
The maximum scattering vector used to generate the PDF.
217+
"""
208218
self._calc.qmax = qmax
209-
self.meta["qmax"] = self.getQmax()
219+
self.meta["qmax"] = self.get_qmax()
210220
return
211221

212-
def getQmax(self):
213-
"""Get the qmax value."""
222+
def get_qmax(self):
223+
"""Get the qmax value.
224+
225+
Returns
226+
-------
227+
float
228+
The maximum scattering vector used to generate the PDF.
229+
"""
214230
return self._calc.qmax
215231

216-
def setQmin(self, qmin):
217-
"""Set the qmin value."""
232+
def set_qmin(self, qmin):
233+
"""Set the qmin value.
234+
235+
Parameters
236+
----------
237+
qmin : float
238+
The minimum scattering vector used to generate the PDF.
239+
"""
218240
self._calc.qmin = qmin
219-
self.meta["qmin"] = self.getQmin()
241+
self.meta["qmin"] = self.get_qmin()
220242
return
221243

222-
def getQmin(self):
223-
"""Get the qmin value."""
244+
def get_qmin(self):
245+
"""Get the qmin value.
246+
247+
Returns
248+
-------
249+
float
250+
The minimum scattering vector used to generate the PDF.
251+
"""
224252
return self._calc.qmin
225253

226-
def setStructure(self, stru, name="phase", periodic=True):
254+
def set_structure(self, structure, name="phase", periodic=True):
227255
"""Set the structure that will be used to calculate the PDF.
228256
229257
This creates a DiffpyStructureParSet, ObjCrystCrystalParSet or
230-
ObjCrystMoleculeParSet that adapts stru to a ParameterSet interface.
258+
ObjCrystMoleculeParSet that adapts structure to a ParameterSet
259+
interface.
231260
See those classes (located in diffpy.srfit.structure) for how they are
232261
used. The resulting ParameterSet will be managed by this generator.
233262
234-
Attributes
263+
Parameters
235264
----------
236-
stru
237-
diffpy.structure.Structure, pyobjcryst.crystal.Crystal or
238-
pyobjcryst.molecule.Molecule instance. Default None.
239-
name
240-
A name to give to the managed ParameterSet that adapts stru
265+
structure : Structure or Crystal or Molecule
266+
The diffpy.structure.Structure, pyobjcryst.crystal.Crystal or
267+
pyobjcryst.molecule.Molecule instance.
268+
name : str, optional
269+
The name to give to the managed ParameterSet that adapts structure
241270
(default "phase").
242-
periodic
271+
periodic : bool, optional
243272
The structure should be treated as periodic (default
244273
True). Note that some structures do not support
245274
periodicity, in which case this will have no effect on the
246275
PDF calculation.
247276
"""
248277

249278
# Create the ParameterSet
250-
parset = struToParameterSet(name, stru)
279+
parset = struToParameterSet(name, structure)
251280

252281
# Set the phase
253-
self.setPhase(parset, periodic)
282+
self.set_structure_from_parset(parset, periodic)
254283
return
255284

256-
def setPhase(self, parset, periodic=True):
285+
def set_structure_from_parset(self, parset, periodic=True):
257286
"""Set the phase that will be used to calculate the PDF.
258287
259288
Set the phase directly with a DiffpyStructureParSet,
260289
ObjCrystCrystalParSet or ObjCrystMoleculeParSet that adapts a structure
261290
object (from diffpy or pyobjcryst). The passed ParameterSet will be
262291
managed by this generator.
263292
264-
Attributes
293+
Parameters
265294
----------
266-
parset
267-
A SrRealParSet that holds the structural information.
295+
parset : SrRealParSet
296+
The SrRealParSet that holds the structural information.
268297
This can be used to share the phase between multiple
269298
BasePDFGenerators, and have the changes in one reflect in
270299
another.
271-
periodic
300+
periodic : bool, optional
272301
The structure should be treated as periodic (default True).
273302
Note that some structures do not support periodicity, in
274303
which case this will be ignored.
275304
"""
276305
# Store the ParameterSet for easy access
277306
self._phase = parset
278-
self.stru = self._phase.stru
307+
self.structure = self._phase.stru
279308

280309
# Put this ParameterSet in the ProfileGenerator.
281-
self.addParameterSet(parset)
310+
self.add_parameter_set(parset)
282311

283312
# Set periodicity
284313
self._phase.useSymmetry(periodic)
@@ -321,7 +350,7 @@ def __call__(self, r):
321350
if not numpy.array_equal(r, self._lastr):
322351
self._prepare(r)
323352

324-
rcalc, y = self._calc(self._phase._getSrRealStructure())
353+
rcalc, y = self._calc(self._phase._get_srreal_structure())
325354

326355
if numpy.isnan(y).any():
327356
y = numpy.zeros_like(r)

0 commit comments

Comments
 (0)