Skip to content

Commit 5ab6404

Browse files
authored
Merge pull request #4 from openmc-data-storage/adding-fendl
Adding fendl
2 parents 39b5361 + 3a963f7 commit 5ab6404

File tree

5 files changed

+41649
-262613
lines changed

5 files changed

+41649
-262613
lines changed

make_index.py

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import requests
2+
import json
3+
import os
4+
import csv
5+
6+
# reads in the JSON index files and makes a more compact table of the data
7+
8+
compact_table = []
9+
local_file_paths = []
10+
11+
urls=[
12+
"https://raw.githubusercontent.com/openmc-data-storage/ENDF-B-VIII.0-NNDC-json/refs/heads/main/json_files/ENDFB-8.0_index.json",
13+
"https://raw.githubusercontent.com/openmc-data-storage/FENDL-3.2c-json/refs/heads/main/FENDL-3.2c_json/FENDL-3.2c_index.json",
14+
]
15+
i=0
16+
for url in urls:
17+
print(url)
18+
local_file_path= url.split('/')[-1]
19+
if os.path.exists(local_file_path):
20+
with open(local_file_path, 'r') as file:
21+
data = json.load(file)
22+
else:
23+
print(f'downloading file {local_file_path}')
24+
25+
response = requests.get(url)
26+
data = response.json()
27+
with open(local_file_path, 'w') as file:
28+
json.dump(data, file)
29+
30+
31+
for entry in data:
32+
# print(entry.keys())
33+
# input()
34+
new_entry = {}
35+
new_entry['id'] =i # id
36+
new_entry['element'] = entry['Atomic symbol']
37+
new_entry['nucleons'] = entry['Mass number']
38+
new_entry['library'] = entry['Library']
39+
# new_entry['reaction'] = f'({entry["Incident particle"][0]},{entry["Reaction products"]})'
40+
new_entry['incident_particle'] = entry["Incident particle"][0]
41+
new_entry['mt'] = entry['MT reaction number']
42+
new_entry['temperature'] = entry['Temperature(K)']
43+
44+
45+
compact_table.append(new_entry)
46+
47+
i=i+1
48+
49+
with open('src/types/table_data.json', 'w') as outfile:
50+
json.dump(compact_table, outfile)
51+
52+
# Write to CSV file
53+
csv_file_path = 'src/types/table_data.csv'
54+
csv_columns = ['id', 'element', 'nucleons', 'library', 'incident_particle', 'mt', 'temperature']
55+
56+
with open(csv_file_path, 'w', newline='') as csvfile:
57+
writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
58+
writer.writeheader()
59+
for data in compact_table:
60+
writer.writerow(data)
61+
62+
# index_filename
63+
# [
64+
# {
65+
# "Proton number": 19,
66+
# "Mass number": 39,
67+
# "Neutron number": 20,
68+
# "Element": "potassium",
69+
# "Atomic symbol": "K",
70+
# "Temperature(K)": "0",
71+
# "Incident particle": "neutron",
72+
# "Reaction products": "elastic",
73+
# "MT reaction number": 2,
74+
# "Library": "FENDL-3.2c"},
75+
76+
# {
77+
# "id": 0,
78+
# "element": "Dy",
79+
# "nucleons": 157,
80+
# "library": "ENDFB-8.0",
81+
# "reaction": "damage-energy",
82+
# "MT": 444,
83+
# "temperature": "294K"
84+
# },

src/sauce/home.rs

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,14 @@ async fn get_values_by_id(id: i32) -> Result<(Vec<f64>, Vec<f64>, String), reqwe
155155
let output = convert_string(entry);
156156
console::log_1(&serde_wasm_bindgen::to_value(&"output").unwrap());
157157
console::log_1(&serde_wasm_bindgen::to_value(&output).unwrap());
158+
console::log_1(&serde_wasm_bindgen::to_value(&"entry.library").unwrap());
159+
console::log_1(&serde_wasm_bindgen::to_value(&entry.library).unwrap());
158160

