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()
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()
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
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
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()
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()
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
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
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
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