当前位置: 首页>>代码示例>>Python>>正文


Python QtViewer.add_renderer方法代码示例

本文整理汇总了Python中chemlab.graphics.qtviewer.QtViewer.add_renderer方法的典型用法代码示例。如果您正苦于以下问题:Python QtViewer.add_renderer方法的具体用法?Python QtViewer.add_renderer怎么用?Python QtViewer.add_renderer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在chemlab.graphics.qtviewer.QtViewer的用法示例。


在下文中一共展示了QtViewer.add_renderer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: showsys

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def showsys(sys, width=400, height=400):
    v = QtViewer()
    w = v.widget
    w.initializeGL()

    
    w.resize(width, height)
    w.resizeGL(width, height)

    sr = v.add_renderer(AtomRenderer, sys.r_array, sys.type_array,
                        backend='impostors')
    
    if sys.box_vectors is not None:
        v.add_renderer(BoxRenderer, sys.box_vectors)
    
    w.camera.autozoom(sys.r_array)
    
    w.camera.orbit_y(3.14/4)    
    w.camera.orbit_x(3.14/4)

    w.paintGL()
    # Make sure to finish everything
    data = glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE)

    # Make pil image to save as png
    image = pil_Image.fromstring('RGB', (width, height), data)
    b = BytesIO()
    image.save(b, format='png')
    data = b.getvalue()
    
    # Cleanup
    del v
    del w
    # Save as png
    return ipy_Image(data=data)
开发者ID:yotama9,项目名称:chemlab,代码行数:37,代码来源:ipython.py

示例2: showmol

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def showmol(mol, style="ball-and-stick", width=300, height=300):
    v = QtViewer()
    w = v.widget

    if style == "ball-and-stick":
        bs = v.add_renderer(BallAndStickRenderer, mol.r_array, mol.type_array, mol.bonds)
    elif style == "vdw":
        sr = v.add_renderer(AtomRenderer, mol.r_array, mol.type_array, backend="impostors")

    w.camera.autozoom(mol.r_array)

    # Make sure to finish everything
    glBindTexture(w.textures["color"])
    glActiveTexture(GL_TEXTURE0)
    data = glGetTexImage(GL_TEXTURE_2D, 0, RGB, GL_UNSIGNED_BYTE)
    # data = glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE)    # Make pil image to save as png
    image = pil_Image.fromstring("RGB", (width, height), data)

    b = BytesIO()
    image.save(b, format="png")
    data = b.getvalue()

    # Cleanup
    del v
    del w

    # Save as png
    return ipy_Image(data=data)
开发者ID:baoboa,项目名称:chemlab,代码行数:30,代码来源:ipython.py

示例3: test_cylinder_impostor_renderer

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def test_cylinder_impostor_renderer():
    from chemlab.graphics.renderers import CylinderImpostorRenderer
    
    bounds = np.array([[[-1.0, 0.0, 0.0], [-1.0, 1.0, 0.0]],
                       [[1.0, 0.0, 0.0], [1.0, 3.0, 0.0]],
                       [[1.0, 0.0, 0.0], [1.0, 0.0, 1.0]]])
    radii = np.array([0.5, 0.3, 0.3])
    colors = np.array([blue, orange, green])
    
    bounds = np.array([[[0.0, 0.0, 0.0], [0.0, 1.0, 0.0]]])
    radii = np.array([0.2])
    colors = np.array([blue])

    # Test for speed
    # random bounds
    #n = 50000
    #bounds = np.random.rand(n, 2, 3) * 10
    #radii = np.random.rand(n)/10.0
    #colors = np.array([blue] * n)
    
    import time
    v = QtViewer()
    t0 = time.time()
    ar = v.add_renderer(CylinderImpostorRenderer, bounds, radii, colors)
    #ar = v.add_renderer(CylinderRenderer, bounds, radii* 2.0, colors)
    sr = v.add_renderer(SphereImpostorRenderer, bounds[:, 0], radii, colors)
    sr = v.add_renderer(SphereImpostorRenderer, bounds[:, 1], radii, colors)
    print time.time() - t0
    
    #ar = v.add_renderer(CylinderRenderer, bounds, radii, colors)
    #ar.update_bounds(bounds)
    
    v.run()
开发者ID:,项目名称:,代码行数:35,代码来源:

