Spaces:
Runtime error
Runtime error
File size: 6,356 Bytes
1c703f0 |
1 2 3 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 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 |
"""
Structure of our main database:
DB
βββ unique_id.json :(dictionary)
β βββ unique_id [str]
β βββ formula [str]
β βββ key_words [list(str)]
β βββ source: (dictionary)
β β βββ name: [str](ex: JARVIS /C2DB /None etc)
β β βββ source_id:[str]
β βββ structure:(dictionary)
β β βββ atoms [list(int)]
β β βββ lattice_vectors [3x3[array]]
β β βββ pbc [bool, bool ,bool]
β β βββ position [nx3[array]] n-nr of atoms
β βββ sub_components: [list(str)] (list of parents ids )
β βββ propriety: (dictionary)
β β βββ energy: (list[prop_dictionary])
β β βββ band gap: (list[prop_dictionary])
β β βββ band structure:(list[prop_dictionary])
β β βββ ....
β β βββ density of states:(list[prop_dictionary])
β β
β βββ citation:"str"
β βββ author: (dictionary)
β βββ name
β βββ id
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββ prop_dictionary
β βββ name :(str) energy
β βββ value: (int float list )
β βββ source: (dictionary)
β βββ tipe: (DB/computation/author_enforce)
β βββ citation:"str"
β βββ description: (dictionary)
β βββ author_id : (str)
β βββ method_name : (str)
β βββ hyperparameters :(dictionary)
β βββ inputs :(dictionary)
β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"""
from .utils import read_json , process_chemical_formula
from .parse_c2db import *
from .parse_jarvis import *
# Constants:
JARVIS_DB_path = "/Users/voicutomut/Documents/GitLab/bespoke-interface/DB_experiments/JARVIS2D/d2-12-12-2022.json"
class DBInstance:
def __init__(self):
self.unique_id = None
self.formula = None
self.key_words = []
self.source = None
self.structure = {}
self.sub_components = []
self.propriety = {}
self.author = {}
def from_json_file(self, file_name):
data = read_json(file_name)
self.unique_id = data["unique_id"]
self.formula = data["formula"]
self.key_words = data["key_words"]
self.structure = data["structure"]
self.sub_components = data["sub_components"]
self.source = data["source"]
prop = {}
for key in data["propriety"].keys():
prop[key] = []
read_prop = data["propriety"][key]
for pro in read_prop:
source = Source(pro["source"]["tipe"],
pro["source"]["author_id"],
pro["source"]["description"],
pro["source"]["cite"])
r_pro = DBPropriety(pro["name"], pro["value"], source)
prop[key].append(r_pro)
self.propriety = prop
self.author = data["author"]
return self
def from_c2db_jason(self, file_path):
c2 = read_c2db_json(file_path)
self.unique_id = from_c2db_unique_id(c2['structure.json'])
self.formula = from_c2db_formula(c2['structure.json'])
self.structure = from_c2db_structure(c2['structure.json'])
self.source = {
"name": "C2DB",
"id": from_c2db_unique_id(c2['structure.json']),
"file": file_path.split("/")[-1],
"cite": "DOI 10.1088/2053-1583/aacfc1"
}
self.propriety = {
"energy": [from_c2db_energy(c2['structure.json'])],
"band_gap": [from_c2db_band_gap(c2)],
"band_structure": [from_c2db_band_structure(c2)],
"density_of_states": [from_c2db_density_of_states(c2)],
}
# Todo:
self.key_words = process_chemical_formula(self.formula)
self.sub_components = {}
self.author = {"name": "c2db",
"id": "c2db"}
return self
def from_jarvis_json(self, jarvis_id, jarvis_data=JARVIS_DB_path):
self.unique_id = jarvis_id
jr_data = read_jarvis(jarvis_data)
jr = get_jarvis_instance(jr_data, jarvis_id)
self.formula = from_jarvis_formula(jr)
self.structure = from_jarvis_structure(jr)
self.source = {
"name": "Jarvis",
"id": jarvis_id,
"file": jarvis_data.split("/")[-1],
"cite": "https://jarvis.nist.gov"
}
self.propriety = {
"energy": [from_jarvis_energy(jr)],
"band_gap": [from_jarvis_band_gap(jr)],
"band_structure": [from_jarvis_band_structure(jr)],
"density_of_states": [from_jarvis_density_of_states(jr)],
}
print("band_structure:", self.propriety)
self.key_words = process_chemical_formula(self.formula)
self.sub_components = {}
self.author = {"name": "jarvis",
"id": "jarvis"}
return self
def json_descript(self):
propriety = {}
for key in self.propriety.keys():
propriety[key] = [prop.json_descript() for prop in self.propriety[key] if prop is not None]
data_instance = {"unique_id": self.unique_id,
"formula": self.formula,
"key_words": self.key_words,
"source": self.source,
"structure": self.structure,
"sub_components": self.sub_components,
"propriety": propriety,
"author": self.author}
return data_instance
# inst = DBInstance().from_c2db_jason("/Users/voicutomut/Desktop/WS2-64090c9845f8_data.json")
# print(inst.propriety["energy"][0].value)
|