Exemplo n.º 1
0
def test_calc_alpha_array():
    alpha0 = 1.0
    dr = 0.1
    r = np.arange(0, 2.5, dr)
    form = "linear"
    alpha = alpha_array(alpha0, r, form)
    assert alpha[0] == alpha0
    assert alpha[-1] == 0.0

    form = "margaret-thatcher"
    with pytest.raises(ValueError):
        alpha = alpha_array(alpha0, r, form)
Exemplo n.º 2
0
def test_calc_alpha_array():
    alpha0 = 1.0
    dr = 0.1
    r = np.arange(0, 2.5, dr)
    form = 'linear'
    alpha = alpha_array(alpha0, r, form)
    assert alpha[0] == alpha0
    assert alpha[-1] == 0.0

    form = 'margaret-thatcher'
    with pytest.raises(ValueError):
        alpha = alpha_array(alpha0, r, form)
Exemplo n.º 3
0
    def update_potential(self, pot_r, r_switch=None):
        """Update the potential using all states. """
        self.previous_potential = np.copy(self.potential)
        for state in self.states:
            kT = state.kT
            alpha0 = self.states[state]['alpha']
            form = self.states[state]['alpha_form']
            alpha = alpha_array(alpha0, pot_r, form=form)

            current_rdf = self.states[state]['current_rdf'][:, 1]
            target_rdf = self.states[state]['target_rdf'][:, 1]

            # For cases where rdf_cutoff != pot_cutoff, only update the
            # potential using RDF values < pot_cutoff.
            unused_rdf_vals = current_rdf.shape[0] - self.potential.shape[0]
            if unused_rdf_vals != 0:
                current_rdf = current_rdf[:-unused_rdf_vals]
                target_rdf = target_rdf[:-unused_rdf_vals]

            # The actual IBI step.
            self.potential += (kT * alpha * np.log(current_rdf / target_rdf) /
                               len(self.states))

        # Apply corrections to ensure continuous, well-behaved potentials.
        self.potential = tail_correction(pot_r, self.potential, r_switch)
        self.potential = head_correction(pot_r, self.potential,
                self.previous_potential, self.head_correction_form)
Exemplo n.º 4
0
    def update_potential(self, pot_r, r_switch=None):
        """Update the potential using all states. """
        self.previous_potential = np.copy(self.potential)
        for state in self.states:
            kT = state.kT
            alpha0 = self.states[state]['alpha']
            form = self.states[state]['alpha_form']
            alpha = alpha_array(alpha0, pot_r, form=form)

            current_rdf = self.states[state]['current_rdf'][:, 1]
            target_rdf = self.states[state]['target_rdf'][:, 1]

            # For cases where rdf_cutoff != pot_cutoff, only update the
            # potential using RDF values < pot_cutoff.
            unused_rdf_vals = current_rdf.shape[0] - self.potential.shape[0]
            if unused_rdf_vals != 0:
                current_rdf = current_rdf[:-unused_rdf_vals]
                target_rdf = target_rdf[:-unused_rdf_vals]

            # The actual IBI step.
            self.potential += (kT * alpha * np.log(current_rdf / target_rdf) /
                               len(self.states))

        # Apply corrections to ensure continuous, well-behaved potentials.
        self.potential = tail_correction(pot_r, self.potential, r_switch)
        self.potential = head_correction(pot_r, self.potential,
                                         self.previous_potential,
                                         self.head_correction_form)
Exemplo n.º 5
0
Arquivo: pair.py Projeto: cmelab/msibi
    def update_potential(self, pot_r, r_switch=None, verbose=False):
        """Update the potential using all states. """
        self.previous_potential = np.copy(self.potential)
        for state in self.states:
            kT = state.kT
            alpha0 = self.states[state]["alpha"]
            form = self.states[state]["alpha_form"]
            alpha = alpha_array(alpha0, pot_r, form=form)

            current_rdf = self.states[state]["current_rdf"][:, 1]
            target_rdf = self.states[state]["target_rdf"][:, 1]

            # For cases where rdf_cutoff != pot_cutoff, only update the
            # potential using RDF values < pot_cutoff.
            unused_rdf_vals = current_rdf.shape[0] - self.potential.shape[0]
            if unused_rdf_vals != 0:
                current_rdf = current_rdf[:-unused_rdf_vals]
                target_rdf = target_rdf[:-unused_rdf_vals]

            if verbose:  # pragma: no cover
                plt.plot(current_rdf, label="current rdf")
                plt.plot(target_rdf, label="target rdf")
                plt.legend()
                plt.show()

            # The actual IBI step.
            self.potential += (kT * alpha * np.log(current_rdf / target_rdf) /
                               len(self.states))

            if verbose:  # pragma: no cover
                plt.plot(pot_r,
                         self.previous_potential,
                         label="previous potential")
                plt.plot(pot_r, self.potential, label="potential")
                plt.legend()
                plt.show()

        # Apply corrections to ensure continuous, well-behaved potentials.
        if verbose:  # pragma: no cover
            plt.plot(pot_r, self.potential, label="uncorrected potential")
        self.potential = tail_correction(pot_r, self.potential, r_switch)
        if verbose:  # pragma: no cover
            plt.plot(pot_r, self.potential, label="tail correction")
        self.potential = head_correction(pot_r, self.potential,
                                         self.previous_potential,
                                         self.head_correction_form)
        if verbose:  # pragma: no cover
            plt.plot(pot_r, self.potential, label="head correction")
            plt.legend()
            plt.show()
Exemplo n.º 6
0
    def update_potential(self, pot_r, r_switch=None, verbose=False):
        """Update the potential using all states. """
        self.previous_potential = np.copy(self.potential)
        for state in self._states:
            kT = state.kT
            alpha0 = self._states[state]["alpha"]
            form = self._states[state]["alpha_form"]
            alpha = alpha_array(alpha0, pot_r, form=form)

            current_rdf = self._states[state]["current_rdf"]
            target_rdf = self._states[state]["target_rdf"]

            # For cases where rdf_cutoff != pot_cutoff, only update the
            # potential using RDF values < pot_cutoff.
            unused_rdf_vals = current_rdf.shape[0] - self.potential.shape[0]
            if unused_rdf_vals != 0:
                current_rdf = current_rdf[:-unused_rdf_vals,:]
                target_rdf = target_rdf[:-unused_rdf_vals,:]

            if verbose:  # pragma: no cover
                plt.plot(current_rdf[:,0], current_rdf[:,1], label="current rdf")
                plt.plot(target_rdf[:,0], target_rdf[:,1], label="target rdf")
                plt.legend()
                plt.show()

            # The actual IBI step.
            self.potential += (
                    kT * alpha * np.log(current_rdf[:,1] / target_rdf[:,1]) / len(self._states)
            )

            if verbose:  # pragma: no cover
                plt.plot(
                    pot_r, self.previous_potential, label="previous potential"
                )
                plt.plot(pot_r, self.potential, label="potential")
                plt.ylim(
                    (min(self.potential[np.isfinite(self.potential)])-1,10)
                )
                plt.legend()
                plt.show()

        # Apply corrections to ensure continuous, well-behaved potentials.
        pot = self.potential
        self.potential = tail_correction(pot_r, self.potential, r_switch)
        tail = self.potential
        self.potential = head_correction(
            pot_r,
            self.potential,
            self.previous_potential,
            self.head_correction_form
        )
        head = self.potential
        if verbose:  # pragma: no cover
            plt.plot(pot_r, head, label="head correction")
            plt.plot(pot_r, pot, label="uncorrected potential")
            idx_r, _ = find_nearest(pot_r, r_switch)
            plt.plot(pot_r[idx_r:], tail[idx_r:], label="tail correction")

            plt.ylim((min(pot[np.isfinite(pot)])-1, 10))
            plt.legend()
            plt.show()