def addParticleData(particle, info, massValue, spinValue, parityValue, chargeValue, halflifeValue): if (massValue is not None): mass = massModule.double(info.PoPsLabel, massValue, quantityModule.stringToPhysicalUnit('amu')) particle.mass.add(mass) if (spinValue is not None): spin = spinModule.fraction(info.PoPsLabel, fractions.Fraction(spinValue), spinModule.baseUnit) particle.spin.add(spin) if (parityValue is not None): parity = parityModule.integer(info.PoPsLabel, parityValue, parityModule.baseUnit) particle.parity.add(parity) if (chargeValue is not None): charge = chargeModule.integer(info.PoPsLabel, chargeValue, chargeModule.baseUnit) particle.charge.add(charge) if (halflifeValue is not None): if (isinstance(halflifeValue, str)): halflife = halflifeModule.string(info.PoPsLabel, halflifeValue, halflifeModule.baseUnit) else: halflife = halflifeModule.double(info.PoPsLabel, halflifeValue, halflifeModule.baseUnit) particle.halflife.add(halflife)
def nuclides(Z, A, data): symbol = chemicalElementMiscModule.symbolFromZ[Z] isotopeID = chemicalElementMiscModule.isotopeSymbolFromChemicalElementIDAndA( symbol, A) keys = random.sample([key for key in data], len(data)) for index in keys: name = chemicalElementMiscModule.nuclideIDFromIsotopeSymbolAndIndex( isotopeID, index) nameLower = name[:1].lower() + name[1:] level = nuclideModule.particle(name) nucleus = level.nucleus atomicMass, nuclearMass, energy, charge, halflife, spin, parity = data[ index] energy = nuclearEnergyLevelModule.double( 'base', energy, quantityModule.stringToPhysicalUnit('keV')) level.energy.add(energy) if (atomicMass is not None): mass = massModule.double( 'base', atomicMass, quantityModule.stringToPhysicalUnit('amu')) level.mass.add(mass) if (nuclearMass is not None): mass = massModule.double( 'base', nuclearMass, quantityModule.stringToPhysicalUnit('amu')) nucleus.mass.add(mass) if (charge is not None): charge = chargeModule.integer( 'base', charge, quantityModule.stringToPhysicalUnit('e')) nucleus.charge.add(charge) if (halflife is not None): if (halflife == 'stable'): halflife = halflifeModule.string( 'base', halflife, quantityModule.stringToPhysicalUnit('s')) else: time, unit = halflife.split() halflife = halflifeModule.double( 'base', float(time), quantityModule.stringToPhysicalUnit(unit)) nucleus.halflife.add(halflife) if (spin is not None): spin = spinModule.fraction( 'base', spinModule.fraction.toValueType(spin), quantityModule.stringToPhysicalUnit('hbar')) nucleus.spin.add(spin) if (parity is not None): parity = parityModule.integer( 'base', parity, quantityModule.stringToPhysicalUnit('')) nucleus.parity.add(parity) database.add(level)
def nuclearLevel(Z, A, data): symbol = chemicalElementModule.symbolFromZ[Z] isotopeID = isotopeModule.isotopeIDFromElementIDAndA(symbol, A) keys = random.sample([key for key in data], len(data)) for index in keys: mass, energy, charge, halflife, spin, parity = data[index] name = nucleusModule.nucleusNameFromNucleusNameAndIndex( isotopeID, index) nucleus = nucleusModule.particle(name, index) energy = nuclearEnergyLevelModule.double( 'base', energy, quantityModule.stringToPhysicalUnit('keV')) nucleus.energy.add(energy) name = nucleusModule.levelNameFromIsotopeNameAndIndex(isotopeID, index) level = nuclearLevelModule.particle(name, nucleus) if (mass is not None): mass = massModule.double( 'base', mass, quantityModule.stringToPhysicalUnit('amu')) level.mass.add(mass) if (charge is not None): charge = chargeModule.integer( 'base', charge, quantityModule.stringToPhysicalUnit('e')) level.charge.add(charge) if (halflife is not None): time, unit = halflife.split() halflife = halflifeModule.double( 'base', float(time), quantityModule.stringToPhysicalUnit(unit)) level.halflife.add(halflife) if (spin is not None): spin = spinModule.fraction( 'base', spinModule.fraction.toValueType(spin), quantityModule.stringToPhysicalUnit('hbar')) level.spin.add(spin) if (parity is not None): parity = parityModule.integer( 'base', parity, quantityModule.stringToPhysicalUnit('')) level.parity.add(parity) database.add(level)
name = nucleusModule.levelNameFromIsotopeNameAndIndex(isotopeID, index) level = nuclearLevelModule.particle(name, nucleus) if (mass is not None): mass = massModule.double('base', mass, quantityModule.stringToPhysicalUnit('amu')) level.mass.add(mass) if (charge is not None): charge = chargeModule.integer('base', charge, quantityModule.stringToPhysicalUnit('e')) level.charge.add(charge) if (halflife is not None): halflife = halflifeModule.double( 'base', halflife, quantityModule.stringToPhysicalUnit('s')) level.halflife.add(halflife) if (spin is not None): spin = spinModule.fraction('base', spinModule.fraction.toValueType(spin), quantityModule.stringToPhysicalUnit('hbar')) level.spin.add(spin) if (parity is not None): parity = parityModule.integer('base', parity, quantityModule.stringToPhysicalUnit('')) level.parity.add(parity) isotope.add(level)
quantityModule.stringToPhysicalUnit('e')) xmlc1 = c1.toXML() print xmlc1 c2 = chargeModule.integer.parseXMLStringAsClass(xmlc1) if (xmlc1 != c2.toXML()): raise Exception('Fix me.') print suite = chargeModule.suite() suite.add(c1) print suite.toXML() suite2 = suite.parseXMLStringAsClass(suite.toXML()) if (suite2.toXML() != suite.toXML()): raise Exception('Fix me') print '\n============== HALFLIFE ==============' h1 = halflifeModule.double('nucleus', 3.14e6, quantityModule.stringToPhysicalUnit('d')) xmlh1 = h1.toXML() print xmlh1 h2 = halflifeModule.double.parseXMLStringAsClass(xmlh1) if (xmlh1 != h2.toXML()): raise Exception('Fix me.') print suite = halflifeModule.suite() suite.add(h1) print suite.toXML() suite2 = suite.parseXMLStringAsClass(suite.toXML()) if (suite2.toXML() != suite.toXML()): raise Exception('Fix me') print print h1.pqu()
def ITYPE_4(MTDatas, info, verbose=0): """Convert ENDF ITYPE 4 data (decay data) into PoPs.""" errors = [] # Add ENDF documentation info.PoPs.documentation = '\n'.join(MTDatas[451][1][4:-info.NXC]) # The atom containing the parent nucleus parentAtom = toGNDMisc.getPoPsParticle(info, info.targetZA, name=None, levelIndex=info.levelIndex, level=info.level, levelUnit=energyUnit) decayParticle = parentAtom if (miscPoPsModule.hasNucleas(parentAtom)): decayParticle = parentAtom.nucleus if (457 in MTDatas): dataIndex = 0 MT457MF8Data = MTDatas[457][8] decayData = decayParticle.decayData # Read parent info block ZA, AWR, LIS, LISO, NST, NSP = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MT457MF8Data[dataIndex], intIndices=[2, 3, 4, 5]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (LIS != 0): aliasID = "%s_m%s" % (isotopeModule.isotopeIDFromElementIDAndA( parentAtom.chemicalElement, parentAtom.A), LISO) info.PoPs.add( PoPsAliasModule.metaStable(aliasID, parentAtom.id, LISO)) HL, dHL, dummy, dummy, NC2, dummy = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MT457MF8Data[dataIndex], intIndices=[4]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) NC = NC2 // 2 # NC: number of decay energies if (NC not in [3, 17]): raise ValueError( "Number of decay energies must be 3 or 17, found %d" % NC) nlines = (NC2 + 5) // 6 aveDecayEnergies = [] for index in range(nlines): aveDecayEnergies.extend( endfFileToGNDMisc.sixFunkyFloatStringsToFloats( MT457MF8Data[dataIndex])) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (len([ aveDecayEnergy for aveDecayEnergy in aveDecayEnergies if (aveDecayEnergy != 0) ]) > 0): aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.lightParticles) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.electroMagneticRadiation) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.heavyParticles) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.betaMinus) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.betaPlus) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.AugerElectron) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.conversionElectron) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.gamma) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.xRay) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.internalBremsstrahlung) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.annihilation) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.alpha) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.recoil) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.spontaneousFission) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.fissionNeutrons) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.proton) aveDecayEnergies = addAverageDecayEnergyIfPresent( decayData, aveDecayEnergies, averageEnergyModule.neutrino) SPI, PAR, dum, dum, NDK6, NDK = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MT457MF8Data[dataIndex], intIndices=[1, 2, 3, 4, 5]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (-77.8 < SPI < -77.7): SPI = None # see page 180 of ENDF manual # FIXME: Need "UNKNOWN" markup halflifeValue = None if (NST == 1): halflifeValue = 'stable' if (PAR == 0): PAR = None # BRB, Happens for dec-013_Al_040.endf toGNDMisc.addParticleData(decayParticle, info, massValue=None, spinValue=SPI, parityValue=PAR, chargeValue=None, halflifeValue=halflifeValue) if (NST == 1): # Nucleus is stable, nothing to do pass elif (NST == 0): # Nucleus is unstable halflife = halflifeModule.double( info.PoPsLabel, HL, halflifeModule.baseUnit ) # FIXME: PQU(HL, 's', dHL), can't store uncertainty? decayParticle.halflife.add(halflife) # Iterate over decay chains decayModes = {} for i1 in range(NDK): # iterate over decay modes initialDecay, otherDecays, RTYP_key = getRTYP( MT457MF8Data[dataIndex]) RTYP, RFS, Q, dQ, BR, dBR = endfFileToGNDMisc.sixFunkyFloatStringsToFloats( MT457MF8Data[dataIndex]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (verbose > 3): print('RTYP = ', RTYP) RFS = int(RFS) # BRB, Isometic state of daughter allDecays = [initialDecay] + otherDecays decayMode = decayDataModule.decayMode( str(i1), ','.join([decayType[r_id] for r_id in allDecays])) decayModes[RTYP_key] = decayMode if (dBR): branching = PQU(BR, '', dBR) else: branching = PQU(BR, '') if (dQ): Qval = PQU(Q, energyUnit, dQ) else: Qval = PQU(Q, energyUnit) decayMode.Q.add( QModule.double('', Qval.getValue(), Qval.unit) ) # FIXME: PQU(Q, 'eV', dQ), can't store uncertainty decayMode.probability.add( probabilityModule.double("BR", branching.getValue(), '') ) # FIXME: PQU(BR, 's', dBR), can't store uncertainty # FIXME: what should we do for really small probabilities, so small ENDF gives 0, like spontaneous fission? n1 = len(otherDecays) - 1 residualZA = addDecayMode(info, decayMode, initialDecay, info.targetZA, RFS, -1 == n1) for i2, otherDecay in enumerate(otherDecays): residualZA = addDecayMode(info, decayMode, otherDecay, residualZA, RFS, i2 == n1) decayData.decayModes.add(decayMode) # LCON determines whether continuum spectra given: LCON 0: discrete only, 1: continuous only, 2: both for i1 in range(NSP): # Iterate over spectra initialDecay, otherDecays, STYP_key = getRTYP( MT457MF8Data[dataIndex], 11) dum, STYP, LCON, zero, six, NER = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MT457MF8Data[dataIndex], intIndices=[2, 3, 4, 5]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) STYP = initialDecay specType = decayType[STYP] FD, dFD, ERave, dERave, FC, dFC = endfFileToGNDMisc.sixFunkyFloatStringsToFloats( MT457MF8Data[dataIndex] ) # FD: discrete normalization, FC: continuum norm., ERave: average decay energy dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (LCON != 1): # Discrete spectra given. for i2 in range(NER): ER, dER, dum, dum, NT, dum = endfFileToGNDMisc.sixFunkyFloatStringsToIntsAndFloats( MT457MF8Data[dataIndex], intIndices=[2, 3, 4, 5]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) discreteSpectra = {'ER': ER, 'dER': dER} if (LCON != 1): if (NT not in (6, 8, 12)): raise ValueError( "Unexpected NT=%d encountered!" % NT) initialDecay, otherDecays, RTYP_key = getRTYP( MT457MF8Data[dataIndex]) discreteSpectra[ 'RTYP_plus'] = endfFileToGNDMisc.sixFunkyFloatStringsToFloats( MT457MF8Data[dataIndex]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) if (verbose > 3): print('STYP, RTYP = ', STYP, RTYP_key) if (NT > 6): RICC, dRICC, RICK, dRICK, RICL, dRICL = endfFileToGNDMisc.sixFunkyFloatStringsToFloats( MT457MF8Data[dataIndex]) dataIndex += printInfo(verbose, dataIndex, MT457MF8Data) discreteSpectra['RICC'], discreteSpectra[ 'dRICC'] = RICC, dRICC if (NT > 8): discreteSpectra['RICK'], discreteSpectra[ 'dRICK'] = RICK, dRICK discreteSpectra['RICL'], discreteSpectra[ 'dRICL'] = RICL, dRICL addDiscreteSpectra(decayModes, RTYP_key, STYP, discreteSpectra) if (LCON != 0): # Continuum spectra given. initialDecay, otherDecays, RTYP_key = getRTYP( MT457MF8Data[dataIndex]) dataIndex, TAB1, regions = endfFileToGNDMisc.getTAB1Regions( dataIndex, MT457MF8Data) RTYP = TAB1['C1'] if (verbose > 3): print('STYP, RTYP = ', STYP, RTYP) LCOV = int(TAB1['L2']) if (len(regions) != 1): raise Exception('len( regions ) = %s' % len(regions)) covariance = None if (LCOV != 0): print(" LCOV != 0") dataIndex, covariance = getList( dataIndex, MT457MF8Data) addContinuumSpectrum(decayModes, RTYP_key, STYP, regions, covariance) else: raise ValueError( "In decay data (MT=457,MF=8), NST should be 0 or 1. Found %d" % NST) # Add documentation to PoPs return ({'PoPs': info.PoPs, 'errors': errors, 'info': info})