def test_fail_without_lambdas(self):
     fake_ifaceA = paths.InterfaceSet(cv=self.ifacesA.cv,
                                      volumes=self.ifacesA.volumes,
                                      direction=self.ifacesA.direction)
     network = paths.MISTISNetwork([(self.stateA, fake_ifaceA, self.stateB)
                                    ])
     network.sampling_transitions[0].tcp = self.tcp_A
     bias = paths.SRTISBiasFromNetwork(network)
    def test_bias_from_ms_network(self):
        ms_outer = paths.MSOuterTISInterface.from_lambdas({
            self.ifacesA: -0.1,
            self.ifacesB: 0.1
        })
        network = paths.MISTISNetwork(
            [(self.stateA, self.ifacesA, self.stateB),
             (self.stateB, self.ifacesB, self.stateA)],
            ms_outers=[ms_outer])
        transition_AB = None
        transition_BA = None
        for t in network.sampling_transitions:
            if t.stateA == self.stateA:
                t.tcp = self.tcp_A
                transition_AB = t
            elif t.stateA == self.stateB:
                t.tcp = self.tcp_B
                transition_BA = t
            else:
                print([t.stateA, t.stateB])
                print([self.stateA, self.stateB])
                raise RuntimeError("Weird states in test transition")

        bias = paths.SRTISBiasFromNetwork(network)

        n_ensembles = len(bias.dataframe.index)
        for i in range(n_ensembles):
            for j in range(i, n_ensembles):
                if not np.isnan(bias.dataframe.loc[i, j]):
                    np.testing.assert_almost_equal(
                        bias.dataframe.loc[i, j],
                        old_div(1.0, bias.dataframe.loc[j, i]))

        for i in range(len(transition_AB.ensembles) - 1):
            ens_to = transition_AB.ensembles[i]
            ens_from = transition_AB.ensembles[i + 1]
            assert_almost_equal(bias.bias_value(ens_from, ens_to), 0.5)

        for i in range(len(transition_BA.ensembles) - 1):
            ens_to = transition_BA.ensembles[i]
            ens_from = transition_BA.ensembles[i + 1]
            assert_almost_equal(bias.bias_value(ens_from, ens_to), 0.2)

        for ensA in transition_AB.ensembles:
            for ensB in transition_BA.ensembles:
                assert_equal(np.isnan(bias.bias_value(ensA, ensB)), True)
                assert_equal(np.isnan(bias.bias_value(ensB, ensA)), True)

        assert_almost_equal(
            bias.bias_value(transition_BA.ensembles[-1], network.ms_outers[0]),
            old_div(5.0, 2))
        assert_almost_equal(
            bias.bias_value(transition_AB.ensembles[-1], network.ms_outers[0]),
            old_div(2.0, 2))

        raise SkipTest
    def test_bias_from_network(self):
        # force the TCP in
        network = paths.MISTISNetwork([(self.stateA, self.ifacesA, self.stateB)
                                       ])
        network.sampling_transitions[0].tcp = self.tcp_A
        bias = paths.SRTISBiasFromNetwork(network)
        transition = list(network.transitions.values())[0]  # only one

        # check reciprocal of symmetric partners
        for i in range(4):
            for j in range(i, 4):
                assert_equal(bias.dataframe.loc[i, j],
                             old_div(1.0, bias.dataframe.loc[j, i]))

        for i in range(len(transition.ensembles) - 1):
            ens_to = transition.ensembles[i]
            ens_from = transition.ensembles[i + 1]
            assert_equal(bias.bias_value(ens_from, ens_to), 0.5)

        for i in range(len(transition.ensembles) - 2):
            ens_to = transition.ensembles[i]
            ens_from = transition.ensembles[i + 2]
            assert_equal(bias.bias_value(ens_from, ens_to), 0.25)
 def test_fail_without_tcp(self):
     network = paths.MISTISNetwork([(self.stateA, self.ifacesA, self.stateB)
                                    ])
     bias = paths.SRTISBiasFromNetwork(network)