Skip to content

Commit 10262a7

Browse files
committed
add method to generate a PDF from a structure
1 parent 768580b commit 10262a7

2 files changed

Lines changed: 189 additions & 4 deletions

File tree

src/diffpy/cmipdf/debyepdfgenerator.py

Lines changed: 96 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323

2424
__all__ = ["DebyePDFGenerator"]
2525

26+
from pathlib import Path
27+
2628
from diffpy.cmipdf.basepdfgenerator import BasePDFGenerator
29+
from diffpy.srreal.pdfcalculator import DebyePDFCalculator
30+
from diffpy.structure import loadStructure
2731

2832

2933
class DebyePDFGenerator(BasePDFGenerator):
@@ -136,12 +140,102 @@ def set_structure_from_parset(self, parset, periodic=False):
136140

137141
def __init__(self, name="pdf"):
138142
"""Initialize the generator."""
139-
from diffpy.srreal.pdfcalculator import DebyePDFCalculator
140-
141143
BasePDFGenerator.__init__(self, name)
142144
self._set_calculator(DebyePDFCalculator())
143145
return
144146

147+
def generate_pdf_from_structure(
148+
self,
149+
structure,
150+
rmin=0,
151+
rmax=30,
152+
qmin=0.1,
153+
qmax=25.0,
154+
qdamp=0.03,
155+
qbroad=0.0,
156+
delta1=0.0,
157+
delta2=0.0,
158+
uiso=0.007,
159+
):
160+
"""Calculate the PDF from a structure and return G vs. r.
161+
162+
This is a convenience method that allows the user to calculate
163+
the PDF from a
164+
structure without having to set up the calculator and
165+
structure ParameterSet
166+
manually. The structure can be passed as a path to a
167+
structure file or as a
168+
`diffpy.structure.Structure` object.
169+
170+
Parameters
171+
----------
172+
structure : Path, str, or diffpy.structure.Structure
173+
The structure to calculate the PDF from. Can be a path
174+
to a structure file or a diffpy.structure.Structure
175+
object.
176+
rmin : float, optional
177+
The minimum r value in Angstroms for the PDF (default 0).
178+
rmax : float, optional
179+
The maximum r value in Angstroms for the PDF (default 30).
180+
qmin : float, optional
181+
The minimum scattering vector used to generate the PDF
182+
(default 0.1).
183+
qmax : float, optional
184+
The maximum scattering vector used to generate the PDF
185+
(default 25.0).
186+
uiso : float, optional
187+
The isotropic atomic displacement parameter to use for all
188+
atoms in the structure (default 0.007).
189+
qdamp : float, optional
190+
The resolution dampening term to use in the PDF calculation
191+
(default 0.03).
192+
qbroad : float, optional
193+
The resolution broadening term to use in the PDF calculation
194+
(default 0.0).
195+
delta1 : float, optional
196+
The linear peak broadening term to use in the PDF calculation
197+
(default 0.0).
198+
delta2 : float, optional
199+
The quadratic peak broadening term to use in the PDF calculation
200+
(default 0.0).
201+
uiso : float, optional
202+
The isotropic atomic displacement parameter to use for all
203+
atoms in the structure (default 0.007).
204+
205+
Returns
206+
-------
207+
r : numpy.ndarray
208+
The r values for the PDF in units of Angstroms.
209+
G : numpy.ndarray
210+
The G values for the PDF in units of 1/Angstrom^2.
211+
212+
Example
213+
-------
214+
.. code-block:: python
215+
xyz_path = "path/to/nanoparticle.xyz"
216+
gen = PDFGenerator()
217+
r, g = gen.generate_pdf_from_structure(xyz_path)
218+
"""
219+
if isinstance(structure, Path):
220+
structure = loadStructure(str(structure))
221+
elif isinstance(structure, str):
222+
structure = loadStructure(structure)
223+
structure.Uisoequiv = uiso
224+
225+
calc = DebyePDFCalculator()
226+
calc.qmin = qmin
227+
calc.qmax = qmax
228+
calc.rstep = 0.01
229+
calc.rmin = rmin
230+
calc.rmax = rmax
231+
calc.qdamp = qdamp
232+
calc.qbroad = qbroad
233+
calc.delta1 = delta1
234+
calc.delta2 = delta2
235+
236+
r, g = calc(structure)
237+
return r, g
238+
145239

