Skip to content

Commit dd78a46

Browse files
authored
Cleaning up and fix the flake8 complains (#40)
* Cleaning up and fix the flake8 complains * Add iosrt configurations * Add `application-import-names` * Fix the import order errors from flake8
1 parent 2cca563 commit dd78a46

File tree

9 files changed

+48
-43
lines changed

9 files changed

+48
-43
lines changed

bfit/fit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from timeit import default_timer as timer
2727

2828
import numpy as np
29-
from scipy.optimize import NonlinearConstraint, minimize
29+
from scipy.optimize import minimize, NonlinearConstraint
3030

3131
from bfit.measure import KLDivergence, Measure, SquaredDifference
3232

bfit/greedy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import numpy as np
2828
from scipy.optimize import nnls
2929

30-
from bfit.fit import KLDivergenceFPI, ScipyFit, _BaseFit
30+
from bfit.fit import _BaseFit, KLDivergenceFPI, ScipyFit
3131
from bfit.measure import SquaredDifference
3232
from bfit.model import AtomicGaussianDensity
3333

bfit/test/test_greedy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
import numpy.testing as npt
2727

2828
from bfit.greedy import (
29-
GreedyKLFPI,
30-
GreedyLeastSquares,
3129
get_next_choices,
3230
get_two_next_choices,
31+
GreedyKLFPI,
32+
GreedyLeastSquares,
3333
pick_two_lose_one,
3434
remove_redundancies,
3535
)

bfit/test/test_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import numpy as np
2626
from numpy.testing import assert_almost_equal, assert_raises
2727

28-
from bfit.grid import ClenshawRadialGrid, CubicGrid, UniformRadialGrid, _BaseRadialGrid
28+
from bfit.grid import _BaseRadialGrid, ClenshawRadialGrid, CubicGrid, UniformRadialGrid
2929

3030

3131
def test_raises_base():

docs/conf.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@
2929
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3030
# ones.
3131
extensions = [
32-
'sphinx.ext.napoleon',
33-
'sphinx.ext.autodoc',
34-
'sphinx.ext.todo',
35-
'sphinx.ext.mathjax',
36-
'sphinx.ext.viewcode',
37-
'sphinx.ext.githubpages',
38-
'numpydoc',
32+
"sphinx.ext.napoleon",
33+
"sphinx.ext.autodoc",
34+
"sphinx.ext.todo",
35+
"sphinx.ext.mathjax",
36+
"sphinx.ext.viewcode",
37+
"sphinx.ext.githubpages",
38+
"numpydoc",
3939
# 'sphinx.ext.autosummary',
40-
'sphinx.ext.doctest',
40+
"sphinx.ext.doctest",
4141
# for adding “copy to clipboard” buttons to all text/code boxes
42-
'sphinx_copybutton',
43-
'autoapi.extension',
44-
'nbsphinx',
45-
#'sphinxcontrib.bibtex'
42+
"sphinx_copybutton",
43+
"autoapi.extension",
44+
"nbsphinx",
45+
# 'sphinxcontrib.bibtex',
4646
]
4747

4848
# Add any paths that contain templates here, relative to this directory.

examples/atomdb_db.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,29 @@
1111
import numpy as np
1212
from atomdb import load
1313

14-
from bfit.density import SlaterAtoms
15-
from bfit.fit import KLDivergenceFPI, ScipyFit
14+
from bfit.fit import KLDivergenceFPI
1615
from bfit.grid import ClenshawRadialGrid
17-
from bfit.measure import KLDivergence
1816
from bfit.model import AtomicGaussianDensity
1917
from bfit.parse_ugbs import get_ugbs_exponents
2018

19+
# change the path to the location of the AtomDB data as needed
20+
DATAPATH = ("/home/ali-tehrani/SoftwareProjects/AtomDBdata",)
21+
2122
results_final = {}
2223
atoms = ["H", "C", "N", "O", "F", "P", "S", "Cl"]
23-
atomic_numbs = [1, 6, 7, 8, 9, 15, 16, 17] #[1 + i for i in range(0, len(atoms))]
24+
atomic_numbs = [1, 6, 7, 8, 9, 15, 16, 17] # [1 + i for i in range(0, len(atoms))]
2425
mult = [2, 3, 4, 3, 2, 4, 3, 2]
2526
for k, element in enumerate(atoms):
2627
print("Start Atom %s" % element)
2728

2829
# Construct a integration grid
2930
atomic_numb = atomic_numbs[k]
3031
grid = ClenshawRadialGrid(
31-
atomic_numb, num_core_pts=10000, num_diffuse_pts=899, include_origin=True#, extra_pts=[50,75,100],
32+
atomic_numb,
33+
num_core_pts=10000,
34+
num_diffuse_pts=899,
35+
include_origin=True,
36+
# extra_pts=[50,75,100],
3237
)
3338

3439
# Initial Guess constructed from UGBS
@@ -41,15 +46,19 @@
4146
e_0 = np.array(exps_s + exps_p) * 2.0
4247

4348
# Construct Atomic Density and Fitting Object
44-
#density = SlaterAtoms(element=element).atomic_density(grid.points)
49+
# density = SlaterAtoms(element=element).atomic_density(grid.points)
4550
# Use AtomDB to calculate the density
46-
atom = load(elem=element, charge=0, mult=mult[k], dataset="hci", datapath="/home/ali-tehrani/SoftwareProjects/AtomDBdata")
51+
atom = load(
52+
elem=element,
53+
charge=0,
54+
mult=mult[k],
55+
dataset="hci",
56+
datapath=DATAPATH,
57+
)
4758

4859
dens = atom.dens_func()
4960
density = dens(grid.points)
5061

51-
import matplotlib.pyplot as plt
52-
5362
# plt.plot(grid.points, density, "bo-")
5463
# plt.show()
5564
print(density[-1], grid.points[-1], grid.points[0:3])
@@ -69,7 +78,9 @@
6978
# measure = KLDivergence(mask_value=1e-18)
7079
# fit_KL_slsqp = ScipyFit(grid, density, model, measure=measure, method="SLSQP", spherical=True)
7180
# # Run the SLSQP optimization algorithm
72-
# results = fit_KL_slsqp.run(coeffs, e_0, maxiter=10000, disp=True, with_constraint=True, tol=1e-14)
81+
# results = fit_KL_slsqp.run(
82+
# coeffs, e_0, maxiter=10000, disp=True, with_constraint=True, tol=1e-14
83+
# )
7384

7485
print("KL-FPI INFO")
7586
print("-----------")

examples/table/table_3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010

1111
from bfit.density import SlaterAtoms
12-
from bfit.fit import KLDivergenceFPI, ScipyFit
12+
from bfit.fit import ScipyFit
1313
from bfit.grid import ClenshawRadialGrid
1414
from bfit.measure import KLDivergence
1515
from bfit.model import AtomicGaussianDensity

pyproject.toml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,6 @@ line-length = 100
127127
# )
128128
# '''
129129

130-
[tool.isort]
131-
profile = "black"
132-
known_first_party = ["bfit"]
133-
# If you need to exclude files from having their imports sorted
134-
#extend_skip_glob = [
135-
# "bfit/somefile.py",
136-
# "bfit/somedir/*",
137-
#]
138-
139130
# https://beta.ruff.rs/docs
140131
[tool.ruff]
141132
line-length = 100
@@ -329,4 +320,3 @@ disable=[
329320
"no-else-return",
330321
"too-many-statements",
331322
]
332-

tox.ini

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ commands =
2626
ignore_errors = true
2727

2828
[testenv:linters]
29+
ignore_errors = true
30+
# allow for linters to fail
31+
# ignore_outcome = true
2932
deps =
3033
numpy
3134
scipy
@@ -39,15 +42,13 @@ deps =
3942
# black
4043
bandit
4144
commands =
42-
flake8 bfit/ bfit/test
45+
python -m flake8 --config=tox.ini bfit/ bfit/test
4346
pylint bfit --rcfile=pyproject.toml --disable=similarities
4447
# black -l 100 --check ./
4548
# black -l 100 --diff ./
4649
# Use bandit configuration file
4750
bandit -r bfit -c .bandit.yml
4851

49-
ignore_errors = true
50-
5152
[testenv:coverage-report]
5253
deps = coverage>=4.2
5354
skip_install = true
@@ -93,8 +94,10 @@ exclude =
9394
.eggs,
9495

9596
max-line-length = 100
96-
import-order-style = google
97-
ignore =
97+
; import-order-style = google
98+
import-order-style = smarkets
99+
application-import-names = bfit
100+
extend-ignore =
98101
# E121 : continuation line under-indented for hanging indent
99102
E121,
100103
# E123 : closing bracket does not match indentation of opening bracket’s line
@@ -191,3 +194,4 @@ source =
191194
bfit
192195
.tox/*/lib/python*/site-packages/bfit
193196
.tox/pypy*/site-packages/bfit
197+

0 commit comments

Comments
 (0)