def test_multiple_error_canceling_reactions(self): """ Test that multiple error canceling reactions can be found """ scheme = IsodesmicScheme(self.propene, [ self.propane, self.butane, self.butene, self.pentane, self.pentene, self.hexane, self.hexene, self.benzene ]) reaction_list = scheme.multiple_error_canceling_reaction_search( n_reactions_max=20) self.assertEqual(len(reaction_list), 20) reaction_string = reaction_list.__repr__() # Consider both permutations of the products in the reaction string rxn_str1 = '<ErrorCancelingReaction 1*C=CC + 1*CCCC <=> 1*CCC + 1*C=CCC >' rxn_str2 = '<ErrorCancelingReaction 1*C=CC + 1*CCCC <=> 1*C=CCC + 1*CCC >' self.assertTrue( any(rxn_string in reaction_string for rxn_string in [rxn_str1, rxn_str2])) if self.pyo is not None: # pyomo is slower, so don't test as many reaction_list = scheme.multiple_error_canceling_reaction_search( n_reactions_max=5, milp_software=['pyomo']) self.assertEqual(len(reaction_list), 5) reaction_string = reaction_list.__repr__() self.assertTrue( any(rxn_string in reaction_string for rxn_string in [rxn_str1, rxn_str2]))
def test_calculate_target_enthalpy(self): """ Test that ErrorCancelingScheme is able to calculate thermochemistry for the target species """ scheme = IsodesmicScheme(self.propene, [self.propane, self.butane, self.butene, self.pentane, self.pentene, self.hexane, self.hexene, self.benzene]) target_thermo, rxn_list = scheme.calculate_target_enthalpy(n_reactions_max=3, milp_software=['lpsolve']) self.assertEqual(target_thermo.value_si, 115000.0) self.assertIsInstance(rxn_list[0], ErrorCancelingReaction) if self.pyo is not None: target_thermo, _ = scheme.calculate_target_enthalpy(n_reactions_max=3, milp_software=['pyomo']) self.assertEqual(target_thermo.value_si, 115000.0)
def test_find_error_canceling_reaction(self): """ Test that the MILP problem can be solved to find a single isodesmic reaction """ scheme = IsodesmicScheme(self.propene, [self.propane, self.butane, self.butene, self.caffeine, self.ethyne]) # Note that caffeine and ethyne will not be allowed, so for the full set the indices are [0, 1, 2] rxn, _ = scheme._find_error_canceling_reaction([0, 1, 2], milp_software=['lpsolve']) self.assertEqual(rxn.species[self.butane], -1) self.assertEqual(rxn.species[self.propane], 1) self.assertEqual(rxn.species[self.butene], 1) if self.pyo is not None: rxn, _ = scheme._find_error_canceling_reaction([0, 1, 2], milp_software=['pyomo']) self.assertEqual(rxn.species[self.butane], -1) self.assertEqual(rxn.species[self.propane], 1) self.assertEqual(rxn.species[self.butene], 1)
def test_creating_error_canceling_schemes(self): scheme = ErrorCancelingScheme(self.propene, [self.butane, self.benzene, self.caffeine, self.ethyne], True, True) self.assertEqual(scheme.reference_species, [self.butane]) isodesmic_scheme = IsodesmicScheme(self.propene, [self.butane, self.benzene, self.caffeine, self.ethyne]) self.assertEqual(isodesmic_scheme.reference_species, [self.butane, self.benzene])