@@ -237,6 +237,54 @@ def test_uncertainty_assignment(self):
237237 assert np .isclose (thermo_covariance , expected_uncorrelated_thermo_uncertainties , rtol = 1e-4 ).all ()
238238 assert np .isclose (kinetic_covariance , expected_uncorrelated_kinetic_uncertainties , rtol = 1e-4 ).all ()
239239
240+ def test_source_correlations (self ):
241+ # Check some examples of different species containing the same sources
242+
243+ # ------------------------------------------------------------------------------
244+ # Make sure CH3 (Library + Radical) has a library index/value in common with CH4
245+ i_CH4 = rmgpy .tools .uncertainty .get_i_thing (rmgpy .species .Species (smiles = 'C' ), self .uncertainty .species_list )
246+ assert i_CH4 >= 0
247+
248+ i_CH3 = rmgpy .tools .uncertainty .get_i_thing (rmgpy .species .Species (smiles = '[CH3]' ), self .uncertainty .species_list )
249+ assert i_CH3 >= 0
250+
251+ self .uncertainty .extract_sources_from_model ()
252+ self .uncertainty .assign_parameter_uncertainties (correlated = True )
253+
254+ src1 = self .uncertainty .species_sources_dict [self .uncertainty .species_list [i_CH4 ]] # CH4
255+ src2 = self .uncertainty .species_sources_dict [self .uncertainty .species_list [i_CH3 ]] # CH3
256+
257+ assert 'Library' in src1
258+ assert 'Library' in src2
259+ assert 'GAV' in src2
260+ assert src1 ['Library' ] == src2 ['Library' ] # make sure they refer to the same library source
261+
262+ # -----------------------------------------------------------------------------
263+ # Make sure CH3X (Library + GAV + Adsorption Correction) has a library index/value in common with CH4 (Library)
264+ i_CH3X = rmgpy .tools .uncertainty .get_i_thing (rmgpy .species .Species (smiles = 'C*' ), self .uncertainty .species_list )
265+ assert i_CH3X == - 1
266+ # This is not in the model, so add it to the species list
267+ CH3X = rmgpy .species .Species (smiles = 'C*' )
268+ CH3X .thermo = self .uncertainty .database .thermo .get_thermo_data (CH3X )
269+ self .uncertainty .species_list .append (CH3X )
270+ try :
271+ i_CH3X = rmgpy .tools .uncertainty .get_i_thing (CH3X , self .uncertainty .species_list )
272+ assert i_CH3X >= 0
273+
274+ self .uncertainty .extract_sources_from_model ()
275+ self .uncertainty .assign_parameter_uncertainties (correlated = True )
276+
277+ src1 = self .uncertainty .species_sources_dict [self .uncertainty .species_list [i_CH4 ]] # CH4
278+ src2 = self .uncertainty .species_sources_dict [self .uncertainty .species_list [i_CH3X ]] # CH3X
279+
280+ assert 'Library' in src1
281+ assert 'Library' in src2
282+ assert 'ADS' in src2
283+ assert 'GAV' in src2
284+ assert src1 ['Library' ] == src2 ['Library' ] # make sure they refer to the same library source
285+ finally :
286+ self .uncertainty .species_list .pop () # remove the extra species so it doesn't affect other tests
287+
240288 def test_local_analysis (self ):
241289 """
242290 Test to run uncorrelated and then correlated local_analysis and make sure the results are expected
0 commit comments