Skip to content

Commit 48b3bbb

Browse files
authored
Merge pull request #67 from stevenhua0320/lint-check
(Lint check)Fix E231 E305 error for coreshellnnp.py
2 parents 1f87b7b + aab29dc commit 48b3bbb

File tree

5 files changed

+91
-83
lines changed

5 files changed

+91
-83
lines changed

.idea/.gitignore

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/examples/coreshellnp.py

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,22 @@
3131
from diffpy.srfit.fitbase import FitContribution, FitRecipe
3232
from diffpy.srfit.fitbase import FitResults
3333

34-
####### Example Code
34+
# Example Code
35+
3536

3637
def makeRecipe(stru1, stru2, datname):
3738
"""Create a fitting recipe for crystalline PDF data."""
3839

39-
## The Profile
40+
# The Profile
4041
profile = Profile()
4142

4243
# Load data and add it to the profile
4344
parser = PDFParser()
4445
parser.parseFile(datname)
4546
profile.loadParsedData(parser)
46-
profile.setCalculationRange(xmin=1.5, xmax = 45, dx = 0.1)
47+
profile.setCalculationRange(xmin=1.5, xmax=45, dx=0.1)
4748

48-
## The ProfileGenerator
49+
# The ProfileGenerator
4950
# In order to fit the core and shell phases simultaneously, we must use two
5051
# PDFGenerators.
5152
#
@@ -61,20 +62,20 @@ def makeRecipe(stru1, stru2, datname):
6162
generator_zns.setQmax(26)
6263
generator_zns.qdamp.value = 0.0396
6364

64-
## The FitContribution
65+
# The FitContribution
6566
# Add both generators and the profile to the FitContribution.
6667
contribution = FitContribution("cdszns")
6768
contribution.addProfileGenerator(generator_cds)
6869
contribution.addProfileGenerator(generator_zns)
69-
contribution.setProfile(profile, xname = "r")
70+
contribution.setProfile(profile, xname="r")
7071

7172
# Set up the characteristic functions. We use a spherical CF for the core
7273
# and a spherical shell CF for the shell. Since this is set up as two
7374
# phases, we implicitly assume that the core-shell correlations contribute
7475
# very little to the PDF.
7576
from diffpy.srfit.pdf.characteristicfunctions import sphericalCF, shellCF
76-
contribution.registerFunction(sphericalCF, name = "f_CdS")
77-
contribution.registerFunction(shellCF, name = "f_ZnS")
77+
contribution.registerFunction(sphericalCF, name="f_CdS")
78+
contribution.registerFunction(shellCF, name="f_ZnS")
7879

7980
# Write the fitting equation. We want to sum the PDFs from each phase and
8081
# multiply it by a scaling factor.
@@ -90,7 +91,7 @@ def makeRecipe(stru1, stru2, datname):
9091
recipe.addVar(contribution.thickness, 11)
9192
recipe.constrain(contribution.psize, "2 * radius")
9293

93-
## Configure the fit variables
94+
# Configure the fit variables
9495
# Start by configuring the scale factor and resolution factors.
9596
# We want the sum of the phase scale factors to be 1.
9697
recipe.newVar("scale_CdS", 0.7)
@@ -106,27 +107,28 @@ def makeRecipe(stru1, stru2, datname):
106107
# subsequent refinement.
107108
phase_cds = generator_cds.phase
108109
for par in phase_cds.sgpars.latpars:
109-
recipe.addVar(par, name = par.name + "_cds", tag = "lat")
110+
recipe.addVar(par, name=par.name + "_cds", tag="lat")
110111
for par in phase_cds.sgpars.adppars:
111-
recipe.addVar(par, 1, name = par.name + "_cds", tag = "adp")
112-
recipe.addVar(phase_cds.sgpars.xyzpars.z_1, name = "z_1_cds", tag = "xyz")
112+
recipe.addVar(par, 1, name=par.name + "_cds", tag="adp")
113+
recipe.addVar(phase_cds.sgpars.xyzpars.z_1, name="z_1_cds", tag="xyz")
113114
# Since we know these have stacking disorder, constrain the B33 adps for
114115
# each atom type.
115116
recipe.constrain("B33_1_cds", "B33_0_cds")
116-
recipe.addVar(generator_cds.delta2, name = "delta2_cds", value = 5)
117+
recipe.addVar(generator_cds.delta2, name="delta2_cds", value=5)
117118

