-
Notifications
You must be signed in to change notification settings - Fork 62
/
material.py
161 lines (126 loc) · 4.9 KB
/
material.py
1
2
3
4
5
6
7
8
9
10
11
12
13
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
43
44
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
""" Core definition of a Materials Document """
from __future__ import annotations
from datetime import datetime
from functools import partial
from typing import ClassVar, Mapping, Optional, Sequence, Type, TypeVar, Union
from pydantic import BaseModel, Field, create_model
from pymatgen.analysis.magnetism import CollinearMagneticStructureAnalyzer, Ordering
from emmet.core.structure import StructureMetadata
from emmet.stubs import Structure
class PropertyOrigin(BaseModel):
"""
Provenance document for the origin of properties in a material document
"""
name: str = Field(..., description="The property name")
task_id: str = Field(..., description="The calculation ID this property comes from")
last_updated: datetime = Field(
description="The timestamp when this calculation was last updated",
default_factory=datetime.utcnow,
)
S = TypeVar("S", bound="PropertyDoc")
class PropertyDoc(StructureMetadata):
"""
Base model definition for any singular materials property. This may contain any amount
of structure metadata for the purpose of search
This is intended to be inherited and extended not used directly
"""
property_name: ClassVar[str]
material_id: str = Field(
...,
description="The ID of the material, used as a universal reference across proeprty documents."
"This comes in the form: mp-******",
)
last_updated: datetime = Field(
description="Timestamp for the most recent calculation update for this property",
default_factory=datetime.utcnow,
)
origins: Sequence[PropertyOrigin] = Field(
[], description="Dictionary for tracking the provenance of properties"
)
warnings: Sequence[str] = Field(
None, description="Any warnings related to this property"
)
sandboxes: Sequence[str] = Field(
["core"],
description="List of sandboxes this property belongs to."
" Sandboxes provide a way of controlling access to materials."
" No sandbox means this materials is openly visible",
)
@classmethod
def from_structure( # type: ignore[override]
cls: Type[S], structure: Structure, material_id: str, **kwargs
) -> S:
"""
Builds a materials document using the minimal amount of information
"""
return super().from_structure( # type: ignore
structure=structure,
material_id=material_id,
include_structure=False,
**kwargs
)
T = TypeVar("T", bound="MaterialsDoc")
class MaterialsDoc(StructureMetadata):
"""
Definition for a core Materials Document
"""
# Only material_id is required for all documents
material_id: str = Field(
...,
description="The ID of this material, used as a universal reference across proeprty documents."
"This comes in the form: mp-******",
)
structure: Structure = Field(
..., description="The best structure for this material"
)
deprecated: bool = Field(
True,
description="Whether this materials document is deprecated.",
)
initial_structures: Sequence[Structure] = Field(
[],
description="Initial structures used in the DFT optimizations corresponding to this material",
)
task_ids: Sequence[str] = Field(
[],
title="Calculation IDs",
description="List of Calculations IDs used to make this Materials Document",
)
deprecated_tasks: Sequence[str] = Field([], title="Deprecated Tasks")
calc_types: Mapping[str, str] = Field(
None,
description="Calculation types for all the calculations that make up this material",
)
last_updated: datetime = Field(
description="Timestamp for when this document was last updated",
default_factory=datetime.utcnow,
)
created_at: datetime = Field(
description="Timestamp for when this material document was first created",
default_factory=datetime.utcnow,
)
origins: Sequence[PropertyOrigin] = Field(
None, description="Dictionary for tracking the provenance of properties"
)
warnings: Sequence[str] = Field(
[], description="Any warnings related to this material"
)
sandboxes: Sequence[str] = Field(
["core"],
description="List of sandboxes this material belongs to."
" Sandboxes provide a way of controlling access to materials."
" Core is the primary sandbox for fully open documents",
)
@classmethod
def from_structure( # type: ignore[override]
cls: Type[T], structure: Structure, material_id: str, **kwargs
) -> T:
"""
Builds a materials document using the minimal amount of information
"""
return super().from_structure( # type: ignore
structure=structure,
material_id=material_id,
include_structure=True,
**kwargs
)