pypact/input/inputdata.py
def _serialize(self, f):
        """
            The serialization method
            f: file object
        """
        inputdata = []
        
        def addnewline():
            inputdata.append("")
        
        def addcomment(comment):
            inputdata.append(f"{COMMENT_START} {comment} {COMMENT_END}")
        
        def addkeyword(keyword, args=[]):
            strargs = ' '.join([str(a) for a in args])
            inputdata.append(f"{keyword} {strargs}")
        
        # control keywords
        addcomment("CONTROL PHASE")
        if self._json:
            addcomment("enable JSON output")
            addkeyword('JSON')
                
        if self._overwrite:
            addcomment("overwrite existing output files of same name")
            addkeyword('CLOBBER')
        
        if self._readgammagroup:
            addcomment("read gamma groups from file, specify ggbins in files file")
            addkeyword('READGG')
        
        if self._readspontfission:
            addcomment("read spontaneous fission from file, specify sf_endf in files file")
            addkeyword('READSF')
        
        if self._useeaf:
            addcomment("use EAF nuclear data libraries")
            addkeyword('LIBVERSION', args=[0])
        
        if self._usecumfissyield:
            addcomment("use cumulative fission yield data mt=459 instead of mt=454")
            addkeyword('CUMFYLD')
            
        if self._enablemonitor:
            addcomment("monitor FISPACT-II progress")
            addkeyword('MONITOR', args=[1])
        
        addcomment("the minimum cross section (barns) for inclusion in pathways analysis")
        addkeyword('XSTHRESHOLD', args=[self._xsthreshold])
        
        if not self._ignorecollapse:
            if self._group != 0:
                addcomment("perform collapse")
                addkeyword('GETXS', args=[-1 if self._binaryxs and not self._useeaf else 1, self._group])
            else:
                addcomment("don't do collapse, just read the existing file")
                addkeyword('GETXS', args=[0])

        if not self._ignorecondense:
            addcomment("get decay data")
            addkeyword('GETDECAY', args=[1 if self._condense else 0])
    
        if self._loglevel != LOG_SEVERITY_WARNING:
            addcomment("enable logging at level {}".format(self._loglevel))
            addkeyword('LOGLEVEL', args=[self._loglevel])

        if self._approxgamma:
            addcomment("approximate spectra when not available")
            addkeyword('SPEK')
        
        if self._ignoreuncert:
            addcomment("ignore uncertainties")
            addkeyword('NOERROR')
    
        if self._projectile != PROJECTILE_NEUTRON:
            addcomment("set projectile (n=1, d=2, p=3, a=4, g=5)")
            addkeyword('PROJ', args=[self._projectile])
        
        # end control phase
        addcomment("end control")
        addkeyword('FISPACT')
        addkeyword('*', args=[self.name])

        # initial phase
        addnewline()
        addcomment("INITIALIZATION PHASE")
        if self._outputhalflife:
            addcomment("output half life values")
            addkeyword('HALF')

        if self._outputhazards:
            addcomment("output ingestion and inhalation values")
            addkeyword('HAZARDS')

        if self._clearancedata:
            addcomment("include clearance data of radionuclides to be input")
            addkeyword('CLEAR')
            
        if self._inventoryismass and not self._inventoryisfuel:
            if self._inventorymass.totalMass > 0.0:
                addcomment("set the target via MASS")
                addkeyword(str(self._inventorymass))

        if self._inventoryisfuel and not self._inventoryismass:
            if self._density > 0.0:
                addcomment("set the target via FUEL")
                addkeyword(str(self._inventoryfuel))  
        
        if self._density > 0.0:
            addcomment("set the target density")
            addkeyword('DENSITY', args=[self._density])
        
        if self._atomsthreshold > 0.0:
            addcomment("set the threshold for atoms in the inventory")
            addkeyword('MIND', args=[self._atomsthreshold])
        
        if self._initialinventory:
            addcomment("output the initial inventory")
            addkeyword('ATOMS')

        # inventory phase
        addnewline()
        addcomment("INVENTORY PHASE")
        if len(self._irradschedule) > 0:
            addcomment("irradiation schedule")
            for time, fluxamp in self._irradschedule:
                addkeyword('FLUX', args=[f"{fluxamp:.{self._prec}E}"])
                addkeyword('TIME', args=[f"{time:.{self._prec}E}", 'SECS'])
                addkeyword('ATOMS')
            addcomment("end of irradiation")

            addkeyword('FLUX', args=[0.0])
            addkeyword('ZERO')
            for time in self._coolingschedule:
                addkeyword('TIME', args=[f"{time:.{self._prec}E}", 'SECS'])
                addkeyword('ATOMS')
            addcomment("end of cooling")

        # end file
        addnewline()
        addcomment("end of input")
        addkeyword('END')
        addkeyword('*', args=['end'])
        
        for line in inputdata:
            f.write("{}\n".format(line))

            The serialization method
            f: file object
        
