Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bjmorgan/vasppy
Browse files Browse the repository at this point in the history
  • Loading branch information
bjmorgan committed Oct 6, 2023
2 parents 1362ce2 + 3cfe319 commit b5590c1
Show file tree
Hide file tree
Showing 71 changed files with 4,259 additions and 3,003 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
timeout-minutes: 30
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ['3.9', '3.10', '3.11']
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{matrix.python-version}}
Expand All @@ -26,16 +26,21 @@ jobs:
pip install types-PyYAML
pip install pytest
pip install pytest-cov
pip install pylint
pip install .
pip list
- name: Run tests
run: |
pytest --cov-config=.coveragerc --cov=vasppy --cov-report xml
- name: Publish code coverage
env:
CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_REPO_TOKEN }}
uses: paambaati/codeclimate-action@v2.7.5
pytest --cov-config=.coveragerc --cov=vasppy --cov-report lcov
- name: Coveralls GitHub Action
uses: coverallsapp/github-action@1.1.3
with:
path-to-lcov: ./coverage.lcov
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Static type checking
run: |
mypy vasppy
- name: PyLint
run: |
pylint --errors-only vasppy
8 changes: 8 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Ruff
on: [push, pull_request]
jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: chartboost/ruff-action@v1
27 changes: 27 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Read the Docs configuration file for Sphinx projects
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.11"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/source/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
python:
install:
- requirements: docs/requirements.txt
41 changes: 41 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
select = ["E", "F", "B"]
ignore = ["E501", "E741", "B905"] # B905 valid for 3.10 onwards

# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = ["A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM", "ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF", "SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"]
unfixable = []

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".mypy_cache",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
]

# Same as Black.
line-length = 88

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.9.
target-version = "py39"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