159-
let url = format!("https://raw.githubusercontent.com/openmc-data-storage/ENDF-B-VIII.0-NNDC-json/refs/heads/main/json_files/{output}.json");
161+
let url = match entry.library.as_str() {
162+
"ENDFB-8.0" => format!("https://raw.githubusercontent.com/openmc-data-storage/ENDF-B-VIII.0-NNDC-json/refs/heads/main/json_files/{output}.json"),
163+
"FENDL-3.2c" => format!("https://raw.githubusercontent.com/openmc-data-storage/FENDL-3.2c-json/refs/heads/main/FENDL-3.2c_json/{output}.json"),
164+
_ => panic!("Unsupported library: {}", entry.library),
165+
};
160166

161167
console::log_1(&serde_wasm_bindgen::to_value(&url).unwrap());
162168
let downloaded_reaction_data: ReactionData = reqwest::get(url)
@@ -166,7 +172,7 @@ async fn get_values_by_id(id: i32) -> Result<(Vec<f64>, Vec<f64>, String), reqwe
166172
console::log_1(&serde_wasm_bindgen::to_value("downloaded data").unwrap());
167173
console::log_1(&serde_wasm_bindgen::to_value(&downloaded_reaction_data).unwrap());
168174

169-
let label = entry.element.clone() + entry.nucleons.to_string().as_str() + " " + entry.reaction.as_str(); // + " " +entry.library.as_str() +" " + entry.temperature.as_str();
175+
let label = entry.element.clone() + entry.nucleons.to_string().as_str() + " " + entry.reaction.as_str()+ " " +entry.library.as_str(); // +" " + entry.temperature.as_str();
170176
Ok((downloaded_reaction_data.energy_values, downloaded_reaction_data.cross_section_values, label))
171177
}
172178

@@ -179,7 +185,7 @@ fn convert_string(entry: &Entry) -> String {
179185
let particle:char = 'n'; // entry.particle.clone();
180186
let mt = entry.mt.clone();
181187
let temperature = entry.temperature.clone();
182-
let output = format!("{}_{}_{}_{}_{}_{}", element, nucleons, library, particle, mt, temperature);
188+
let output = format!("{}_{}_{}_{}_{}_{}K", element, nucleons, library, particle, mt, temperature);
183189
output
184190
}
185191