118119
phase_zns = generator_zns.phase
119120
for par in phase_zns.sgpars.latpars:
120-
recipe.addVar(par, name = par.name + "_zns", tag = "lat")
121+
recipe.addVar(par, name=par.name + "_zns", tag="lat")
121122
for par in phase_zns.sgpars.adppars:
122-
recipe.addVar(par, 1, name = par.name + "_zns", tag = "adp")
123-
recipe.addVar(phase_zns.sgpars.xyzpars.z_1, name = "z_1_zns", tag = "xyz")
123+
recipe.addVar(par, 1, name=par.name + "_zns", tag="adp")
124+
recipe.addVar(phase_zns.sgpars.xyzpars.z_1, name="z_1_zns", tag="xyz")
124125
recipe.constrain("B33_1_zns", "B33_0_zns")
125-
recipe.addVar(generator_zns.delta2, name = "delta2_zns", value = 2.5)
126+
recipe.addVar(generator_zns.delta2, name="delta2_zns", value=2.5)
126127

127128
# Give the recipe away so it can be used!
128129
return recipe
129130

131+
130132
def plotResults(recipe):
131133
"""Plot the results contained within a refined FitRecipe."""
132134

@@ -138,10 +140,10 @@ def plotResults(recipe):
138140
diff = g - gcalc + diffzero
139141

140142
import pylab
141-
pylab.plot(r,g,'bo',label="G(r) Data")
142-
pylab.plot(r, gcalc,'r-',label="G(r) Fit")
143-
pylab.plot(r,diff,'g-',label="G(r) diff")
144-
pylab.plot(r,diffzero,'k-')
143+
pylab.plot(r, g, 'bo', label="G(r) Data")
144+
pylab.plot(r, gcalc, 'r-', label="G(r) Fit")
145+
pylab.plot(r, diff, 'g-', label="G(r) diff")
146+
pylab.plot(r, diffzero, 'k-')
145147
pylab.xlabel(r"$r (\AA)$")
146148
pylab.ylabel(r"$G (\AA^{-2})$")
147149
pylab.legend(loc=1)
@@ -172,23 +174,23 @@ def main():
172174
# Start with the lattice parameters. In makeRecipe, these were tagged with
173175
# "lat". Here is how we use that.
174176
recipe.free("lat")
175-
leastsq(recipe.residual, recipe.values, maxfev = 50)
177+
leastsq(recipe.residual, recipe.values, maxfev=50)
176178

177179
# Now the scale and phase fraction.
178180
recipe.free("scale", "scale_CdS")
179-
leastsq(recipe.residual, recipe.values, maxfev = 50)
181+
leastsq(recipe.residual, recipe.values, maxfev=50)
180182

181183
# The ADPs.
182184
recipe.free("adp")
183-
leastsq(recipe.residual, recipe.values, maxfev = 100)
185+
leastsq(recipe.residual, recipe.values, maxfev=100)
184186

185187
# The delta2 parameters.
186188
recipe.free("delta2_cds", "delta2_zns")
187-
leastsq(recipe.residual, recipe.values, maxfev = 50)
189+
leastsq(recipe.residual, recipe.values, maxfev=50)
188190

189191
# The shape parameters.
190192
recipe.free("radius", "thickness")
191-
leastsq(recipe.residual, recipe.values, maxfev = 50)
193+
leastsq(recipe.residual, recipe.values, maxfev=50)
192194

193195
# The positional parameters.
194196
recipe.free("xyz")
@@ -202,6 +204,7 @@ def main():
202204
plotResults(recipe)
203205
return
204206

