コード例 #1
0
    def test_clone(self):
        store = Storage(filename=self.filename, template=self.template_snapshot, mode='w')
        assert(os.path.isfile(self.filename))

        copy = self.template_snapshot.copy()
        store.save(copy)

        store.save(self.traj)

        store.clone(filename=self.filename_clone, subset = self.solute_indices)

        # clone the storage and reduce the number of atoms to only solute

        store2 = Storage(filename=self.filename_clone, mode='a')

        # do some tests, if this is still the same data

        compare_snapshot(
            store2.snapshots.load(0),
            store.snapshots.load(0).subset(self.solute_indices)
        )

        compare_snapshot(
            store2.snapshots.load(1),
            store.snapshots.load(1).subset(self.solute_indices)
        )
        store.close()
        store2.close()

        pass
コード例 #2
0
ファイル: teststorage.py プロジェクト: JM-YE/openpathsampling
    def test_clone_empty(self):
        store = Storage(filename=self.filename, template=self.template_snapshot, mode='w')
        assert(os.path.isfile(self.filename))

        copy = self.template_snapshot.copy()
        store.save(copy)

        store.save(self.traj)
        store.clone_empty(filename=self.filename_clone)

        # clone the storage and reduce the number of atoms to only solute

        store2 = Storage(filename=self.filename_clone, mode='a')

        # do some tests, if this is still the same data

        compare_snapshot(
            store2.snapshots.load(0),
            store.snapshots.load(0)
        )

        # check if the reversed copy also works
        compare_snapshot(
            store2.snapshots.load(1),
            store.snapshots.load(1)
        )

        assert_equal(len(store2.snapshots), 2)
        assert_equal(len(store2.trajectories), 0)

        store.close()
        store2.close()

        pass
コード例 #3
0
    def test_clone_empty(self):
        store = Storage(filename=self.filename, template=self.template_snapshot, mode='w')
        assert(os.path.isfile(self.filename))

        copy = self.template_snapshot.copy()
        store.save(copy)

        store.save(self.traj)
        store.clone_empty(filename=self.filename_clone)

        # clone the storage and reduce the number of atoms to only solute

        store2 = Storage(filename=self.filename_clone, mode='a')

        # do some tests, if this is still the same data

        compare_snapshot(
            store2.snapshots.load(0),
            store.snapshots.load(0)
        )

        # check if the reversed copy also works
        compare_snapshot(
            store2.snapshots.load(1),
            store.snapshots.load(1)
        )

        assert_equal(len(store2.snapshots), 2)
        assert_equal(len(store2.trajectories), 0)

        store.close()
        store2.close()

        pass
コード例 #4
0
ファイル: teststorage.py プロジェクト: JM-YE/openpathsampling
    def test_clone(self):
        store = Storage(filename=self.filename, template=self.template_snapshot, mode='w')
        assert(os.path.isfile(self.filename))

        copy = self.template_snapshot.copy()
        store.save(copy)

        store.save(self.traj)

        store.clone(filename=self.filename_clone, subset = self.solute_indices)

        # clone the storage and reduce the number of atoms to only solute

        store2 = Storage(filename=self.filename_clone, mode='a')

        # do some tests, if this is still the same data

        compare_snapshot(
            store2.snapshots.load(0),
            store.snapshots.load(0).subset(self.solute_indices)
        )

        compare_snapshot(
            store2.snapshots.load(1),
            store.snapshots.load(1).subset(self.solute_indices)
        )
        store.close()
        store2.close()

        pass
