Example #1
0
        #thr_a2 = thr_a * thr_a
        thr_b2 = thr_b * thr_b
        dr2  = ((r_array[i] - r_array[j])**2).sum()
        
        # print(dr2)
        
        if dr2 < thr_b2:
            bonds.append((i, j))
    return np.array(bonds)

# END_PATCH ---

Si = Molecule([Atom('Si', [0.0, 0.0, 0.0])])
la = 0.5431

s = crystal([[0.0, 0.0, 0.0], [0.25, 0.25, 0.25]], # Fractional Positions
[Si, Si], # Molecules
225, # Space Group
cellpar = [la,la,la, 90, 90, 90], # unit cell parameters
repetitions = [2, 2, 2]) # unit cell repetitions in each direction

bonds = guess_bonds(s.r_array, s.type_array, threshold=0.02)


#s.bonds = [[0,1], [1, 2]]
v = QtViewer()
v.add_renderer(BallAndStickRenderer, s.r_array, s.type_array,
               bonds,shading='phong')
v.run()

Example #2
0
        # print(dr2)

        if dr2 < thr_b2:
            bonds.append((i, j))
    return np.array(bonds)


# END_PATCH ---

Si = Molecule([Atom('Si', [0.0, 0.0, 0.0])])
la = 0.5431

s = crystal(
    [[0.0, 0.0, 0.0], [0.25, 0.25, 0.25]],  # Fractional Positions
    [Si, Si],  # Molecules
    225,  # Space Group
    cellpar=[la, la, la, 90, 90, 90],  # unit cell parameters
    repetitions=[2, 2, 2])  # unit cell repetitions in each direction

bonds = guess_bonds(s.r_array, s.type_array, threshold=0.02)

#s.bonds = [[0,1], [1, 2]]
v = QtViewer()
v.add_renderer(BallAndStickRenderer,
               s.r_array,
               s.type_array,
               bonds,
               shading='phong')
v.run()
Example #3
0
import numpy as np
v1 = np.array([1.0, 0.0, -1.0/np.sqrt(2)])
v2 = np.array([-1.0, 0.0, -1.0/np.sqrt(2)])
v3 = np.array([0.0, 1.0, 1.0/np.sqrt(2)])
v4 = np.array([0.0, -1.0, 1.0/np.sqrt(2)])

from chemlab.graphics.qt import QtViewer
from chemlab.graphics.renderers import PointRenderer
from chemlab.graphics.colors import black, green, blue, red

colors = [black, green, blue, red]
v = QtViewer()
v.add_renderer(PointRenderer, np.array([v1, v2, v3, v4]), colors)

from chemlab.graphics.renderers import TriangleRenderer

vertices = np.array([
    v1, v4, v3,
    v3, v4, v2,
    v1, v3, v2,
    v2, v4, v1
])

colors = [green] * 12

# Normals: cross-product for each face
n1 = -np.cross(v4 - v1, v3 - v1)
n1 /= np.linalg.norm(n1)

n2 = -np.cross(v4 - v3, v2 - v3)
n2 /= np.linalg.norm(n2)
Example #4
0
from chemlab.db import CirDB
from chemlab.graphics.qt import QtViewer
from chemlab.graphics.renderers import AtomRenderer
from chemlab.graphics.postprocessing import FXAAEffect, SSAOEffect

# A series of compounds to display
compounds = ["methane", "ethane", "propane", "butane"]

db = CirDB()

# Prepare the viewer
v = QtViewer()
v.widget.initializeGL()
v.add_post_processing(SSAOEffect, kernel_size=128, kernel_radius=1.0)
v.add_post_processing(FXAAEffect)

for compound in compounds:
    mol = db.get("molecule", compound)
    rend = v.add_renderer(AtomRenderer, mol.r_array, mol.type_array)

    v.widget.camera.autozoom(mol.r_array)
    # Give some extra zoom
    v.widget.camera.mouse_zoom(1.0)

    v.widget.toimage(300, 300).save(compound + '.png')

    # Cleanup
    v.remove_renderer(rend)