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)
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() print suite[0].pqu() print suite[0].pqu('s') print suite[0].pqu().getValueAs('s') print suite = halflifeModule.suite() h2 = halflifeModule.string('nucleus', 'stable', quantityModule.stringToPhysicalUnit('s')) suite.add(h2) print suite.toXML() suite2 = suite.parseXMLStringAsClass(suite.toXML()) if (suite2.toXML() != suite.toXML()): raise Exception('Fix me') print '\n============== SPIN ==============' fraction = quantityModule.fraction.toValueType("5/2") s1 = spinModule.fraction('nucleus', fraction, quantityModule.stringToPhysicalUnit('hbar')) xmls1 = s1.toXML() print xmls1 s2 = s1.parseXMLStringAsClass(xmls1) if (xmls1 != s2.toXML()): raise Exception('Fix me.')
from PoPs.quantities import charge as chargeModule from PoPs.quantities import halflife as halflifeModule from PoPs.families import lepton as leptonModule electron = leptonModule.particle('e-', generation='electronic') mass = massModule.double('base', 5.48579909070e-4, quantityModule.stringToPhysicalUnit('amu')) electron.mass.add(mass) charge = chargeModule.integer('base', -1, quantityModule.stringToPhysicalUnit('e')) electron.charge.add(charge) halflife = halflifeModule.string('base', 'stable', quantityModule.stringToPhysicalUnit('s')) electron.halflife.add(halflife) spin = spinModule.fraction('base', spinModule.fraction.toValueType('1/2'), quantityModule.stringToPhysicalUnit('hbar')) electron.spin.add(spin) parity = parityModule.integer('base', 1, quantityModule.stringToPhysicalUnit('')) electron.parity.add(parity) print electron.toXML() print electron2 = leptonModule.particle.parseXMLStringAsClass(electron.toXML()) if (electron.toXML() != electron2.toXML()): raise Exception('Fix me')
def endfFileToGND(fileName, useFilesQAlways=True, singleMTOnly=None, evaluation=None, MTs2Skip=None, parseCrossSectionOnly=False, toStdOut=True, toStdErr=True, logFile=None, skipBadData=False, doCovariances=True, verboseWarnings=False, verbose=1, reconstructResonances=True, **kwargs): logs = logFiles(toStdOut=toStdOut, toStdErr=toStdErr, logFile=logFile, defaultIsStderrWriting=False) header, MAT, MTDatas = endfFileToGNDMisc.parseENDFByMT_MF(fileName, logFile=logs) styleName = 'eval' reconstructedStyleName = 'recon' if MTs2Skip is None: MTs2Skip = [] # Parse the ENDF documentation section info = readMF1MT451(MAT, MTDatas, styleName=styleName, logFile=logs, verboseWarnings=verboseWarnings, **kwargs) # OK, now decide what to do # First batch of ITYPE's are the special cases if (info.ITYPE == 2): # Thermal scattering law data return (ENDF_ITYPE_2.ITYPE_2(MTDatas, info, verbose=verbose)) elif (info.ITYPE == 4): # Decay data, including SFPY return (ENDF_ITYPE_4.ITYPE_4(MTDatas, info, verbose=verbose)) elif (info.ITYPE == 5): # Decay data, including SFPY return (ENDF_ITYPE_5.ITYPE_5(MTDatas, info, verbose=verbose)) elif (info.ITYPE == 6): # Atomic relaxation data if (info.NSUB not in [6]): raise ValueError('For ITYPE = %d, invalid NSUB = %s' % (info.ITYPE, info.NSUB)) return (ENDF_ITYPE_6.ITYPE_6(info.targetZA / 1000, MTDatas, info, verbose=verbose)) # Second batch of ITYPE's are general transport data if (info.LIS != 0): levelIndex = info.LIS if (info.ITYPE in [ 0, 1, 9 ]): # Nuclear transport data (g, n, p, d, t, h, a), including FPY target = toGNDMisc.getTypeNameGamma(info, info.targetZA, level=info.level, levelIndex=info.levelIndex) targetID = target.id if ((info.STA != 0)): halflife = halflifeModule.string(info.PoPsLabel, halflifeModule.UNSTABLE, halflifeModule.baseUnit) target = info.PoPs[targetID] if (isinstance(target, nuclearLevelModule.particle)): target = target.nucleus if (isinstance(target, isotopeModule.suite)): target = target[0].nucleus if (len(target.halflife) == 0): target.halflife.add(halflife) elif (info.ITYPE == 3): # Atomic transport data (e, x) targetZ = info.targetZA / 1000 targetID = chemicalElementModule.symbolFromZ[targetZ] targetName = chemicalElementModule.nameFromZ[targetZ] info.PoPs.add( chemicalElementModule.suite(targetID, targetZ, targetName)) else: raise ValueError("Unsupported ITYPE = %s" % info.ITYPE) # Add alias if needed for metastable target ZA2, MAT2 = endf_endlModule.ZAAndMATFromParticleName(targetID) MAT2 += info.LISO if (MAT2 != info.MAT): info.logs.write( " WARNING: ENDF MAT = %s not as expected (i.e., %s).\n" % (info.MAT, MAT2), stderrWriting=True) if (info.LISO != 0): targetBaseName = targetID.split('_')[0] aliasName = alias.aliases.nuclearMetaStableName( targetBaseName, info.LISO) info.PoPs.add( PoPsAliasModule.metaStable(aliasName, targetID, info.LISO)) # Compute the reconstructed and evaluated Styles evaluatedStyle = fudge.gnd.styles.evaluated( styleName, '', physicalQuantityModule.temperature( PQUModule.pqu_float.surmiseSignificantDigits( info.targetTemperature), 'K'), info.library, info.libraryVersion, date=info.Date) if (evaluation is None): evaluation = "%s-%d.%d" % (info.library, info.NVER, info.LREL) info.reconstructedStyle = stylesModule.crossSectionReconstructed( reconstructedStyleName, derivedFrom=evaluatedStyle.label, date="2016-11-06") # Stuff for handling transport data info.printBadNK14 = True info.continuumSpectraFix = False info.ignoreMF10Fission = False options = [ 'printBadNK14', 'continuumSpectraFix', 'ignoreBadDate', 'ignoreMF10Fission' ] for option in kwargs: if (option not in options): raise DeprecationWarning('invalid deprecated option "%s"' % option) setattr(info, option, kwargs[option]) info.evaluatedStyle = evaluatedStyle info.reconstructedAccuracy = 0.001 info.MF12_LO2 = {} info.AWR_mode = None info.particleSpins = {} info.missingTwoBodyMasses = {} info.MF4ForNonNeutrons = [] projectile = toGNDMisc.getTypeNameGamma(info, info.projectileZA) # Set up the reactionSuite reactionSuite = reactionSuiteModule.reactionSuite( projectile.id, targetID, evaluation, style=info.evaluatedStyle, documentation=info.documentation, MAT=MAT, PoPs=info.PoPs) MTDatas[451][1] = MTDatas[451][1][:4 + info.NWD] info.reactionSuite = reactionSuite info.PoPs = reactionSuite.PoPs info.target = reactionSuite.target # Set up the covarianceSuite, if needed, and do other ITYPE-specific calculations covarianceSuite = None if ((info.ITYPE == 0) or (info.ITYPE == 9)): doRaise = info.NSUB not in { 0: [0, 10, 10010, 10020, 10030, 20030, 20040], 9: [19] }[info.ITYPE] if (doRaise): raise ValueError('For ITYPE = %d, invalid NSUB = %s' % (info.ITYPE, info.NSUB)) covarianceSuite = ENDF_ITYPE_0.ITYPE_0( MTDatas, info, reactionSuite, singleMTOnly, MTs2Skip, parseCrossSectionOnly, doCovariances, verbose, reconstructResonances=reconstructResonances) elif (info.ITYPE in [3, 1]): if (info.NSUB not in [3, 11, 113]): raise ValueError('For ITYPE = %d, invalid NSUB = %s' % (info.ITYPE, info.NSUB)) ENDF_ITYPE_3.ITYPE_3(MTDatas, info, reactionSuite, singleMTOnly, parseCrossSectionOnly, verbose=verbose) # Fill up the reactionSuite for reaction in reactionSuite.reactions: addUnspecifiedDistributions(info, reaction.outputChannel) for production in reactionSuite.productions: addUnspecifiedDistributions(info, production.outputChannel) PoPs = reactionSuite.PoPs lightMasses = { # atomic masses in amu, taken from AME2012 (http://www.nndc.bnl.gov/masses/mass.mas12) 'n': 1.00866491585, 'H1': 1.00782503223, 'H2': 2.01410177812, 'H3': 3.01604927791, 'He3': 3.01602932008, 'He4': 4.00260325413, } for product1ID in info.missingTwoBodyMasses: try: product1Mass = PoPs[product1ID].getMass('amu') except Exception as exc: # FIXME currently getMass raises Exception, should probably be KeyError instead if product1ID in lightMasses: product1Mass = lightMasses[product1ID] PoPs[product1ID].mass.add( massModule.double( info.PoPsLabel, product1Mass, quantityModule.stringToPhysicalUnit('amu'))) else: raise exc massPTmP1 = PoPs[reactionSuite.projectile].getMass( 'amu' ) + PoPs[reactionSuite.target].getMass( 'amu' ) - \ product1Mass summedQM = 0 for product2ID, QM in info.missingTwoBodyMasses[product1ID]: summedQM += QM mass = massPTmP1 - PQUModule.PQU( summedQM / len(info.missingTwoBodyMasses[product1ID]), 'eV/c**2').getValueAs('amu') mass = massModule.double(info.PoPsLabel, mass, quantityModule.stringToPhysicalUnit('amu')) residual = reactionSuite.PoPs[info.missingTwoBodyMasses[product1ID][0] [0]] if (len(residual.mass) == 0): residual.mass.add(mass) # Did we have trouble? if (len(info.MF4ForNonNeutrons) > 0): print ' WARNING: MF=4 data for non-neutron product: MTs = %s' % sorted( info.MF4ForNonNeutrons) if (len(info.doRaise) > 0 and not skipBadData): info.logs.write('\nRaising due to following errors:\n') for err in info.doRaise: info.logs.write(err + '\n') raise Exception('len( info.doRaise ) > 0') return ({ 'reactionSuite': reactionSuite, 'covarianceSuite': covarianceSuite, 'errors': info.doRaise, 'info': info })