示例4: test_pickers

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def test_pickers():
    from chemlab.graphics.pickers import SpherePicker, CylinderPicker
    from chemlab.core.molecule import guess_bonds
    #mol = datafile('tests/data/benzene.mol').read('molecule')
    mol = ChemlabDB().get('molecule', 'example.water')

    centers = mol.r_array
    radii = np.array([0.05]*mol.n_atoms)
    colors = np.array([[0, 255, 255, 255]]*mol.n_atoms)
    bounds = mol.r_array.take(mol.bonds, axis=0)

    b_radii = np.array([0.05]*mol.n_bonds)
    b_colors = np.array([[0, 255, 255, 255]]*mol.n_bonds)

    v = QtViewer()
    #v.widget.camera.autozoom(mol.r_array)
    sr = v.add_renderer(SphereImpostorRenderer, centers, radii*1.2, colors, transparent=False)
    cr = v.add_renderer(CylinderImpostorRenderer, bounds, b_radii, b_colors)

    sp = SpherePicker(v.widget, centers, radii*1.2)
    cp = CylinderPicker(v.widget, bounds, b_radii)

    def on_click(evt):
        x, y = v.widget.screen_to_normalized(evt.x(), evt.y())
        a_i, a_d = sp.pick(x, y)
        b_i, b_d = cp.pick(x, y)
        print('A', a_d)
        print('B', b_d)

    v.widget.clicked.connect(on_click)

    v.run()
开发者ID:B-Rich,项目名称:chemlab,代码行数:34,代码来源:test_graphics.py

示例5: showmol

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def showmol(mol, style='ball-and-stick',
            width=300, height=300):
    v = QtViewer()
    w = v.widget
    
    if style == 'ball-and-stick':
        bs = v.add_renderer(BallAndStickRenderer,
                            mol.r_array,
                            mol.type_array,
                            mol.bonds)
    elif style == 'vdw':
        sr = v.add_renderer(AtomRenderer, mol.r_array, mol.type_array,
                            backend='impostors')

    w.camera.autozoom(mol.r_array)
    
    # Make sure to finish everything
    image = w.toimage(width, height)
    b = BytesIO()
    image.save(b, format='png')
    data = b.getvalue()

    # Cleanup
    del v
    del w
    
    # Save as png
    return ipy_Image(data=data)
开发者ID:ajjackson,项目名称:chemlab,代码行数:30,代码来源:ipython.py

示例6: showsys

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def showsys(sys, width=400, height=400):
    v = QtViewer()
    w = v.widget

    sr = v.add_renderer(AtomRenderer, sys.r_array, sys.type_array,
                        backend='impostors')
    
    if sys.box_vectors is not None:
        v.add_renderer(BoxRenderer, sys.box_vectors)
    
    w.camera.autozoom(sys.r_array)
    
    w.camera.orbit_y(3.14/4)    
    w.camera.orbit_x(3.14/4)

    image = w.toimage(width, height)
    b = BytesIO()
    image.save(b, format='png')
    data = b.getvalue()
    
    # Cleanup
    del v
    del w
    # Save as png
    return ipy_Image(data=data)
开发者ID:ajjackson,项目名称:chemlab,代码行数:27,代码来源:ipython.py

示例7: test_cylinder_impostor_renderer

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def test_cylinder_impostor_renderer():
    bounds = np.array([[[-1.0, 0.0, 0.0], [-1.0, 1.0, 0.0]],
                       [[1.0, 0.0, 0.0], [1.0, 3.0, 0.0]],
                       [[1.0, 0.0, 0.0], [1.0, 0.0, 1.0]]])
    radii = np.array([0.5, 0.3, 0.3])
    colors = np.array([colors.blue, colors.orange, colors.green])

    bounds = np.array([[[0.0, 0.0, 0.0], [0.0, 1.0, 0.0]]])
    radii = np.array([0.2])
    colors = np.array([colors.blue])

    # Test for speed
    # random bounds
    #n = 50000
    #bounds = np.random.rand(n, 2, 3) * 10
    #radii = np.random.rand(n)/10.0
    #colors = np.array([colors.blue] * n)

    v = QtViewer()
    ar = v.add_renderer(CylinderImpostorRenderer, bounds, radii, colors)    
    sr = v.add_renderer(SphereImpostorRenderer, bounds[:, 0], radii, colors)
    sr = v.add_renderer(SphereImpostorRenderer, bounds[:, 1], radii, colors)
    v.run()
    
    # Test updates
    ar.update_radii([0.1])
    bounds[0,0] -= 1.0
    ar.update_bounds(bounds)
    ar.update_colors([colors.green])
    v.run()
    
    # Test emptiness
    ar.change_attributes([], [], [])
