@@ -933,3 +933,45 @@ def test_write_constantTVLiquidReactor_and_run(self):
933933
934934 # clean up
935935 shutil .rmtree (new_run_dir )
936+
937+ def test_MBSampledReactor_write (self ):
938+ """
939+ Test that we can write MB sampled reactor input file and read it back in with the same values.
940+ Note that the MBSampledReactor is not intended to be used with a standard RMG job, so there's no point in running it as a test
941+ """
942+
943+ mbsampled_input_file = '../../../rmgpy/tools/data/sim/mbSampled/input.py'
944+ mbsampled_output_file = 'temp_mbsampled_input.py'
945+
946+ rmg = RMG ()
947+ inp .read_input_file (mbsampled_input_file , rmg )
948+
949+ # read a bunch of values in from input file to check they are the same after writing
950+ T = rmg .reaction_systems [0 ].T .value_si
951+ P = rmg .reaction_systems [0 ].P .value_si
952+ sampling_rate = rmg .reaction_systems [0 ].k_sampling .value_si
953+
954+ initialMoleFractions = {k .label : v for k , v in rmg .reaction_systems [0 ].initial_mole_fractions .items ()}
955+
956+ for term in rmg .reaction_systems [0 ].termination :
957+ if hasattr (term , 'time' ):
958+ termination_time = term .time .value_si
959+
960+ inp .save_input_file (mbsampled_output_file , rmg )
961+ # read it back in and confirm all the values match
962+ rmg1 = RMG ()
963+ inp .read_input_file (mbsampled_output_file , rmg1 )
964+ assert rmg1 .reaction_systems [0 ].T .value_si == T
965+ assert rmg1 .reaction_systems [0 ].P .value_si == P
966+ assert rmg1 .reaction_systems [0 ].k_sampling .value_si == sampling_rate
967+
968+ new_initialMoleFractions = {k .label : v for k , v in rmg1 .reaction_systems [0 ].initial_mole_fractions .items ()}
969+ assert pytest .approx (new_initialMoleFractions , rel = 1e-4 ) == initialMoleFractions
970+
971+ for term in rmg1 .reaction_systems [0 ].termination :
972+ if hasattr (term , 'time' ):
973+ assert term .time .value_si == termination_time
974+
975+ # clean up
976+ import os
977+ os .remove (mbsampled_output_file )
0 commit comments