207+
205208
if __name__ == "__main__":
206209
main()
207210

src/diffpy/srfit/fitbase/calculator.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from diffpy.srfit.fitbase.parameterset import ParameterSet
3030
from diffpy.srfit.equation.literals.operators import Operator
3131

32+
3233
class Calculator(Operator, ParameterSet):
3334
"""Base class for calculators.
3435
@@ -75,12 +76,10 @@ def __init__(self, name):
7576
Operator.__init__(self, name)
7677
return
7778

78-
7979
@property
8080
def symbol(self):
8181
return self.name
8282

83-
8483
# Overload me!
8584
def __call__(self, *args):
8685
"""Calculate something.
@@ -92,12 +91,10 @@ def __call__(self, *args):
9291
"""
9392
return 0
9493

95-
9694
def operation(self, *args):
9795
self._value = self.__call__(*args)
9896
return self._value
9997

100-
10198
def _validate(self):
10299
"""Validate my state.
103100

src/diffpy/srfit/structure/diffpyparset.py

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -94,49 +94,49 @@ def __init__(self, name, atom):
9494
self.atom = atom
9595
a = atom
9696
# x, y, z, occupancy
97-
self.addParameter(ParameterAdapter("x", a, _xyzgetter(0),
98-
_xyzsetter(0)))
99-
self.addParameter(ParameterAdapter("y", a, _xyzgetter(1),
100-
_xyzsetter(1)))
101-
self.addParameter(ParameterAdapter("z", a, _xyzgetter(2),
102-
_xyzsetter(2)))
103-
occupancy = ParameterAdapter("occupancy", a, attr = "occupancy")
97+
self.addParameter(ParameterAdapter("x", a,
98+
_xyzgetter(0), _xyzsetter(0)))
99+
self.addParameter(ParameterAdapter("y", a,
100+
_xyzgetter(1), _xyzsetter(1)))
101+
self.addParameter(ParameterAdapter("z", a,
102+
_xyzgetter(2), _xyzsetter(2)))
103+
occupancy = ParameterAdapter("occupancy", a, attr="occupancy")
104104
self.addParameter(occupancy)
105105
self.addParameter(ParameterProxy("occ", occupancy))
106106
# U
107-
self.addParameter(ParameterAdapter("U11", a, attr = "U11"))
108-
self.addParameter(ParameterAdapter("U22", a, attr = "U22"))
109-
self.addParameter(ParameterAdapter("U33", a, attr = "U33"))
110-
U12 = ParameterAdapter("U12", a, attr = "U12")
107+
self.addParameter(ParameterAdapter("U11", a, attr="U11"))
108+
self.addParameter(ParameterAdapter("U22", a, attr="U22"))
109+
self.addParameter(ParameterAdapter("U33", a, attr="U33"))
110+
U12 = ParameterAdapter("U12", a, attr="U12")
111111
U21 = ParameterProxy("U21", U12)
112-
U13 = ParameterAdapter("U13", a, attr = "U13")
112+
U13 = ParameterAdapter("U13", a, attr="U13")
113113
U31 = ParameterProxy("U31", U13)
114-
U23 = ParameterAdapter("U23", a, attr = "U23")
114+
U23 = ParameterAdapter("U23", a, attr="U23")
115115
U32 = ParameterProxy("U32", U23)
116116
self.addParameter(U12)
117117
self.addParameter(U21)
118118
self.addParameter(U13)
119119
self.addParameter(U31)
120120
self.addParameter(U23)
121121
self.addParameter(U32)
122-
self.addParameter(ParameterAdapter("Uiso", a, attr = "Uisoequiv"))
122+
self.addParameter(ParameterAdapter("Uiso", a, attr="Uisoequiv"))
123123
# B
124-
self.addParameter(ParameterAdapter("B11", a, attr = "B11"))
125-
self.addParameter(ParameterAdapter("B22", a, attr = "B22"))
126-
self.addParameter(ParameterAdapter("B33", a, attr = "B33"))
127-
B12 = ParameterAdapter("B12", a, attr = "B12")
124+
self.addParameter(ParameterAdapter("B11", a, attr="B11"))
125+
self.addParameter(ParameterAdapter("B22", a, attr="B22"))
126+
self.addParameter(ParameterAdapter("B33", a, attr="B33"))
127+
B12 = ParameterAdapter("B12", a, attr="B12")
128128
B21 = ParameterProxy("B21", B12)
129-
B13 = ParameterAdapter("B13", a, attr = "B13")
129+
B13 = ParameterAdapter("B13", a, attr="B13")
130130
B31 = ParameterProxy("B31", B13)
131-
B23 = ParameterAdapter("B23", a, attr = "B23")
131+
B23 = ParameterAdapter("B23", a, attr="B23")
132132
B32 = ParameterProxy("B32", B23)
133133
self.addParameter(B12)
134134
self.addParameter(B21)
135135
self.addParameter(B13)
136136
self.addParameter(B31)
137137
self.addParameter(B23)
138138
self.addParameter(B32)
139-
self.addParameter(ParameterAdapter("Biso", a, attr = "Bisoequiv"))
139+
self.addParameter(ParameterAdapter("Biso", a, attr="Bisoequiv"))
140140
return
141141

