Skip to content
Open
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
6 changes: 6 additions & 0 deletions openpathsampling/engines/trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,3 +611,9 @@ def _to_list_of_trajectories(trajectories):
return paths.Trajectory([trajectories])

return trajectories

def unproxy(self):
for idx, snapshot in enumerate(self.iter_proxies()):
if issubclass(type(snapshot), LoaderProxy):
list.__setitem__(self, idx, snapshot.__subject__)
snapshot.__subject__.unproxy();
2 changes: 1 addition & 1 deletion openpathsampling/netcdfplus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .base import StorableNamedObject, StorableObject, create_to_dict
from .cache import WeakKeyCache, WeakLRUCache, WeakValueCache, MaxCache, \
NoCache, Cache, LRUCache, LRUChunkLoadingCache
from .dictify import ObjectJSON, StorableObjectJSON, UUIDObjectJSON
from .dictify import ObjectJSON, UUIDObjectJSON
from .netcdfplus import NetCDFPlus

from .stores import ObjectStore
Expand Down
7 changes: 7 additions & 0 deletions openpathsampling/netcdfplus/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,13 @@ def from_dict(cls, dct):
else:
return cls(**dct)

def unproxy(self):
if hasattr(self, '_lazy') :
for attr, value in self._lazy.items() :
if hasattr(value, '__subject__') :
self._lazy[attr] = value.__subject__
value.__subject__.unproxy()


class StorableNamedObject(StorableObject):
"""Mixin that allows an object to carry a .name property that can be saved
Expand Down
42 changes: 0 additions & 42 deletions openpathsampling/netcdfplus/dictify.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,48 +589,6 @@ def unit_from_json(self, json_string):
return self.unit_from_dict(self.from_json(json_string))


class StorableObjectJSON(ObjectJSON):
def __init__(self, storage, unit_system=None):
super(StorableObjectJSON, self).__init__(unit_system)
self.excluded_keys = ['idx', 'json', 'identifier']
self.storage = storage

def simplify(self, obj, base_type=''):
if obj is self.storage:
return {'_storage': 'self'}
if obj.__class__.__module__ != builtin_module:
if obj.__class__ in self.storage._obj_store:
store = self.storage._obj_store[obj.__class__]
if not store.nestable or obj.base_cls_name != base_type:
# this also returns the base class name used for storage
# store objects only if they are not creatable. If so they
# will only be created in their top instance and we use
# the simplify from the super class ObjectJSON
idx = store.save(obj)
if idx is None:
raise RuntimeError(
'cannot store idx None in store %s' % store)
return {
'_idx': idx,
'_store': store.prefix}

return super(StorableObjectJSON, self).simplify(obj, base_type)

def build(self, obj):
if type(obj) is dict:
if '_storage' in obj:
if obj['_storage'] == 'self':
return self.storage

if '_idx' in obj and '_store' in obj:
store = self.storage._stores[obj['_store']]
result = store.load(obj['_idx'])

return result

return super(StorableObjectJSON, self).build(obj)


class UUIDObjectJSON(ObjectJSON):
def __init__(self, storage, unit_system=None):
super(UUIDObjectJSON, self).__init__(unit_system)
Expand Down
6 changes: 3 additions & 3 deletions openpathsampling/netcdfplus/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ def _load_(self):
if type(self.__uuid__) is int:
raise RuntimeWarning(
'Index %s is not in store. This should never happen!' %
self._idx)
self.__uuid__)
else:
raise RuntimeWarning(
'Object %s is not in store. Attach it using fallbacks.' %
self._idx)
self.__uuid__)


class DelayedLoader(object):
Expand All @@ -114,7 +114,7 @@ class DelayedLoader(object):
def __get__(self, instance, owner):
if instance is not None:
obj = instance._lazy[self]
if hasattr(obj, '_idx'):
if isinstance(obj, LoaderProxy):
return obj.__subject__
else:
return obj
Expand Down
4 changes: 0 additions & 4 deletions openpathsampling/tests/test_collectivevariable.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,6 @@ def test_storage_cv_function(self):
assert (cv_cache.allow_incomplete == allow_incomplete)

for idx, snap in enumerate(storage_r.trajectories[1]):
# print idx, snap
# if hasattr(snap, '_idx'):
# print 'Proxy IDX', snap._idx

# print 'ITEMS', storage_r.snapshots.index.items()
# print snap, type(snap), snap.__dict__

Expand Down