Skip to content

Commit

Permalink
Substantial progress towards fixing old and failing doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebBell committed Jan 12, 2017
1 parent e7bc325 commit 98823aa
Show file tree
Hide file tree
Showing 17 changed files with 169 additions and 48 deletions.
67 changes: 67 additions & 0 deletions tests/test_chemical.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from numpy.testing import assert_allclose
import pytest
from thermo.chemical import *
from thermo.identifiers import pubchem_dict

def test_Chemical_properties():
w = Chemical('water')
Expand Down Expand Up @@ -256,3 +257,69 @@ def test_H_Chemical():
dH_20K_gas = w.Hm - Hm_as_vapor
assert_allclose(dH_20K_gas, 1000*(48.9411675-48.2041134), rtol=1E-1) # Web tables, but hardly matches because of the excess


@pytest.mark.slow
@pytest.mark.meta_Chemical
def test_all_chemicals():
for i in pubchem_dict.keys():
c = Chemical(i)

# T and P dependent properties - just test they can be called
c.Psat
c.Hvapm
c.Hvap
c.Cpsm
c.Cplm
c.Cpgm
c.Cps
c.Cpl
c.Cpg
c.Cvgm
c.Cvg
c.isentropic_exponent
c.Vms
c.Vml
c.Vmg
c.rhos
c.rhol
c.rhog
c.rhosm
c.rholm
c.rhogm
c.Zs
c.Zl
c.Zg
c.Bvirial
c.isobaric_expansion_l
c.isobaric_expansion_g
c.mul
c.mug
c.kl
c.kg
c.sigma
c.permittivity
c.JTl
c.JTg
c.nul
c.nug
c.alphal
c.alphag
c.Prl
c.Prg
c.solubility_parameter
c.Parachor

# Any phase dependent property
c.Cp
c.Cpm
c.Vm
c.rho
c.rhom
c.Z
c.isobaric_expansion
c.JT
c.mu
c.k
c.nu
c.alpha
c.Pr
7 changes: 0 additions & 7 deletions tests/test_datasheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,3 @@
# df = tabulate_constants(['hexane', 'toluene'], full=True, vertical=True)
# df_as_dict = {'hexane': {'Electrical conductivity, S/m': 1e-16, 'Global warming potential': None, 'InChI key': 'VLKZOEOYAKHREP-UHFFFAOYSA-N', 'Heat of vaporization at Tb, J/mol': 28862.311605415733, 'Time-weighted average exposure limit': "(50.0, 'ppm')", 'Tc, K': 507.6, 'Short-term exposure limit': 'None', 'Molecular Diameter, Angstrom': 5.61841, 'Formula': 'C6H14', 'InChI': 'C6H14/c1-3-5-6-4-2/h3-6H2,1-2H3', 'Parachor': 272.1972168105559, 'Heat of fusion, J/mol': 13080.0, 'Tb, K': 341.87, 'Stockmayer parameter, K': 434.76, 'IUPAC name': 'hexane', 'Refractive index': 1.3727, 'Tm, K': 178.075, 'solubility parameter, Pa^0.5': 14848.17694628013, 'Heat of formation, J/mol': -166950.0, 'Pc, Pa': 3025000.0, 'Lower flammability limit, fraction': 0.01, 'Vc, m^3/mol': 0.000368, 'Upper flammability limit, fraction': 0.08900000000000001, 'Dipole moment, debye': 0.0, 'MW, g/mol': 86.17536, 'Acentric factor': 0.2975, 'rhoC, kg/m^3': 234.17217391304345, 'Zc': 0.2637652305242204, 'Triple pressure, Pa': 1.1747772750450831, 'Autoignition temperature, K': 498.15, 'CAS': '110-54-3', 'smiles': 'CCCCCC', 'Flash temperature, K': 251.15, 'Ozone depletion potential': None, 'logP': 4.0, 'Heat of sublimation, J/mol': None, 'Triple temperature, K': 177.84}, 'toluene': {'Electrical conductivity, S/m': 1e-12, 'Global warming potential': None, 'InChI key': 'YXFVVABEGXRONW-UHFFFAOYSA-N', 'Heat of vaporization at Tb, J/mol': 33233.94544167449, 'Time-weighted average exposure limit': "(20.0, 'ppm')", 'Tc, K': 591.75, 'Short-term exposure limit': 'None', 'Molecular Diameter, Angstrom': 5.4545, 'Formula': 'C7H8', 'InChI': 'C7H8/c1-7-5-3-2-4-6-7/h2-6H,1H3', 'Parachor': 246.76008384965857, 'Heat of fusion, J/mol': 6639.9999999999991, 'Tb, K': 383.75, 'Stockmayer parameter, K': 350.74, 'IUPAC name': 'methylbenzene', 'Refractive index': 1.4941, 'Tm, K': 179.2, 'solubility parameter, Pa^0.5': 18242.232319337778, 'Heat of formation, J/mol': 50170.0, 'Pc, Pa': 4108000.0, 'Lower flammability limit, fraction': 0.01, 'Vc, m^3/mol': 0.00031600000000000004, 'Upper flammability limit, fraction': 0.078, 'Dipole moment, debye': 0.33, 'MW, g/mol': 92.13842, 'Acentric factor': 0.257, 'rhoC, kg/m^3': 291.5772784810126, 'Zc': 0.26384277925843774, 'Triple pressure, Pa': 0.04217711401906639, 'Autoignition temperature, K': 803.15, 'CAS': '108-88-3', 'smiles': 'CC1=CC=CC=C1', 'Flash temperature, K': 277.15, 'Ozone depletion potential': None, 'logP': 2.73, 'Heat of sublimation, J/mol': None, 'Triple temperature, K': 179.2}}
# pd.util.testing.assert_frame_equal(pd.DataFrame(df_as_dict), pd.DataFrame(df.to_dict()))

