|
24 | 24 | import numpy as np |
25 | 25 | import pooch |
26 | 26 | import requests |
27 | | -from msgpack import packb, unpackb |
28 | | -from msgpack_numpy import decode, encode |
29 | 27 | from numpy import ndarray |
30 | 28 | from scipy.interpolate import CubicSpline |
31 | 29 |
|
32 | | -from atomdb.periodic import Element, element_symbol |
| 30 | +from atomdb.periodic_test import element_symbol_map, PROPERTY_NAME_MAP, get_scalar_data, ElementAttr |
33 | 31 | from atomdb.utils import DEFAULT_DATAPATH, DEFAULT_DATASET, DEFAULT_REMOTE |
34 | 32 | from importlib_resources import \ |
35 | 33 | files |
36 | 34 | import tables as pt |
37 | 35 | from numbers import Integral |
38 | | -from migration.periodic.elements_data import PROPERTY_NAME_MAP, map_element_symbol |
39 | 36 |
|
40 | | -elements_hdf5_file = files("atomdb.data").joinpath("elements_data.h5") |
41 | 37 | datasets_hdf5_file = files("atomdb.data").joinpath("datasets_data.h5") |
42 | | - |
43 | | - |
44 | | -ELEMENTS_H5FILE = pt.open_file(elements_hdf5_file, mode="r") |
45 | 38 | DATASETS_H5FILE = pt.open_file(datasets_hdf5_file, mode="r") |
46 | 39 |
|
47 | | -element_symbol_map = map_element_symbol(ELEMENTS_H5FILE) |
| 40 | + |
48 | 41 |
|
49 | 42 | __all__ = [ |
50 | 43 | "Species", |
@@ -90,41 +83,6 @@ def wrapper(self): |
90 | 83 | return wrapper |
91 | 84 |
|
92 | 85 |
|
93 | | -def get_scalar_data(prop_name, atnum, nelec): |
94 | | - charge = atnum - nelec |
95 | | - |
96 | | - if charge != 0 and prop_name != "atmass": |
97 | | - return None |
98 | | - |
99 | | - # get the element group |
100 | | - element_group = f"/Elements/{atnum:03d}" |
101 | | - |
102 | | - table_name = PROPERTY_NAME_MAP[prop_name] |
103 | | - table_path = f"{element_group}/{table_name}" |
104 | | - |
105 | | - # get the table node from the HDF5 file |
106 | | - table = ELEMENTS_H5FILE.get_node(table_path) |
107 | | - |
108 | | - # Handle basic properties (single column --> no sources) |
109 | | - if len(table.colnames) == 1 and table.colnames[0] == "value": |
110 | | - value = table[0]["value"] |
111 | | - # if the value is an int, return it as an int |
112 | | - if isinstance(value, Integral): |
113 | | - return int(value) |
114 | | - # if the value is a string, decode from bytes |
115 | | - elif isinstance(value, bytes): |
116 | | - return value.decode("utf-8") |
117 | | - else: |
118 | | - # handle properties with multiple sources |
119 | | - result = {} |
120 | | - for row in table: |
121 | | - source = row["source"].decode("utf-8") |
122 | | - value = row["value"] |
123 | | - # exclude none values |
124 | | - if not np.isnan(value): |
125 | | - result[source] = float(value) |
126 | | - return result if result else None |
127 | | - |
128 | 86 |
|
129 | 87 | def _remove_suffix(input_string, suffix): |
130 | 88 | if suffix and input_string.endswith(suffix): |
@@ -781,19 +739,19 @@ def compile_species( |
781 | 739 | fields = submodule.run(elem, charge, mult, nexc, dataset, datapath) |
782 | 740 |
|
783 | 741 | # dump the data to the HDF5 file |
784 | | - dump(fields, dataset, elem, charge, mult, nexc) |
| 742 | + # dump(fields, dataset, elem, charge, mult, nexc) |
785 | 743 |
|
786 | 744 |
|
787 | | - # fields = asdict(fields) |
788 | | - # # print all fields |
789 | | - # for key, value in fields.items(): |
790 | | - # if isinstance(value, np.ndarray): |
791 | | - # print(f"{key}: shape={value.shape}, first 5 elements={value.flat[:5]}") |
792 | | - # else: |
793 | | - # print(f"{key}: {value}") |
794 | | - # |
795 | | - # species = Species(dataset, fields) |
796 | | - # return species |
| 745 | + fields = asdict(fields) |
| 746 | + # print all fields |
| 747 | + for key, value in fields.items(): |
| 748 | + if isinstance(value, np.ndarray): |
| 749 | + print(f"{key}: shape={value.shape}, first 5 elements={value.flat[:5]}") |
| 750 | + else: |
| 751 | + print(f"{key}: {value}") |
| 752 | + |
| 753 | + species = Species(dataset, fields) |
| 754 | + return species |
797 | 755 |
|
798 | 756 |
|
799 | 757 |
|
@@ -1014,7 +972,8 @@ def get_species_data(folder_path, elem, DATASET_PROPERTY_CONFIGS): |
1014 | 972 | fields[config['Carray_property']] = table[:] |
1015 | 973 |
|
1016 | 974 |
|
1017 | | - fields['atnum'] = element_symbol_map[elem][0] |
| 975 | + fields['atnum'] = element_symbol_map[elem][ElementAttr.atnum] |
| 976 | + |
1018 | 977 |
|
1019 | 978 | # Add scalar properties |
1020 | 979 | for prop in ('atmass', 'cov_radius', 'vdw_radius', 'at_radius', 'polarizability', 'dispersion'): |
@@ -1063,7 +1022,8 @@ def raw_datafile( |
1063 | 1022 | str |
1064 | 1023 | Path to the raw data file. |
1065 | 1024 | """ |
1066 | | - elem = "*" if elem is Ellipsis else element_symbol(elem) |
| 1025 | + # elem = "*" if elem is Ellipsis else element_symbol(elem) --> why using element_symbol here |
| 1026 | + elem = "*" if elem is Ellipsis else elem |
1067 | 1027 | charge = "*" if charge is Ellipsis else f"{charge:03d}" |
1068 | 1028 | mult = "*" if mult is Ellipsis else f"{mult:03d}" |
1069 | 1029 | nexc = "*" if nexc is Ellipsis else f"{nexc:03d}" |
|
0 commit comments