@@ -447,3 +447,58 @@ def test_completed_networks_none(self):
447447
448448 # Check that no networks were added
449449 assert len (rmg .reaction_model .completed_pdep_networks ) == 0
450+
451+ class TestWriteInputFile :
452+ """
453+ Contains unit test for writing input files
454+ """
455+ def setup_method (self ):
456+ """This method is run before every test in this class"""
457+ global rmg
458+ rmg .reaction_systems = []
459+
460+
461+ def test_write_superminimal_input (self ):
462+ """
463+ Test that we can write superminimal input file and read it back in with the same values.
464+ """
465+
466+ superminimal_input_file = '../../../examples/rmg/superminimal/input.py'
467+ superminimal_output_file = 'temp_superminimal_input.py'
468+
469+
470+ rmg = RMG ()
471+ inp .read_input_file (superminimal_input_file , rmg )
472+
473+ # read a bunch of values in from input file to check they are the same after writing
474+ T = rmg .reaction_systems [0 ].T .value_si
475+ P = rmg .reaction_systems [0 ].P .value_si
476+ initialMoleFractions = {k .label : v for k , v in rmg .reaction_systems [0 ].initial_mole_fractions .items ()}
477+ for term in rmg .reaction_systems [0 ].termination :
478+ if hasattr (term , 'time' ):
479+ termination_time = term .time .value_si
480+ elif hasattr (term , 'conversion' ):
481+ termination_conversion = term .conversion
482+ termination_converstion_species = term .species .label
483+
484+
485+
486+ inp .save_input_file (superminimal_output_file , rmg )
487+ # read it back in and confirm all the values match
488+ rmg1 = RMG ()
489+ inp .read_input_file (superminimal_output_file , rmg1 )
490+ assert rmg1 .reaction_systems [0 ].T .value_si == T
491+ assert rmg1 .reaction_systems [0 ].P .value_si == P
492+ output_mol_fractions = {k .label : v for k , v in rmg1 .reaction_systems [0 ].initial_mole_fractions .items ()}
493+ assert output_mol_fractions == initialMoleFractions
494+ for term in rmg1 .reaction_systems [0 ].termination :
495+ if hasattr (term , 'time' ):
496+ assert term .time .value_si == termination_time
497+ elif hasattr (term , 'conversion' ):
498+ assert term .conversion == termination_conversion
499+ assert term .species .label == termination_converstion_species
500+
501+ # clean up
502+ import os
503+ os .remove (superminimal_output_file )
504+
0 commit comments