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
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 | |
__str__()
Human-readable representation of this component.
Source code in src/easydiffraction/core/category.py
193 194 195 196 197 | |
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
229 230 231 232 233 234 235 236 237 238 239 | |
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
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
from_cif(block)
Populate this collection from a CIF block.
Source code in src/easydiffraction/core/category.py
225 226 227 | |
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 159 160 161 | |
__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
62 63 64 | |
help()
Print parameters, other properties, and methods.
Source code in src/easydiffraction/core/category.py
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 | |
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
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 | |
__contains__(name)
Check whether an item with the given key exists.
Source code in src/easydiffraction/core/collection.py
92 93 94 95 | |
__delitem__(name)
Delete an item by key or raise KeyError if missing.
Source code in src/easydiffraction/core/collection.py
82 83 84 85 86 87 88 89 90 | |
__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
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 | |
__iter__()
Iterate over items in insertion order.
Source code in src/easydiffraction/core/collection.py
97 98 99 | |
__len__()
Return the number of items in the collection.
Source code in src/easydiffraction/core/collection.py
101 102 103 | |
__setitem__(name, item)
Insert or replace an item under the given identity key.
Source code in src/easydiffraction/core/collection.py
69 70 71 72 73 74 75 76 77 78 79 80 | |
help()
Print a summary of public attributes and contained items.
Source code in src/easydiffraction/core/collection.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | |
items()
Yield (key, item) pairs in insertion order.
Source code in src/easydiffraction/core/collection.py
141 142 143 | |
keys()
Yield keys for all items in insertion order.
Source code in src/easydiffraction/core/collection.py
133 134 135 | |
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 |
Source code in src/easydiffraction/core/collection.py
105 106 107 108 109 110 111 112 113 114 | |
values()
Yield items in insertion order.
Source code in src/easydiffraction/core/collection.py
137 138 139 | |
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
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 | |
__str__()
Human-readable representation of this component.
Source code in src/easydiffraction/core/datablock.py
169 170 171 172 173 | |
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
157 158 159 160 161 162 163 164 165 166 167 | |
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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
__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
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
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
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 | |
attr_error(name, key, allowed, label='Allowed')
staticmethod
Log unknown attribute access and suggest closest key.
Source code in src/easydiffraction/core/diagnostic.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
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
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
no_value(name, default)
staticmethod
Log that default will be used due to missing value.
Source code in src/easydiffraction/core/diagnostic.py
141 142 143 144 | |
none_value(name)
staticmethod
Log explicit None provided by a user.
Source code in src/easydiffraction/core/diagnostic.py
146 147 148 149 | |
none_value_skip_range(name)
staticmethod
Log that range validation is skipped due to None.
Source code in src/easydiffraction/core/diagnostic.py
151 152 153 154 155 156 | |
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
94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
readonly_error(name, key=None)
staticmethod
Log an attempt to change a read-only attribute.
Source code in src/easydiffraction/core/diagnostic.py
45 46 47 48 49 50 51 52 53 54 | |
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
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
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
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |
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
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
validated(name, value, stage=None)
staticmethod
Log that a value passed a validation stage.
Source code in src/easydiffraction/core/diagnostic.py
158 159 160 161 162 | |
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
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 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 | |
__init_subclass__(**kwargs)
Give each subclass its own independent registry and rules.
Source code in src/easydiffraction/core/factory.py
35 36 37 38 39 40 | |
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
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 | |
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
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
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
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 | |
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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 | |
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
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 | |
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
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 | |
supported_tags()
classmethod
Return list of all supported tags.
Source code in src/easydiffraction/core/factory.py
70 71 72 73 | |
guard
GuardedBase
Bases: ABC
Base class enforcing controlled attribute access and linkage.
Source code in src/easydiffraction/core/guard.py
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 228 229 230 231 232 233 234 235 236 237 238 | |
__getattr__(key)
Raise a descriptive error for unknown attribute access.
Source code in src/easydiffraction/core/guard.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
__repr__()
Return the developer representation of this object.
Source code in src/easydiffraction/core/guard.py
30 31 32 | |
__setattr__(key, value)
Set an attribute with access-control diagnostics.
Source code in src/easydiffraction/core/guard.py
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 | |
__str__()
Return the string representation of this object.
Source code in src/easydiffraction/core/guard.py
26 27 28 | |
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
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 | |
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
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 | |
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
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
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
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 | |
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
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 | |
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
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
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
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 | |
apply()
Evaluate constraints and apply them to dependent parameters.
For each constraint: - Evaluate RHS using current values of aliased parameters - Locate the dependent parameter via direct alias reference - Update its value and mark it as constrained
Source code in src/easydiffraction/core/singleton.py
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 | |
set_aliases(aliases)
Set the alias map (name → alias wrapper).
Called when user registers parameter aliases like: alias='biso_La', param=model.atom_sites['La'].adp_iso
Source code in src/easydiffraction/core/singleton.py
60 61 62 63 64 65 66 67 | |
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
69 70 71 72 73 74 75 76 77 | |
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
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
get()
classmethod
Return the shared instance, creating it if needed.
Source code in src/easydiffraction/core/singleton.py
26 27 28 29 30 31 | |
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
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 | |
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
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 | |
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
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 | |
validated(value, name, default=None, current=None)
Validate membership and return value or fallback.
Source code in src/easydiffraction/core/validation.py
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 | |
RangeValidator
Bases: ValidatorBase
Ensure a numeric value lies within [ge, le].
Source code in src/easydiffraction/core/validation.py
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 | |
validated(value, name, default=None, current=None)
Validate range and return value or fallback.
Source code in src/easydiffraction/core/validation.py
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 | |
RegexValidator
Bases: ValidatorBase
Ensure that a string matches a given regular expression.
Source code in src/easydiffraction/core/validation.py
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 277 278 | |
validated(value, name, default=None, current=None)
Validate regex and return value or fallback.
Source code in src/easydiffraction/core/validation.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | |
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 158 159 | |
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
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 | |
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
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 | |
__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 | None
|
Optional human-readable description. |
None
|
Source code in src/easydiffraction/core/variable.py
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 | |
__str__()
Return the string representation of this descriptor.
Source code in src/easydiffraction/core/variable.py
97 98 99 | |
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
200 201 202 | |
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
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 | |
__str__()
Return the string representation including units.
Source code in src/easydiffraction/core/variable.py
237 238 239 240 241 242 243 | |
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
254 255 256 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 383 384 385 386 387 388 | |
__str__()
Return string representation with uncertainty and free.
Source code in src/easydiffraction/core/variable.py
305 306 307 308 309 310 311 312 313 314 | |
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.
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
208 209 210 211 212 213 214 215 216 217 | |
NumericDescriptor
Bases: GenericNumericDescriptor
Numeric descriptor bound to a CIF handler.
Source code in src/easydiffraction/core/variable.py
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
__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
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
Parameter
Bases: GenericParameter
Fittable parameter bound to a CIF handler.
Source code in src/easydiffraction/core/variable.py
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
__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
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
StringDescriptor
Bases: GenericStringDescriptor
String descriptor bound to a CIF handler.
Source code in src/easydiffraction/core/variable.py
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |
__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
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 | |