Пример #1
0
def getAtoms(formula):
    formula = validateStr(formula)
    if '))' in formula:
        return False
    atoms = []
    numAtoms = []
    while (len(formula) > 0):
        #First computes the molecular weight of all parenthetical formulas from left to right
        while (len(re.findall('\(\w*\)[0-9]+', formula)) != 0):
            parenthetical = re.findall('\(\w*\)[0-9]+', formula)
            for i in range(0, len(parenthetical)):
                parenMult1 = re.findall('\)[0-9]+', parenthetical[i])
                #                print "ParenMult1", parenMult1, parenthetical[i]
                parenMult2 = re.findall('[0-9]+', parenMult1[0])
                #                print "ParentMult2", parenMult2
                segments = parseFormula(parenthetical[i])
                #                print "Segments", segments
                for i in range(0, len(segments)):
                    multFactor = re.findall('[0-9]+', segments[i])
                    subSegs = re.findall('[A-Z][a-z]*', segments[i])
                    #                    print "MultiFactor: ", multFactor
                    #                    print "Subsegs: ", subSegs
                    for seg in subSegs:
                        atoms.append(seg)
                        if len(parenMult2) > 0:
                            coreNum = int(parenMult2[0])
                        else:
                            coreNum = 1
                        if len(multFactor) > 0:
                            multNum = int(multFactor[0])
                            numAtoms.append(coreNum * multNum)
                        else:
                            numAtoms.append(coreNum)

            formula = re.sub('\(\w*\)[0-9]+', '', formula)
        #Sums nonparenthetical molecular weights when all parenthetical molecular weights have been summed
        segments = parseFormula(formula)
        #        print "Segments", segments
        for i in range(0, len(segments)):
            multFactor = re.findall('[0-9]+', segments[i])
            subSegs = re.findall('[A-Z][a-z]*', segments[i])
            #            print "MultiFactor: ", multFactor
            #            print "Subsegs: ", subSegs
            for seg in subSegs:
                atoms.append(seg)
                if len(multFactor) > 0:
                    multNum = int(multFactor[0])
                    numAtoms.append(1 * multNum)
                else:
                    numAtoms.append(1)

        formula = re.sub(formula, '', formula)

    elemOk = True
    for elem in atoms:
        if not elemDict.has_key(elem):
            elemOk = False
            return elemOk, atoms, numAtoms

    return elemOk, atoms, numAtoms
Пример #2
0
 def plotElementParameter(self, elemKey, plotType):#plot electronic affinities
     paramVals = []
     elemList = []
     try:
         if elemKey == 'ionenergy':
             for elem in TableofElementsList:
                 if elemDict.has_key(elem):
                     elemList.append(elem)
                     paramVals.append(elemDict[elem].__dict__[elemKey][0])
         else:
             for elem in TableofElementsList:
                 if elemDict.has_key(elem):
                     elemList.append(elem)
                     paramVals.append(elemDict[elem].__dict__[elemKey])
         self.addPlot(paramVals, elemList, plotType, 'Element #', 'Parameter Value')
     except:
         print elemDict[elem].name, elemDict[elem].ionenergy
         raise
Пример #3
0
 def plotElementParameter(self, elemKey,
                          plotType):  #plot electronic affinities
     paramVals = []
     elemList = []
     try:
         if elemKey == 'ionenergy':
             for elem in TableofElementsList:
                 if elemDict.has_key(elem):
                     elemList.append(elem)
                     paramVals.append(elemDict[elem].__dict__[elemKey][0])
         else:
             for elem in TableofElementsList:
                 if elemDict.has_key(elem):
                     elemList.append(elem)
                     paramVals.append(elemDict[elem].__dict__[elemKey])
         self.addPlot(paramVals, elemList, plotType, 'Element #',
                      'Parameter Value')
     except:
         print elemDict[elem].name, elemDict[elem].ionenergy
         raise
Пример #4
0
def isoCalc(elemList, elemComp, charge = 0):
    '''
    interface to mercury calc to get user defined isotope patterns
    Limiting the maximum isotopes to be considered to 5
    '''
    try:

        if len(elemList)== 0 or len(elemComp) == 0:
            return False

        if len(elemList) != len(elemComp):
            return False

        maxIsotopes = 7
        numElements = len(elemList)
        numIsotopes = N.zeros(maxIsotopes, dtype = N.int)

        elemMasses = N.zeros((numElements, maxIsotopes))
        elemAbundances = N.zeros((numElements, maxIsotopes))

        for i,elem in enumerate(elemList):
            if elemDict.has_key(elem):
                tempIsos = elemDict[elem].isotopes
                tempOrder = []
                tempOrder = N.array(tempOrder)
                orderInd = tempOrder.argsort()
    #            print orderInd
    #            tempIsos = tempIsos[maxOrder]
                maxIso = len(tempIsos)
                if maxIso > maxIsotopes:
                    maxIso = maxIsotopes
                numIsotopes[i] = int(maxIso)
                for j in xrange(maxIso):
                    #each iso is a tuple that is the (nominal mass, isotope mass, isotope abundance)
                    iso = tempIsos[j]
    #                print elem, iso[1], iso[2]
                    elemMasses[i][j]=iso[1]
                    elemAbundances[i][j]=iso[2]
    except:
        return [False, None]
#    print elemList
#    print elemMasses
#    print elemAbundances
#    print numIsotopes

    if libmercuryOk:
        print "Libmercury OK"
        mercAns = LMI.mercury(elemComp, numIsotopes, elemMasses, elemAbundances, charge, 1e-3)
