Skip to content

Commit 2f017ed

Browse files
authored
Merge pull request #1151 from dwhswenson/volume-shooting-point-selector
Volume shooting point selector
2 parents d833c5c + 61e75cb commit 2f017ed

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎openpathsampling/shooting.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,11 @@ def probability_ratio(self, snapshot, old_trajectory,
271271
if new_snapshot is None:
272272
NEW_SNAPSHOT_SELECTOR.warn(stacklevel=3)
273273
return 1.0
274+
275+
276+
class VolumeSelector(ShootingPointSelector):
277+
def __init__(self, volume):
278+
self.volume = volume
279+
280+
def f(self, frame, trajectory):
281+
return float(self.volume(frame))

‎openpathsampling/tests/test_shooting.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,20 @@ def test_probability_ratio_modified_coordinates(self, new_coord, expected):
251251
assert prob == expected
252252

253253

254+
class TestVolumeSelector(SelectorTest):
255+
def setup_method(self):
256+
super().setup_method()
257+
self.cv = paths.FunctionCV("Id", lambda x: x.xyz[0][0])
258+
vol = paths.CVDefinedVolume(self.cv, 0.15, 0.35)
259+
self.sel = VolumeSelector(vol)
260+
261+
@pytest.mark.parametrize('frame,expected', [
262+
(0, 0.0), (1, 0.0), (2, 1.0), (3, 1.0), (4, 0.0)
263+
])
264+
def test_f(self, frame, expected):
265+
assert self.sel.f(self.mytraj[frame], self.mytraj) == expected
266+
267+
254268
class TestDeprecations(object):
255269
@pytest.mark.parametrize('selector_class', [ShootingPointSelector,
256270
FirstFrameSelector,

0 commit comments

Comments
 (0)