コード例 #5
0
    def test_mention_only(self):
        storage_w = paths.Storage(self.filename, "w", use_uuid=True)

        template = self.template_snapshot

        storage_w.snapshots.add_type(template)

        test_snap = self.traj[2]

        # only touch a new snapshot
        storage_w.snapshots.only_mention = True
        storage_w.snapshots.save(test_snap)

        # check that the snapshot is there
        assert(len(storage_w.snapshots) == 4)
        # in the memory uuid index
        assert(test_snap.__uuid__ in storage_w.snapshots.index)
        # and stored
        assert(test_snap.__uuid__ == storage_w.snapshots.vars['uuid'][1])

        # but no real snapshot has been stored
        # print len(storage_w.objects['snapshot0'])
        assert(len(storage_w.objects['snapshot0']) == 2)

        # switch on normal saving
        storage_w.snapshots.only_mention = False

        test_snap = self.traj[4]
        storage_w.snapshots.mention(test_snap)

        # check that the snapshot is there
        assert(len(storage_w.snapshots) == 6)
        # in the memory uuid index
        assert(test_snap.__uuid__ in storage_w.snapshots.index)
        # and stored
        assert(test_snap.__uuid__ == storage_w.snapshots.vars['uuid'][2])

        # but no real snapshot has been stored
        assert(len(storage_w.objects['snapshot0']) == 2)

        # try to now add it
        storage_w.snapshots.save(test_snap)

        # check that the snapshot is not stored again (only 3 snapshots)
        assert(len(storage_w.snapshots) == 6)
        assert(len(storage_w.objects['snapshot0']) == 4)

        # print storage_w.objects['snapshot0'][1].coordinates
        # print template.coordinates
        # print storage_w.objects['snapshot0'][0].coordinates
        # print test_snap.coordinates
        # print storage_w.objects['snapshot0'].vars['statics'][0].coordinates
        # print storage_w.objects['snapshot0'].vars['statics'][1].coordinates
        # print storage_w.objects['snapshot0'].index

        compare_snapshot(storage_w.objects['snapshot0'][4], test_snap)
コード例 #6
0
    def test_mention_only(self):
        storage_w = paths.Storage(self.filename, "w", use_uuid=True)

        template = self.template_snapshot

        storage_w.snapshots.add_type(template)

        test_snap = self.traj[2]

        # only touch a new snapshot
        storage_w.snapshots.only_mention = True
        storage_w.snapshots.save(test_snap)

        # check that the snapshot is there
        assert (len(storage_w.snapshots) == 4)
        # in the memory uuid index
        assert (test_snap.__uuid__ in storage_w.snapshots.index)
        # and stored
        assert (test_snap.__uuid__ == storage_w.snapshots.vars['uuid'][1])

        # but no real snapshot has been stored
        # print len(storage_w.objects['snapshot0'])
        assert (len(storage_w.objects['snapshot0']) == 2)

        # switch on normal saving
        storage_w.snapshots.only_mention = False

        test_snap = self.traj[4]
        storage_w.snapshots.mention(test_snap)

        # check that the snapshot is there
        assert (len(storage_w.snapshots) == 6)
        # in the memory uuid index
        assert (test_snap.__uuid__ in storage_w.snapshots.index)
        # and stored
        assert (test_snap.__uuid__ == storage_w.snapshots.vars['uuid'][2])

        # but no real snapshot has been stored
        assert (len(storage_w.objects['snapshot0']) == 2)

        # try to now add it
        storage_w.snapshots.save(test_snap)

        # check that the snapshot is not stored again (only 3 snapshots)
        assert (len(storage_w.snapshots) == 6)
        assert (len(storage_w.objects['snapshot0']) == 4)

        # print storage_w.objects['snapshot0'][1].coordinates
        # print template.coordinates
        # print storage_w.objects['snapshot0'][0].coordinates
        # print test_snap.coordinates
        # print storage_w.objects['snapshot0'].vars['statics'][0].coordinates
        # print storage_w.objects['snapshot0'].vars['statics'][1].coordinates
        # print storage_w.objects['snapshot0'].index

        compare_snapshot(storage_w.objects['snapshot0'][4], test_snap)
