Example #1
0
 def test_instantaneous_temperature(self):
     vel_unit = u.nanometers / u.picoseconds
     new_velocities = [[1.0, 0.0, 0.0]] * self.n_atoms * vel_unit
     self.engine.current_snapshot = omm_engine.Snapshot.construct(
         coordinates=self.engine.current_snapshot.coordinates,
         box_vectors=self.engine.current_snapshot.box_vectors,
         velocities=new_velocities,
         engine=self.engine)
     test_snap = self.engine.current_snapshot
     expected_ke = sum([m * vel_unit**2 for m in test_snap.masses],
                       0.0 * u.joule)
     n_dofs = 51.0  # see test above
     assert_close_unit(test_snap.instantaneous_temperature,
                       expected_ke / u.BOLTZMANN_CONSTANT_kB / n_dofs)
Example #2
0
 def test_instantaneous_temperature(self):
     vel_unit = u.nanometers / u.picoseconds
     new_velocities = [[1.0, 0.0, 0.0]] * self.n_atoms * vel_unit
     self.engine.current_snapshot = omm_engine.Snapshot.construct(
         coordinates=self.engine.current_snapshot.coordinates,
         box_vectors=self.engine.current_snapshot.box_vectors,
         velocities=new_velocities,
         engine=self.engine
     )
     test_snap = self.engine.current_snapshot
     expected_ke = sum(
         [m * vel_unit**2 for m in test_snap.masses], 
         0.0*u.joule
     )
     n_dofs = 51.0  # see test above
     assert_close_unit(test_snap.instantaneous_temperature,
                       expected_ke / u.BOLTZMANN_CONSTANT_kB / n_dofs)
Example #3
0
def compate_attribute(snapshot_class, attr_name, attr_value, attr_reversal_fnc):
    a = snapshot_class(**{attr_name: attr_value})
    b = a.copy()
    c = a.create_reversed()
    d = a.reversed

    assert_close_unit(getattr(a, attr_name), attr_value)
    assert(getattr(a, attr_name) is not getattr(b, attr_name))
    assert_close_unit(getattr(a, attr_name), getattr(b, attr_name))
    assert_close_unit(getattr(a, attr_name), attr_reversal_fnc(getattr(c, attr_name)))
    assert_close_unit(getattr(a, attr_name), attr_reversal_fnc(getattr(d, attr_name)))
Example #4
0
def compate_attribute(snapshot_class, attr_name, attr_value,
                      attr_reversal_fnc):
    a = snapshot_class(**{attr_name: attr_value})
    b = a.copy()
    c = a.create_reversed()
    d = a.reversed

    assert_close_unit(getattr(a, attr_name), attr_value)
    assert (getattr(a, attr_name) is not getattr(b, attr_name))
    assert_close_unit(getattr(a, attr_name), getattr(b, attr_name))
    assert_close_unit(getattr(a, attr_name),
                      attr_reversal_fnc(getattr(c, attr_name)))
    assert_close_unit(getattr(a, attr_name),
                      attr_reversal_fnc(getattr(d, attr_name)))
Example #5
0
    def test_storage_cv_function(self):
        import os

        # test all combinations of (1) with and without UUIDs,
        # (2) using partial yes, no all of these must work
        for use_uuid, allow_incomplete in [(True, True), (False, True),
                                        (True, False), (False, False)]:

            # print '=========================================================='
            # print 'UUID', use_uuid, 'PARTIAL', allow_incomplete
            # print '=========================================================='

            fname = data_filename("cv_storage_test.nc")
            if os.path.isfile(fname):
                os.remove(fname)

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

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

            cv1 = paths.CoordinateFunctionCV(
                'f1',
                lambda x: x.coordinates[0]
            ).with_diskcache(
                allow_incomplete=allow_incomplete
            )

            storage_w.save(cv1)

            # let's mess up the order in which we save and
            # include reversed ones as well
            assert (len(storage_w.snapshots) == 2)
            storage_w.trajectories.save(traj[3:])
            assert (len(storage_w.snapshots) == 16)
            storage_w.snapshots.save(traj[1].reversed)
            assert (len(storage_w.snapshots) == 18)
            storage_w.trajectories.save(traj.reversed)
            assert (len(storage_w.snapshots) == 20)

            # this should be ignored for all is saved already
            storage_w.trajectories.save(traj)
            storage_w.close()

            storage_r = paths.AnalysisStorage(fname)
            rcv1 = storage_r.cvs['f1']

            assert(rcv1._store_dict)

            cv_cache = rcv1._store_dict.value_store

            assert (cv_cache.allow_incomplete == allow_incomplete)

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

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

                # print snap.__uuid__
                # print snap.reversed.__uuid__
                # print snap.create_reversed().__uuid__
                #
                # print 'POS', cv_cache.snapshot_pos(snap),
                # print 'POS', storage_r.snapshots.pos(snap),
                # print 'POS', storage_r.snapshots.index[snap]
                #
                # print 'POS', cv_cache.snapshot_pos(snap.reversed),
                # print 'POS', storage_r.snapshots.pos(snap.reversed),
                # print 'POS', storage_r.snapshots.index[snap.reversed]

                # if len(cv_cache.cache._chunkdict) > 0:
                #
                #     if allow_incomplete:
                #         print cv_cache.index
                #         print cv_cache.vars['value'][:]
                #
                #     for n, v in enumerate(cv_cache.cache._chunkdict[0]):
                #         print n, v
                #
                # print cv1(snap)
                # print cv1(snap.reversed)
                # print cv_cache[snap]
                #
                # print cv_cache[snap.reversed]

                if not allow_incomplete or cv_cache[snap] is not None:
                    assert_close_unit(cv_cache[snap], cv1(snap))
                    assert_close_unit(
                        cv_cache[snap.reversed],
                        cv1(snap.reversed))

            storage_r.close()

            if os.path.isfile(fname):
                os.remove(fname)
