MCPcopy Create free account
hub / github.com/Materials-Consortia/optimade-python-tools / Assembly

Class Assembly

optimade/models/structures.py:217–274  ·  view source on GitHub ↗

A description of groups of sites that are statistically correlated. - **Examples** (for each entry of the assemblies list): - `{"sites_in_groups": [[0], [1]], "group_probabilities: [0.3, 0.7]}`: the first site and the second site never occur at the same time in the unit cell.

Source from the content-addressed store, hash-verified

215
216
217class Assembly(BaseModel):
218 """A description of groups of sites that are statistically correlated.
219
220 - **Examples** (for each entry of the assemblies list):
221 - `{"sites_in_groups": [[0], [1]], "group_probabilities: [0.3, 0.7]}`: the first site and the second site never occur at the same time in the unit cell.
222 Statistically, 30 % of the times the first site is present, while 70 % of the times the second site is present.
223 - `{"sites_in_groups": [[1,2], [3]], "group_probabilities: [0.3, 0.7]}`: the second and third site are either present together or not present; they form the first group of atoms for this assembly.
224 The second group is formed by the fourth site. Sites of the first group (the second and the third) are never present at the same time as the fourth site.
225 30 % of times sites 1 and 2 are present (and site 3 is absent); 70 % of times site 3 is present (and sites 1 and 2 are absent).
226
227 """
228
229 sites_in_groups: Annotated[
230 list[list[int]],
231 OptimadeField(
232 description="""Index of the sites (0-based) that belong to each group for each assembly.
233
234- **Examples**:
235 - `[[1], [2]]`: two groups, one with the second site, one with the third.
236 - `[[1,2], [3]]`: one group with the second and third site, one with the fourth.""",
237 support=SupportLevel.MUST,
238 queryable=SupportLevel.OPTIONAL,
239 ),
240 ]
241
242 group_probabilities: Annotated[
243 list[float],
244 OptimadeField(
245 description="""Statistical probability of each group. It MUST have the same length as `sites_in_groups`.
246It SHOULD sum to one.
247See below for examples of how to specify the probability of the occurrence of a vacancy.
248The possible reasons for the values not to sum to one are the same as already specified above for the `concentration` of each `species`.""",
249 support=SupportLevel.MUST,
250 queryable=SupportLevel.OPTIONAL,
251 ),
252 ]
253
254 @field_validator("sites_in_groups", mode="after")
255 @classmethod
256 def validate_sites_in_groups(cls, value: list[list[int]]) -> list[list[int]]:
257 sites = []
258 for group in value:
259 sites.extend(group)
260 if len(set(sites)) != len(sites):
261 raise ValueError(
262 f"A site MUST NOT appear in more than one group. Given value: {value}"
263 )
264 return value
265
266 @model_validator(mode="after")
267 def check_self_consistency(self) -> "Assembly":
268 if len(self.group_probabilities) != len(self.sites_in_groups):
269 raise ValueError(
270 f"sites_in_groups and group_probabilities MUST be of same length, "
271 f"but are {len(self.sites_in_groups)} and {len(self.group_probabilities)}, "
272 "respectively"
273 )
274 return self

Callers

nothing calls this directly

Calls 1

OptimadeFieldFunction · 0.90

Tested by

no test coverage detected