Dataset Module
energy_gnome.dataset
energy_gnome.dataset.BaseDatabase
Bases: ABC
Abstract base class for managing a structured database system with multiple processing stages and data subsets.
This class provides a standardized framework for handling data across different stages of processing (raw
, processed
, final
). It ensures proper directory structure, initializes database placeholders, and offers an interface for subclassing specialized database implementations.
Attributes:
Name | Type | Description |
---|---|---|
name | str | The name of the database instance. |
data_dir | Path | Root directory where database files are stored. |
processing_stages | list[str] | The main stages of data processing. |
interim_sets | list[str] | Subsets within the training pipelines (e.g., training, validation). |
database_directories | dict[str, Path] | Mapping of processing stages to their respective directories. |
database_paths | dict[str, Path] | Paths to database files for each processing stage. |
databases | dict[str, DataFrame] | Data storage for each processing stage. |
subset | dict[str, DataFrame] | Storage for subsets like training, validation, and testing. |
_update_raw | bool | Flag indicating whether raw data should be updated. |
_is_specialized | bool | Indicates whether a subclass contains materials for specialized energy applications. |
Source code in energy_gnome/dataset/base_dataset.py
Python | |
---|---|
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 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 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 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 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
|
__init__(name, data_dir=DATA_DIR)
Sets up the directory structure for storing data across different processing stages (raw
, processed
, final
) and initializes empty Pandas DataFrames for managing the data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the database instance. | required |
data_dir | Path | Root directory path for storing database files. Defaults to | DATA_DIR |
Source code in energy_gnome/dataset/base_dataset.py
__repr__()
Text representation of the BaseDatabase instance. Used for print()
and str()
calls.
Returns:
Name | Type | Description |
---|---|---|
str | str | ASCII table representation of the database |
Source code in energy_gnome/dataset/base_dataset.py
Python | |
---|---|
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 |
|
allow_raw_update()
Enables modifications to the raw
data stage.
This method sets the internal flag _update_raw
to True
, allowing changes to be made to the raw data without raising an exception.
Warning
Use with caution, as modifying raw data can impact data integrity.
Source code in energy_gnome/dataset/base_dataset.py
backup_and_changelog(old_db, new_db, differences, stage)
Backup the old database and update the changelog with identified differences.
This method saves a backup of the existing database before updating it with new data. It also logs the changes detected by comparing the old and new databases, storing the details in a changelog file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
old_db | DataFrame | The existing database before updating. | required |
new_db | DataFrame | The new database with updated entries. | required |
differences | Series | A series containing the material IDs of entries that differ. | required |
stage | str | The processing stage ("raw", "processed", "final") for which the backup and changelog are being maintained. | required |
Raises:
Type | Description |
---|---|
ValueError | If an invalid |
OSError | If there is an issue writing to the backup or changelog files. |
Logs
- ERROR: If an invalid stage is provided.
- DEBUG: When the old database is successfully backed up.
- ERROR: If the backup process fails.
- DEBUG: When the changelog is successfully updated with differences.
- ERROR: If updating the changelog fails.
Source code in energy_gnome/dataset/base_dataset.py
build_reduced_database(size, new_name, stage, seed=42)
Build a reduced database by sampling random entries from an existing database.
This method creates a new database by randomly sampling a specified number of entries from the given stage (raw
, processed
, or final
) of the existing database. The new database is saved and returned as a new instance.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
size | int | The number of entries for the reduced database. | required |
new_name | str | The name for the new reduced database. | required |
stage | str | The processing stage ( | required |
seed | int | The random seed used to generate reproducible samples. Defaults to 42. | 42 |
Returns:
Type | Description |
---|---|
DataFrame | The reduced database as a pandas DataFrame with the sampled entries. |
Raises:
Type | Description |
---|---|
ValueError | If |
Logs
ERROR: If the database size is set to 0. INFO: If the new reduced database is successfully created and saved.
Source code in energy_gnome/dataset/base_dataset.py
compare_and_update(new_db, stage)
Compare and update the database with new entries.
This method checks for new entries in the provided database and updates the stored database accordingly. It ensures that raw data remains immutable unless explicitly allowed. If new entries are found, the old database is backed up, and a changelog is created.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_db | DataFrame | The new database to compare against the existing one. | required |
stage | str | The processing stage ("raw", "processed", "final"). | required |
Returns:
Type | Description |
---|---|
DataFrame | pd.DataFrame: The updated database containing new entries. |
Raises:
Type | Description |
---|---|
ImmutableRawDataError | If attempting to modify raw data without explicit permission. |
Logs
- WARNING: If new items are detected in the database.
- ERROR: If an attempt is made to modify immutable raw data.
- INFO: When saving or updating the database.
- INFO: If no new items are found and no update is required.
Source code in energy_gnome/dataset/base_dataset.py
compare_databases(new_db, stage)
Compare two databases and identify new entry IDs.
This method compares an existing database (loaded from the specified stage) with a new database. It returns the entries from the new database that are not present in the existing one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_db | DataFrame | New database to compare. | required |
stage | str | Processing stage ("raw", "processed", "final"). | required |
Returns:
Type | Description |
---|---|
DataFrame | pd.DataFrame: Subset of |
Logs
- DEBUG: The number of new entries found.
- WARNING: If the old database is empty and nothing can be compared.
Source code in energy_gnome/dataset/base_dataset.py
copy_cif_files(stage, mute_progress_bars=True)
Copy CIF files from the raw stage to another processing stage.
This method transfers CIF files from the raw
stage directory to the specified processing stage (processed
or final
). It ensures that existing CIF files in the target directory are cleared before copying and updates the database with the new file paths.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | str | The processing stage to copy CIF files to ( | required |
mute_progress_bars | bool | If True, disables progress bars. Defaults to True. | True |
Raises:
Type | Description |
---|---|
ValueError | If the stage argument is |
MissingData | If the raw CIF directory does not exist or is empty. |
Logs
- WARNING: If the target directory is cleaned or CIF files are missing for some materials.
- ERROR: If a CIF file fails to copy.
- INFO: When CIF files are successfully copied and the database is updated.
Source code in energy_gnome/dataset/base_dataset.py
Python | |
---|---|
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 |
|
get_database(stage, subset=None)
Retrieves the database for a specified processing stage or subset.
This method returns the database associated with the given stage
. If the stage is raw
, processed
, or final
, it retrieves the corresponding database. If stage
is interim
, a specific subset
(e.g., training
, validation
, testing
) must be provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | str | The processing stage to retrieve. Must be one of | required |
subset | Optional[str] | The subset to retrieve when | None |
Returns:
Type | Description |
---|---|
DataFrame | pd.DataFrame: The requested database or subset. |
Raises:
Type | Description |
---|---|
ValueError | If an invalid |
ValueError | If |
Logs
- ERROR: If an invalid
stage
is provided. - WARNING: If the retrieved database is empty.
Source code in energy_gnome/dataset/base_dataset.py
load_all()
Loads the databases for all processing stages and subsets.
This method sequentially loads the databases for all predefined processing stages (raw
, processed
, final
). Additionally, it loads both regressor and classifier data for all interim subsets (training
, validation
, testing
).
Calls
load_database(stage)
: Loads the database for each processing stage.load_regressor_data(subset)
: Loads regressor-specific data for each subset.load_classifier_data(subset)
: Loads classifier-specific data for each subset.
Source code in energy_gnome/dataset/base_dataset.py
load_classifier_data(subset='training')
Load the interim dataset for a classification model.
This method retrieves the specified subset of the interim dataset specifically for classification models by internally calling _load_interim
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subset | str | The subset of the dataset to load ( | 'training' |
Returns:
Type | Description |
---|---|
DataFrame | The loaded regression dataset or an empty DataFrame if not found. |
Raises:
Type | Description |
---|---|
ValueError | If the provided |
Logs
- ERROR: If an invalid subset is provided.
- DEBUG: If an existing database is successfully loaded.
- WARNING: If no database file is found.
Source code in energy_gnome/dataset/base_dataset.py
load_database(stage)
Loads the existing database for a specified processing stage.
This method retrieves the database stored in a JSON file for the given processing stage (raw
, processed
, or final
). If the file exists, it loads the data into a pandas DataFrame. If the file is missing, a warning is logged, and an empty DataFrame remains in place.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | str | The processing stage to load. Must be one of | required |
Raises:
Type | Description |
---|---|
ValueError | If |
Logs
ERROR: If an invalid stage
is provided. DEBUG: If a database is successfully loaded. WARNING: If the database file is not found.
Source code in energy_gnome/dataset/base_dataset.py
load_regressor_data(subset='training')
Load the interim dataset for a regression model.
This method retrieves the specified subset of the interim dataset specifically for regression models by internally calling _load_interim
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
subset | str | The subset of the dataset to load ( | 'training' |
Returns:
Type | Description |
---|---|
DataFrame | The loaded regression dataset or an empty DataFrame if not found. |
Raises:
Type | Description |
---|---|
ValueError | If the provided |
Logs
- ERROR: If an invalid subset is provided.
- DEBUG: If an existing database is successfully loaded.
- WARNING: If no database file is found.
Source code in energy_gnome/dataset/base_dataset.py
save_database(stage)
Saves the current state of the database to a JSON file.
This method serializes the database DataFrame for the specified processing stage (raw
, processed
, or final
) and writes it to a JSON file. If an existing file is present, it is removed before saving the new version.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | str | The processing stage to save. Must be one of | required |
Raises:
Type | Description |
---|---|
ValueError | If |
OSError | If an error occurs while writing the DataFrame to the file. |
Logs
- ERROR: If an invalid
stage
is provided. - INFO: If the database is successfully saved.
- ERROR: If the save operation fails.
Source code in energy_gnome/dataset/base_dataset.py
save_split_db(database_dict, model_type='regressor')
Saves the split databases (training, validation, testing) into JSON files.
This method saves the split databases into individual files in the designated directory for the given model type (e.g., regressor
, classifier
). It checks whether the databases are empty before saving. If any of the databases are empty, it logs a warning or raises an error depending on the subset (training, validation, testing).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
database_dict | dict | A dictionary containing the split databases ( | required |
model_type | str | The model type for which the splits are being saved (e.g., | 'regressor' |
Returns:
Type | Description |
---|---|
None | None |
Raises:
Type | Description |
---|---|
DatabaseError | If the training dataset is empty when attempting to save. |
Logs
INFO: When a database is successfully saved to its designated path. WARNING: When the validation or testing database is empty. ERROR: If any dataset is empty and it is the train
subset.
Source code in energy_gnome/dataset/base_dataset.py
split_classifier(test_size=0.2, seed=42, balance_composition=False, save_split=False)
Splits the processed database into training and test sets for classification tasks.
This method divides the database into two subsets: training and test. It always stratifies the split based on the target property (is_specialized
). If balance_composition
is True, it additionally balances the frequency of chemical species across the training and test sets. The size of the test set can be customized with the test_size
argument.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
test_size | float | The proportion of the data to use for the test set. Defaults to 0.2. | 0.2 |
seed | int | The random seed for reproducibility. Defaults to 42. | 42 |
balance_composition | bool | Whether to balance the frequency of chemical species across the training and test sets in addition to stratifying by the target property ( | False |
save_split | bool | Whether to save the resulting splits as files. Defaults to False. | False |
Returns:
Type | Description |
---|---|
None | None |
Raises:
Type | Description |
---|---|
ValueError | If the database is empty or invalid. |
Logs
INFO: If the dataset is successfully split. ERROR: If the dataset is invalid or empty.
Source code in energy_gnome/dataset/base_dataset.py
split_regressor(target_property, valid_size=0.2, test_size=0.05, seed=42, balance_composition=True, save_split=False)
Splits the processed database into training, validation, and test sets for regression tasks.
This method divides the database into three subsets: training, validation, and test. It either performs a random split with or without balancing the frequency of chemical species across the splits. If balance_composition
is True, it ensures that elements appear in approximately equal proportions in each subset. The split sizes for validation and test sets can be customized.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
target_property | str | The property used for the regression task (e.g., a material property like "energy"). | required |
valid_size | float | The proportion of the data to use for the validation set. Defaults to 0.2. | 0.2 |
test_size | float | The proportion of the data to use for the test set. Defaults to 0.05. | 0.05 |
seed | int | The random seed for reproducibility. Defaults to 42. | 42 |
balance_composition | bool | Whether to balance the frequency of chemical species across the subsets. Defaults to True. | True |
save_split | bool | Whether to save the resulting splits as files. Defaults to False. | False |
Returns:
Type | Description |
---|---|
None | None |
Raises:
Type | Description |
---|---|
ValueError | If the sum of |
Logs
INFO: If the dataset is successfully split. ERROR: If the sum of valid_size
and test_size
is greater than 1.
Source code in energy_gnome/dataset/base_dataset.py
Python | |
---|---|
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 |
|
energy_gnome.dataset.CathodeDatabase
Bases: BaseDatabase
Source code in energy_gnome/dataset/cathodes.py
Python | |
---|---|
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 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 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 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 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
|
__init__(data_dir=DATA_DIR, name='cathodes', working_ion='Li', battery_type='insertion')
Sets up the directory structure for storing data across different processing stages (raw/
, processed/
, final/
) and initializes placeholders for database paths and data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data_dir | Path | Root directory path for storing data. Defaults to DATA_DIR from config. | DATA_DIR |
working_ion | str | The working ion used in the dataset (e.g., 'Li'). Defaults to "Li". | 'Li' |
battery_type | str | The type of battery type (e.g., 'insertion', 'conversion'). Defaults to "insertion". | 'insertion' |
Raises:
Type | Description |
---|---|
NotImplementedError | If the specified processing stage is not supported. |
ImmutableRawDataError | If attempting to set an unsupported processing stage. |
Source code in energy_gnome/dataset/cathodes.py
__repr__()
Text representation of the CathodeDatabase instance. Used for print()
and str()
calls.
Returns:
Name | Type | Description |
---|---|---|
str | str | ASCII table representation of the database |
Source code in energy_gnome/dataset/cathodes.py
Python | |
---|---|
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 |
|
add_material_properties(stage, materials_mp_query, charge_state, mute_progress_bars=True)
Add material properties to the database from Material Project query results.
Saves CIF files for each material in the query and updates the database with file paths and properties.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | str | Processing stage ('raw', 'processed', 'final'). | required |
materials_mp_query | List[Any] | List of material query results. | required |
charge_state | str | The state of the cathode ('charge' or 'discharge'). | required |
mute_progress_bars | bool | Disable progress bar if True. Defaults to True. | True |
Returns:
Type | Description |
---|---|
DataFrame | pd.DataFrame: Updated database with material properties. |
Raises:
Type | Description |
---|---|
ImmutableRawDataError | If attempting to modify immutable raw data. |
KeyError | If a material ID is not found in the database. |
Source code in energy_gnome/dataset/cathodes.py
Python | |
---|---|
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 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 |
|
backup_and_changelog(old_db, new_db, differences, stage)
Backup the old database and update the changelog with identified differences.
Creates a backup of the existing database and appends a changelog entry detailing the differences between the old and new databases. The changelog includes information such as entry identifiers, formulas, and last updated timestamps.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
old_db | DataFrame | The existing database before updates. | required |
new_db | DataFrame | The new database containing updates. | required |
differences | Series | Series of identifiers that are new or updated. | required |
stage | str | The processing stage ('raw', 'processed', 'final'). | required |
Source code in energy_gnome/dataset/cathodes.py
compare_and_update(new_db, stage)
Compare and update the database with new entries.
Identifies new entries and updates the database accordingly. Ensures that raw data remains immutable by preventing updates unless explicitly allowed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_db | DataFrame | New database to compare. | required |
stage | str | Processing stage ("raw", "processed", "final"). | required |
Returns:
Type | Description |
---|---|
DataFrame | pd.DataFrame: Updated database containing new entries. |
Raises:
Type | Description |
---|---|
ImmutableRawDataError | If attempting to modify immutable raw data. |
Source code in energy_gnome/dataset/cathodes.py
compare_databases(new_db, stage)
Compare two databases and identify new entry IDs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
new_db | DataFrame | New database to compare. | required |
stage | str | Processing stage ("raw", "processed", "final"). | required |
Returns:
Type | Description |
---|---|
DataFrame | pd.DataFrame: Subset of |
Source code in energy_gnome/dataset/cathodes.py
copy_cif_files(stage, charge_state, mute_progress_bars=True)
Copy CIF files from the raw stage to another processing stage.
Copies CIF files corresponding to the specified cathode state from the 'raw' processing stage to the target stage. Updates the database with the new file paths.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | str | Target processing stage ('processed', 'final'). | required |
charge_state | str | The charge state of the cathode ('charge' or 'discharge'). | required |
mute_progress_bars | bool | Disable progress bar if True. Defaults to True. | True |
Raises:
Type | Description |
---|---|
ValueError | If the target stage is 'raw'. |
MissingData | If the source CIF directory does not exist or is empty. |
Source code in energy_gnome/dataset/cathodes.py
Python | |
---|---|
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 |
|
load_interim(subset='training')
Load the existing interim databases.
Checks for the presence of an existing database file for the given subset and loads it into a pandas DataFrame. If the database file does not exist, logs a warning and returns an empty DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
set | str | The interim subset ('training', 'validation', 'testing'). | required |
Returns:
Type | Description |
---|---|
DataFrame | pd.DataFrame: The loaded database or an empty DataFrame if not found. |
Source code in energy_gnome/dataset/cathodes.py
retrieve_materials(stage, charge_state, mute_progress_bars=True)
Retrieve material structures from the Material Project API.
Fetches material structures based on the processing stage and charge state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | str | Processing stage ('raw', 'processed', 'final'). | required |
charge_state | str | Cathode charge state ('charge', 'discharge'). | required |
mute_progress_bars | bool | Disable progress bar if True. Defaults to True. | True |
Returns:
Type | Description |
---|---|
list[Any] | List[Any]: List of retrieved material objects. |
Raises:
Type | Description |
---|---|
ValueError | If the charge_state is invalid. |
MissingData | If the required data is missing in the database. |
Source code in energy_gnome/dataset/cathodes.py
retrieve_models(mute_progress_bars=True)
Retrieve battery models from the Materials Project API.
Connects to the Material Project API using MPRester, queries for materials based on the working ion and processing stage, and retrieves the specified fields. Cleans the data by removing entries with missing critical identifiers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mute_progress_bars | bool | If | True |
Returns:
Type | Description |
---|---|
DataFrame | pd.DataFrame: DataFrame containing the retrieved and cleaned models. |
Raises:
Type | Description |
---|---|
Exception | If the API query fails. |
Source code in energy_gnome/dataset/cathodes.py
retrieve_remote(mute_progress_bars=True)
Retrieve models from the Material Project API.
Wrapper method to call retrieve_models
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mute_progress_bars | bool | If | True |
Returns:
Type | Description |
---|---|
DataFrame | pd.DataFrame: DataFrame containing the retrieved models. |
Source code in energy_gnome/dataset/cathodes.py
save_cif_files(stage, materials_mp_query, charge_state, mute_progress_bars=True)
Save CIF files for materials and update the database accordingly.
Manages the saving of CIF files for each material and updates the database with the file paths and relevant properties. Ensures that raw data remains immutable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | str | Processing stage ('raw', 'processed', 'final'). | required |
materials_mp_query | List[Any] | List of material query results. | required |
charge_state | str | The charge state of the cathode ('charge' or 'discharge'). | required |
mute_progress_bars | bool | Disable progress bar if True. Defaults to True. | True |
Raises:
Type | Description |
---|---|
ImmutableRawDataError | If attempting to modify immutable raw data. |
Source code in energy_gnome/dataset/cathodes.py
Python | |
---|---|
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 |
|
energy_gnome.dataset.PerovskiteDatabase
Bases: BaseDatabase
Source code in energy_gnome/dataset/perovskites.py
Python | |
---|---|
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 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 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 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 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 |
|
__init__(name='perovskites', data_dir=DATA_DIR, external_perovproj_path=EXTERNAL_DATA_DIR / Path('perovskites') / Path('perovproject_db.json'))
This constructor sets up the directory structure for storing data across different processing stages (raw
, processed
, final
). It also initializes placeholders for the database paths and data specific to the PerovskiteDatabase
class, including a path for the external Perovskite project data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the database. Defaults to "perovskites". | 'perovskites' |
data_dir | Path or str | Root directory path for storing data. Defaults to | DATA_DIR |
external_perovproj_path | Path or str | Path to the external Perovskite Project database file. Defaults to | EXTERNAL_DATA_DIR / Path('perovskites') / Path('perovproject_db.json') |
Raises:
Type | Description |
---|---|
NotImplementedError | If the specified processing stage is not supported. |
ImmutableRawDataError | If attempting to set an unsupported processing stage. |
Source code in energy_gnome/dataset/perovskites.py
__repr__()
Text representation of the PerovskiteDatabase instance. Used for print()
and str()
calls.
Returns:
Name | Type | Description |
---|---|---|
str | str | ASCII table representation of the database |
Source code in energy_gnome/dataset/perovskites.py
Python | |
---|---|
433 434 435 436 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 503 504 505 506 507 508 509 510 511 |
|
process_database(band_gap_lower, band_gap_upper, inplace=True, db=None, clean_magnetic=True)
Process the raw perovskite database to the processed
stage.
This method filters materials based on their band gap energy range and optionally removes metallic and magnetic materials. The processed data can either be saved in place or returned as a separate DataFrame.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
band_gap_lower | float | Lower bound of the band gap energy range (in eV). | required |
band_gap_upper | float | Upper bound of the band gap energy range (in eV). | required |
inplace | bool | If True, updates the "processed" database in-place. If False, returns the processed DataFrame. Defaults to True. | True |
db | DataFrame | The database to process if | None |
clean_magnetic | bool | If True, removes magnetic materials. Defaults to True. | True |
Returns:
Type | Description |
---|---|
DataFrame | Processed database if |
Raises:
Type | Description |
---|---|
ValueError | If |
Logs
- INFO: Steps of the processing, including filtering metallic and magnetic materials.
- ERROR: If
inplace
is False and no input database is provided.
Source code in energy_gnome/dataset/perovskites.py
retrieve_materials(mute_progress_bars=True)
Retrieve Perovskite materials from the Materials Project API.
This method connects to the Materials Project API using the MPRester
, queries for materials related to Perovskites, and retrieves specified properties. The data is then cleaned by removing rows with missing critical fields and filtering out metallic perovskites. The method returns a cleaned DataFrame of Perovskites.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mute_progress_bars | bool | If | True |
Returns:
Type | Description |
---|---|
DataFrame | A DataFrame containing the retrieved and cleaned Perovskite materials. |
Raises:
Type | Description |
---|---|
Exception | If the API query fails or any issue occurs during data retrieval. |
Logs
- DEBUG: Logs the process of querying and cleaning data.
- INFO: Logs successful query results and how many Perovskites were retrieved.
- SUCCESS: Logs the successful retrieval of Perovskite materials.
Source code in energy_gnome/dataset/perovskites.py
Python | |
---|---|
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 272 |
|
save_cif_files(stage, mute_progress_bars=True)
Save CIF files for materials and update the database efficiently.
This method retrieves crystal structures from the Materials Project API and saves them as CIF files in the appropriate directory. It ensures raw data integrity and efficiently updates the database with CIF file paths.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | str | The processing stage ( | required |
mute_progress_bars | bool | If True, disables progress bars. Defaults to True. | True |
Raises:
Type | Description |
---|---|
ImmutableRawDataError | If attempting to modify immutable raw data. |
Logs
- WARNING: If the CIF directory is being cleaned or if a material ID is missing.
- ERROR: If an API query fails or CIF file saving encounters an error.
- INFO: When CIF files are successfully retrieved and saved.
Source code in energy_gnome/dataset/perovskites.py
Python | |
---|---|
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 |
|
energy_gnome.dataset.MPDatabase
Bases: BaseDatabase
Source code in energy_gnome/dataset/random_mats.py
Python | |
---|---|
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 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 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 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
|
__init__(name='mp', data_dir=DATA_DIR)
This constructor sets up the directory structure for storing data across different processing stages (raw
, processed
, final
). It also initializes placeholders for the database paths and data specific to the MPDatabase
class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the database. Defaults to "mp". | 'mp' |
data_dir | Path or str | Root directory path for storing data. Defaults to | DATA_DIR |
Raises:
Type | Description |
---|---|
NotImplementedError | If the specified processing stage is not supported. |
ImmutableRawDataError | If attempting to set an unsupported processing stage. |
Source code in energy_gnome/dataset/random_mats.py
__repr__()
Text representation of the MPDatabase instance. Used for print()
and str()
calls.
Returns:
Name | Type | Description |
---|---|---|
str | str | ASCII table representation of the database |
Source code in energy_gnome/dataset/random_mats.py
Python | |
---|---|
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 |
|
remove_cross_overlap(stage, database)
Remove entries in the generic database that overlap with a category-specific database.
This function identifies and removes material entries that exist in both the generic and category-specific databases for a given processing stage.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | str | Processing stage ( | required |
database | DataFrame | The category-specific database to compare with the generic database. | required |
Returns:
Type | Description |
---|---|
DataFrame | pd.DataFrame: The filtered generic database with overlapping entries removed. |
Raises:
Type | Description |
---|---|
ValueError | If an invalid processing stage is provided. |
Logs
- ERROR: If an invalid stage is given.
- INFO: Number of overlapping entries identified and removed.
Source code in energy_gnome/dataset/random_mats.py
retrieve_materials(max_framework_size=6, mute_progress_bars=True)
Retrieve materials from the Materials Project API.
This method connects to the Materials Project API using the MPRester
, queries for all materials, and retrieves specified properties. The data is then cleaned by removing rows with missing critical fields. The method returns a cleaned DataFrame of materials.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mute_progress_bars | bool | If | True |
Returns:
Type | Description |
---|---|
DataFrame | A DataFrame containing the retrieved and cleaned materials. |
Raises:
Type | Description |
---|---|
Exception | If the API query fails or any issue occurs during data retrieval. |
Logs
- DEBUG: Logs the process of querying and cleaning data.
- INFO: Logs successful query results and how many materials were retrieved.
- SUCCESS: Logs the successful retrieval of materials.
Source code in energy_gnome/dataset/random_mats.py
save_cif_files(stage, mute_progress_bars=True)
Save CIF files for materials and update the database efficiently.
This method retrieves crystal structures from the Materials Project API and saves them as CIF files in the appropriate directory. It ensures raw data integrity and efficiently updates the database with CIF file paths.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
stage | str | The processing stage ( | required |
mute_progress_bars | bool | If True, disables progress bars. Defaults to True. | True |
Raises:
Type | Description |
---|---|
ImmutableRawDataError | If attempting to modify immutable raw data. |
Logs
- WARNING: If the CIF directory is being cleaned or if a material ID is missing.
- ERROR: If an API query fails or CIF file saving encounters an error.
- INFO: When CIF files are successfully retrieved and saved.
Source code in energy_gnome/dataset/random_mats.py
Python | |
---|---|
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 |
|
energy_gnome.dataset.GNoMEDatabase
Bases: BaseDatabase
Source code in energy_gnome/dataset/gnome.py
Python | |
---|---|
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 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 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 440 441 442 443 444 445 446 447 448 449 450 451 |
|
__init__(name='gnome', data_dir=DATA_DIR)
This constructor sets up the directory structure for storing data across different processing stages (raw
, processed
, final
). It also initializes placeholders for the database paths and data specific to the GNoMEDatabase
class.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name | str | The name of the database. Defaults to "gnome". | 'gnome' |
data_dir | Path or str | Root directory path for storing data. Defaults to | DATA_DIR |
Raises:
Type | Description |
---|---|
NotImplementedError | If the specified processing stage is not supported. |
ImmutableRawDataError | If attempting to set an unsupported processing stage. |
Source code in energy_gnome/dataset/gnome.py
__repr__()
Text representation of the GNoMEDatabase instance. Used for print()
and str()
calls.
Returns:
Name | Type | Description |
---|---|---|
str | str | ASCII table representation of the database |
Source code in energy_gnome/dataset/gnome.py
Python | |
---|---|
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 |
|
filter_by_elements(include=None, exclude=None, stage='final', save_filtered_db=False)
Filters the database entries based on the presence or absence of specified chemical elements or element groups.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
include | list[str] | A list of chemical elements that must be present in the composition. - If None, no filtering is applied based on inclusion. - If an element group is passed using the format | None |
exclude | list[str] | A list of chemical elements that must not be present in the composition. - If None, no filtering is applied based on exclusion. - If an element group is passed using the format | None |
stage | str | The processing stage to retrieve the database from. Defaults to | 'final' |
save_filtered_db | bool | If True, saves the filtered database back to | False |
Returns:
Type | Description |
---|---|
DataFrame | A filtered DataFrame containing only the entries that match the inclusion/exclusion criteria. |
Raises:
Type | Description |
---|---|
ValueError | If both |
Notes
- If both
include
andexclude
are provided, the function will return entries that contain at least one of theinclude
elements but none of theexclude
elements. - If an entry in
include
is in the format"A-B"
, the material must contain all elements in that group. - If an entry in
exclude
is in the format"A-B"
, the material is removed only if it contains all elements in that group. - If
save_filtered_db
is True, the filtered DataFrame is stored inself.databases[stage]
and saved persistently.
Source code in energy_gnome/dataset/gnome.py
Python | |
---|---|
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 |
|
retrieve_materials()
TBD (after implementing the fetch routine)
Source code in energy_gnome/dataset/gnome.py
save_cif_files()
Save CIF files for materials and update the database accordingly. Uses OS-native unzippers for maximum speed.