示例#1
0
文件: compound.py 项目: FHe/tdl
    def set(self,formula):
        """
        This methods appends to or modifies the existing formula

        Paramters:
        ----------
        * formula is a dictionary: {'El':nu}
          where 'El' is the atomic symbol or Z (integer)
          and nu is the stoichiometric coefficient

          Or formula is a string: 'Si O2' (see parse_formula)

          Note nu = moles_of_El / mole_of_component
          therefore nu may be fractional and are converted to
          float even if passed as int
        
        """
        #if type(formula) == types.StringType:
        #    formula = {formula:1.}
        if type(formula) == types.StringType:
            formula = parse_formula(formula)
            if formula == None: return
            
        for el,nu in formula.items():
            if type(el) != types.StringType:
                el = elements.symbol(el)
                if el == None:
                    print "Error setting component formula"
                    return
            el = el.title()
            if el in self.formula.keys():
                self.formula[el] = float(nu)
            else:
                self.formula.update({el:float(nu)})
        self.update()
示例#2
0
文件: compound.py 项目: ttrainor/_tdl
    def set(self, formula):
        """
        This methods appends to or modifies the existing formula

        Paramters:
        ----------
        * formula is a dictionary: {'El':nu}
          where 'El' is the atomic symbol or Z (integer)
          and nu is the stoichiometric coefficient

          Or formula is a string: 'Si O2' (see parse_formula)

          Note nu = moles_of_El / mole_of_component
          therefore nu may be fractional and are converted to
          float even if passed as int
        
        """
        #if type(formula) == types.StringType:
        #    formula = {formula:1.}
        if type(formula) == types.StringType:
            formula = parse_formula(formula)
            if formula == None: return

        for el, nu in formula.items():
            if type(el) != types.StringType:
                el = elements.symbol(el)
                if el == None:
                    print "Error setting component formula"
                    return
            el = el.title()
            if el in self.formula.keys():
                self.formula[el] = float(nu)
            else:
                self.formula.update({el: float(nu)})
        self.update()
示例#3
0
文件: compound.py 项目: FHe/tdl
 def __getitem__(self,el):
     """
     return stiochiometric coefficient of element
     """
     if type(el) != types.StringType:
         el = elements.symbol(el)
         if el == None: 0.0
     el = el.title()
     if el in self.formula.keys():
         return self.formula[el]
     else:
         return 0.0
示例#4
0
文件: compound.py 项目: ttrainor/_tdl
 def __getitem__(self, el):
     """
     return stiochiometric coefficient of element
     """
     if type(el) != types.StringType:
         el = elements.symbol(el)
         if el == None: 0.0
     el = el.title()
     if el in self.formula.keys():
         return self.formula[el]
     else:
         return 0.0
示例#5
0
文件: compound.py 项目: FHe/tdl
 def __setitem__(self,el,nu):
     """
     set/add stioch of element
     """
     if type(el) != types.StringType:
         el = elements.symbol(el)
         if el == None: return
     el = el.title()
     if el in self.formula.keys():
         self.formula[el] = float(nu)
     else:
         self.formula.update({el:float(nu)})
     self.update()
示例#6
0
文件: compound.py 项目: ttrainor/_tdl
 def __setitem__(self, el, nu):
     """
     set/add stioch of element
     """
     if type(el) != types.StringType:
         el = elements.symbol(el)
         if el == None: return
     el = el.title()
     if el in self.formula.keys():
         self.formula[el] = float(nu)
     else:
         self.formula.update({el: float(nu)})
     self.update()
示例#7
0
文件: compound.py 项目: FHe/tdl
 def nuZ(self,el):
     """
     return the stoichiometric coefficient
     of the element given by Z (int or str)
     """
     nu_tot = 0.0
     if type(el) != types.StringType:
         el = elements.symbol(el)
         if el == None: return 0.0
     el = el.title()
     for (comp,nu) in self.comp:
         if el in comp.formula.keys():
             nu_tot = nu_tot + nu*comp.formula[el]
     return nu_tot
示例#8
0
文件: compound.py 项目: ttrainor/_tdl
 def nuZ(self, el):
     """
     return the stoichiometric coefficient
     of the element given by Z (int or str)
     """
     nu_tot = 0.0
     if type(el) != types.StringType:
         el = elements.symbol(el)
         if el == None: return 0.0
     el = el.title()
     for (comp, nu) in self.comp:
         if el in comp.formula.keys():
             nu_tot = nu_tot + nu * comp.formula[el]
     return nu_tot
示例#9
0
文件: compound.py 项目: FHe/tdl
 def nuZ(self,el):
     """
     return the stoichiometric coefficient
     
     Paramters:
     ----------
     * el is a string 'El' or integer Z
     """
     if type(el) != types.StringType:
         el = elements.symbol(el)
         if el == None: return 0.0
     el = el.title()
     if el in self.formula.keys():
         return self.formula[el]
     else:
         return 0.0
示例#10
0
文件: compound.py 项目: ttrainor/_tdl
 def nuZ(self, el):
     """
     return the stoichiometric coefficient
     
     Paramters:
     ----------
     * el is a string 'El' or integer Z
     """
     if type(el) != types.StringType:
         el = elements.symbol(el)
         if el == None: return 0.0
     el = el.title()
     if el in self.formula.keys():
         return self.formula[el]
     else:
         return 0.0