@@ -193,10 +199,12 @@ pub fn home() -> Html {
193199
let nucleons_search_term = use_state(|| None::<String>);
194200
let reaction_search_term = use_state(|| None::<String>);
195201
let mt_search_term = use_state(|| None::<String>);
202+
let library_search_term = use_state(|| None::<String>);
196203
let element_search = (*element_search_term).as_ref().cloned();
197204
let nucleons_search = (*nucleons_search_term).as_ref().cloned();
198205
let reaction_search = (*reaction_search_term).as_ref().cloned();
199206
let mt_search = (*mt_search_term).as_ref().cloned();
207+
let library_search = (*library_search_term).as_ref().cloned();
200208

201209
let page = use_state(|| 0usize);
202210
let current_page = (*page).clone();
@@ -212,6 +220,7 @@ pub fn home() -> Html {
212220
ColumnBuilder::new("reaction").orderable(true).short_name("Reaction").data_property("reaction").header_class("user-select-none").build(),
213221
// ColumnBuilder::new("library").orderable(true).short_name("Library").data_property("library").header_class("user-select-none").build(),
214222
ColumnBuilder::new("mt").orderable(true).short_name("MT").data_property("mt").header_class("user-select-none").build(),
223+
ColumnBuilder::new("library").orderable(true).short_name("Library").data_property("library").header_class("user-select-none").build(),
215224
// ColumnBuilder::new("temperature").orderable(true).short_name("Temperature").data_property("temperature").header_class("user-select-none").build(),
216225
];
217226

@@ -239,6 +248,7 @@ pub fn home() -> Html {
239248
let nucleons = &entry.nucleons;
240249
let reaction = &entry.reaction;
241250
let mt = &entry.mt;
251+
let library = &entry.library;
242252

243253
let element_match = match element_search {
244254
Some(ref term) => element.to_lowercase().contains(&term.to_lowercase()),
@@ -256,17 +266,21 @@ pub fn home() -> Html {
256266
Some(ref term) => mt.to_string().contains(&*term),
257267
None => true,
258268
};
269+
let library_match = match library_search {
270+
Some(ref term) => library.to_lowercase().contains(&term.to_lowercase()),
271+
None => true,
272+
};
259273

260-
element_match && nucleons_match && reaction_match && mt_match
274+
element_match && nucleons_match && reaction_match && mt_match && library_match
261275
})
262276
.map(|(index, entry)| TableLine {
263277
original_index: index,
264278
id: entry.id,
265279
element: entry.element.clone(),
266280
nucleons: entry.nucleons.clone(),
267-
library: entry.library.clone(),
268281
reaction: entry.reaction.clone(),
269282
mt: entry.mt.clone(),
283+
library: entry.library.clone(),
270284
temperature: entry.temperature.clone(),
271285
checked: selected_indexes.current().contains(&index),
272286
sum_callback: callback_sum.clone(),
@@ -339,6 +353,18 @@ pub fn home() -> Html {
339353
})
340354
};
341355

356+
let oninput_library_search = {
357+
let library_search_term = library_search_term.clone();
358+
Callback::from(move |e: InputEvent| {
359+
let input: HtmlInputElement = e.target_unchecked_into();
360+
if input.value().is_empty() {
361+
library_search_term.set(None);
362+
} else {
363+
library_search_term.set(Some(input.value()));
364+
}
365+
})
366+
};
367+
342368
// let pagination_options = yew_custom_components::pagination::Options::default()
343369
// .show_prev_next(true)
344370
// .show_first_last(true)
@@ -412,6 +438,18 @@ pub fn home() -> Html {
412438
oninput={oninput_mt_search}
413439
/>
414440
</div>
441+
<div class="flex-grow-1 p-2 input-group">
442+
<span class="input-group-text">
443+
<i class="fas fa-search"></i>
444+
</span>
445+
<input
446+
class="form-control"
447+
type="text"
448+
id="library-search"
449+
placeholder="Search by library"
450+
oninput={oninput_library_search}
451+
/>
452+
</div>
415453
</div>
416454

417455

@@ -421,13 +459,13 @@ pub fn home() -> Html {
421459
options={options.clone()}
422460
limit={Some(limit)}
423461
page={current_page}
424-
search={element_search.clone()}
462+
// search={element_search.clone()}
425463
classes={classes!("table", "table-hover")}
426464
columns={columns.clone()}
427465
data={paginated_data}
428466
orderable={true}
429467
/>
430-
<h5>{"Number selected"} <span class="badge text-bg-secondary">{sum}</span></h5>
468+
<h5>{"Selected"} <span class="badge text-bg-secondary">{sum}</span>{" from 41337 available database entries."}</h5>
431469
</div>
432470
<div class="flex-grow-1 p-2 input-group">
433471

@@ -454,17 +492,17 @@ struct TableLine {
454492
pub id: i32,
455493
pub element: String,
456494
pub nucleons: i32,
457-
pub library: String,
458495
pub reaction: String,
459496
pub mt: i32,
497+
pub library: String,
460498
pub temperature: String,
461499
#[serde(skip_serializing)]
462500
pub sum_callback: Callback<usize>,
463501
}
464502

465503
impl PartialEq<Self> for TableLine {
466504
fn eq(&self, other: &Self) -> bool {
467-
self.element == other.element && self.nucleons == other.nucleons && self.checked == other.checked
505+
self.element == other.element && self.nucleons == other.nucleons && self.library == other.library && self.reaction == other.reaction && self.mt == other.mt && self.checked == other.checked
468506
}
469507
}
470508

0 commit comments

Comments
 (0)