Skip to content

black autofix #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions conda-recipe/run_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python

import diffpy.srreal.tests

assert diffpy.srreal.tests.test().wasSuccessful()
72 changes: 39 additions & 33 deletions devutils/tunePeakPrecision.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@
from diffpy.structure import Structure
from diffpy.srreal.pdf_ext import PDFCalculator
import diffpy.pdffit2

# make PdfFit silent
diffpy.pdffit2.redirect_stdout(open('/dev/null', 'w'))
diffpy.pdffit2.redirect_stdout(open("/dev/null", "w"))

# define nickel structure data
nickel_discus_data = '''
nickel_discus_data = """
title Ni
spcgr P1
cell 3.523870, 3.523870, 3.523870, 90.000000, 90.000000, 90.000000
Expand All @@ -44,10 +45,10 @@
NI 0.00000000 0.50000000 0.50000000 0.1000
NI 0.50000000 0.00000000 0.50000000 0.1000
NI 0.50000000 0.50000000 0.00000000 0.1000
'''
"""

nickel = Structure()
nickel.readStr(nickel_discus_data, format='discus')
nickel.readStr(nickel_discus_data, format="discus")


def Gpdffit2(qmax):
Expand All @@ -59,7 +60,7 @@ def Gpdffit2(qmax):
"""
# calculate reference data using pdffit2
pf2 = diffpy.pdffit2.PdfFit()
pf2.alloc('X', qmax, 0.0, rmin, rmax, int((rmax - rmin) / rstep + 1))
pf2.alloc("X", qmax, 0.0, rmin, rmax, int((rmax - rmin) / rstep + 1))
pf2.add_structure(nickel)
pf2.calc()
rg = numpy.array((pf2.getR(), pf2.getpdf_fit()))
Expand All @@ -81,7 +82,7 @@ def Gsrreal(qmax, peakprecision=None):
pdfcalc._setDoubleAttr("rmax", rmax + rstep * 1e-4)
pdfcalc._setDoubleAttr("rstep", rstep)
if peakprecision is not None:
pdfcalc._setDoubleAttr('peakprecision', peakprecision)
pdfcalc._setDoubleAttr("peakprecision", peakprecision)
pdfcalc.eval(nickel)
rg = numpy.array([pdfcalc.rgrid, pdfcalc.pdf])
return rg
Expand All @@ -105,38 +106,39 @@ def comparePDFCalculators(qmax, peakprecision=None):
t0, t1 -- CPU times used by pdffit2 and PDFCalculator calls
"""
rv = {}
rv['qmax'] = qmax
rv['peakprecision'] = (peakprecision is None and
PDFCalculator()._getDoubleAttr('peakprecision') or peakprecision)
rv["qmax"] = qmax
rv["peakprecision"] = (
peakprecision is None and PDFCalculator()._getDoubleAttr("peakprecision") or peakprecision
)
ttic = time.clock()
rg0 = Gpdffit2(qmax)
ttoc = time.clock()
rv['r'] = rg0[0]
rv['g0'] = rg0[1]
rv['t0'] = ttoc - ttic
rv["r"] = rg0[0]
rv["g0"] = rg0[1]
rv["t0"] = ttoc - ttic
ttic = time.clock()
rg1 = Gsrreal(qmax, peakprecision)
ttoc = time.clock()
assert numpy.all(rv['r'] == rg1[0])
rv['g1'] = rg1[1]
rv['t1'] = ttoc - ttic
rv['gdiff'] = rv['g0'] - rv['g1']
rv['grmsd'] = numpy.sqrt(numpy.mean(rv['gdiff']**2))
assert numpy.all(rv["r"] == rg1[0])
rv["g1"] = rg1[1]
rv["t1"] = ttoc - ttic
rv["gdiff"] = rv["g0"] - rv["g1"]
rv["grmsd"] = numpy.sqrt(numpy.mean(rv["gdiff"] ** 2))
return rv


def processCommandLineArguments():
global qmax, peakprecision, createplot
argc = len(sys.argv)
if set(['-h', '--help']).intersection(sys.argv):
if set(["-h", "--help"]).intersection(sys.argv):
print(__doc__)
sys.exit()
if argc > 1:
qmax = float(sys.argv[1])
if argc > 2:
peakprecision = float(sys.argv[2])
if argc > 3:
createplot = sys.argv[3].lower() in ('y', 'yes', '1', 'true')
createplot = sys.argv[3].lower() in ("y", "yes", "1", "true")
return


Expand All @@ -148,37 +150,41 @@ def plotComparison(cmpdata):
No return value.
"""
import pylab

