@@ -79,7 +79,6 @@ def launch_workflow(config):
7979 workflow = AutoTSWorkflow (config = config )
8080 workflow .run_workflow ()
8181
82-
8382def main ():
8483 """
8584 Main function for command-line execution.
@@ -104,8 +103,8 @@ def main():
104103 parser .add_argument (
105104 "-ma" , "--manual_AFIR" ,
106105 nargs = "*" ,
107- required = False ,
108- help = "Manual AFIR parameters for Step 1 (e.g., 150 6 8 150 1 9)"
106+ required = False , # <-- This is no longer strictly required at parse time
107+ help = "Manual AFIR parameters for Step 1 (e.g., 150 6 8 150 1 9). Overrides config file. "
109108 )
110109 parser .add_argument (
111110 "-osp" , "--software_path_file" ,
@@ -140,7 +139,7 @@ def main():
140139 # --- 1. Load Base Configuration from File ---
141140 workflow_config = load_config_from_file (args .config_file )
142141
143- # --- 2. Override Config with CMD Arguments ---
142+ # --- 2. Override Config with CMD Arguments (Except AFIR) ---
144143 workflow_config ["initial_mol_file" ] = args .input_file
145144 workflow_config ["software_path_file_source" ] = os .path .abspath (args .software_path_file )
146145 workflow_config ["skip_step1" ] = args .skip_step1
@@ -150,21 +149,42 @@ def main():
150149 if args .top_n is not None :
151150 workflow_config ["top_n_candidates" ] = args .top_n
152151
153- # --- Validation ---
154- if not args .skip_step1 and not args .skip_to_step4 and not args .manual_AFIR :
155- print ("\n Error: The -ma/--manual_AFIR argument is required unless skipping Step 1 or Step 4." )
156- sys .exit (1 )
157-
158- if args .manual_AFIR :
159- workflow_config ["step1_settings" ]["manual_AFIR" ] = args .manual_AFIR
160- elif not args .skip_step1 and not args .skip_to_step4 :
161- # Ensure 'manual_AFIR' key exists if running Step 1
162- workflow_config .setdefault ("step1_settings" , {})["manual_AFIR" ] = []
163-
164- # --- 3. Call the launcher function ---
152+ # --- 3. NEW: AFIR Validation and Handling ---
153+
154+ # Ensure 'step1_settings' key exists to avoid errors
155+ workflow_config .setdefault ("step1_settings" , {})
156+
157+ is_running_step1 = not args .skip_step1 and not args .skip_to_step4
158+
159+ # Check if AFIR is defined in the loaded config
160+ # Use .get() to safely check for the key, default to None if not present
161+ config_has_afir = workflow_config ["step1_settings" ].get ("manual_AFIR" )
162+
163+ # Check if AFIR is provided on the command line
164+ cmd_has_afir = args .manual_AFIR is not None
165+
166+ if is_running_step1 :
167+ if cmd_has_afir :
168+ # Case 1: CMD argument is given. It *always* overrides the config.
169+ workflow_config ["step1_settings" ]["manual_AFIR" ] = args .manual_AFIR
170+ print (f"Using 'manual_AFIR' from command line (overrides config): { args .manual_AFIR } " )
171+
172+ elif config_has_afir :
173+ # Case 2: CMD argument is NOT given, but config *has* AFIR.
174+ # This is your desired behavior. We just print a confirmation.
175+ print (f"Using 'manual_AFIR' from config file: { config_has_afir } " )
176+ # No action needed, the value is already loaded.
177+
178+ else :
179+ # Case 3: Running Step 1, but no AFIR in config OR command line.
180+ # This is an error.
181+ print ("\n Error: 'manual_AFIR' is not defined in the config file and was not provided via -ma." )
182+ print (" Please add 'manual_AFIR' to your JSON or use the -ma argument." )
183+ sys .exit (1 )
184+
185+ # --- 4. Call the launcher function ---
165186 launch_workflow (workflow_config )
166187
167-
168188if __name__ == "__main__" :
169189 main ()
170190
0 commit comments