99
1010
1111def yesno (question ):
12- """Simple Yes/No Function, Ruben's code """
12+ """Simple Yes/No Function, From Volcanic """
1313 prompt = f"{ question } ? (y/n): "
1414 ans = input (prompt ).strip ().lower ()
1515 if ans not in ["y" , "n" ]:
@@ -21,7 +21,6 @@ def yesno(question):
2121
2222
2323def check_existence (wdir , verb ):
24-
2524 kinetic_mode = False
2625 k_exist = False
2726
@@ -35,10 +34,10 @@ def check_existence(wdir, verb):
3534 c0_exist = any ([last_row_index .lower () in rows_to_search ])
3635 k_exist = all ([column in df .columns for column in columns_to_search ])
3736 if not (c0_exist ):
38- logging .critical ("Initial concentration not found in rxn_network.csv" )
37+ logging .critical ("Initial concentration not found in rxn_network.csv. " )
3938
4039 else :
41- logging .critical ("rxn_network.csv not found" )
40+ logging .critical ("rxn_network.csv not found. " )
4241
4342 filename = f"{ wdir } reaction_data"
4443 extensions = [".csv" , ".xls" , ".xlsx" ]
@@ -47,21 +46,21 @@ def check_existence(wdir, verb):
4746
4847 if energy_exist :
4948 if verb > 2 :
50- print ("reaction_data file exists " )
49+ print ("Found reaction data file. " )
5150 if k_exist :
52- print ("Both energy data and rate constants are provided" )
51+ print ("Both energy data and rate constants are provided. " )
5352 else :
5453 if k_exist :
55- print ("reaction_data file not found, but rate constants are provided" )
54+ print ("reaction_data file not found, but rate constants are provided. " )
5655 else :
5756 logging .critical (
58- "reaction_data file not found and rate constants are not provided"
57+ "reaction_data file not found and rate constants are not provided. "
5958 )
6059
6160 if os .path .exists (f"{ wdir } kinetic_data.csv" ) or os .path .exists (
6261 f"{ wdir } kinetic_data.xlsx"
6362 ):
64- kinetic_mode = yesno ("kinetic_profile.csv exists, toggle to kinetic mode?" )
63+ kinetic_mode = yesno ("kinetic_profile.csv exists, toggle the kinetic mode?" )
6564
6665 return kinetic_mode
6766
@@ -86,9 +85,9 @@ def check_km_inp(df, df_network, mode="energy"):
8685 if last_row_index .lower () in ["initial_conc" , "c0" , "initial conc" ]:
8786 initial_conc = df_network .iloc [- 1 :].to_numpy ()[0 ]
8887 df_network = df_network .drop (df_network .index [- 1 ])
89- logging .info ("Initial conditions found" )
88+ logging .info ("Initial conditions found. " )
9089 else :
91- logging .critical ("Initial conditions not found" )
90+ logging .critical ("Initial conditions not found. " )
9291
9392 states_network = df_network .columns .to_numpy ()[:]
9493 states_profile = df .columns .to_numpy ()[1 :]
@@ -116,19 +115,19 @@ def check_km_inp(df, df_network, mode="energy"):
116115 clear = False
117116 logging .warning (
118117 f"""\n { state } cannot be found in the reaction data, if it is in different name,
119- change it to be the same in both reaction data and the network"""
118+ change it to be the same in both reaction data and the network. """
120119 )
121120 elif mode == "kinetic" :
122121 if int ((df .shape [1 ] - 1 ) / 2 ) != df_network .shape [0 ]:
123122 clear = False
124123 logging .critical (
125- "Number of rate constants in the profile doesn't match with number of steps in the network input"
124+ "Number of rate constants in the profile doesn't match with number of steps in the network input. "
126125 )
127126
128127 # initial conc
129128 if len (states_network ) != len (initial_conc ):
130129 clear = False
131- logging .warning ("\n Your initial conc seems wrong" )
130+ logging .warning ("\n Your initial conc seems wrong. " )
132131
133132 # check network sanity
134133 mask = (~ df_network .isin ([- 1 , 1 ])).all (axis = 1 )
@@ -143,21 +142,20 @@ def check_km_inp(df, df_network, mode="energy"):
143142 if np .any (mask_R ):
144143 clear = False
145144 logging .warning (
146- f"\n The reactant location: { states_network [r_indices [mask_R ]]} appears wrong"
145+ f"\n The reactant location: { states_network [r_indices [mask_R ]]} appears wrong. "
147146 )
148147
149148 mask_P = (~ df_network .iloc [:, p_indices ].isin ([1 ])).all (axis = 0 ).to_numpy ()
150149 if np .any (mask_P ):
151150 clear = False
152151 logging .warning (
153- f"\n The product location: { states_network [p_indices [mask_P ]]} appears wrong"
152+ f"\n The product location: { states_network [p_indices [mask_P ]]} appears wrong. "
154153 )
155154
156155 return clear
157156
158157
159158def preprocess_data_mkm (arguments , mode ):
160-
161159 parser = argparse .ArgumentParser (
162160 prog = "mikimo" ,
163161 description = "Perform microkinetic simulations and generate microkinetic volcano plots for homogeneous catalytic reactions." ,
@@ -295,7 +293,7 @@ def preprocess_data_mkm(arguments, mode):
295293 type = int ,
296294 default = 1 ,
297295 help = """Run mode (default: 1)
298- 0: Run mkm for every profile in the input.
296+ 0: Run mkm for every profile in the reaction data input.
2992971: Construct microkinetic volcano plot.
3002982: Construct microkinetic activity/selectivity map.
301299 """ ,
@@ -361,24 +359,24 @@ def preprocess_data_mkm(arguments, mode):
361359
362360 if t_finals is None :
363361 if verb > 0 :
364- print ("No time input, use the default value of 54800 s (1d)" )
362+ print ("No time input, use the default value of 54800 s (1d). " )
365363 t_finals = 54800
366364 elif len (t_finals ) == 1 :
367365 t_finals = t_finals [0 ]
368366 elif len (t_finals ) > 1 :
369367 if verb > 0 :
370- print ("t_final is a range, use the first value" )
368+ print ("t_final is a range, use the first value. " )
371369 t_finals = t_finals [0 ]
372370
373371 if temperatures is None :
374372 if verb > 0 :
375- print ("No temperature input, use the default value of 298.15 K" )
373+ print ("No temperature input, use the default value of 298.15 K. " )
376374 temperatures = 298.15
377375 elif len (temperatures ) == 1 :
378376 temperatures = temperatures [0 ]
379377 elif len (temperatures ) > 1 :
380378 if verb > 0 :
381- print ("temperature is a range, use the first value" )
379+ print ("Temperature input is a range, use the first value. " )
382380 temperatures = temperatures [0 ]
383381
384382 rnx = f"{ wdir } /rxn_network.csv"
@@ -424,10 +422,10 @@ def preprocess_data_mkm(arguments, mode):
424422 clear = check_km_inp (df , df_network )
425423
426424 if not (clear ):
427- print ("\n Recheck your reaction network and your reaction data\n " )
425+ print ("\n Recheck your reaction network and your reaction data. \n " )
428426 else :
429427 if verb > 0 :
430- print ("\n KM input is clear \n " )
428+ print ("\n MKM inputs are clean \n " )
431429 return (
432430 dg ,
433431 df_network ,
@@ -486,16 +484,16 @@ def preprocess_data_mkm(arguments, mode):
486484 df = pd .read_csv (filename_csv )
487485 clear = check_km_inp (df , df_network )
488486 if not (clear ):
489- print ("\n Recheck your reaction network and your reaction data\n " )
487+ print ("\n Recheck your reaction network and your reaction data. \n " )
490488 else :
491489 if verb > 0 :
492- print ("\n KM inputs are clear \n " )
490+ print ("\n MKM inputs are clean. \n " )
493491
494492 tags = np .array ([str (tag ) for tag in df .columns [1 :]], dtype = object )
495493 if ncore == - 1 :
496494 ncore = multiprocessing .cpu_count ()
497495 if verb > 2 :
498- print (f"Use { ncore } cores for parallel computing" )
496+ print (f"Use { ncore } cores for parallel computing. " )
499497
500498 if plotmode == 0 and comp_ci :
501499 plotmode = 1
@@ -603,10 +601,10 @@ def preprocess_data_mkm(arguments, mode):
603601 clear = check_km_inp (df , df_network )
604602
605603 if not (clear ):
606- print ("\n Recheck your reaction network and your reaction data\n " )
604+ print ("\n Recheck your reaction network and your reaction data. \n " )
607605 else :
608606 if verb > 0 :
609- print ("\n KM inputs are clear \n " )
607+ print ("\n MKM inputs are clean \n " )
610608 return (
611609 dg ,
612610 df_network ,
@@ -629,7 +627,7 @@ def process_data_mkm(
629627 dg : np .ndarray , df_network : pd .DataFrame , tags : List [str ], states : List [str ]
630628) -> Tuple [np .ndarray , List [np .ndarray ], List [float ], List [np .ndarray ], np .ndarray ]:
631629 """
632- Processes data for kinetic modeling.
630+ Processes data for micokinetic modeling.
633631
634632 Args:
635633 dg (numpy.array): free energy profile.
@@ -722,7 +720,7 @@ def process_data_mkm(
722720
723721
724722def test_process_data_mkm ():
725- # Test data
723+ """test data processor"""
726724 dg = np .array (
727725 [
728726 0.0 ,
@@ -828,9 +826,13 @@ def test_process_data_mkm():
828826 )
829827
830828 # Test the function
831- initial_conc , energy_profile_all , dgr_all , coeff_TS_all , rxn_network_all = process_data_mkm (
832- dg , df_network , tags , states
833- )
829+ (
830+ initial_conc ,
831+ energy_profile_all ,
832+ dgr_all ,
833+ coeff_TS_all ,
834+ rxn_network_all ,
835+ ) = process_data_mkm (dg , df_network , tags , states )
834836
835837 # Compare the results
836838 assert np .array_equal (initial_conc , initial_conc_expected )
0 commit comments