Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
[pre-commit.ci] auto fixes from pre-commit hooks
  • Loading branch information
pre-commit-ci[bot] committed Jul 22, 2024
commit 6eb7215b1032d5911127e346e58613a532733993
1 change: 1 addition & 0 deletions conda-recipe/expandpdfguibase.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import sys

from pkg_resources import Requirement, resource_filename

pkg = Requirement.parse("diffpy.pdfgui")
Expand Down
38 changes: 22 additions & 16 deletions devutils/makesdist
Original file line number Diff line number Diff line change
@@ -1,51 +1,57 @@
#!/usr/bin/env python

'''Create source distribution tar.gz archive, where each file belongs
"""Create source distribution tar.gz archive, where each file belongs
to a root user and modification time is set to the git commit time.
'''
"""

import sys
import glob
import gzip
import os
import subprocess
import glob
import sys
import tarfile
import gzip

BASEDIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
sys.path.insert(0, BASEDIR)

from setup import versiondata, FALLBACK_VERSION
timestamp = versiondata.getint('DEFAULT', 'timestamp')
from setup import FALLBACK_VERSION, versiondata

vfb = versiondata.get('DEFAULT', 'version').split('.post')[0] + '.post0'
timestamp = versiondata.getint("DEFAULT", "timestamp")

vfb = versiondata.get("DEFAULT", "version").split(".post")[0] + ".post0"
emsg = "Invalid FALLBACK_VERSION. Expected %r got %r."
assert vfb == FALLBACK_VERSION, emsg % (vfb, FALLBACK_VERSION)


def inform(s):
sys.stdout.write(s)
sys.stdout.flush()
return


inform('Run "setup.py sdist --formats=tar" ')
cmd_sdist = [sys.executable] + 'setup.py sdist --formats=tar'.split()
ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, 'w'))
if ec: sys.exit(ec)
cmd_sdist = [sys.executable] + "setup.py sdist --formats=tar".split()
ec = subprocess.call(cmd_sdist, cwd=BASEDIR, stdout=open(os.devnull, "w"))
if ec:
sys.exit(ec)
inform("[done]\n")

tarname = max(glob.glob(BASEDIR + '/dist/*.tar'), key=os.path.getmtime)
tarname = max(glob.glob(BASEDIR + "/dist/*.tar"), key=os.path.getmtime)

tfin = tarfile.open(tarname)
fpout = gzip.GzipFile(tarname + '.gz', 'w', mtime=0)
tfout = tarfile.open(fileobj=fpout, mode='w')
fpout = gzip.GzipFile(tarname + ".gz", "w", mtime=0)
tfout = tarfile.open(fileobj=fpout, mode="w")


def fixtarinfo(tinfo):
tinfo.uid = tinfo.gid = 0
tinfo.uname = tinfo.gname = 'root'
tinfo.uname = tinfo.gname = "root"
tinfo.mtime = timestamp
tinfo.mode &= ~0o022
return tinfo

inform('Filter %s --> %s.gz ' % (2 * (os.path.basename(tarname),)))

inform("Filter %s --> %s.gz " % (2 * (os.path.basename(tarname),)))
for ti in tfin:
tfout.addfile(fixtarinfo(ti), tfin.extractfile(ti))

Expand Down
10 changes: 4 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
import os
import re
import sys
from setuptools import setup, find_packages

from setuptools import find_packages, setup

# Use this version when git data are not available, like in git zip archive.
# Update when tagging a new release.
Expand All @@ -28,7 +29,7 @@


def gitinfo():
from subprocess import Popen, PIPE
from subprocess import PIPE, Popen

kw = dict(stdout=PIPE, cwd=MYDIR, universal_newlines=True)
proc = Popen(["git", "describe", "--tags", "--match=v[[:digit:]]*"], **kw)
Expand Down Expand Up @@ -67,10 +68,7 @@ def getversioncfg():
cp = RawConfigParser()
cp.read(versioncfgfile)
d = cp.defaults()
rewrite = not d or (
g["commit"]
and (g["version"] != d.get("version") or g["commit"] != d.get("commit"))
)
rewrite = not d or (g["commit"] and (g["version"] != d.get("version") or g["commit"] != d.get("commit")))
if rewrite:
cp.set("DEFAULT", "version", g["version"])
cp.set("DEFAULT", "commit", g["commit"])
Expand Down
4 changes: 2 additions & 2 deletions src/diffpy/pdfgui/applications/pdfgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@

from __future__ import print_function

import sys
import os
import getopt
import os
import sys


def usage():
Expand Down
10 changes: 6 additions & 4 deletions src/diffpy/pdfgui/control/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
import copy
import math

from diffpy.pdfgui.control.controlerrors import ControlConfigError
from diffpy.pdfgui.control.controlerrors import ControlKeyError
from diffpy.pdfgui.control.controlerrors import ControlValueError
from diffpy.pdfgui.control.controlerrors import (
ControlConfigError,
ControlKeyError,
ControlValueError,
)
from diffpy.pdfgui.control.pdfcomponent import PDFComponent
from diffpy.pdfgui.utils import safeCPickleDumps, pickle_loads
from diffpy.pdfgui.utils import pickle_loads, safeCPickleDumps


class Calculation(PDFComponent):
Expand Down
6 changes: 2 additions & 4 deletions src/diffpy/pdfgui/control/constraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
constraints will be stored in { variable : constraint } dictionary
"""

