Logic
This page provides the documentation for the commands encoding undo/redo actions, data serialization, and workers used for running processes on parallel threads.
Brillouin Zone Commands¶
TiBi.logic.commands.AddBZPointCommand
¶
Bases: QUndoCommand
Add a point to the special points path in the Brillouin zone.
Because this action would invalidate the already-calculated bands, the band structure is reset.
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cell |
UnitCell
|
|
point |
NDArray[float64]
|
The point to be added |
computation_view |
ComputationView
|
UI object containing the computation view |
signal |
Signal
|
Signal to be emitted to trigger a redraw of the BZ path |
Source code in TiBi/logic/commands/bz_commands.py
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 | |
TiBi.logic.commands.ClearBZPathCommand
¶
Bases: QUndoCommand
Clear the special points path in the Brillouin zone.
Because this action would invalidate the already-calculated bands, the band structure is reset.
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cell |
UnitCell
|
|
special_points |
list[NDArray[float64]]
|
List of special points before clearing the path |
computation_view |
ComputationView
|
UI object containing the computation view |
signal |
Signal
|
Signal to be emitted to trigger a redraw of the BZ path |
Source code in TiBi/logic/commands/bz_commands.py
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 | |
TiBi.logic.commands.RemoveBZPointCommand
¶
Bases: QUndoCommand
Remove the last point from the special points path in the Brillouin zone.
Because this action would invalidate the already-calculated bands, the band structure is reset.
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cell |
UnitCell
|
|
point |
NDArray
|
The point to be removed |
computation_view |
ComputationView
|
UI object containing the computation view |
signal |
Signal
|
Signal to be emitted to trigger a redraw of the BZ path |
Source code in TiBi/logic/commands/bz_commands.py
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 | |
Tree Commands¶
TiBi.logic.commands.AddSiteCommand
¶
Bases: QUndoCommand
Create a new site in the currently selected unit cell.
Creates a site with default name and coordinates (0,0,0), adds it to the sites dictionary of the selected unit cell and to the tree.
The default site has: - Name: "New Site" - Coordinates (0,0,0) - No states initially - Default radius - Random color
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cells |
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
selection |
Selection
|
Dictionary containing the current selection |
tree_view |
SystemTree
|
UI object containing the tree view |
uc_id |
UUID
|
UUID of the selected |
site |
Site
|
Newly created |
Source code in TiBi/logic/commands/tree_commands.py
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 | |
TiBi.logic.commands.AddStateCommand
¶
Bases: QUndoCommand
Create a new state in the currently selected site.
Creates a state with default name, adds it to the states dictionary of the selected site and to the tree.
The default state has: - Name: "New State"
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cells |
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
selection |
Selection
|
Model containing the current selection |
tree_view |
SystemTree
|
UI object containing the tree view |
signal |
Signal
|
Signal emitted when the state is added/removed |
uc_id |
UUID
|
UUID of the selected |
site_id |
UUID
|
UUID of the selected |
state |
State
|
Newly created |
Source code in TiBi/logic/commands/tree_commands.py
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 | |
TiBi.logic.commands.AddUnitCellCommand
¶
Bases: QUndoCommand
Create a new unit cell with default properties and add it to the model.
Creates a unit cell with orthogonal basis vectors along the x, y, and z axes, adds it to the unit_cells dictionary and to the tree view.
The default unit cell has: - Name: "New Unit Cell" - Three orthogonal unit vectors along the x, y, and z axes - No periodicity (0D system) - No sites or states initially
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cells |
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
tree_view |
SystemTree
|
UI object containing the tree view |
unit_cell |
UnitCell
|
Newly created |
Source code in TiBi/logic/commands/tree_commands.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 | |
TiBi.logic.commands.DeleteItemCommand
¶
Bases: QUndoCommand
Delete the currently selected item from the model.
This command handles deletion of UnitCells, Sites, and States
based on the current selection. It updates both the data model and
the tree view to reflect the deletion, and ensures that
the selection is updated appropriately.
The deletion follows the containment hierarchy:
- Deleting a UnitCell also removes all its Sites and States
- Deleting a Site also removes all its States
- Deleting a State only removes that specific State
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cells |
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
selection |
Selection
|
Dictionary containing the current selection |
tree_view |
SystemTree
|
UI object containing the tree view |
signal |
Signal
|
Signal emitted when a state is added/removed |
uc_id |
UUID
|
UUID of the selected |
site_id |
UUID
|
UUID of the selected |
state_id |
UUID
|
UUID of the selected |
Source code in TiBi/logic/commands/tree_commands.py
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 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 | |
TiBi.logic.commands.RenameTreeItemCommand
¶
Bases: QUndoCommand
Change the name of a tree item in the unit cells model.
The name is changed by double-clicking on an item in the tree view.
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cells |
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
selection |
Selection
|
Dictionary containing the current selection |
tree_view |
SystemTree
|
UI object containing the tree view |
signal |
Signal
|
Signal to be emitted when the command is executed |
item |
QStandardItem
|
The item in the tree view that was changed |
uc_id |
UUID
|
UUID of the selected |
site_id |
UUID
|
UUID of the selected |
state_id |
UUID
|
UUID of the selected |
old_name |
str
|
The old name of the item before the change |
new_name |
str
|
The new name of the item after the change |
Source code in TiBi/logic/commands/tree_commands.py
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 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 | |
Hopping Commands¶
TiBi.logic.commands.SaveHoppingsCommand
¶
Bases: QUndoCommand
Save the hoppings between two states.
Update the entry in the hoppings dictionary of the selected unit
for the selected pair of states.
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cells |
dict[UUID, UnitCell]
|
Reference to the dictionary mapping UUIDs to UnitCell objects |
selection |
Selection
|
Reference to the dictionary containing the current selection |
uc_id |
UUID
|
UUID of the selected |
site_id |
UUID
|
UUID of the selected |
state_id |
UUID
|
UUID of the selected |
pair_selection |
list[Tuple[str, UUID, str, UUID]]
|
Reference to the list of selected |
s1, s2 |
Tuple[str, UUID, str, UUID]
|
Information tuples for the selected |
new_hoppings |
list[Tuple[Tuple[int, int, int], complex128]]
|
List of new hoppings to be added to the |
old_hoppings |
list[Tuple[Tuple[int, int, int], complex128]]
|
List of old hoppings to be removed from the |
signal |
Signal
|
Signal to be emitted when the command is executed. The signal
carries the information about the selected |
Source code in TiBi/logic/commands/hopping_commands.py
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 | |
Unit Cell Commands¶
TiBi.logic.commands.UpdateUnitCellParameterCommand
¶
Bases: QUndoCommand
Update a parameter of the selected UnitCell.
This command is used to update the basis vectors of the unit cell when the user types in the spinbox.
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cells |
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
selection |
Selection
|
Model tracking the currently selected unit cell, site, and state |
vector |
str
|
The vector to be updated (v1, v2, or v3) |
coordinate |
str
|
The coordinate to be updated (x, y, or z) |
spinbox |
QDoubleSpinBox
|
The spinbox widget used to input the new value |
signal |
Signal
|
Signal to be emitted when the command is executed, requesting a plot update |
uc_id |
UUID
|
UUID of the selected |
old_value |
float
|
The old value of the parameter before the change |
new_value |
float
|
The new value of the parameter after the change |
Source code in TiBi/logic/commands/uc_commands.py
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 | |
TiBi.logic.commands.ReduceBasisCommand
¶
Bases: QUndoCommand
Reduce the basis vectors of the selected unit cell.
This method applies the Lenstra-Lenstra-Lovász (LLL) lattice reduction algorithm to find a more orthogonal set of basis vectors that spans the same lattice. This is useful for finding a 'nicer' representation of the unit cell with basis vectors that are shorter and more orthogonal to each other.
The method only affects the periodic directions of the unit cell. After reduction, the UI is updated to reflect the new basis vectors.
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cells |
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
selection |
Selection
|
Model tracking the currently selected unit cell, site, and state |
unit_cell_view |
UnitCellView
|
UI object containing the unit cell view |
signal |
Signal
|
Signal to be emitted when the command is executed, requesting a plot update |
uc_id |
UUID
|
UUID of the selected |
old_basis |
list[BasisVector]
|
The old basis vectors of the unit cell before reduction |
new_basis |
list[BasisVector]
|
The new basis vectors of the unit cell after reduction |
Source code in TiBi/logic/commands/uc_commands.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 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 | |
TiBi.logic.commands.ChangeDimensionalityCommand
¶
Bases: QUndoCommand
Change the dimensionality of the selected UnitCell (0D, 1D, 2D, 3D).
This method is called when the user selects a different dimensionality radio button. It updates the unit cell's periodicity flags and enables/disables appropriate basis vector components based on the selected dimensionality.
For example: - 0D: All directions are non-periodic (isolated system) - 1D: First direction is periodic, others are not - 2D: First and second directions are periodic, third is not - 3D: All directions are periodic (fully periodic crystal)
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cells |
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
selection |
Selection
|
Model tracking the currently selected unit cell, site, and state |
unit_cell_view |
UnitCellView
|
UI object containing the unit cell view |
signal |
Signal
|
Signal to be emitted when the command is executed, requesting a plot update |
dim |
int
|
The new dimensionality of the unit cell (0, 1, 2, or 3) |
buttons |
list[QRadioButton]
|
List of radio buttons corresponding to the dimensionality options in the UI |
uc_id |
UUID
|
UUID of the selected |
old_v1 |
BasisVector
|
The old basis vector 1 of the unit cell before the change |
old_v2 |
BasisVector
|
The old basis vector 2 of the unit cell before the change |
old_v3 |
BasisVector
|
The old basis vector 3 of the unit cell before the change |
old_dim |
int
|
The old dimensionality of the unit cell before the change |
new_v1 |
BasisVector
|
The new basis vector 1 of the unit cell after the change |
new_v2 |
BasisVector
|
The new basis vector 2 of the unit cell after the change |
new_v3 |
BasisVector
|
The new basis vector 3 of the unit cell after the change |
Source code in TiBi/logic/commands/uc_commands.py
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 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 | |
TiBi.logic.commands.UpdateSiteParameterCommand
¶
Bases: QUndoCommand
Update a parameter of the selected Site.
This command is used to update the basis vectors of the site when the user types in the spinbox.
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cells |
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
selection |
Selection
|
Model tracking the currently selected unit cell, site, and state |
param |
str
|
The parameter to be updated (radius, color, etc.) |
spinbox |
QDoubleSpinBox
|
The spinbox widget used to input the new value |
signal |
Signal
|
Signal to be emitted when the command is executed, requesting a plot update |
uc_id |
UUID
|
UUID of the selected |
site_id |
UUID
|
UUID of the selected |
old_value |
float
|
The old value of the parameter before the change |
new_value |
float
|
The new value of the parameter after the change |
Source code in TiBi/logic/commands/uc_commands.py
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 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
TiBi.logic.commands.ChangeSiteColorCommand
¶
Bases: QUndoCommand
Change the color of the selected Site.
Attributes:
| Name | Type | Description |
|---|---|---|
unit_cells |
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
selection |
Selection
|
Model tracking the currently selected unit cell, site, and state |
new_color |
QColor
|
The new color to be set for the site |
old_color |
QColor
|
The old color of the site before the change |
unit_cell_view |
UnitCellView
|
UI object containing the unit cell view |
signal |
Signal
|
Signal to be emitted when the command is executed, requesting a plot update |
Source code in TiBi/logic/commands/uc_commands.py
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 | |
Serialization¶
TiBi.logic.serialization.UnitCellEncoder
¶
Bases: JSONEncoder
Custom JSON encoder for UnitCell objects and their components.
Handles serialization of custom types to JSON-compatible formats: - UUID objects are converted to strings - NumPy complex values are converted to [real, imag] lists - NumPy arrays are converted to lists - BasisVector, State, Site, and UnitCell objects are converted to dicts - Dictionaries with UUID keys are converted to dicts with string keys - Tuples with UUID elements are converted to strings
Source code in TiBi/logic/serialization/serialization.py
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 | |
TiBi.logic.serialization.decode_unit_cell_json(json_obj)
¶
Decode JSON objects into their appropriate custom types.
This is used as the object_hook for json.loads() to deserialize JSON data back into UnitCell, Site, State, and BasisVector objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_obj
|
dict
|
A dictionary representing a JSON object |
required |
Returns:
| Type | Description |
|---|---|
The appropriate Python object based on the 'type' field
|
|
Source code in TiBi/logic/serialization/serialization.py
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 | |
TiBi.logic.serialization.serialize_unit_cells(unit_cells)
¶
Serialize a dictionary of UnitCell objects to a JSON string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
unit_cells
|
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
required |
Returns:
| Type | Description |
|---|---|
str
|
JSON string representation of the unit_cells dictionary |
Source code in TiBi/logic/serialization/serialization.py
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | |
TiBi.logic.serialization.deserialize_unit_cells(json_str)
¶
Deserialize a JSON string back into a dictionary of UnitCell objects.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_str
|
str
|
JSON string representation of unit_cells dictionary |
required |
Returns:
| Type | Description |
|---|---|
dict[UUID, UnitCell]
|
Dictionary mapping UUIDs to |
Source code in TiBi/logic/serialization/serialization.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
Workers¶
TiBi.logic.workers.DiagonalizationWorker
¶
Bases: Worker
Worker for diagonalizing a Hamiltonian at multiple k-points.
Attributes:
| Name | Type | Description |
|---|---|---|
hamiltonian_func |
callable
|
Function that takes a k-point and returns the Hamiltonian matrix. |
k_points |
list
|
List of k-points at which to diagonalize the Hamiltonian. |
Source code in TiBi/logic/workers/diagonalization_worker.py
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 | |
do_work()
¶
Diagonalize the Hamiltonian at the specified k-points.
At the end of the computation, emit a signal with the results.
Source code in TiBi/logic/workers/diagonalization_worker.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 | |
TiBi.logic.workers.Worker
¶
Bases: QObject
General worker class for performing background tasks.
Attributes:
| Name | Type | Description |
|---|---|---|
_abort |
bool
|
Flag indicating whether the worker should abourt its task. |
progress_updated |
Signal
|
Emitted to update the progress of the task. |
task_finished |
Signal
|
Emitted when the task is completed successfully. |
task_aborted |
Signal
|
Emitted when the task is aborted by the user. |
Methods:
| Name | Description |
|---|---|
do_work |
Abstract method implemented by subclasses to perform the actual work. |
request_abort |
Set the abort flag to True, signaling the worker to stop its task. |
Source code in TiBi/logic/workers/worker.py
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 | |
request_abort()
¶
Set the abort flag to True, signaling the worker to stop its task.
Source code in TiBi/logic/workers/worker.py
38 39 40 41 42 | |