@@ -448,9 +448,20 @@ def test_completed_networks_none(self):
448448 # Check that no networks were added
449449 assert len (rmg .reaction_model .completed_pdep_networks ) == 0
450450
451+
451452class TestWriteInputFile :
452453 """
453- Contains unit test for writing input files
454+ Contains unit test for writing input files for each of the reactor types:
455+
456+ 'simpleReactor': simple_reactor, ✅
457+ 'constantVIdealGasReactor' : constant_V_ideal_gas_reactor,
458+ 'constantTPIdealGasReactor' : constant_TP_ideal_gas_reactor,
459+ 'liquidSurfaceReactor' : liquid_cat_reactor,
460+ 'constantTVLiquidReactor': constant_T_V_liquid_reactor,
461+ 'liquidReactor': liquid_reactor,
462+ 'surfaceReactor': surface_reactor, ✅
463+ 'mbsampledReactor': mb_sampled_reactor,
464+
454465 """
455466 def setup_method (self ):
456467 """This method is run before every test in this class"""
@@ -502,3 +513,90 @@ def test_write_superminimal_input(self):
502513 import os
503514 os .remove (superminimal_output_file )
504515
516+ @pytest .mark .skip (reason = "Slow test that runs a full RMG job" )
517+ def test_write_superminimal_and_run (self ):
518+ """
519+ Test that we can write superminimal input file and then run RMG without errors
520+ """
521+ import os
522+ import shutil
523+
524+
525+ superminimal_input_file = '../../../examples/rmg/superminimal/input.py'
526+ new_run_dir = 'temp_superminimal_run'
527+ os .makedirs (new_run_dir , exist_ok = True )
528+ superminimal_output_file = os .path .join (new_run_dir , 'temp_superminimal_input.py' )
529+
530+
531+ rmg = RMG ()
532+ inp .read_input_file (superminimal_input_file , rmg )
533+ inp .save_input_file (superminimal_output_file , rmg )
534+
535+ # run RMG with the new input file
536+ import subprocess
537+ subprocess .run (['python' , '../../../rmg.py' , superminimal_output_file ], check = True )
538+
539+
540+ # clean up
541+ shutil .rmtree (new_run_dir )
542+
543+
544+ def test_write_min_surf_input (self ):
545+ """
546+ Test that we can write the minimal surface input file and read it back in with the same values.
547+ """
548+
549+ min_surf_input_file = '../../../examples/rmg/minimal_surface/input.py'
550+ min_surf_output_file = 'temp_min_surf_input.py'
551+
552+
553+ rmg = RMG ()
554+ inp .read_input_file (min_surf_input_file , rmg )
555+
556+ # read a bunch of values in from input file to check they are the same after writing
557+ T = rmg .reaction_systems [0 ].T .value_si
558+ P = rmg .reaction_systems [0 ].P_initial .value_si
559+ initialMoleFractions = {k .label : v for k , v in rmg .reaction_systems [0 ].initial_gas_mole_fractions .items ()}
560+ initialSurfaceCoverages = {k .label : v for k , v in rmg .reaction_systems [0 ].initial_surface_coverages .items ()}
561+ for term in rmg .reaction_systems [0 ].termination :
562+ if hasattr (term , 'time' ):
563+ termination_time = term .time .value_si
564+ elif hasattr (term , 'conversion' ):
565+ termination_conversion = term .conversion
566+ termination_converstion_species = term .species .label
567+ elif hasattr (term , 'ratio' ):
568+ termination_ratio = term .ratio
569+
570+ binding_energies = {k : v .value_si for k , v in rmg .binding_energies .items ()}
571+ surface_site_density = rmg .surface_site_density .value_si
572+
573+
574+ inp .save_input_file (min_surf_output_file , rmg )
575+ # read it back in and confirm all the values match
576+ rmg1 = RMG ()
577+ inp .read_input_file (min_surf_output_file , rmg1 )
578+ assert rmg1 .reaction_systems [0 ].T .value_si == T
579+ assert rmg1 .reaction_systems [0 ].P_initial .value_si == P
580+ output_mol_fractions = {k .label : v for k , v in rmg1 .reaction_systems [0 ].initial_gas_mole_fractions .items ()}
581+ assert output_mol_fractions == initialMoleFractions
582+ output_surface_coverages = {k .label : v for k , v in rmg1 .reaction_systems [0 ].initial_surface_coverages .items ()}
583+ assert output_surface_coverages == initialSurfaceCoverages
584+
585+ output_binding_energies = {k : v .value_si for k , v in rmg1 .binding_energies .items ()}
586+ assert output_binding_energies == binding_energies
587+
588+ assert rmg1 .surface_site_density .value_si == surface_site_density
589+
590+ for term in rmg1 .reaction_systems [0 ].termination :
591+ if hasattr (term , 'time' ):
592+ assert term .time .value_si == termination_time
593+ elif hasattr (term , 'conversion' ):
594+ assert term .conversion == termination_conversion
595+ assert term .species .label == termination_converstion_species
596+ elif hasattr (term , 'ratio' ):
597+ assert term .ratio == termination_ratio
598+
599+ # clean up
600+ import os
601+ os .remove (min_surf_output_file )
602+
0 commit comments