Skip to content

New functions to calculate state lifetimes by counting frames#173

Merged
andthum merged 9 commits intomainfrom
feat/src/mdtools/dtrj/state-lifetimes
Jul 6, 2023
Merged

New functions to calculate state lifetimes by counting frames#173
andthum merged 9 commits intomainfrom
feat/src/mdtools/dtrj/state-lifetimes

Conversation

@andthum
Copy link
Owner

@andthum andthum commented Jul 6, 2023

New functions to calculate state lifetimes by counting frames

Type of change

  • Change of core package.
  • Change of scripts.
  • Bug fix.
  • New feature.
  • Code refactoring.
  • Dependency update.
  • Documentation update.
  • Maintenance.
  • Other: Description.
  • Non-breaking (backward-compatible) change.
  • Breaking (non-backward-compatible) change.

Proposed changes

New features

  • Create a new function mdtools.dtrj.lifetimes that calculates the lifetimes for all compounds in all states of a discrete trajectory by simply counting the number of frames a given compound stays in a given state.
  • Create a new function mdtools.dtrj.lifetimes_per_state that calculates the lifetime of each state in a discrete trajectory by simply counting the number of frames a given compound stays in a given state.

Cod refactoring

  • Refactor the function mdtools.numpy_helper_functions.group_by:
    • Use a stable sort when sorting the keys and values with respect to the keys. A stable sort keeps the relative order of equal elements.
    • Always check the input arguments. The debug argument is now without use.
    • Add examples to the docstring.

Documentation update

  • Add more information about how to calculate lifetimes from remain probabilities to the docstring of the function mdtools.dtrj.remain_prob.

  • Correct a wrong comment in the Examples section of the docstring of the function mdtools.dtrj.remain_prob_discrete.

PR checklist

  • I followed the guidelines in the Developer's guide.
  • New/changed code is properly tested.
  • New/changed code is properly documented.
  • The CI workflow is passing.

andthum added 9 commits July 6, 2023 12:50
Refactor the function `mdtools.numpy_helper_functions.group_by`:

* Use a stable sort when sorting the keys and values with respect to the
  keys.  A stable sort keeps the relative order of equal elements.

* Always check the input arguments.  The `debug` argument is now without
  use.

* Add examples to the docstring.
Create a new function `mdtools.dtrj.lifetimes` that calculates the
lifetimes averaged over all compounds and all states by simply counting
the number of frames a given compound stays in a given state.
Create a new function `mdtools.dtrj.lifetimes_per_state` that calculates
the lifetime of each state in a discrete trajectory by simply counting
the number of frames a given compound stays in a given state.
Add more information about how to calculate lifetimes from remain
probabilities to the docstring of the function
`mdtools.dtrj.remain_prob`.
Correct wrong comment in the Examples section of the docstring of the
function `mdtools.dtrj.remain_prob_discrete`.
Extend the functionality of the function
`mdtools.dtrj.lifetimes_per_states`:

* Add a new argument `return_cmp_ix` that allows the user to return the
  compound indices associated with the returned lifetimes.

* Add a new argument `discard_neg_start` that allows the user to discard
  lifetimes of negative states (like in the functions
  `mdtools.dtrj.remain_prob` and `mdtools.dtrj.remain_prob_discrete`).

* Add a new argument `discard_all_neg` that allows the user to discard
  the lifetimes of all negative states and of all states that are
  followed by a negative state (like in the functions
  `mdtools.dtrj.remain_prob` and `mdtools.dtrj.remain_prob_discrete`).
Extend the functionality of the function `mdtools.dtrj.lifetimes`:

* Add a new argument `return_states` that allows the user to return the
  state indices associated with the returned lifetimes.

* Add a new argument `discard_neg_start` that allows the user to discard
  lifetimes of negative states (like in the functions
  `mdtools.dtrj.remain_prob` and `mdtools.dtrj.remain_prob_discrete`).

* Add a new argument `discard_all_neg` that allows the user to discard
  the lifetimes of all negative states and of all states that are
  followed by a negative state (like in the functions
  `mdtools.dtrj.remain_prob` and `mdtools.dtrj.remain_prob_discrete`).
Replace the main body of the function `mdtools.dtrj.lifetimes_per_state`
by a call of the function `mdtools.dtrj.lifetimes`.
@github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request minor Change that results in a new minor version patch Change that results in a new patch version refactoring Code refactoring labels Jul 6, 2023
@andthum andthum merged commit 1be5ce5 into main Jul 6, 2023
@andthum andthum deleted the feat/src/mdtools/dtrj/state-lifetimes branch July 6, 2023 12:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request minor Change that results in a new minor version patch Change that results in a new patch version refactoring Code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant