Example #1
0
def test_merge_system():
    # take a protein
    from chemlab.io import datafile
    from chemlab.graphics import display_system

    from chemlab.db import ChemlabDB

    water = ChemlabDB().get("molecule", "example.water")

    prot = datafile("tests/data/3ZJE.pdb").read("system")

    # Take a box of water
    NWAT = 50000
    bsize = 20.0
    pos = np.random.random((NWAT, 3)) * bsize
    wat = water.copy()

    s = System.empty(NWAT, NWAT*3, box_vectors=np.eye(3)*bsize)
    for i in range(NWAT):
        wat.move_to(pos[i])
        s.add(wat)

    prot.r_array += 10
    s = merge_systems(s, prot, 0.5)

    display_system(s, 'ball-and-stick')
Example #2
0
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()
Example #3
0
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()
Example #4
0
def test_random():
    '''Testing random made box'''
    from chemlab.db import ChemlabDB
    cdb = ChemlabDB()
    na = Molecule([Atom('Na', [0.0, 0.0, 0.0])])
    cl = Molecule([Atom('Cl', [0.0, 0.0, 0.0])])
    wat = cdb.get("molecule", 'gromacs.spce')

    s = random_lattice_box([na, cl, wat], [160, 160, 160], [4, 4, 4])
Example #5
0
def test_molecular_viewer():
    from chemlab.mviewer.qtmolecularviewer import QtMolecularViewer
    from chemlab.mviewer.representations import BallAndStickRepresentation
    cdb = ChemlabDB()

    mol = cdb.get('molecule', 'example.norbornene')
    mol.guess_bonds()
    v = QtMolecularViewer()
    
    v.run()
Example #6
0
def test_molecular_viewer():
    from chemlab.graphics.qtmolecularviewer import QtMolecularViewer
    from chemlab.db import ChemlabDB, CirDB
    from chemlab.io import datafile

    cdb = ChemlabDB()

    mol = cdb.get('molecule', 'example.norbornene')

    #mol = datafile('tests/data/3ZJE.pdb').read('system')
    #mol = datafile('tests/data/naclwater.gro').read('system')
    mol.guess_bonds()

    v = QtMolecularViewer(mol)

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

    def on_action1():
        if len(v.representation.selection) == 2:
            i, j = v.representation.selection
            distsq = ((mol.r_array[j] - mol.r_array[i])**2).sum()
            print 'distance between', i, j, np.sqrt(distsq)

    def select_all_atoms():
        which = v.representation.selection[0]
        at = mol.type_array[which]
        sel = mol.type_array == at
        v.representation.make_selection(sel.nonzero()[0])

    def select_all_molecules():
        which = v.representation.last_modified
        if which is None:
            return

        at = mol.type_array[which]
        sel = mol.type_array == at
        allmol = mol.atom_to_molecule_indices(sel)
        allmol = mol.mol_to_atom_indices(allmol)
        v.representation.make_selection(allmol, additive=True)

    def change_representation():
        BallAndStickRepresentation = 0
        # We need two representations
        rep = v.add_representation(BallAndStickRepresentation, mol)
        rep.set_mask(self.selection)
        rep.set_mask(not self.selection)

    def scale_radii():
        #v.representation.scale_radii(v.representation.selection, 0.9)
        v.representation.hide(v.representation.selection)

    v.run()
Example #7
0
def test_molecular_viewer():
    from chemlab.graphics.qtmolecularviewer import QtMolecularViewer
    from chemlab.db import ChemlabDB, CirDB
    from chemlab.io import datafile
    
    cdb = ChemlabDB()
    
    mol = cdb.get('molecule', 'example.norbornene')
    
    mol = datafile('tests/data/3ZJE.pdb').read('system')
    v = QtMolecularViewer(mol)
    v.highlight([0, 2, 8])
    v.run()
    
Example #8
0
def test_multiple_post_processing():
    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()
Example #9
0
def test_ssao():
    from chemlab.db import ChemlabDB, CirDB
    from chemlab.io import datafile
    
    cdb = ChemlabDB()
    
    mol = cdb.get('molecule', 'example.norbornene')
    
    mol = datafile('tests/data/3ZJE.pdb').read('system')
    v = QtViewer()
    

    v.widget.camera.autozoom(mol.r_array)
    v.widget.post_processing.append(SSAOEffect(v.widget, kernel_size=16, kernel_radius=3.0, ssao_power=2.7))
    sr = v.add_renderer(AtomRenderer, mol.r_array, mol.type_array, 'impostors')
    #ar = v.add_renderer(BallAndStickRenderer, mol.r_array, mol.type_array, [])
    
    v.run()
Example #10
0
def test_outline():
    from chemlab.db import ChemlabDB, CirDB
    from chemlab.io import datafile
    from chemlab.graphics.postprocessing.outline import OutlineEffect
    
    cdb = ChemlabDB()
    mol = cdb.get('molecule', 'example.norbornene')
    
    mol = datafile('tests/data/3ZJE.pdb').read('system')
    #mol = datafile('tests/data/water.gro').read('system')
    #mol = datafile('tests/data/benzene.mol').read('molecule')
    v = QtViewer()

    v.widget.camera.autozoom(mol.r_array)
    sr = v.add_renderer(AtomRenderer, mol.r_array, mol.type_array,
                        'impostors', shading='toon')
    
    v.add_post_processing(OutlineEffect, 'depthonly')
    v.add_post_processing(FXAAEffect)
    v.add_post_processing(GammaCorrectionEffect)
    v.run()
Example #11
0
def test_local():
    db = ChemlabDB()
    bz = db.get("molecule", "example.norbornene")

    pre_string = bz.tojson()
    db = LocalDB("/tmp/testdb/")
    db.store("molecule", 'norbornene', bz, nowarn=True)
    
    post_string = db.get('molecule', 'norbornene').tojson()
    assert pre_string == post_string
    
    # Do the same thing for a system of 3 norbornenes
    s = System([bz.copy() for i in range(3)])
    pre_string = s.tojson()
    db.store("system", 'norbornene-3', s, nowarn=True)
    post_string = db.get('system', 'norbornene-3').tojson()
    
    assert pre_string == post_string
Example #12
0
def test_local():
    db = ChemlabDB()
    bz = db.get("molecule", "example.norbornene")
    pre_dict = bz.to_dict()

    db = LocalDB("/tmp/testdb/")
    db.store("molecule", 'norbornene', bz, nowarn=True)
    
    post_dict = db.get('molecule', 'norbornene').to_dict()
    
    npeq_(pre_dict['r_array'], post_dict['r_array'])
    
    # Do the same thing for a system of 3 norbornenes
    s = System([bz.copy() for i in range(3)])
    pre_dict = s.to_dict()
    db.store("system", 'norbornene-3', s, nowarn=True)
    post_dict = db.get('system', 'norbornene-3').to_dict()
    
    npeq_(pre_dict['r_array'], post_dict['r_array'])
Example #13
0
def test_glow():
    from chemlab.db import ChemlabDB, CirDB
    from chemlab.io import datafile
    from chemlab.graphics.postprocessing.glow import GlowEffect
    
    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)
    
    v.add_post_processing(GlowEffect)
    #v.add_post_processing(SSAOEffect, ssao_power = 5.0)
    #v.add_post_processing(FXAAEffect)
    #v.add_post_processing(GammaCorrectionEffect)
    v.run()