pylab.clf()
pylab.subplot(211)
pylab.title('qmax=%(qmax)g peakprecision=%(peakprecision)g' % cmpdata)
pylab.ylabel('G')
r = cmpdata['r']
g0 = cmpdata['g0']
g1 = cmpdata['g1']
gdiff = cmpdata['gdiff']
pylab.title("qmax=%(qmax)g peakprecision=%(peakprecision)g" % cmpdata)
pylab.ylabel("G")
r = cmpdata["r"]
g0 = cmpdata["g0"]
g1 = cmpdata["g1"]
gdiff = cmpdata["gdiff"]
pylab.plot(r, g0, r, g1)
pylab.subplot(212)
pylab.plot(r, gdiff, 'r')
pylab.plot(r, gdiff, "r")
slope = numpy.sum(r * gdiff) / numpy.sum(r**2)
pylab.plot(r, slope * r, '--')
pylab.xlabel('r')
pylab.ylabel('Gdiff')
pylab.title('slope = %g' % slope)
pylab.plot(r, slope * r, "--")
pylab.xlabel("r")
pylab.ylabel("Gdiff")
pylab.title("slope = %g" % slope)
pylab.draw()
return


def main():
processCommandLineArguments()
cmpdata = comparePDFCalculators(qmax, peakprecision)
print(("qmax = %(qmax)g pkprec = %(peakprecision)g " +
"grmsd = %(grmsd)g t0 = %(t0).3f t1 = %(t1).3f") % cmpdata)
print(
("qmax = %(qmax)g pkprec = %(peakprecision)g " + "grmsd = %(grmsd)g t0 = %(t0).3f t1 = %(t1).3f")
% cmpdata
)
if createplot:
plotComparison(cmpdata)
import pylab

pylab.show()
return


if __name__ == '__main__':
if __name__ == "__main__":
main()
87 changes: 44 additions & 43 deletions doc/manual/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('../../..'))
# sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath("../../.."))

# abbreviations
ab_authors = u'Pavol Juhás, Christopher L. Farrow, Simon J.L. Billinge group'
ab_authors = "Pavol Juhás, Christopher L. Farrow, Simon J.L. Billinge group"

# -- General configuration -----------------------------------------------------

Expand All @@ -33,38 +33,39 @@
# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.napoleon',
'sphinx.ext.intersphinx',
'm2r',
"sphinx.ext.autodoc",
"sphinx.ext.coverage",
"sphinx.ext.napoleon",
"sphinx.ext.intersphinx",
"m2r",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
source_suffix = ['.rst', '.md']
source_suffix = [".rst", ".md"]

# The encoding of source files.
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = 'diffpy.srreal'
copyright = '%Y, Brookhaven National Laboratory'
project = "diffpy.srreal"
copyright = "%Y, Brookhaven National Laboratory"

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
from setup import versiondata
fullversion = versiondata.get('DEFAULT', 'version')

fullversion = versiondata.get("DEFAULT", "version")
# The short X.Y version.
version = ''.join(fullversion.split('.post')[:1])
version = "".join(fullversion.split(".post")[:1])
# The full version, including alpha/beta/rc tags.
release = fullversion

Expand All @@ -75,13 +76,13 @@
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# today = ''
today_seconds = versiondata.getint('DEFAULT', 'timestamp')
today = time.strftime('%B %d, %Y', time.localtime(today_seconds))
today_seconds = versiondata.getint("DEFAULT", "timestamp")
today = time.strftime("%B %d, %Y", time.localtime(today_seconds))
year = today.split()[-1]
# Else, today_fmt is used as the format for a strftime call.
# today_fmt = '%B %d, %Y'
# substitute YEAR in the copyright string
copyright = copyright.replace('%Y', year)
copyright = copyright.replace("%Y", year)

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand All @@ -102,10 +103,10 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
modindex_common_prefix = ['diffpy.srreal']
modindex_common_prefix = ["diffpy.srreal"]