コード例 #7
0
ファイル: teststorage.py プロジェクト: JM-YE/openpathsampling
    def test_stored_template(self):
        store = Storage(filename=self.filename, template=self.template_snapshot, mode='w')
        assert(os.path.isfile(self.filename))
        store.close()

        store = Storage(filename=self.filename, mode='a')
        loaded_template = store.template

        compare_snapshot(loaded_template, self.template_snapshot)

        store.close()
コード例 #8
0
    def test_stored_template(self):
        store = Storage(filename=self.filename, template=self.template_snapshot, mode='w')
        assert(os.path.isfile(self.filename))
        store.close()

        store = Storage(filename=self.filename, mode='a')
        loaded_template = store.template

        compare_snapshot(loaded_template, self.template_snapshot)

        store.close()
コード例 #9
0
    def test_load_save(self):
        store = Storage(filename=self.filename, template=self.template_snapshot, mode='w')
        assert(os.path.isfile(self.filename))

        copy = self.template_snapshot.copy()
        store.save(copy)

        store.close()

        store = Storage(filename=self.filename, mode='a')
        loaded_template = store.template

        compare_snapshot(loaded_template, self.template_snapshot)
        loaded_copy = store.load(Snapshot, 1)

        compare_snapshot(loaded_template, loaded_copy)

        store.close()
コード例 #10
0
ファイル: teststorage.py プロジェクト: JM-YE/openpathsampling
    def test_load_save(self):
        store = Storage(filename=self.filename, template=self.template_snapshot, mode='w')
        assert(os.path.isfile(self.filename))

        copy = self.template_snapshot.copy()
        store.save(copy)

        store.close()

        store = Storage(filename=self.filename, mode='a')
        loaded_template = store.template

        compare_snapshot(loaded_template, self.template_snapshot)
        loaded_copy = store.load(Snapshot, 1)

        compare_snapshot(loaded_template, loaded_copy)

        store.close()
コード例 #11
0
    def test_proxy(self):
        for use_uuid in [True, False]:
            store = Storage(filename=self.filename,
                            mode='w',
                            use_uuid=use_uuid)
            assert (os.path.isfile(self.filename))

            tm = self.template_snapshot

            store.save(tm)

            px = store.snapshots.proxy(0)

            # make sure that the proxy and
            assert (hash(px) == hash(tm))
            assert (px == tm)

            store.snapshots.cache.clear()
            s0 = store.snapshots[0]

            assert (hash(px) == hash(s0))
            assert (px == s0)

            compare_snapshot(px, tm)
            compare_snapshot(s0, tm)

            px = store.snapshots.proxy(0)

            # make sure that after reloading it still works
            assert (hash(px) == hash(tm))
            assert (px == tm)

            store.close()

            store = Storage(filename=self.filename, mode='a')

            s1 = store.snapshots[0]

            store.close()

            # when loading only for uuid based storages you get the same id
            assert ((hash(px) == hash(s1)) is use_uuid)
            assert ((px == s1) is use_uuid)
コード例 #12
0
    def test_proxy(self):
        for use_uuid in [True, False]:
            store = Storage(filename=self.filename, mode='w', use_uuid=use_uuid)
            assert(os.path.isfile(self.filename))

            tm = self.template_snapshot

            store.save(tm)

            px = store.snapshots.proxy(0)

            # make sure that the proxy and
            assert(hash(px) == hash(tm))
            assert(px == tm)

            store.snapshots.cache.clear()
            s0 = store.snapshots[0]

            assert(hash(px) == hash(s0))
            assert(px == s0)

            compare_snapshot(px, tm)
            compare_snapshot(s0, tm)

            px = store.snapshots.proxy(0)

            # make sure that after reloading it still works
            assert(hash(px) == hash(tm))
            assert(px == tm)

            store.close()

            store = Storage(filename=self.filename, mode='a')

            s1 = store.snapshots[0]

            store.close()

            # when loading only for uuid based storages you get the same id
            assert((hash(px) == hash(s1)) is use_uuid)
            assert((px == s1) is use_uuid)
