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
8 changes: 8 additions & 0 deletions openpathsampling/shooting.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,11 @@ def probability_ratio(self, snapshot, old_trajectory,
if new_snapshot is None:
NEW_SNAPSHOT_SELECTOR.warn(stacklevel=3)
return 1.0


class VolumeSelector(ShootingPointSelector):
def __init__(self, volume):
self.volume = volume

def f(self, frame, trajectory):
return float(self.volume(frame))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

any particular reason you went for float instead of int casting?
(I understand it makes sense from a probablility point of view, but not really from the point of view that the output of volume should be bool)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'm thinking of it as a special case of a shooting point biasing function, like BiasedSelector. In that case you bias toward certain shooting points using a CV, which returns floats. Really, the actual value that comes out here doesn't matter, as long as it is either 0 or some constant $k$ (I took $k=1$).

FWIW, even UniformSelector technically returns 1.0 for its f. So this also keeps the typing consistent across different selectors.

14 changes: 14 additions & 0 deletions openpathsampling/tests/test_shooting.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ def test_probability_ratio_modified_coordinates(self, new_coord, expected):
assert prob == expected


class TestVolumeSelector(SelectorTest):
def setup_method(self):
super().setup_method()
self.cv = paths.FunctionCV("Id", lambda x: x.xyz[0][0])
vol = paths.CVDefinedVolume(self.cv, 0.15, 0.35)
self.sel = VolumeSelector(vol)

@pytest.mark.parametrize('frame,expected', [
(0, 0.0), (1, 0.0), (2, 1.0), (3, 1.0), (4, 0.0)
])
def test_f(self, frame, expected):
assert self.sel.f(self.mytraj[frame], self.mytraj) == expected


class TestDeprecations(object):
@pytest.mark.parametrize('selector_class', [ShootingPointSelector,
FirstFrameSelector,
Expand Down