Ejemplo n.º 1
0
    def unreadZA(self, ZA, suffix=""):
        """Removes self's reference to ZA, but does not delete ZA's directory from self's work 
        directory (i.e., if process( ) is called this ZA will be processed). Also see removeZA."""

        sZA = endlmisc.strZASuffix(ZA, suffix)
        for i in range(len(self.zas)):
            if (self.zas[i].sZA == sZA):
                del self.zas[i]
                return
        endlmisc.printWarning("Warning in endlProject.unreadZA: za = " + sZA +
                              " not in project")
Ejemplo n.º 2
0
    def unread(self, target):
        """Removes self's reference to target, but does not delete target's directory from self's work 
        directory (i.e., if process( ) is called this target will be processed). Also see remove."""

        for i in range(len(self.zas)):
            if (self.zas[i] == target):
                del self.zas[i]
                return
        endlmisc.printWarning(
            "Warning in endlProject.unread: target = %s is not a part of project"
            % target)
Ejemplo n.º 3
0
    def removeZA(self, ZA, suffix=""):
        """Removes self's reference to ZA and deletes ZA's directory from self's work 
        directory (i.e., if process( ) is called this ZA will not be processed).  Also see unreadZA."""

        sZA = endlmisc.strZASuffix(ZA, suffix)
        for i in range(len(self.zas)):
            if (self.zas[i].sZA == sZA):
                if (self.zas[i].workDir != None):
                    os.system("rm -rf " + self.zas[i].workDir)
                del self.zas[i]
                return
        endlmisc.printWarning(
            "Warning in endlProject.removeZA: za = %s not in project" % sZA)
Ejemplo n.º 4
0
    def remove(self, target):
        """Removes self's reference to target and deletes target's directory from self's work 
        directory (i.e., if process( ) is called this target will not be processed).  Also see unread."""

        for i in range(len(self.zas)):
            if (self.zas[i] == target):
                if (self.zas[i].workDir != None):
                    os.system("rm -rf " + self.zas[i].workDir)
                del self.zas[i]
                return
        endlmisc.printWarning(
            "Warning in endlProject.remove: target = %s is not a part of project"
            % target.name)
Ejemplo n.º 5
0
    def setDate( self, date = None ) :
        "Sets self's data and self's header date value to data. If date is None then today's date is used."

        if ( date is None ) :
            date = time.localtime( time.time( ) )
            date = 10000 * ( date[0] - 2000 ) + 100 * date[1] + date[2]
        if ( type( date ) == type( "" ) ) :
            try :
                date = int( date )
            except :
                endlmisc.printWarning( "date cannot be converted to an integer" )
                raise ValueError
        if ( type( date ) == type( 1 ) ) and ( date > 0 ) and ( date < 1000000 ) :
            self.h[0] = "%-25s%6.6d%s" % ( self.h[0][0:25], date, self.h[0][31:] )
        else :
            raise Exception( "\nError in setDate: date must be an integer, or a string convertible to an \ninteger, in the range [1, 999999]" )
Ejemplo n.º 6
0
    def readZA(self, ZA, database=None, suffix=""):
        """Reads in ZA from database, creating a new endlZA in self.  If database = None, the database from self is used. Also see addZA."""

        sZA = endlmisc.strZASuffix(ZA, suffix)
        for z in self.zas:
            if (z.sZA == sZA):
                endlmisc.printWarning(
                    "za = %s already present in this endlProject" % sZA)
                return z
        if (database == None): database = self.database
        z = endlZA.endlZA(ZA,
                          self.yi,
                          database=database,
                          workDir=self.workDir,
                          suffix=suffix,
                          readOnly=self.readOnly,
                          bdflsFile=self.bdflsFile)
        self.zas.append(z)
        return z