コード例 #13
0
    def test_load_save_uuid(self):
        store = Storage(filename=self.filename, mode='w')
        assert (os.path.isfile(self.filename))

        store.save(self.template_snapshot)
        store.close()

        store = Storage(filename=self.filename, mode='a')
        loaded_template = store.snapshots[self.template_snapshot.__uuid__]
        loaded_r = store.snapshots[self.template_snapshot.reversed.__uuid__]

        compare_snapshot(loaded_template, self.template_snapshot, True)
        compare_snapshot(loaded_template.reversed,
                         self.template_snapshot.reversed, True)
        compare_snapshot(loaded_r, self.template_snapshot.reversed)

        store.close()
コード例 #14
0
    def test_load_save_uuid(self):
        store = Storage(filename=self.filename, mode='w')
        assert(os.path.isfile(self.filename))

        store.save(self.template_snapshot)
        store.close()

        store = Storage(filename=self.filename, mode='a')
        loaded_template = store.snapshots[self.template_snapshot.__uuid__]
        loaded_r = store.snapshots[self.template_snapshot.reversed.__uuid__]

        compare_snapshot(loaded_template, self.template_snapshot, True)
        compare_snapshot(
            loaded_template.reversed,
            self.template_snapshot.reversed, True)
        compare_snapshot(loaded_r, self.template_snapshot.reversed)

        store.close()
コード例 #15
0
    def test_load_save_toy(self):
        store = Storage(filename=self.filename, mode='w', use_uuid=False)
        assert (os.path.isfile(self.filename))

        store.save(self.toy_template)

        store.close()

        store = Storage(filename=self.filename, mode='a')
        loaded_template = store.snapshots[0]
        loaded_r = store.snapshots[1]

        compare_snapshot(loaded_template, self.toy_template, True)
        compare_snapshot(loaded_template.reversed, self.toy_template.reversed,
                         True)
        compare_snapshot(loaded_r, self.toy_template.reversed)

        store.close()
コード例 #16
0
    def test_load_save_toy(self):
        store = Storage(filename=self.filename, mode='w', use_uuid=False)
        assert(os.path.isfile(self.filename))

        store.save(self.toy_template)

        store.close()

        store = Storage(filename=self.filename, mode='a')
        loaded_template = store.snapshots[0]
        loaded_r = store.snapshots[1]

        compare_snapshot(loaded_template, self.toy_template, True)
        compare_snapshot(
            loaded_template.reversed,
            self.toy_template.reversed, True)
        compare_snapshot(loaded_r, self.toy_template.reversed)

        store.close()
コード例 #17
0
    def test_load_save(self):
        for use_uuid in [True, False]:
            store = Storage(filename=self.filename, mode='w', use_uuid=use_uuid)
            assert(os.path.isfile(self.filename))

            store.save(self.template_snapshot)
            store.close()

            store = Storage(filename=self.filename, mode='a')
            loaded_template = store.snapshots[0]
            loaded_r = store.snapshots[1]

            compare_snapshot(loaded_template, self.template_snapshot, True)
            compare_snapshot(
                loaded_template.reversed,
                self.template_snapshot.reversed, True)
            compare_snapshot(loaded_r, self.template_snapshot.reversed)

            store.close()
コード例 #18
0
    def test_load_save(self):
        for use_uuid in [True, False]:
            store = Storage(filename=self.filename,
                            mode='w',
                            use_uuid=use_uuid)
            assert (os.path.isfile(self.filename))

            store.save(self.template_snapshot)
            store.close()

            store = Storage(filename=self.filename, mode='a')
            loaded_template = store.snapshots[0]
            loaded_r = store.snapshots[1]

            compare_snapshot(loaded_template, self.template_snapshot, True)
            compare_snapshot(loaded_template.reversed,
                             self.template_snapshot.reversed, True)
            compare_snapshot(loaded_r, self.template_snapshot.reversed)

            store.close()
コード例 #19
0
    def test_store_snapshots(self):
        fname = data_filename("cv_storage_test.nc")
        if os.path.isfile(fname):
            os.remove(fname)

        traj = paths.Trajectory(list(self.traj))
        template = traj[0]

        for use_uuid, use_cache in [(True, True), (False, True), (True, False),
                                    (False, False)]:
            # print '=========================================================='
            # print 'UUID', use_uuid, 'CACHE', use_cache
            # print '=========================================================='

            storage_w = paths.Storage(fname, "w", use_uuid=use_uuid)
            storage_w.snapshots.save(template)

            # let's mess up the order in which we save and include
            # reversed ones as well

            assert (len(storage_w.snapshots) == 2)
            assert (len(storage_w.trajectories) == 0)
            assert (len(storage_w.stores['snapshot0']) == 2)
            storage_w.snapshots.save(traj[8].reversed)
            assert (len(storage_w.snapshots) == 4)
            assert (len(storage_w.trajectories) == 0)
            assert (len(storage_w.stores['snapshot0']) == 4)
            # this will store traj[6:] under pos IDX #0
            storage_w.trajectories.save(traj[6:])
            assert (len(storage_w.snapshots) == 10)
            assert (len(storage_w.trajectories) == 1)
            assert (len(storage_w.stores['snapshot0']) == 10)

            traj_rev = traj.reversed

            # this will store traj_rev under pos IDX #1
            storage_w.trajectories.mention(traj_rev)
            assert (len(storage_w.snapshots) == 20)
            assert (len(storage_w.trajectories) == 2)
            assert (len(storage_w.stores['snapshot0']) == 10)

            # this will not do anything since traj is already saved
            storage_w.trajectories.save(traj_rev)
            assert (len(storage_w.snapshots) == 20)
            assert (len(storage_w.trajectories) == 2)
            assert (len(storage_w.stores['snapshot0']) == 10)

            # this will store traj under pos IDX #2
            storage_w.trajectories.save(traj)
            assert (len(storage_w.snapshots) == 20)
            assert (len(storage_w.trajectories) == 3)
            assert (len(storage_w.stores['snapshot0']) == 20)

            # this will not store since traj is already stored
            storage_w.trajectories.save(traj)
            assert (len(storage_w.snapshots) == 20)
            assert (len(storage_w.trajectories) == 3)
            assert (len(storage_w.stores['snapshot0']) == 20)

            # we saved in this order [0f, 8r, 6f, 7f, 9f, 5r, 4r, 3r, 2r, 1r ]
            # these are indices      [ 0, 17, 12, 14, 18,  3,  5,  7,  9, 11 ]

            storage_w.close()

            if use_cache:
                storage_r = paths.AnalysisStorage(fname)
            else:
                storage_r = paths.Storage(fname, 'r')
                storage_r.snapshots.set_caching(False)
                storage_r.stores['snapshot0'].set_caching(False)

            # check if the loaded trajectory is reproduced
            for s1, s2 in zip(traj, storage_r.trajectories[2]):
                compare_snapshot(s1, s2, True)

            # this is the expected order in which it is saved
            eff_traj = [
                traj[0],
                traj[8].reversed,
                traj[6],
                traj[7],
                traj[9],
                traj[5].reversed,
                traj[4].reversed,
                traj[3].reversed,
                traj[2].reversed,
                traj[1].reversed,
            ]

            # load from hidden and see, if the hidden store looks as expected
            # we open every second snapshot from the hidden store because the
            # ones in between correspond to the reversed ones

            hidden_snapshots = storage_r.stores['snapshot0'][:]
            for idx in range(10):
                s1 = eff_traj[idx]
                s1r = s1.reversed
                s2 = hidden_snapshots[2 * idx]
                s2r = hidden_snapshots[2 * idx + 1]
                compare_snapshot(s1, s2, True)
                compare_snapshot(s1r, s2r, True)

            storage_r.close()