开发者ID:B-Rich,项目名称:chemlab,代码行数:35,代码来源:test_graphics.py

示例8: test_glow

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def test_glow():
    from PySide import QtCore
    
    cdb = ChemlabDB()
    mol = cdb.get('molecule', 'example.norbornene')
    
    v = QtViewer()
    colors = np.array([(255, 0, 0, 255)]*mol.n_atoms)
    colors[0][3] = 0

    v.widget.camera.autozoom(mol.r_array)
    sr = v.add_renderer(SphereImpostorRenderer, mol.r_array, [0.1]*mol.n_atoms,
                        colors)

    ge = v.add_post_processing(GlowEffect)
    #v.add_post_processing(GammaCorrectionEffect)
    def changeglow():
        #ge.radius = np.sin(time.time()*10.0) + 2.5
        colors[0][3] = 255 * (np.sin(time.time()*10.0)*0.5 + 0.5)
        sr.update_colors(colors)
        v.widget.update()

    timer = QtCore.QTimer()
    timer.timeout.connect(changeglow)
    timer.start(10)
    v.run()
开发者ID:B-Rich,项目名称:chemlab,代码行数:28,代码来源:test_graphics.py

示例9: test_ball_and_stick_renderer

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def test_ball_and_stick_renderer():
    from collections import defaultdict
    from chemlab.io import datafile
    from chemlab.db.cirdb import CirDB
    
    v = QtViewer()
    v.add_post_processing(SSAOEffect, kernel_radius = 0.15)
    
    #v.widget.background_color = black
    #mol = Molecule([Atom("O", [-0.499, 0.249, 0.0]),
    #                Atom("H", [-0.402, 0.249, 0.0]),
    #                Atom("H", [-0.532, 0.198, 0.10])])
    
    #mol.bonds = np.array([[0, 1],[0, 2]])
    
    #mol = CirDB().get("molecule", "moronic acid")
    mol = datafile('tests/data/3ZJE.pdb').read('molecule')
    mol.bonds = find_bonds(mol)
    
    ar = v.add_renderer(BallAndStickRenderer, mol.r_array, mol.type_array, mol.bonds)

    
    # Try without bonds
    # ar2 = v.add_renderer(BallAndStickRenderer, mol.r_array + 0.5, mol.type_array, np.array([]))
    
    v.run()
开发者ID:,项目名称:,代码行数:28,代码来源:

示例10: test_pickers

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def test_pickers():
    from chemlab.graphics.pickers import SpherePicker
    from chemlab.io import datafile
    mol = datafile('/home/gabriele/projects/LiCl/interface/loafintjc-heat/equilibrium.gro').read('system')
    
    centers = [[0.0, 0.0, 0.0], [1.0, 0.0, 1.0]]
    radii = np.array([1.0, 0.5])
    colors = [[0, 255, 255, 100], [255, 255, 0, 100]]
    
    centers = mol.r_array
    radii = np.array([0.2]*mol.n_atoms)
    colors = np.array([[0, 255, 255, 255]]*mol.n_atoms)
    
    v = QtViewer()
    sr = v.add_renderer(SphereImpostorRenderer, centers, radii, colors, transparent=False)
    #sr = v.add_renderer(SphereImpostorRenderer, centers,
    #                    radii*1.5, [[255, 255, 255, 50]]*mol.n_atoms, transparent=True)

    
    sp = SpherePicker(v.widget, centers, radii)

    def on_click(evt):
        x, y = v.widget.screen_to_normalized(evt.x(), evt.y())
        print sp.pick(x, y)
    
    v.widget.clicked.connect(on_click)
    
    v.run()
开发者ID:,项目名称:,代码行数:30,代码来源:

示例11: test_toon_shading

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def test_toon_shading():

    from chemlab.db import ChemlabDB, CirDB
    from chemlab.io import datafile
    from chemlab.graphics import colors
    from chemlab.core.molecule import guess_bonds
    
    cdb = ChemlabDB()
    
    #mol = cdb.get('molecule', 'example.norbornene')
    
    mol = datafile('tests/data/3ZJE.pdb').read('system')
    v = QtViewer()
    #v.widget.post_processing = FXAAEffect(v.widget)
    #v.widget.post_processing = SSAOEffect(v.widget, kernel_size=64, kernel_radius=1.0, ssao_power=2.0)
    

    v.widget.camera.autozoom(mol.r_array)
    #sr = v.add_renderer(AtomRenderer, mol.r_array,
    #                    mol.type_array, 'impostors',
    #                    shading='toon')
    #sr = v.add_renderer(AtomRenderer, mol.r_array,
    #                    mol.type_array, 'polygons',
    #                    shading='toon')
    
    ar = v.add_renderer(BallAndStickRenderer,
                        mol.r_array, mol.type_array,
                        guess_bonds(mol.r_array, mol.type_array),
                        shading='toon')
    
    v.run()
开发者ID:,项目名称:,代码行数:33,代码来源:

示例12: test_glow

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def test_glow():
    from chemlab.db import ChemlabDB, CirDB
    from chemlab.io import datafile
    from chemlab.graphics.postprocessing.glow import GlowEffect
    from PySide import QtCore

    cdb = ChemlabDB()
    mol = cdb.get('molecule', 'example.norbornene')
    #mol = datafile('tests/data/3ZJE.pdb').read('system')

    v = QtViewer()

    colors = np.array([(255, 0, 0, 255)]*mol.n_atoms)
    colors[0][3] = 0

    v.widget.camera.autozoom(mol.r_array)
    sr = v.add_renderer(SphereImpostorRenderer, mol.r_array, [0.1]*mol.n_atoms,
                        colors)

    ge = v.add_post_processing(GlowEffect)
    #v.add_post_processing(GammaCorrectionEffect)
    def changeglow():
        #ge.radius = np.sin(time.time()*10.0) + 2.5
        colors[0][3] = 255 * (np.sin(time.time()*10.0)*0.5 + 0.5)
        sr.update_colors(colors)
        v.widget.update()

    timer = QtCore.QTimer()
    timer.timeout.connect(changeglow)
    timer.start(10)
    #v.add_post_processing(SSAOEffect, ssao_power = 5.0)
    #v.add_post_processing(FXAAEffect)
    #v.add_post_processing(GammaCorrectionEffect)
    v.run()
开发者ID:yotama9,项目名称:chemlab,代码行数:36,代码来源:test_graphics.py

示例13: test_point_renderer

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def test_point_renderer():
    '''To see if we're able to render a triangle'''
    vertices = [[0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [2.0, 0.0, 0.0]]
    colors = [colors.blue] * 3

    v = QtViewer()
    tr = v.add_renderer(PointRenderer, vertices, colors)
    v.run()
开发者ID:B-Rich,项目名称:chemlab,代码行数:10,代码来源:test_graphics.py

示例14: test_line_renderer

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def test_line_renderer():
    vectors = np.array([[0.0, 0.0, 0.0], [0.0, 1.0, 0.0],
                        [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]])
    colors = [blue, orange, orange, orange]
    
    v = QtViewer()
    ar = v.add_renderer(LineRenderer, vectors, colors)
    v.run()
开发者ID:,项目名称:,代码行数:10,代码来源:

示例15: test_triangle_renderer

# 需要导入模块: from chemlab.graphics.qtviewer import QtViewer [as 别名]
# 或者: from chemlab.graphics.qtviewer.QtViewer import add_renderer [as 别名]
def test_triangle_renderer():
    '''To see if we're able to render a triangle'''
    vertices = [[0.0, 0.0, 0.0], [0.0, 1.0, 0.0], [2.0, 0.0, 0.0]]
    normals = [[0.0, 0.0, 1.0], [0.0, 0.0, 1.0], [0.0, 0.0, 1.0]]
    colors = [colors.blue]* 3

    v = QtViewer()
    tr = v.add_renderer(TriangleRenderer, vertices, normals, colors, shading='toon')
    v.run()
开发者ID:B-Rich,项目名称:chemlab,代码行数:11,代码来源:test_graphics.py


注:本文中的chemlab.graphics.qtviewer.QtViewer.add_renderer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。