Ejemplo n.º 7
0
def residualZA_yos_Q( yi_, ZA_, C, targetELevel = 0., X4 = 0, specialCases = 1, printQWarning = True, bdflsFile = None ) :
    """Returns a tuple containing the residual ZA', yos and Q for reaction of type 
    C involving incident particle yi and target ZA.  yos is a list.  For example,
    the reation, ZA + yi -> ZA' + yo_1 + yo_2 + ... + yo_n + Q,
    would return ( ZA', [ yo_1, yo_2, ..., yo_n ], Q )."""

    if( bdflsFile is None ) :
        import bdfls
        bdflsFile = bdfls.getDefaultBdfls( )
    import endlmisc
    ZA, Suffix = endlmisc.intZASuffix( ZA_ )
    if( ( ( ZA % 1000 ) / 100 ) > 7 ) : ZA = ZA % 100 + 1000 * ( ZA / 1000 )
    yi = endlmisc.incidentParticleTags( yi_ )[0]
    if( ( ( yi == 3 ) and ( ZA == 1003 ) and ( C == 30 ) ) or       # Added kludge to handle t(d,g n)He reaction.
        ( ( yi == 4 ) and ( ZA == 1002 ) and ( C == 30 ) ) ) :
        yos = [ 7, 1 ]
    else :
        yos = endl_C.endl_C_yoInfo( C )
    if ( yos is None ) or ( yos == () ) : return (None, ( ), None) # No such C-value or C-value does is not a reaction (e.g., C=1).
    if ( yos[0] == -1 ) : return ( ZA, ( yi, ), None )            # yo unknown.
    if ( yos[0] == -2 ) : return ( ZA, ( yi, ), 0. )              # yo = yi.
    if ( yos[0] == -3 ) : return ( None, ( -3, ), None )          # Fission
    if ( yos[0] == -4 ) : return ( None, ( -4, yos[1] ), None )  # Xyo
    if ( ZA >= 99000 ) and ( ZA <= 99200 ) : return( None, yos, None )
    Zr, Ar = ZandAFromZA( ZA )
    Z_A = ZandAFromZA( yoToZA_forNuclei( ZAToYo( yi ) ) )             # yi's Z and A.
    Zr += Z_A[0]
    if( Ar != 0 ) : Ar += Z_A[1]
    ZAr = ZA + yoToZA_forNuclei( ZAToYo( yi ) )                   # Add yi's ZA to ZAr.
    for yo in yos :                                         # Subtract yos' Z, A and ZA from ZAr.
        if( yo in [ 7, 8, 9 ] ) : continue
        yo_ = yo
        if ( yo < 1001 ) : yo_ = yoToZA_forNuclei( yo )
        Z_A = ZandAFromZA( yo_ )
        Zr -= Z_A[0]
        if( Ar != 0 ) :
            Ar -= Z_A[1]
            ZAr -= yo_
    if( Zr < 0 ) :                                          # Check all ok.
        raise Exception( "\nError in residualZA_yos_Q: bad C-value = %d for ZA = %d and yi = %d" % ( C, ZA, yi ) )
    if( specialCases and ( ZAr == 4008 ) ) :        # Special case for Be8 ->  2 He (e.g., n + Be9  -> 2 n + (Be8 ->  2 He)).
        yos = yos + ( 2004, )
        Zr, Ar, ZAr = 2, 4, 2004
    if( Ar < 0 ) : Ar = 0
    if( Ar == 0 ) : return( 1000 * Zr, yos, None )
    Remove_yi = True
    yos_ = []
    for yo in yos :                                         # To make math better, do not add and then subtract when yo = yi.
        try :
            yo_ = ZAToYo( yo )
        except :
            yo_ = yo
        if( Remove_yi and ( yo_ == yi ) ) :
            Remove_yi = False
        else :
            if ( yo != 0 ) : yos_.append( yo )
    if ( ZAr == ZA ) :
        ZAyos = 0
        for yo in yos :
            if( yo < 1000 ) :
                ZAyos += yoToZA_forNuclei( yo )
            else :
                ZAyos += yo
        q = bdflsFile.mass( yi )
        for yo in yos : q -= bdflsFile.mass( yo )
        if ( len( yos_ ) == 0 ) or ( ZAyos == yoToZA_forNuclei( yi ) ) :
            q = ( bdflsFile.constant( 4 ) * q )
            q += targetELevel - X4
            return ( ZAr, yos, q )
        endlmisc.printWarning( "Printing yo list")
        for yo in yos_ : endlmisc.printWarning( `yo` )
        endlmisc.printWarning( "\n" )
        raise Exception( "Error in residualZA_yos_Q: ZAr == ZA, but yo list not empty" )
    q = 0.
    if( Remove_yi ) : q += bdflsFile.mass( yi )
    for yo in yos_ : q -= bdflsFile.mass( yo )
    ZAm = bdflsFile.mass( ZA )
    if ( ZAm is None ) :
        if( printQWarning ) : endlmisc.printWarning( "Warning in residualZA_yos_Q: target ZA = %d not in bdfls file (yi = %d, ZA = %d, C = %d)" % \
            ( ZA, yi, ZA, C ) )
        q = None
    else :
        m = bdflsFile.mass( ZAr )                              # Mass of residual.
        if ( m is None ) : 
            if( printQWarning ) : endlmisc.printWarning( "Warning in residualZA_yos_Q: could not calculate Q as residual ZA = %d" % ZAr + 
                " not in bdfls file (yi = %d, ZA = %d, C = %d)" % ( yi, ZA, C ) )
            q = None
        else :
            q += bdflsFile.mass( ZA ) - m
            q *= bdflsFile.constant( 4 )                       # Convert AMU to MeVs.
    if q is not None : q += targetELevel - X4
    return ( ZAr, yos, q )
