예제 #1
0
파일: views.py 프로젝트: Bernhard10/ernvis
def changeLoop(filename, loopname):
    posted=request.get_json(force=True)
    if posted["action"]=="change" and posted["method"]=="random":
        sm=get_sm(filename)
        sm.load_sampled_elems()
        if loopname not in sm.bg.coords:
            abort(404)
        original_cg=copy.deepcopy(sm.bg)
        new_filename=get_new_filename()
        smCache.renameSM(filename, new_filename)
        change_elem(sm, loopname)
        cg=sm.bg

        centroid0 = ftuv.get_vector_centroid(ftug.bg_virtual_residues(original_cg))
        centroid1 = ftuv.get_vector_centroid(ftug.bg_virtual_residues(cg))
        crds0 = ftuv.center_on_centroid(ftug.bg_virtual_residues(original_cg))
        crds1 = ftuv.center_on_centroid(ftug.bg_virtual_residues(cg))
        rot_mat = ftur.optimal_superposition(crds0, crds1)
        for k in cg.coords.keys():
            cg.coords[k] = (np.dot(rot_mat, cg.coords[k][0] - centroid1),
                            np.dot(rot_mat, cg.coords[k][1] - centroid1))
            if k[0] == 's':
                cg.twists[k] = (np.dot(rot_mat, cg.twists[k][0]),
                                np.dot(rot_mat, cg.twists[k][1]))

        filename=get_new_filename()
        cg.to_cg_file("user_files/"+filename)

        return jsonify({"url": url_for("structure_main", filename=filename)})
    else:
        abort(403)
예제 #2
0
def changeLoop(filename, loopname):
    posted = request.get_json(force=True)
    if posted["action"] == "change" and posted["method"] == "random":
        sm = get_sm(filename)
        sm.load_sampled_elems()
        if loopname not in sm.bg.coords:
            abort(404)
        original_cg = copy.deepcopy(sm.bg)
        new_filename = get_new_filename()
        smCache.renameSM(filename, new_filename)
        change_elem(sm, loopname)
        cg = sm.bg

        centroid0 = ftuv.get_vector_centroid(
            ftug.bg_virtual_residues(original_cg))
        centroid1 = ftuv.get_vector_centroid(ftug.bg_virtual_residues(cg))
        crds0 = ftuv.center_on_centroid(ftug.bg_virtual_residues(original_cg))
        crds1 = ftuv.center_on_centroid(ftug.bg_virtual_residues(cg))
        rot_mat = ftur.optimal_superposition(crds0, crds1)
        for k in cg.coords.keys():
            cg.coords[k] = (np.dot(rot_mat, cg.coords[k][0] - centroid1),
                            np.dot(rot_mat, cg.coords[k][1] - centroid1))
            if k[0] == 's':
                cg.twists[k] = (np.dot(rot_mat, cg.twists[k][0]),
                                np.dot(rot_mat, cg.twists[k][1]))

        filename = get_new_filename()
        cg.to_cg_file("user_files/" + filename)

        return jsonify({"url": url_for("structure_main", filename=filename)})
    else:
        abort(403)
예제 #3
0
def align_cgs(cgs):
    '''
    Align each coarse grain RNA to the first one.

    The points representing each coarse grain RNA molecule
    will be the virtual residues.
    
    @param cgs: A list of CoarseGrainRNA structures.
    @return: Nothing, the cgs are modified in place
    '''
    centroid0 = ftuv.get_vector_centroid(ftug.bg_virtual_residues(cgs[0]))
    crds0 = ftuv.center_on_centroid(ftug.bg_virtual_residues(cgs[0]))

    for cg in cgs:
        centroid1 = ftuv.get_vector_centroid(ftug.bg_virtual_residues(cg))
        crds1 = ftuv.center_on_centroid(ftug.bg_virtual_residues(cg))

        rot_mat = ftur.optimal_superposition(crds0, crds1)
        for k in cg.coords.keys():
            cg.coords[k] = (np.dot(rot_mat, cg.coords[k][0] - centroid1),
                            np.dot(rot_mat, cg.coords[k][1] - centroid1))

            if k[0] == 's':
                cg.twists[k] = (np.dot(rot_mat, cg.twists[k][0]),
                                np.dot(rot_mat, cg.twists[k][1]))
예제 #4
0
 def test_center_on_centroid(self):
     coords = [[0., 1., 1.], [1, 1, 1], [-1, 2, 3], [3, 0, 0], [-3, 1, 0]]
     nptest.assert_almost_equal(
         ftuv.center_on_centroid(np.array(coords)),
         [[0, 0., 0], [1, 0, 0], [-1, 1, 2], [3, -1, -1], [-3, 0, -1]])
     nptest.assert_equal(
         ftuv.get_vector_centroid(ftuv.center_on_centroid(coords)),
         [0, 0., 0])
