Esempio n. 1
0
def test_stick(interactive=False):
    molecule = mol.Molecule()
    mol.add_atom(molecule, 6, 0, 0, 0)
    mol.add_atom(molecule, 6, 2, 0, 0)

    # Test errors for inadequate bonding data
    npt.assert_raises(ValueError, mol.stick, molecule)
    mol.add_bond(molecule, 0, 1, 1)

    colormodes = ['discrete', 'single']
    bond_thickness = [0.1, 0.12]
    table = mol.PTable()
    colors = np.array([[table.atom_color(6)],
                       [[150/255, 150/255, 150/255],
                        [50/255, 50/255, 50/255]]], dtype=object)
    scene = window.Scene()
    for i, colormode in enumerate(colormodes):
        test_actor = mol.stick(molecule, colormode, bond_thickness[i])
        scene.add(test_actor)
        scene.reset_camera()
        scene.reset_clipping_range()

        if interactive:
            window.show(scene)

        npt.assert_equal(scene.GetActors().GetNumberOfItems(), 1)

        arr = window.snapshot(scene)
        report = window.analyze_snapshot(arr, colors=colors[i])
        npt.assert_equal(report.objects, 1)
        scene.clear()

    # Testing warnings
    npt.assert_warns(UserWarning, mol.stick, molecule, 'multiple')
Esempio n. 2
0
def test_bounding_box(interactive=False):
    scene = window.Scene()
    molecule = mol.Molecule()
    mol.add_atom(molecule, 6, 0, 0, 0)
    mol.add_atom(molecule, 6, 1, 1, 1)
    mol.add_bond(molecule, 0, 1, 1)

    molecule_actor = mol.stick(molecule)
    test_box = mol.bounding_box(molecule, colors=(0, 1, 1), linewidth=0.1)
    scene.add(molecule_actor)
    scene.add(test_box)

    if interactive:
        window.show(scene)

    npt.assert_equal(scene.GetActors().GetNumberOfItems(), 2)

    table = mol.PTable()
    colors = np.array([table.atom_color(1), table.atom_color(6)])
    arr = window.snapshot(scene)
    report = window.analyze_snapshot(arr, colors=colors)
    npt.assert_equal(report.objects, 1)
    scene.clear()
Esempio n. 3
0
# 4. Computing the bonding information for the molecule.
# 5. Generating and adding various molecular representaions to the scene.
scene = window.Scene()
scene.set_camera(position=(20, 10, 0),
                 focal_point=(0, 0, 0),
                 view_up=(0, 1, 0))
scene.zoom(0.8)
axes_actor = actor.axes()
scene.add(axes_actor)

molecule = mol.Molecule(atomic_numbers, atom_coords, atom_types, model,
                        residue_seq, chain, sheets, helix, is_hetatm)
mol.compute_bonding(molecule)

# stick representation
scene.add(mol.stick(molecule, bond_thickness=0.2))

# ribbon representation
scene.add(mol.ribbon(molecule))

# ball and stick representation
# scene.add(mol.ball_stick(molecule, atom_scale_factor=0.3,
#                          bond_thickness=0.2))

# bounding box
scene.add(mol.bounding_box(molecule, linewidth=0.4))

# sphere representation
# scene.add(mol.sphere_cpk(molecule))

###############################################################################