From 3dff7d4af94201d7fc837e2eb2fb90287294c9ab Mon Sep 17 00:00:00 2001 From: AdityaSavara <39929571+AdityaSavara@users.noreply.github.com> Date: Tue, 16 Aug 2022 15:24:21 -0400 Subject: [PATCH 1/8] improving movies images filenames --- kmcos/run/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/kmcos/run/__init__.py b/kmcos/run/__init__.py index 72454801..8a460b07 100644 --- a/kmcos/run/__init__.py +++ b/kmcos/run/__init__.py @@ -837,9 +837,10 @@ class KMC_Model(Process): os.mkdir('exported_movie_images') image_folder = './exported_movie_images' # os.chdir(image_folder) + digitsLength = len(str(frames)) #we will need to add some zeros to get the images in order. for i in range(frames): self.do_steps(steps) - self.export_picture(filename = image_folder + "/" + filename + str(i), resolution = resolution, scale = scale) + self.export_picture(filename = image_folder + "/" + filename + str(i).zfill(digitsLength), resolution = resolution, scale = scale) #os.chdir("..") image_files = [os.path.join(image_folder,img) for img in os.listdir(image_folder) if img.endswith(".png")] clip = moviepy.video.io.ImageSequenceClip.ImageSequenceClip(image_files, fps=fps) -- GitLab From 33fc0fc770a380a827787da0508360250cac172a Mon Sep 17 00:00:00 2001 From: AdityaSavara <39929571+AdityaSavara@users.noreply.github.com> Date: Tue, 16 Aug 2022 15:24:50 -0400 Subject: [PATCH 2/8] Update installation.rst --- doc/source/installation/installation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/installation/installation.rst b/doc/source/installation/installation.rst index 5e6e5239..93ce1a7a 100644 --- a/doc/source/installation/installation.rst +++ b/doc/source/installation/installation.rst @@ -51,7 +51,7 @@ The easiest way to install kmcos is to use one of the automatic installers:: bash install-kmcos-linux-venv.bash #use 'bash install-kmcos-linux-user.bash' if you are not using a venv. #For the develop branch, use install-kmcos-linux-venv-develop.bash or install-kmcos-linux-user-develop.bash -For personal computer usage (not on a supercomputer), it is a good idea to also run the following command, which will add the kmcos viewer:: +For personal computer usage (not on a supercomputer), it is a good idea to also run the following command, which will add the kmcos viewer and movie maker:: bash install-kmcos-complete-linux-venv-Ubuntu20.bash #this is for Ubuntu20. There is also an Ubuntu18 version. -- GitLab From fe70ed2eb8157895039c5e01dce9a0c08079374a Mon Sep 17 00:00:00 2001 From: AdityaSavara <39929571+AdityaSavara@users.noreply.github.com> Date: Tue, 16 Aug 2022 15:25:15 -0400 Subject: [PATCH 3/8] Update __init__.py --- kmcos/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kmcos/__init__.py b/kmcos/__init__.py index e378a8ea..b4c04ebb 100644 --- a/kmcos/__init__.py +++ b/kmcos/__init__.py @@ -50,7 +50,7 @@ from __future__ import print_function -__version__ = "0.0.75" +__version__ = "0.0.76" VERSION = __version__ def evaluate_param_expression(param, parameters={}): -- GitLab From 0b6cd1908f816a22ccfb7aee8cc9c2a87cb94c33 Mon Sep 17 00:00:00 2001 From: AdityaSavara <39929571+AdityaSavara@users.noreply.github.com> Date: Tue, 16 Aug 2022 16:36:54 -0400 Subject: [PATCH 4/8] Update MyFirstThrottling.py --- examples/MyFirstThrottling/MyFirstThrottling.py | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/MyFirstThrottling/MyFirstThrottling.py b/examples/MyFirstThrottling/MyFirstThrottling.py index 1a954fc0..e66c9dc3 100644 --- a/examples/MyFirstThrottling/MyFirstThrottling.py +++ b/examples/MyFirstThrottling/MyFirstThrottling.py @@ -322,3 +322,4 @@ kmc_model.add_process(**temporary_kwargs_dictionary) kmc_model.filename = model_name + ".xml" kmc_model.save_model() +kmcos.compile(kmc_model) \ No newline at end of file -- GitLab From ff414632f6d959d9652741bb1598d6947a129882 Mon Sep 17 00:00:00 2001 From: AdityaSavara <39929571+AdityaSavara@users.noreply.github.com> Date: Tue, 16 Aug 2022 17:08:25 -0400 Subject: [PATCH 5/8] improvement in export_import_library.py --- .../export_import_library.py | 17 +++++++++++++++-- .../export_import_library.py | 17 +++++++++++++++-- .../export_import_library.py | 2 +- .../export_import_library.py | 17 +++++++++++++++-- .../export_import_library.py | 2 +- .../export_import_library.py | 17 +++++++++++++++-- 6 files changed, 62 insertions(+), 10 deletions(-) diff --git a/examples/MyFirstTPD_DesorptionOnly_local_smart/export_import_library.py b/examples/MyFirstTPD_DesorptionOnly_local_smart/export_import_library.py index 8beb3d77..fe29e884 100644 --- a/examples/MyFirstTPD_DesorptionOnly_local_smart/export_import_library.py +++ b/examples/MyFirstTPD_DesorptionOnly_local_smart/export_import_library.py @@ -23,7 +23,7 @@ class module_export_import: with open(self.save_filename, 'wt') as f: for module_var in module_vars: module_var_val = getattr(self.module, module_var) - if type(module_var_val) is str: + if (type(module_var_val) == type('str')) or (type(module_var_val) == type(b'str')): # We need to make sure string values get printed as string # values or they won't be read properly on reload f.write(module_var + " = '" + str(module_var_val) + "'\n") @@ -61,7 +61,20 @@ class module_export_import: module_var_val = module_var_val.strip() # Convert to an actual Python object - module_var_val = ast.literal_eval(module_var_val) + # Workaround for sets as literal_eval can't handle them in + # Python 2.7 + if 'set' in module_var_val: + # Extract the bracketed portion which can be converted into + # a list + module_var_val = module_var_val[4:-1] + + # Convert to a list + module_var_val = ast.literal_eval(module_var_val) + + # Convert list to a set + module_var_val = set(module_var_val) + else: + module_var_val = ast.literal_eval(module_var_val) # Store it in the module setattr(self.module, module_var, module_var_val) diff --git a/examples/MyFirstTPD_Precovered_local_smart/export_import_library.py b/examples/MyFirstTPD_Precovered_local_smart/export_import_library.py index b9869b27..fe29e884 100644 --- a/examples/MyFirstTPD_Precovered_local_smart/export_import_library.py +++ b/examples/MyFirstTPD_Precovered_local_smart/export_import_library.py @@ -23,7 +23,7 @@ class module_export_import: with open(self.save_filename, 'wt') as f: for module_var in module_vars: module_var_val = getattr(self.module, module_var) - if type(module_var_val) is str or type(module_var_val) is str: + if (type(module_var_val) == type('str')) or (type(module_var_val) == type(b'str')): # We need to make sure string values get printed as string # values or they won't be read properly on reload f.write(module_var + " = '" + str(module_var_val) + "'\n") @@ -61,7 +61,20 @@ class module_export_import: module_var_val = module_var_val.strip() # Convert to an actual Python object - module_var_val = ast.literal_eval(module_var_val) + # Workaround for sets as literal_eval can't handle them in + # Python 2.7 + if 'set' in module_var_val: + # Extract the bracketed portion which can be converted into + # a list + module_var_val = module_var_val[4:-1] + + # Convert to a list + module_var_val = ast.literal_eval(module_var_val) + + # Convert list to a set + module_var_val = set(module_var_val) + else: + module_var_val = ast.literal_eval(module_var_val) # Store it in the module setattr(self.module, module_var, module_var_val) diff --git a/examples/MyFirstThrottling/MyFirstThrottling_local_smart/export_import_library.py b/examples/MyFirstThrottling/MyFirstThrottling_local_smart/export_import_library.py index 8581f870..fe29e884 100644 --- a/examples/MyFirstThrottling/MyFirstThrottling_local_smart/export_import_library.py +++ b/examples/MyFirstThrottling/MyFirstThrottling_local_smart/export_import_library.py @@ -23,7 +23,7 @@ class module_export_import: with open(self.save_filename, 'wt') as f: for module_var in module_vars: module_var_val = getattr(self.module, module_var) - if type(module_var_val) is str or type(module_var_val) is str: + if (type(module_var_val) == type('str')) or (type(module_var_val) == type(b'str')): # We need to make sure string values get printed as string # values or they won't be read properly on reload f.write(module_var + " = '" + str(module_var_val) + "'\n") diff --git a/examples/MyThirdTPR_local_smart/export_import_library.py b/examples/MyThirdTPR_local_smart/export_import_library.py index 8beb3d77..fe29e884 100644 --- a/examples/MyThirdTPR_local_smart/export_import_library.py +++ b/examples/MyThirdTPR_local_smart/export_import_library.py @@ -23,7 +23,7 @@ class module_export_import: with open(self.save_filename, 'wt') as f: for module_var in module_vars: module_var_val = getattr(self.module, module_var) - if type(module_var_val) is str: + if (type(module_var_val) == type('str')) or (type(module_var_val) == type(b'str')): # We need to make sure string values get printed as string # values or they won't be read properly on reload f.write(module_var + " = '" + str(module_var_val) + "'\n") @@ -61,7 +61,20 @@ class module_export_import: module_var_val = module_var_val.strip() # Convert to an actual Python object - module_var_val = ast.literal_eval(module_var_val) + # Workaround for sets as literal_eval can't handle them in + # Python 2.7 + if 'set' in module_var_val: + # Extract the bracketed portion which can be converted into + # a list + module_var_val = module_var_val[4:-1] + + # Convert to a list + module_var_val = ast.literal_eval(module_var_val) + + # Convert list to a set + module_var_val = set(module_var_val) + else: + module_var_val = ast.literal_eval(module_var_val) # Store it in the module setattr(self.module, module_var, module_var_val) diff --git a/tests/MyFirstThrottling/MyFirstThrottling_local_smart/export_import_library.py b/tests/MyFirstThrottling/MyFirstThrottling_local_smart/export_import_library.py index 8581f870..fe29e884 100644 --- a/tests/MyFirstThrottling/MyFirstThrottling_local_smart/export_import_library.py +++ b/tests/MyFirstThrottling/MyFirstThrottling_local_smart/export_import_library.py @@ -23,7 +23,7 @@ class module_export_import: with open(self.save_filename, 'wt') as f: for module_var in module_vars: module_var_val = getattr(self.module, module_var) - if type(module_var_val) is str or type(module_var_val) is str: + if (type(module_var_val) == type('str')) or (type(module_var_val) == type(b'str')): # We need to make sure string values get printed as string # values or they won't be read properly on reload f.write(module_var + " = '" + str(module_var_val) + "'\n") diff --git a/tests/SQERTSS_unit_tests/throttling_test_reaction_local_smart/export_import_library.py b/tests/SQERTSS_unit_tests/throttling_test_reaction_local_smart/export_import_library.py index b9869b27..fe29e884 100644 --- a/tests/SQERTSS_unit_tests/throttling_test_reaction_local_smart/export_import_library.py +++ b/tests/SQERTSS_unit_tests/throttling_test_reaction_local_smart/export_import_library.py @@ -23,7 +23,7 @@ class module_export_import: with open(self.save_filename, 'wt') as f: for module_var in module_vars: module_var_val = getattr(self.module, module_var) - if type(module_var_val) is str or type(module_var_val) is str: + if (type(module_var_val) == type('str')) or (type(module_var_val) == type(b'str')): # We need to make sure string values get printed as string # values or they won't be read properly on reload f.write(module_var + " = '" + str(module_var_val) + "'\n") @@ -61,7 +61,20 @@ class module_export_import: module_var_val = module_var_val.strip() # Convert to an actual Python object - module_var_val = ast.literal_eval(module_var_val) + # Workaround for sets as literal_eval can't handle them in + # Python 2.7 + if 'set' in module_var_val: + # Extract the bracketed portion which can be converted into + # a list + module_var_val = module_var_val[4:-1] + + # Convert to a list + module_var_val = ast.literal_eval(module_var_val) + + # Convert list to a set + module_var_val = set(module_var_val) + else: + module_var_val = ast.literal_eval(module_var_val) # Store it in the module setattr(self.module, module_var, module_var_val) -- GitLab From 861e1a394b1cfbfdc4f3def59df196d38f3a5c0e Mon Sep 17 00:00:00 2001 From: AdityaSavara <39929571+AdityaSavara@users.noreply.github.com> Date: Tue, 16 Aug 2022 17:49:04 -0400 Subject: [PATCH 6/8] improving commenting about updating rate constants --- .../runfile2_TPD_desorptionOnlyWithExportImport.py | 2 +- examples/MyFirstTPD_Precovered_local_smart/runfile1.py | 2 +- examples/MyFirstTPD_Precovered_local_smart/runfile1b.py | 2 +- examples/MyFirstTPD_Precovered_local_smart/runfile2.py | 2 +- examples/MyFirstTPD_Precovered_local_smart/runfile3.py | 2 +- examples/MyFirstTPD_Precovered_local_smart/runfile4.py | 4 ++-- examples/MyFirstTPD_Precovered_local_smart/runfile5.py | 2 +- examples/MyFirstTPD_Precovered_local_smart/runfile6.py | 2 +- examples/MyThirdTPR_local_smart/runfile.py | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/MyFirstTPD_DesorptionOnly_local_smart/runfile2_TPD_desorptionOnlyWithExportImport.py b/examples/MyFirstTPD_DesorptionOnly_local_smart/runfile2_TPD_desorptionOnlyWithExportImport.py index 5c41d856..8487056c 100644 --- a/examples/MyFirstTPD_DesorptionOnly_local_smart/runfile2_TPD_desorptionOnlyWithExportImport.py +++ b/examples/MyFirstTPD_DesorptionOnly_local_smart/runfile2_TPD_desorptionOnlyWithExportImport.py @@ -166,7 +166,7 @@ if load_simulation_state: # The following assignment (and similar assignments elsewhere) is *magical*. # It invokes a hidden __setattr__ method of the Model_Parameters class that # calls the set_rate_constants() function to update the values of the rate - # constants in the Fortran base module. Any other kind of assignment will + # constants in the Fortran base module. Any other syntax of assignment will # require an explicit call to set_rate_constants(). *Failure to update the # rate constants in the Fortran module will result in wrong results!* T = T_initial + T_ramp * (kmc_time - kmc_time_tpdinit) diff --git a/examples/MyFirstTPD_Precovered_local_smart/runfile1.py b/examples/MyFirstTPD_Precovered_local_smart/runfile1.py index 8a0dc9f8..f1b1b864 100644 --- a/examples/MyFirstTPD_Precovered_local_smart/runfile1.py +++ b/examples/MyFirstTPD_Precovered_local_smart/runfile1.py @@ -64,7 +64,7 @@ if load_simulation_state: # The following assignment (and similar assignments elsewhere) is *magical*. # It invokes a hidden __setattr__ method of the Model_Parameters class that # calls the set_rate_constants() function to update the values of the rate - # constants in the Fortran base module. Any other kind of assignment will + # constants in the Fortran base module. Any other syntax of assignment will # require an explicit call to set_rate_constants(). *Failure to update the # rate constants in the Fortran module will result in wrong results!* T = Ti + beta * (sg.kmc_time) diff --git a/examples/MyFirstTPD_Precovered_local_smart/runfile1b.py b/examples/MyFirstTPD_Precovered_local_smart/runfile1b.py index 472f34f1..35e2197b 100644 --- a/examples/MyFirstTPD_Precovered_local_smart/runfile1b.py +++ b/examples/MyFirstTPD_Precovered_local_smart/runfile1b.py @@ -64,7 +64,7 @@ if load_simulation_state: # The following assignment (and similar assignments elsewhere) is *magical*. # It invokes a hidden __setattr__ method of the Model_Parameters class that # calls the set_rate_constants() function to update the values of the rate - # constants in the Fortran base module. Any other kind of assignment will + # constants in the Fortran base module. Any other syntax of assignment will # require an explicit call to set_rate_constants(). *Failure to update the # rate constants in the Fortran module will result in wrong results!* T = Ti + beta * (sg.kmc_time) diff --git a/examples/MyFirstTPD_Precovered_local_smart/runfile2.py b/examples/MyFirstTPD_Precovered_local_smart/runfile2.py index 02f10e7b..f107f48d 100644 --- a/examples/MyFirstTPD_Precovered_local_smart/runfile2.py +++ b/examples/MyFirstTPD_Precovered_local_smart/runfile2.py @@ -63,7 +63,7 @@ if load_simulation_state: # The following assignment (and similar assignments elsewhere) is *magical*. # It invokes a hidden __setattr__ method of the Model_Parameters class that # calls the set_rate_constants() function to update the values of the rate - # constants in the Fortran base module. Any other kind of assignment will + # constants in the Fortran base module. Any other syntax of assignment will # require an explicit call to set_rate_constants(). *Failure to update the # rate constants in the Fortran module will result in wrong results!* T = Ti + beta * (sg.kmc_time) diff --git a/examples/MyFirstTPD_Precovered_local_smart/runfile3.py b/examples/MyFirstTPD_Precovered_local_smart/runfile3.py index 70dccede..ddf40a88 100644 --- a/examples/MyFirstTPD_Precovered_local_smart/runfile3.py +++ b/examples/MyFirstTPD_Precovered_local_smart/runfile3.py @@ -64,7 +64,7 @@ if load_simulation_state: # The following assignment (and similar assignments elsewhere) is *magical*. # It invokes a hidden __setattr__ method of the Model_Parameters class that # calls the set_rate_constants() function to update the values of the rate - # constants in the Fortran base module. Any other kind of assignment will + # constants in the Fortran base module. Any other syntax of assignment will # require an explicit call to set_rate_constants(). *Failure to update the # rate constants in the Fortran module will result in wrong results!* T = Ti + beta * (sg.kmc_time) diff --git a/examples/MyFirstTPD_Precovered_local_smart/runfile4.py b/examples/MyFirstTPD_Precovered_local_smart/runfile4.py index 5bdba992..b23d86f4 100644 --- a/examples/MyFirstTPD_Precovered_local_smart/runfile4.py +++ b/examples/MyFirstTPD_Precovered_local_smart/runfile4.py @@ -63,7 +63,7 @@ if load_simulation_state: # The following assignment (and similar assignments elsewhere) is *magical*. # It invokes a hidden __setattr__ method of the Model_Parameters class that # calls the set_rate_constants() function to update the values of the rate - # constants in the Fortran base module. Any other kind of assignment will + # constants in the Fortran base module. Any other syntax of assignment will # require an explicit call to set_rate_constants(). *Failure to update the # rate constants in the Fortran module will result in wrong results!* T = Ti + beta * (sg.kmc_time) @@ -131,7 +131,7 @@ if load_simulation_state: # The following assignment (and similar assignments elsewhere) is *magical*. # It invokes a hidden __setattr__ method of the Model_Parameters class that # calls the set_rate_constants() function to update the values of the rate - # constants in the Fortran base module. Any other kind of assignment will + # constants in the Fortran base module. Any other syntax of assignment will # require an explicit call to set_rate_constants(). *Failure to update the # rate constants in the Fortran module will result in wrong results!* T = Ti + beta * (sg.kmc_time) diff --git a/examples/MyFirstTPD_Precovered_local_smart/runfile5.py b/examples/MyFirstTPD_Precovered_local_smart/runfile5.py index 0eafe9d1..25e7b0c7 100644 --- a/examples/MyFirstTPD_Precovered_local_smart/runfile5.py +++ b/examples/MyFirstTPD_Precovered_local_smart/runfile5.py @@ -64,7 +64,7 @@ if load_simulation_state: # The following assignment (and similar assignments elsewhere) is *magical*. # It invokes a hidden __setattr__ method of the Model_Parameters class that # calls the set_rate_constants() function to update the values of the rate - # constants in the Fortran base module. Any other kind of assignment will + # constants in the Fortran base module. Any other syntax of assignment will # require an explicit call to set_rate_constants(). *Failure to update the # rate constants in the Fortran module will result in wrong results!* T = Ti + beta * (sg.kmc_time) diff --git a/examples/MyFirstTPD_Precovered_local_smart/runfile6.py b/examples/MyFirstTPD_Precovered_local_smart/runfile6.py index 30c23446..664c683e 100644 --- a/examples/MyFirstTPD_Precovered_local_smart/runfile6.py +++ b/examples/MyFirstTPD_Precovered_local_smart/runfile6.py @@ -64,7 +64,7 @@ if load_simulation_state: # The following assignment (and similar assignments elsewhere) is *magical*. # It invokes a hidden __setattr__ method of the Model_Parameters class that # calls the set_rate_constants() function to update the values of the rate - # constants in the Fortran base module. Any other kind of assignment will + # constants in the Fortran base module. Any other syntax of assignment will # require an explicit call to set_rate_constants(). *Failure to update the # rate constants in the Fortran module will result in wrong results!* T = Ti + beta * (sg.kmc_time) diff --git a/examples/MyThirdTPR_local_smart/runfile.py b/examples/MyThirdTPR_local_smart/runfile.py index 5c41d856..8487056c 100644 --- a/examples/MyThirdTPR_local_smart/runfile.py +++ b/examples/MyThirdTPR_local_smart/runfile.py @@ -166,7 +166,7 @@ if load_simulation_state: # The following assignment (and similar assignments elsewhere) is *magical*. # It invokes a hidden __setattr__ method of the Model_Parameters class that # calls the set_rate_constants() function to update the values of the rate - # constants in the Fortran base module. Any other kind of assignment will + # constants in the Fortran base module. Any other syntax of assignment will # require an explicit call to set_rate_constants(). *Failure to update the # rate constants in the Fortran module will result in wrong results!* T = T_initial + T_ramp * (kmc_time - kmc_time_tpdinit) -- GitLab From 0d14c01ba19790bd7e2e4caa5ce875bf7b4b274f Mon Sep 17 00:00:00 2001 From: AdityaSavara <39929571+AdityaSavara@users.noreply.github.com> Date: Tue, 16 Aug 2022 20:18:46 -0400 Subject: [PATCH 7/8] Create runfile7.py --- .../runfile7.py | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 examples/MyFirstTPD_Precovered_local_smart/runfile7.py diff --git a/examples/MyFirstTPD_Precovered_local_smart/runfile7.py b/examples/MyFirstTPD_Precovered_local_smart/runfile7.py new file mode 100644 index 00000000..6a075e6f --- /dev/null +++ b/examples/MyFirstTPD_Precovered_local_smart/runfile7.py @@ -0,0 +1,122 @@ +from kmcos.snapshots import * +import kmcos.snapshots_globals as sg +import kmcos.snapshots as snapshots +import kmcos.throttling_globals as tg +import kmcos.throttling as throttling +import os; import sys +import export_import_library as eil + + +##### SOME LINES THAT SHOULD NOT NORMALLY BE CHANGED#### + +# File names for loading/saving parameters (related to the export import module and throttling module) +# These will not really be used for this example, but are good lines to have. +# In the future, this may be done automatically within kmcos. +tg_load_file = sg.simulation_name + 'throttling_parameters.txt' +tg_save_file = sg.simulation_name + 'throttling_parameters.txt' +sg_load_file = sg.simulation_name + 'snapshots_parameters.txt' +sg_save_file = sg.simulation_name + 'snapshots_parameters.txt' + +# Export/import module objects for saving/loading data +tg_module = eil.module_export_import(tg_save_file, tg_load_file, tg) +sg_module = eil.module_export_import(sg_save_file, sg_load_file, sg) + + +#### LOADING AND INITIALIZING ##### +# Random seed +random_seed = -731543673 #can be any integer. only used if not loading a simulation. The PRNG_state that will be generated is a list, unlike the seed, which is an integer. + +load_simulation_state = False #This is a user setting that will affect what happens below. It is for continuing a simulation from where one left off. + +if load_simulation_state == False: #initialize the seed. + snapshots.seed_PRNG(restart=False, state=random_seed) +elif load_simulation_state == True: #load everything and set the SEED to be what it was before. + # Load modules + sg_module.load_params() + tg_module.load_params() + + # Reset number of steps and time + sg.model.base.set_kmc_time(sg.kmc_time) + sg.model.base.set_kmc_step(sg.steps_so_far) + sg.atoms.kmc_step = sg.steps_so_far + + # Load the lattice + sg.model._set_configuration(np.array(sg.config)) + sg.model._adjust_database() + + # Read the PRNG state, if available, and set it in the model + snapshots.seed_PRNG(restart=True, state=sg.PRNG_state) + # Update the snapshot number + tg.current_snapshot += 1 + + +##### GETTING SETTINGS READY FOR THE SIMULATION #### + +#Snapshots module options. +sg.parameters_of_interest = ['T'] #['T','R'] #<-- put the parameters you want exported with each snapshot here. Can also put activation energy etc. +sps = 1000 # <-- the kmc steps per snapshot. Defining this variable now is optional, and also the value can be changed later. +n_snapshots = 1 # <-- The total number of snapshots to do. Defining this variable now is optional, and also the value can be changed later. +tps = 1.0 #this sets the maximum amount of time per snapshot. + +#Generally, if a user needs to change a parameter after each snapshot, only do 1 snapshot at a time with n_snapshots=1. +#This example is a temperature programmed reaction example, so n_snapshots=1 makes sense, since we need to change the temperature after each snapshot. + +#Some simulation settings. +Ti = 300 #initial temperature +Tf = 345 #final temperature +beta = 5 #beta, heating rate in Kelvin per second. + + + +# Update the cutoff time +tg.cutoff_time = 1E6 #the throttling module's cutoff time is in seconds. We are not using that feature in this simulation, but it could be set here, for example. + + +if load_simulation_state == False: + sg.model.parameters.T = 300 #set the initial temperature. + T = Ti + sys.stdout.write("Starting a fresh simulation. Current temperature is " + + str(T) + " K. Current time is " + str(sg.kmc_time) + " s.\n") + #The kmcos Model is initialized in create_headers + create_headers() + #If it is desired to run snapshots without writing output to a file, set sg.write_output = 'False'. + #If you want to start writing again, set sg.write_output = 'True' before running + #more snapshots. +elif load_simulation_state == True: + #The temperatures will have been loaded already, but we need to set our runfile's variable. + T = sg.model.parameters.T + sys.stdout.write("Restarting from old simulation. Current temperature is " + + str(T) + " K. Current time is " + str(sg.kmc_time) + " s.\n") + + +# The following assignment (and similar assignments elsewhere) is *magical*. +# It invokes a hidden __setattr__ method of the Model_Parameters class that +# calls the set_rate_constants() function to update the values of the rate +# constants in the Fortran base module. Any other kind of assignment will +# require an explicit call to set_rate_constants(). *Failure to update the +# rate constants in the Fortran module will result in wrong results!* +sg.model.parameters.T = T + +#### SIMULATING AFTER ALL INITIALIZING IS DONE #### + +#Here is the TPD/TPR loop. +while T < Tf: + #Set the 'previous' Temperature and time variables before running any steps. + last_T = T + last_t = sg.atoms.kmc_time + #Run some steps as snapshots. + # Note that the below command will try to run n_snapshots with a certain 'steps per snapshot' + # but for any given snapshot, if thte time per snapshot (tps) is reached, the snapshot will be stopped. + # in this way, no snapshot will be greater than 1 second. + + do_snapshots(sps=sps, n_snapshots=n_snapshots, tps=tps) + #update the time and temperature for after the snaphsot is over. + t = sg.atoms.kmc_time + Tincr = beta*(t-last_t) # calculate the value to increment the temperature by + T = T + Tincr + sg.model.parameters.T = T + print("Snapshot taken. New temperature:", T) + + +#The final command below writes the simulation details to the logfile +create_log() -- GitLab From ad06b07da3f58dcefd02d8b6999ed239c8330e50 Mon Sep 17 00:00:00 2001 From: AdityaSavara <39929571+AdityaSavara@users.noreply.github.com> Date: Tue, 16 Aug 2022 20:45:23 -0400 Subject: [PATCH 8/8] Update __init__.py --- kmcos/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kmcos/__init__.py b/kmcos/__init__.py index b4c04ebb..2abc59a0 100644 --- a/kmcos/__init__.py +++ b/kmcos/__init__.py @@ -50,7 +50,7 @@ from __future__ import print_function -__version__ = "0.0.76" +__version__ = "1.0.0" VERSION = __version__ def evaluate_param_expression(param, parameters={}): -- GitLab