Esempio n. 1
0
def test_multiple_post_processing():
    from chemlab.db import ChemlabDB, CirDB
    from chemlab.io import datafile

    v = QtViewer()
    cdb = ChemlabDB()
    mol = cdb.get('molecule', 'example.norbornene')
    #mol = datafile('/home/gabriele/projects/LiCl/interface/loafintjc-heat/equilibrium.gro').read('system')
    sr = v.add_renderer(AtomRenderer,
                        mol.r_array,
                        mol.type_array,
                        'impostors',
                        shading='toon')

    # Adding multiple post processing effects

    v.add_post_processing(SSAOEffect)
    v.add_post_processing(GammaCorrectionEffect, 2.0)
    #v.add_post_processing(GammaCorrectionEffect, 2.0)
    #v.add_post_processing(FXAAEffect)

    v.run()
Esempio n. 2
0
def test_wireframe_renderer():
    from collections import defaultdict
    from chemlab.db.cirdb import CirDB

    v = QtViewer()
    #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")
    ar = v.add_renderer(WireframeRenderer, mol.r_array, mol.type_array,
                        mol.bonds)

    # Try without bonds
    #ar2 = v.add_renderer(WireframeRenderer, mol.r_array + 0.5, mol.type_array, np.array([]))

    v.run()
Esempio n. 3
0
def test_unproject():
    v = QtViewer()

    vectors = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]
    colors = [colors.blue, colors.blue]
    ar = v.add_renderer(LineRenderer, vectors, colors)

    def mouse_move(evt):
        x,y =  evt.x(), evt.y()
        w = v.widget.width()
        h = v.widget.height()
        x, y = 2*float(x)/w - 1.0, 1.0 - 2*float(y)/h

        start =  v.widget.camera.unproject(x,y,-1.0)
        print(x,y, 0.0)
        print(start)
        vectors[1] = [0.0, 0.0, 0.0]
        vectors[0] = start

        ar.update_positions(np.array(vectors))
        v.widget.repaint()
    v.mousePressEvent = mouse_move # Super Hack
    v.run()
Esempio n. 4
0
def test_cylinder_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([blue, orange, green])

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

    v = QtViewer()
    import time
    t0 = time.time()
    ar = v.add_renderer(CylinderRenderer, bounds, radii, colors)
    print time.time() - t0

    #ar.update_bounds(bounds)

    v.run()
Esempio n. 5
0
def test_pickers():
    from chemlab.graphics.pickers import SpherePicker, CylinderPicker
    from chemlab.core.molecule import guess_bonds
    from chemlab.io import datafile
    #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()
Esempio n. 6
0
def test_offline():
    # Api for PNG saving
    v = QtViewer()
    mol = cdb.get('molecule', 'example.norbornene')
    sr = v.add_renderer(AtomRenderer,
                        mol.r_array,
                        mol.type_array,
                        'impostors',
                        shading='toon')
    v.add_post_processing(SSAOEffect, kernel_size=128)
    v.add_post_processing(FXAAEffect)
    ne = v.add_post_processing(NoEffect)

    v.widget.camera.autozoom(mol.r_array)

    def dump():
        image = v.widget.toimage(2048, 2048)
        image.save("/tmp/hello.png")
        os.system("eog /tmp/hello.png")

    from PySide.QtCore import Qt
    v.key_actions[Qt.Key_A] = dump

    v.run()
Esempio n. 7
0
def showmol(mol, style='ball-and-stick',
            width=300, height=300):
    v = QtViewer()
    w = v.widget
    w.initializeGL()
    
    w.resize(width, height)
    w.resizeGL(width, height)
    
    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)
    
    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)
Esempio n. 8
0
def test_box_renderer():
    vectors = np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]])
    v = QtViewer()
    ar = v.add_renderer(BoxRenderer, vectors, origin=np.array([-0.5, -0.5, -0.5]))
    v.run()