예제 #5
0
def _pointwise_deviation(crds1, crds2, is_centered=False):
    """
    Helper function for Kabsch RMSD
    """
    if not is_centered:
        crds1 = ftuv.center_on_centroid(crds1)
        crds2 = ftuv.center_on_centroid(crds2)

    os = optimal_superposition(crds1, crds2)
    crds_aligned = np.dot(crds1, os)

    diff_vecs = (crds2 - crds_aligned)

    return diff_vecs
예제 #6
0
def _pointwise_deviation(crds1, crds2, is_centered=False):
    """
    Helper function for Kabsch RMSD
    """
    if not is_centered:
        crds1 = ftuv.center_on_centroid(crds1)
        crds2 = ftuv.center_on_centroid(crds2)

    os = optimal_superposition(crds1, crds2)
    crds_aligned = np.dot(crds1, os)

    diff_vecs = (crds2 - crds_aligned)

    return diff_vecs
예제 #7
0
def rmsd(crds1, crds2):
    '''
    Center the coordinate vectors on their centroid
    and then calculate the rmsd.
    '''
    crds1 = ftuv.center_on_centroid(crds1)
    crds2 = ftuv.center_on_centroid(crds2)

    os = optimal_superposition(crds1, crds2)
    crds_aligned = np.dot(crds1, os)

    diff_vecs = (crds2 - crds_aligned)
    vec_lengths = np.sum(diff_vecs * diff_vecs, axis=1)

    return math.sqrt(sum(vec_lengths) / len(vec_lengths))
예제 #8
0
파일: rmsd.py 프로젝트: tcarlile/forgi
def rmsd(crds1, crds2):
    '''
    Center the coordinate vectors on their centroid
    and then calculate the rmsd.
    '''
    crds1 = ftuv.center_on_centroid(crds1)
    crds2 = ftuv.center_on_centroid(crds2)

    os = optimal_superposition(crds1, crds2)
    crds_aligned = np.dot(crds1, os)

    diff_vecs = (crds2 - crds_aligned)
    vec_lengths = np.sum(diff_vecs * diff_vecs, axis=1)

    return math.sqrt(sum(vec_lengths) / len(vec_lengths))   #rmsd(crds1, crds2)
예제 #9
0
def prepare_pca_input(cgs):
    data = []
    for cg in cgs:
        # reshape(-1) returns a flattened view
        data.append(ftuv.center_on_centroid(
            cg.get_ordered_stem_poss()).reshape(-1))
    return np.array(data)
예제 #10
0
def prepare_pca_input(cgs):
    data = []
    for cg in cgs:
        # reshape(-1) returns a flattened view
        data.append(
            ftuv.center_on_centroid(cg.get_ordered_stem_poss()).reshape(-1))
    return np.array(data)
예제 #11
0
파일: rmsd.py 프로젝트: marcelTBI/forgi
def centered_drmsd(crds1, crds2):
    '''
    Center the coordinate vectors on their centroid
    and then calculate the drmsd.
    '''
    crds1 = ftuv.center_on_centroid(crds1)
    crds2 = ftuv.center_on_centroid(crds2)

    os = optimal_superposition(crds1, crds2)
    crds_aligned = np.dot(crds1, os)

    s2 = sum(sum((crds2 - crds_aligned) * (crds2 - crds_aligned)))
    diff_vecs = (crds2 - crds_aligned)
    sums = np.sum(diff_vecs * diff_vecs, axis=1)
    sqrts = np.sqrt(sums)

    return drmsd(crds1, crds2)
예제 #12
0
 def center(self):
     self._coordinates = ftuv.center_on_centroid(self._coordinates)
     self.is_centered = True
예제 #13
0
 def test_center_on_centroid(self):
     coords = [[0., 1., 1.], [1, 1, 1], [-1, 2, 3], [3, 0, 0], [-3, 1, 0]]
     nptest.assert_almost_equal(ftuv.center_on_centroid(np.array(coords)),
                                [[0, 0., 0], [1, 0, 0], [-1, 1, 2], [3, -1, -1], [-3, 0, -1]])
     nptest.assert_equal(ftuv.get_vector_centroid(
         ftuv.center_on_centroid(coords)), [0, 0., 0])
예제 #14
0
 def center(self):
     self._coordinates = ftuv.center_on_centroid(self._coordinates)
     self.is_centered = True