Skip to content

Commit 772a01e

Browse files
authored
Merge pull request #34 from 8bitsam/cookie-src
Cookiecutting - src directory
2 parents ccf5fb5 + af811e8 commit 772a01e

24 files changed

+8140
-0
lines changed

src/diffpy/__init__.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env python
2+
##############################################################################
3+
#
4+
# (c) 2024 The Trustees of Columbia University in the City of New York.
5+
# All rights reserved.
6+
#
7+
# File coded by: Billinge Group members and community contributors.
8+
#
9+
# See GitHub contributions for a more detailed list of contributors.
10+
# https://github.com/diffpy/diffpy.pdffit2/graphs/contributors
11+
#
12+
# See LICENSE.rst for license information.
13+
#
14+
##############################################################################
15+
16+
"""Blank namespace package for module diffpy."""
17+
18+
19+
from pkgutil import extend_path
20+
21+
__path__ = extend_path(__path__, __name__)
22+
23+
# End of file

src/diffpy/pdffit2/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env python
2+
##############################################################################
3+
#
4+
# (c) 2024 The Trustees of Columbia University in the City of New York.
5+
# All rights reserved.
6+
#
7+
# File coded by: Billinge Group members and community contributors.
8+
#
9+
# See GitHub contributions for a more detailed list of contributors.
10+
# https://github.com/diffpy/diffpy.pdffit2/graphs/contributors
11+
#
12+
# See LICENSE.rst for license information.
13+
#
14+
##############################################################################
15+
16+
"""PDFfit2 - real space structure refinement program."""
17+
18+
# package version
19+
from diffpy.pdffit2.version import __version__
20+
21+
# silence the pyflakes syntax checker
22+
assert __version__ or True
23+
24+
# End of file

src/diffpy/pdffit2/ipy_ext.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env python
2+
3+
"""This module defines functions within IPython session to simulate
4+
the old pdffit2 interactive session.
5+
6+
Usage: %load_ext diffpy.pdffit2.ipy_ext
7+
"""
8+
9+
10+
def load_ipython_extension(ipython):
11+
from diffpy.pdffit2 import PdfFit
12+
13+
pf = PdfFit()
14+
pdf = EasyPDFPlotting(pf)
15+
print(" Type help(pdffit) or help(topic) for information.\n")
16+
ns = dict(pdffit=PdfFit, pdf=pdf)
17+
pf._exportAll(ns)
18+
ipython.user_ns.update(ns)
19+
return
20+
21+
22+
class EasyPDFPlotting(object):
23+
"""Convenience functions for accessing and plotting PDFfit2 data."""
24+
25+
def __init__(self, pdffit_instance):
26+
self._pdffit = pdffit_instance
27+
return
28+
29+
@property
30+
def r(self):
31+
"R-grid for PDF simulation."
32+
return self._asarray(self._pdffit.getR(), dtype=float)
33+
34+
@property
35+
def Gobs(self):
36+
"Observed PDF data."
37+
return self._asarray(self._pdffit.getpdf_obs(), dtype=float)
38+
39+
@property
40+
def Gcalc(self):
41+
"Calculated PDF data."
42+
return self._asarray(self._pdffit.getpdf_fit())
43+
44+
@property
45+
def Gdiff(self):
46+
"Difference between the observed and simulated PDF."
47+
return self.Gobs - self.Gcalc
48+
49+
def showfit(self, offset=None):
50+
"""Plot observed and simulated PDFs and the difference curve.
51+
52+
offset -- offset for the difference curve.
53+
54+
No return value.
55+
"""
56+
from math import floor
57+
58+
from matplotlib.pyplot import gca
59+
60+
cr = self.r
61+
cGobs = self.Gobs
62+
cGcalc = self.Gcalc
63+
cGdiff = self.Gdiff
64+
if offset is None:
65+
offset = floor(min([min(cGobs), min(cGcalc)]) - max(cGdiff))
66+
ax = gca()
67+
ax.plot(cr, cGobs, "r.", cr, cGcalc, "b-", cr, cGdiff + offset, "g-")
68+
xl = ax.xaxis.get_label().get_text()
69+
yl = ax.yaxis.get_label().get_text()
70+
if xl == "":
71+
ax.set_xlabel("r (A)")
72+
if yl == "":
73+
ax.set_ylabel("G (A**-2)")
74+
return
75+
76+
def showRw(self):
77+
"Plot cumulative Rw."
78+
from matplotlib.pyplot import gca
79+
80+
cRw = self._asarray(self._pdffit.getcrw())
81+
ax = gca()
82+
ax.plot(self.r, cRw)
83+
ax.set_title("Cumulative Rw = %.4f" % cRw[-1])
84+
ax.set_xlabel("r")
85+
ax.set_ylabel("Rw")
86+
return
87+
88+
@staticmethod
89+
def _asarray(x, dtype=None):
90+
import numpy
91+
92+
return numpy.asarray(x, dtype=dtype)
93+
94+
95+
# End of class EasyPDFPlotting

src/diffpy/pdffit2/output.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python
2+
##############################################################################
3+
#
4+
# pdffit2 by DANSE Diffraction group
5+
# Simon J. L. Billinge
6+
# (c) 2007 trustees of the Michigan State University.
7+
# All rights reserved.
8+
#
9+
# File coded by: Pavol Juhas
10+
#
11+
# See AUTHORS.txt for a list of people who contributed.
12+
# See LICENSE.txt for license information.
13+
#
14+
##############################################################################
15+
16+
"""Take care of sending engine output to given file-like object.
17+
The output file is stored in local module variable stdout.
18+
"""
19+
20+
21+
# create module variable stdout
22+
23+
from sys import stdout as stdout
24+
25+
# silence pyflakes checker
26+
assert stdout
27+
28+
29+
def redirect_stdout(dst):
30+
"""Redirect PDFfit2 standard output to a file-like object dst.
31+
The dst value is stored in module variable stdout.
32+
"""
33+
from diffpy.pdffit2.pdffit2 import redirect_stdout
34+
35+
redirect_stdout(dst)
36+
global stdout
37+
stdout = dst
38+
return
39+
40+
41+
# End of file

0 commit comments

Comments
 (0)