@@ -162,45 +162,60 @@ def test_enumerating_constraints(self):
162162 Test that a SpeciesConstraints object can properly enumerate the constraints of a given ErrorCancelingSpecies
163163 """
164164 spcs_consts = SpeciesConstraints (self .benzene , [])
165- assert set (spcs_consts .constraint_map .keys ()) == {"C" , "H" , "C=C" , "C-C" , "C-H" , "6_ring" }
166-
167- # Now that we have confirmed that the correct keys are present, overwrite the constraint map to set the order
168- spcs_consts .constraint_map = {
169- "H" : 0 ,
170- "C" : 1 ,
171- "C=C" : 2 ,
172- "C-C" : 3 ,
173- "C-H" : 4 ,
174- "6_ring" : 5 ,
175- }
165+ benzene_features = spcs_consts ._get_all_constraints (self .benzene )
166+ benzene_constraint_list = [feat .__repr__ () for feat in benzene_features ]
167+ assert set (benzene_constraint_list ) == {"C=C" , "C-C" , "C-H" , "6_ring" }
168+
169+ target_constraints , _ = spcs_consts ._enumerate_constraints ([benzene_features ])
170+ benzene_constraints = target_constraints
176171
177172 assert np .array_equal (
178- spcs_consts . _enumerate_constraints ( self . propene ) ,
179- np .array ([6 , 3 , 1 , 1 , 6 , 0 ]),
173+ benzene_constraints ,
174+ np .array ([1 , 3 , 6 , 3 ]),
180175 )
176+
177+ spcs_consts .all_reference_species = [self .propene ]
178+ propene_features = spcs_consts ._get_all_constraints (self .propene )
179+ _ , reference_constraints = spcs_consts ._enumerate_constraints ([benzene_features , propene_features ])
180+ propene_constraints = reference_constraints [0 ]
181181 assert np .array_equal (
182- spcs_consts . _enumerate_constraints ( self . butane ) ,
183- np .array ([10 , 4 , 0 , 3 , 10 , 0 ]),
182+ propene_constraints ,
183+ np .array ([0 , 1 , 6 , 1 ]),
184184 )
185+
186+ spcs_consts .all_reference_species = [self .butane ]
187+ butane_features = spcs_consts ._get_all_constraints (self .butane )
188+ _ , reference_constraints = spcs_consts ._enumerate_constraints ([benzene_features , butane_features ])
189+ butane_constraints = reference_constraints [0 ]
185190 assert np .array_equal (
186- spcs_consts . _enumerate_constraints ( self . benzene ) ,
187- np .array ([6 , 6 , 3 , 3 , 6 , 1 ]),
191+ butane_constraints ,
192+ np .array ([0 , 3 , 10 , 0 ]),
188193 )
189194
190- # Caffeine and ethyne should return None since they have features not found in benzene
191- assert spcs_consts ._enumerate_constraints (self .caffeine ) is None
192- assert spcs_consts ._enumerate_constraints (self .ethyne ) is None
195+ # Caffeine and ethyne should return empty list since they have features not found in benzene
196+ spcs_consts .all_reference_species = [self .caffeine ]
197+ caffeine_features = spcs_consts ._get_all_constraints (self .caffeine )
198+ _ , reference_constraints = spcs_consts ._enumerate_constraints ([benzene_features , caffeine_features ])
199+ assert len (reference_constraints ) == 0
200+
201+ spcs_consts .all_reference_species = [self .ethyne ]
202+ ethyne_features = spcs_consts ._get_all_constraints (self .ethyne )
203+ _ , reference_constraints = spcs_consts ._enumerate_constraints ([benzene_features , ethyne_features ])
204+ assert len (reference_constraints ) == 0
193205
194206 def test_calculating_constraints (self ):
195207 """
196208 Test that a SpeciesConstraints object can properly return the target constraint vector and the constraint matrix
197209 """
198210 spcs_consts = SpeciesConstraints (self .caffeine , [self .propene , self .butane , self .benzene , self .ethyne ])
199- assert set (spcs_consts .constraint_map .keys ()) == {
200- "H" ,
201- "C" ,
202- "O" ,
203- "N" ,
211+ caffeine_features = spcs_consts ._get_all_constraints (self .caffeine )
212+ propene_features = spcs_consts ._get_all_constraints (self .propene )
213+ butane_features = spcs_consts ._get_all_constraints (self .butane )
214+ benzene_features = spcs_consts ._get_all_constraints (self .benzene )
215+ ethyne_features = spcs_consts ._get_all_constraints (self .ethyne )
216+
217+ caffeine_feature_list = [feat .__repr__ () for feat in caffeine_features ]
218+ assert set (caffeine_feature_list ) == {
204219 "C=O" ,
205220 "C-N" ,
206221 "C-H" ,
@@ -211,36 +226,20 @@ def test_calculating_constraints(self):
211226 "6_ring" ,
212227 }
213228
214- # Now that we have confirmed that the correct keys are present, overwrite the constraint map to set the order
215- spcs_consts .constraint_map = {
216- "H" : 0 ,
217- "C" : 1 ,
218- "O" : 2 ,
219- "N" : 3 ,
220- "C=O" : 4 ,
221- "C-N" : 5 ,
222- "C-H" : 6 ,
223- "C=C" : 7 ,
224- "C=N" : 8 ,
225- "C-C" : 9 ,
226- "5_ring" : 10 ,
227- "6_ring" : 11 ,
228- }
229-
230229 target_consts , consts_matrix = spcs_consts .calculate_constraints ()
231230
232231 # First, test that ethyne is not included in the reference set
233232 assert spcs_consts .reference_species == [self .propene , self .butane , self .benzene ]
234233
235234 # Then, test the output of the calculation
236- assert np .array_equal (target_consts , np .array ([10 , 8 , 2 , 4 , 2 , 10 , 10 , 1 , 1 , 1 , 1 , 1 ]))
235+ assert np .array_equal (target_consts , np .array ([ 1 , 1 , 1 , 10 , 10 , 1 , 1 , 2 , 0 , 8 , 10 , 4 , 2 ]))
237236 assert np .array_equal (
238237 consts_matrix ,
239238 np .array (
240239 [
241- [6 , 3 , 0 , 0 , 0 , 0 , 6 , 1 , 0 , 1 , 0 , 0 ],
242- [10 , 4 , 0 , 0 , 0 , 0 , 10 , 0 , 0 , 3 , 0 , 0 ],
243- [6 , 6 , 0 , 0 , 0 , 0 , 6 , 3 , 0 , 3 , 0 , 1 ],
240+ [ 0 , 0 , 1 , 6 , 0 , 1 , 0 , 0 , 0 , 3 , 6 , 0 , 0 ],
241+ [ 0 , 0 , 3 , 10 , 0 , 0 , 0 , 0 , 0 , 4 , 10 , 0 , 0 ],
242+ [ 0 , 1 , 3 , 6 , 0 , 3 , 0 , 0 , 0 , 6 , 6 , 0 , 0 ],
244243 ]
245244 ),
246245 )
@@ -276,6 +275,8 @@ def test_creating_error_canceling_schemes(self):
276275 scheme = ErrorCancelingScheme (
277276 self .propene ,
278277 [self .butane , self .benzene , self .caffeine , self .ethyne ],
278+ "rc2" ,
279+ True ,
279280 True ,
280281 True ,
281282 )
@@ -326,7 +327,7 @@ def test_multiple_error_canceling_reactions(self):
326327 )
327328
328329 reaction_list = scheme .multiple_error_canceling_reaction_search (n_reactions_max = 20 )
329- assert len (reaction_list ) == 20
330+ assert len (reaction_list ) == 6
330331 reaction_string = reaction_list .__repr__ ()
331332 # Consider both permutations of the products in the reaction string
332333 rxn_str1 = "<ErrorCancelingReaction 1*C=CC + 1*CCCC <=> 1*CCC + 1*C=CCC >"
@@ -359,9 +360,9 @@ def test_calculate_target_enthalpy(self):
359360 )
360361
361362 target_thermo , rxn_list = scheme .calculate_target_enthalpy (n_reactions_max = 3 , milp_software = ["lpsolve" ])
362- assert target_thermo .value_si == 115000 .0
363+ assert target_thermo .value_si == 110000 .0
363364 assert isinstance (rxn_list [0 ], ErrorCancelingReaction )
364365
365366 if self .pyo is not None :
366367 target_thermo , _ = scheme .calculate_target_enthalpy (n_reactions_max = 3 , milp_software = ["pyomo" ])
367- assert target_thermo .value_si == 115000 .0
368+ assert target_thermo .value_si == 110000 .0
0 commit comments