def find_engulfing_sphere_radius(x):
    if True:
        cm = x.mean(0)
        d_to_cm = np.linalg.norm(x - cm, axis=0)
        return max(d_to_cm) / float(len(x) ** 3)
    if False:
        from csb.bio.utils import radius_of_gyration
        return radius_of_gyration(x) / float(len(x) ** 3)
示例#2
0
文件: gibbs.py 项目: jyarger/cg
    def report_progress(self, samples):

        info = (len(samples['s']), len(samples['X'][-1]),
                rmsd(*samples['X'][-2:]), float(samples['s'][-1]),
                samples['r_min'][-1], samples['eps'][-1],
                self.posteriors['X'].sampler.dt,
                np.sum(self.posteriors['X'].likelihood.N < 1.),
                radius_of_gyration(samples['X'][-1]))

        print GibbsSampler.output.format(*info)
示例#3
0
def random_sphere(n_particles, Rg):
    """Generate particles within a sphere such that a desired radius of gyration
    is matched. 
    """
    r = np.random.random(n_particles)**(1/3.)
    phi = np.random.uniform(0., 2*np.pi, size=n_particles)
    theta = np.arccos(np.random.uniform(-1., 1., size=n_particles))
    coords = np.transpose([np.cos(phi) * np.sin(theta) * r,
                           np.sin(phi) * np.sin(theta) * r, 
                           np.cos(theta) * r])
    coords -= coords.mean(0)
    coords *= Rg / radius_of_gyration(coords)
    return coords
示例#4
0
    def _single_structure_log_prob(self, structure):
        """
        Evaluates log-probability for a single structure

        :param structure: coordinates of a single structure
        :type structure: :class:`numpy.ndarray`

        :returns: log-probability
        :rtype: float
        """
        X = structure.reshape(-1, 3)
        rg = radius_of_gyration(X)

        return -0.5 * self['k_rog'].value * (self['rog'].value - rg)**2
示例#5
0
    def _single_structure_gradient(self, structure):
        """
        Evaluates the negative log-probability gradient 
        for a single structure

        :param structure: coordinates of a single structure
        :type structure: :class:`numpy.ndarray`

        :returns: gradient vector
        :rtype: :class:`numpy.ndarray`
        """
        X = structure.reshape(-1, 3)
        r_gyr = radius_of_gyration(X)
        k = self['k_rog'].value
        target_rog = self['rog'].value

        return -k * (target_rog - r_gyr) * (X -
                                            X.mean(0)).ravel() / r_gyr / len(X)
    ax = fig.add_subplot(111)
    ax.hist([s.variables['norm'] for s in samples],
            bins=int(np.sqrt(len(samples))))
    ax.set_xlabel('gamma')
    ax.set_yticks([])
    fig.tight_layout()

    if show_plots:
        plt.show()

if not True:

    from csb.bio.utils import radius_of_gyration

    rgs = map(radius_of_gyration, structures)
    true1_rg = radius_of_gyration(true1)
    true2_rg = radius_of_gyration(true2)

    fig = plt.figure()
    ax = fig.add_subplot(111)
    h = ax.hist(rgs, bins=int(sqrt(len(rgs))))
    ax.plot((true1_rg, true1_rg), (0, max(h[0])), c='r', label=label1)
    ax.plot((true2_rg, true2_rg), (0, max(h[0])), c='b', label=label2)
    ax.set_xlabel('radius of gyration')
    ax.set_ylabel('# structures')
    ax.set_yticks([])
    ax.legend()

    if show_plots:
        plt.show()
示例#7
0
    def testRadiusOfGyration(self):
        gyradius = cbu.radius_of_gyration(X4)

        s2 = 2.0**0.5
        self.assertArrayEqual(gyradius, s2 / 2.0)