def accumulate(self, points, acc):
        acc.fill(0)
        for (x, y) in points:
            if not (np.isfinite(x) and np.isfinite(y)): continue
            r = np.linalg.norm([x, y])
            ix_r, ix_t = self.hough(x,
                                    y,
                                    self.theta_,
                                    s=self.sin_,
                                    c=self.cos_)
            ix_r *= (self.n_r_ / self.mx_r_)
            ix_t *= (self.n_t_ / self.mx_t_)

            # convert to index
            ix_r = U.rint(ix_r)
            ix_t = U.rint(ix_t)

            # filter by max radius
            sel = (ix_r < self.n_r_)
            ix_r = ix_r[sel]
            ix_t = ix_t[sel]

            try:
                # weighted addition based on radius
                # TODO : is this a better method?
                np.add.at(acc, (ix_r, ix_t), r)
            except Exception as e:
                print x
                print y
                raise e
示例#2
0
def _solve(M, N, strict_nonblocking=False):
    if strict_nonblocking:
        target = partial(_get_links_strict, M, N)
    else:
        target = partial(_get_links_rearrangeable, M, N)
    mid = (M * N * 1. / (M + N))**.5
    b0 = .5 * min(M, N)**.5
    b1 = 2. * max(M, N)**.5
    n1, n2 = opt.minimize(target, (mid, mid), bounds=((b0, b1), (b0, b1))).x
    # print "%.3f %.3f" % (n1, n2)
    n1 = rint(n1)
    n2 = rint(n2)
    return n1, n2
 def convert_to_bin_idx(self, grid_idx):
     bin_idx = utils.rint(np.sum(grid_idx * self._modulus))
     if bin_idx >= self.nbins or bin_idx < 0:
         raise Exception(
             "Invalid bin index %s. You are probably outside the grid. Size:%s"
             % (bin_idx, self.nbins))
     return bin_idx
def _create_beta1_targetedmd():
    cvs_dir = "../../gpcr/cvs/beta1-cvs/"
    beta1_cvs = load_object(cvs_dir + "cvs")
    create_targetmd_input(
        beta1_cvs,
        np.loadtxt(cvs_dir +
                   "string-paths/string0_beta1_inactive_endpoint.txt"),
        steps_per_point=utils.rint(3000000 / 22),
        backwards=True)
示例#5
0
 def create_default_mapping(self, previous_stringpath, stringpath,
                            fixed_endpoints):
     mapping = np.zeros((len(stringpath), 3)) - 1
     point_ratio = len(previous_stringpath) / len(stringpath)
     if fixed_endpoints:
         mapping[0, 0] = 0
         mapping[-1, 0] = len(previous_stringpath) - 1
     for point_idx in range(len(mapping)):
         if fixed_endpoints and (point_idx == 0
                                 or point_idx == len(stringpath) - 1):
             continue
         previous_idx = utils.rint(point_idx * point_ratio)
         mapping[point_idx, 0] = previous_idx
     return mapping
def _create_beta2_targetedmd():
    time_ns = 10
    kappa = 10000.0
    topology = md.load(
        utils.project_dir +
        "gpcr/reference_structures/3p0g/asp79-apo/equilibrated.gro").topology
    cvs = colvars.cvs_definition_reader.load_cvs(cvs_len5path + "cvs.json")
    plumed_file_content = colvars.plumed_tools.convert_to_plumed_restraints(
        cvs, topology, kappa)
    logger.info("plumed_file_content:\n\n%s\n", plumed_file_content)
    # stringpath = np.loadtxt(cvs_len5path + "string-paths-drorpath/dror_path_fixedep.txt")
    # stringpath = np.loadtxt(cvs_len5path + "string-paths-3p0g-3sn6/straight4points.txt")
    create_targetmd_input(cvs,
                          stringpath,
                          steps_per_point=utils.rint(time_ns * 1e6 /
                                                     len(stringpath)),
                          backwards=False,
                          kappa=kappa)
def peak_local_max_wrap(
    image,
    min_distance=1,
    threshold_abs=None,
    threshold_rel=None,
    num_peaks=np.inf,
):
    """ adapted from skimage to support theta wrap """

    if np.all(image == image.flat[0]):
        return np.empty((0, 2), np.int)

    # Non maximum filter
    # if footprint is not None:
    #     image_max = ndi.maximum_filter(image, footprint=footprint,
    #                                    mode='wrap')
    # else:
    #     size = 2 * min_distance + 1
    #     image_max = ndi.maximum_filter(image, size=size, mode='wrap')

    # maximum filter with gaussian kernel
    ker = cv2.getGaussianKernel(U.rint(2 * min_distance + 1), sigma=2.0)
    ker = ker * ker.T
    image_max = ndi.maximum_filter(image, footprint=ker, mode='wrap')

    # alternatively,
    # size = 2 * min_distance + 1
    # image_max = ndi.maximum_filter(image, size=size, mode='wrap')

    mask = image == image_max

    # find top peak candidates above a threshold
    thresholds = []
    if threshold_abs is None:
        threshold_abs = image.min()
    thresholds.append(threshold_abs)
    if threshold_rel is not None:
        thresholds.append(threshold_rel * image.max())
    if thresholds:
        mask &= image > max(thresholds)

    # Select highest intensities (num_peaks)
    coordinates = _get_high_intensity_peaks(image, mask, num_peaks)
    return coordinates
示例#8
0
 def to_node_id(self, iteration, point_idx):
     return "i{}p{}".format(utils.rint(iteration), utils.rint(point_idx))