Skip to content

Commit

Permalink
Added command-line arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-drews committed Jun 24, 2024
1 parent 5e5b6be commit 321d2b9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/acom_music_box/goMusicBox.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
python music_box_main.py
python music_box_main.py homeDir="C:\\2024\MusicBox\music-box\\tests\\configs\\analytical_config\\"
7 changes: 1 addition & 6 deletions src/acom_music_box/music_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,7 @@ def solve(self, path_to_output = None):
next_output_time = curr_time
#runs the simulation at each timestep

music_box_logger.progress("solve03 path_to_output = {}".format(path_to_output))


while(curr_time <= self.box_model_options.simulation_length):

#outputs to output_array if enough time has elapsed
Expand Down Expand Up @@ -518,9 +516,7 @@ def solve(self, path_to_output = None):

else:
next_conditions = None

music_box_logger.progress("solve033 species_constant_ordering = {}".format(species_constant_ordering))



#updates M accordingly
if 'M' in species_constant_ordering:
Expand All @@ -529,7 +525,6 @@ def solve(self, path_to_output = None):
GAS_CONSTANT = BOLTZMANN_CONSTANT * AVOGADRO_CONSTANT
ordered_concentrations[species_constant_ordering['M']] = curr_conditions.pressure / (GAS_CONSTANT * curr_conditions.temperature)

music_box_logger.progress("solve035 args = {} {} {} {} {}".format(self.box_model_options.chem_step_time, curr_conditions.temperature, curr_conditions.pressure, ordered_concentrations, ordered_rate_constants))
#solves and updates concentration values in concentration array
if (not ordered_concentrations):
music_box_logger.progress("Warning: ordered_concentrations list is empty.")
Expand Down
6 changes: 1 addition & 5 deletions src/acom_music_box/music_box_logger.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sys

# Class Logger is included here for completeness,
# but not used because progress() is such a lighweight function.
# but not used because progress() is such a lightweight function.
class Logger:
"""
Logs messages to the console, which can then be captured to a log file.
Expand All @@ -15,10 +15,6 @@ def __init__(self):
Args:
name (str): The name of the reaction.
reaction_type (str): The type of the reaction.
reactants (List[Reactant]): A list of Reactant instances representing the reactants. Default is an empty list.
products (List[Product]): A list of Product instances representing the products. Default is an empty list.
scaling_factor (float, optional): A scaling factor for the reaction rate. Defaults to None.
"""
pass

Expand Down
30 changes: 28 additions & 2 deletions src/acom_music_box/music_box_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,40 @@



# Retrieve named arguments from the command line and
# return in a dictionary of keywords.
# argPairs = list of arguments, probably from sys.argv
# named arguments are formatted like this=3.14159
# return dictionary of keywords and values
def getArgsDictionary(argPairs):
argDict = {}

for argPair in argPairs:
# the arguments are: arg=value
pairValue = argPair.split('=')
if (len(pairValue) < 2):
argDict[pairValue[0]] = None
continue

argDict[pairValue[0]] = pairValue[1]

return(argDict)



if __name__ == "__main__":
music_box_logger.progress("{}".format(__file__))
music_box_logger.progress("Start time: {}".format(datetime.datetime.now()))

music_box_logger.progress("Hello, MusicBox World!")

# set up the home configuration directory TODO: Make this a command-line argument.
musicBoxHomeDir = "C:\\2024\\MusicBox\\music-box\\tests\\configs\\analytical_config\\"
# retrieve and parse the command-line arguments
myArgs = getArgsDictionary(sys.argv)

# set up the home configuration directory
musicBoxHomeDir = "music-box\\tests\\configs\\analytical_config\\" # default
if ("homeDir" in myArgs):
musicBoxHomeDir = myArgs.get("homeDir")

# create and load a MusicBox object
myBox = MusicBox()
Expand Down

0 comments on commit 321d2b9

Please sign in to comment.