142142
def __repr__(self):
@@ -156,6 +156,7 @@ def _setElem(self, el):
156156
def _latgetter(par):
157157
return bind2nd(getattr, par)
158158

159+
159160
def _latsetter(par):
160161
return bind2nd(setattr, par)
161162

@@ -185,19 +186,19 @@ def __init__(self, lattice):
185186
ParameterSet.__init__(self, "lattice")
186187
self.angunits = "deg"
187188
self.lattice = lattice
188-
l = lattice
189-
self.addParameter(ParameterAdapter("a", l, _latgetter("a"),
190-
_latsetter("a")))
191-
self.addParameter(ParameterAdapter("b", l, _latgetter("b"),
192-
_latsetter("b")))
193-
self.addParameter(ParameterAdapter("c", l, _latgetter("c"),
194-
_latsetter("c")))
195-
self.addParameter(ParameterAdapter("alpha", l, _latgetter("alpha"),
196-
_latsetter("alpha")))
197-
self.addParameter(ParameterAdapter("beta", l, _latgetter("beta"),
198-
_latsetter("beta")))
199-
self.addParameter(ParameterAdapter("gamma", l, _latgetter("gamma"),
200-
_latsetter("gamma")))
189+
lat = lattice
190+
self.addParameter(ParameterAdapter("a", lat,
191+
_latgetter("a"), _latsetter("a")))
192+
self.addParameter(ParameterAdapter("b", lat,
193+
_latgetter("b"), _latsetter("b")))
194+
self.addParameter(ParameterAdapter("c", lat,
195+
_latgetter("c"), _latsetter("c")))
196+
self.addParameter(ParameterAdapter("alpha", lat, _latgetter("alpha"),
197+
_latsetter("alpha")))
198+
self.addParameter(ParameterAdapter("beta", lat, _latgetter("beta"),
199+
_latsetter("beta")))
200+
self.addParameter(ParameterAdapter("gamma", lat, _latgetter("gamma"),
201+
_latsetter("gamma")))
201202
return
202203

203204
def __repr__(self):
@@ -242,10 +243,10 @@ def __init__(self, name, stru):
242243
for a in stru:
243244
el = a.element.title()
244245
# Try to sanitize the name.
245-
el = el.replace("+","p")
246-
el = el.replace("-","m")
246+
el = el.replace("+", "p")
247+
el = el.replace("-", "m")
247248
i = cdict.get(el, 0)
248-
aname = "%s%i"%(el,i)
249+
aname = "%s%i" % (el, i)
249250
cdict[el] = i+1
250251
atom = DiffpyAtomParSet(aname, a)
251252
self.addParameterSet(atom)

0 commit comments

Comments
 (0)