Skip to content

Commit

Permalink
Fixes with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebBell committed Oct 21, 2023
1 parent e816d45 commit fe78fb9
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 86 deletions.
4 changes: 2 additions & 2 deletions thermo/bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ class BulkSettings:
'mu_VL', 'mu_VL_power_exponent', 'k_LL', 'k_LL_power_exponent', 'k_VL', 'k_VL_power_exponent',
'sigma_LL', 'sigma_LL_power_exponent', 'T_liquid_volume_ref', 'T_normal', 'P_normal', 'T_standard',
'P_standard', 'T_gas_ref', 'P_gas_ref', 'speed_of_sound', 'kappa', 'isobaric_expansion',
'Joule_Thomson', 'VL_ID', 'VL_ID_settings', 'S_ID', 'S_ID_settings', 'solid_sort_method',
'liquid_sort_method', 'liquid_sort_cmps', 'solid_sort_cmps', 'liquid_sort_cmps_neg', 'solid_sort_cmps_neg',
'Joule_Thomson', 'VL_ID', 'VL_ID_settings', 'S_ID', 'S_ID_settings', 'solid_sort_method',
'liquid_sort_method', 'liquid_sort_cmps', 'solid_sort_cmps', 'liquid_sort_cmps_neg', 'solid_sort_cmps_neg',
'liquid_sort_prop', 'solid_sort_prop', 'phase_sort_higher_first', 'water_sort', 'equilibrium_perturbation')

def as_json(self):
Expand Down
2 changes: 1 addition & 1 deletion thermo/chemical_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ def compound_index(self, CAS=None, name=None, smiles=None, InChI=None,

@property
def CAS_to_index(self):
r'''Dictionary of CAS: index, used for efficiently
r'''Dictionary of CAS: index, used for efficiently
looking up which index a specified CAS number is in.
This can save a lot of time, but does take a little more memory.
Expand Down
18 changes: 9 additions & 9 deletions thermo/chemical_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def S0_basis_converter(c, S0_liq=None, S0_gas=None, T_ref=298.15):
# 'S': {'Tm': 388.360, 'Tb': 882.117, 'Hfus': 1721, 'Hvap': 53326, 'solid_T_trans': [368.300], 'solid_H_trans': [401]}, # TODO
# 'Be': {'Tm': 1560.000, 'Tb': 2741.437, 'Hfus': 7895, 'Hvap': 291572, 'solid_T_trans': [1527.000], 'solid_H_trans': [6849]}, # TODO
# 'Fe': {'Tm': 3133.345, 'Hfus': 349585, 'solid_T_trans': [1184.000, 1665.000], 'solid_H_trans': [900, 837]}, # TODO

}