146240
# End class DebyePDFGenerator
147241

src/diffpy/cmipdf/pdfgenerator.py

Lines changed: 93 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@
2525

2626
__all__ = ["PDFGenerator"]
2727

28+
from pathlib import Path
29+
2830
from diffpy.cmipdf.basepdfgenerator import BasePDFGenerator
31+
from diffpy.srreal.pdfcalculator import PDFCalculator
32+
from diffpy.structure import loadStructure
2933

3034

3135
class PDFGenerator(BasePDFGenerator):
@@ -86,11 +90,98 @@ class PDFGenerator(BasePDFGenerator):
8690

8791
def __init__(self, name="pdf"):
8892
"""Initialize the generator."""
89-
from diffpy.srreal.pdfcalculator import PDFCalculator
90-
9193
BasePDFGenerator.__init__(self, name)
9294
self._set_calculator(PDFCalculator())
9395
return
9496

97+
def generate_pdf_from_structure(
98+
self,
99+
structure,
100+
rmin=0,
101+
rmax=30,
102+
qmin=0.1,
103+
qmax=25.0,
104+
qdamp=0.03,
105+
qbroad=0.0,
106+
delta1=0.0,
107+
delta2=0.0,
108+
uiso=0.007,
109+
):
110+
"""Calculate the PDF from a structure and return G vs. r.
111+
112+
This is a convenience method that allows the user to calculate
113+
the PDF from a
114+
structure without having to set up the calculator and
115+
structure ParameterSet
116+
manually. The structure can be passed as a path to a
117+
structure file or as a
118+
`diffpy.structure.Structure` object.
119+
120+
Parameters
121+
----------
122+
structure : Path, str, or diffpy.structure.Structure
123+
The structure to calculate the PDF from. Can be a path
124+
to a structure file or a diffpy.structure.Structure
125+
object.
126+
rmin : float, optional
127+
The minimum r value in Angstroms for the PDF (default 0).
128+
rmax : float, optional
129+
The maximum r value in Angstroms for the PDF (default 30).
130+
qmin : float, optional
131+
The minimum scattering vector used to generate the PDF
132+
(default 0.1).
133+
qmax : float, optional
134+
The maximum scattering vector used to generate the PDF
135+
(default 25.0).
136+
qdamp : float, optional
137+
The resolution dampening term to use in the PDF calculation
138+
(default 0.03).
139+
qbroad : float, optional
140+
The resolution broadening term to use in the PDF calculation
141+
(default 0.0).
142+
delta1 : float, optional
143+
The linear peak broadening term to use in the PDF calculation
144+
(default 0.0).
145+
delta2 : float, optional
146+
The quadratic peak broadening term to use in the PDF calculation
147+
(default 0.0).
148+
uiso : float, optional
149+
The isotropic atomic displacement parameter to use for all
150+
atoms in the structure (default 0.007).
151+
152+
Returns
153+
-------
154+
r : numpy.ndarray
155+
The r values for the PDF in units of Angstroms.
156+
G : numpy.ndarray
157+
The G values for the PDF in units of 1/Angstrom^2.
158+
159+
Example
160+
-------
161+
.. code-block:: python
162+
cif_path = "path/to/ni.cif"
163+
gen = PDFGenerator()
164+
r, g = gen.generate_pdf_from_structure(cifpath)
165+
"""
166+
if isinstance(structure, Path):
167+
structure = loadStructure(str(structure))
168+
elif isinstance(structure, str):
169+
structure = loadStructure(structure)
170+
structure.Uisoequiv = uiso
171+
172+
calc = PDFCalculator()
173+
calc.qmin = qmin
174+
calc.qmax = qmax
175+
calc.rstep = 0.01
176+
calc.rmin = rmin
177+
calc.rmax = rmax
178+
calc.qdamp = qdamp
179+
calc.qbroad = qbroad
180+
calc.delta1 = delta1
181+
calc.delta2 = delta2
182+
183+
r, g = calc(structure)
184+
return r, g
185+
95186

96187
# End class PDFGenerator

0 commit comments

Comments
 (0)