Skip to content

Commit

Permalink
add dependent feature loading
Browse files Browse the repository at this point in the history
  • Loading branch information
jhprinz committed Mar 12, 2016
1 parent 08fd993 commit d7b9494
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
19 changes: 16 additions & 3 deletions openpathsampling/engines/features/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _decorator(cls):
__features__ = dict()

for name in ['attributes', 'minus', 'reversal', 'properties',
'flip', 'numpy', 'lazy', 'required', 'classes', 'provides']:
'flip', 'numpy', 'lazy', 'required', 'classes']:
if name not in __features__:
__features__[name] = []

Expand All @@ -83,10 +83,23 @@ def _decorator(cls):

__features__['classes'] += features

for feature in features:
# add provided additional feature and run though the added ones
# recursively until nothing is added
feat_no = 0
while feat_no < len(__features__['classes']):
feature = __features__['classes'][feat_no]

# add provides additional features
if hasattr(feature, 'provides'):
__features__['classes'] += feature.provides
if type(feature.provides) is list:
for c in feature.provides:
if c not in __features__['classes']:
__features__['classes'].append(c)
else:
if feature.provides not in __features__['classes']:
__features__['classes'].append(feature.provides)

feat_no += 1

if use_lazy_reversed:
cls._reversed = DelayedLoader()
Expand Down
3 changes: 3 additions & 0 deletions openpathsampling/engines/features/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
atomic coordinates
"""

from openpathsampling.engines.features import xyz

attributes = ['coordinates']
numpy = ['coordinates']

provides = [xyz]


def netcdfplus_init(store):
store.create_variable('coordinates', 'numpy.float32',
Expand Down
4 changes: 4 additions & 0 deletions openpathsampling/engines/features/statics.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
from shared import StaticContainerStore
import mdtraj

from openpathsampling.engines.features import xyz

attributes = ['statics', 'box_vectors', 'md', 'coordinates']
lazy = ['statics']

provides = [xyz]


def netcdfplus_init(store):
store.storage.create_store('statics', StaticContainerStore())
Expand Down
3 changes: 0 additions & 3 deletions openpathsampling/engines/openmm/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
features.velocities,
features.coordinates,
features.box_vectors,
features.xyz,
features.topology
])
class MDSnapshot(BaseSnapshot):
Expand All @@ -28,7 +27,6 @@ class MDSnapshot(BaseSnapshot):
# features.velocities,
# features.coordinates,
# features.box_vectors,
# features.xyz,
# features.topology
# ],
# description="A fast MDSnapshot",
Expand All @@ -39,7 +37,6 @@ class MDSnapshot(BaseSnapshot):
@features.base.attach_features([
features.statics,
features.kinetics,
features.xyz,
features.topology # for compatibility
])
class Snapshot(BaseSnapshot):
Expand Down
1 change: 0 additions & 1 deletion openpathsampling/engines/toy/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
features=[
features.velocities,
features.coordinates,
features.xyz,
features.topology
],
description="Simulation snapshot. Only references to coordinates and velocities",
Expand Down

0 comments on commit d7b9494

Please sign in to comment.