diff --git a/.gitignore b/.gitignore index 4cdd979..1aa874f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,163 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class -# Ignore (in-place) build results -*.pyc +# C extensions +*.so -# Ignore PyCharm -.idea +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +doc/_build/ +doc/html/ +doc/latex/ +doc/man/ +doc/xml/ +doc/source +doc/modules + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +# Editor junk +tags +[._]*.s[a-v][a-z] +[._]*.sw[a-p] +[._]s[a-v][a-z] +[._]sw[a-p] +*~ +\#*\# +.\#* +.ropeproject +.idea/ +.spyderproject +.spyproject +.vscode/ +# Mac .DS_Store +.DS_Store + +# jupyter notebook checkpoints +.ipynb_checkpoints + +# codecov files +*.gcno +*.gcda +*.gcov + +*/*/_build +*/_build diff --git a/bfit/__init__.py b/bfit/__init__.py index af9a036..0aea2e7 100644 --- a/bfit/__init__.py +++ b/bfit/__init__.py @@ -22,9 +22,9 @@ # --- r"""Package for fitting densities to a linear combination of Gaussians.""" +from bfit.density import * from bfit.fit import * +from bfit.greedy import * from bfit.grid import * -from bfit.model import * -from bfit.density import * from bfit.measure import * -from bfit.greedy import * +from bfit.model import * diff --git a/bfit/_slater.py b/bfit/_slater.py index 634b416..5c9788f 100644 --- a/bfit/_slater.py +++ b/bfit/_slater.py @@ -26,7 +26,6 @@ import numpy as np - __all__ = ["load_slater_wfn"] @@ -127,7 +126,7 @@ def _get_number_of_electrons_per_orbital(configuration): for x in orbitals: if x in electron_config_list: index = electron_config_list.index(x) - orbital = (electron_config_list[index: index + 2]) + orbital = electron_config_list[index : index + 2] if orbital[1] == "D" or orbital[1] == "F": num_electrons = re.search(orbital + r"\((.*?)\)", electron_config_list).group(1) diff --git a/bfit/density.py b/bfit/density.py index ad92da5..564c9e9 100644 --- a/bfit/density.py +++ b/bfit/density.py @@ -22,10 +22,10 @@ # --- r"""Slater Atomic Density Module.""" -from bfit._slater import load_slater_wfn import numpy as np from scipy.special import factorial +from bfit._slater import load_slater_wfn __all__ = ["SlaterAtoms"] diff --git a/bfit/fit.py b/bfit/fit.py index a592bdb..c72a675 100644 --- a/bfit/fit.py +++ b/bfit/fit.py @@ -22,13 +22,13 @@ # --- r"""Fitting Algorithms.""" -from timeit import default_timer as timer import warnings +from timeit import default_timer as timer -from bfit.measure import KLDivergence, Measure, SquaredDifference import numpy as np -from scipy.optimize import minimize, NonlinearConstraint +from scipy.optimize import NonlinearConstraint, minimize +from bfit.measure import KLDivergence, Measure, SquaredDifference __all__ = ["KLDivergenceFPI", "ScipyFit"] diff --git a/bfit/greedy.py b/bfit/greedy.py index c612129..ae72984 100644 --- a/bfit/greedy.py +++ b/bfit/greedy.py @@ -24,12 +24,13 @@ from abc import ABCMeta, abstractmethod -from bfit.fit import _BaseFit, KLDivergenceFPI, ScipyFit -from bfit.measure import SquaredDifference -from bfit.model import AtomicGaussianDensity import numpy as np from scipy.optimize import nnls +from bfit.fit import KLDivergenceFPI, ScipyFit, _BaseFit +from bfit.measure import SquaredDifference +from bfit.model import AtomicGaussianDensity + __all__ = ["GreedyLeastSquares", "GreedyKLFPI"] @@ -801,6 +802,7 @@ def optimize_using_nnls(true_dens, cofactor_matrix): row_nnls_coefficients = nnls(cofactor_matrix, b_vector) return row_nnls_coefficients[0] + # pylint: disable=arguments-differ def get_optimization_routine(self, params, local=False): r"""Optimize least-squares using nnls and scipy.optimize from ScipyFit.""" # First solves the optimal coefficients (while exponents are fixed) using NNLS. @@ -946,6 +948,7 @@ def get_best_one_function_solution(self): exps = 3. * self.integral_dens / (2. * 4. * np.pi * denom) return np.array([self.integral_dens, exps]) + # pylint: disable=arguments-differ def get_optimization_routine(self, params, local=False): r"""Optimize KL using KL-FPI method.""" coeffs, exps = params[:len(params)//2], params[len(params)//2:] diff --git a/bfit/measure.py b/bfit/measure.py index 8deaa7a..776ed7c 100644 --- a/bfit/measure.py +++ b/bfit/measure.py @@ -26,7 +26,6 @@ import numpy as np - __all__ = ["SquaredDifference", "KLDivergence", "TsallisDivergence"] diff --git a/bfit/test/test_density.py b/bfit/test/test_density.py index 1b76a7d..0952c65 100644 --- a/bfit/test/test_density.py +++ b/bfit/test/test_density.py @@ -22,11 +22,12 @@ # --- r"""Test bfit.density module.""" -from bfit.density import SlaterAtoms -from bfit.grid import ClenshawRadialGrid import numpy as np -from numpy.testing import assert_almost_equal, assert_equal, assert_raises import scipy +from numpy.testing import assert_almost_equal, assert_equal, assert_raises + +from bfit.density import SlaterAtoms +from bfit.grid import ClenshawRadialGrid def slater(e, n, r, derivative=False): diff --git a/bfit/test/test_fit.py b/bfit/test/test_fit.py index d72adfe..80c43f9 100644 --- a/bfit/test/test_fit.py +++ b/bfit/test/test_fit.py @@ -22,12 +22,13 @@ # --- r"""Test bfit.fit module.""" +import numpy as np +from numpy.testing import assert_almost_equal, assert_equal, assert_raises + from bfit.fit import KLDivergenceFPI, ScipyFit from bfit.grid import CubicGrid, UniformRadialGrid from bfit.measure import KLDivergence, SquaredDifference from bfit.model import AtomicGaussianDensity, MolecularGaussianDensity -import numpy as np -from numpy.testing import assert_almost_equal, assert_equal, assert_raises def test_lagrange_multiplier(): diff --git a/bfit/test/test_greedy.py b/bfit/test/test_greedy.py index 49e5317..beed48a 100644 --- a/bfit/test/test_greedy.py +++ b/bfit/test/test_greedy.py @@ -22,13 +22,18 @@ # --- r"""Test file for 'bfit.greedy'.""" +import numpy as np +import numpy.testing as npt + from bfit.greedy import ( - get_next_choices, get_two_next_choices, GreedyKLFPI, - GreedyLeastSquares, pick_two_lose_one, remove_redundancies + GreedyKLFPI, + GreedyLeastSquares, + get_next_choices, + get_two_next_choices, + pick_two_lose_one, + remove_redundancies, ) from bfit.grid import UniformRadialGrid -import numpy as np -import numpy.testing as npt def test_check_redundancies(): diff --git a/bfit/test/test_grid.py b/bfit/test/test_grid.py index 57eee8a..3c4ee39 100644 --- a/bfit/test/test_grid.py +++ b/bfit/test/test_grid.py @@ -22,10 +22,11 @@ # --- r"""Test bfit.grid module.""" -from bfit.grid import _BaseRadialGrid, ClenshawRadialGrid, CubicGrid, UniformRadialGrid import numpy as np from numpy.testing import assert_almost_equal, assert_raises +from bfit.grid import ClenshawRadialGrid, CubicGrid, UniformRadialGrid, _BaseRadialGrid + def test_raises_base(): r"""Test _BaseRadialGrid raises errors.""" diff --git a/bfit/test/test_measure.py b/bfit/test/test_measure.py index 7a923ad..a8b5571 100644 --- a/bfit/test/test_measure.py +++ b/bfit/test/test_measure.py @@ -22,10 +22,11 @@ # --- r"""Test bfit.measure module.""" -from bfit.measure import KLDivergence, SquaredDifference, TsallisDivergence import numpy as np from numpy.testing import assert_almost_equal, assert_raises +from bfit.measure import KLDivergence, SquaredDifference, TsallisDivergence + def test_raises_kl(): r"""Test raise error when using Kullback-Leibler.""" @@ -193,8 +194,8 @@ def test_evaluating_tsallis_derivative_against_finite_difference(): _, actual_deriv = measure.evaluate(dens, model, deriv=True) measure_pt_plus_1 = measure.evaluate(dens, model + eps, deriv=False) measure_pt_plus_2 = measure.evaluate(dens, model + 2.0 * eps, deriv=False) - desired = (measure_pt_minus_2 / 12.0 - (2.0 / 3.0) * measure_pt_minus_1) - desired += ((2.0 / 3.0) * measure_pt_plus_1 - measure_pt_plus_2 / 12.0) + desired = measure_pt_minus_2 / 12.0 - (2.0 / 3.0) * measure_pt_minus_1 + desired += (2.0 / 3.0) * measure_pt_plus_1 - measure_pt_plus_2 / 12.0 assert_almost_equal(actual_deriv, desired / eps, decimal=1) diff --git a/bfit/test/test_model.py b/bfit/test/test_model.py index cbccf4c..dba11f8 100644 --- a/bfit/test/test_model.py +++ b/bfit/test/test_model.py @@ -22,11 +22,12 @@ # --- r"""Test bfit.model module.""" -from bfit.grid import CubicGrid, UniformRadialGrid -from bfit.model import AtomicGaussianDensity, MolecularGaussianDensity import numpy as np from numpy.testing import assert_almost_equal, assert_equal, assert_raises +from bfit.grid import CubicGrid, UniformRadialGrid +from bfit.model import AtomicGaussianDensity, MolecularGaussianDensity + def test_raises_gaussian_model(): r"""Test raises error of all Gaussian model classes.""" diff --git a/bfit/test/test_slater.py b/bfit/test/test_slater.py index 6700b4e..82d0332 100644 --- a/bfit/test/test_slater.py +++ b/bfit/test/test_slater.py @@ -22,9 +22,10 @@ # --- r"""Test bfit._slater module.""" -from bfit._slater import load_slater_wfn import numpy as np +from bfit._slater import load_slater_wfn + def test_parsing_slater_density_be(): r"""Test correct parsing of beryllium Slater file.""" diff --git a/docs/conf.py b/docs/conf.py index 608586c..1e90644 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -12,6 +12,7 @@ # import os import sys + sys.path.insert(0, os.path.abspath('../')) diff --git a/examples/atomdb_db.py b/examples/atomdb_db.py index b0a0831..da48b36 100644 --- a/examples/atomdb_db.py +++ b/examples/atomdb_db.py @@ -9,14 +9,14 @@ at each iteration. """ import numpy as np +from atomdb import load from bfit.density import SlaterAtoms -from bfit.fit import ScipyFit,KLDivergenceFPI +from bfit.fit import KLDivergenceFPI, ScipyFit from bfit.grid import ClenshawRadialGrid -from bfit.model import AtomicGaussianDensity from bfit.measure import KLDivergence +from bfit.model import AtomicGaussianDensity from bfit.parse_ugbs import get_ugbs_exponents -from atomdb import load results_final = {} atoms = ["H", "C", "N", "O", "F", "P", "S", "Cl"] @@ -49,6 +49,7 @@ density = dens(grid.points) import matplotlib.pyplot as plt + # plt.plot(grid.points, density, "bo-") # plt.show() print(density[-1], grid.points[-1], grid.points[0:3]) diff --git a/examples/table/table_1_and_2.py b/examples/table/table_1_and_2.py index 313f181..7c4bc2d 100644 --- a/examples/table/table_1_and_2.py +++ b/examples/table/table_1_and_2.py @@ -16,7 +16,6 @@ from bfit.model import AtomicGaussianDensity from bfit.parse_ugbs import get_ugbs_exponents - results_final = {} atoms = ["h", "he", "li", "be", "b", "c", "n", "o", "f", "ne", "na", "mg", "al", "si", "p", "s", "cl", "ar", "k", "ca", diff --git a/examples/table/table_3.py b/examples/table/table_3.py index 6185fc7..1e01478 100644 --- a/examples/table/table_3.py +++ b/examples/table/table_3.py @@ -9,13 +9,12 @@ import numpy as np from bfit.density import SlaterAtoms -from bfit.fit import ScipyFit, KLDivergenceFPI +from bfit.fit import KLDivergenceFPI, ScipyFit from bfit.grid import ClenshawRadialGrid from bfit.measure import KLDivergence from bfit.model import AtomicGaussianDensity from bfit.parse_ugbs import get_ugbs_exponents - for atomic_numb, element in [ (2, "he"), (4, "be"), diff --git a/examples/table/table_4.py b/examples/table/table_4.py index 34d5ed8..34abf09 100644 --- a/examples/table/table_4.py +++ b/examples/table/table_4.py @@ -12,10 +12,10 @@ import numpy as np from bfit.density import SlaterAtoms +from bfit.fit import ScipyFit from bfit.grid import ClenshawRadialGrid -from bfit.model import AtomicGaussianDensity from bfit.measure import SquaredDifference -from bfit.fit import ScipyFit +from bfit.model import AtomicGaussianDensity from bfit.parse_ugbs import get_ugbs_exponents WITH_CONSTRAINT = False diff --git a/examples/table/table_5.py b/examples/table/table_5.py index 1e6ad2d..2031c30 100644 --- a/examples/table/table_5.py +++ b/examples/table/table_5.py @@ -15,7 +15,6 @@ from bfit.model import AtomicGaussianDensity from bfit.parse_ugbs import get_ugbs_exponents - for atomic_numb, element in [ (2, "he"), (4, "be"), diff --git a/pyproject.toml b/pyproject.toml index 560a627..82541aa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -297,3 +297,36 @@ skips = [ "B603", # Ignore subprocess call "B607", # Ignore subprocess call ] + +[tool.pylint.MASTER] +ignore-patterns = [ + "test_.*\\.py$", + ".*_test\\.py$" +] +ignore-paths = [ + "tests/.*", + ".*/tests/.*" +] + +[tool.pylint.messages_control] +# Pylint configuration +max-line-length = 100 +# ignore +# List of message identifiers to ignore, separated by a comma. +disable=[ + "fixme", # Disable fixme messages + "too-many-positional-arguments", # Disable too many positional arguments + "too-many-locals", # Disable too many locals + "too-many-instance-attributes", # Disable too many instance attributes + "too-many-positional-arguments", # Disable too many positional arguments + "missing-class-docstring", # Disable missing class docstring + "too-few-public-methods", # Disable too few public methods + "protected-access", # Disable protected access + "too-many-lines", # Disable too many lines + "possibly-used-before-assignment", + "too-many-branches", + "too-many-arguments", + "no-else-return", + "too-many-statements", +] + diff --git a/tox.ini b/tox.ini index 795663c..2b9d4eb 100644 --- a/tox.ini +++ b/tox.ini @@ -40,7 +40,7 @@ deps = bandit commands = flake8 bfit/ bfit/test - pylint bfit --rcfile=tox.ini --disable=similarities + pylint bfit --rcfile=pyproject.toml --disable=similarities # black -l 100 --check ./ # black -l 100 --diff ./ # Use bandit configuration file