import re
import math
import re

from diffpy.pdfgui.control.controlerrors import ControlSyntaxError

Expand Down Expand Up @@ -135,9 +135,7 @@ def __setattr__(self, name, value):
raise ControlSyntaxError(message)
# few more checks of the formula:
if newformula.find("**") != -1:
emsg = (
"invalid constraint formula '{}', " "operator '**' not supported."
).format(newformula)
emsg = ("invalid constraint formula '{}', " "operator '**' not supported.").format(newformula)
raise ControlSyntaxError(emsg)
# checks checked
self.__dict__["formula"] = newformula
Expand Down
34 changes: 10 additions & 24 deletions src/diffpy/pdfgui/control/fitdataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
"""

import copy

import numpy

from diffpy.pdfgui.control.pdfdataset import PDFDataSet
from diffpy.pdfgui.control.parameter import Parameter
from diffpy.pdfgui.control.controlerrors import ControlStatusError
from diffpy.pdfgui.control.parameter import Parameter
from diffpy.pdfgui.control.pdfdataset import PDFDataSet


class FitDataSet(PDFDataSet):
Expand Down Expand Up @@ -112,9 +113,7 @@ def getYNames(self):

returns list of strings
"""
ynames = ["Gobs", "Gcalc", "Gdiff", "Gtrunc", "dGcalc", "crw"] + list(
self.constraints.keys()
)
ynames = ["Gobs", "Gcalc", "Gdiff", "Gtrunc", "dGcalc", "crw"] + list(self.constraints.keys())
return ynames

def getXNames(self):
Expand Down Expand Up @@ -321,10 +320,7 @@ def writeCalcStr(self):
Gdiff = self.Gdiff
drcalc = 0.0
for i in range(len(self.rcalc)):
lines.append(
"%g %g %.1f %g %g"
% (self.rcalc[i], self.Gcalc[i], drcalc, self.dGcalc[i], Gdiff[i])
)
lines.append("%g %g %.1f %g %g" % (self.rcalc[i], self.Gcalc[i], drcalc, self.dGcalc[i], Gdiff[i]))
# lines are ready here
datastring = "\n".join(lines) + "\n"
return datastring
Expand Down Expand Up @@ -636,9 +632,7 @@ def _set_fitrmin(self, value):
self._fitrmin = float(value)
return

