Skip to content

Commit

Permalink
Apply linting to all of pymatgen unless excluded in setup.cfg.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Sep 15, 2019
1 parent e56f26d commit 5d9bf3d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ jobs:
pycodestyle pymatgen
echo "--- Done ---"
echo "flake8 checks..."
flake8 --count --select=E9,F63,F7,F82 --show-source --statistics pymatgen
flake8 --count --show-source --statistics pymatgen/core pymatgen/electronic_structure pymatgen/ext pymatgen/io pymatgen/transformations pymatgen/analysis
flake8 --count --show-source --statistics pymatgen
# exit-zero treats all errors as warnings.
flake8 --count --exit-zero --max-complexity=10 --statistics pymatgen
echo "--- Done ---"
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/pmg-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ jobs:
run: |
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 --count --select=E9,F63,F7,F82 --show-source --statistics pymatgen
flake8 --count --show-source --statistics pymatgen/core pymatgen/electronic_structure pymatgen/ext pymatgen/io pymatgen/transformations pymatgen/analysis
flake8 --count --show-source --statistics pymatgen
# exit-zero treats all errors as warnings.
flake8 --count --exit-zero --max-complexity=10 --statistics pymatgen
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ script:
- echo "It is highly recommended that you use the pre-commit hook provided in pymatgen (simply copy pre-commit to .git/hooks) to check before pushing your code."
- travis_wait 28800 pycodestyle pymatgen && mypy pymatgen && pytest $EXCLUDE_TESTS pymatgen
# Docstyle checks are enforced for files that have been modified since the v2019.9.12 tagged release.
- flake8 --count --select=E9,F63,F7,F82 --show-source --statistics pymatgen
- flake8 --count --show-source --statistics pymatgen/core pymatgen/electronic_structure pymatgen/ext pymatgen/io pymatgen/transformations pymatgen/analysis
- flake8 --count --show-source --statistics pymatgen
- flake8 --count --exit-zero --max-complexity=10 --statistics pymatgen
- export MODIFIED_FILES=`git diff --diff-filter=ACMRTUXB --name-only HEAD v2019.9.12 | grep -E 'pymatgen.*\.(py)$' | sed '/test_/d' | sed 'post_processors_abc/d' | tr '\n' ' '`
- pydocstyle --count pymatgen/core $MODIFIED_FILES
Expand Down
27 changes: 20 additions & 7 deletions pymatgen/phonon/bandstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Copyright (c) Pymatgen Development Team.
# Distributed under the terms of the MIT License.

"""
This module provides classes to define a phonon band structure.
"""

import collections
import numpy as np
Expand All @@ -11,10 +14,6 @@
from pymatgen.electronic_structure.bandstructure import Kpoint
from monty.json import MSONable

"""
This module provides classes to define a phonon band structure.
"""


def get_reasonable_repetitions(natoms):
"""
Expand Down Expand Up @@ -239,6 +238,9 @@ def asr_breaking(self, tol_eigendisplacements=1e-5):
return None

def as_dict(self):
"""
:return: MSONable dict
"""
d = {"@module": self.__class__.__module__,
"@class": self.__class__.__name__,
"lattice_rec": self.lattice_rec.as_dict(),
Expand All @@ -265,6 +267,10 @@ def as_dict(self):

@classmethod
def from_dict(cls, d):
"""
:param d: Dict representation
:return: PhononBandStructure
"""
lattice_rec = Lattice(d['lattice_rec']['matrix'])
eigendisplacements = np.array(d['eigendisplacements']['real']) + np.array(d['eigendisplacements']['imag']) * 1j
nac_eigendisplacements = [(direction, np.array(e['real']) + np.array(e['imag']) * 1j)
Expand All @@ -276,7 +282,7 @@ def from_dict(cls, d):


class PhononBandStructureSymmLine(PhononBandStructure):
"""
r"""
This object stores phonon band structures along selected (symmetry) lines in the
Brillouin zone. We call the different symmetry lines (ex: \\Gamma to Z)
"branches".
Expand Down Expand Up @@ -399,7 +405,7 @@ def get_equivalent_qpoints(self, index):
return list_index_qpoints

def get_branch(self, index):
"""
r"""
Returns in what branch(es) is the qpoint. There can be several
branches.
Expand Down Expand Up @@ -429,7 +435,7 @@ def write_phononwebsite(self, filename):
"""
import json
with open(filename, 'w') as f:
phononwebsite_json = json.dump(self.as_phononwebsite(), f)
json.dump(self.as_phononwebsite(), f)

def as_phononwebsite(self):
"""
Expand Down Expand Up @@ -541,6 +547,9 @@ def band_reorder(self):
eig[:, nq] = eigq[order[nq]]

def as_dict(self):
"""
:return: MSONable dict
"""
d = super().as_dict()
# remove nac_frequencies and nac_eigendisplacements as they are reconstructed
# in the __init__ when the dict is deserialized
Expand All @@ -551,6 +560,10 @@ def as_dict(self):

@classmethod
def from_dict(cls, d):
"""
:param d: Dict representation
:return: PhononBandStructureSummLine
"""
lattice_rec = Lattice(d['lattice_rec']['matrix'])
eigendisplacements = np.array(d['eigendisplacements']['real']) + np.array(d['eigendisplacements']['imag']) * 1j
structure = Structure.from_dict(d['structure']) if 'structure' in d else None
Expand Down

0 comments on commit 5d9bf3d

Please sign in to comment.