diff --git a/src/heurams/kernel/particles/atom.py b/src/heurams/kernel/particles/atom.py index 0e3d0f6..5483f6a 100644 --- a/src/heurams/kernel/particles/atom.py +++ b/src/heurams/kernel/particles/atom.py @@ -52,4 +52,4 @@ class Atom(): @staticmethod def placeholder(): - return (Electron.placeholder(), Nucleon.placeholder(), {}) + return (Electron.placeholder(), Nucleon.placeholder(), {}) \ No newline at end of file diff --git a/src/heurams/kernel/particles/loader.py b/src/heurams/kernel/particles/loader.py index 14efd4f..42aba06 100644 --- a/src/heurams/kernel/particles/loader.py +++ b/src/heurams/kernel/particles/loader.py @@ -5,7 +5,7 @@ import pathlib import toml import json -def loader_nucleon(path: pathlib.Path, fmt = "toml"): +def load_nucleon(path: pathlib.Path, fmt = "toml"): with open(path, "r") as f: dictdata = dict() toml.load(f, dictdata) # type: ignore @@ -13,4 +13,14 @@ def loader_nucleon(path: pathlib.Path, fmt = "toml"): for item, attr in dictdata.items(): if item == "__metadata__": continue - lst.append(Nucleon(hasher.hash(item), attr)) + lst.append((Nucleon(hasher.hash(item), attr), dictdata["__metadata__"]["orbital"])) + return lst + +def load_electron(path: pathlib.Path, fmt = "json"): + with open(path, "r") as f: + dictdata = dict() + json.load(f, dictdata) # type: ignore + lst = list() + for item, attr in dictdata.items(): + lst.append(Electron(hasher.hash(item), attr)) + return lst \ No newline at end of file diff --git a/src/heurams/kernel/particles/nucleon.py b/src/heurams/kernel/particles/nucleon.py index a8d3591..f6e7f73 100644 --- a/src/heurams/kernel/particles/nucleon.py +++ b/src/heurams/kernel/particles/nucleon.py @@ -1,29 +1,29 @@ class Nucleon: """原子核: 材料元数据""" - def __init__(self, ident: str, metadata: dict): + def __init__(self, ident: str, payload: dict): """初始化原子核 (记忆内容) Args: ident: 唯一标识符 - metadata: 记忆内容信息 + payload: 记忆内容信息 """ - self.metadata = metadata + self.payload = payload self.ident = ident def __getitem__(self, key): if key == "ident": return self.ident - if key in self.metadata: - return self.metadata[key] + if key in self.payload: + return self.payload[key] else: - raise KeyError(f"Key '{key}' not found in metadata.") + raise KeyError(f"Key '{key}' not found in payload.") def __iter__(self): - yield from self.metadata.keys() + yield from self.payload.keys() def __len__(self): - return len(self.metadata) + return len(self.payload) def __hash__(self): return hash(self.ident)