8080from rmgpy .tools .plot import plot_sensitivity
8181from rmgpy .tools .uncertainty import Uncertainty , process_local_results
8282from rmgpy .yml import RMSWriter
83- from rmgpy .rmg .reactors import Reactor
83+ from rmgpy .rmg .reactionmechanismsimulator_reactors import Reactor as RMSReactor
84+ from rmgpy .rmg .reactionmechanismsimulator_reactors import NO_JULIA
8485
8586################################################################################
8687
@@ -507,6 +508,12 @@ def initialize(self, **kwargs):
507508
508509 # Read input file
509510 self .load_input (self .input_file )
511+
512+ # Check if ReactionMechanismSimulator reactors are being used
513+ # if RMS is not installed but the user attempted to use it, the load_input_file would have failed
514+ # if RMS is installed but they did not use it, we can avoid extra work
515+ # if RMS is not installed and they did not use it, we avoid calling certain functions that would raise an error
516+ requires_rms = any (isinstance (reactor_system , RMSReactor ) for reactor_system in self .reaction_systems )
510517
511518 if kwargs .get ("restart" , "" ):
512519 import rmgpy .rmg .input
@@ -550,10 +557,10 @@ def initialize(self, **kwargs):
550557 self .load_database ()
551558
552559 for spec in self .initial_species :
553- self .reaction_model .add_species_to_edge (spec )
560+ self .reaction_model .add_species_to_edge (spec , requires_rms = requires_rms )
554561
555562 for reaction_system in self .reaction_systems :
556- if isinstance (reaction_system , Reactor ):
563+ if not NO_JULIA and isinstance (reaction_system , RMSReactor ):
557564 reaction_system .finish_termination_criteria ()
558565
559566 # Load restart seed mechanism (if specified)
@@ -618,12 +625,12 @@ def initialize(self, **kwargs):
618625 # Seed mechanisms: add species and reactions from seed mechanism
619626 # DON'T generate any more reactions for the seed species at this time
620627 for seed_mechanism in self .seed_mechanisms :
621- self .reaction_model .add_seed_mechanism_to_core (seed_mechanism , react = False )
628+ self .reaction_model .add_seed_mechanism_to_core (seed_mechanism , react = False , requires_rms = requires_rms )
622629
623630 # Reaction libraries: add species and reactions from reaction library to the edge so
624631 # that RMG can find them if their rates are large enough
625632 for library , option in self .reaction_libraries :
626- self .reaction_model .add_reaction_library_to_edge (library )
633+ self .reaction_model .add_reaction_library_to_edge (library , requires_rms = requires_rms )
627634
628635 # Also always add in a few bath gases (since RMG-Java does)
629636 for label , smiles in [("Ar" , "[Ar]" ), ("He" , "[He]" ), ("Ne" , "[Ne]" ), ("N2" , "N#N" )]:
@@ -695,35 +702,35 @@ def initialize(self, **kwargs):
695702 # This is necessary so that the PDep algorithm can identify the bath gas
696703 for spec in self .initial_species :
697704 if not spec .reactive :
698- self .reaction_model .enlarge (spec )
705+ self .reaction_model .enlarge (spec , requires_rms = requires_rms )
699706 for spec in self .initial_species :
700707 if spec .reactive :
701- self .reaction_model .enlarge (spec )
708+ self .reaction_model .enlarge (spec , requires_rms = requires_rms )
702709
703710 # chatelak: store constant SPC indices in the reactor attributes if any constant SPC provided in the input file
704711 # advantages to write it here: this is run only once (as species indexes does not change over the generation)
705712 if self .solvent is not None :
706713 for index , reaction_system in enumerate (self .reaction_systems ):
707- if (
708- not isinstance (reaction_system , Reactor ) and reaction_system .const_spc_names is not None
709- ): # if no constant species provided do nothing
714+ if ((NO_JULIA or not isinstance (reaction_system , RMSReactor )) and reaction_system .const_spc_names is not None ): # if no constant species provided do nothing
710715 reaction_system .get_const_spc_indices (self .reaction_model .core .species ) # call the function to identify indices in the solver
711716
712717 self .initialize_reaction_threshold_and_react_flags ()
713718 if self .filter_reactions and self .init_react_tuples :
714- self .react_init_tuples ()
719+ self .react_init_tuples (requires_rms = requires_rms )
715720 self .reaction_model .initialize_index_species_dict ()
716721
717722 self .initialize_seed_mech ()
723+ return requires_rms
718724
719- def register_listeners (self ):
725+ def register_listeners (self , requires_rms = False ):
720726 """
721727 Attaches listener classes depending on the options
722728 found in the RMG input file.
723729 """
724730
725731 self .attach (ChemkinWriter (self .output_directory ))
726- self .attach (RMSWriter (self .output_directory ))
732+ if not NO_JULIA and requires_rms :
733+ self .attach (RMSWriter (self .output_directory ))
727734
728735 if self .generate_output_html :
729736 self .attach (OutputHTMLWriter (self .output_directory ))
@@ -735,7 +742,7 @@ def register_listeners(self):
735742
736743 if self .save_simulation_profiles :
737744 for index , reaction_system in enumerate (self .reaction_systems ):
738- if isinstance (reaction_system , Reactor ):
745+ if not NO_JULIA and requires_rms and isinstance (reaction_system , RMSReactor ):
739746 typ = type (reaction_system )
740747 raise InputError (f"save_simulation_profiles=True not compatible with reactor of type { typ } " )
741748 reaction_system .attach (SimulationProfileWriter (self .output_directory , index , self .reaction_model .core .species ))
@@ -749,10 +756,10 @@ def execute(self, initialize=True, **kwargs):
749756 """
750757
751758 if initialize :
752- self .initialize (** kwargs )
759+ requires_rms = self .initialize (** kwargs )
753760
754761 # register listeners
755- self .register_listeners ()
762+ self .register_listeners (requires_rms = requires_rms )
756763
757764 self .done = False
758765
@@ -779,7 +786,7 @@ def execute(self, initialize=True, **kwargs):
779786 # Update react flags
780787 if self .filter_reactions :
781788 # Run the reaction system to update threshold and react flags
782- if isinstance (reaction_system , Reactor ):
789+ if not NO_JULIA and requires_rms and isinstance (reaction_system , RMSReactor ):
783790 self .update_reaction_threshold_and_react_flags (
784791 rxn_sys_unimol_threshold = np .zeros ((len (self .reaction_model .core .species ),), bool ),
785792 rxn_sys_bimol_threshold = np .zeros ((len (self .reaction_model .core .species ), len (self .reaction_model .core .species )), bool ),
@@ -822,6 +829,7 @@ def execute(self, initialize=True, **kwargs):
822829 unimolecular_react = self .unimolecular_react ,
823830 bimolecular_react = self .bimolecular_react ,
824831 trimolecular_react = self .trimolecular_react ,
832+ requires_rms = requires_rms ,
825833 )
826834
827835 if not np .isinf (self .model_settings_list [0 ].thermo_tol_keep_spc_in_edge ):
@@ -834,7 +842,7 @@ def execute(self, initialize=True, **kwargs):
834842 )
835843
836844 if not np .isinf (self .model_settings_list [0 ].thermo_tol_keep_spc_in_edge ):
837- self .reaction_model .thermo_filter_down (maximum_edge_species = self .model_settings_list [0 ].maximum_edge_species )
845+ self .reaction_model .thermo_filter_down (maximum_edge_species = self .model_settings_list [0 ].maximum_edge_species , requires_rms = requires_rms )
838846
839847 logging .info ("Completed initial enlarge edge step.\n " )
840848
@@ -900,7 +908,7 @@ def execute(self, initialize=True, **kwargs):
900908 prune = False
901909
902910 try :
903- if isinstance (reaction_system , Reactor ):
911+ if not NO_JULIA and requires_rms and isinstance (reaction_system , RMSReactor ):
904912 (
905913 terminated ,
906914 resurrected ,
@@ -993,7 +1001,7 @@ def execute(self, initialize=True, **kwargs):
9931001
9941002 # Add objects to enlarge to the core first
9951003 for objectToEnlarge in objects_to_enlarge :
996- self .reaction_model .enlarge (objectToEnlarge )
1004+ self .reaction_model .enlarge (objectToEnlarge , requires_rms = requires_rms )
9971005
9981006 if model_settings .filter_reactions :
9991007 # Run a raw simulation to get updated reaction system threshold values
@@ -1002,7 +1010,7 @@ def execute(self, initialize=True, **kwargs):
10021010 temp_model_settings .tol_keep_in_edge = 0
10031011 if not resurrected :
10041012 try :
1005- if isinstance (reaction_system , Reactor ):
1013+ if not NO_JULIA and requires_rms and isinstance (reaction_system , RMSReactor ):
10061014 (
10071015 terminated ,
10081016 resurrected ,
@@ -1071,7 +1079,7 @@ def execute(self, initialize=True, **kwargs):
10711079 skip_update = True ,
10721080 )
10731081 logging .warning (
1074- "Reaction thresholds/flags for Reaction System {0} was not updated due " " to resurrection" .format (index + 1 )
1082+ "Reaction thresholds/flags for Reaction System {0} was not updated due to resurrection" .format (index + 1 )
10751083 )
10761084
10771085 logging .info ("" )
@@ -1094,13 +1102,14 @@ def execute(self, initialize=True, **kwargs):
10941102 unimolecular_react = self .unimolecular_react ,
10951103 bimolecular_react = self .bimolecular_react ,
10961104 trimolecular_react = self .trimolecular_react ,
1105+ requires_rms = requires_rms ,
10971106 )
10981107
10991108 if old_edge_size != len (self .reaction_model .edge .reactions ) or old_core_size != len (self .reaction_model .core .reactions ):
11001109 reactor_done = False
11011110
11021111 if not np .isinf (self .model_settings_list [0 ].thermo_tol_keep_spc_in_edge ):
1103- self .reaction_model .thermo_filter_down (maximum_edge_species = model_settings .maximum_edge_species )
1112+ self .reaction_model .thermo_filter_down (maximum_edge_species = model_settings .maximum_edge_species , requires_rms = requires_rms )
11041113
11051114 max_num_spcs_hit = len (self .reaction_model .core .species ) >= model_settings .max_num_species
11061115
@@ -1127,6 +1136,7 @@ def execute(self, initialize=True, **kwargs):
11271136 model_settings .tol_move_to_core ,
11281137 model_settings .maximum_edge_species ,
11291138 model_settings .min_species_exist_iterations_for_prune ,
1139+ requires_rms = requires_rms ,
11301140 )
11311141 # Perform garbage collection after pruning
11321142 collected = gc .collect ()
@@ -1891,7 +1901,7 @@ def initialize_reaction_threshold_and_react_flags(self):
18911901 if self .trimolecular :
18921902 self .trimolecular_react [:num_restart_spcs , :num_restart_spcs , :num_restart_spcs ] = False
18931903
1894- def react_init_tuples (self ):
1904+ def react_init_tuples (self , requires_rms = False ):
18951905 """
18961906 Reacts tuples given in the react block
18971907 """
@@ -1924,6 +1934,7 @@ def react_init_tuples(self):
19241934 unimolecular_react = self .unimolecular_react ,
19251935 bimolecular_react = self .bimolecular_react ,
19261936 trimolecular_react = self .trimolecular_react ,
1937+ requires_rms = requires_rms ,
19271938 )
19281939
19291940 def update_reaction_threshold_and_react_flags (
@@ -2218,7 +2229,7 @@ def __init__(self, reaction_system, bspc):
22182229 if isinstance (value , list ):
22192230 self .Ranges [key ] = [v .value_si for v in value ]
22202231
2221- if isinstance (reaction_system , Reactor ):
2232+ if not NO_JULIA and isinstance (reaction_system , RMSReactor ):
22222233 self .tmax = reaction_system .tf
22232234 else :
22242235 for term in reaction_system .termination :
0 commit comments