# Display all warnings for missing links.
nitpicky = True
Expand All @@ -114,14 +115,14 @@

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
html_theme = 'sphinx_py3doc_enhanced_theme'
html_theme = "sphinx_py3doc_enhanced_theme"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
'collapsiblesidebar' : 'true',
'navigation_with_keys' : 'true',
"collapsiblesidebar": "true",
"navigation_with_keys": "true",
}

# Add any paths that contain custom themes here, relative to this directory.
Expand Down Expand Up @@ -190,27 +191,24 @@
# html_file_suffix = None

# Output file base name for HTML help builder.
htmlhelp_basename = 'srrealdoc'
htmlhelp_basename = "srrealdoc"


# -- Options for LaTeX output --------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
# 'preamble': '',
# The paper size ('letterpaper' or 'a4paper').
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
# 'preamble': '',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
('index', 'diffpy.srreal.tex', 'diffpy.srreal Documentation',
ab_authors, 'manual'),
("index", "diffpy.srreal.tex", "diffpy.srreal Documentation", ab_authors, "manual"),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -238,10 +236,7 @@

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
('index', 'diffpy.srreal', 'diffpy.srreal Documentation',
ab_authors, 1)
]
man_pages = [("index", "diffpy.srreal", "diffpy.srreal Documentation", ab_authors, 1)]

# If true, show URL addresses after external links.
# man_show_urls = False
Expand All @@ -253,9 +248,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
('index', 'diffpy.srreal', 'diffpy.srreal Documentation',
ab_authors, 'diffpy.srreal', 'One line description of project.',
'Miscellaneous'),
(
"index",
"diffpy.srreal",
"diffpy.srreal Documentation",
ab_authors,
"diffpy.srreal",
"One line description of project.",
"Miscellaneous",
),
]

# Documents to append as an appendix to all manuals.
Expand All @@ -270,6 +271,6 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'numpy': ('https://docs.scipy.org/doc/numpy', None),
'python' : ('https://docs.python.org/3.7', None),
"numpy": ("https://docs.scipy.org/doc/numpy", None),
"python": ("https://docs.python.org/3.7", None),
}
9 changes: 5 additions & 4 deletions examples/compareC60PDFs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
from diffpy.srreal.pdfcalculator import PDFCalculator, DebyePDFCalculator

mydir = os.path.dirname(os.path.abspath(sys.argv[0]))
buckyfile = os.path.join(mydir, 'datafiles', 'C60bucky.stru')
buckyfile = os.path.join(mydir, "datafiles", "C60bucky.stru")

# load C60 molecule as a diffpy.structure object
bucky = Structure(filename=buckyfile)
cfg = { 'qmax' : 25,
'rmin' : 0,
'rmax' : 10.001,
cfg = {
"qmax": 25,
"rmin": 0,
"rmax": 10.001,
}

# calculate PDF by real-space summation
Expand Down
13 changes: 7 additions & 6 deletions examples/compareC60PDFs_objcryst.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from diffpy.srreal.pdfcalculator import PDFCalculator, DebyePDFCalculator

# load C60 molecule as a diffpy.structure object
bucky_diffpy = Structure(filename='datafiles/C60bucky.stru')
bucky_diffpy = Structure(filename="datafiles/C60bucky.stru")

# convert to an ObjCryst molecule
c60 = Crystal(1, 1, 1, 'P1')
c60 = Crystal(1, 1, 1, "P1")
mc60 = Molecule(c60, "C60")
c60.AddScatterer(mc60)
# Create the scattering power object for the carbon atoms
Expand All @@ -26,10 +26,11 @@
mc60.AddAtom(a.xyz_cartn[0], a.xyz_cartn[1], a.xyz_cartn[2], sp, cname)

# PDF configuration
cfg = { 'qmax' : 25,
'rmin' : 0,
'rmax' : 10.001,
'rstep' : 0.05,
cfg = {
"qmax": 25,
"rmin": 0,
"rmax": 10.001,
"rstep": 0.05,
}

# calculate PDF by real-space summation
Expand Down
Loading