Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting the parent KZA values from GENDF files. #65

Merged
merged 5 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
279 changes: 279 additions & 0 deletions src/DataLib/fendl32B_retrofit/files_for_tests/gendf_test1.gendf

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/DataLib/fendl32B_retrofit/groupr_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,4 @@ def cleanup_njoy_files(output_path = 'njoy_ouput'):
njoy_files = [INPUT, 'tape20', 'tape21']
for file in njoy_files:
Path.unlink(Path(file))
Path('output').rename(Path(output_path))
Path('output').rename(Path(output_path))
4 changes: 3 additions & 1 deletion src/DataLib/fendl32B_retrofit/process_fendl3.2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ def main():
material_id, MTs = tp.extract_endf_specs(endf_path)
njoy_input = groupr_tools.fill_input_template(material_id, MTs, 'Fe', 56, mt_dict)
groupr_tools.write_njoy_input_file(njoy_input)
groupr_tools.run_njoy('Fe', 56, material_id)
gendf_path = groupr_tools.run_njoy('Fe', 56, material_id)
groupr_tools.cleanup_njoy_files()

pKZA = tp.extract_gendf_pkza(gendf_path)

if __name__ == '__main__':
main()
30 changes: 29 additions & 1 deletion src/DataLib/fendl32B_retrofit/tendl_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,32 @@ def extract_endf_specs(path):
# Extract the MT numbers that are present in the file
MTs = [MT.MT for MT in file.sections.to_list()]

return matb, MTs
return matb, MTs

def extract_gendf_pkza(gendf_path):
"""
Read in and parse the contents of a GENDF file to construct the parent
KZA. KZA values are defined as ZZAAAM, where ZZ is the isotope's
atomic number, AAA is the mass number, and M is the isomeric state
(0 if non-isomeric).

Arguments:
gendf_path (str): File path to the GENDF file being analyzed.
M (str, optional): Identifier of isomer, signified by the letter "M"
at the end of the mass number string.

Defaults to None and will be otherwise defined internally.

Returns:
pKZA (int): Parent KZA identifier.
"""

with open(gendf_path, 'r') as f:
first_line = f.readline()
Z, element, A = first_line.split('-')[:3]

Z = int(Z)
M = 1 if 'm' in A.lower() else 0
A = int(A.lower().split(' ')[0].split('m')[0])
pKZA = (Z * 1000 + A) * 10 + M
return pKZA
3 changes: 1 addition & 2 deletions src/DataLib/fendl32B_retrofit/test_groupr_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
'Fe',
56,
mt_dict,
'''
groupr/
'''groupr/
20 21 0 31/
2631 17 0 11 0 1 1 1/
"26-Fe-56 for TENDL 2017"/
Expand Down
16 changes: 13 additions & 3 deletions src/DataLib/fendl32B_retrofit/test_tendl_processing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Import packages
import pytest
import tendl_preprocessing as tpp
import tendl_processing as tp

dir = './files_for_tests'

Expand All @@ -16,9 +16,19 @@
]
)
def test_extract_endf_specs(endf_file, exp):
obs = tpp.extract_endf_specs(f'{dir}/{endf_file}')
obs = tp.extract_endf_specs(f'{dir}/{endf_file}')
assert obs == exp

def test_extract_endf_specs_empty_endf():
with pytest.raises(Exception, match='std::exception'):
tpp.extract_endf_specs(f'{dir}/endf_test2.tendl')
tp.extract_endf_specs(f'{dir}/endf_test2.tendl')

@pytest.mark.parametrize(
"gendf_file, exp",
[
('gendf_test1.gendf', 260560)
]
)
def test_extract_gendf_pkza(gendf_file, exp):
obs = tp.extract_gendf_pkza(f'{dir}/{gendf_file}')
assert obs == exp