Ejemplo n.º 8
0
    def __init__(self,
                 database=None,
                 projectile=None,
                 yi=None,
                 workDir=None,
                 delWorkDirWhenDone=0,
                 readOnly=0,
                 release='current',
                 bdflsFile=None,
                 cleanWorkDirOfZAs=False):
        """Creates a new endlProject with database as the default database to use when reading ZAs. If bdflsFile is not None, then
        it is the bdfls class instance associated with self."""

        if (yi != None):
            endlmisc.printWarning(
                'Argument "yi" for Constructor of endlProject is deprecated, please use argument "projectile" instead.'
            )
            if (projectile != None):
                raise Exception(
                    'Both "yi" and "projectile" argument specified, only use "projectile".'
                )
            projectile = yi
        if (database == None): database = fudgeDefaults.ENDL_DEFAULT_DATABASE
        if (bdflsFile == None):
            bdflsFileName = None
            if (os.path.exists('bdfls')):
                bdflsFileName = './bdfls'  # Else logic handled below.
        else:
            bdflsFileName = bdflsFile.Source
        self.readOnly = readOnly or fudgeParameters.ReadOnly
        self.delWorkDirWhenDone = delWorkDirWhenDone
        dbInDatabaseName, yiInDatabaseName = os.path.split(database)
        if (yiInDatabaseName in [
                "yi01", "yi02", "yi03", "yi04", "yi05", "yi06", "yi07", "yi09"
        ]):
            database = dbInDatabaseName
            if ((projectile != None)
                    and (yiInDatabaseName !=
                         endlmisc.incidentParticleTags(projectile)[1])):
                raise Exception(
                    "\nError in endlProject.__init__: yi in database name and yi differ"
                )
            projectile = endlmisc.incidentParticleTags(yiInDatabaseName)[5]
        else:
            if (projectile == None): projectile = 'n'
        self.yiTags = endlmisc.incidentParticleTags(projectile)
        self.name = self.yiTags[5]
        (self.database,
         Status) = endlmisc.getFullPath(os.path.join(database, 'ascii'),
                                        fudgeDefaults.ENDL_DATABASE_DIR)
        if (Status == 0):
            (self.database,
             Status) = endlmisc.getFullPath(database,
                                            fudgeDefaults.ENDL_DATABASE_DIR)
        if (Status == 0):            ( self.database, Status ) = endlmisc.getFullPath( os.path.join( database, 'ascii' ), \
os.path.join( fudgeDefaults.TRANSLATED_DATABASE_DIR, release ) )
        if (Status == 0):  # File or directory does not exist
            if (self.yiTags[0] not in [1, 2, 3, 4, 5, 6, 7, 9]):
                raise Exception(
                    "\nError in endlProject.__init__: invalid projectile = %s"
                    % self.name)
            self.database = None
            self.yi = self.yiTags[0]
            if (fudgeParameters.VerboseMode > 0): print self.yiTags[1]
        elif (Status == 1):
            raise Exception(
                "\nError in endlProject.__init__: database is not a directory")
        else:
            self.database = os.path.join(self.database, self.yiTags[1])
            if (not os.path.exists(self.database)):
                self.database = None
            else:
                if (bdflsFileName == None):
                    bdflsFileName = os.path.join(
                        os.path.dirname(self.database).split('/ascii')[0],
                        'bdfls')
                    if (not os.path.exists(bdflsFileName)):
                        bdflsFileName = None
            self.yi = self.yiTags[0]
        self.bdflsFile = bdflsFile
        if (bdflsFile == None):
            self.bdflsFile = bdfls.getBdflsFile(
                name=bdflsFileName
            )  # endlProject relies on bdfls class to search BDFLSPATH
        self.bdflsFileName = endlmisc.getAbsPath_withDefaultDBCheck(
            self.bdflsFile.Source)[
                0]  # and "/usr/gapps/data/nuclear/bdfls", in that order,
        self.mass = 0  # for the bdfls file.
        yoZA = endl2.yoToZA(self.yiTags[0])
        if (self.yiTags[0] != 7): self.mass = self.bdflsFile.mass(abs(yoZA))
        if (yoZA < 0): yoZA = 0
        self.Z, self.A = endl2.ZandAFromZA(yoZA)
        if (fudgeParameters.VerboseMode > 0):
            print 'Using bdfls', self.bdflsFileName
            print self.database
        gappsDir = os.path.realpath('/usr/gapps/data/nuclear')
        if self.readOnly:
            self.workDir = None
        else:
            if (workDir == ''): workDir = self.database
            if (workDir == None):
                self.workDir = tempfile.mkdtemp()
            else:
                self.workDir = workDir
            if (gappsDir == os.path.realpath(self.workDir)[:len(gappsDir)]):
                if ('development' not in os.path.realpath(self.workDir)):
                    raise Exception(
                        'cannot make workDir point to /usr/gapps/data/nuclear, except in a development sub-directory'
                    )
            if (not os.path.isdir(self.workDir)): os.makedirs(self.workDir)
            self.workDir = endlmisc.appendyiDirIfNeeded(
                self.workDir, self.yiTags[0])
            if (not os.path.isdir(self.workDir)): os.makedirs(self.workDir)
        if (not (self.workDir is None) and cleanWorkDirOfZAs):
            os.system('rm -rf %s/za[0-9][0-9][0-9][0-9][0-9][0-9]*' %
                      self.workDir)
        self.zas = []
        self.documentation = None
        if (self.database != None):
            documentationFileName = os.path.join(self.database,
                                                 'documentation.txt')
            if (os.path.exists(documentationFileName)):
                self.documentation = fudgeDocumentationFile.fudgeDocumentationFile(
                    documentationFileName)
        endlProjectList.append(self)
