Coverage for src/metador_core/schema/examples/matsci.py: 100%
50 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-02 09:33 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-02 09:33 +0000
1"""Example schema for Metador in Materials Science tutorial.
3The metadata modelling here is intentionally left simple and minimal.
4"""
6from typing import List, Optional
8from pydantic import Field, PositiveFloat
9from typing_extensions import Annotated, Literal
11from ..common import rocrate, schemaorg
12from ..core import MetadataSchema
13from ..decorators import make_mandatory
16class Material(MetadataSchema):
17 """A material that was used in an experiment or simulation."""
19 class Plugin:
20 name = "example.matsci.material"
21 version = (0, 1, 0)
23 materialName: schemaorg.Text
24 """The name of material."""
26 chemicalComposition: Optional[schemaorg.Text]
27 """Chemical formula reflecting distribution of elements in the material."""
29 density: Optional[PositiveFloat]
30 """The density of the material (in g/cm3)."""
32 crystalGrainType: Optional[Literal["single_crystal", "bi_crystal", "poly_crystal"]]
33 """Type of a grain of a crystalline material."""
36class Instrument(MetadataSchema):
37 """Metadata of the instrument used to generate some data."""
39 class Plugin:
40 name = "example.matsci.instrument"
41 version = (0, 1, 0)
43 instrumentName: schemaorg.Text
44 instrumentModel: schemaorg.Text
45 instrumentManufacturer: Optional[rocrate.Organization]
48class Specimen(MetadataSchema):
49 """Metadata of the specimen tested in an experiment."""
51 class Plugin:
52 name = "example.matsci.specimen"
53 version = (0, 1, 0)
55 diameter: PositiveFloat
56 """The diameter of the specimen (in mm)."""
58 gaugeLength: PositiveFloat
59 """The gauge length of the specimen (in mm)."""
62class Method(MetadataSchema):
63 """A method used to conduct a materials science experiment or simulation."""
65 class Plugin:
66 name = "example.matsci.method"
67 version = (0, 1, 0)
69 methodType: Optional[Literal["tensile_test", "other"]]
70 """Type of method used to obtain the resulting data."""
72 instrument: Instrument
73 specimen: Specimen
76@make_mandatory("abstract", "dateCreated", "author")
77class MatsciFileInfo(schemaorg.CreativeWork):
78 """Metadata for a file with data obtained from research in Materials Science.
80 **Note:** To state authors or contributors, use the `core.person` schema.
81 """
83 class Plugin:
84 name = "example.matsci.info"
85 version = (0, 1, 0)
87 material: Annotated[List[Material], Field(default_factory=lambda: [], min_items=1)]
88 """Physical material associated with the file."""
90 method: Annotated[List[Method], Field(default_factory=lambda: [])]
91 """Materials Science method associated with the file."""