The serialization method
f: file object
The serialization method f : file object
def _serialize(self, f):
        inputdata = []
        def addnewline():
            inputdata.append("")
        def addcomment(comment):
            inputdata.append(f"{COMMENT_START} {comment} {COMMENT_END}")
        def addkeyword(keyword, args=[]):
            strargs = ' '.join([str(a) for a in args])
            inputdata.append(f"{keyword} {strargs}")
        addcomment("CONTROL PHASE")
        if self._json:
            addcomment("enable JSON output")
            addkeyword('JSON')
        if self._overwrite:
            addcomment("overwrite existing output files of same name")
            addkeyword('CLOBBER')
        if self._readgammagroup:
            addcomment("read gamma groups from file, specify ggbins in files file")
            addkeyword('READGG')
        if self._readspontfission:
            addcomment("read spontaneous fission from file, specify sf_endf in files file")
            addkeyword('READSF')
        if self._useeaf:
            addcomment("use EAF nuclear data libraries")
            addkeyword('LIBVERSION', args=[0])
        if self._usecumfissyield:
            addcomment("use cumulative fission yield data mt=459 instead of mt=454")
            addkeyword('CUMFYLD')
        if self._enablemonitor:
            addcomment("monitor FISPACT-II progress")
            addkeyword('MONITOR', args=[1])
        addcomment("the minimum cross section (barns) for inclusion in pathways analysis")
        addkeyword('XSTHRESHOLD', args=[self._xsthreshold])
        if not self._ignorecollapse:
            if self._group != 0:
                addcomment("perform collapse")
                addkeyword('GETXS', args=[-1 if self._binaryxs and not self._useeaf else 1, self._group])
            else:
                addcomment("don't do collapse, just read the existing file")
                addkeyword('GETXS', args=[0])
        if not self._ignorecondense:
            addcomment("get decay data")
            addkeyword('GETDECAY', args=[1 if self._condense else 0])
        if self._loglevel != LOG_SEVERITY_WARNING:
            addcomment("enable logging at level {}".format(self._loglevel))
            addkeyword('LOGLEVEL', args=[self._loglevel])
        if self._approxgamma:
            addcomment("approximate spectra when not available")
            addkeyword('SPEK')
        if self._ignoreuncert:
            addcomment("ignore uncertainties")
            addkeyword('NOERROR')
        if self._projectile != PROJECTILE_NEUTRON:
            addcomment("set projectile (n=1, d=2, p=3, a=4, g=5)")
            addkeyword('PROJ', args=[self._projectile])
        addcomment("end control")
        addkeyword('FISPACT')
        addkeyword('*', args=[self.name])
        addnewline()
        addcomment("INITIALIZATION PHASE")
        if self._outputhalflife:
            addcomment("output half life values")
            addkeyword('HALF')
        if self._outputhazards:
            addcomment("output ingestion and inhalation values")
            addkeyword('HAZARDS')
        if self._clearancedata:
            addcomment("include clearance data of radionuclides to be input")
            addkeyword('CLEAR')
        if self._inventoryismass and not self._inventoryisfuel:
            if self._inventorymass.totalMass > 0.0:
                addcomment("set the target via MASS")
                addkeyword(str(self._inventorymass))
        if self._inventoryisfuel and not self._inventoryismass:
            if self._density > 0.0:
                addcomment("set the target via FUEL")
                addkeyword(str(self._inventoryfuel))  
        if self._density > 0.0:
            addcomment("set the target density")
            addkeyword('DENSITY', args=[self._density])
        if self._atomsthreshold > 0.0:
            addcomment("set the threshold for atoms in the inventory")
            addkeyword('MIND', args=[self._atomsthreshold])
        if self._initialinventory:
            addcomment("output the initial inventory")
            addkeyword('ATOMS')
        addnewline()
        addcomment("INVENTORY PHASE")
        if len(self._irradschedule) > 0:
            addcomment("irradiation schedule")
            for time, fluxamp in self._irradschedule:
                addkeyword('FLUX', args=[f"{fluxamp:.{self._prec}E}"])
                addkeyword('TIME', args=[f"{time:.{self._prec}E}", 'SECS'])
                addkeyword('ATOMS')
            addcomment("end of irradiation")
            addkeyword('FLUX', args=[0.0])
            addkeyword('ZERO')
            for time in self._coolingschedule:
                addkeyword('TIME', args=[f"{time:.{self._prec}E}", 'SECS'])
                addkeyword('ATOMS')
            addcomment("end of cooling")
        addnewline()
        addcomment("end of input")
        addkeyword('END')
        addkeyword('*', args=['end'])
        for line in inputdata:
            f.write("{}\n".format(line))
