Skip to content

Commit

Permalink
allow compatibility with python 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Feb 26, 2021
1 parent 5fa366a commit 33b6f03
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 129 deletions.
2 changes: 1 addition & 1 deletion chemicals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"""

import os

from . import utils
from .utils import mark_jit_unsafe
from . import critical
from . import elements
from . import reaction
Expand Down
6 changes: 3 additions & 3 deletions chemicals/acentric.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
__all__ = ['omega', 'LK_omega', 'Stiel_polar_factor',
'omega_methods', 'omega_all_methods', 'omega_definition']

from chemicals.numba import unsafe
from chemicals import mark_jit_unsafe
from chemicals.utils import log, log10
from chemicals import critical
from chemicals.data_reader import (retrieve_from_df_dict,
Expand All @@ -61,7 +61,7 @@
omega_all_methods = ('PSRK', 'PD', 'YAWS')
'''Tuple of method name keys. See the `omega` for the actual references'''

@unsafe
@mark_jit_unsafe
def omega_methods(CASRN):
"""Return all methods available for obtaining omega for the desired
chemical.
Expand All @@ -82,7 +82,7 @@ def omega_methods(CASRN):
"""
return list_available_methods_from_df_dict(critical.omega_sources, CASRN, 'omega')

@unsafe
@mark_jit_unsafe
def omega(CASRN, method=None):
r'''Retrieve a chemical's acentric factor, `omega`.
Expand Down
17 changes: 10 additions & 7 deletions chemicals/combustion.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"""

from chemicals.elements import mass_fractions, molecular_weight, simple_formula_parser
from chemicals.utils import property_molar_to_mass, property_mass_to_molar
from chemicals.utils import property_molar_to_mass, property_mass_to_molar, mark_jit_unsafe
from fluids.numerics import normalize

