Skip to content

Commit

Permalink
Merge pull request #108 from nlesc-nano/get_formula
Browse files Browse the repository at this point in the history
MAINT: Fix a documentation failure and deprecate usage of `Molecule.get_formula`
  • Loading branch information
BvB93 authored Dec 2, 2021
2 parents cbad6ff + cfb0b1f commit cc0d005
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 18 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Change Log
All notable changes to this project will be documented in this file.
This project adheres to `Semantic Versioning <http://semver.org/>`_.


0.7.1
*****
* Deprecate usage of ``Molecule.get_formula`` in favor of a PLAMS <=1.5.1-based backport.
* Fix a failure in the documentation generation


0.7.0
*****
* Added a new fast-bulkiness workflow.
Expand Down
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
:target: https://github.com/nlesc-nano/nano-CAT/actions?query=workflow%3A%22Build+with+Conda%22
.. image:: https://readthedocs.org/projects/cat/badge/?version=latest
:target: https://cat.readthedocs.io/en/latest/
.. image:: https://badge.fury.io/py/nano-CAT.svg
:target: https://badge.fury.io/py/nano-CAT

|
Expand All @@ -14,7 +16,7 @@


##############
Nano-CAT 0.7.0
Nano-CAT 0.7.1
##############

**Nano-CAT** is a collection of tools for the analysis of nanocrystals,
Expand Down
2 changes: 1 addition & 1 deletion nanoCAT/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.7.0'
__version__ = '0.7.1'
7 changes: 4 additions & 3 deletions nanoCAT/recipes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
>>> from nanoCAT.recipes import bulk_workflow
>>> from nanoCAT.recipes import get_lig_charge
>>> from nanoCAT.recipes import replace_surface
>>> from nanoCAT.recipes import coordination_number
>>> from nanoCAT.recipes import get_coordination_number, coordination_outer
>>> from nanoCAT.recipes import dissociate_surface, row_accumulator, dissociate_bulk
>>> from nanoCAT.recipes import get_mol_length, filter_mol, filter_data
>>> from nanoCAT.recipes import run_jobs, get_global_descriptors, cdft
Expand All @@ -25,7 +25,7 @@
from .charges import get_lig_charge
from .mark_surface import replace_surface
from .dissociation import dissociate_surface, row_accumulator, dissociate_bulk
from .coordination_number import coordination_number
from .coordination_number import get_coordination_number, coordination_outer
from .multi_lig_job import multi_ligand_job
from .mol_filter import get_mol_length, filter_mol, filter_data
from .cdft_utils import run_jobs, get_global_descriptors, cdft
Expand All @@ -35,7 +35,8 @@
__all__ = [
'bulk_workflow', 'fast_bulk_workflow',
'replace_surface', 'dissociate_surface', 'dissociate_bulk',
'row_accumulator', 'get_lig_charge', 'coordination_number',
'row_accumulator', 'get_lig_charge',
'get_coordination_number', 'coordination_outer',
'multi_ligand_job',
'get_mol_length', 'filter_mol', 'filter_data',
'run_jobs', 'get_global_descriptors', 'cdft',
Expand Down
15 changes: 10 additions & 5 deletions nanoCAT/recipes/coordination_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
-----
.. currentmodule:: nanoCAT.recipes
.. autosummary::
coordination_number
get_coordination_number
coordination_outer
API
---
.. autofunction:: coordination_number
.. autofunction:: get_coordination_number
.. autofunction:: coordination_outer
"""

Expand All @@ -26,7 +28,7 @@
from nanoutils import group_by_values
from nanoCAT.bde.guess_core_dist import guess_core_core_dist

__all__: List[str] = ['coordination_number', 'coordination_outer']
__all__ = ['get_coordination_number', 'coordination_outer']

#: A nested dictonary
NestedDict = Dict[str, Dict[int, List[int]]]
Expand Down Expand Up @@ -116,8 +118,8 @@ def map_coordination(coord: np.ndarray, idx_dict: Dict[str, np.ndarray]) -> Nest
return cn_dict


def coordination_number(mol: Molecule, shell: str = 'inner',
d_outer: Optional[float] = None) -> NestedDict:
def get_coordination_number(mol: Molecule, shell: str = 'inner',
d_outer: Optional[float] = None) -> NestedDict:
"""Take a molecule and identify the coordination number of each atom.
The function first compute the pair distance between all reference atoms in **mol**.
Expand Down Expand Up @@ -192,3 +194,6 @@ def coordination_number(mol: Molecule, shell: str = 'inner',

# Return the final dictionary
return map_coordination(coord, idx_dict)


coordination_number = get_coordination_number
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
'flake8',
],
extras_require={
'test': ['pytest', 'pytest-cov', 'pytest-mock'],
'test': [
'pytest',
'pytest-cov',
'pytest-mock',
'nlesc-CAT>=0.10.1',
],
}
)
3 changes: 2 additions & 1 deletion tests/test_bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from scm.plams import Molecule
from scipy.spatial.distance import cdist
from nanoCAT.recipes import bulk_workflow, fast_bulk_workflow
from CAT.utils import get_formula

if TYPE_CHECKING:
import _pytest
Expand Down Expand Up @@ -45,7 +46,7 @@ def test_bulk_workflow() -> None:
iterator = enumerate(zip(mol_list, formula_list), start=2)
for i, (mol, formula) in iterator:
assertion.eq(mol[i].coords, (0.0, 0.0, 0.0))
assertion.eq(mol.get_formula(), formula)
assertion.eq(get_formula(mol), formula)

ref = [17.07131616, 64.15117841, 74.79488029]
np.testing.assert_allclose(bulk_ar, ref)
Expand Down
13 changes: 7 additions & 6 deletions tests/test_coordination_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
from scm.plams import Molecule
from assertionlib import assertion

from nanoCAT.recipes import coordination_number
from nanoCAT.recipes import get_coordination_number

PATH = Path('tests') / 'test_files'
MOL = Molecule(PATH / 'Cd68Se55.xyz')


def test_coordination_number() -> None:
"""Tests for :func:`nanoCAT.recipes.coordination_number`."""
"""Tests for :func:`nanoCAT.recipes.get_coordination_number`."""

out_inner = coordination_number(MOL, shell='inner')
out_inner = get_coordination_number(MOL, shell='inner')

out_outer = coordination_number(MOL, shell='outer', d_outer=5.2)
out_outer = get_coordination_number(MOL, shell='outer', d_outer=5.2)

ref_inner = {'Cd': {3: [30, 31, 34, 35, 36, 46, 47, 52, 53, 54, 57, 58, 59, 60, 63, 64, 65, 67,
69, 70, 71, 75, 78, 79],
Expand Down Expand Up @@ -50,5 +50,6 @@ def test_coordination_number() -> None:
np.testing.assert_equal(out_inner, ref_inner)
np.testing.assert_equal(out_outer, ref_outer)

assertion.assert_(coordination_number, MOL, shell='bob', exception=ValueError)
assertion.assert_(coordination_number, MOL, shell='outer', d_outer=None, exception=TypeError)
assertion.assert_(get_coordination_number, MOL, shell='bob', exception=ValueError)
assertion.assert_(get_coordination_number, MOL, shell='outer', d_outer=None,
exception=TypeError)

0 comments on commit cc0d005

Please sign in to comment.