Skip to content

Commit f4bbc2e

Browse files
committed
fix uncertainty whitespace/linting errors
1 parent 64fa3d1 commit f4bbc2e

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

rmgpy/tools/uncertainty.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def __init__(self, dG_library=1.5, dG_QM=3.0, dG_GAV=1.5, dG_group=0.1, dG_ADS_c
4747
"""
4848
Initialize the different uncertainties dG_library, dG_QM, dG_GAV, and dG_other with set values
4949
in units of kcal/mol.
50-
50+
5151
We expect a uniform distribution for some species free energy G in [Gmin, Gmax].
5252
dG = (Gmax-Gmin)/2
5353
"""
@@ -82,7 +82,7 @@ def get_uncertainty_value(self, source):
8282
def get_partial_uncertainty_value(self, source, corr_source_type, corr_param=None, corr_group_type=None):
8383
"""
8484
Obtain the partial uncertainty dG/dG_corr*dG_corr, where dG_corr is the correlated parameter
85-
85+
8686
`corr_param` is the parameter identifier itself, which is a integer for QM and library parameters, or a string for group values
8787
`corr_source_type` is a string, being either 'Library', 'QM', 'GAV', 'ADS', or 'Estimation'
8888
`corr_group_type` is a string used only when the source type is 'GAV' and indicates grouptype
@@ -135,11 +135,12 @@ def get_partial_uncertainty_value(self, source, corr_source_type, corr_param=Non
135135
def get_uncertainty_factor(self, source):
136136
"""
137137
Retrieve the uncertainty factor f in kcal/mol when the source of the thermo of a species is given.
138-
138+
139139
This is equivalent to sqrt(3)*dG in a uniform uncertainty interval
140140
"""
141141
dG = self.get_uncertainty_value(source)
142142
f = np.sqrt(3) * dG
143+
return f
143144

144145

145146
class KineticParameterUncertainty(object):
@@ -151,7 +152,7 @@ def __init__(self, dlnk_library=0.5, dlnk_training=0.5, dlnk_pdep=2.0, dlnk_fami
151152
dlnk_rule=0.5, dlnk_Surface_Library=2.659, dlnk_family_surface=2.659):
152153
"""
153154
Initialize the different uncertainties dlnk
154-
155+
155156
We expect a uniform distribution for some reaction kinetics about ln(k0) in [ln(kmin), ln(kmax)].
156157
dlnk = (ln(kmax)-ln(kmin))/2
157158
"""
@@ -181,7 +182,7 @@ def get_uncertainty_value(self, source):
181182
elif 'Training' in source:
182183
# Should be a single training reaction
183184
# Although some training entries may be used in reverse,
184-
# We still consider the kinetics to be directly dependent
185+
# We still consider the kinetics to be directly dependent
185186
dlnk += self.dlnk_training
186187
elif 'Rate Rules' in source:
187188
family_label = source['Rate Rules'][0]
@@ -231,7 +232,7 @@ def get_uncertainty_value(self, source):
231232
def get_partial_uncertainty_value(self, source, corr_source_type, corr_param=None, corr_family=None):
232233
"""
233234
Obtain the partial uncertainty dlnk/dlnk_corr*dlnk_corr, where dlnk_corr is the correlated parameter
234-
235+
235236
`corr_param` is the parameter identifier itself, which is the string identifier of the rate rule
236237
`corr_source_type` is a string, being either 'Rate Rules', 'Library', 'PDep', 'Training' or 'Estimation'
237238
`corr_family` is a string used only when the source type is 'Rate Rules' and indicates the family
@@ -303,11 +304,12 @@ def get_partial_uncertainty_value(self, source, corr_source_type, corr_param=Non
303304
def get_uncertainty_factor(self, source):
304305
"""
305306
Retrieve the uncertainty factor f when the source of the reaction kinetics are given.
306-
307+
307308
This is equivalent to sqrt(3)/ln(10) * dlnk in a uniform uncertainty interval
308309
"""
309310
dlnk = self.get_uncertainty_value(source)
310311
f = np.sqrt(3) / np.log(10) * dlnk
312+
return f
311313

312314

313315
class Uncertainty(object):
@@ -340,16 +342,16 @@ def __init__(self, species_list=None, reaction_list=None, output_directory=''):
340342
if not os.path.exists(self.output_directory):
341343
try:
342344
os.makedirs(self.output_directory)
343-
except:
345+
except OSError:
344346
raise Exception('Uncertainty output directory could not be created.')
345347

346348
def load_database(self, kinetics_families='all', kinetics_depositories=None, thermo_libraries=None, reaction_libraries=None):
347349
"""
348350
This function loads a single copy of the RMGDatabase with full verbose averaging
349-
of the rate rule to trace kinetics sources.
350-
351+
of the rate rule to trace kinetics sources.
352+
351353
By default, this function loads all the kinetics families, only the training kinetics depository,
352-
the primaryThermoLibrary, and no reaction libraries.
354+
the primaryThermoLibrary, and no reaction libraries.
353355
"""
354356
from rmgpy.data.rmg import RMGDatabase
355357
from rmgpy import settings
@@ -380,7 +382,7 @@ def load_model(self, chemkin_path, dictionary_path, transport_path=None, surface
380382
"""
381383
Load a RMG-generated model into the Uncertainty class
382384
`chemkin_path`: path to the chem_annotated.inp CHEMKIN mechanism
383-
`dictionary_path`: path to the species_dictionary.txt file
385+
`dictionary_path`: path to the species_dictionary.txt file
384386
`transport_path`: path to the tran.dat file (optional)
385387
386388
Then create dictionaries stored in self.thermoGroups and self.rateRules
@@ -457,7 +459,7 @@ def extract_sources_from_model(self):
457459
# We must retrieve the original saturated molecule's thermo instead of using the radical species as the source of thermo
458460
saturated_species, ignore_spc = self.retrieve_saturated_species_from_list(species)
459461

460-
if ignore_spc: # this is saturated species that isn't in the actual model
462+
if ignore_spc: # this is saturated species that isn't in the actual model
461463
self.extra_species.append(saturated_species)
462464

463465
if 'Library' in source:
@@ -729,7 +731,7 @@ def sensitivity_analysis(self, initial_mole_fractions, sensitive_species, T, P,
729731
sensitivity_threshold=1e-3, number=10, fileformat='.png'):
730732
"""
731733
Run sensitivity analysis using the RMG solver in a single ReactionSystem object
732-
734+
733735
initial_mole_fractions is a dictionary with Species objects as keys and mole fraction initial conditions
734736
sensitive_species is a list of sensitive Species objects
735737
number is the number of top species thermo or reaction kinetics desired to be plotted
@@ -798,7 +800,7 @@ def local_analysis(self, sensitive_species, reaction_system_index=0, correlated=
798800
output = {}
799801
for sens_species in sensitive_species:
800802
csvfile_path = os.path.join(self.output_directory, 'solver',
801-
'sensitivity_{0}_SPC_{1}.csv'.format(reaction_system_index+1,
803+
'sensitivity_{0}_SPC_{1}.csv'.format(reaction_system_index + 1,
802804
sens_species.index))
803805
time, data_list = parse_csv_data(csvfile_path)
804806
# Assign uncertainties
@@ -855,7 +857,7 @@ def local_analysis(self, sensitive_species, reaction_system_index=0, correlated=
855857
# Add the reaction index to the data label of the reaction uncertainties
856858
# data.index stores the physical index of the reaction + 1, so we convert it to the RMG index here
857859
for data in reaction_data_list:
858-
data.label = 'k' + str(self.reaction_list[data.index-1].index) + ': ' + data.label.split()[-1]
860+
data.label = 'k' + str(self.reaction_list[data.index - 1].index) + ': ' + data.label.split()[-1]
859861

860862
if correlated:
861863
folder = os.path.join(self.output_directory, 'correlated')

0 commit comments

Comments
 (0)