Skip to content

resource

Models specific to the resource strategy.

OPTIMADEResourceConfig

Bases: ResourceConfig

OPTIMADE-specific resource strategy config.

Source code in oteapi_optimade/models/strategies/resource.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class OPTIMADEResourceConfig(ResourceConfig):
    """OPTIMADE-specific resource strategy config."""

    resourceType: Annotated[
        # later OPTIMADE/references and more should be added and other resources
        Literal["optimade/structures"],
        BeforeValidator(lambda x: x.lower() if isinstance(x, str) else x),
        Field(description=ResourceConfig.model_fields["resourceType"].description),
    ]
    accessUrl: Annotated[
        OPTIMADEUrl,
        Field(description="Either a base OPTIMADE URL or a full OPTIMADE URL."),
    ]
    accessService: Annotated[
        Literal["optimade", "optimade+dlite"],
        BeforeValidator(lambda x: x.lower() if isinstance(x, str) else x),
        Field(
            description="The registered strategy name for OPTIMADEResourceStrategy.",
        ),
    ]
    configuration: Annotated[
        Union[OPTIMADEConfig | OPTIMADEDLiteConfig],
        Field(
            description=(
                "OPTIMADE configuration. Contains relevant information necessary to "
                "perform OPTIMADE queries."
            ),
        ),
    ] = OPTIMADEConfig()

OPTIMADEResourceResult

Bases: AttrDict

OPTIMADE session for the resource strategy.

Source code in oteapi_optimade/models/strategies/resource.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
class OPTIMADEResourceResult(AttrDict):
    """OPTIMADE session for the resource strategy."""

    model_config = ConfigDict(validate_assignment=True, arbitrary_types_allowed=True)

    optimade_config: Annotated[
        Optional[OPTIMADEConfig],
        Field(
            description=(
                "OPTIMADE configuration. Contains relevant information necessary to "
                "perform OPTIMADE queries."
            ),
        ),
    ] = None
    optimade_resources: Annotated[
        list[dict[str, Any]],
        Field(
            description=(
                "List of OPTIMADE resources (structures, references, errors, ...) returned"
                " from the OPTIMADE request."
            ),
        ),
    ] = []  # noqa: RUF012
    optimade_resource_model: Annotated[
        str,
        Field(
            description=(
                "Importable path to the resource model to be used to parse the OPTIMADE "
                "resources in `optimade_resource`. The importable path should be a fully "
                "importable path to a module separated by a colon (`:`) to then define the "
                "resource model class name. This means one can then do:\n\n```python\n"
                "from PACKAGE.MODULE import RESOURCE_CLS\n```\nFrom the value "
                "`PACKAGE.MODULE:RESOURCE_CLS`"
            ),
            pattern=(
                r"^([a-zA-Z][a-zA-Z0-9_]*(\.[a-zA-Z][a-zA-Z0-9_]*)*"  # package.module
                r":[a-zA-Z][a-zA-Z0-9_]*)?$"  # class
            ),
        ),
    ] = ""