def test_check_for_existing_reaction_eliminates_identical_reactions_without_duplicate_flag( self): """ Test that check_for_existing_reaction eliminates reactions with different templates and duplicate=false """ cerm = CoreEdgeReactionModel() # make species' objects spcA = Species().from_smiles('[H]') spcB = Species().from_smiles('C=C[CH2]C') spcC = Species().from_smiles('C=C=CC') spcD = Species().from_smiles('[H][H]') spcA.label = '[H]' spcB.label = 'C=C[CH2]C' spcC.label = 'C=C=CC' spcD.label = '[H][H]' spcB.generate_resonance_structures() cerm.add_species_to_core(spcA) cerm.add_species_to_core(spcB) cerm.add_species_to_core(spcC) cerm.add_species_to_core(spcD) reaction_in_model = TemplateReaction(reactants=[spcA, spcB], products=[spcC, spcD], family='H_Abstraction', template=['Csd', 'H'], duplicate=False) reaction_in_model.reactants.sort() reaction_in_model.products.sort() reaction_to_add = TemplateReaction(reactants=[spcA, spcB], products=[spcC, spcD], family='H_Abstraction', template=['Cs12345', 'H'], duplicate=False) cerm.add_reaction_to_core(reaction_in_model) cerm.register_reaction(reaction_in_model) found, rxn = cerm.check_for_existing_reaction(reaction_to_add) self.assertTrue( found, 'check_for_existing_reaction failed to eliminate reactions without duplicate tag' )
def test_check_for_existing_reaction_eliminates_identical_reactions(self): """ Test that check_for_existing_reaction catches identical reactions. """ cerm = CoreEdgeReactionModel() # make species' objects spcA = Species().from_smiles('[H]') spcB = Species().from_smiles('C=C[CH2]C') spcC = Species().from_smiles('C=C=CC') spcD = Species().from_smiles('[H][H]') spcA.label = '[H]' spcB.label = 'C=C[CH2]C' spcC.label = 'C=C=CC' spcD.label = '[H][H]' spcB.generate_resonance_structures() cerm.add_species_to_core(spcA) cerm.add_species_to_core(spcB) cerm.add_species_to_core(spcC) cerm.add_species_to_core(spcD) reaction_in_model = TemplateReaction(reactants=[spcA, spcB], products=[spcC, spcD], family='H_Abstraction', template=['Csd', 'H']) reaction_in_model.reactants.sort() reaction_in_model.products.sort() reaction_to_add = TemplateReaction(reactants=[spcA, spcB], products=[spcC, spcD], family='H_Abstraction', template=['Csd', 'H']) cerm.add_reaction_to_core(reaction_in_model) cerm.register_reaction(reaction_in_model) found, rxn = cerm.check_for_existing_reaction(reaction_to_add) self.assertTrue( found, 'check_for_existing_reaction failed to identify existing reaction')
def test_thermo_filter_down(self): """ test that thermo_filter_down with maximum_edge_species = 1 reduces the edge to one species """ cerm = CoreEdgeReactionModel() spcs = [ Species().from_smiles('[OH]'), Species().from_smiles('C'), Species().from_smiles('[CH3]'), Species().from_smiles('[CH2]'), Species().from_smiles('O') ] for spc in spcs: cerm.make_new_species(spc, label=spc.molecule[0].to_smiles()) spc.label = spc.molecule[0].to_smiles() thermo_dict = { '[OH]': NASA(polynomials=[ NASAPolynomial(coeffs=[ 3.51457, 2.92787e-05, -5.32168e-07, 1.0195e-09, -3.85947e-13, 3414.25, 2.10435 ], Tmin=(100, 'K'), Tmax=(1145.75, 'K')), NASAPolynomial(coeffs=[ 3.07194, 0.000604014, -1.39775e-08, -2.13448e-11, 2.48067e-15, 3579.39, 4.578 ], Tmin=(1145.75, 'K'), Tmax=(5000, 'K')) ], Tmin=(100, 'K'), Tmax=(5000, 'K'), E0=(28.3945, 'kJ/mol'), Cp0=(29.1007, 'J/(mol*K)'), CpInf=(37.4151, 'J/(mol*K)'), label="""OH(D)""", comment="""Thermo library: primaryThermoLibrary"""), 'C': NASA(polynomials=[ NASAPolynomial(coeffs=[ 4.20541, -0.00535551, 2.51121e-05, -2.1376e-08, 5.97513e-12, -10161.9, -0.921259 ], Tmin=(100, 'K'), Tmax=(1084.13, 'K')), NASAPolynomial(coeffs=[ 0.908298, 0.011454, -4.57171e-06, 8.29185e-10, -5.66309e-14, -9719.99, 13.9929 ], Tmin=(1084.13, 'K'), Tmax=(5000, 'K')) ], Tmin=(100, 'K'), Tmax=(5000, 'K'), E0=(-84.435, 'kJ/mol'), Cp0=(33.2579, 'J/(mol*K)'), CpInf=(108.088, 'J/(mol*K)'), label="""CH4""", comment="""Thermo library: primaryThermoLibrary"""), '[CH3]': NASA(polynomials=[ NASAPolynomial(coeffs=[ 3.67359, 0.00201095, 5.73022e-06, -6.87117e-09, 2.54386e-12, 16445, 1.60456 ], Tmin=(200, 'K'), Tmax=(1000, 'K')), NASAPolynomial(coeffs=[ 2.28572, 0.0072399, -2.98714e-06, 5.95685e-10, -4.67154e-14, 16775.6, 8.48007 ], Tmin=(1000, 'K'), Tmax=(3500, 'K')) ], Tmin=(200, 'K'), Tmax=(3500, 'K'), E0=(136.42, 'kJ/mol'), Cp0=(33.2579, 'J/(mol*K)'), CpInf=(83.1447, 'J/(mol*K)'), label="""CH3""", comment="""Thermo library: GRI-Mech3.0"""), '[CH2]': NASA(polynomials=[ NASAPolynomial(coeffs=[ 4.01192, -0.000154978, 3.26298e-06, -2.40422e-09, 5.69497e-13, 45867.7, 0.533201 ], Tmin=(100, 'K'), Tmax=(1104.62, 'K')), NASAPolynomial(coeffs=[ 3.14983, 0.00296674, -9.76056e-07, 1.54115e-10, -9.50338e-15, 46058.1, 4.77808 ], Tmin=(1104.62, 'K'), Tmax=(5000, 'K')) ], Tmin=(100, 'K'), Tmax=(5000, 'K'), E0=(381.37, 'kJ/mol'), Cp0=(33.2579, 'J/(mol*K)'), CpInf=(58.2013, 'J/(mol*K)'), label="""CH2(T)""", comment="""Thermo library: primaryThermoLibrary"""), 'O': NASA(polynomials=[ NASAPolynomial(coeffs=[ 4.05764, -0.000787936, 2.90877e-06, -1.47519e-09, 2.12842e-13, -30281.6, -0.311364 ], Tmin=(100, 'K'), Tmax=(1130.24, 'K')), NASAPolynomial(coeffs=[ 2.84325, 0.00275109, -7.81031e-07, 1.07244e-10, -5.79392e-15, -29958.6, 5.91042 ], Tmin=(1130.24, 'K'), Tmax=(5000, 'K')) ], Tmin=(100, 'K'), Tmax=(5000, 'K'), E0=(-251.755, 'kJ/mol'), Cp0=(33.2579, 'J/(mol*K)'), CpInf=(58.2013, 'J/(mol*K)'), label="""H2O""", comment="""Thermo library: primaryThermoLibrary"""), } for spc in spcs[:3]: cerm.add_species_to_core(spc) reaction = TemplateReaction(reactants=[spcs[0], spcs[2]], products=[spcs[-1], spcs[-2]], degeneracy=1, reversible=True, family='H_Abstraction') cerm.process_new_reactions(new_reactions=[reaction], new_species=[]) # add CH2 and O to edge for spc in cerm.core.species + cerm.edge.species: spc.thermo = thermo_dict[ spc.molecule[0].to_smiles()] # assign thermo cerm.set_thermodynamic_filtering_parameters( Tmax=300.0, thermo_tol_keep_spc_in_edge=1000.0, min_core_size_for_prune=0, maximum_edge_species=1, reaction_systems=[]) difset = set([ x.molecule[0].to_smiles() for x in cerm.edge.species ]) - set([x.molecule[0].to_smiles() for x in cerm.core.species]) self.assertEquals( len(difset), 2) # no change because toleranceThermoKeepSpeciesInEdge is high cerm.thermo_filter_down(maximum_edge_species=1) difset = set([ x.molecule[0].to_smiles() for x in cerm.edge.species ]) - set([x.molecule[0].to_smiles() for x in cerm.core.species]) self.assertEquals( len(difset), 1 ) # should be one because we thermo filtered down to one edge species