Exemple #1
0
 def i_charge(self, i):
     self._i_charge = check_return_property('i_charge', i)
     if not self._i_charge:
         if self.formula:
             charge = charge_from_formula(self.formula)
             chem_MW = molecular_weight(self.atoms)
             i = charge/chem_MW * self.i_mass
             self._i_charge = check_return_property('i_charge', i)
         else: self._i_charge = 0.
Exemple #2
0
    def charge(self):
        """Charge of the species as an integer.

        Computed as a property as most species do not have a charge and so
        storing it would be a waste of memory.
        """
        try:
            return self._charge
        except AttributeError:
            self._charge = charge_from_formula(self.formula)
            return self._charge
Exemple #3
0
def test_Marcus_ion_conductivities():
    # Check the CAS numbers are the "canonical" ones
    assert all([CAS_from_any(i) == i for i in Marcus_ion_conductivities.index])

    # Check the charges match up
    for v, CAS in zip(Marcus_ion_conductivities['Charge'], Marcus_ion_conductivities.index):
        assert v == charge_from_formula(pubchem_db.search_CAS(CAS).formula)

    # Even check the formulas work!
    for formula, CAS in zip(Marcus_ion_conductivities['Formula'], Marcus_ion_conductivities.index):
        assert pubchem_db.search_CAS(CAS_from_any(formula)).CASs == CAS
Exemple #4
0
 def i_COD(self, i):
     if i is not None: self._i_COD = check_return_property('i_COD', i)
     else:
         if self.organic or self.formula in ('H2', 'O2', 'N2', 'NO2-', 'NO3-'):
             if self.measured_as == 'COD': self._i_COD = 1.
             elif not self.atoms:
                 raise AttributeError(f"Must specify `i_COD` for organic component {self.ID}, "
                                      f"which is not measured as COD and has no formula.")
             else:
                 chem_MW = molecular_weight(self.atoms)
                 chem_charge = charge_from_formula(self.formula)
                 if self.formula in ('O2', 'N2', 'NO2-', 'NO3-'):
                     cod = electron_acceptor_cod(self.atoms, chem_charge) * molecular_weight({'O':2})
                 else:
                     Cr2O7 = - cod_test_stoichiometry(self.atoms, chem_charge)['Cr2O7-2']
                     cod = Cr2O7 * 1.5 * molecular_weight({'O':2})
                 self._i_COD = check_return_property('i_COD', cod/chem_MW * self.i_mass)
         else: self._i_COD = 0.
Exemple #5
0
 def i_mass(self, i):
     if self.atoms:
         if i: raise AttributeError(f'Component {self.ID} has formula, i_mass '
                                    f'is calculated, cannot be set.')
         else:
             if self.measured_as in self.atoms:
                 i = 1/get_mass_frac(self.atoms)[self.measured_as]
             elif self.measured_as == 'COD':
                 chem_MW = molecular_weight(self.atoms)
                 chem_charge = charge_from_formula(self.formula)
                 Cr2O7 = - cod_test_stoichiometry(self.atoms, chem_charge)['Cr2O7-2']
                 cod = Cr2O7 * 1.5 * molecular_weight({'O':2})
                 i = chem_MW/cod
             elif self.measured_as:
                 raise AttributeError(f'Must specify i_mass for component {self.ID} '
                                      f'measured as {self.measured_as}.')
     if self.measured_as == None:
         if i and i != 1:
             raise AttributeError(f'Component {self.ID} is measured as itself, '
                                  f'i_mass cannot be set to values other than 1.')
         i = 1
     self._i_mass = check_return_property('i_mass', i)