コード例 #20
0
    def test_store_snapshots(self):
        fname = data_filename("cv_storage_test.nc")
        if os.path.isfile(fname):
            os.remove(fname)

        traj = paths.Trajectory(list(self.traj))
        template = traj[0]

        for use_uuid, use_cache in [
                (True, True), (False, True), (True, False), (False, False)]:
            # print '=========================================================='
            # print 'UUID', use_uuid, 'CACHE', use_cache
            # print '=========================================================='

            storage_w = paths.Storage(fname, "w", use_uuid=use_uuid)
            storage_w.snapshots.save(template)

            # let's mess up the order in which we save and include
            # reversed ones as well

            assert(len(storage_w.snapshots) == 2)
            assert(len(storage_w.trajectories) == 0)
            assert(len(storage_w.stores['snapshot0']) == 2)
            storage_w.snapshots.save(traj[8].reversed)
            assert(len(storage_w.snapshots) == 4)
            assert(len(storage_w.trajectories) == 0)
            assert(len(storage_w.stores['snapshot0']) == 4)
            # this will store traj[6:] under pos IDX #0
            storage_w.trajectories.save(traj[6:])
            assert(len(storage_w.snapshots) == 10)
            assert(len(storage_w.trajectories) == 1)
            assert(len(storage_w.stores['snapshot0']) == 10)

            traj_rev = traj.reversed

            # this will store traj_rev under pos IDX #1
            storage_w.trajectories.mention(traj_rev)
            assert(len(storage_w.snapshots) == 20)
            assert(len(storage_w.trajectories) == 2)
            assert(len(storage_w.stores['snapshot0']) == 10)

            # this will not do anything since traj is already saved
            storage_w.trajectories.save(traj_rev)
            assert(len(storage_w.snapshots) == 20)
            assert(len(storage_w.trajectories) == 2)
            assert(len(storage_w.stores['snapshot0']) == 10)

            # this will store traj under pos IDX #2
            storage_w.trajectories.save(traj)
            assert(len(storage_w.snapshots) == 20)
            assert(len(storage_w.trajectories) == 3)
            assert(len(storage_w.stores['snapshot0']) == 20)

            # this will not store since traj is already stored
            storage_w.trajectories.save(traj)
            assert(len(storage_w.snapshots) == 20)
            assert(len(storage_w.trajectories) == 3)
            assert(len(storage_w.stores['snapshot0']) == 20)

            # we saved in this order [0f, 8r, 6f, 7f, 9f, 5r, 4r, 3r, 2r, 1r ]
            # these are indices      [ 0, 17, 12, 14, 18,  3,  5,  7,  9, 11 ]

            storage_w.close()

            if use_cache:
                storage_r = paths.AnalysisStorage(fname)
            else:
                storage_r = paths.Storage(fname, 'r')
                storage_r.snapshots.set_caching(False)
                storage_r.stores['snapshot0'].set_caching(False)

            # check if the loaded trajectory is reproduced
            for s1, s2 in zip(traj, storage_r.trajectories[2]):
                compare_snapshot(s1, s2, True)

            # this is the expected order in which it is saved
            eff_traj = [
                traj[0],
                traj[8].reversed,
                traj[6],
                traj[7],
                traj[9],
                traj[5].reversed,
                traj[4].reversed,
                traj[3].reversed,
                traj[2].reversed,
                traj[1].reversed,
            ]

            # load from hidden and see, if the hidden store looks as expected
            # we open every second snapshot from the hidden store because the
            # ones in between correspond to the reversed ones

            hidden_snapshots = storage_r.stores['snapshot0'][:]
            for idx in range(10):
                s1 = eff_traj[idx]
                s1r = s1.reversed
                s2 = hidden_snapshots[2 * idx]
                s2r = hidden_snapshots[2 * idx + 1]
                compare_snapshot(s1, s2, True)
                compare_snapshot(s1r, s2r, True)

            storage_r.close()