Example #6
0
    def test_storage_sync(self):
        import os

        # test all combinations of (1) with and without UUIDs,
        # (2) using partial yes; all of these must work

        allow_incomplete = True

        # print
        # print

        for use_uuid in [True, False]:

            # print '=========================================================='
            # print 'UUID', use_uuid
            # print '=========================================================='

            fname = data_filename("cv_storage_test.nc")
            if os.path.isfile(fname):
                os.remove(fname)

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

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

            cv1 = paths.CoordinateFunctionCV(
                'f1',
                lambda snapshot: snapshot.coordinates[0]
            ).with_diskcache(
                allow_incomplete=allow_incomplete)

            # let's mess up the order in which we save and
            # include reversed ones as well
            assert (len(storage_w.snapshots) == 2)
            storage_w.trajectories.save(traj[6:])
            assert (len(storage_w.snapshots) == 10)
            storage_w.snapshots.save(traj[1].reversed)
            assert (len(storage_w.snapshots) == 12)

            storage_w.save(cv1)

            store = storage_w.cvs.cache_store(cv1)
            assert (len(store.vars['value']) == 0)
            storage_w.snapshots.sync_cv(cv1)

            # nothing added to the cache so no changes
            assert (len(store.vars['value']) == 1)

            # fill the cache
            _ = cv1(traj)

            storage_w.snapshots.sync_cv(cv1)

            # should match the number of stored snapshots
            assert (len(store.vars['value']) == 6)

            # save the rest
            storage_w.trajectories.save(traj.reversed)
            assert (len(storage_w.snapshots) == 20)

            # should still be unchanged
            assert (len(store.vars['value']) == 6)

            # this should store the remaining CV values

            storage_w.snapshots.sync_cv(cv1)
            assert (len(store.vars['value']) == 10)

            # check if the values match
            for idx, value in zip(
                    store.variables['index'][:],
                    store.vars['value']):
                if use_uuid:

                    snap = storage_w.snapshots[
                        storage_w.snapshots.vars['uuid'][idx]]
                else:
                    # * 2 because we use a symmetric cv
                    snap = storage_w.snapshots[int(idx) * 2]

                assert_close_unit(cv1(snap), value)

            storage_w.close()

            if os.path.isfile(fname):
                os.remove(fname)
    def test_storage_cv_function(self):
        import os

        # test all combinations of (1) with and without UUIDs,
        # (2) using partial yes, no all of these must work
        for allow_incomplete in (True, False):

            # print '=========================================================='
            # print 'PARTIAL', allow_incomplete
            # print '=========================================================='

            fname = data_filename("cv_storage_test.nc")
            if os.path.isfile(fname):
                os.remove(fname)

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

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

            cv1 = paths.CoordinateFunctionCV(
                'f1', lambda x: x.coordinates[0]).with_diskcache(
                    allow_incomplete=allow_incomplete)

            storage_w.save(cv1)

            # let's mess up the order in which we save and
            # include reversed ones as well
            assert (len(storage_w.snapshots) == 2)
            storage_w.trajectories.save(traj[3:])
            assert (len(storage_w.snapshots) == 16)
            storage_w.snapshots.save(traj[1].reversed)
            assert (len(storage_w.snapshots) == 18)
            storage_w.trajectories.save(traj.reversed)
            assert (len(storage_w.snapshots) == 20)

            # this should be ignored for all is saved already
            storage_w.trajectories.save(traj)
            storage_w.close()

            storage_r = paths.AnalysisStorage(fname)
            rcv1 = storage_r.cvs['f1']

            assert (rcv1._store_dict)

            cv_cache = rcv1._store_dict.value_store

            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__

                # print snap.__uuid__
                # print snap.reversed.__uuid__
                # print snap.create_reversed().__uuid__
                #
                # print 'POS', cv_cache.snapshot_pos(snap),
                # print 'POS', storage_r.snapshots.pos(snap),
                # print 'POS', storage_r.snapshots.index[snap]
                #
                # print 'POS', cv_cache.snapshot_pos(snap.reversed),
                # print 'POS', storage_r.snapshots.pos(snap.reversed),
                # print 'POS', storage_r.snapshots.index[snap.reversed]

                # if len(cv_cache.cache._chunkdict) > 0:
                #
                #     if allow_incomplete:
                #         print cv_cache.index
                #         print cv_cache.vars['value'][:]
                #
                #     for n, v in enumerate(cv_cache.cache._chunkdict[0]):
                #         print n, v
                #
                # print cv1(snap)
                # print cv1(snap.reversed)
                # print cv_cache[snap]
                #
                # print cv_cache[snap.reversed]

                if not allow_incomplete or cv_cache[snap] is not None:
                    assert_close_unit(cv_cache[snap], cv1(snap))
                    assert_close_unit(cv_cache[snap.reversed],
                                      cv1(snap.reversed))

            storage_r.close()

            if os.path.isfile(fname):
                os.remove(fname)
    def test_storage_sync(self):
        import os

        # test all combinations of (1) with and without UUIDs,
        # (2) using partial yes; all of these must work

        allow_incomplete = True

        # print
        # print

        for use_uuid in [True]:

            # print '=========================================================='
            # print 'UUID', use_uuid
            # print '=========================================================='

            fname = data_filename("cv_storage_test.nc")
            if os.path.isfile(fname):
                os.remove(fname)

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

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

            cv1 = paths.CoordinateFunctionCV(
                'f1', lambda snapshot: snapshot.coordinates[0]).with_diskcache(
                    allow_incomplete=allow_incomplete)

            # let's mess up the order in which we save and
            # include reversed ones as well
            assert (len(storage_w.snapshots) == 2)
            storage_w.trajectories.save(traj[6:])
            assert (len(storage_w.snapshots) == 10)
            storage_w.snapshots.save(traj[1].reversed)
            assert (len(storage_w.snapshots) == 12)

            storage_w.save(cv1)

            store = storage_w.cvs.cache_store(cv1)
            assert (len(store.vars['value']) == 0)
            storage_w.snapshots.sync_cv(cv1)

            # nothing added to the cache so no changes
            assert (len(store.vars['value']) == 1)

            # fill the cache
            _ = cv1(traj)

            storage_w.snapshots.sync_cv(cv1)

            # should match the number of stored snapshots
            assert (len(store.vars['value']) == 6)

            # save the rest
            storage_w.trajectories.save(traj.reversed)
            assert (len(storage_w.snapshots) == 20)

            # should still be unchanged
            assert (len(store.vars['value']) == 6)

            # this should store the remaining CV values

            storage_w.snapshots.sync_cv(cv1)
            assert (len(store.vars['value']) == 10)

            # check if the values match
            for idx, value in zip(store.variables['index'][:],
                                  store.vars['value']):
                snap = storage_w.snapshots[storage_w.snapshots.vars['uuid']
                                           [idx]]

                assert_close_unit(cv1(snap), value)

            storage_w.close()

            if os.path.isfile(fname):
                os.remove(fname)
    def test_storage_sync_and_complete(self):
        import os

        # test all combinations of (1) with and without UUIDs,
        # (2) using partial yes, no all of these must work

        allow_incomplete = True

        # print
        # print

        for use_uuid in [True]:

            # print '=========================================================='
            # print 'UUID', use_uuid
            # print '=========================================================='

            fname = data_filename("cv_storage_test.nc")
            if os.path.isfile(fname):
                os.remove(fname)

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

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

            cv1 = paths.CoordinateFunctionCV(
                'f1', lambda snapshot: snapshot.coordinates[0]).with_diskcache(
                    allow_incomplete=allow_incomplete)

            # let's mess up the order in which we save and include
            # reversed ones as well
            assert (len(storage_w.snapshots) == 2)
            storage_w.trajectories.save(traj[3:])
            assert (len(storage_w.snapshots) == 16)
            storage_w.snapshots.save(traj[1].reversed)
            assert (len(storage_w.snapshots) == 18)
            storage_w.trajectories.save(traj.reversed)
            assert (len(storage_w.snapshots) == 20)

            storage_w.save(cv1)

            store = storage_w.cvs.cache_store(cv1)
            assert (len(store.vars['value']) == 0)

            storage_w.snapshots.complete_cv(cv1)
            assert (len(store.vars['value']) == 10)

            # check if stored values match computed ones
            for idx, value in zip(store.variables['index'][:],
                                  store.vars['value']):
                snap = storage_w.snapshots[storage_w.snapshots.vars['uuid']
                                           [idx]]

                assert_close_unit(cv1(snap), value)

            storage_w.close()

            if os.path.isfile(fname):
                os.remove(fname)