|
23 | 23 |
|
24 | 24 | __all__ = ["DebyePDFGenerator"] |
25 | 25 |
|
| 26 | +from pathlib import Path |
| 27 | + |
26 | 28 | from diffpy.cmipdf.basepdfgenerator import BasePDFGenerator |
| 29 | +from diffpy.srreal.pdfcalculator import DebyePDFCalculator |
| 30 | +from diffpy.structure import loadStructure |
27 | 31 |
|
28 | 32 |
|
29 | 33 | class DebyePDFGenerator(BasePDFGenerator): |
@@ -136,12 +140,102 @@ def set_structure_from_parset(self, parset, periodic=False): |
136 | 140 |
|
137 | 141 | def __init__(self, name="pdf"): |
138 | 142 | """Initialize the generator.""" |
139 | | - from diffpy.srreal.pdfcalculator import DebyePDFCalculator |
140 | | - |
141 | 143 | BasePDFGenerator.__init__(self, name) |
142 | 144 | self._set_calculator(DebyePDFCalculator()) |
143 | 145 | return |
144 | 146 |
|
| 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 | + |
145 | 239 |
|
146 | 240 | # End class DebyePDFGenerator |
147 | 241 |
|
|
0 commit comments