shomate_gas_elements = ('H', 'O', 'N', 'F', 'P', 'Cl', 'Br', 'I', 'Mg', 'B', 'Pb', 'Li', 'Na', 'Al', 'K', 'V', 'Cr')
Expand Down Expand Up @@ -206,12 +206,12 @@ def element_HeatCapacitySolid_cache(CAS):
def standard_state_ideal_gas_formation(c, T, Hf=None, Sf=None, T_ref=298.15):
r'''This function calculates the standard state ideal-gas heat of formation
of a compound at a specified from first principles. The entropy change and
Gibbs free energy change of formation are also returned.
Gibbs free energy change of formation are also returned.
This special condition is usually tabulated in thermodynamic tables, and
this function is intended to be consistent with the standard conventions.
The values returned depend on:
* The heat of formation as an ideal gas of the compound at 298.15 K (must be measured experimentally)
* The ideal gas absolute entropy of the compound at 298.15 K (calculated from heat capacity and phase transitions of the compound and its various phases)
* The chosen reference states of the elements (convention, but hardcoded)
Expand Down Expand Up @@ -260,7 +260,7 @@ def standard_state_ideal_gas_formation(c, T, Hf=None, Sf=None, T_ref=298.15):
Hf_ref = Hf if Hf is not None else c.Hfgm
Sf_ref = Sf if Sf is not None else c.Sfgm
atoms = c.atoms
return _standard_state_ideal_gas_formation_direct(T=T, Hf_ref=Hf_ref, Sf_ref=Sf_ref,
return _standard_state_ideal_gas_formation_direct(T=T, Hf_ref=Hf_ref, Sf_ref=Sf_ref,
atoms=atoms, gas_Cp=c.HeatCapacityGas, T_ref=T_ref)

_standard_formation_reaction_cache = {}
Expand All @@ -282,14 +282,14 @@ def _standard_state_ideal_gas_formation_direct(T, Hf_ref, Sf_ref, atoms, gas_Cp,

dH_compound = gas_Cp.T_dependent_property_integral(T_ref, T)
dS_compound = gas_Cp.T_dependent_property_integral_over_T(T_ref, T)

H_calc = reactant_coeff*Hf_ref + reactant_coeff*dH_compound
S_calc = reactant_coeff*Sf_ref + reactant_coeff*dS_compound
# if the compound is an element it will need special handling to go from solid liquid to gas if needed

solid_ele = set(['C'])
liquid_ele = set([''])

for coeff, ele_data in zip(elemental_counts, elemental_composition):
ele = list(ele_data.keys())[0]
element_obj = periodic_table[ele]
Expand Down Expand Up @@ -334,7 +334,7 @@ def _standard_state_ideal_gas_formation_direct(T, Hf_ref, Sf_ref, atoms, gas_Cp,
elif ele == 'P':
# White phosphorus is the basis here
T_alpha_beta_P = 195.400
Htrans_alpha_beta_P = 521.0 # 525.5104 reported in
Htrans_alpha_beta_P = 521.0 # 525.5104 reported in
# The thermodynamic properties of elementary phosphorus The heat capacities of two crystalline modifications of red phosphorus, of α and β white phosphorus, and of black phosphorus from 15 to 300 K
Tm_P = 317.300
Hfus_P = 659
Expand Down Expand Up @@ -389,7 +389,7 @@ def _standard_state_ideal_gas_formation_direct(T, Hf_ref, Sf_ref, atoms, gas_Cp,
H_calc -= coeff*dH_ele
S_calc -= coeff*dS_ele
G_calc = H_calc - T*S_calc

H_calc, S_calc, G_calc = H_calc/reactant_coeff, S_calc/reactant_coeff, G_calc/reactant_coeff

return H_calc, S_calc, G_calc
2 changes: 1 addition & 1 deletion thermo/equilibrium.py
Original file line number Diff line number Diff line change
Expand Up @@ -3395,7 +3395,7 @@ def get_bulk_property(self):
'Gs_ideal_gas_standard_state', 'S_ideal_gas_standard_state', 'Ss_ideal_gas_standard_state',

'concentrations_mass_gas', 'concentrations_mass_gas_normal', 'concentrations_mass_gas_standard',
'concentrations_gas_standard', 'concentrations_gas_normal', 'concentrations_gas'
'concentrations_gas_standard', 'concentrations_gas_normal', 'concentrations_gas'
]


Expand Down
10 changes: 5 additions & 5 deletions thermo/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,17 @@ def split_data(x, y, folds=5, seed=42):
if pts != len(y):
raise ValueError("Wrong size")
z = list(range(pts))

Random(seed).shuffle(z)
# go one by one and assign data to each group

fold_xs = [[] for _ in range(folds)]
fold_ys = [[] for _ in range(folds)]
for i in range(pts):
l = i%folds
fold_xs[l].append(x[i])
fold_ys[l].append(y[i])

return fold_xs, fold_ys

def assemble_fit_test_groups(x_groups, y_groups):
Expand All @@ -98,7 +98,7 @@ def assemble_fit_test_groups(x_groups, y_groups):
if j != i:
x_train.extend(x_groups[j])
y_train.extend(y_groups[j])

train_x_groups.append(x_train)
train_y_groups.append(y_train)
return (train_x_groups, test_x_groups, train_y_groups, test_y_groups)
Expand Down Expand Up @@ -851,7 +851,7 @@ def jac_wrapped_for_leastsq(params):
statistics['min_ratio'] = float(stats[2])
statistics['max_ratio'] = float(stats[3])
try:
pcov = float(pcov)
pcov = float(pcov)
except:
# ndarray or None
pass
Expand Down
2 changes: 1 addition & 1 deletion thermo/flash/flash_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@ def _finish_initialization_base(self):
self.scalar = scalar_statuses.pop()

self.supports_lnphis_args = all(p.supports_lnphis_args for p in self.phases)

# Make the phases aware of the constants and properties
constants = self.constants
correlations = self.correlations
Expand Down
12 changes: 6 additions & 6 deletions thermo/flash/flash_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
'generate_phase_boundaries_naive',
'water_wet_bulb_temperature',
'water_dew_point_from_humidity',
'solve_water_wet_bulb_temperature_nested',
'solve_water_wet_bulb_temperature_nested',
'solve_water_wet_bulb_temperature_direct',
]

Expand Down Expand Up @@ -5280,13 +5280,13 @@ def water_dew_point_from_humidity(flasher, T, P, humidity, zs_air, zs_added):
except:
return None
N = flasher.N
ratio = sat.flash_convergence['mixing_factor']
ratio = sat.flash_convergence['mixing_factor']
feed_ns = zs_air
zs_for_factor = flash_mixing_remove_overlap(zs_air, zs_added)
n_factor = sum([feed_ns[i] if zs_for_factor[i] > 0 else 0 for i in range(N)])
ns_out = [n_factor*(zs_for_factor[i] + zs_added[i]*ratio*humidity) for i in range(N)]
zs_my_flash = normalize(ns_out)

return water_wet_bulb_temperature(flasher, zs=zs_my_flash, T=T, P=P)


Expand Down Expand Up @@ -5413,10 +5413,10 @@ def solve_water_wet_bulb_temperature_direct(flasher, zs, T, P, T_wet_bulb):
H_water_product = water_product.H()
flashes2 = []

'''Known: T_wet_bulb. Product T. Product P.
"""Known: T_wet_bulb. Product T. Product P.
Unknown: x_w out, how many moles water to add to cause saturation of water, the temperature of the end flash
'''
"""
def wet_bulb_T_error_direct(guess):
# TODO make a standalone function for this
moles_water_1, moles_water_2 = guess
Expand All @@ -5439,7 +5439,7 @@ def wet_bulb_T_error_direct(guess):
zs_out = normalize(ns_out_2)

