import os
import xml.etree.ElementTree as ET
import duo.core.duo_exception as de
import duo.core.element as duoelement
import duo.core.photoatomic_xs as duophotoatomic_xs
#------------------------------------------------------------
#------------------------------------------------------------
[docs]class PhotoAtomicXSIOManager:
"""Class that manages photoatomic cross-section IO.
Two formats of the ENDF-B-VIII.0 photoatomic libraries are used
- endfb format: Conventional format. Used herein for the list of elements available.
- gnd format: Newer xml-based format. Used herein for both atomic weight ratio (AWR) and microscopic cross-section.
:ivar dictionary elementList: Each (key, value) pair is (Z, :class:`.Element`).
"""
#------------------------------------------------------------
#------------------------------------------------------------
def __init__(self, endfbDir="", gndDir=""):
self.endfbDir = endfbDir
self.endfbFileList = []
self.gndDir = gndDir
self.gndFileList = []
self.elementList = {}
#------------------------------------------------------------
#------------------------------------------------------------
#------------------------------------------------------------
#------------------------------------------------------------
#------------------------------------------------------------
#------------------------------------------------------------
[docs] def OutputAWRToFile(self, outputAWRPath = "awr.txt"):
print("--> Output atomic weight ratio")
with open(outputAWRPath, "w") as outfile:
for Z, element in self.elementList.items():
result = "{0:10d}, {1:10f}, {2:10f}\n".format(element.Z, element.AWR, element.A)
outfile.write(result)
#------------------------------------------------------------
#------------------------------------------------------------
#------------------------------------------------------------
# Add element symbol
#------------------------------------------------------------
[docs] def GetBasicInfo(self, root):
# use xpath feature to find specific node
result = root.findall(".//chemicalElement")
if len(result) != 1:
raise de.DuoException("--> More than 1 chemical info.")
info = result[0]
Z = int(info.attrib["Z"])
if Z not in self.elementList.keys():
raise de.DuoException("--> Element not found.")
element = self.elementList[Z]
element.symbol = info.attrib["symbol"]
return element
#------------------------------------------------------------
#------------------------------------------------------------
[docs] def GetTotalXS(self, root, element):
# use xpath feature to find specific node
result = root.findall(".//crossSectionSum[@ENDF_MT='501']//crossSection//regions1d")
if len(result) != 1:
raise de.DuoException("--> More than 1 interesting section found. Need further handling.")
xsXML = result[0].findall(".//XYs1d/values")
xsList = []
for subXML in xsXML:
stringList = subXML.text.split()
for i in range(len(stringList) // 2):
energy = float(stringList[2 * i]) / 1000.0 # eV to keV
microXS = float(stringList[2 * i + 1]) # barn
xs = duophotoatomic_xs.PhotoAtomicXS(energy, microXS)
xsList.append(xs)
element.xsTable["total_ref"] = xsList
#------------------------------------------------------------
#------------------------------------------------------------
[docs] def GetAllOtherXS(self, root, element):
result = root.findall(".//crossSectionSum[@ENDF_MT='501']/summands/*")
for item in result:
xpath = item.attrib["href"]
# replace substring "/reactionSuite" with "./" to make a legitimate xpath
xpath = xpath.replace("/reactionSuite", "./")
# get xs name
result = xpath.replace("/crossSection", "")
result = root.findall(result)
xsName = result[0].attrib["label"]
block = root.findall(xpath)
# use xpath feature to find specific node
xsXML = block[0].findall(".//XYs1d/values")
xsList = []
for subXML in xsXML:
stringList = subXML.text.split()
for i in range(len(stringList) // 2):
energy = float(stringList[2 * i]) / 1000.0 # eV to keV
microXS = float(stringList[2 * i + 1]) # barn
xs = duophotoatomic_xs.PhotoAtomicXS(energy, microXS)
xsList.append(xs)
element.xsTable[xsName] = xsList
#------------------------------------------------------------
#------------------------------------------------------------
[docs] def Show(self):
for key, value in self.elementList.items():
value.Show()