Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,11 @@ jobs:
python -Ic "import cinnabar; print(cinnabar.__version__)"

- name: Run tests
env:
DUECREDIT_ENABLE: "yes"
shell: bash -l {0}
run: |
pytest -v --cov=cinnabar --cov-report=xml --cov-report=term --color=yes cinnabar/tests/
pytest -v --cov=cinnabar/ --cov-report=xml --cov-report=term --color=yes cinnabar/tests/

- name: codecov
if: ${{ github.repository == 'OpenFreeEnergy/cinnabar' && github.event_name != 'schedule'}}
Expand Down
81 changes: 81 additions & 0 deletions cinnabar/_due.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# emacs: at the end of the file
# ex: set sts=4 ts=4 sw=4 et:
# ## ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### #
from __future__ import annotations

from typing import Any

"""

Stub file for a guaranteed safe import of duecredit constructs: if duecredit
is not available.

To use it, place it into your project codebase to be imported, e.g. copy as

cp stub.py /path/tomodule/module/due.py

Note that it might be better to avoid naming it duecredit.py to avoid shadowing
installed duecredit.

Then use in your code as

from .due import due, Doi, BibTeX, Text

See https://github.com/duecredit/duecredit/blob/master/README.md for examples.

Origin: Originally a part of the duecredit
Copyright: 2015-2021 DueCredit developers
License: BSD-2
"""

__version__ = "0.0.9"


class InactiveDueCreditCollector:
"""Just a stub at the Collector which would not do anything"""

def _donothing(self, *_args: Any, **_kwargs: Any) -> None:
"""Perform no good and no bad"""
pass

def dcite(self, *_args: Any, **_kwargs: Any):
"""If I could cite I would"""

def nondecorating_decorator(func):
return func

return nondecorating_decorator

active = False
activate = add = cite = dump = load = _donothing

def __repr__(self) -> str:
return self.__class__.__name__ + "()"


def _donothing_func(*args: Any, **kwargs: Any) -> None:
"""Perform no good and no bad"""
pass


try:
from duecredit import BibTeX, Doi, Text, Url, due # lgtm [py/unused-import]

if "due" in locals() and not hasattr(due, "cite"):
raise RuntimeError("Imported due lacks .cite. DueCredit is now disabled")
except Exception as e:
if not isinstance(e, ImportError):
import logging

logging.getLogger("duecredit").error(f"Failed to import duecredit due to {e}")
# Initiate due stub
due = InactiveDueCreditCollector() # type: ignore[assignment]
BibTeX = Doi = Url = Text = _donothing_func # type: ignore[assignment, misc]

# Emacs mode definitions
# Local Variables:
# mode: python
# py-indent-offset: 4
# tab-width: 4
# indent-tabs-mode: nil
# End:
11 changes: 9 additions & 2 deletions cinnabar/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
import sklearn.metrics
from typing import Union

from ._due import due, Doi

due.cite(
Doi("10.1021/acs.jcim.9b00528"),
description="Compute maximum likelihood estimate of free energies and covariance in their estimates",
path="cinnabar.stats.mle",
cite_module=True
)

def bootstrap_statistic(
y_true: np.ndarray,
Expand Down Expand Up @@ -139,7 +147,6 @@ def unique_differences(x):

return rmse_stats


def mle(
graph: nx.DiGraph, factor: str = "f_ij", node_factor: Union[str, None] = None
) -> np.ndarray:
Expand All @@ -151,7 +158,7 @@ def mle(
We assume the free energy of node 0 is zero.

Reference : https://pubs.acs.org/doi/abs/10.1021/acs.jcim.9b00528
Xu, Huafengraph. "Optimal measurement network of pairwise differences."
Xu, Huafeng. "Optimal measurement network of pairwise differences."
Journal of Chemical Information and Modeling 59.11 (2019): 4720-4728.

NOTE: Self-edges (edges that connect a node to itself) will be ignored.
Expand Down
12 changes: 12 additions & 0 deletions cinnabar/tests/test_due.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest


from cinnabar._due import due


pytest.importorskip("duecredit")

def test_duecredit_mle():
"""Make sure duecredit is captured when the stats module is used"""
mle_key = ("cinnabar.stats.mle", "10.1021/acs.jcim.9b00528")
assert due.citations[mle_key].cites_module
1 change: 1 addition & 0 deletions devtools/conda-envs/env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies:
- scikit-learn
- adjustText
- openff-units
- duecredit<0.10

# format
- black
Expand Down
7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,9 @@ exclude_lines = [
"pragma: no-cover",
"-no-cov",
"raise NotImplementedError",
]
]

[tool.coverage.run]
omit = [
"cinnabar/_due.py",
]
Loading