Skip to content

Commit

Permalink
For MPcules: Molecule Trajectory and graph hashes (#2945)
Browse files Browse the repository at this point in the history
* Initial commit; adding graph hashing from emmet, beginning work on molecule-specific trajectory

* Continued

* Trajectory first draft done

* Tests

* Beginning to add entry classes to incorporate into Emmet

* More test fixes for molecule trajectory

* molecule trajectory works

* Small addition

* Add tests for graph hashing

* Small tweaks to trajectory tests

* pre-commit auto-fixes

* mypy is a cruelty to both programmers and programming languages

* Ah, yes. Let's just staple type-checking to a language built around duck-typing. That'll go great

* fix common typo MSONAble->MSONable

* tweak PR template

* fix supported types list

* fix from_molecules() return type

* Requested change

* pre-commit auto-fixes

* Trying to make mypy happy, like a crying child

* And now ruff

* pre-commit auto-fixes

* Please let it end

* faff

* remove use_molecule kwarg

can we rely on heuristic if lattice is None, we're handling molecules?

* fix mypy, refactor to_positions() and to_displacements()

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Janosh Riebesell <[email protected]>
  • Loading branch information
3 people authored Apr 25, 2023
1 parent e165609 commit a553f37
Show file tree
Hide file tree
Showing 27 changed files with 791 additions and 172 deletions.
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Before a pull request can be merged, the following items must be checked:
- [ ] Tests have been added for any new functionality or bug fixes.
- [ ] All linting and tests pass.

Note that the CI system will run all the above checks. But it will be much more efficient if you already fix most errors prior to submitting the PR. We highly recommended installing `pre-commit` hooks. Simply Run
Our CI will run all the above checks but it might be more efficient if you already fix most errors before submitting the PR. We highly recommended installing `pre-commit` hooks. Simply Run

```sh
pip install -U pre-commit
pre-commit install
```

in the repo's root directory. Afterwards linters will run before every commit and abort if any issues pop up.
in the repo's root directory. Once `pre-commit` has installed `git` hooks, our linters will run before every commit and abort if issues pop up.
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ v2020.7.16

v2020.7.14
----------
* EwaldSummation is now MSONAble (@lbluque).
* EwaldSummation is now MSONable (@lbluque).
* Fix for QChem freq parsing (@samblau)
* Much improved linting and workflows.

Expand Down
2 changes: 1 addition & 1 deletion docs_rst/change_log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ v2020.7.16

v2020.7.14
----------
* EwaldSummation is now MSONAble (@lbluque).
* EwaldSummation is now MSONable (@lbluque).
* Fix for QChem freq parsing (@samblau)
* Much improved linting and workflows.

Expand Down
2 changes: 1 addition & 1 deletion pymatgen/alchemy/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def __repr__(self):

def as_dict(self):
"""
Returns: MSONAble dict
Returns: MSONable dict
"""
return {
"@module": type(self).__module__,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __new__(cls, myfloat):
return flt

def as_dict(self):
"""MSONAble dict"""
"""MSONable dict"""
return {
"@module": type(self).__module__,
"@class": type(self).__name__,
Expand Down Expand Up @@ -109,7 +109,7 @@ def __new__(cls, myfloat):
return flt

def as_dict(self):
"""MSONAble dict"""
"""MSONable dict"""
return {
"@module": type(self).__module__,
"@class": type(self).__name__,
Expand Down Expand Up @@ -1300,7 +1300,7 @@ def __eq__(self, other: object) -> bool:
return self.aa == other.aa # type: ignore

def as_dict(self):
"""MSONAble dict"""
"""MSONable dict"""
return {
"@module": type(self).__module__,
"@class": type(self).__name__,
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/chemenv/utils/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def from_edges(cls, edges, edges_are_ordered=True):

def as_dict(self):
"""
:return: MSONAble dict
:return: MSONable dict
"""
d = MSONable.as_dict(self)
# Transforming tuple object to a list to allow BSON and MongoDB
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/diffraction/tests/test_xrd.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test_get_pattern(self):
struct = self.get_structure("CsCl")
c = XRDCalculator()
xrd = c.get_pattern(struct, two_theta_range=(0, 90))
assert xrd.to_json() # Test MSONAble property
assert xrd.to_json() # Test MSONable property
# Check the first two peaks
assert xrd.x[0] == pytest.approx(21.107738329639844)
assert xrd.y[0] == pytest.approx(36.483184003748946)
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/analysis/molecule_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def __init__(self, angle_tolerance=10.0):
def as_dict(self):
"""
Returns:
MSONAble dict.
MSONable dict.
"""
return {
"version": __version__,
Expand Down Expand Up @@ -710,7 +710,7 @@ def group_molecules(self, mol_list):
def as_dict(self):
"""
Returns:
MSONAble dict.
MSONable dict.
"""
return {
"version": __version__,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def cond_prob_list(self, l1, l2):

def as_dict(self):
"""
Returns: MSONAble dict
Returns: MSONable dict
"""
return {
"name": type(self).__name__,
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/apps/battery/insertion_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ def from_dict_legacy(cls, d):

def as_dict_legacy(self):
"""
Returns: MSONAble dict
Returns: MSONable dict
"""
return {
"@module": type(self).__module__,
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/apps/borg/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def __str__(self):

def as_dict(self):
"""
Returns: MSONAble dict
Returns: MSONable dict
"""
return {
"init_args": {"inc_structure": self._inc_structure},
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def __update_c(self, new_c: float) -> None:

def as_dict(self):
"""
:return: MSONAble dict
:return: MSONable dict
"""
d = super().as_dict()
d["in_plane_offset"] = self.in_plane_offset.tolist()
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def rotoreflection(axis: ArrayLike, angle: float, origin: ArrayLike = (0, 0, 0))

def as_dict(self) -> dict[str, Any]:
"""
:return: MSONAble dict.
:return: MSONable dict.
"""
return {
"@module": type(self).__module__,
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -1510,7 +1510,7 @@ def from_string(species_string: str) -> DummySpecies:

def as_dict(self) -> dict:
"""
:return: MSONAble dict representation.
:return: MSONable dict representation.
"""
d = {
"@module": type(self).__module__,
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ def lattice(self) -> Lattice:
@property
def density(self) -> float:
"""
Returns the density in units of g/cc
Returns the density in units of g/cm^3.
"""
m = Mass(self.composition.weight, "amu")
return m.to("g") / (self.volume * Length(1, "ang").to("cm") ** 3)
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def to_s(x):

def as_dict(self):
"""
:return: MSONAble dict
:return: MSONable dict
"""
d = super().as_dict()
d["@module"] = type(self).__module__
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/tensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def as_dict(self, voigt: bool = False) -> dict:

@classmethod
def from_dict(cls, d) -> Tensor:
"""Instantiate Tensors from dicts (using MSONAble API).
"""Instantiate Tensors from dicts (using MSONable API).
Returns:
Tensor: hydrated tensor object
Expand Down
Loading

0 comments on commit a553f37

Please sign in to comment.