Skip to content

Commit

Permalink
Some cleanup of entries package. Make pydocstyle the last thing to run.
Browse files Browse the repository at this point in the history
If documentation is an issue for failure, pymatgen maintainers will make
a determination.
  • Loading branch information
shyuep committed Sep 12, 2019
1 parent c591a19 commit 8415ba8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 18 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ jobs:
# Add executables and path.
for EXEPATH in `pwd`/cmd_line/*/Linux_64bit; do export PATH=$PATH:$EXEPATH; done
pip install --quiet -e .
echo "Checks will be performed in the order of pycodestyle -> pydocstyle -> mypy"
echo "Checks will be performed in the order of pycodestyle -> mypy -> pytest -> pydocstyle "
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."
echo "pycodestyle checks..."
pycodestyle pymatgen
echo "--- Done ---"
export MODIFIED_FILES=`git diff --diff-filter=d --name-only HEAD v2019.9.12 | grep -E '\.(py)' | tr '\n' ' '`
echo "pydocstyle checks for $MODIFIED_FILES..."
pydocstyle --count pymatgen/core $MODIFIED_FILES
echo "--- Done ---"
echo "mypy checks..."
mypy pymatgen
echo "--- Done ---"
pytest --ignore=pymatgen/analysis/tests/test_pourbaix_diagram.py --cov=pymatgen --cov-report html:coverage_reports pymatgen
export MODIFIED_FILES=`git diff --diff-filter=d --name-only HEAD v2019.9.12 | grep -E '\.(py)' | tr '\n' ' '`
echo "pydocstyle checks for $MODIFIED_FILES..."
pydocstyle --count pymatgen/core $MODIFIED_FILES
echo "--- Done ---"
# Command line tests
pmg structure --convert --filenames test_files/Li2O.cif POSCAR.pmg
pmg structure --convert --filenames POSCAR.pmg pmg.cif
Expand Down
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@ before_script:
script:
- export PATH="$HOME/miniconda/bin:$PATH"
- source activate test-environment
- export MODIFIED_FILES=`git diff --diff-filter=d --name-only HEAD v2019.9.12 | grep -E '\.(py)' | tr '\n' ' '`
- echo "pycodestyle->pydocstyle->mypy->pytest... Note that this fails on the first command with error."
- echo "pycodestyle->mypy->pytest->pydocstyle... Note that this fails on the first command with error."
- 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 && pydocstyle --count pymatgen/core $MODIFIED_FILES && mypy pymatgen && pytest $EXCLUDE_TESTS pymatgen
- travis_wait 28800 pycodestyle pymatgen && mypy pymatgen && pytest $EXCLUDE_TESTS pymatgen
- export MODIFIED_FILES=`git diff --diff-filter=d --name-only HEAD v2019.9.12 | grep -E '\.(py)' | tr '\n' ' '`
- pydocstyle --count pymatgen/core $MODIFIED_FILES

notifications:
email:
recipients:
Expand Down
40 changes: 30 additions & 10 deletions pymatgen/entries/computed_entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# Copyright (c) Pymatgen Development Team.
# Distributed under the terms of the MIT License.

"""
This module implements equivalents of the basic ComputedEntry objects, which
is the basic entity that can be used to perform many analyses. ComputedEntries
contain calculated information, typically from VASP or other electronic
structure codes. For example, ComputedEntries can be used as inputs for phase
diagram analysis.
"""

import json

Expand All @@ -11,13 +18,6 @@
from pymatgen.core.structure import Structure
from monty.json import MSONable

"""
This module implements equivalents of the basic ComputedEntry objects, which
is the basic entity that can be used to perform many analyses. ComputedEntries
contain calculated information, typically from VASP or other electronic
structure codes. For example, ComputedEntries can be used as inputs for phase
diagram analysis.
"""

__author__ = "Shyue Ping Ong, Anubhav Jain"
__copyright__ = "Copyright 2011, The Materials Project"
Expand Down Expand Up @@ -93,17 +93,23 @@ def normalize(self, mode: str = "formula_unit") -> None:

@property
def is_element(self) -> bool:
"""
:return: Whether composition of entry is an element.
"""
return self.composition.is_element

@property
def energy(self) -> float:
"""
Returns the *corrected* energy of the entry.
:return: the *corrected* energy of the entry.
"""
return self.uncorrected_energy + self.correction

@property
def energy_per_atom(self) -> float:
"""
:return: the *corrected* energy per atom of the entry.
"""
return self.energy / self.composition.num_atoms

def __repr__(self):
Expand All @@ -123,7 +129,11 @@ def __str__(self):
return self.__repr__()

@classmethod
def from_dict(cls, d):
def from_dict(cls, d) -> 'ComputedEntry':
"""
:param d: Dict representation.
:return: ComputedEntry
"""
dec = MontyDecoder()
return cls(d["composition"], d["energy"], d["correction"],
parameters={k: dec.process_decoded(v)
Expand All @@ -133,6 +143,9 @@ def from_dict(cls, d):
entry_id=d.get("entry_id", None))

def as_dict(self) -> dict:
"""
:return: MSONable dict.
"""
return {"@module": self.__class__.__module__,
"@class": self.__class__.__name__,
"energy": self.uncorrected_energy,
Expand Down Expand Up @@ -194,14 +207,21 @@ def __str__(self):
return self.__repr__()

def as_dict(self) -> dict:
"""
:return: MSONAble dict.
"""
d = super().as_dict()
d["@module"] = self.__class__.__module__
d["@class"] = self.__class__.__name__
d["structure"] = self.structure.as_dict()
return d

@classmethod
def from_dict(cls, d):
def from_dict(cls, d) -> 'ComputedStructureEntry':
"""
:param d: Dict representation.
:return: ComputedStructureEntry
"""
dec = MontyDecoder()
return cls(dec.process_decoded(d["structure"]),
d["energy"], d["correction"],
Expand Down

0 comments on commit 8415ba8

Please sign in to comment.