コード例 #1
0
ファイル: lga.py プロジェクト: sailfish009/openstructure
def _ParseRotationAndShift(lines):
    t = [l.split() for l in lines]
    rot = geom.Mat3()
    shift = geom.Vec3()
    for i, x in enumerate(t):
        rot[(i, 0)] = +float(x[2])
        rot[(i, 1)] = +float(x[6])
        rot[(i, 2)] = +float(x[10])
        shift[i] = float(x[14])
    return rot, shift
コード例 #2
0
 def test_data(self):
     self.assertEqual(geom.Vec2(1, 2).data, [1, 2])
     self.assertEqual(geom.Vec3(1, 2, 3).data, [1, 2, 3])
     self.assertEqual(geom.Vec4(1, 2, 3, 4).data, [1, 2, 3, 4])
     self.assertEqual(geom.Mat2(1, 2, 3, 4).data, [1, 2, 3, 4])
     self.assertEqual(
         geom.Mat3(1, 2, 3, 4, 5, 6, 7, 8, 9).data,
         [1, 2, 3, 4, 5, 6, 7, 8, 9])
     self.assertEqual(
         geom.Mat4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
                   16).data,
         [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16])
コード例 #3
0
def _ParseTmScore(lines):
  tf1=[float(i.strip()) for i in lines[23].split()]
  tf2=[float(i.strip()) for i in lines[24].split()]
  tf3=[float(i.strip()) for i in lines[25].split()]
  rot=geom.Mat3(tf1[2], tf1[3], tf1[4], tf2[2], tf2[3],
                  tf2[4], tf3[2], tf3[3], tf3[4])
  tf=geom.Mat4(rot)
  tf.PasteTranslation(geom.Vec3(tf1[1], tf2[1], tf3[1]))
  result=TMScoreResult(float(lines[14].split()[-1].strip()),
                       float(lines[16].split()[2].strip()),
                       float(lines[17].split()[1].strip()),
                       float(lines[18].split()[1].strip()),
                       float(lines[19].split()[1].strip()),
                       float(lines[27].split()[-1].strip()),
                       tf)
  return result
コード例 #4
0
ファイル: lga.py プロジェクト: sailfish009/openstructure
def _ParseLGAOutput(output, residue_count):
    result = GDTResult(geom.Mat3(), geom.Vec3(), 0.0, 0.0)
    found_gdt_section = False
    found_transform_section = False
    for index, line in enumerate(output):
        if line.startswith('GLOBAL_DISTANCE_TEST'):
            next_lines = output[index + 1:index + 5]
            result.gdt_ts, result.gdt_ha = _ParseGDTSection(
                next_lines, residue_count)
            found_gdt_section = True
        if line.startswith('Unitary ROTATION matrix'):
            next_lines = output[index + 1:index + 4]
            result.rotation, result.shift = _ParseRotationAndShift(next_lines)
            found_transform_section = True
            break
    assert found_transform_section and found_gdt_section
    return result
コード例 #5
0
def _ParseTmAlign(lines,lines_matrix):
  info_line=lines[12].split(',')
  aln_length=int(info_line[0].split('=')[1].strip())
  rmsd=float(info_line[1].split('=')[1].strip())  
  tm_score=float(lines[14].split('=')[1].split('(')[0].strip())
  tf1=[float(i.strip()) for i in lines_matrix[2].split()]
  tf2=[float(i.strip()) for i in lines_matrix[3].split()]
  tf3=[float(i.strip()) for i in lines_matrix[4].split()]
  rot=geom.Mat3(tf1[2], tf1[3], tf1[4], tf2[2], tf2[3],
                tf2[4], tf3[2], tf3[3], tf3[4])
  tf=geom.Mat4(rot)
  tf.PasteTranslation(geom.Vec3(tf1[1], tf2[1], tf3[1]))
  seq1 = seq.CreateSequence("1",lines[18].strip())
  seq2 = seq.CreateSequence("2",lines[20].strip())
  alignment = seq.CreateAlignment()
  alignment.AddSequence(seq2)
  alignment.AddSequence(seq1)
  return ost.bindings.TMAlignResult(rmsd, tm_score, aln_length, tf, alignment)
コード例 #6
0
    def test_boundary_checks_mat3(self):
        m = geom.Mat3()
        m[0, 0] = m[0, 0]
        m[0, 1] = m[0, 1]
        m[0, 2] = m[0, 2]
        m[1, 0] = m[1, 0]
        m[1, 1] = m[1, 1]
        m[1, 2] = m[1, 2]
        m[2, 0] = m[2, 0]
        m[2, 1] = m[2, 1]
        m[2, 2] = m[2, 2]
        self.assertRaises(IndexError, m.__setitem__, (-1, 0), 1)
        self.assertRaises(IndexError, m.__setitem__, (3, 0), 1)
        self.assertRaises(IndexError, m.__setitem__, (0, -1), 1)
        self.assertRaises(IndexError, m.__setitem__, (-1, 3), 1)

        self.assertRaises(IndexError, m.__getitem__, (-1, 0))
        self.assertRaises(IndexError, m.__getitem__, (3, 0))
        self.assertRaises(IndexError, m.__getitem__, (0, -1))
        self.assertRaises(IndexError, m.__getitem__, (0, 3))