[![DOI](https://zenodo.org/badge/17946870.svg)](https://zenodo.org/badge/latestdoi/17946870)
[![PyPI version](https://badge.fury.io/py/vasppy.svg)](https://badge.fury.io/py/vasppy)
[![Build Status](https://travis-ci.org/bjmorgan/vasppy.svg?branch=master)](https://travis-ci.org/bjmorgan/vasppy)
[![Test Coverage](https://codeclimate.com/github/bjmorgan/vasppy/badges/coverage.svg)](https://codeclimate.com/github/bjmorgan/vasppy/coverage)
[![Build Status](https://github.com/bjmorgan/vasppy/actions/workflows/build.yml/badge.svg)](https://github.com/bjmorgan/vasppy/actions/workflows/build.yml)
[![Coverage Status](https://coveralls.io/repos/github/bjmorgan/vasppy/badge.svg?branch=main)](https://coveralls.io/github/bjmorgan/vasppy?branch=main)
[![Documentation Status](https://readthedocs.org/projects/vasppy/badge/?version=latest)](http://vasppy.readthedocs.io/en/latest/?badge=latest)

`vasppy` is a suite of Python tools and scripts written in Python for manipulating and processing [VASP](https://www.vasp.at/) input and output files.

## Tests

Automated testing of the latest build happens [here](https://travis-ci.org/bjmorgan/vasppy).
Automated testing of the latest build happens [here](https://github.com/bjmorgan/vasppy/actions/workflows/build.yml)

Manual tests can be run using
```
Expand Down
3 changes: 2 additions & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Sphinx>=1.6.3
Sphinx~=6.2.1
nbsphinx
jupyter
git+https://github.com/bjmorgan/figure_formatting.git
-r ../requirements.txt
124 changes: 66 additions & 58 deletions docs/source/examples/rdfs.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
numpy>=1.16.2
numpy>=1.20
monty
pandas
pymatgen
pymatgen>=2023.6.28
PyYAML
fortranformat
scipy>=1.4.1
Expand Down
10 changes: 4 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

scripts = ['check_species',
'checkforce',
'convergence_testing',
'murnfit',
'vasp_summary',
'poscar_to_cif',
Expand All @@ -18,7 +19,6 @@
'fat_bands',
'pimaim_to_poscar',
'pimaim_to_xtl',
'poscar_sort',
'poscar_to_pimaim',
'poscar_to_xtl',
'proc_poscar',
Expand Down Expand Up @@ -46,15 +46,13 @@
'{} = vasppy.scripts.{}:main'.format(s, s) for s in scripts]},
license='MIT',
install_requires=['monty',
'numpy>=1.16.2',
'numpy>=1.20',
'pandas',
'pymatgen>=2022.0.0',
'pymatgen>=2023.6.28',
'PyYAML',
'coverage==4.3.4',
'codeclimate-test-reporter',
'fortranformat',
'scipy>=1.4.1',
'tqdm',
'lxml'],
python_requires='>=3.7'
python_requires='>=3.9'
)
17 changes: 9 additions & 8 deletions tests/test_atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@

from vasppy.atom import Atom

class AtomTestCase( unittest.TestCase ):

def test_init_atom( self ):
label = 'A'
r = np.array( [ 0.1, 0.2, 0.3 ] )
atom = Atom( label=label, r=r )
self.assertEqual( atom.label, label )
np.testing.assert_array_equal( atom.r, r )
class AtomTestCase(unittest.TestCase):
def test_init_atom(self):
label = "A"
r = np.array([0.1, 0.2, 0.3])
atom = Atom(label=label, r=r)
self.assertEqual(atom.label, label)
np.testing.assert_array_equal(atom.r, r)

if __name__ == '__main__':

if __name__ == "__main__":
unittest.main()
52 changes: 28 additions & 24 deletions tests/test_band.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,45 @@

from vasppy.band import Band, handle_occupancy

class BandTestCase( unittest.TestCase ):

class BandTestCase(unittest.TestCase):
"""Tests for procar.Band class"""

def test_band_is_initialised( self ):
def test_band_is_initialised(self):
"""Test Band object is initialised"""
index = 2
energy = 1.0
occupancy = 0.5
with patch( 'vasppy.band.handle_occupancy' ) as mock_handle_occupancy:
with patch("vasppy.band.handle_occupancy") as mock_handle_occupancy:
mock_handle_occupancy.return_value = 0.5
band = Band( index=index, energy=energy, occupancy=occupancy )
self.assertEqual( index, band.index )
self.assertEqual( energy, band.energy )
self.assertEqual( occupancy, band.occupancy )
mock_handle_occupancy.assert_has_calls( [call(0.5, negative_occupancies='warn')] )
band = Band(index=index, energy=energy, occupancy=occupancy)
self.assertEqual(index, band.index)
self.assertEqual(energy, band.energy)
self.assertEqual(occupancy, band.occupancy)
mock_handle_occupancy.assert_has_calls([call(0.5, negative_occupancies="warn")])

def test_handle_occupancy_raises_valuerror_if_negative_occupancies_is_invalid_keyword(
self,
):
with self.assertRaises(ValueError):
handle_occupancy(0.5, negative_occupancies="foo")

def test_handle_occupancy_raises_valuerror_if_negative_occupancies_is_invalid_keyword( self ):
with self.assertRaises( ValueError ):
handle_occupancy( 0.5, negative_occupancies='foo' )
def test_handle_occupancy_warns_about_negative_occupancies(self):
with warnings.catch_warnings(record=True) as w:
handle_occupancy(-0.1, negative_occupancies="warn")
self.assertEqual(len(w), 1)
self.assertTrue("negative" in str(w[-1].message))

def test_handle_occupancy_warns_about_negative_occupancies( self ):
with warnings.catch_warnings( record=True ) as w:
handle_occupancy( -0.1, negative_occupancies='warn' )
self.assertEqual( len(w), 1 )
self.assertTrue( "negative" in str(w[-1].message) )
def test_handle_occupancy_raises_exception_if_negative_occupancies_is_raise(self):
with self.assertRaises(ValueError):
handle_occupancy(-0.1, negative_occupancies="raise")

def test_handle_occupancy_raises_exception_if_negative_occupancies_is_raise( self ):
with self.assertRaises( ValueError ):
handle_occupancy( -0.1, negative_occupancies='raise' )
def test_handle_occupancy_if_negative_occupancies_is_ignore(self):
self.assertEqual(handle_occupancy(-0.1, negative_occupancies="ignore"), -0.1)

def test_handle_occupancy_if_negative_occupancies_is_ignore( self ):
self.assertEqual( handle_occupancy( -0.1, negative_occupancies='ignore' ), -0.1 )
def test_handle_occupancy_zeros_occupancies_if_negative_occupancies_is_zero(self):
self.assertEqual(handle_occupancy(-0.1, negative_occupancies="zero"), 0.0)

def test_handle_occupancy_zeros_occupancies_if_negative_occupancies_is_zero( self ):
self.assertEqual( handle_occupancy( -0.1, negative_occupancies='zero' ), 0.0 )

if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
Loading

0 comments on commit b5590c1

Please sign in to comment.