core
category
CategoryCollection
Bases: CollectionBase
Handles loop-style category containers (e.g. AtomSites).
Each item is a CategoryItem (component).
Source code in src/easydiffraction/core/category.py
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
__str__()
Human-readable representation of this component.
Source code in src/easydiffraction/core/category.py
190 191 192 193 194 | |
add(item)
Insert or replace a pre-built item into the collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
A |
required |
Source code in src/easydiffraction/core/category.py
223 224 225 226 227 228 229 230 231 232 233 | |
as_cif
property
Return CIF representation of this object.
create(**kwargs)
Create a new item with the given attributes and add it.
A default instance of the collection's item type is created,
then each keyword argument is applied via setattr.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
object
|
Attribute names and values for the new item. |
{}
|
Source code in src/easydiffraction/core/category.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 | |
from_cif(block)
Populate this collection from a CIF block.
Source code in src/easydiffraction/core/category.py
219 220 221 | |
parameters
property
All parameters from all items in this collection.
unique_name
property
Return None; collections have no unique name.
CategoryItem
Bases: GuardedBase
Base class for items in a category collection.
Source code in src/easydiffraction/core/category.py
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 | |
__str__()
Human-readable representation of this component.
Source code in src/easydiffraction/core/category.py
26 27 28 29 30 | |
as_cif
property
Return CIF representation of this object.
from_cif(block, idx=0)
Populate this item from a CIF block.
Source code in src/easydiffraction/core/category.py
59 60 61 | |
help()
Print parameters, other properties, and methods.
Source code in src/easydiffraction/core/category.py
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 | |
parameters
property
All GenericDescriptorBase instances on this item.
unique_name
property
Fully qualified name: datablock, category, entry.
collection
Lightweight container for guarded items with name-based indexing.
CollectionBase maintains an ordered list of items and a lazily
rebuilt index by the item's identity key. It supports dict-like access
for get, set and delete, along with iteration over the items.
CollectionBase
Bases: GuardedBase
A minimal collection with stable iteration and name indexing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item_type
|
type
|
Type of items accepted by the collection. Used for validation and tooling; not enforced at runtime here. |
required |
Source code in src/easydiffraction/core/collection.py
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 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
__contains__(name)
Check whether an item with the given key exists.
Source code in src/easydiffraction/core/collection.py
88 89 90 91 | |
__delitem__(name)
Delete an item by key or raise KeyError if missing.
Source code in src/easydiffraction/core/collection.py
78 79 80 81 82 83 84 85 86 | |
__getitem__(key)
Return an item by name or positional index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str | int
|
Identity key (str) or zero-based positional index (int). |
required |
Returns:
| Type | Description |
|---|---|
GuardedBase
|
The item matching the given key or index. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If key is neither |
Source code in src/easydiffraction/core/collection.py
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 | |
__iter__()
Iterate over items in insertion order.
Source code in src/easydiffraction/core/collection.py
93 94 95 | |
__len__()
Return the number of items in the collection.
Source code in src/easydiffraction/core/collection.py
97 98 99 | |
__setitem__(name, item)
Insert or replace an item under the given identity key.
Source code in src/easydiffraction/core/collection.py
65 66 67 68 69 70 71 72 73 74 75 76 | |
help()
Print a summary of public attributes and contained items.
Source code in src/easydiffraction/core/collection.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
items()
Yield (key, item) pairs in insertion order.
Source code in src/easydiffraction/core/collection.py
145 146 147 | |
keys()
Yield keys for all items in insertion order.
Source code in src/easydiffraction/core/collection.py
137 138 139 | |
names
property
List of all item keys in the collection.
remove(name)
Remove an item by its key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Identity key of the item to remove. |
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no item with the given key exists. |
Source code in src/easydiffraction/core/collection.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
values()
Yield items in insertion order.
Source code in src/easydiffraction/core/collection.py
141 142 143 | |
datablock
DatablockCollection
Bases: CollectionBase
Collection of top-level datablocks (e.g. Structures, Experiments).
Each item is a DatablockItem.
Subclasses provide explicit add_from_* convenience methods that
delegate to the corresponding factory classmethods, then call
:meth:add with the resulting item.
Source code in src/easydiffraction/core/datablock.py
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |
__str__()
Human-readable representation of this component.
Source code in src/easydiffraction/core/datablock.py
147 148 149 150 151 | |
add(item)
Add a pre-built item to the collection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
object
|
A |
required |
Source code in src/easydiffraction/core/datablock.py
135 136 137 138 139 140 141 142 143 144 145 | |
as_cif
property
Return CIF representation of this object.
fittable_parameters
property
All non-constrained Parameters in this collection.
free_parameters
property
All fittable parameters that are currently marked as free.
parameters
property
All parameters from all datablocks in this collection.
unique_name
property
Return None; collections have no unique name.
DatablockItem
Bases: GuardedBase
Base class for items in a datablock collection.
Source code in src/easydiffraction/core/datablock.py
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 | |
__repr__()
Developer-oriented representation of this component.
Source code in src/easydiffraction/core/datablock.py
27 28 29 30 31 32 | |
__str__()
Human-readable representation of this component.
Source code in src/easydiffraction/core/datablock.py
20 21 22 23 24 25 | |
as_cif
property
Return CIF representation of this object.
categories
property
All category objects in this datablock by priority.
help()
Print a summary of public attributes and categories.
Source code in src/easydiffraction/core/datablock.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
parameters
property
All parameters from all categories in this datablock.
unique_name
property
Unique name of this datablock item (from identity).
diagnostic
Diagnostics helpers for logging validation messages.
This module centralizes human-friendly error and debug logs for attribute validation and configuration checks.
Diagnostics
Centralized logger for attribute errors and validation hints.
Source code in src/easydiffraction/core/diagnostic.py
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 | |
attr_error(name, key, allowed, label='Allowed')
staticmethod
Log unknown attribute access and suggest closest key.
Source code in src/easydiffraction/core/diagnostic.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
choice_mismatch(name, value, allowed, current=None, default=None)
staticmethod
Log an invalid choice against allowed values.
Source code in src/easydiffraction/core/diagnostic.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
no_value(name, default)
staticmethod
Log that default will be used due to missing value.
Source code in src/easydiffraction/core/diagnostic.py
138 139 140 141 | |
none_value(name)
staticmethod
Log explicit None provided by a user.
Source code in src/easydiffraction/core/diagnostic.py
143 144 145 146 | |
none_value_skip_range(name)
staticmethod
Log that range validation is skipped due to None.
Source code in src/easydiffraction/core/diagnostic.py
148 149 150 151 152 153 | |
range_mismatch(name, value, ge, le, current=None, default=None)
staticmethod
Log range violation for a numeric value.
Source code in src/easydiffraction/core/diagnostic.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
readonly_error(name, key=None)
staticmethod
Log an attempt to change a read-only attribute.
Source code in src/easydiffraction/core/diagnostic.py
42 43 44 45 46 47 48 49 50 51 | |
regex_mismatch(name, value, pattern, current=None, default=None)
staticmethod
Log a regex mismatch with the expected pattern.
Source code in src/easydiffraction/core/diagnostic.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
type_mismatch(name, value, expected_type, current=None, default=None)
staticmethod
Log a type mismatch and keep current or default value.
Source code in src/easydiffraction/core/diagnostic.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
type_override_error(cls_name, expected, got)
staticmethod
Report an invalid DataTypes override.
Used when descriptor and AttributeSpec types conflict.
Source code in src/easydiffraction/core/diagnostic.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
validated(name, value, stage=None)
staticmethod
Log that a value passed a validation stage.
Source code in src/easydiffraction/core/diagnostic.py
155 156 157 158 159 | |
factory
Base factory with registration, lookup, and context-dependent defaults.
Concrete factories inherit from FactoryBase and only need to define
_default_rules.
FactoryBase
Shared base for all factories.
Subclasses must set:
_default_rules-- mapping offrozensetconditions to tag strings. Usefrozenset(): 'tag'for a universal default.
The __init_subclass__ hook ensures every subclass gets its own
independent _registry list.
Source code in src/easydiffraction/core/factory.py
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
__init_subclass__(**kwargs)
Give each subclass its own independent registry and rules.
Source code in src/easydiffraction/core/factory.py
39 40 41 42 43 44 | |
create(tag, **kwargs)
classmethod
Instantiate a registered class by tag.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tag
|
str
|
|
required |
**kwargs
|
object
|
Forwarded to the class constructor. |
{}
|
Returns:
| Type | Description |
|---|---|
object
|
A new instance of the registered class. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If tag is not in the registry. |
Source code in src/easydiffraction/core/factory.py
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 | |
create_default_for(**conditions)
classmethod
Instantiate the default class for a given context.
Combines default_tag(**conditions) with create(tag).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**conditions
|
object
|
Experimental-axis values. |
{}
|
Returns:
| Type | Description |
|---|---|
object
|
A new instance of the default class. |
Source code in src/easydiffraction/core/factory.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
default_tag(**conditions)
classmethod
Resolve the default tag for a given experimental context.
Uses largest-subset matching: the rule whose key is the
biggest subset of the given conditions wins. A rule with an
empty key (frozenset()) acts as a universal fallback.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**conditions
|
object
|
Experimental-axis values, e.g.
|
{}
|
Returns:
| Type | Description |
|---|---|
str
|
The resolved default tag string. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no rule matches the given conditions. |
Source code in src/easydiffraction/core/factory.py
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 | |
register(klass)
classmethod
Class decorator to register a concrete class.
Usage::
@SomeFactory.register class MyClass(SomeBase): type_info = TypeInfo(...)
Returns the class unmodified.
Source code in src/easydiffraction/core/factory.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 | |
show_supported(*, calculator=None, sample_form=None, scattering_type=None, beam_mode=None, radiation_probe=None)
classmethod
Pretty-print a table of supported types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calculator
|
object
|
Optional |
None
|
sample_form
|
object
|
Optional |
None
|
scattering_type
|
object
|
Optional |
None
|
beam_mode
|
object
|
Optional |
None
|
radiation_probe
|
object
|
Optional |
None
|
Source code in src/easydiffraction/core/factory.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
supported_for(*, calculator=None, sample_form=None, scattering_type=None, beam_mode=None, radiation_probe=None)
classmethod
Return classes matching conditions and/or calculator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calculator
|
object
|
Optional |
None
|
sample_form
|
object
|
Optional |
None
|
scattering_type
|
object
|
Optional |
None
|
beam_mode
|
object
|
Optional |
None
|
radiation_probe
|
object
|
Optional |
None
|
Returns:
| Type | Description |
|---|---|
List[Type]
|
Classes matching the given conditions. |
Source code in src/easydiffraction/core/factory.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
supported_tags()
classmethod
Return list of all supported tags.
Source code in src/easydiffraction/core/factory.py
74 75 76 77 | |
guard
GuardedBase
Bases: ABC
Base class enforcing controlled attribute access and linkage.
Source code in src/easydiffraction/core/guard.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 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
__getattr__(key)
Raise a descriptive error for unknown attribute access.
Source code in src/easydiffraction/core/guard.py
31 32 33 34 35 36 37 38 39 40 41 | |
__repr__()
Return the developer representation of this object.
Source code in src/easydiffraction/core/guard.py
27 28 29 | |
__setattr__(key, value)
Set an attribute with access-control diagnostics.
Source code in src/easydiffraction/core/guard.py
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 | |
__str__()
Return the string representation of this object.
Source code in src/easydiffraction/core/guard.py
23 24 25 | |
as_cif
abstractmethod
property
Return CIF representation (implemented by subclasses).
help()
Print a summary of public properties and methods.
Source code in src/easydiffraction/core/guard.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
parameters
abstractmethod
property
Return a list of parameters (implemented by subclasses).
unique_name
property
Fallback unique name: the class name.
identity
Identity helpers to build CIF-like hierarchical names.
Used by containers and items to expose datablock/category/entry names without tight coupling.
Identity
Resolve datablock/category/entry relationships lazily.
Source code in src/easydiffraction/core/identity.py
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 | |
category_code
property
writable
Category code like 'atom_site' or 'background'.
category_entry_name
property
writable
Category entry name or None if not set.
datablock_entry_name
property
writable
Datablock entry name or None if not set.
metadata
Metadata dataclasses for factory-created classes.
Three frozen dataclasses describe a concrete class:
TypeInfo— stable tag and human-readable description. -Compatibility— experimental conditions (multiple fields). -CalculatorSupport— which calculation engines can handle it.
CalculatorSupport
dataclass
Which calculation engines can handle this class.
Attributes:
| Name | Type | Description |
|---|---|---|
calculators |
FrozenSet, default=frozenset()
|
Frozenset of |
Source code in src/easydiffraction/core/metadata.py
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 | |
supports(calculator)
Check if a specific calculator can handle this class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
calculator
|
object
|
A |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in src/easydiffraction/core/metadata.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
Compatibility
dataclass
Experimental conditions under which a class can be used.
Each field is a frozenset of enum values representing the set of supported values for that axis. An empty frozenset means "compatible with any value of this axis" (i.e. no restriction).
Source code in src/easydiffraction/core/metadata.py
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 | |
supports(sample_form=None, scattering_type=None, beam_mode=None, radiation_probe=None)
Check if this compatibility matches the given conditions.
Each argument is an optional enum member. Returns True if
every provided value is in the corresponding frozenset (or the
frozenset is empty, meaning any).
Example::
compat.supports( scattering_type=ScatteringTypeEnum.BRAGG, beam_mode=BeamModeEnum.CONSTANT_WAVELENGTH, )
Source code in src/easydiffraction/core/metadata.py
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 | |
TypeInfo
dataclass
Stable identity and description for a factory-created class.
Attributes:
| Name | Type | Description |
|---|---|---|
tag |
str
|
Short, stable string identifier used for serialization,
user-facing selection, and factory lookup. Must be unique within
a factory's registry. Examples: |
description |
str, default=''
|
One-line human-readable explanation. Used in
|
Source code in src/easydiffraction/core/metadata.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |
singleton
ConstraintsHandler
Bases: SingletonBase
Manage parameter constraints using aliases and expressions.
Uses the asteval interpreter for safe evaluation of mathematical expressions. Constraints are defined as: lhs_alias = expression(rhs_aliases).
Source code in src/easydiffraction/core/singleton.py
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
apply()
Evaluate constraints and applies them to dependent parameters.
For each constraint: - Evaluate RHS using current values of aliases - Locate the dependent parameter by alias → uid → param - Update its value and mark it as constrained
Source code in src/easydiffraction/core/singleton.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
set_aliases(aliases)
Set the alias map (name → parameter wrapper).
Called when user registers parameter aliases like: alias='biso_La', param=model.atom_sites['La'].b_iso
Source code in src/easydiffraction/core/singleton.py
108 109 110 111 112 113 114 115 | |
set_constraints(constraints)
Set the constraints and triggers parsing into internal format.
Called when user registers expressions like: lhs_alias='occ_Ba', rhs_expr='1 - occ_La'
Source code in src/easydiffraction/core/singleton.py
117 118 119 120 121 122 123 124 125 | |
SingletonBase
Base class to implement Singleton pattern.
Ensures only one shared instance of a class is ever created. Useful for managing shared state across the library.
Source code in src/easydiffraction/core/singleton.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | |
get()
classmethod
Return the shared instance, creating it if needed.
Source code in src/easydiffraction/core/singleton.py
28 29 30 31 32 33 | |
UidMapHandler
Bases: SingletonBase
Global handler to manage UID-to-Parameter object mapping.
Source code in src/easydiffraction/core/singleton.py
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 | |
add_to_uid_map(parameter)
Add a single Parameter or Descriptor object to the UID map.
Only Descriptor or Parameter instances are allowed (not Components or others).
Source code in src/easydiffraction/core/singleton.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
get_uid_map()
Return the current UID-to-Parameter map.
Source code in src/easydiffraction/core/singleton.py
46 47 48 | |
replace_uid(old_uid, new_uid)
Replace an existing UID key in the UID map with a new UID.
Moves the associated parameter from old_uid to new_uid. Raises a KeyError if the old_uid doesn't exist.
Source code in src/easydiffraction/core/singleton.py
66 67 68 69 70 71 72 73 74 75 76 77 | |
validation
Lightweight runtime validation utilities.
Provides DataTypes, type/content validators, and AttributeSpec used by descriptors and parameters. Only documentation was added here.
AttributeSpec
Hold metadata and validators for a single attribute.
Source code in src/easydiffraction/core/validation.py
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
validated(value, name, current=None)
Validate through type and content validators.
Returns validated value, possibly default or current if errors occur. None may short-circuit further checks when allowed.
Source code in src/easydiffraction/core/validation.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
DataTypeHints
Type hint aliases for numeric, string, and boolean types.
Source code in src/easydiffraction/core/validation.py
26 27 28 29 30 31 | |
DataTypes
Bases: Enum
Enumeration of supported data types for descriptors.
Source code in src/easydiffraction/core/validation.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
__str__()
Return the lowercase name of the data type.
Source code in src/easydiffraction/core/validation.py
45 46 47 | |
expected_type
property
Convenience alias for tuple of allowed Python types.
MembershipValidator
Bases: ValidatorBase
Ensure that a value is among allowed choices.
allowed may be an iterable or a callable returning a collection.
Source code in src/easydiffraction/core/validation.py
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
validated(value, name, default=None, current=None)
Validate membership and return value or fallback.
Source code in src/easydiffraction/core/validation.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
RangeValidator
Bases: ValidatorBase
Ensure a numeric value lies within [ge, le].
Source code in src/easydiffraction/core/validation.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
validated(value, name, default=None, current=None)
Validate range and return value or fallback.
Source code in src/easydiffraction/core/validation.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | |
RegexValidator
Bases: ValidatorBase
Ensure that a string matches a given regular expression.
Source code in src/easydiffraction/core/validation.py
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
validated(value, name, default=None, current=None)
Validate regex and return value or fallback.
Source code in src/easydiffraction/core/validation.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
TypeValidator
Bases: ValidatorBase
Ensure a value is of the expected data type.
Source code in src/easydiffraction/core/validation.py
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 | |
validated(value, name, default=None, current=None, allow_none=False)
Validate type and return value or fallback.
If allow_none is True, None bypasses content checks.
Source code in src/easydiffraction/core/validation.py
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 | |
ValidationStage
Bases: Enum
Phases of validation for diagnostic logging.
Source code in src/easydiffraction/core/validation.py
60 61 62 63 64 65 66 67 68 69 70 | |
__str__()
Return the lowercase name of the validation stage.
Source code in src/easydiffraction/core/validation.py
68 69 70 | |
ValidatorBase
Bases: ABC
Abstract base class for all validators.
Source code in src/easydiffraction/core/validation.py
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 | |
validated(value, name, default=None, current=None)
abstractmethod
Return a validated value or fallback.
Subclasses must implement this method.
Source code in src/easydiffraction/core/validation.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
variable
GenericDescriptorBase
Bases: GuardedBase
Base class for all parameter-like descriptors.
A descriptor encapsulates a typed value with validation, human-readable name/description and a globally unique identifier that is stable across the session. Concrete subclasses specialize the expected data type and can extend the public API with additional behavior (e.g. units).
Source code in src/easydiffraction/core/variable.py
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
__init__(*, value_spec, name, description=None)
Initialize the descriptor with validation and identity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value_spec
|
AttributeSpec
|
Validation specification for the value. |
required |
name
|
str
|
Local name of the descriptor within its category. |
required |
description
|
str
|
Optional human-readable description. |
None
|
Source code in src/easydiffraction/core/variable.py
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 | |
__str__()
Return the string representation of this descriptor.
Source code in src/easydiffraction/core/variable.py
100 101 102 | |
as_cif
property
Serialize this descriptor to a CIF-formatted string.
description
property
Optional human-readable description.
from_cif(block, idx=0)
Populate this parameter from a CIF block.
Source code in src/easydiffraction/core/variable.py
203 204 205 | |
name
property
Local name of the descriptor (without category/datablock).
parameters
property
Return a flat list of parameters contained by this object.
For a single descriptor, it returns a one-element list with itself. Composite objects override this to flatten nested structures.
unique_name
property
Fully qualified name: datablock, category and entry.
value
property
writable
Current validated value.
GenericNumericDescriptor
Bases: GenericDescriptorBase
Base descriptor that constrains values to numbers.
Source code in src/easydiffraction/core/variable.py
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | |
__str__()
Return the string representation including units.
Source code in src/easydiffraction/core/variable.py
240 241 242 243 244 245 246 | |
units
property
Units associated with the numeric value, if any.
GenericParameter
Bases: GenericNumericDescriptor
Numeric descriptor extended with fitting-related attributes.
Adds standard attributes used by minimizers: "free" flag, uncertainty, bounds and an optional starting value. Subclasses can integrate with specific backends while preserving this interface.
Source code in src/easydiffraction/core/variable.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
__str__()
Return string representation with uncertainty and free.
Source code in src/easydiffraction/core/variable.py
293 294 295 296 297 298 299 300 301 302 | |
constrained
property
Whether this parameter is part of a constraint expression.
fit_max
property
writable
Upper fitting bound.
fit_min
property
writable
Lower fitting bound.
free
property
writable
Whether this parameter is currently varied during fitting.
uid
property
Stable random identifier for this descriptor.
uncertainty
property
writable
Estimated standard uncertainty of the fitted value.
GenericStringDescriptor
Bases: GenericDescriptorBase
Base descriptor that constrains values to strings.
Source code in src/easydiffraction/core/variable.py
211 212 213 214 215 216 217 218 219 220 | |
NumericDescriptor
Bases: GenericNumericDescriptor
Numeric descriptor bound to a CIF handler.
Source code in src/easydiffraction/core/variable.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
__init__(*, cif_handler, **kwargs)
Numeric descriptor bound to a CIF handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cif_handler
|
CifHandler
|
Object that tracks CIF identifiers. |
required |
**kwargs
|
object
|
Forwarded to GenericNumericDescriptor. |
{}
|
Source code in src/easydiffraction/core/variable.py
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | |
Parameter
Bases: GenericParameter
Fittable parameter bound to a CIF handler.
Source code in src/easydiffraction/core/variable.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
__init__(*, cif_handler, **kwargs)
Fittable parameter bound to a CIF handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cif_handler
|
CifHandler
|
Object that tracks CIF identifiers. |
required |
**kwargs
|
object
|
Forwarded to GenericParameter. |
{}
|
Source code in src/easydiffraction/core/variable.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 | |
StringDescriptor
Bases: GenericStringDescriptor
String descriptor bound to a CIF handler.
Source code in src/easydiffraction/core/variable.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |
__init__(*, cif_handler, **kwargs)
Initialize a string descriptor bound to a CIF handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cif_handler
|
CifHandler
|
Object that tracks CIF identifiers. |
required |
**kwargs
|
object
|
Forwarded to GenericStringDescriptor. |
{}
|
Source code in src/easydiffraction/core/variable.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 | |