From 7ac454cc7530d84883c95946b141d32b30f149da Mon Sep 17 00:00:00 2001 From: Jimmy Date: Tue, 5 Jul 2022 15:48:40 -0600 Subject: [PATCH 1/3] saving the hop trajectory. Still need to figure out the os directory managment of the thing --- morphct/mobility_kmc.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/morphct/mobility_kmc.py b/morphct/mobility_kmc.py index 8c31188..06672f8 100644 --- a/morphct/mobility_kmc.py +++ b/morphct/mobility_kmc.py @@ -402,6 +402,7 @@ def run_single_kmc( carrier_list is returned. Otherwise it is assumed this function is being as part of a multiprocessing run and nothing is returned. """ + if seed is not None: np.random.seed(seed) @@ -433,6 +434,7 @@ def run_single_kmc( carrier_list = [] box = snap.configuration.box[:3] for i_job, [carrier_no, lifetime, ctype] in enumerate(jobs): + hopsites = [] v_print(f"starting job {i_job}", verbose, filename=filename) t1 = time.perf_counter() # Find a random position to start the carrier in @@ -458,13 +460,22 @@ def run_single_kmc( continue_sim = True while continue_sim: continue_sim = i_carrier.calculate_hop(chromo_list, verbose=verbose) + hopsites.append(i_carrier.current_chromo.center) # Now the carrier has finished hopping, let's calculate its vitals i_carrier.update_displacement() t2 = time.perf_counter() elapsed_time = float(t2) - float(t1) time_str = hf.time_units(elapsed_time) - + + if not os.path.exists(kmc_directory + "/carrier_pathfiles"): + os.makedirs(kmc_directory, "carrier_pathfiles") + hoppathfile = os.path.join(kmc_directory,"carrier_pathfiles/", f"{i_carrier.id}.npy") + if os.path.exists(hoppathfile): + os.remove(hoppathfile) + hopsites = np.array(hopsites) + np.save(hoppathfile, hopsites) + v_print( f"\t{i_carrier.c_type} hopped {i_carrier.n_hops} times over " + f"{i_carrier.current_time:.2e} seconds " From 6efa9bda4166e18b6b24a69f7c2c8b6d9119e64d Mon Sep 17 00:00:00 2001 From: Jimmy Date: Thu, 7 Jul 2022 11:40:43 -0600 Subject: [PATCH 2/3] added a directory for saving the ho paths so we can make trajectories from them. Still need to link this to verbosity perhaps and maybe just save one trajectory if verbosity is 0 or whatever. --- morphct/mobility_kmc.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/morphct/mobility_kmc.py b/morphct/mobility_kmc.py index 06672f8..e36a123 100644 --- a/morphct/mobility_kmc.py +++ b/morphct/mobility_kmc.py @@ -415,6 +415,8 @@ def run_single_kmc( else: filename = None + + v_print(f"Found {len(jobs):d} jobs to run", verbose, filename=filename) try: @@ -468,11 +470,16 @@ def run_single_kmc( elapsed_time = float(t2) - float(t1) time_str = hf.time_units(elapsed_time) - if not os.path.exists(kmc_directory + "/carrier_pathfiles"): - os.makedirs(kmc_directory, "carrier_pathfiles") - hoppathfile = os.path.join(kmc_directory,"carrier_pathfiles/", f"{i_carrier.id}.npy") + hopdirectory = os.path.join(kmc_directory, "carrier_pathfiles") + + if not os.path.exists(hopdirectory): + os.makedirs(hopdirectory) + + hoppathfile = os.path.join(hopdirectory, f"{i_carrier.id}.npy") + if os.path.exists(hoppathfile): os.remove(hoppathfile) + hopsites = np.array(hopsites) np.save(hoppathfile, hopsites) From 00d318a64a6cad7a1c4edb8c1063be3e489f504b Mon Sep 17 00:00:00 2001 From: Jimmy Date: Wed, 20 Jul 2022 12:32:47 -0600 Subject: [PATCH 3/3] trying out saving the first five carrier hop histories --- morphct/mobility_kmc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/morphct/mobility_kmc.py b/morphct/mobility_kmc.py index e36a123..dfc523e 100644 --- a/morphct/mobility_kmc.py +++ b/morphct/mobility_kmc.py @@ -479,9 +479,10 @@ def run_single_kmc( if os.path.exists(hoppathfile): os.remove(hoppathfile) - - hopsites = np.array(hopsites) - np.save(hoppathfile, hopsites) + + if i_carrier.id in range(0,5,1): + hopsites = np.array(hopsites) + np.save(hoppathfile, hopsites) v_print( f"\t{i_carrier.c_type} hopped {i_carrier.n_hops} times over "