def _serialize ( self , f ) : inputdata = [ ] def addnewline ( ) : inputdata . append ( "" ) def addcomment ( comment ) : inputdata . append ( f"{COMMENT_START} {comment} {COMMENT_END}" ) def addkeyword ( keyword , args = [ ] ) : strargs = ' ' . join ( [ str ( a ) for a in args ] ) inputdata . append ( f"{keyword} {strargs}" ) addcomment ( "CONTROL PHASE" ) if self . _json : addcomment ( "enable JSON output" ) addkeyword ( 'JSON' ) if self . _overwrite : addcomment ( "overwrite existing output files of same name" ) addkeyword ( 'CLOBBER' ) if self . _readgammagroup : addcomment ( "read gamma groups from file, specify ggbins in files file" ) addkeyword ( 'READGG' ) if self . _readspontfission : addcomment ( "read spontaneous fission from file, specify sf_endf in files file" ) addkeyword ( 'READSF' ) if self . _useeaf : addcomment ( "use EAF nuclear data libraries" ) addkeyword ( 'LIBVERSION' , args = [ 0 ] ) if self . _usecumfissyield : addcomment ( "use cumulative fission yield data mt=459 instead of mt=454" ) addkeyword ( 'CUMFYLD' ) if self . _enablemonitor : addcomment ( "monitor FISPACT-II progress" ) addkeyword ( 'MONITOR' , args = [ 1 ] ) addcomment ( "the minimum cross section (barns) for inclusion in pathways analysis" ) addkeyword ( 'XSTHRESHOLD' , args = [ self . _xsthreshold ] ) if not self . _ignorecollapse : if self . _group != 0 : addcomment ( "perform collapse" ) addkeyword ( 'GETXS' , args = [ - 1 if self . _binaryxs and not self . _useeaf else 1 , self . _group ] ) else : addcomment ( "don't do collapse, just read the existing file" ) addkeyword ( 'GETXS' , args = [ 0 ] ) if not self . _ignorecondense : addcomment ( "get decay data" ) addkeyword ( 'GETDECAY' , args = [ 1 if self . _condense else 0 ] ) if self . _loglevel != LOG_SEVERITY_WARNING : addcomment ( "enable logging at level {}" . format ( self . _loglevel ) ) addkeyword ( 'LOGLEVEL' , args = [ self . _loglevel ] ) if self . _approxgamma : addcomment ( "approximate spectra when not available" ) addkeyword ( 'SPEK' ) if self . _ignoreuncert : addcomment ( "ignore uncertainties" ) addkeyword ( 'NOERROR' ) if self . _projectile != PROJECTILE_NEUTRON : addcomment ( "set projectile (n=1, d=2, p=3, a=4, g=5)" ) addkeyword ( 'PROJ' , args = [ self . _projectile ] ) addcomment ( "end control" ) addkeyword ( 'FISPACT' ) addkeyword ( '*' , args = [ self . name ] ) addnewline ( ) addcomment ( "INITIALIZATION PHASE" ) if self . _outputhalflife : addcomment ( "output half life values" ) addkeyword ( 'HALF' ) if self . _outputhazards : addcomment ( "output ingestion and inhalation values" ) addkeyword ( 'HAZARDS' ) if self . _clearancedata : addcomment ( "include clearance data of radionuclides to be input" ) addkeyword ( 'CLEAR' ) if self . _inventoryismass and not self . _inventoryisfuel : if self . _inventorymass . totalMass > 0.0 : addcomment ( "set the target via MASS" ) addkeyword ( str ( self . _inventorymass ) ) if self . _inventoryisfuel and not self . _inventoryismass : if self . _density > 0.0 : addcomment ( "set the target via FUEL" ) addkeyword ( str ( self . _inventoryfuel ) ) if self . _density > 0.0 : addcomment ( "set the target density" ) addkeyword ( 'DENSITY' , args = [ self . _density ] ) if self . _atomsthreshold > 0.0 : addcomment ( "set the threshold for atoms in the inventory" ) addkeyword ( 'MIND' , args = [ self . _atomsthreshold ] ) if self . _initialinventory : addcomment ( "output the initial inventory" ) addkeyword ( 'ATOMS' ) addnewline ( ) addcomment ( "INVENTORY PHASE" ) if len ( self . _irradschedule ) > 0 : addcomment ( "irradiation schedule" ) for time , fluxamp in self . _irradschedule : addkeyword ( 'FLUX' , args = [ f"{fluxamp:.{self._prec}E}" ] ) addkeyword ( 'TIME' , args = [ f"{time:.{self._prec}E}" , 'SECS' ] ) addkeyword ( 'ATOMS' ) addcomment ( "end of irradiation" ) addkeyword ( 'FLUX' , args = [ 0.0 ] ) addkeyword ( 'ZERO' ) for time in self . _coolingschedule : addkeyword ( 'TIME' , args = [ f"{time:.{self._prec}E}" , 'SECS' ] ) addkeyword ( 'ATOMS' ) addcomment ( "end of cooling" ) addnewline ( ) addcomment ( "end of input" ) addkeyword ( 'END' ) addkeyword ( '*' , args = [ 'end' ] ) for line in inputdata : f . write ( "{}\n" . format ( line ) )
The serialization method
f: file object
The serialization method f : file object
"""
            The serialization method
            f: file object
        """ # control keywords # end control phase # initial phase # inventory phase # end file
self
f