Statistiques
| Révision :

root / ase / visualize / vtk / __init__.py @ 1

Historique | Voir | Annoter | Télécharger (1,06 ko)

1
try:
2
    import vtk
3
    hasvtk = True
4
    hasmpi = hasattr(vtk, 'vtkMPIController')
5
except ImportError:
6
    hasvtk = False
7
    hasmpi = False
8

    
9
def requirevtk(code=0, parallel=False):
10
    from ase.test import NotAvailable
11
    if not hasvtk:
12
        # VTK required but not installed, force termination
13
        # with exit status determined by the code argument.
14
        raise NotAvailable('VTK is not installed.', code)
15
    if parallel and not hasmpi:
16
        # VTK MPI required but not installed, force termination
17
        # with exit status determined by the code argument.
18
        raise NotAvailable('VTK is not MPI compatible.', code)
19

    
20
def probe_vtk_kilobyte(default=None):
21
    if not hasvtk:
22
        return default
23

    
24
    from vtk import vtkCharArray
25
    vtk_da = vtkCharArray()
26
    vtk_da.SetNumberOfComponents(1)
27
    vtk_da.SetNumberOfTuples(1024**2)
28

    
29
    # Size of 1 MB = 1024**2 bytes in "VTK kilobytes"
30
    size = vtk_da.GetActualMemorySize()
31
    if size == 1024:
32
        return 1024
33
    elif round(abs(size-1024**2/1e3)) == 0:
34
        return 1e3
35
    else:
36
        return default