fitrmin = property(
_get_fitrmin, _set_fitrmin, doc="Lower boundary for simulated PDF curve."
)
fitrmin = property(_get_fitrmin, _set_fitrmin, doc="Lower boundary for simulated PDF curve.")

# fitrmax

Expand All @@ -650,9 +644,7 @@ def _set_fitrmax(self, value):
self._fitrmax = float(value)
return

fitrmax = property(
_get_fitrmax, _set_fitrmax, doc="Upper boundary for simulated PDF curve."
)
fitrmax = property(_get_fitrmax, _set_fitrmax, doc="Upper boundary for simulated PDF curve.")

# fitrstep

Expand All @@ -664,9 +656,7 @@ def _set_fitrstep(self, value):
self._fitrstep = float(value)
return

fitrstep = property(
_get_fitrstep, _set_fitrstep, doc="R-step used for simulated PDF curve."
)
fitrstep = property(_get_fitrstep, _set_fitrstep, doc="R-step used for simulated PDF curve.")

# rcalc

Expand Down Expand Up @@ -707,9 +697,7 @@ def _set_dGcalc(self, value):
self._dGcalc = value
return

dGcalc = property(
_get_dGcalc, _set_dGcalc, doc="List of standard deviations of Gcalc."
)
dGcalc = property(_get_dGcalc, _set_dGcalc, doc="List of standard deviations of Gcalc.")

# Gtrunc

Expand Down Expand Up @@ -757,9 +745,7 @@ def _get_Gdiff(self):
rv = []
return rv

Gdiff = property(
_get_Gdiff, doc="Difference between observed and calculated PDF on rcalc grid."
)
Gdiff = property(_get_Gdiff, doc="Difference between observed and calculated PDF on rcalc grid.")

# crw
def _get_crw(self):
Expand Down
30 changes: 9 additions & 21 deletions src/diffpy/pdfgui/control/fitstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@

import copy
import re

import numpy

from diffpy.pdfgui.control.pdfstructure import PDFStructure
from diffpy.pdfgui.control.constraint import Constraint
from diffpy.pdfgui.control.parameter import Parameter
from diffpy.pdfgui.control.controlerrors import ControlTypeError, ControlValueError
from diffpy.pdfgui.control.parameter import Parameter
from diffpy.pdfgui.control.pdfstructure import PDFStructure
from diffpy.structure import Atom


Expand Down Expand Up @@ -309,12 +310,7 @@ def expandSuperCell(self, mno):
# back to business
acd = self._popAtomConstraints()
mnofloats = numpy.array(mno[:3], dtype=float)
ijklist = [
(i, j, k)
for i in range(mno[0])
for j in range(mno[1])
for k in range(mno[2])
]
ijklist = [(i, j, k) for i in range(mno[0]) for j in range(mno[1]) for k in range(mno[2])]
# build a list of new atoms
newatoms = []
for a in self.initial:
Expand Down Expand Up @@ -389,9 +385,7 @@ def getSpaceGroupList(self):
existing_names[sg.short_name] = True
# sort by International Tables number, stay compatible with 2.3
n_sg = [(sg.number % 1000, sg) for sg in unique_named_list]
n_sg = sorted(
n_sg, key=lambda x: x[0]
) # sort by the first element of tuple.
n_sg = sorted(n_sg, key=lambda x: x[0]) # sort by the first element of tuple.
FitStructure.sorted_standard_space_groups = [sg for n, sg in n_sg]
sglist = list(FitStructure.sorted_standard_space_groups)
if self.custom_spacegroup:
Expand Down Expand Up @@ -438,9 +432,7 @@ def expandAsymmetricUnit(self, spacegroup, indices, sgoffset=[0, 0, 0]):
coreatoms = [self.initial[i] for i in ruindices]
corepos = [a.xyz for a in coreatoms]
coreUijs = [a.U for a in coreatoms]
eau = ExpandAsymmetricUnit(
spacegroup, corepos, coreUijs, sgoffset=sgoffset, eps=self.symposeps
)
eau = ExpandAsymmetricUnit(spacegroup, corepos, coreUijs, sgoffset=sgoffset, eps=self.symposeps)
# build a nested list of new atoms:
newatoms = []
for i in range(len(coreatoms)):
Expand Down Expand Up @@ -469,9 +461,7 @@ def expandAsymmetricUnit(self, spacegroup, indices, sgoffset=[0, 0, 0]):
self._restoreAtomConstraints(acd)
return

