conceptual-dictionary 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- conceptual_dictionary/__init__.py +1 -0
- conceptual_dictionary/conceptualdict.py +70 -0
- conceptual_dictionary/templates.py +62 -0
- conceptual_dictionary-0.1.1.dist-info/METADATA +115 -0
- conceptual_dictionary-0.1.1.dist-info/RECORD +8 -0
- conceptual_dictionary-0.1.1.dist-info/WHEEL +5 -0
- conceptual_dictionary-0.1.1.dist-info/licenses/LICENSE +21 -0
- conceptual_dictionary-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# This file marks the conceptual_dictionary module.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import yaml
|
|
2
|
+
import json
|
|
3
|
+
from typing import Any, Dict
|
|
4
|
+
import numpy as np
|
|
5
|
+
import string
|
|
6
|
+
import random
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class ConceptualDict(dict):
|
|
10
|
+
def __init__(self, *args, **kwargs):
|
|
11
|
+
data = {"computational_sample": [], "workflow": []}
|
|
12
|
+
super().__init__(data, *args, **kwargs)
|
|
13
|
+
|
|
14
|
+
def generate_id(self, length=7):
|
|
15
|
+
"""Generate a random alphanumeric ID of given length."""
|
|
16
|
+
chars = string.ascii_letters + string.digits
|
|
17
|
+
return "".join(random.choices(chars, k=length))
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def _clean_data(obj: Any) -> Any:
|
|
21
|
+
if isinstance(obj, dict):
|
|
22
|
+
return {k: ConceptualDict._clean_data(v) for k, v in obj.items()}
|
|
23
|
+
elif isinstance(obj, list):
|
|
24
|
+
return [ConceptualDict._clean_data(v) for v in obj]
|
|
25
|
+
elif isinstance(obj, np.ndarray):
|
|
26
|
+
return obj.tolist()
|
|
27
|
+
elif isinstance(obj, (np.floating, np.float32, np.float64)):
|
|
28
|
+
return float(obj)
|
|
29
|
+
elif isinstance(obj, (np.integer, np.int32, np.int64)):
|
|
30
|
+
return int(obj)
|
|
31
|
+
elif isinstance(obj, (np.bool_, bool)):
|
|
32
|
+
return bool(obj)
|
|
33
|
+
elif obj is None or isinstance(obj, (str, float, int)):
|
|
34
|
+
return obj
|
|
35
|
+
else:
|
|
36
|
+
return str(obj)
|
|
37
|
+
|
|
38
|
+
# --------------------
|
|
39
|
+
# YAML I/O
|
|
40
|
+
# --------------------
|
|
41
|
+
def to_yaml(self, filepath: str, sort_keys: bool = False) -> None:
|
|
42
|
+
clean_dict = ConceptualDict._clean_data(dict(self))
|
|
43
|
+
with open(filepath, "w") as f:
|
|
44
|
+
yaml.safe_dump(clean_dict, f, sort_keys=sort_keys, allow_unicode=True)
|
|
45
|
+
|
|
46
|
+
@classmethod
|
|
47
|
+
def from_yaml(cls, filepath: str) -> "ConceptualDict":
|
|
48
|
+
with open(filepath, "r") as f:
|
|
49
|
+
data = yaml.safe_load(f)
|
|
50
|
+
kg = cls()
|
|
51
|
+
kg.update(data)
|
|
52
|
+
return kg
|
|
53
|
+
|
|
54
|
+
# --------------------
|
|
55
|
+
# JSON I/O
|
|
56
|
+
# --------------------
|
|
57
|
+
def to_json(self, filepath: str, sort_keys: bool = False, indent: int = 2) -> None:
|
|
58
|
+
clean_dict = ConceptualDict._clean_data(dict(self))
|
|
59
|
+
with open(filepath, "w") as f:
|
|
60
|
+
json.dump(
|
|
61
|
+
clean_dict, f, sort_keys=sort_keys, indent=indent, ensure_ascii=False
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
@classmethod
|
|
65
|
+
def from_json(cls, filepath: str) -> "ConceptualDict":
|
|
66
|
+
with open(filepath, "r") as f:
|
|
67
|
+
data = json.load(f)
|
|
68
|
+
kg = cls()
|
|
69
|
+
kg.update(data)
|
|
70
|
+
return kg
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
sample_template = {
|
|
2
|
+
"id": "sample1",
|
|
3
|
+
"material": {
|
|
4
|
+
"element_ratio": {},
|
|
5
|
+
"crystal_structure": {
|
|
6
|
+
"spacegroup_symbol": None,
|
|
7
|
+
"spacegroup_number": None,
|
|
8
|
+
"unit_cell": {
|
|
9
|
+
"bravais_lattice": None,
|
|
10
|
+
"lattice_parameter": None,
|
|
11
|
+
"angle": [],
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
"simulation_cell": {
|
|
16
|
+
"volume": {"value": None},
|
|
17
|
+
"number_of_atoms": None,
|
|
18
|
+
"length": [],
|
|
19
|
+
"vector": [],
|
|
20
|
+
"angle": [],
|
|
21
|
+
"repetitions": [],
|
|
22
|
+
"grain_size": None,
|
|
23
|
+
"number_of_grains": 0,
|
|
24
|
+
},
|
|
25
|
+
"atom_attribute": {
|
|
26
|
+
"position": None,
|
|
27
|
+
"species": None,
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
property_template = {
|
|
32
|
+
"basename": None,
|
|
33
|
+
"value": None,
|
|
34
|
+
"unit": None,
|
|
35
|
+
"associate_to_sample": [],
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
workflow_template = {
|
|
39
|
+
"algorithm": None,
|
|
40
|
+
"method": None,
|
|
41
|
+
"xc_functional": None,
|
|
42
|
+
"input_parameter": [],
|
|
43
|
+
"input_sample": [],
|
|
44
|
+
"output_sample": [],
|
|
45
|
+
"calculated_property": [],
|
|
46
|
+
"degrees_of_freedom": [],
|
|
47
|
+
"interatomic_potential": {
|
|
48
|
+
"potential_type": None,
|
|
49
|
+
"uri": None,
|
|
50
|
+
},
|
|
51
|
+
"software": {
|
|
52
|
+
"uri": None,
|
|
53
|
+
"version": None,
|
|
54
|
+
"label": None,
|
|
55
|
+
},
|
|
56
|
+
"workflow_manager": {
|
|
57
|
+
"uri": None,
|
|
58
|
+
"version": None,
|
|
59
|
+
"label": None,
|
|
60
|
+
},
|
|
61
|
+
"thermodynamic_ensemble": None,
|
|
62
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: conceptual-dictionary
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: A Python dictionary template for storing serializable metadata
|
|
5
|
+
Author: Sarath Menon, Abril Azocar Guzman
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 pyscal
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/pyscal/conceptual_dictionary
|
|
29
|
+
Project-URL: Bug Tracker, https://github.com/pyscal/conceptual_dictionary/issues
|
|
30
|
+
Keywords: dictionary,metadata,serialization,conceptual
|
|
31
|
+
Classifier: Development Status :: 3 - Alpha
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
41
|
+
Requires-Python: >=3.7
|
|
42
|
+
Description-Content-Type: text/markdown
|
|
43
|
+
License-File: LICENSE
|
|
44
|
+
Requires-Dist: numpy
|
|
45
|
+
Requires-Dist: pyyaml
|
|
46
|
+
Dynamic: license-file
|
|
47
|
+
|
|
48
|
+
# conceptual_dictionary
|
|
49
|
+
|
|
50
|
+
A Python dictionary template for storing serializable metadata.
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
Install from source:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install -e .
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
61
|
+
|
|
62
|
+
### Using Templates
|
|
63
|
+
|
|
64
|
+
Import and use predefined dictionary templates:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from conceptual_dictionary.templates import sample_template, property_template, workflow_template
|
|
68
|
+
|
|
69
|
+
# Use a template directly
|
|
70
|
+
my_data = sample_template.copy()
|
|
71
|
+
my_data['material']['element_ratio'] = {'Fe': 0.7, 'C': 0.3}
|
|
72
|
+
my_data['simulation_cell']['volume']['value'] = 1000
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Using ConceptualDict Class
|
|
76
|
+
|
|
77
|
+
Work with conceptual dictionaries using the ConceptualDict class:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from conceptual_dictionary.conceptualdict import ConceptualDict
|
|
81
|
+
|
|
82
|
+
# Create a new conceptual dictionary
|
|
83
|
+
cd = ConceptualDict()
|
|
84
|
+
|
|
85
|
+
# Set values using dot notation
|
|
86
|
+
cd.set("material.element_ratio.Fe", 0.7)
|
|
87
|
+
cd.set("material.element_ratio.C", 0.3)
|
|
88
|
+
cd.set("simulation_cell.volume.value", 1000)
|
|
89
|
+
|
|
90
|
+
# Get values
|
|
91
|
+
fe_ratio = cd.get("material.element_ratio.Fe")
|
|
92
|
+
volume = cd.get("simulation_cell.volume.value")
|
|
93
|
+
|
|
94
|
+
# Convert to standard dictionary
|
|
95
|
+
data = cd.to_dict()
|
|
96
|
+
|
|
97
|
+
# Serialize to JSON
|
|
98
|
+
json_str = cd.to_json(indent=2)
|
|
99
|
+
|
|
100
|
+
# Save to file
|
|
101
|
+
cd.save("my_conceptual.json")
|
|
102
|
+
|
|
103
|
+
# Load from file
|
|
104
|
+
cd_loaded = ConceptualDict.from_json("my_conceptual.json")
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Available Templates
|
|
108
|
+
|
|
109
|
+
- **sample_template**: Standard template with metadata, content, and schema sections
|
|
110
|
+
- **property_template**: Template for defining properties with values and units
|
|
111
|
+
- **workflow_template**: Template for describing workflows, including algorithms and methods
|
|
112
|
+
|
|
113
|
+
## License
|
|
114
|
+
|
|
115
|
+
MIT License
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
conceptual_dictionary/__init__.py,sha256=Gtthpv5dXjBPbhDviJsLqf7ui_CMQH7KqOqsA2kmooY,52
|
|
2
|
+
conceptual_dictionary/conceptualdict.py,sha256=uU_1zbZVCAseXhO-y-j8HdulFQtBZvUAlHOqUa2YQzE,2357
|
|
3
|
+
conceptual_dictionary/templates.py,sha256=cJf4ItGZa74W9lLXLzTD16Dr35Q-LqdgEe1iI_kRlV4,1375
|
|
4
|
+
conceptual_dictionary-0.1.1.dist-info/licenses/LICENSE,sha256=Cz67nMihKnofYU66OZOzm0k5gCBMC56w6wWV-AuffKw,1063
|
|
5
|
+
conceptual_dictionary-0.1.1.dist-info/METADATA,sha256=Tx8qkFb0DVGH20YqdTb3Djtc1bNv6BWGMlFPd40Inzw,3837
|
|
6
|
+
conceptual_dictionary-0.1.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
+
conceptual_dictionary-0.1.1.dist-info/top_level.txt,sha256=YuqFwcFZvCKBgG1-2CqVjzFCcE135GEmwMZWEz5yf6w,22
|
|
8
|
+
conceptual_dictionary-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 pyscal
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
conceptual_dictionary
|