Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
4b257b2
Fix stab at fixing multi chain RMSD analysis
hannahbaumann Dec 18, 2025
236ff72
Some updates
hannahbaumann Dec 18, 2025
d274b0c
Add tests
hannahbaumann Dec 18, 2025
f3634dd
Some fixes
hannahbaumann Dec 19, 2025
e92adb3
Add another test
hannahbaumann Dec 19, 2025
b528ca2
Move some tests to use skipped smaller data
hannahbaumann Jan 16, 2026
a477bc1
Test out zenodo dealings
hannahbaumann Jan 16, 2026
ad84082
Try to improbe speed
hannahbaumann Jan 16, 2026
8ba8087
Try removing locking
hannahbaumann Jan 16, 2026
ead7951
Run downloads before the testing to have a single download for all th…
hannahbaumann Jan 19, 2026
f898a35
add import pooch
hannahbaumann Jan 19, 2026
c675a5c
Test out more
hannahbaumann Jan 19, 2026
88e456d
Ensure datasets get closed
hannahbaumann Jan 19, 2026
73a8e4d
Move to per test download again
hannahbaumann Jan 19, 2026
43aaca2
Remove commented out lines
hannahbaumann Jan 21, 2026
c165525
Test out adding an extra slash
hannahbaumann Jan 21, 2026
5f17770
Switch to all version doi
hannahbaumann Jan 21, 2026
c28286e
Download url directly
hannahbaumann Jan 21, 2026
197b6ba
Small fix
hannahbaumann Jan 21, 2026
b45390a
Change url
hannahbaumann Jan 21, 2026
1d70936
Add missing s
hannahbaumann Jan 21, 2026
20084c3
Switch to api url
hannahbaumann Jan 21, 2026
1a1c916
Revert to old cli
hannahbaumann Jan 22, 2026
59c7392
Update cli.py
hannahbaumann Jan 22, 2026
5e135ab
Update cli.py
hannahbaumann Jan 22, 2026
a9a8780
Update tests for new results
hannahbaumann Jan 23, 2026
92af45b
Change shift to enable other boxes
hannahbaumann Jan 23, 2026
8ea3585
Update multichain code
hannahbaumann Jan 26, 2026
220d504
Add ligand in shifting
hannahbaumann Jan 26, 2026
8c44cb2
USe new shift class instead of old minimiser since that one is no lon…
hannahbaumann Jan 26, 2026
d13495f
Update some tests
hannahbaumann Jan 26, 2026
c34c97c
Update conftest
hannahbaumann Jan 26, 2026
0161673
Update to v2
hannahbaumann Jan 26, 2026
9b6ca69
Update tests
hannahbaumann Jan 26, 2026
1d5c849
Update rmsd test, currently large rmsd till rmsd fix comes in
hannahbaumann Jan 26, 2026
f4e88e2
Make last test pass
hannahbaumann Jan 26, 2026
bd0c8ee
Switch to zenodo fetch
hannahbaumann Jan 26, 2026
ba4c912
remove lines
hannahbaumann Jan 26, 2026
157c02f
Update tests with large errors multichain failure
hannahbaumann Jan 27, 2026
98ea023
Apply suggestion from @hannahbaumann
hannahbaumann Jan 28, 2026
c5b2d70
Reuse zenodo specification
hannahbaumann Jan 28, 2026
54576ab
reorder install
hannahbaumann Jan 28, 2026
3aa52a5
Small fix
hannahbaumann Jan 28, 2026
ff6991a
Remove flaky retries
hannahbaumann Jan 28, 2026
7a30f69
Small fix
hannahbaumann Jan 28, 2026
ac1fe7b
Merge in the fix flakyness PR and update tests
hannahbaumann Jan 28, 2026
67a0913
Add wrapping to get positions to be greater than 0
hannahbaumann Jan 29, 2026
e706b11
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 29, 2026
7277f20
Replace state_id and replica_id with index and view
hannahbaumann Jan 30, 2026
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
27 changes: 27 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,33 @@ jobs:
run: |
python -m pip install --no-deps .

- name: Cache Pooch data
uses: actions/cache@v4
with:
path: |
# Linux cache location
~/.cache/openfe_analysis
# macOS cache location
~/Library/Caches/openfe_analysis
key: pooch-${{ matrix.os }}-v2

- name: "Download Zenodo data"
run: |
python - <<'EOF'
import pooch
from openfe_analysis.tests.conftest import ZENODO_DOI, ZENODO_FILES

zenodo = pooch.create(
path=pooch.os_cache('openfe_analysis'),
base_url=ZENODO_DOI,
registry=ZENODO_FILES,
)

for fname in ZENODO_FILES:
zenodo.fetch(fname, processor=pooch.Untar())

EOF

- name: "Test imports"
run: |
python -Ic "import openfe_analysis; print(openfe_analysis.__version__)"
Expand Down
2 changes: 1 addition & 1 deletion src/openfe_analysis/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
from .reader import FEReader
from .transformations import (
Aligner,
Minimiser,
ClosestImageShift,
NoJump,
)
105 changes: 59 additions & 46 deletions src/openfe_analysis/reader.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Optional
import pathlib
from typing import Literal, Optional

import netCDF4 as nc
import numpy as np
Expand Down Expand Up @@ -52,16 +53,20 @@ def _determine_iteration_dt(dataset) -> float:


class FEReader(ReaderBase):
"""A MDAnalysis Reader for NetCDF files created by
"""
MDAnalysis Reader for NetCDF files created by
`openmmtools.multistate.MultiStateReporter`