Ejemplo n.º 9
0
    def __init__(self,
                 f,
                 I_,
                 yo,
                 C,
                 I,
                 S,
                 h,
                 points,
                 i0=0,
                 i1=1,
                 i2=None,
                 i3=None,
                 bdflsFile=None):
        """For internal use only."""

        if (I != I_):
            raise Exception("\nError in endlI%d.__init__: I = %d != %d" %
                            (I_, I, I_))
        if (bdflsFile == None): bdflsFile = bdfls.getDefaultBdfls()
        self.bdflsFile = bdflsFile
        self.columns = endlmisc.getNumberOfColumns_(I, "endlNd.__init__")
        self.yo = yo
        self.C = C
        self.I = I
        self.S = S
        self.format = 12
        if (f == None):  # Designer data.
            self.h = copy.deepcopy(h)
            data = points
            self.designerData = 1
        elif (type(f) == file
              ):  # Otherwise, data must be in an endl formatted file.
            self.h = [f.readline(), ""]
            if (self.h[0] == ""): return
            self.h[1] = f.readline()
            if (self.h[1] == ""):
                raise Exception(
                    "\nError in endlNd.__init__: end-of-file while reading from %s"
                    % f.name)
            data = readNdEndlData(f, i0, i1, i2, i3)  # File data.
            self.designerData = 0
        else:
            raise Exception(
                "\nError from endlNd.__init__: invalid type = %s for f" %
                type(f))
        if (not ((self.h[0] == "\n") and (C == 1) and (I == 0))):
            if (self.yo != int(self.h[0][9:12])):
                raise Exception(
                    "\nError in endlNd.__init__: yo in header differs from requested yo\n"
                    + ` self.h `)
            if (self.C != int(self.h[1][:2])):
                raise Exception(
                    "\nError in endlNd.__init__: C in header differs from requested C\n"
                    + ` self.h `)
            if (self.I != int(self.h[1][2:5])):
                raise Exception(
                    "\nError in endlNd.__init__: I in header differs from requested I\n"
                    + ` self.h `)
            if (self.S != int(self.h[1][5:8])):
                raise Exception(
                    "\nError in endlNd.__init__: S in header differs from requested S\n"
                    + ` self.h `)
            try:
                self.ZA = int(self.h[0][:6])
                self.yi = int(self.h[0][6:9])
                self.Mass = endlmisc.headerString2FunkyDouble(
                    self.h[0], 13, "endlNd.__init__")
                if (self.h[0][31] == ' '):
                    self.ENDLInterpolation = 0
                else:
                    self.ENDLInterpolation = int(self.h[0][31])
                self.format = int(self.h[0][32:34])
                self.ELevel = endlmisc.headerString2FunkyDouble(
                    self.h[0], 35, "endlNd.__init__")
                self.Halflife = endlmisc.headerString2FunkyDouble(
                    self.h[0], 47, "endlNd.__init__")
                self.Temperature = endlmisc.headerString2FunkyDouble(
                    self.h[0], 59, "endlNd.__init__")
                self.Q = 0.
            except:
                endlmisc.printWarning(self.h[0])
                endlmisc.printWarning(self.h[1])
                raise
            if (len(self.h[1]) >= 20):
                self.Q = endlmisc.headerString2FunkyDouble(
                    self.h[1], 9, "endlNd.__init__")
            self.X1 = 0.
            if (len(self.h[1]) >= 32):
                self.X1 = endlmisc.headerString2FunkyDouble(
                    self.h[1], 21, "endlNd.__init__")
            self.X2 = 0.
            if (len(self.h[1]) >= 44):
                self.X2 = endlmisc.headerString2FunkyDouble(
                    self.h[1], 33, "endlNd.__init__")
            self.X3 = 0.
            if (len(self.h[1]) >= 56):
                self.X3 = endlmisc.headerString2FunkyDouble(
                    self.h[1], 45, "endlNd.__init__")
            self.X4 = 0.
            if (len(self.h[1]) >= 68):
                self.X4 = endlmisc.headerString2FunkyDouble(
                    self.h[1], 57, "endlNd.__init__")
        else:
            if (not (self.designerData)):
                endlmisc.printWarning(
                    "Warning: using old style C = 1, I = 0 header file")
            self.ZA = None
            self.yi = None
            self.yo = 0
            self.C = 1
            self.I = 0
            self.S = 0
            self.Mass = None
            self.ENDLInterpolation = 0
            self.ELevel = None
            self.Halflife = None
            self.Temperature = None
            self.Q = 0.
            self.X1 = 0.
            self.X2 = 0.
            self.X3 = 0.
            self.X4 = 0.
        self.set(data,
                 checkDataType=0,
                 interpolation=endlmisc.endlToFudgeInterpolation(
                     self.ENDLInterpolation))
Ejemplo n.º 10
0
    def setLifetime(self, Halflife):
        "Deprecated method. Use setHalflife instead."

        endlmisc.printWarning(
            'setLifetime is a deprecated method. Use setHalflife instead.')
        self.setHalflife(Halflife)
Ejemplo n.º 11
0
    def getLifetime(self):
        "Deprecated method. Use getHalflife instead."

        endlmisc.printWarning(
            'getLifetime is a deprecated method. Use getHalflife instead.')
        return (self.getHalflife())