def applySymmetryConstraints(
self, spacegroup, indices, posflag, Uijflag, sgoffset=[0, 0, 0]
):
def applySymmetryConstraints(self, spacegroup, indices, posflag, Uijflag, sgoffset=[0, 0, 0]):
"""Generate symmetry constraints for positions and thermal factors.
Both positions and thermal factors may get corrected to reflect
space group symmetry. Old positional and thermal constraints get
Expand Down Expand Up @@ -511,9 +501,7 @@ def applySymmetryConstraints(
selatoms = [self.initial[i] for i in uindices]
selpos = [a.xyz for a in selatoms]
selUijs = [a.U for a in selatoms]
symcon = SymmetryConstraints(
spacegroup, selpos, selUijs, sgoffset=sgoffset, eps=self.symposeps
)
symcon = SymmetryConstraints(spacegroup, selpos, selUijs, sgoffset=sgoffset, eps=self.symposeps)
# deal with positions
if posflag:
# fix positions:
Expand Down Expand Up @@ -762,8 +750,8 @@ def load(self, z, subpath):
subpath -- path to its own storage within project file
"""
# subpath = projname/fitname/structure/myname/
from diffpy.pdfgui.utils import asunicode
from diffpy.pdfgui.control.pdfguicontrol import CtrlUnpickler
from diffpy.pdfgui.utils import asunicode

subs = subpath.split("/")
rootDict = z.fileTree[subs[0]][subs[1]][subs[2]][subs[3]]
Expand Down
24 changes: 11 additions & 13 deletions src/diffpy/pdfgui/control/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,25 @@
import threading
import time

from diffpy.pdfgui.control.controlerrors import (
ControlError,
ControlStatusError,
ControlValueError,
)
from diffpy.pdfgui.control.organizer import Organizer
from diffpy.pdfgui.control.controlerrors import ControlError
from diffpy.pdfgui.control.controlerrors import ControlStatusError
from diffpy.pdfgui.control.controlerrors import ControlValueError
from diffpy.pdfgui.utils import safeCPickleDumps, pickle_loads
from diffpy.pdfgui.utils import pickle_loads, safeCPickleDumps

# helper routines to deal with PDFfit2 exceptions


def getEngineExceptions():
"""Return a tuple of possible exceptions from diffpy.pdffit2.pdffit2."""
from diffpy.pdffit2.pdffit2 import (
dataError,
unassignedError,
calculationError,
constraintError,
dataError,
structureError,
calculationError,
unassignedError,
)

engine_exceptions = (
Expand Down Expand Up @@ -212,9 +214,7 @@ def load(self, z, subpath):

self.parameters = CtrlUnpickler.loads(z.read(subpath + "parameters"))
if "steps" in rootDict:
self.itemIndex, self.dataNameDict, self.snapshots = pickle_loads(
z.read(subpath + "steps")
)
self.itemIndex, self.dataNameDict, self.snapshots = pickle_loads(z.read(subpath + "steps"))
if "result" in rootDict:
self.rw, self.res = pickle_loads(z.read(subpath + "result"))

Expand Down Expand Up @@ -582,9 +582,7 @@ def close(self, force=False):
# way while user choose to stop forcefully
else:
if self.isThreadRunning():
raise ControlStatusError(
"Fitting: Fitting %s is still running" % self.name
)
raise ControlStatusError("Fitting: Fitting %s is still running" % self.name)
if self.thread is not None:
self.thread.join()

Expand Down
Loading