コード例 #7
0
ファイル: ialign.py プロジェクト: sailfish009/openstructure
def _ParseiAlign(lines):
    info_line = lines[18].split(',')
    is_score = float(info_line[0].split('=')[1].strip())
    aln_residues = int(lines[19].split('=')[1].strip())
    aln_contacts = int(lines[20].split('=')[1].strip())
    info_line = lines[21].split(',')
    rmsd = float(info_line[0].split('=')[1].strip())

    tf1 = [float(i.strip()) for i in lines[25][1:].split()]
    tf2 = [float(i.strip()) for i in lines[26][1:].split()]
    tf3 = [float(i.strip()) for i in lines[27][1:].split()]
    rot = geom.Mat3(tf1[2], tf1[3], tf1[4], tf2[2], tf2[3], tf2[4], tf3[2],
                    tf3[3], tf3[4])
    tf = geom.Mat4(rot)
    tf.PasteTranslation(geom.Vec3(tf1[1], tf2[1], tf3[1]))
    seq1 = seq.CreateSequence("1", lines[32].strip())
    seq2 = seq.CreateSequence("2", lines[34].strip())
    alignment = seq.CreateAlignment()
    alignment.AddSequence(seq2)
    alignment.AddSequence(seq1)
    return iAlignResult(rmsd, tf, alignment, is_score, aln_residues,
                        aln_contacts)
コード例 #8
0
    def test_repr(self):
        v = geom.Vec2(1, 2)
        v2 = eval(repr(v))
        self.assertTrue(geom.Equal(v, v2))

        v = geom.Vec3(1, 2, 3)
        v2 = eval(repr(v))
        self.assertTrue(geom.Equal(v, v2))

        v = geom.Vec4(1, 2, 3, 4)
        v2 = eval(repr(v))
        self.assertTrue(geom.Equal(v, v2))

        m = geom.Mat2(1, 2, 3, 4)
        m2 = eval(repr(m))
        self.assertTrue(geom.Equal(m, m2))

        m = geom.Mat3(1, 2, 3, 4, 5, 6, 7, 8, 9)
        m2 = eval(repr(m))
        self.assertTrue(geom.Equal(m, m2))

        m = geom.Mat4(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16)
        m2 = eval(repr(m))
        self.assertTrue(geom.Equal(m, m2))
コード例 #9
0
def FitToScreen(gfx_ent, width=None, height=None, margin=0.05):
    """
  Setup camera such that it is centered on the graphical entity and the entity 
  fits the entire viewport. The longest axes of the entity are aligned along 
  the x- and y- axes of the screen.
  
  :param gfx_ent: The graphical entity
  :type gfx_ent: str or :class:`Entity`
  
  
  """
    from ost import geom
    import math

    def _XYZ(view, axes):
        """
    returns the vectors in x, y and z direction respectively. The smallest 
    vector is in z, then y, and the largest along x.
    """
        rows = [axes.GetRow(i) for i in range(3)]
        lengths = []
        for axe in rows:
            min_proj = geom.Dot(axe, view.atoms[0].pos)
            max_proj = min_proj
            for atom in view.atoms[1:]:
                proj = geom.Dot(axe, atom.pos)
                min_proj = min(proj, min_proj)
                max_proj = max(proj, max_proj)
            lengths.append(max_proj - min_proj)

        def cmp_x(rhs, lhs):
            # replaced cmp when porting to Python 3
            #return cmp(lhs[1], rhs[1])
            return (lhs[1] > rhs[1]) - (lhs[1] < rhs[1])

        sorted_axes = sorted(zip(rows, lengths),
                             key=functools.cmp_to_key(cmp_x))
        return [r * l for r, l in sorted_axes]

    scene = Scene()
    if not isinstance(gfx_ent, Entity):
        gfx_ent = scene[str(gfx_ent)]
    width = width and width or scene.viewport.width
    height = height and height or scene.viewport.height
    atom_positions = geom.Vec3List([atom.pos for atom in gfx_ent.view.atoms])
    axes = atom_positions.principal_axes
    sorted_axes = _XYZ(gfx_ent.view, axes)
    x_bigger_than_y = geom.Length(sorted_axes[0]) > geom.Length(sorted_axes[1])
    if x_bigger_than_y:
        if width > height:
            x_axes = geom.Normalize(sorted_axes[0])
            y_axes = geom.Normalize(sorted_axes[1])
        else:
            x_axes = geom.Normalize(sorted_axes[1])
            y_axes = geom.Normalize(sorted_axes[0])
    else:
        if width > height:
            x_axes = geom.Normalize(sorted_axes[1])
            y_axes = geom.Normalize(sorted_axes[0])
        else:
            x_axes = geom.Normalize(sorted_axes[0])
            y_axes = geom.Normalize(sorted_axes[1])
    z_axes = geom.Normalize(geom.Cross(x_axes, y_axes))
    rotation = geom.Mat3(x_axes[0], x_axes[1], x_axes[2], y_axes[0], y_axes[1],
                         y_axes[2], z_axes[0], z_axes[1], z_axes[2])
    rtc = geom.Mat4(rotation)

    center = gfx_ent.center
    aspect = float(width) / float(height)
    factor_y = 1.0 / math.tan(math.radians(scene.fov))
    factor_x = factor_y / aspect
    z_off = geom.Length(sorted_axes[2]) * 0.5
    rtc[0, 3] = center[0]
    rtc[1, 3] = center[1]
    rtc[2, 3] = center[2]
    rtc[3, 0] = 0
    rtc[3, 1] = 0
    rtc[3, 2] = -(max(factor_x * (1 + margin) * geom.Length(sorted_axes[0]),
                      factor_y *
                      (1 + margin) * geom.Length(sorted_axes[1])) + z_off)
    scene.SetRTC(rtc)