def ITYPE_6(Z, MTDatas, info, verbose=False): MT = 533 errors = [] elementSymbol = nuclearModule.elementSymbolFromZ(Z) element = xParticleModule.element(elementSymbol) MTs = sorted(MTDatas.keys()) if (451 in MTs): MTs.remove(451) if (MTs != [MT]): raise Exception('Only allowed MT is %s (and 451): %s' % (MT, MTs)) warningList = [] MFData = MTDatas[MT] info.logs.write(' %3d %s' % (MT, sorted(MFData.keys()))) if (MFData.keys() != [28]): raise Exception('For MT %s data, only allowed MF is 28: %s' % (MT, MFData.keys())) MF28 = MFData[28] offset = 0 ZA, AWP, dummy, dummy, NSS, dummy = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MF28[offset], intIndices=[4], logFile=info.logs) offset += 1 for subshell in range(NSS): SUBI, dummy, dummy, dummy, dummy, NTR = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MF28[offset], intIndices=[0, 5], logFile=info.logs) offset += 1 EBI, ELN, dummy, dummy, dummy, dummy = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MF28[offset], intIndices=[], logFile=info.logs) offset += 1 atomicConfiguration = xParticleModule.atomicConfiguration( MT_AtomicConfigurations[534 + SUBI - 1], PQUModule.PQU(EBI, 'eV'), ELN) probabilitySum = 0. info.logs.write(' : %s' % MT_AtomicConfigurations[534 + SUBI - 1]) for transition in range(NTR): SUBJ, SUBK, ETR, FTF, dummy, dummy = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MF28[offset], intIndices=[0, 1], logFile=info.logs) offset += 1 secondAC = ' ' if (SUBK > 0): secondAC = MT_AtomicConfigurations[534 + SUBK - 1] daughters = [] if (SUBK == 0): daughters.append('photon') daughters.append( '%s{%s}' % (elementSymbol, MT_AtomicConfigurations[534 + SUBJ - 1])) else: daughters.append('e-') daughters.append( '%s{%s,%s}' % (elementSymbol, MT_AtomicConfigurations[534 + SUBJ - 1], MT_AtomicConfigurations[534 + SUBK - 1])) atomicDecay = xParticleModule.atomicDecay(FTF, daughters) atomicConfiguration.addDecay(atomicDecay) probabilitySum += FTF if (NTR > 0): if (abs(1 - probabilitySum) > 1e-4): warningList.append('decay probabilities sum to %.6f not 1.' % probabilitySum) element.addConfiguration(atomicConfiguration.subshell, atomicConfiguration) if (offset != len(MF28)): raise Exception( 'Not allow lines of MF 28 data processed: offset = %d, len( MF28 ) = %d' % (offset, len(MF28))) info.logs.write('\n') for warning in warningList: info.logs.write(" WARNING: %s\n" % warning, stderrWriting=True) return ({'element': element, 'errors': errors})
def getZAFromGNDName(name): sym, A, m = getSymAFromGNDName(name) Z = elementSymbolFromZ(sym) return Z * 1000 + int(A)
def ITYPE_3(MTDatas, info, reactionSuite, singleMTOnly, parseCrossSectionOnly, verbose=False): MTs = sorted(MTDatas.keys()) if (451 in MTs): MTs.remove(451) MTList = endfFileToGNDMisc.niceSortOfMTs(MTs, verbose=verbose, logFile=info.logs) MT505 = extractMT505or506(info, 505, MTList, MTDatas, 'imaginary part of anomalous scattering factor') MT506 = extractMT505or506(info, 506, MTList, MTDatas, 'real part of anomalous scattering factor') iChannel = 0 summedReactions = {501: None, 516: None, 522: None} for MT in MTList: if (MT == 500): raise Exception("MT %d not supported" % MT) if ((singleMTOnly is not None) and (MT != singleMTOnly)): continue if (MT in [523]): print ' Skipping MT %d as I do not know what it really is' % MT continue warningList = [] MTData = MTDatas[MT] info.logs.write(' %3d %s' % (MT, sorted(MTData.keys()))) EPE, EFL, crossSection, LR, breakupProducts = readMF3( info, MT, MTData[23], warningList) del MTData[23] isTwoBody, productList = MT == 526, [] undefinedLevelInfo = { 'ZA': None, 'level': 0, 'levelIndex': None, 'count': 0 } if (26 in MTData): isTwoBody = readMF6(MT, info, MTData[26], productList, warningList, undefinedLevelInfo, isTwoBody, crossSection) del MTData[26] addTargetAsResidual = True productsNeeded = [] try: process = { 502: 'coherent', 504: 'incoherent', 522: None, 515: 'electron field', 517: 'nuclear field', 526: 'large angle Coulomb scattering', 527: 'bremsstrahlung', 528: 'excitation' }[MT] except KeyError: process = None if (MT in [502, 504, 522]): outputChannel = channelsModule.twoBodyOutputChannel( process=process) outputChannel.Q.add( toGNDMiscModule.returnConstantQ(info.style, 0, crossSection)) if (MT in [502, 504]): product = toGNDMiscModule.getTypeNameGamma(info, 0) product = toGNDMiscModule.newGNDParticle( info, product, crossSection) outputChannel.products.add( outputChannel.products.uniqueLabel(product)) if (MT == 502): formFactor = readMF27(info, MT, MTData, 'coherent scattering function', warningList) form = photonScatteringModule.coherent.form( info.style, standardsModule.frames.labToken, formFactor, MT506, MT505) else: subform = readMF27(info, MT, MTData, 'incoherent scattering function', warningList) form = photonScatteringModule.incoherent.form( info.style, standardsModule.frames.labToken, subform) product.distribution.add(form) elif (MT in [526, 527, 528]): if (isTwoBody): outputChannel = channelsModule.twoBodyOutputChannel( process=process) else: outputChannel = channelsModule.NBodyOutputChannel( process=process) outputChannel.Q.add( toGNDMiscModule.returnConstantQ(info.style, 0, crossSection)) productsNeeded = ['e-'] if (MT == 527): productsNeeded.insert(0, IDsPoPsModule.photon) else: outputChannel = channelsModule.NBodyOutputChannel(process=process) outputChannel.Q.add( toGNDMiscModule.returnConstantQ(info.style, EPE, crossSection)) if (MT in MT_AtomicConfigurations): productsNeeded = ['e-'] elif (MT in [515, 517]): productsNeeded = ['e-', 'e+'] else: addTargetAsResidual = False if (MT in [526, 527, 528]): productList[0].addAttribute('ENDFconversionFlag', 'MF26') for name in productsNeeded: product = None for i1, product in enumerate(productList): if (name == product.name): break product = None if (product is None): product = toGNDMiscModule.getTypeNameGamma( info, { "photon": 0, "e+": 8, "e-": 9 }[name]) product = toGNDMiscModule.newGNDParticle( info, product, crossSection) outputChannel.products.add( outputChannel.products.uniqueLabel(product)) if ((MT >= 534) and (reactionSuite.projectile == 'e-')): product = toGNDMiscModule.getTypeNameGamma(info, 9) product = toGNDMiscModule.newGNDParticle(info, product, crossSection) outputChannel.products.add( outputChannel.products.uniqueLabel(product)) if (addTargetAsResidual): elementSymbol = nuclearModule.elementSymbolFromZ(info.targetZA / 1000) if (MT >= 534): elementSymbol += '{%s}' % MT_AtomicConfigurations[MT] element = xParticleModule.element(elementSymbol) residual = toGNDMiscModule.newGNDParticle(info, element, crossSection) outputChannel.products.add( outputChannel.products.uniqueLabel(residual)) if (len(MTData) > 0): raise Exception('Untranslated MF data: MFs = %s' % MTData.keys()) if (MT in summedReactions): summedReactions[MT] = [crossSection, outputChannel] info.logs.write('\n') continue EFL = PQUModule.PQU(PQUModule.pqu_float.surmiseSignificantDigits(EFL), 'eV') reaction = reactionModule.reaction(outputChannel, ENDF_MT=MT, EFL=EFL) reaction.crossSection.add(crossSection) reactionSuite.reactions.add(reaction) info.logs.write('\n') for warning in warningList: info.logs.write(" WARNING: %s\n" % warning, stderrWriting=True) if (True): # Need to test for gamma as projectile. for MT in sorted(summedReactions.keys()): if (summedReactions[MT] is None): continue crossSection, outputChannel = summedReactions[MT] summands = [] summandMTs = { 501: range(502, 573), 516: (515, 517), 522: range(534, 573) }[MT] for reaction in reactionSuite: if (reaction.ENDF_MT in summandMTs): summands.append(sumsModule.add(link=reaction.crossSection)) summedCrossSection = sumsModule.crossSectionSum( label=photonSumLabels[MT], ENDF_MT=MT, summands=sumsModule.listOfSummands(summandList=summands), crossSection=crossSection) Q = outputChannel.Q[info.style] if (Q is not None): summedCrossSection.Q.add(Q) reactionSuite.sums.crossSections.add(summedCrossSection) iChannel += 1
def toENDF6(self, style, flags, verbosityIndent='', covarianceSuite=None, useRedsFloatFormat=False, lineNumbers=True, **kwargs): _useRedsFloatFormat = endfFormatsModule.useRedsFloatFormat endfFormatsModule.useRedsFloatFormat = useRedsFloatFormat evaluatedStyle = self.styles.getEvaluatedStyle() if (evaluatedStyle is None): raise ValueError('no evaluation style found') if (flags['verbosity'] >= 10): print '%s%s' % (verbosityIndent, self.inputParticlesToReactionString(suffix=" -->")) verbosityIndent2 = verbosityIndent + ' ' * ( len(self.inputParticlesToReactionString(suffix=" -->")) + 1) projectileZA = miscPoPsModule.ZA(self.PoPs[self.projectile]) IPART = projectileZA if (self.projectile == 'e-'): IPART = 11 targetZA, MAT = endf_endlModule.ZAAndMATFromParticleName(self.target) targetZ, targetA = divmod(targetZA, 1000) targetInfo = {} targetInfo['massTracker'] = massTrackerModule.massTracker() for particle in self.PoPs: if (isinstance(particle, (gaugeBosonPoPsModule.particle, leptonPoPsModule.particle, isotopePoPsModule.suite))): ZA = miscPoPsModule.ZA(particle) if (isinstance(particle, isotopePoPsModule.suite)): if (particle[0].intIndex != 0): continue if (len(particle.mass) > 0): targetInfo['massTracker'].addMassAMU(ZA, particle.getMass('amu')) elif (isinstance(particle, chemicalElementPoPsModule.suite)): ZA = 1000 * particle.Z targetInfo['massTracker'].addMassAMU( ZA, targetInfo['massTracker'].getElementalMassAMU(ZA)) targetInfo['style'] = style targetInfo['reactionSuite'] = self targetInfo['ZA'] = targetZA target = self.PoPs[self.target] levelIndex = 0 levelEnergy_eV = 0 if (isinstance(target, nuclearLevelPoPsModule.particle)): # isomer target levelIndex = target.intIndex levelEnergy_eV = target.energy[0].float('eV') targetInfo['mass'] = targetInfo['massTracker'].getMassAWR( targetZA, levelEnergyInEv=levelEnergy_eV) targetInfo['LIS'] = levelIndex targetInfo['metastables'] = {} targetInfo['LISO'] = 0 if (levelIndex > 0): targetInfo['LISO'] = 1 # BRBBRB for alias in self.PoPs.aliases: if (hasattr(alias, 'metaStableIndex')): targetInfo['metastables'][alias.pid] = alias MAT += targetInfo['LISO'] if (self.MAT is not None): MAT = self.MAT ITYPE = 0 for reaction in self.reactions: if (500 <= reaction.ENDF_MT < 573): ITYPE = 3 targetInfo['crossSectionMF'] = {0: 3, 3: 23}[ITYPE] targetInfo['delayedRates'] = [] targetInfo['MTs'], targetInfo['MF8'], targetInfo['LRs'] = {}, {}, {} endfMFList = { 1: { 451: [] }, 2: {}, 3: {}, 4: {}, 5: {}, 6: {}, 8: {}, 9: {}, 10: {}, 12: {}, 13: {}, 14: {}, 15: {}, 23: {}, 26: {}, 27: {}, 31: {}, 32: {}, 33: {}, 34: {}, 35: {}, 40: {} } if (self.resonances is not None): # Add resonances, independent of reaction channels self.resonances.toENDF6(endfMFList, flags, targetInfo, verbosityIndent=verbosityIndent2) targetInfo['production_gammas'] = {} for multiplicitySum in self.sums.multiplicities: if multiplicitySum.ENDF_MT == 452: targetInfo['totalNubar'] = multiplicitySum.multiplicity.evaluated elif multiplicitySum.ENDF_MT == 455: targetInfo[ 'totalDelayedNubar'] = multiplicitySum.multiplicity.evaluated for reaction in self: reaction.toENDF6(endfMFList, flags, targetInfo, verbosityIndent=verbosityIndent2) gndToENDF6Module.upDateENDFMF8Data(endfMFList, targetInfo) for MT, production_gammas in targetInfo['production_gammas'].items(): MF, production_gammas = production_gammas[0], production_gammas[1:] for productionReaction in production_gammas: gammas = [gamma for gamma in productionReaction.outputChannel] targetInfo['crossSection'] = productionReaction.crossSection[ targetInfo['style']] gndToENDF6Module.gammasToENDF6_MF12_13(MT, MF, endfMFList, flags, targetInfo, gammas) for particle in self.PoPs: if (isinstance(particle, nucleusPoPsModule.particle)): if (len(particle.decayData.decayModes) > 0): for baseMT in [50, 600, 650, 700, 750, 800]: residualZA = endf_endlModule.ENDF_MTZAEquation( projectileZA, targetZA, baseMT)[0][-1] atomID = particle.findClassInAncestry( isotopePoPsModule.suite).id if (nuclearModule.nucleusNameFromZA(residualZA) == atomID): break addDecayGamma(self.PoPs, particle, baseMT, endfMFList, flags, targetInfo) if 'totalNubar' in targetInfo: multiplicityModule.fissionNeutronsToENDF6(452, targetInfo['totalNubar'], endfMFList, flags, targetInfo) if 'promptNubar' in targetInfo: multiplicityModule.fissionNeutronsToENDF6(456, targetInfo['promptNubar'], endfMFList, flags, targetInfo) if 'totalDelayedNubar' in targetInfo: MF5MT455s = endfMFList[5][455] endfMFList[1][455] = [ endfFormatsModule.endfHeadLine(targetZA, targetInfo['mass'], 0, 2, 0, 0) ] # Currently, only LDG = 0, LNU = 2 is supported. endfMFList[1][455] += [ endfFormatsModule.endfHeadLine(0, 0, 0, 0, len(targetInfo['delayedRates']), 0) ] endfMFList[1][455] += endfFormatsModule.endfDataList( targetInfo['delayedRates']) multiplicityModule.fissionNeutronsToENDF6( 455, targetInfo['totalDelayedNubar'], endfMFList, flags, targetInfo) MF5MT455List = [ endfFormatsModule.endfHeadLine(targetZA, targetInfo['mass'], 0, 0, len(MF5MT455s), 0) ] for MF5MT455 in MF5MT455s: MF5MT455List += MF5MT455 if (len(MF5MT455s) == 0): del endfMFList[5][455] else: endfMFList[5][455] = MF5MT455List + [ endfFormatsModule.endfSENDLineNumber() ] if (covarianceSuite): covarianceSuite.toENDF6(endfMFList, flags, targetInfo) endfDoc = self.documentation.get('endfDoc') if (endfDoc is None): docHeader2 = [ ' %2d-%-2s-%3d LLNL EVAL-OCT03 Unknown' % (targetZ, nuclearModule.elementSymbolFromZ(targetZ), targetA), ' DIST-DEC99 19990101 ', '----ENDL MATERIAL %4d' % MAT, '-----INCIDENT %s DATA' % { 1: 'NEUTRON', 1001: 'PROTON', 1002: 'DEUTERON', 1003: 'TRITON', 2003: 'HELION', 2004: 'ALPHA' }[projectileZA], '------ENDF-6 FORMAT' ] endfDoc = [ 'LLNL ENDL file translated to ENDF6 by FUDGE.', '' ' ************************ C O N T E N T S ***********************' ] endlDoc = self.documentation.get('ENDL').getLines() endlDoc2 = [] if endlDoc != None: for line in endlDoc: if 'endep' in line: # remove text from the line before the ones containing 'endep' del endlDoc2[-1] break newline = textwrap.wrap(line, width=66, drop_whitespace=False, subsequent_indent=' ') if len(newline) == 0: newline = [' ' ] # do not let blank lines disappear altogether endlDoc2 += newline endfDoc = endlDoc2 + endfDoc else: docHeader2 = [] endfDoc = endfDoc.getLines() # update the documentation, including metadata on first 4 lines: if self.getReaction('fission') is not None: LFI = True else: LFI = False LRP = -1 if (self.resonances is not None): if (self.resonances.scatteringRadius): LRP = 0 elif (self.resonances.reconstructCrossSection): LRP = 1 elif (self.resonances.unresolved and not self.resonances.resolved): # self-shielding only LRP = 1 else: LRP = 2 crossSectionScale = self.reactions[0].domainUnitConversionFactor('eV') EMAX = max([ crossSectionScale * reaction.crossSection.domainMax for reaction in self.reactions ]) temperature = self.styles[style].temperature.getValueAs('K') library = evaluatedStyle.library version = evaluatedStyle.version if ( library == 'ENDL' ): # Additional ENDF meta-data. If the library is unknown, use NLIB = -1 NVER, LREL, NMOD = 1, 1, 1 NLIB = -1 else: NVER, LREL, NMOD = map(int, version.split('.')) # Version stored as '7.2.1' NLIB = { "ENDF/B": 0, "ENDF/A": 1, "JEFF": 2, "EFF": 3, "ENDF/B (HE)": 4, "CENDL": 5, "JENDL": 6, "SG-23": 21, "INDL/V": 31, "INDL/A": 32, "FENDL": 33, "IRDF": 34, "BROND (IAEA version)": 35, "INGDB-90": 36, "FENDL/A": 37, "BROND": 41 }.get(library, -1) NFOR = 6 # ENDF-6 format NSUB = 10 * IPART + ITYPE LDRV = 0 NLIB = kwargs.get('NLIB', NLIB) STA = 0 target = self.PoPs[self.target] if (isinstance(target, isotopePoPsModule.suite)): target = target[0] if (len(target.nucleus.halflife) > 0): if (target.nucleus.halflife[0].value == halflifePoPsModule.UNSTABLE ): STA = 1 if (levelIndex > 0): STA = 1 projectileMass = targetInfo['massTracker'].getMassAWR(projectileZA, asTarget=False) docHeader = [ endfFormatsModule.endfHeadLine(targetZA, targetInfo['mass'], LRP, LFI, NLIB, NMOD), endfFormatsModule.endfHeadLine(levelEnergy_eV, STA, levelIndex, targetInfo['LISO'], 0, NFOR), endfFormatsModule.endfHeadLine(projectileMass, EMAX, LREL, 0, NSUB, NVER), endfFormatsModule.endfHeadLine(temperature, 0, LDRV, 0, len(docHeader2 + endfDoc), -1) ] new_doc = documentationModule.documentation( 'endf', '\n'.join(docHeader + docHeader2 + endfDoc)) endfMFList[1][451] += endfFormatsModule.toEndfStringList(new_doc) endfFormatsModule.useRedsFloatFormat = _useRedsFloatFormat return (endfFormatsModule.endfMFListToFinalFile(endfMFList, MAT, lineNumbers=lineNumbers))