1
"""
2
Manipulates available services.
3
"""
4

5 4
from .gridoptimization_service import GridOptimizationService
6 4
from .torsiondrive_service import TorsionDriveService
7

8 4
__all__ = ["initialize_service", "construct_service"]
9

10

11 4
def _service_chooser(name):
12
    """
13
    Choose the correct service.
14
    """
15 1
    name = name.lower()
16 1
    if name == "torsiondrive":
17 1
        return TorsionDriveService
18 1
    elif name == "gridoptimization":
19 1
        return GridOptimizationService
20
    else:
21 0
        raise KeyError("Name {} not recognized.".format(name.title()))
22

23

24 4
def initialize_service(storage_socket, logger, service_input, tag=None, priority=None):
25
    """Initializes a service from a API call.
26

27
    Parameters
28
    ----------
29
    storage_socket : StorageSocket
30
        A StorageSocket to the currently active database
31
    logger
32
        A logger for use by the service
33
    service_input
34
        The service to be initialized.
35
    tag : Optional
36
        Optional tag to user with the service. Defaults to None
37
    priority :
38
        The priority of the service.
39

40
    Returns
41
    -------
42
    Service
43
        Returns an instantiated service
44

45
    """
46 1
    name = service_input.procedure
47 1
    return _service_chooser(name).initialize_from_api(storage_socket, logger, service_input, tag=tag, priority=priority)
48

49

50 4
def construct_service(storage_socket, logger, data):
51
    """Initializes a service from a JSON blob.
52

53
    Parameters
54
    ----------
55
    storage_socket : StorageSocket
56
        A StorageSocket to the currently active database
57
    logger
58
        A logger for use by the service
59
    data : dict
60
        The associated JSON blob with the service
61

62
    Returns
63
    -------
64
    Service
65
        Returns an instantiated service
66

67
    """
68 1
    name = data["service"]
69 1
    return _service_chooser(name)(**data, storage_socket=storage_socket, logger=logger)

Read our documentation on viewing source code .

Loading