@pytest.mark.slow
@pytest.mark.meta_Chemical
def test_all_chemicals():
for i in pubchem_dict.keys():
Chemical(i)

2 changes: 1 addition & 1 deletion thermo/acentric.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def StielPolar(Tc=None, Pc=None, omega=None, CASRN='', Method=None,
Examples
--------
>>> StielPolar(647.3, 22048321.0, 0.344, CASRN='7732-18-5')
0.02458114034873482
0.024581140348734376
References
----------
Expand Down
2 changes: 1 addition & 1 deletion thermo/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ def list_methods():
methods.append('SUPERCRITICAL_T')
if none_and_length_check([Pcs]) and all([P >= i for i in Pcs]):
methods.append('SUPERCRITICAL_P')
if none_and_length_check((zs, Tcs)) and any([T > Tc for Tc in Tcs]):
if none_and_length_check([zs, Tcs]) and any([T > Tc for Tc in Tcs]):
methods.append('IDEAL_VLE_SUPERCRITICAL')
methods.append('NONE')
return methods
Expand Down
77 changes: 69 additions & 8 deletions thermo/chemical.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Chemical(object): # pragma: no cover
Default initialization is for 298.15 K, 1 atm.
Goal is for, when a method fails, a warning is printed.
'''
eos_in_a_box = []
def __repr__(self):
Expand Down Expand Up @@ -714,38 +715,98 @@ def Hvap(self):

@property
def Cpsm(self):
'''Solid-phase heat capacity of the chemical at its current temperature,
in units of J/mol/K. For calculation of this property at other
temperatures, or specifying manually the method used to calculate it,
and more - see the object oriented interface
:obj:`thermo.heat_capacity.HeatCapacitySolid`; each Chemical instance
creates one to actually perform the calculations.
Examples
--------
>>> Chemical('palladium').Cpsm
24.930765664000003
>>> Chemical('palladium').HeatCapacitySolid.T_dependent_property(320)
25.098979200000002
>>> Chemical('palladium').HeatCapacitySolid.all_methods
set(["Perry's Table 2-151", 'CRC Standard Thermodynamic Properties of Chemical Substances', 'Lastovka, Fulem, Becerra and Shaw (2008)'])
'''
return self.HeatCapacitySolid(self.T)

@property
def Cplm(self):
'''Liquid-phase heat capacity of the chemical at its current temperature,
in units of J/mol/K. For calculation of this property at other
temperatures, or specifying manually the method used to calculate it,
and more - see the object oriented interface
:obj:`thermo.heat_capacity.HeatCapacityLiquid`; each Chemical instance
creates one to actually perform the calculations.
Notes
-----
Some methods give heat capacity along the saturation line, some at
1 atm but only up to the normal boiling point, and some give heat
capacity at 1 atm up to the normal boiling point and then along the
saturation line. Real-liquid heat capacity is pressure dependent, but
this interface is not.
Examples
--------
>>> Chemical('water').Cplm
75.31462591538555
>>> Chemical('water').HeatCapacityLiquid.T_dependent_property(320)
75.25917443606316
>>> Chemical('water').HeatCapacityLiquid.T_dependent_property_integral(300, 320)
1505.0619005000553
'''
return self.HeatCapacityLiquid(self.T)

@property
def Cpgm(self):
'''Gas-phase ideal gas heat capacity of the chemical at its current
temperature, in units of J/mol/K. For calculation of this property at
other temperatures, or specifying manually the method used to calculate
it, and more - see the object oriented interface
:obj:`thermo.heat_capacity.HeatCapacityGas`; each Chemical instance
creates one to actually perform the calculations.
Examples
--------
>>> Chemical('water').Cpgm
33.583577868850675
>>> Chemical('water').HeatCapacityGas.T_dependent_property(320)
33.67865044005934
>>> Chemical('water').HeatCapacityGas.T_dependent_property_integral(300, 320)
672.6480417968248
'''
return self.HeatCapacityGas(self.T)

@property
def Cps(self):
if self.Cpsm:
return property_molar_to_mass(self.Cpsm, self.MW)
Cpsm = self.HeatCapacitySolid(self.T)
if Cpsm:
return property_molar_to_mass(Cpsm, self.MW)
return None

@property
def Cpl(self):
if self.Cplm:
return property_molar_to_mass(self.Cplm, self.MW)
Cplm = self.HeatCapacityLiquid(self.T)
if Cplm:
return property_molar_to_mass(Cplm, self.MW)
return None

@property
def Cpg(self):
if self.Cpgm:
return property_molar_to_mass(self.Cpgm, self.MW)
Cpgm = self.HeatCapacityGas(self.T)
if Cpgm:
return property_molar_to_mass(Cpgm, self.MW)
return None

@property
def Cvgm(self):
if self.Cpgm:
return self.Cpgm - R
Cpgm = self.HeatCapacityGas(self.T)
if Cpgm:
return Cpgm - R
return None

@property
Expand Down
2 changes: 1 addition & 1 deletion thermo/coolprop.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def CoolProp_T_dependent_property(T, CASRN, prop, phase):
Water at STP according to IAPWS-95
>>> CoolProp_T_dependent_property(298.15, '7732-18-5', 'D', 'l')
997.0476367603451
997.047636760347
References
----------
Expand Down
4 changes: 2 additions & 2 deletions thermo/critical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ def critical_surface(Tc=None, Pc=None, Vc=None, AvailableMethods=False,
--------
Decamethyltetrasiloxane [141-62-8]
>>> critical_surface(Tc=599.4, Pc=1.19E6, Method='Ihmels')
>>> critical_surface(Tc=599.4, Pc=1.19E6, Method='IHMELS')
0.0010927333333333334
'''
def list_methods():
Expand Down Expand Up @@ -1619,7 +1619,7 @@ def modified_Wilson_Vc(zs, Vcs, Aijs):
>>> modified_Wilson_Vc([0.4271, 0.5729], [0.000273, 0.000256],
... [[0, 0.6671250], [1.3939900, 0]])
0.00026643350327068809
0.0002664335032706881
References
----------
Expand Down
6 changes: 3 additions & 3 deletions thermo/electrochem.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def Laliberte_viscosity_i(T, w_w, v1, v2, v3, v4, v5, v6):
--------
>>> d = _Laliberte_Viscosity_ParametersDict['7647-14-5']
>>> Laliberte_viscosity_i(273.15+5, 1-0.005810, d["V1"], d["V2"], d["V3"], d["V4"], d["V5"], d["V6"] )
0.0042540255333087936
0.004254025533308794
References
----------
Expand Down Expand Up @@ -385,7 +385,7 @@ def Laliberte_heat_capacity_w(T):
Examples
--------
>>> Laliberte_heat_capacity_w(273.15+3.56)
4208.8759205525475
4208.875920552542
References
----------
Expand Down Expand Up @@ -479,7 +479,7 @@ def Laliberte_heat_capacity(T, ws, CASRNs):
Examples
--------
>>> Laliberte_heat_capacity(273.15+1.5, [0.00398447], ['7647-14-5']) #4186.0988
4186.566417712068
4186.566417712063
References
----------
Expand Down
2 changes: 1 addition & 1 deletion thermo/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ def similarity_variable(atoms, MW=None):
Examples
--------
>>> similarity_variable({'H': 32, 'C': 15})
0.22125872677371825
0.2212654140784498
References
----------
Expand Down
30 changes: 15 additions & 15 deletions thermo/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,27 +1471,27 @@ class PR(GCEOS):
>>> eos = PR(Tc=507.6, Pc=3025000, omega=0.2975, T=400., P=1E6)
>>> eos.V_l, eos.V_g
(0.0001560731318852931, 0.0021418760907613724)
(0.000156073131885293, 0.0021418760907613724)
>>> eos.phase
'l/g'
>>> eos.H_dep_l, eos.H_dep_g
(-26111.86872116082, -3549.2993749373945)
(-26111.868721160834, -3549.2993749373945)
>>> eos.S_dep_l, eos.S_dep_g
(-58.09842815106086, -6.439449710478305)
(-58.0984281510609, -6.439449710478305)
>>> eos.U_dep_l, eos.U_dep_g
(-22942.157933046114, -2365.391545698767)
(-22942.157933046128, -2365.391545698767)
>>> eos.G_dep_l, eos.G_dep_g
(-2872.4974607364747, -973.5194907460736)
(-2872.4974607364747, -973.5194907460723)
>>> eos.A_dep_l, eos.A_dep_g
(297.21332737823104, 210.38833849255388)
(297.21332737823104, 210.38833849255525)
>>> eos.beta_l, eos.beta_g
(0.0026933709177838043, 0.010123223911174959)
(0.002693370917783791, 0.01012322391117497)
>>> eos.kappa_l, eos.kappa_g
(9.335721543829601e-09, 1.9710669809793286e-06)
(9.335721543829537e-09, 1.9710669809793307e-06)
>>> eos.Cp_minus_Cv_l, eos.Cp_minus_Cv_g
(48.51014580740871, 44.54414603000341)
(48.51014580740853, 44.54414603000345)
>>> eos.Cv_dep_l, eos.Cp_dep_l
(25.165377505266747, 44.50559908690951)
(18.89210627002109, 59.08779227742962)
P-T initialization, liquid phase, and round robin trip:
Expand Down Expand Up @@ -1744,7 +1744,7 @@ class PR78(PR):
>>> eos = PR78(Tc=632, Pc=5350000, omega=0.734, T=299., P=1E6)
>>> eos.phase, eos.V_l, eos.H_dep_l, eos.S_dep_l
('l', 8.351960066075052e-05, -63764.64948050847, -130.737108912626)
('l', 8.351960066075009e-05, -63764.649480508735, -130.73710891262687)
Notes
-----
Expand Down Expand Up @@ -1826,7 +1826,7 @@ class PRSV(PR):
>>> eos = PRSV(Tc=507.6, Pc=3025000, omega=0.2975, T=299., P=1E6, kappa1=0.05104)
>>> eos.phase, eos.V_l, eos.H_dep_l, eos.S_dep_l
('l', 0.0001301268694484059, -31698.916002476708, -74.1674902435042)
('l', 0.00013012686944840622, -31698.916002476657, -74.16749024350403)
Notes
-----
Expand Down Expand Up @@ -2043,7 +2043,7 @@ class PRSV2(PR):
>>> eos = PRSV2(Tc=507.6, Pc=3025000, omega=0.2975, T=299., P=1E6, kappa1=0.05104, kappa2=0.8634, kappa3=0.460)
>>> eos.phase, eos.V_l, eos.H_dep_l, eos.S_dep_l
('l', 0.00013018821346475254, -31496.173493225753, -73.6152580115141)
('l', 0.00013018821346475243, -31496.173493225775, -73.61525801151417)
Notes
-----
Expand Down Expand Up @@ -2397,7 +2397,7 @@ class RK(GCEOS):
--------
>>> eos = RK(Tc=507.6, Pc=3025000, T=299., P=1E6)
>>> eos.phase, eos.V_l, eos.H_dep_l, eos.S_dep_l
('l', 0.00015189341729751865, -26160.833620674082, -63.01311649400543)
('l', 0.00015189341729751854, -26160.8336206741, -63.01311649400547)
Notes
-----
Expand Down Expand Up @@ -2997,7 +2997,7 @@ def TWU_a_alpha_common(T, Tc, omega, a, full=True, quick=True, method='PR'):
brevity; they are obtainable from the following SymPy expression.
>>> from sympy import *
>>> N1, N0, M1, M0, L1, L0 = symbols('N1, N0, M1, M0, L1, L0')
>>> T, Tc, omega, N1, N0, M1, M0, L1, L0 = symbols('T, Tc, omega, N1, N0, M1, M0, L1, L0')
>>> Tr = T/Tc
>>> alpha0 = Tr**(N0*(M0-1))*exp(L0*(1-Tr**(N0*M0)))
>>> alpha1 = Tr**(N1*(M1-1))*exp(L1*(1-Tr**(N1*M1)))
Expand Down
2 changes: 1 addition & 1 deletion thermo/eos_mix.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ class VDWMIX(GCEOSMIX, VDW):
>>> eos.V_l, eos.V_g
(5.8813678514166464e-05, 0.0007770869741895237)
>>> eos.fugacities_l, eos.fugacities_g
([854533.2669205102, 207126.8497276205], [448470.7363380735, 397826.5439999289])
([854533.2669205095, 207126.8497276207], [448470.73633807345, 397826.5439999289])
Notes
-----
Expand Down
2 changes: 1 addition & 1 deletion thermo/heat_capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1764,7 +1764,7 @@ def Cv_gas_mixture(zs=None, ws=None, Cps=None, CASRNs=None, AvailableMethods=Fa
This API is considered experimental, and is expected to be removed in a
future release in favor of a more complete object-oriented interface.
>>> Cv_gas_mixture(ws=[0.6, 0.3, 0.1], Cps=[1402.64, 1116.27, 1558.23])
>>> Cv_gas_mixture(ws=[0.6, 0.3, 0.1], Cps=[1402.64, 1116.27, 1558.23])
1332.2880000000002
'''
def list_methods():
Expand Down
Loading

0 comments on commit 98823aa

Please sign in to comment.