# As best as I can tell, the VF=1 flash is required otherwise the newton solver will
# go nuts with no jacobian.
# go nuts with no jacobian.
flash_out = flasher.flash(VF=1, P=P, zs=zs_out)
flashes2[:] = [flash_out]
energy_err = H_out_balanced - flash_out.H()
Expand Down
8 changes: 4 additions & 4 deletions thermo/functional_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2829,7 +2829,7 @@ def count_rings_attatched_to_rings(mol, allow_neighbors=True, atom_rings=None):
benzene_smarts = 'c1ccccc1'

def benene_rings(mol):
r'''Given a `rdkit.Chem.rdchem.Mol` object, returns the number of benzene rings
r'''Given a `rdkit.Chem.rdchem.Mol` object, returns the number of benzene rings
in the molecule.
Parameters
Expand Down Expand Up @@ -2914,9 +2914,9 @@ def is_radionuclide(mol):
References
----------
.. [1] Kondev, F. G., M. Wang, W. J. Huang, S. Naimi, and G. Audi.
"The NUBASE2020 Evaluation of Nuclear Physics Properties *."
Chinese Physics C 45, no. 3 (March 2021): 030001.
.. [1] Kondev, F. G., M. Wang, W. J. Huang, S. Naimi, and G. Audi.
"The NUBASE2020 Evaluation of Nuclear Physics Properties *."
Chinese Physics C 45, no. 3 (March 2021): 030001.
https://doi.org/10.1088/1674-1137/abddae.
'''
for atom in mol.GetAtoms():
Expand Down
2 changes: 1 addition & 1 deletion thermo/heat_capacity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1551,7 +1551,7 @@ class HeatCapacityLiquidMixture(MixtureProperty):
ranked_methods = [LALIBERTE, LINEAR]
pure_references = ('HeatCapacityLiquids',)
pure_reference_types = (HeatCapacityLiquid,)

pure_constants = ('MWs', )
custom_args = pure_constants

Expand Down
18 changes: 9 additions & 9 deletions thermo/phases/gibbs_eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

class GibbsEOS(Phase):
# http://www.iapws.org/relguide/Advise3.pdf is useful
def V(self):
def V(self):
return self.dG_dP()
# return self._V

Expand All @@ -41,7 +41,7 @@ def dV_dP(self):
return self.d2G_dP2()

dV_dP_T = dV_dP

def dP_dV(self):
return 1.0/self.d2G_dP2()

Expand All @@ -55,12 +55,12 @@ def dV_dT(self):

def dT_dV(self):
return 1.0/self.d2G_dTdP()

dT_dV_P = dT_dV

def d2V_dT2(self):
return self.d3G_dT2dP()

def d2V_dTdP(self):
return self.d3G_dTdP2()

Expand All @@ -72,7 +72,7 @@ def dP_dT(self):

def dT_dP(self):
return 1.0/self.dP_dT()

dT_dP_V = dT_dP


Expand All @@ -81,10 +81,10 @@ def H(self):

def S(self):
return -self.dG_dT()

def Cp(self):
return -self.T*self.d2G_dT2()

def U(self):
return self.G() - self.T*self.dG_dT() - self.P*self.dG_dP()

Expand All @@ -109,6 +109,6 @@ def d2S_dP2(self):

def d2S_dTdP(self):
return -self.d3G_dT2dP()





28 changes: 14 additions & 14 deletions thermo/phases/iapws_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class IAPWS95(HelmholtzEOS):
Hfs = [-241822.0]
Sfs = [-44.5]
Gfs = [-228554.325]

N = 1
rhoc_inv = rho_to_Vm(rhoc_mass, _MW)
rhoc = 1.0/rhoc_inv
Expand Down Expand Up @@ -756,35 +756,35 @@ def _set_core(self):

tau2 = tau*tau
v0 = pi - pi0
r2 = (v0*(v0*(2.34801409215913e-11 - 2.85651142904972e-11j)
r2 = (v0*(v0*(2.34801409215913e-11 - 2.85651142904972e-11j)
+ (-5.57107698030123e-5 + 4.64578634580806e-5j))
+ (-72.597457432922 - 78.100842711287j))

r2p = (v0*(7.677551608692879e-14-9.340239477516712e-14j)
r2p = (v0*(7.677551608692879e-14-9.340239477516712e-14j)
+ (-9.108171704568459e-08+7.595411065038183e-08j))
g0 = (v0*(v0*(v0*(-5.56464869058991e-22*v0 + 3.39746123271053e-15)
g0 = (v0*(v0*(v0*(-5.56464869058991e-22*v0 + 3.39746123271053e-15)
- 1.89369929326131e-8) + 0.655022213658955) - 632020.233335886)
g0p = (v0*(v0*(-3.6390648292032365e-24*v0 + 1.666356094695489e-17)
- 6.192030151739651e-11) + 0.0010708979275295713)
g0pp = ((-1.7848556441943294e-26*v0 + 5.44866189611331e-20)*v0
g0pp = ((-1.7848556441943294e-26*v0 + 5.44866189611331e-20)*v0
- 1.0123370045204503e-13)


log_t1_tau = logc(t1 + tau)
log_t1_n_tau = logc(t1 - tau)
log_t2_tau = logc(t2 + tau)
log_t2_n_tau = logc(t2 - tau)

log_t1 = logc(t1)
log_t2 = logc(t2)

t2_inv = 1.0/t2
t1_inv = 1.0/t1

tau_t2inv = tau*t2_inv
t2_log_t2 = t2*log_t2
t2_log_t2_2 = t2_log_t2 + t2_log_t2

g_real_sum = (r1*((t1-tau)*log_t1_n_tau + (t1+tau)*log_t1_tau - 2.0*t1*log_t1 - tau2*t1_inv)
+ (r2*((t2-tau)*log_t2_n_tau + (t2+tau)*log_t2_tau - t2_log_t2_2 - tau2*t2_inv))).real
g = g0 - s0*Tt*tau + Tt*g_real_sum
Expand All @@ -798,7 +798,7 @@ def _set_core(self):
g_TT = 0.0036608581051398447*g_TT_real_sum #1.0/Tt*g_TT_real_sum

x0 = (t2-tau)*log_t2_n_tau + (t2+tau)*log_t2_tau - t2_log_t2_2 - tau2*t2_inv

g_P_real_sum = (r2p*(x0)).real
g_P = g0p + Tt*g_P_real_sum
g_PP_real_sum = (self.r2pp*(x0)).real
Expand Down Expand Up @@ -828,19 +828,19 @@ def G(self):

def dG_dT(self):
return self._dG_dT

def d2G_dT2(self):
return self._d2G_dT2

def dG_dP(self):
return self._dG_dP

def d2G_dP2(self):
return self._d2G_dP2

def d2G_dTdP(self):
return self._d2G_dTdP

d2G_dPdT = d2G_dTdP

def P_sub(self):
Expand Down
6 changes: 3 additions & 3 deletions thermo/phases/phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,12 @@ def is_same_model(self, other_phase, ignore_phase=False):
if identical_model_attribute_ids:
if ignore_phase:
return True
return self.__class__.__name__ == other_phase.__class__.__name__
return self.__class__.__name__ == other_phase.__class__.__name__

# Using identities only we could not confirm if the phase was the same or not.
# The values may still be the same if the identities are not.
return self.model_hash(ignore_phase) == other_phase.model_hash(ignore_phase)

def model_hash(self, ignore_phase=False):
r'''Method to compute a hash of a phase.
Expand Down Expand Up @@ -6363,7 +6363,7 @@ def _der(self, property=a, differentiate_by=b, at_constant=c):
# These will probably need their doc fixed
'd2G_dP2', 'd2G_dT2',
'd2G_dPdT', 'd2G_dTdP',

]
derivatives_thermodynamic_mass = []

Expand Down
Loading

0 comments on commit fe78fb9

Please sign in to comment.