#        mercAns = LMI.mercury(modelComp, numIsotopes, elemMasses, elemAbundances, charge, 1e-3)
        if mercAns[0] == 0:
            return [True, scaleIsos(mercAns[1])]
    else:
        return [False, None]
Пример #5
0
def getMass(x):
    atom=re.findall('[A-Z][a-z]*',x)
    number=re.findall('[0-9]+', x)
    if len(number) == 0:
        multiplier = 1
    else:
        multiplier = float(number[0])
    if elemDict.has_key(atom[0]):
#        atomic_mass=TableofElements[atom[0]]
#        atomic_mass=elemDict[atom[0]].mass#TableofElements[atom[0]]
        atomic_mass=elemDict[atom[0]].isotopes[0][1]#get monoisotopic mass
    else:
        atomic_mass = 0.0

    return (atomic_mass*multiplier)
Пример #6
0
def getMass(x):
    atom = re.findall('[A-Z][a-z]*', x)
    number = re.findall('[0-9]+', x)
    if len(number) == 0:
        multiplier = 1
    else:
        multiplier = float(number[0])
    if elemDict.has_key(atom[0]):
        #        atomic_mass=TableofElements[atom[0]]
        #        atomic_mass=elemDict[atom[0]].mass#TableofElements[atom[0]]
        atomic_mass = elemDict[atom[0]].isotopes[0][1]  #get monoisotopic mass
    else:
        atomic_mass = 0.0

    return (atomic_mass * multiplier)
Пример #7
0
    def mousePressEvent(self, event):
        '''
        The SVG coordinates are reversed in the y dimension so we need to subtract
        '''
#        print event.button(), event.x(), self.origH-event.y()
        xP = N.round(event.x()/self.xMod)#event.x()+
        yP = N.round(self.origH-(event.y()/self.yMod))
#        print xP, yP, event.x(), self.origH-(event.y())
        crit = (xP >= self.xLo) & (xP <= self.xHi) & (yP >= self.yLo) & (yP <= self.yHi)
        Ans = N.where(crit)[0]
        if len(Ans)>0:
            curAtom = self.elems[Ans]
#            print curAtom
            if elemDict.has_key(curAtom):
                elem = elemDict[curAtom]
                print elem.name, elem.mass
                self.emit(QtCore.SIGNAL("elementSelected(PyQt_PyObject)"),elem)
Пример #8
0
 def mousePressEvent(self, event):
     '''
     The SVG coordinates are reversed in the y dimension so we need to subtract
     '''
     #        print event.button(), event.x(), self.origH-event.y()
     xP = N.round(event.x() / self.xMod)  #event.x()+
     yP = N.round(self.origH - (event.y() / self.yMod))
     #        print xP, yP, event.x(), self.origH-(event.y())
     crit = (xP >= self.xLo) & (xP <= self.xHi) & (yP >= self.yLo) & (
         yP <= self.yHi)
     Ans = N.where(crit)[0]
     if len(Ans) > 0:
         curAtom = self.elems[Ans]
         #            print curAtom
         if elemDict.has_key(curAtom):
             elem = elemDict[curAtom]
             print elem.name, elem.mass
             self.emit(QtCore.SIGNAL("elementSelected(PyQt_PyObject)"),
                       elem)
Пример #9
0
def getAtoms(formula):
    formula = validateStr(formula)
    if '))' in formula:
        return False
    atoms = []
    numAtoms = []
    while (len(formula)>0):
        #First computes the molecular weight of all parenthetical formulas from left to right
        while (len(re.findall('\(\w*\)[0-9]+', formula))!=0):
            parenthetical=re.findall('\(\w*\)[0-9]+',formula)
            for i in range(0,len(parenthetical)):
                parenMult1 = re.findall('\)[0-9]+', parenthetical[i])
#                print "ParenMult1", parenMult1, parenthetical[i]
                parenMult2 = re.findall('[0-9]+', parenMult1[0])
#                print "ParentMult2", parenMult2
                segments =parseFormula(parenthetical[i])
#                print "Segments", segments
                for i in range(0, len(segments)):
                    multFactor = re.findall('[0-9]+', segments[i])
                    subSegs = re.findall('[A-Z][a-z]*',segments[i])
#                    print "MultiFactor: ", multFactor
#                    print "Subsegs: ", subSegs
                    for seg in subSegs:
                        atoms.append(seg)
                        if len(parenMult2)>0:
                            coreNum = int(parenMult2[0])
                        else:
                            coreNum = 1
                        if len(multFactor)>0:
                            multNum = int(multFactor[0])
                            numAtoms.append(coreNum*multNum)
                        else:
                            numAtoms.append(coreNum)

            formula=re.sub('\(\w*\)[0-9]+', '', formula)
        #Sums nonparenthetical molecular weights when all parenthetical molecular weights have been summed
        segments = parseFormula(formula)
#        print "Segments", segments
        for i in range(0, len(segments)):
            multFactor = re.findall('[0-9]+', segments[i])
            subSegs = re.findall('[A-Z][a-z]*',segments[i])
#            print "MultiFactor: ", multFactor
#            print "Subsegs: ", subSegs
            for seg in subSegs:
                atoms.append(seg)
                if len(multFactor)>0:
                    multNum = int(multFactor[0])
                    numAtoms.append(1*multNum)
                else:
                    numAtoms.append(1)

        formula=re.sub(formula, '', formula)

    elemOk = True
    for elem in atoms:
        if not elemDict.has_key(elem):
            elemOk = False
            return elemOk, atoms, numAtoms


    return elemOk, atoms, numAtoms