From 5bb04fa952c7f975577695e648d67e700304d82c Mon Sep 17 00:00:00 2001 From: wolearyc Date: Sun, 28 Jul 2024 21:16:37 -0700 Subject: [PATCH] updated workflow, added badges --- .github/workflows/python-package.yml | 7 +++- .pre-commit-config.yaml | 11 +++++- README.md | 8 +++++ README.rst | 8 ----- ramannoodle/__init__.py | 48 -------------------------- ramannoodle/io/vasp/__init__.py | 2 -- ramannoodle/io/vasp/vasp_utils.py | 2 +- ramannoodle/polarizability/__init__.py | 2 -- ramannoodle/spectrum/__init__.py | 2 -- ramannoodle/symmetry/__init__.py | 3 +- ramannoodle/symmetry/symmetry_utils.py | 2 +- reports/coverage-badge.svg | 1 + reports/junit/junit.xml | 1 + reports/tests-badge.svg | 1 + requirements.txt | 1 + test/tests/test_vasp.py | 26 +++++--------- 16 files changed, 39 insertions(+), 86 deletions(-) create mode 100644 README.md delete mode 100644 README.rst create mode 100644 reports/coverage-badge.svg create mode 100644 reports/junit/junit.xml create mode 100644 reports/tests-badge.svg diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 495c31a..8e53fbb 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -1,7 +1,7 @@ # This workflow will install Python dependencies, lint, and run tests with a variety of Python versions # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python -name: Python package +name: Test and Lint on: push: @@ -31,6 +31,11 @@ jobs: - name: Analyzing the code with pylint run: | pylint $(git ls-files '*.py') + - name: Analyzing the code with flake8 + uses: py-actions/flake8@v2 + with: + max-line-length: "88" + plugins: "flake8-bugbear==24.4.26" - name: Test with pytest run: | pytest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 20e96c4..21e6a2b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ # See https://pre-commit.com for more information # See https://pre-commit.com/hooks.html for more hooks ci: - skip: [pylint] + skip: [pylint,flake8] exclude: EPS_OUTCAR repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -40,3 +40,12 @@ repos: [ pytest, ] +- repo: https://github.com/pycqa/flake8 + rev: '7.1.0' # pick a git hash / tag to point to + hooks: + - id: flake8 + args: [--max-line-length=88] + additional_dependencies: + [ + flake8-bugbear + ] diff --git a/README.md b/README.md new file mode 100644 index 0000000..6776dbf --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +ramannoodle +=========== +[![python](https://img.shields.io/badge/Python-3.12-3776AB.svg?style=flat&logo=python&logoColor=white)](https://www.python.org) [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) [![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/) [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/license/mit) + +![Tests](reports/tests-badge.svg) + + +`ramannoodle` helps you calculate Raman spectra quickly and efficiency based on VASP calculations. **This software is currently being completely overhauled.** Check out the `legacy` branch for the old (and functional!) version. diff --git a/README.rst b/README.rst deleted file mode 100644 index 5a165e0..0000000 --- a/README.rst +++ /dev/null @@ -1,8 +0,0 @@ -ramannoodle -======================================= - -Calculates Raman spectra from VASP calculations. - -This tool is currently being completely overhauled. - -Check out the `legacy`` branch for the old version. diff --git a/ramannoodle/__init__.py b/ramannoodle/__init__.py index ee992d5..e69de29 100644 --- a/ramannoodle/__init__.py +++ b/ramannoodle/__init__.py @@ -1,48 +0,0 @@ -""" -Sample includes: - -from dynamics import Phonons -from dynamics import MDTrajectory - -from spectrum import RamanSpectrum -from spectrum import VibrationalSpectrum - -from spectrometer import RamanSpectrometer -from spectrometer import VibrationalSpectrometer - -from spectrum.phonons import PhononRamanSpectrum -from spectrum.md import MDRamanSpectrum - -from polarizability import PolarizabilityModel - -from polarizability.taylor import LinearPolarizabilityModel - - -Workflow: - -1. Create a Dynamics object from your simulations. - -2. Create an InterpolationPolarizabilityModel from your simulations. -- Set up a Symmetry object from an OUTCAR -- Set up a model for that symmetry -- Insert DOF, a set of displacements and polarizabilities (e.g. +,-, -polarizability_plus,polarizability_minus) - - Check that displacements given are colinear. - - That that the new displacements are orthogonal to all existing displacements - - If checks are successful: - - Generate all symmetry equivalent displacements. - - Do sanity check to ensure we're still totally orthogonal - - add interpolation and normalized dof displacements - -Run a virtual experiment -- Specify RamanSettings (angle, polycrystalline) -- dynamics.get_spectrum(PolarizabilityModel, SpectrometerSettings) -> RamanSpectrum - -Extract Relevant information from RamanSpectrum -- Spectrum.get_intensities(temperature, correction factors, smearing, etc.) -- Spectrum.get_wavenumbers() -- - -For now, I will not implement SpectrometerSettings. This can wait. - -""" diff --git a/ramannoodle/io/vasp/__init__.py b/ramannoodle/io/vasp/__init__.py index 8533189..6a004c0 100644 --- a/ramannoodle/io/vasp/__init__.py +++ b/ramannoodle/io/vasp/__init__.py @@ -1,7 +1,6 @@ """Utilities for VASP.""" from pathlib import Path -from typing import TextIO import numpy as np from numpy.typing import NDArray @@ -9,7 +8,6 @@ from ...symmetry import StructuralSymmetry from ...globals import ATOMIC_WEIGHTS, ATOMIC_NUMBERS from .vasp_utils import ( - _get_atomic_symbol_from_potcar_line, _read_atomic_symbols_from_outcar, _read_eigenvector_from_outcar, _read_cartesian_positions_from_outcar, diff --git a/ramannoodle/io/vasp/vasp_utils.py b/ramannoodle/io/vasp/vasp_utils.py index 76fd4a9..028a4a9 100644 --- a/ramannoodle/io/vasp/vasp_utils.py +++ b/ramannoodle/io/vasp/vasp_utils.py @@ -104,7 +104,7 @@ def _read_polarizability_from_outcar(outcar_file: TextIO) -> NDArray[np.float64] def _get_lattice_vector_from_outcar_line(line: str) -> NDArray[np.float64]: - """e.g. "11.823066970 0.000000000 0.000000000 0.084580423 0.000000000 0.000000000" """ + """Extracts lattice vector from an appropriate line from an outcar""" return np.array([float(item) for item in line.split()[0:3]]) diff --git a/ramannoodle/polarizability/__init__.py b/ramannoodle/polarizability/__init__.py index d2ade47..005b89b 100644 --- a/ramannoodle/polarizability/__init__.py +++ b/ramannoodle/polarizability/__init__.py @@ -5,12 +5,10 @@ import numpy as np from numpy.typing import NDArray from scipy.interpolate import make_interp_spline, BSpline -import spglib from . import polarizability_utils from ..symmetry.symmetry_utils import is_orthogonal_to_all from ..symmetry import StructuralSymmetry -from ..exceptions import InvalidDOFException, SymmetryException class PolarizabilityModel(ABC): # pylint: disable=too-few-public-methods diff --git a/ramannoodle/spectrum/__init__.py b/ramannoodle/spectrum/__init__.py index 9b347d0..bcc95b6 100644 --- a/ramannoodle/spectrum/__init__.py +++ b/ramannoodle/spectrum/__init__.py @@ -1,7 +1,5 @@ """Spectra.""" -from abc import ABC, abstractmethod - import numpy as np from numpy.typing import NDArray diff --git a/ramannoodle/symmetry/__init__.py b/ramannoodle/symmetry/__init__.py index 453e80e..d0a6851 100644 --- a/ramannoodle/symmetry/__init__.py +++ b/ramannoodle/symmetry/__init__.py @@ -2,11 +2,10 @@ import numpy as np from numpy.typing import NDArray -from scipy.interpolate import make_interp_spline, BSpline import spglib from . import symmetry_utils -from ..exceptions import InvalidDOFException, SymmetryException +from ..exceptions import SymmetryException class StructuralSymmetry: diff --git a/ramannoodle/symmetry/symmetry_utils.py b/ramannoodle/symmetry/symmetry_utils.py index 0682e26..fc152fa 100644 --- a/ramannoodle/symmetry/symmetry_utils.py +++ b/ramannoodle/symmetry/symmetry_utils.py @@ -89,7 +89,7 @@ def get_fractional_positions_permutation_matrix( def transform_fractional_positions( positions: NDArray[np.float64], rotation: NDArray[np.float64], - translation: NDArray[np.float64] = np.array([0.0, 0.0, 0.0]), + translation: NDArray[np.float64], ) -> NDArray[np.float64]: """Transforms fractional coordinates and applies periodic boundary conditions.""" diff --git a/reports/coverage-badge.svg b/reports/coverage-badge.svg new file mode 100644 index 0000000..b2c9504 --- /dev/null +++ b/reports/coverage-badge.svg @@ -0,0 +1 @@ +coverage: 92.69%coverage92.69% diff --git a/reports/junit/junit.xml b/reports/junit/junit.xml new file mode 100644 index 0000000..5c9a029 --- /dev/null +++ b/reports/junit/junit.xml @@ -0,0 +1 @@ + diff --git a/reports/tests-badge.svg b/reports/tests-badge.svg new file mode 100644 index 0000000..f036f56 --- /dev/null +++ b/reports/tests-badge.svg @@ -0,0 +1 @@ +tests: 23tests23 diff --git a/requirements.txt b/requirements.txt index 3a9f042..423d9fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ +flake8 numpy pre-commit pylint diff --git a/test/tests/test_vasp.py b/test/tests/test_vasp.py index 5e68631..994956e 100644 --- a/test/tests/test_vasp.py +++ b/test/tests/test_vasp.py @@ -15,6 +15,8 @@ from .. import EPS_OUTCAR_NUM_ATOMS, PHONONS_OUTCAR_NUM_ATOMS +# pylint: disable=protected-access + @pytest.mark.parametrize( "outcar_path_fixture, known_num_atoms, known_wavenumbers," @@ -64,9 +66,7 @@ def test_load_phonons_from_outcar( ) def test_get_atomic_symbol_from_potcar_line(potcar_line: str, known: str) -> None: """test""" - result = vasp_utils._get_atomic_symbol_from_potcar_line( # pylint: disable=protected-access - potcar_line - ) + result = vasp_utils._get_atomic_symbol_from_potcar_line(potcar_line) assert result == known @@ -80,11 +80,7 @@ def test_read_atomic_symbols_from_outcar( known: list[str], ) -> None: """test""" - atomic_symbols = ( - vasp_utils._read_atomic_symbols_from_outcar( # pylint: disable=protected-access - outcar_file_fixture - ) - ) + atomic_symbols = vasp_utils._read_atomic_symbols_from_outcar(outcar_file_fixture) assert atomic_symbols == known @@ -105,7 +101,7 @@ def test_read_cartesian_positions_from_outcar( known_last_position: NDArray[np.float64], ) -> None: """test""" - cartesian_positions = vasp_utils._read_cartesian_positions_from_outcar( # pylint: disable=protected-access + cartesian_positions = vasp_utils._read_cartesian_positions_from_outcar( outcar_file_fixture, EPS_OUTCAR_NUM_ATOMS ) @@ -131,7 +127,7 @@ def test_read_fractional_positions_from_outcar( known_last_position: NDArray[np.float64], ) -> None: """test""" - fractional_positions = vasp_utils._read_fractional_positions_from_outcar( # pylint: disable=protected-access + fractional_positions = vasp_utils._read_fractional_positions_from_outcar( outcar_file_fixture, EPS_OUTCAR_NUM_ATOMS ) @@ -162,11 +158,7 @@ def test_read_polarizability_from_outcar( ) -> None: """test""" - polarizability = ( - vasp_utils._read_polarizability_from_outcar( # pylint: disable=protected-access - outcar_file_fixture - ) - ) + polarizability = vasp_utils._read_polarizability_from_outcar(outcar_file_fixture) assert np.isclose(polarizability, known_polarizability).all() @@ -201,7 +193,5 @@ def test_read_lattice_from_outcar( outcar_file_fixture: TextIO, known_lattice: NDArray[np.float64] ) -> None: """test""" - result = vasp_utils._read_lattice_from_outcar( # pylint: disable=protected-access - outcar_file_fixture - ) + result = vasp_utils._read_lattice_from_outcar(outcar_file_fixture) assert np.isclose(result, known_lattice).all()