Ejemplo n.º 1
0
def test_sphere_cpk(interactive=False):
    atomic_numbers, atom_coords = get_default_molecular_info()
    molecule = mol.Molecule(atomic_numbers, atom_coords)
    table = mol.PTable()
    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')
Ejemplo n.º 2
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')
Ejemplo n.º 3
0
def test_periodic_table():
    # Testing class PeriodicTable()
    table = mol.PTable()
    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")
Ejemplo 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.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()
Ejemplo n.º 5
0
downloadurl = "https://files.rcsb.org/download/"
pdbfn = pdb_code + ".pdb"
flag = 0
if not os.path.isfile(pdbfn):
    flag = 1
    url = downloadurl + pdbfn
    outfnm = os.path.join(pdbfn)
    try:
        urllib.request.urlretrieve(url, outfnm)
    except Exception:
        print("Error in downloading the file!")

###############################################################################
# Creating a `PeriodicTable()` object to obtain atomic numbers from names of
# elements
table = mol.PTable()

###############################################################################
# Creating empty lists which will be filled with atomic information as we
# parse the pdb file.
NumberOfAtoms = 0

atom_coords = []
atomic_numbers = []
atom_types = []
model = []
sheets = []
helix = []
residue_seq = []
chain = []
is_hetatm = []