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.PeriodicTable()
    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_sphere_cpk(interactive=False):
    atomic_numbers, atom_coords = get_default_molecular_info()
    molecule = mol.Molecule(atomic_numbers, atom_coords)
    table = mol.PeriodicTable()
    colormodes = ['discrete', 'single']
    colors = np.array(
        [[table.atom_color(1), table.atom_color(6)],
         [[150 / 255, 250 / 255, 150 / 255]]],
        dtype=object)
    scene = window.Scene()
    for i, colormode in enumerate(colormodes):
        test_actor = mol.sphere_cpk(molecule, colormode)

        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.sphere_cpk, molecule, 'multiple')
Esempio n. 3
0
def test_periodic_table():
    # Testing class PeriodicTable()
    table = mol.PeriodicTable()
    npt.assert_equal(table.atomic_number('C'), 6)
    npt.assert_equal(table.element_name(7), 'Nitrogen')
    npt.assert_equal(table.atomic_symbol(8), 'O')
    npt.assert_allclose(table.atomic_radius(1, 'VDW'), 1.2, 0.1, 0)
    npt.assert_allclose(table.atomic_radius(6, 'Covalent'), 0.75, 0.1, 0)
    npt.assert_array_almost_equal(table.atom_color(1), np.array([1, 1, 1]))

    # Test errors
    npt.assert_raises(ValueError, table.atomic_radius, 4, "test")
Esempio n. 4
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.PeriodicTable()
    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()