Looks along a multistate NetCDF file along one of two axes:
- constant state/lambda (varying replica)
- constant replica (varying lambda)
Provides a 1D trajectory view along either:

- constant Hamiltonian state (`view="state"`)
- constant replica (`view="replica"`)

selected via the `index` argument.
"""

_state_id: Optional[int]
_replica_id: Optional[int]
_index: Optional[int]
_view: Optional[str]
_frame_index: int
_dataset: nc.Dataset
_dataset_owner: bool
Expand All @@ -70,35 +75,27 @@ class FEReader(ReaderBase):

units = {"time": "ps", "length": "nanometer"}

def __init__(self, filename, convert_units=True, state_id=None, replica_id=None, **kwargs):
def __init__(
self,
filename: str | pathlib.Path | nc.Dataset,
*,
index: int,
view: Literal["state", "replica"] = "state",
convert_units: bool = True,
**kwargs,
):
"""
Parameters
----------
filename : pathlike or nc.Dataset
path to the .nc file
Path to the .nc file or an open Dataset.
index : int
Index of the state or replica to extract. May be negative.
view : {"state", "replica"}, default "state"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

view is a bit unclear, I would maybe call it something like index_style or index_method? That way it's clear you're talking about how it's being indexed.

Whether `index` refers to a Hamiltonian state or a replica.
convert_units : bool
convert positions to Angstrom
state_id : Optional[int]
The Hamiltonian state index to extract. Must be defined if
``replica_id`` is not defined. May be negative (see notes below).
replica_id : Optional[int]
The replica index to extract. Must be defined if ``state_id``
is not defined. May be negative (see notes below).

Notes
-----
A negative index may be passed to either ``state_id`` or
``replica_id``. This will be interpreted as indexing in reverse
starting from the last state/replica. For example, passing a
value of -2 for ``replica_id`` will select the before last replica.
Convert positions to Angstrom.
"""
if not ((state_id is None) ^ (replica_id is None)):
raise ValueError(
"Specify one and only one of state or replica, "
f"got state id={state_id} "
f"replica_id={replica_id}"
)

super().__init__(filename, convert_units, **kwargs)

if isinstance(filename, nc.Dataset):
Expand All @@ -108,29 +105,37 @@ def __init__(self, filename, convert_units=True, state_id=None, replica_id=None,
self._dataset = nc.Dataset(filename)
self._dataset_owner = True

# Handle the negative ID case
if state_id is not None and state_id < 0:
state_id = range(self._dataset.dimensions["state"].size)[state_id]
if view not in {"state", "replica"}:
raise ValueError(f"View must be 'state' or 'replica', got {view}")

if replica_id is not None and replica_id < 0:
replica_id = range(self._dataset.dimensions["replica"].size)[replica_id]
self._view = view

self._state_id = state_id
self._replica_id = replica_id
# Handle the negative ID case
if view == "state":
size = self._dataset.dimensions["state"].size
else:
size = self._dataset.dimensions["replica"].size

self._index = index % size
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would call this multistate_index or something like that, otherwise it gets very confusing with frame_index, etc...


self._n_atoms = self._dataset.dimensions["atom"].size
self.ts = Timestep(self._n_atoms)
self._frames = _determine_position_indices(self._dataset)
# The MDAnalysis trajectory "dt" is the iteration dt
# multiplied by the number of iterations between frames.
self._dt = _determine_iteration_dt(self._dataset) * np.diff(self._frames)[0]
self._frame_index = -1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't do this, let _read_frame set the frame_index to 0. Otherwise you're setting the variable to a value only for it to be reset two instructions later (it's a bit of a code smell).

self._read_frame(0)

@staticmethod
def _format_hint(thing) -> bool:
# can pass raw nc datasets through to reduce open/close operations
return isinstance(thing, nc.Dataset)

@property
def index(self) -> int:
return self._index

@property
def n_atoms(self) -> int:
return self._n_atoms
Expand All @@ -139,6 +144,10 @@ def n_atoms(self) -> int:
def n_frames(self) -> int:
return len(self._frames)

@property
def view(self) -> str:
return self._view

@staticmethod
def parse_n_atoms(filename, **kwargs) -> int:
with nc.Dataset(filename) as ds:
Expand All @@ -153,17 +162,19 @@ def _read_next_timestep(self, ts=None) -> Timestep:
def _read_frame(self, frame: int) -> Timestep:
self._frame_index = frame

if self._state_id is not None:
frame = self._frames[self._frame_index]

if self._view == "state":
rep = multistate._state_to_replica(
self._dataset, self._state_id, self._frames[self._frame_index]
self._dataset,
self._index,
frame,
)
else:
rep = self._replica_id
rep = self._index

pos = multistate._replica_positions_at_frame(
self._dataset, rep, self._frames[self._frame_index]
)
dim = multistate._get_unitcell(self._dataset, rep, self._frames[self._frame_index])
pos = multistate._replica_positions_at_frame(self._dataset, rep, frame)
dim = multistate._get_unitcell(self._dataset, rep, frame)

if pos is None:
errmsg = (
Expand Down Expand Up @@ -193,5 +204,7 @@ def _reopen(self):
self._frame_index = -1

def close(self):
if self._dataset_owner:
self._dataset.close()
if self._dataset is not None:
if self._dataset_owner:
self._dataset.close()
self._dataset = None
Loading