From 425ec0f425b92971c9b3249e145ebf1988660b41 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 26 Jul 2024 18:21:58 -0400 Subject: [PATCH 01/12] fix not in --- src/diffpy/pdfgui/control/fitstructure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffpy/pdfgui/control/fitstructure.py b/src/diffpy/pdfgui/control/fitstructure.py index f643c994..515fdec5 100644 --- a/src/diffpy/pdfgui/control/fitstructure.py +++ b/src/diffpy/pdfgui/control/fitstructure.py @@ -252,7 +252,7 @@ def _restoreAtomConstraints(self, acd): acd -- dictionary obtained from _popAtomConstraints() """ for i, a in enumerate(self.initial): - if not a in acd: + if a not in acd: continue # there are some constraints for atom a siteindex = i + 1 From 8c2b49020c72a1d3f5b84ed35ceed1274ba52329 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 26 Jul 2024 18:26:00 -0400 Subject: [PATCH 02/12] fix lambda functions --- src/diffpy/pdfgui/control/organizer.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/diffpy/pdfgui/control/organizer.py b/src/diffpy/pdfgui/control/organizer.py index 31a5a095..fd6ace53 100644 --- a/src/diffpy/pdfgui/control/organizer.py +++ b/src/diffpy/pdfgui/control/organizer.py @@ -230,7 +230,7 @@ def organization(self): return org - def __forward_spdiameter(self): + def __forward_spdiameter(strucs, datasets, calcs): """Copy spdiameter value loaded from fit or calculation to phase. This method takes care of loading old PDFgui projects where @@ -238,20 +238,26 @@ def __forward_spdiameter(self): It should be called only from the Organizer.load method. """ # Jump out if any of structures has spdiameter set - for stru in self.strucs: + for stru in strucs: if stru.getvar("spdiameter"): return - # Search datasets for spdiameter and its constraints - spd_assigned = lambda ds: bool(ds.spdiameter) - spd_constrained = lambda ds: "spdiameter" in ds.constraints + + # Helper function to check if spdiameter is assigned + def spd_assigned(ds): + return bool(ds.spdiameter) + + # Helper function to check if spdiameter is constrained + def spd_constrained(ds): + return "spdiameter" in ds.constraints + # Figure out the value and constraint for spdiameter. # The highest priority is for a dataset with constrained spdiameter, # then for dataset with assigned spdiameter and finally from # a calculation. spd_val = spd_cns = None - constrained_datas = list(filter(spd_constrained, self.datasets)) - assigned_datas = list(filter(spd_assigned, self.datasets)) - assigned_calcs = list(filter(spd_assigned, self.calcs)) + constrained_datas = list(filter(spd_constrained, datasets)) + assigned_datas = list(filter(spd_assigned, datasets)) + assigned_calcs = list(filter(spd_assigned, calcs)) if constrained_datas: spd_val = constrained_datas[0].spdiameter spd_cns = constrained_datas[0].constraints["spdiameter"] @@ -260,13 +266,13 @@ def __forward_spdiameter(self): elif assigned_calcs: spd_val = assigned_calcs[0].spdiameter # assign spd_val to all structures that don't have it set - for stru in self.strucs: + for stru in strucs: if spd_val and not stru.getvar("spdiameter"): stru.setvar("spdiameter", spd_val) if spd_cns: stru.constraints.setdefault("spdiameter", spd_cns) # finally remove any spdiameter constraints from all datasets - for ds in self.datasets: + for ds in datasets: ds.constraints.pop("spdiameter", None) return From 2e0b3482a37ff41d83c91d0301f1b0d40829dc5f Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 26 Jul 2024 18:26:35 -0400 Subject: [PATCH 03/12] remove # --- src/diffpy/pdfgui/control/pdfguicontrol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/diffpy/pdfgui/control/pdfguicontrol.py b/src/diffpy/pdfgui/control/pdfguicontrol.py index bb39baa8..15632a0d 100644 --- a/src/diffpy/pdfgui/control/pdfguicontrol.py +++ b/src/diffpy/pdfgui/control/pdfguicontrol.py @@ -58,7 +58,7 @@ def __init__(self, gui=None): self.fittingQueue = [] self.currentFitting = None self.queueManager = PDFGuiControl.QueueManager(self) - ##self.startQueue() + # self.startQueue() def reset(self): """clean up for a new project""" From 4b0ed92c164c7c5d0eeb7bf4fad7f4a0a64745bf Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 26 Jul 2024 18:31:26 -0400 Subject: [PATCH 04/12] remove lambda func --- src/diffpy/pdfgui/control/plotter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/diffpy/pdfgui/control/plotter.py b/src/diffpy/pdfgui/control/plotter.py index 77134fb1..39359cbd 100644 --- a/src/diffpy/pdfgui/control/plotter.py +++ b/src/diffpy/pdfgui/control/plotter.py @@ -129,6 +129,11 @@ def _buildStyle(plotter, name, group, yNames): return style +def deblank(s): + """Remove all whitespace from the given string.""" + return "".join(s.split()) + + class Plotter(PDFComponent): """Plots a single graph. It can have multiple curves.""" @@ -622,7 +627,6 @@ def export(self, filename): header = "# Generated on %s by %s.\n" % (time.ctime(), getpass.getuser()) header += "# This file was created by PDFgui.\n" outfile.write(header) - deblank = lambda s: "".join(s.split()) xylist = [(c.x, c.y) for c in self.curves] xynames = [(_transName(c.xStr), deblank(c.name)) for c in self.curves] _exportCompactData(outfile, xylist, xynames) From 5d9f060b897d49ebab1394418de6ee0a656d7910 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 26 Jul 2024 18:32:12 -0400 Subject: [PATCH 05/12] modules to top --- src/diffpy/pdfgui/doc/manual/extractEquations.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/diffpy/pdfgui/doc/manual/extractEquations.py b/src/diffpy/pdfgui/doc/manual/extractEquations.py index 4c32814e..ce3a9819 100644 --- a/src/diffpy/pdfgui/doc/manual/extractEquations.py +++ b/src/diffpy/pdfgui/doc/manual/extractEquations.py @@ -1,4 +1,7 @@ #!/usr/bin/python +import os +import shutil +import sys """Read one or more texinfo files and extract any equations marked in the code with '@EquationMark' macro as PNG files to the images @@ -31,10 +34,6 @@ ############################################################################## # business -import os -import shutil -import sys - def loadEquations(): """Search for equation codes preceded by @EquationMark macro. From f4763cd60ef1bf95a142aba81f8764ea935012db Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 26 Jul 2024 18:34:32 -0400 Subject: [PATCH 06/12] mod to top --- .../pdfgui/doc/tutorial/tui_mno_bond_lengths.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/diffpy/pdfgui/doc/tutorial/tui_mno_bond_lengths.py b/src/diffpy/pdfgui/doc/tutorial/tui_mno_bond_lengths.py index 79c1b527..1f43d196 100755 --- a/src/diffpy/pdfgui/doc/tutorial/tui_mno_bond_lengths.py +++ b/src/diffpy/pdfgui/doc/tutorial/tui_mno_bond_lengths.py @@ -7,12 +7,17 @@ are plotted versus temperature and saved to "mno-bond-lengths.dat" file. """ +import pylab + +from diffpy.pdffit2 import PdfFit + +# Import tui (Text User Interface) functions from diffpy.pdfgui +from diffpy.pdfgui import tui + # PDFgui project file project_file = "lmo-template.ddp3" output_file = "mno-bond-lengths.dat" -# Import tui (Text User Interface) functions from diffpy.pdfgui -from diffpy.pdfgui import tui # load project file prj = tui.LoadProject(project_file) @@ -21,7 +26,7 @@ # using diffpy.pdffit2 # Create a PDF calculator object that will be used in that function. -from diffpy.pdffit2 import PdfFit + pf = PdfFit() @@ -69,7 +74,6 @@ def shortestBond_MnO(stru): # Plot results using matplotlib; pylab is a part of matplotlib that # provides MATLAB-like plotting functions. -import pylab pylab.plot(temperatures, MnO_bond_lengths, "o--") pylab.title("Data from refined phases in PDFgui project %s" % project_file) From 8fb1196f4bf3fda5c65838a3e93bc1db43733380 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 26 Jul 2024 18:36:32 -0400 Subject: [PATCH 07/12] line length and import and #s --- src/diffpy/pdfgui/gui/dopingseriespanel.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/diffpy/pdfgui/gui/dopingseriespanel.py b/src/diffpy/pdfgui/gui/dopingseriespanel.py index 211e2f8e..fd60c1bf 100644 --- a/src/diffpy/pdfgui/gui/dopingseriespanel.py +++ b/src/diffpy/pdfgui/gui/dopingseriespanel.py @@ -18,7 +18,6 @@ import os.path import re -import sys import wx @@ -41,7 +40,10 @@ def __init__(self, *args, **kwds): self.instructionsLabel = wx.StaticText( self, wx.ID_ANY, - "Select a fit from the tree on the left then add datasets and assign\ndoping elements and values below. If you have not set up a fit to be\nthe template for the series, hit cancel and rerun this macro once a\nfit has been created.", + "Select a fit from the tree on the left then add datasets and " + + "assign\ndoping elements and values below. " + + "If you have not set up a fit to be\nthe template for the series, " + + "hit cancel and rerun this macro once a\nfit has been created.", ) self.instructionsLabel.SetFont( wx.Font( @@ -210,7 +212,11 @@ def onAdd(self, event): # wxGlade: DopingSeriesPanel. if not dir: dir = self.mainFrame.workpath - matchstring = "PDF data files (*.gr)|*.gr|PDF fit files (*.fgr)|*.fgr|PDF fit files (*.fit)|*.fit|PDF calculation files (*.cgr)|*.cgr|PDF calculation files (*.calc)|*.calc|All Files|*" + matchstring = ( + "PDF data files (*.gr)|*.gr|PDF fit files (*.fgr)|*.fgr|PDF fit files (*.fit)|" + "*.fit|PDF calculation files (*.cgr)|*.cgr|PDF calculation files (*.calc)|*.calc|" + "All Files|*" + ) d = wx.FileDialog( None, "Choose files", @@ -304,7 +310,7 @@ def onCancel(self, event): # wxGlade: DopingSeriesPanel. self.mainFrame.switchRightPanel("blank") return - ## Utility functions + # Utility functions def checkConfiguration(self): """Verify that the dopant and base are elements. @@ -340,7 +346,7 @@ def fillList(self): self.listCtrlFiles.SetItem(index, 1, shortname) return - ## Needed by mainframe + # Needed by mainframe def treeSelectionUpdate(self, node): """Set the current fit when the tree selection changes.""" nodetype = self.treeCtrlMain.GetNodeType(node) @@ -349,7 +355,7 @@ def treeSelectionUpdate(self, node): self.refresh() return - ## Required by PDFPanel + # Required by PDFPanel def refresh(self): """Block out OK button if there is no fit. From f5938e75038ee27e8df4bb4d9d2ce0f843b11095 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 26 Jul 2024 18:40:34 -0400 Subject: [PATCH 08/12] fix line length and #s --- src/diffpy/pdfgui/gui/errorreportdialog.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/diffpy/pdfgui/gui/errorreportdialog.py b/src/diffpy/pdfgui/gui/errorreportdialog.py index b93cca76..308954c0 100644 --- a/src/diffpy/pdfgui/gui/errorreportdialog.py +++ b/src/diffpy/pdfgui/gui/errorreportdialog.py @@ -207,15 +207,18 @@ def _extractSearchTerms(tbtext): return rv -##### testing code ############################################################ +# testing code ############################################################ _EXAMPLE_TRACEBACK = r""" Traceback (most recent call last): - File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\diffpy\pdfgui\gui\errorwrapper.py", line 60, in _f + File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\ +diffpy\pdfgui\gui\errorwrapper.py", line 60, in _f return func(*args, **kwargs) - File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\diffpy\pdfgui\gui\mainframe.py", line 2176, in onSave + File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\ +diffpy\pdfgui\gui\mainframe.py", line 2176, in onSave self.control.save(self.fullpath) - File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\diffpy\pdfgui\control\pdfguicontrol.py", line 507, in save + File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\ +diffpy\pdfgui\control\pdfguicontrol.py", line 507, in save self.projfile = projfile.encode('ascii') UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 115: ordinal not in range(128) """.strip() @@ -242,4 +245,4 @@ def test(self): app = MyApp(0) app.MainLoop() -##### end of testing code ##################################################### +# end of testing code ##################################################### From e1b0843147816ee7424f5ce4bc8a208c233707e3 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 26 Jul 2024 18:43:14 -0400 Subject: [PATCH 09/12] comment unused var, fix imports and #s --- .../gui/errorreportdialog_control_fix.py | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/diffpy/pdfgui/gui/errorreportdialog_control_fix.py b/src/diffpy/pdfgui/gui/errorreportdialog_control_fix.py index 71e239ca..11a8681b 100644 --- a/src/diffpy/pdfgui/gui/errorreportdialog_control_fix.py +++ b/src/diffpy/pdfgui/gui/errorreportdialog_control_fix.py @@ -17,7 +17,6 @@ # generated by wxGlade 0.9.3 on Fri Jul 19 16:01:37 2019 import re -import webbrowser # # "Bug report" Dialog @@ -25,6 +24,8 @@ import wx import wx.html +from .errorreportdialog import ErrorReportDialog + # Constants ------------------------------------------------------------------ ISSUESTRACKER = "https://github.com/diffpy/diffpy.pdfgui/issues" @@ -77,7 +78,7 @@ def __do_layout(self): # begin wxGlade: ErrorReportDialog.__do_layout sizer_main = wx.BoxSizer(wx.VERTICAL) sizer_buttons = wx.BoxSizer(wx.HORIZONTAL) - sizer_log = wx.BoxSizer(wx.VERTICAL) + # sizer_log = wx.BoxSizer(wx.VERTICAL) sizer_label = wx.BoxSizer(wx.HORIZONTAL) sizer_label.Add(self.label_header, 1, wx.EXPAND, 5) sizer_main.Add(sizer_label, 1, wx.ALL | wx.EXPAND, 5) @@ -141,17 +142,21 @@ def _extractSearchTerms(tbtext): return rv -##### testing code ############################################################ +# testing code ############################################################ _EXAMPLE_TRACEBACK = r""" Traceback (most recent call last): - File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\diffpy\pdfgui\gui\errorwrapper.py", line 60, in _f + File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\ +\diffpy\pdfgui\gui\errorwrapper.py", line 60, in _f return func(*args, **kwargs) - File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\diffpy\pdfgui\gui\mainframe.py", line 2176, in onSave + File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\ +\diffpy\pdfgui\gui\mainframe.py", line 2176, in onSave self.control.save(self.fullpath) - File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\diffpy\pdfgui\control\pdfguicontrol.py", line 507, in save + File "C:\DiffPy\Python25\lib\site-packages\diffpy.pdfgui-1.0_r3067_20090410-py2.5.egg\ +\diffpy\pdfgui\control\pdfguicontrol.py", line 507, in save self.projfile = projfile.encode('ascii') -UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 115: ordinal not in range(128) +UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 115: \ +ordinal not in range(128) """.strip() @@ -176,4 +181,4 @@ def test(self): app = MyApp(0) app.MainLoop() -##### end of testing code ##################################################### +# end of testing code ##################################################### From 8aa878daf1110518111e8791b277246436c9e526 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Fri, 26 Jul 2024 18:44:31 -0400 Subject: [PATCH 10/12] modules to top and inline comment fix --- src/diffpy/pdfgui/gui/extendedplotframe.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/diffpy/pdfgui/gui/extendedplotframe.py b/src/diffpy/pdfgui/gui/extendedplotframe.py index 848b54d6..297a7670 100644 --- a/src/diffpy/pdfgui/gui/extendedplotframe.py +++ b/src/diffpy/pdfgui/gui/extendedplotframe.py @@ -20,8 +20,6 @@ import os.path import matplotlib - -matplotlib.use("WXAgg") import wx from matplotlib.artist import setp from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas @@ -32,6 +30,8 @@ from diffpy.pdfgui.gui.pdfguiglobals import iconpath from diffpy.pdfgui.gui.wxextensions import wx12 +matplotlib.use("WXAgg") + DATA_SAVE_ID = wx12.NewIdRef() @@ -303,7 +303,7 @@ def __translateStyles(self, style): symbolSize = style["symbolSize"] symbolColor = colorDict.get(style["symbolColor"], "k") properties.update( - { #'linewidth':0.0, # doesn't affect any + { # 'linewidth':0.0, # doesn't affect any "markerfacecolor": symbolColor, "markeredgecolor": color, "marker": symbol, From 3ee896adaee7244dfc6c858a5b88dfc0ab6a50b8 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Mon, 29 Jul 2024 16:11:26 -0400 Subject: [PATCH 11/12] def functions within function to pass tests --- src/diffpy/pdfgui/control/organizer.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/diffpy/pdfgui/control/organizer.py b/src/diffpy/pdfgui/control/organizer.py index fd6ace53..83ffd93c 100644 --- a/src/diffpy/pdfgui/control/organizer.py +++ b/src/diffpy/pdfgui/control/organizer.py @@ -230,7 +230,7 @@ def organization(self): return org - def __forward_spdiameter(strucs, datasets, calcs): + def __forward_spdiameter(self): """Copy spdiameter value loaded from fit or calculation to phase. This method takes care of loading old PDFgui projects where @@ -238,15 +238,14 @@ def __forward_spdiameter(strucs, datasets, calcs): It should be called only from the Organizer.load method. """ # Jump out if any of structures has spdiameter set - for stru in strucs: + for stru in self.strucs: if stru.getvar("spdiameter"): return - # Helper function to check if spdiameter is assigned + # Search datasets for spdiameter and its constraints def spd_assigned(ds): return bool(ds.spdiameter) - # Helper function to check if spdiameter is constrained def spd_constrained(ds): return "spdiameter" in ds.constraints @@ -255,9 +254,9 @@ def spd_constrained(ds): # then for dataset with assigned spdiameter and finally from # a calculation. spd_val = spd_cns = None - constrained_datas = list(filter(spd_constrained, datasets)) - assigned_datas = list(filter(spd_assigned, datasets)) - assigned_calcs = list(filter(spd_assigned, calcs)) + constrained_datas = list(filter(spd_constrained, self.datasets)) + assigned_datas = list(filter(spd_assigned, self.datasets)) + assigned_calcs = list(filter(spd_assigned, self.calcs)) if constrained_datas: spd_val = constrained_datas[0].spdiameter spd_cns = constrained_datas[0].constraints["spdiameter"] @@ -266,13 +265,13 @@ def spd_constrained(ds): elif assigned_calcs: spd_val = assigned_calcs[0].spdiameter # assign spd_val to all structures that don't have it set - for stru in strucs: + for stru in self.strucs: if spd_val and not stru.getvar("spdiameter"): stru.setvar("spdiameter", spd_val) if spd_cns: stru.constraints.setdefault("spdiameter", spd_cns) # finally remove any spdiameter constraints from all datasets - for ds in datasets: + for ds in self.datasets: ds.constraints.pop("spdiameter", None) return From d36838eee06f408431e5b0a62faadbb432f073f5 Mon Sep 17 00:00:00 2001 From: Caden Myers Date: Mon, 29 Jul 2024 16:18:17 -0400 Subject: [PATCH 12/12] move functions outside of class --- src/diffpy/pdfgui/control/organizer.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/diffpy/pdfgui/control/organizer.py b/src/diffpy/pdfgui/control/organizer.py index 83ffd93c..e5c74d37 100644 --- a/src/diffpy/pdfgui/control/organizer.py +++ b/src/diffpy/pdfgui/control/organizer.py @@ -20,6 +20,15 @@ from diffpy.pdfgui.control.pdfcomponent import PDFComponent +# Search datasets for spdiameter and its constraints +def spd_assigned(ds): + return bool(ds.spdiameter) + + +def spd_constrained(ds): + return "spdiameter" in ds.constraints + + class Organizer(PDFComponent): """Base class for Fitting. It holds separate lists of datasets, strucs and calculations @@ -242,13 +251,6 @@ def __forward_spdiameter(self): if stru.getvar("spdiameter"): return - # Search datasets for spdiameter and its constraints - def spd_assigned(ds): - return bool(ds.spdiameter) - - def spd_constrained(ds): - return "spdiameter" in ds.constraints - # Figure out the value and constraint for spdiameter. # The highest priority is for a dataset with constrained spdiameter, # then for dataset with assigned spdiameter and finally from