__all__ = ('combustion_stoichiometry',
Expand Down Expand Up @@ -145,6 +145,7 @@ def as_atoms(formula):
O2_CAS = '7782-44-7'
H2O_CAS = '7732-18-5'

@mark_jit_unsafe
def combustion_stoichiometry(atoms, MW=None, missing_handling='elemental'):
r"""Return a dictionary of stoichiometric coefficients of chemical
combustion, given a dictionary of a molecule's constituent atoms and their
Expand Down Expand Up @@ -280,7 +281,7 @@ def combustion_stoichiometry(atoms, MW=None, missing_handling='elemental'):
raise ValueError("Allowed values for `missing_handling` are 'elemental' and 'ash'.")
return products


@mark_jit_unsafe
def combustion_products_mixture(atoms_list, zs, reactivities=None, CASs=None,
missing_handling='elemental',
combustion_stoichiometries=None):
Expand Down Expand Up @@ -373,7 +374,7 @@ def combustion_products_to_list(products, CASs):
return zs



@mark_jit_unsafe
def is_combustible(CAS, atoms, reactive=True):
if not reactive:
return False
Expand All @@ -386,6 +387,7 @@ def is_combustible(CAS, atoms, reactive=True):
else:
return False

@mark_jit_unsafe
def HHV_stoichiometry(stoichiometry, Hf, Hf_chemicals=None):
r"""
Return the higher heating value [HHV; in J/mol] based on the
Expand Down Expand Up @@ -430,6 +432,7 @@ def HHV_stoichiometry(stoichiometry, Hf, Hf_chemicals=None):
Hfs = Hf_chemicals or Hf_combustion_chemicals
return sum([Hfs[i] * j for i, j in stoichiometry.items()]) - Hf

@mark_jit_unsafe
def HHV_modified_Dulong(mass_fractions):
r"""
Return higher heating value [HHV; in J/g] based on the modified
Expand Down Expand Up @@ -518,6 +521,7 @@ def LHV_from_HHV(HHV, N_H2O):
"""
return HHV + 44011.496 * N_H2O

@mark_jit_unsafe
def combustion_data(formula=None, stoichiometry=None, Hf=None, MW=None,
method=None, missing_handling='ash'):
r"""
Expand Down Expand Up @@ -620,7 +624,6 @@ def combustion_data(formula=None, stoichiometry=None, Hf=None, MW=None,
"not %s" %(method))
return CombustionData(stoichiometry, HHV, Hf, MW)


class CombustionData(object):
r"""
Return a CombustionData object (a named tuple) that contains the stoichiometry
Expand Down Expand Up @@ -757,7 +760,7 @@ def air_fuel_ratio_solver(ratio, Vm_air, Vm_fuel, MW_air, MW_fuel,
mass_ratio, volume_ratio = MW_air/MW_fuel*mole_ratio, Vm_air/Vm_fuel*mole_ratio
return n_air, n_fuel, mole_ratio, mass_ratio, volume_ratio


@mark_jit_unsafe
def fuel_air_spec_solver(zs_air, zs_fuel, CASs, atomss, n_fuel=None,
n_air=None, n_out=None,
O2_excess=None, frac_out_O2=None,
Expand Down Expand Up @@ -1092,7 +1095,7 @@ def fuel_air_spec_solver(zs_air, zs_fuel, CASs, atomss, n_fuel=None,

return results


@mark_jit_unsafe
def fuel_air_third_spec_solver(zs_air, zs_fuel, zs_third, CASs, atomss, n_third,
n_fuel=None, n_air=None, n_out=None,
O2_excess=None, frac_out_O2=None,
Expand Down Expand Up @@ -1242,7 +1245,7 @@ def fix_ratios(results):

return ans


@mark_jit_unsafe
def combustion_spec_solver(zs_air, zs_fuel, zs_third, CASs, atomss, n_third,
n_fuel=None, n_air=None, n_out=None,
O2_excess=None, frac_out_O2=None,
Expand Down
20 changes: 10 additions & 10 deletions chemicals/critical.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
'critical_surface_all_methods']

import os
from chemicals.numba import unsafe
from chemicals import mark_jit_unsafe
from fluids.constants import R, R_inv, N_A
from chemicals.utils import log, PY37, source_path, os_path_join, can_load_data
from chemicals.data_reader import (register_df_source,
Expand Down Expand Up @@ -189,7 +189,7 @@ def __getattr__(name):
Tc_all_methods = (IUPAC, MATTHEWS, CRC, PSRK, PD, YAWS)
'''Tuple of method name keys. See the `Tc` for the actual references'''

@unsafe
@mark_jit_unsafe
def Tc_methods(CASRN):
"""Return all methods available to obtain Tc for the desired chemical.
Expand All @@ -210,7 +210,7 @@ def Tc_methods(CASRN):
if not _critical_data_loaded: _load_critical_data()
return list_available_methods_from_df_dict(Tc_sources, CASRN, 'Tc')

@unsafe
@mark_jit_unsafe
def Tc(CASRN, method=None):
r'''This function handles the retrieval of a chemical's critical
temperature. Lookup is based on CASRNs. Will automatically select a data
Expand Down Expand Up @@ -347,7 +347,7 @@ def Tc(CASRN, method=None):
Pc_all_methods = (IUPAC, MATTHEWS, CRC, PSRK, PD, YAWS)
'''Tuple of method name keys. See the `Pc` for the actual references'''

@unsafe
@mark_jit_unsafe
def Pc_methods(CASRN):
"""Return all methods available to obtain Pc for the desired chemical.
Expand All @@ -367,7 +367,7 @@ def Pc_methods(CASRN):
"""
return list_available_methods_from_df_dict(Pc_sources, CASRN, 'Pc')

@unsafe
@mark_jit_unsafe
def Pc(CASRN, method=None):
r'''This function handles the retrieval of a chemical's critical
pressure. Lookup is based on CASRNs. Will automatically select a data
Expand Down Expand Up @@ -503,7 +503,7 @@ def Pc(CASRN, method=None):
Vc_all_methods = (IUPAC, MATTHEWS, CRC, PSRK, YAWS)
'''Tuple of method name keys. See the `Vc` for the actual references'''

@unsafe
@mark_jit_unsafe
def Vc_methods(CASRN):
"""Return all methods available to obtain Vc for the desired chemical.
Expand All @@ -524,7 +524,7 @@ def Vc_methods(CASRN):
if not _critical_data_loaded: _load_critical_data()
return list_available_methods_from_df_dict(Vc_sources, CASRN, 'Vc')

@unsafe
@mark_jit_unsafe
def Vc(CASRN, method=None):
r'''This function handles the retrieval of a chemical's critical
volume. Lookup is based on CASRNs. Will automatically select a data
Expand Down Expand Up @@ -654,7 +654,7 @@ def Vc(CASRN, method=None):
Zc_all_methods = (IUPAC, MATTHEWS, CRC, PSRK, YAWS)
'''Tuple of method name keys. See the `Zc` for the actual references'''

@unsafe
@mark_jit_unsafe
def Zc_methods(CASRN):
"""Return all methods available to obtain Zc for the desired chemical.
Expand All @@ -675,7 +675,7 @@ def Zc_methods(CASRN):
if not _critical_data_loaded: _load_critical_data()
return list_available_methods_from_df_dict(Zc_sources, CASRN, 'Zc')

@unsafe
@mark_jit_unsafe
def Zc(CASRN, method=None):
r'''This function handles the retrieval of a chemical's critical
compressibility. Lookup is based on CASRNs. Will automatically select a
Expand Down Expand Up @@ -845,7 +845,7 @@ def Zc(CASRN, method=None):
u'Cs': 3.433699060142929,
u'Zr': 0.9346554283483623}

@unsafe
@mark_jit_unsafe
def Mersmann_Kind_predictor(atoms, coeff=3.645, power=0.5,
covalent_radii=rcovs_Mersmann_Kind):
r'''Predicts the critical molar volume of a chemical based only on its
Expand Down
26 changes: 13 additions & 13 deletions chemicals/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
'serialize_formula', 'mixture_atomic_composition_ordered',
'periodic_table']
import re
from chemicals.numba import unsafe
from chemicals import mark_jit_unsafe

CAS_by_number_standard = ['1333-74-0', '7440-59-7', '7439-93-2', '7440-41-7', '7440-42-8', '7440-44-0', '7727-37-9', '7782-44-7', '7782-41-4', '7440-01-9', '7440-23-5', '7439-95-4', '7429-90-5', '7440-21-3', '7723-14-0', '7704-34-9', '7782-50-5', '7440-37-1', '7440-09-7', '7440-70-2', '7440-20-2', '7440-32-6', '7440-62-2', '7440-47-3', '7439-96-5', '7439-89-6', '7440-48-4', '7440-02-0', '7440-50-8', '7440-66-6', '7440-55-3', '7440-56-4', '7440-38-2', '7782-49-2', '7726-95-6', '7439-90-9', '7440-17-7', '7440-24-6', '7440-65-5', '7440-67-7', '7440-03-1', '7439-98-7', '7440-26-8', '7440-18-8', '7440-16-6', '7440-05-3', '7440-22-4', '7440-43-9', '7440-74-6', '7440-31-5', '7440-36-0', '13494-80-9', '7553-56-2', '7440-63-3', '7440-46-2', '7440-39-3', '7439-91-0', '7440-45-1', '7440-10-0', '7440-00-8', '7440-12-2', '7440-19-9', '7440-53-1', '7440-54-2', '7440-27-9', '7429-91-6', '7440-60-0', '7440-52-0', '7440-30-4', '7440-64-4', '7439-94-3', '7440-58-6', '7440-25-7', '7440-33-7', '7440-15-5', '7440-04-2', '7439-88-5', '7440-06-4', '7440-57-5', '7439-97-6', '7440-28-0', '7439-92-1', '7440-69-9', '7440-08-6', '7440-68-8', '10043-92-2', '7440-73-5', '7440-14-4', '7440-34-8', '7440-29-1', '7440-13-3', '7440-61-1', '7439-99-8', '7440-07-5', '7440-35-9', '7440-51-9', '7440-40-6', '7440-71-3', '7429-92-7', '7440-72-4', '7440-11-1', '10028-14-5', '22537-19-5', '53850-36-5', '53850-35-4', '54038-81-2', '54037-14-8', '54037-57-9', '54038-01-6', '54083-77-1', '54386-24-2', '54084-26-3', '54084-70-7', '54085-16-4', '54085-64-2', '54100-71-9', '54101-14-3', '54144-19-3']
'''Standard CAS numbers of the elements, indexed by atomic numbers off-by-one up to 118.'''
Expand Down Expand Up @@ -554,7 +554,7 @@ class directly.
'''
del openbabel_element_data

@unsafe
@mark_jit_unsafe
def molecular_weight(atoms):
r'''Calculates molecular weight of a molecule given a dictionary of its
atoms and their counts, in the format {symbol: count}.
Expand Down Expand Up @@ -603,7 +603,7 @@ def molecular_weight(atoms):
raise ValueError('Molecule includes unknown atoms')
return MW

@unsafe
@mark_jit_unsafe
def mass_fractions(atoms, MW=None):
r'''Calculates the mass fractions of each element in a compound,
given a dictionary of its atoms and their counts, in the format
Expand Down Expand Up @@ -654,7 +654,7 @@ def mass_fractions(atoms, MW=None):
raise ValueError('Molecule includes unknown atoms')
return mfracs

@unsafe
@mark_jit_unsafe
def atom_fractions(atoms):
r'''Calculates the atomic fractions of each element in a compound,
given a dictionary of its atoms and their counts, in the format
Expand Down Expand Up @@ -695,7 +695,7 @@ def atom_fractions(atoms):
afracs[i] = atoms[i]/count
return afracs

@unsafe
@mark_jit_unsafe
def mixture_atomic_composition(atomss, zs):
r'''Simple function to calculate the atomic average composition of a
mixture, using the mole fractions of each species and their own atomic
Expand Down Expand Up @@ -730,7 +730,7 @@ def mixture_atomic_composition(atomss, zs):
ans[key] = val*zs_i
return ans

@unsafe
@mark_jit_unsafe
def mixture_atomic_composition_ordered(atomss, zs):
r'''Simple function to calculate the atomic average composition of a
mixture, using the mole fractions of each species and their own atomic
Expand Down Expand Up @@ -769,7 +769,7 @@ def mixture_atomic_composition_ordered(atomss, zs):
eles.append(k)
return nums, eles

@unsafe
@mark_jit_unsafe
def atom_matrix(atomss, atom_IDs=None):
r'''Simple function to create a matrix of elements in each compound, where
each row has the same elements.
Expand Down Expand Up @@ -817,7 +817,7 @@ def atom_matrix(atomss, atom_IDs=None):

return element_matrix

@unsafe
@mark_jit_unsafe
def similarity_variable(atoms, MW=None):
r'''Calculates the similarity variable of an compound, as defined in [1]_.
Currently only applied for certain heat capacity estimation routines.
Expand Down Expand Up @@ -859,7 +859,7 @@ def similarity_variable(atoms, MW=None):
MW = molecular_weight(atoms)
return sum(atoms.values())/MW

@unsafe
@mark_jit_unsafe
def atoms_to_Hill(atoms):
r'''Determine the Hill formula of a compound, given a dictionary of its
atoms and their counts, in the format {symbol: count}.
Expand Down Expand Up @@ -920,7 +920,7 @@ def str_ele_count(ele):
_simple_formula_parser_re_str = r'([A-Z][a-z]{0,2})([\d\.\d]+)?'
_simple_formula_parser_re = None # Delay creation to simple_formula_parser to speedup start

@unsafe
@mark_jit_unsafe
def simple_formula_parser(formula):
r'''Basic formula parser, primarily for obtaining element counts from
formulas as formated in PubChem. Handles formulas with integer or decimal
Expand Down Expand Up @@ -976,7 +976,7 @@ def simple_formula_parser(formula):
formula_token_matcher_rational = bracketed_charge_re = None
letter_set = set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ')

@unsafe
@mark_jit_unsafe
def nested_formula_parser(formula, check=True):
r'''Improved formula parser which handles braces and their multipliers,
as well as rational element counts.
Expand Down Expand Up @@ -1064,7 +1064,7 @@ def nested_formula_parser(formula, check=True):
ans[ele] = count
return ans

@unsafe
@mark_jit_unsafe
def charge_from_formula(formula):
r'''Basic formula parser to determine the charge from a formula - given
that the charge is already specified as one element of the formula.
Expand Down Expand Up @@ -1120,7 +1120,7 @@ def charge_from_formula(formula):
else:
return multiplier*count

@unsafe
@mark_jit_unsafe
def serialize_formula(formula):
r'''Basic formula serializer to construct a consistently-formatted formula.
This is necessary for handling user-supplied formulas, which are not always
Expand Down
Loading

0 comments on commit 33b6f03

Please sign in to comment.