From ebb0a955efbcad56a4fd573dab305209d5b73fb5 Mon Sep 17 00:00:00 2001 From: gusmaogabriels Date: Sat, 9 Nov 2019 22:49:42 -0500 Subject: [PATCH 1/2] Fixed adsorbate-adsorbate interaction + backward python 2.7 compatibility. --- catmap/analyze/analysis_base.py | 2 +- catmap/model.py | 24 ++++++++++--------- .../first_order_interactions.py | 5 ++-- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/catmap/analyze/analysis_base.py b/catmap/analyze/analysis_base.py index c8e95eda..829e2f99 100755 --- a/catmap/analyze/analysis_base.py +++ b/catmap/analyze/analysis_base.py @@ -11,7 +11,7 @@ from mpl_toolkits.axes_grid1 import make_axes_locatable plt = catmap.plt -pickle= catmap.pickle +pickle = catmap.pickle np = catmap.np spline = catmap.spline mtransforms = catmap.mtransforms diff --git a/catmap/model.py b/catmap/model.py index ae443298..6cd3e3c1 100644 --- a/catmap/model.py +++ b/catmap/model.py @@ -10,7 +10,6 @@ import re from .data import regular_expressions string2symbols = catmap.string2symbols -pickle = catmap.pickle plt = catmap.plt @@ -278,7 +277,8 @@ def Axb_solver(A, b): for attr in dir(self): if (not attr.startswith('_') and not callable(getattr(self, attr)) and - attr not in self._classes): + attr not in self._classes and + not inspect.ismodule(getattr(self,attr))): if (len(repr(getattr(self, attr))) > self._max_log_line_length): # Line is too long for logfile -> put into pickle @@ -286,11 +286,11 @@ def Axb_solver(A, b): pickled_data = {} for attr in self._pickle_attrs: pickled_data[attr] = getattr(self, attr) - try: - pickle.dump(pickled_data, open(self.data_file, 'w')) - except: + if sys.version_info[0]<3: + catmap.pickle.dump(pickled_data, open(self.data_file, 'w')) + else: # Fallback workaround for Py3 - pickle.dump(pickled_data, open(self.data_file, 'wb')) + catmap.pickle.dump(pickled_data, open(self.data_file, 'wb',protocol=2)) # Make logfile log_txt = self._log_imports @@ -380,8 +380,8 @@ def load(self, setup_file): # globs = {} locs = defaults - - exec(compile(open(setup_file, 'r').read(), '', 'exec'), globs, locs) + + exec(compile(open(setup_file, 'rb').read(), '', 'exec'), globs, locs) for var in locs.keys(): if var in self._classes: #black magic to auto-import classes @@ -437,9 +437,9 @@ def load_data_file(self, overwrite=False): """ if os.path.exists(self.data_file): try: - pickled_data = pickle.load(open(self.data_file, 'r')) + pickled_data = catmap.pickle.load(open(self.data_file, 'r')) except: - pickled_data = pickle.load(open(self.data_file, 'rb')) + pickled_data = catmap.pickle.load(open(self.data_file, 'rb')) for attr in pickled_data: if not overwrite: if getattr(self, attr, None) is None: # Don't over-write @@ -1155,7 +1155,9 @@ def _header(self,exclude_outputs=[],re_parse=False): for attr in dir(self): if (not attr.startswith('_') and not callable(getattr(self,attr)) and - attr not in self._classes): + attr not in self._classes and + not inspect.ismodule(getattr(self,attr))): + print(attr) val = repr(getattr(self,attr)) new_line = '' if attr not in self._pickle_attrs: diff --git a/catmap/thermodynamics/first_order_interactions.py b/catmap/thermodynamics/first_order_interactions.py index ae8c795c..fed09384 100644 --- a/catmap/thermodynamics/first_order_interactions.py +++ b/catmap/thermodynamics/first_order_interactions.py @@ -270,7 +270,8 @@ def sync_with_species_defs(fitting_info,surf_id): if cvg_Ed_Eint_i not in required_params_dict[reqd]: required_params_dict[reqd] += [cvg_Ed_Eint_i] - for key in required_params_dict.keys(): + for key in list(required_params_dict.keys()): + print(key) keylist = eval(key) cvgs = required_params_dict[key] if len(keylist) == 1: @@ -332,7 +333,7 @@ def sync_with_species_defs(fitting_info,surf_id): for key in cross_keys_3: params = eval(key) - params = [pi for pi in params if pi not in fitting_info.keys()+user_inputs] + params = [pi for pi in params if pi not in list(fitting_info.keys())+user_inputs] assert len(params) <= 1 #if not then something is very weird. if params: param = params[0] From 7c2bf0486af5c41f25b0ea4cbdbd7a78f8af13c4 Mon Sep 17 00:00:00 2001 From: gusmaogabriels Date: Sat, 9 Nov 2019 23:35:52 -0500 Subject: [PATCH 2/2] Fixed adsorbate-adsorbate interaction + backward python 2.7 compatibility. --- catmap/model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/catmap/model.py b/catmap/model.py index 6cd3e3c1..5a99c54b 100644 --- a/catmap/model.py +++ b/catmap/model.py @@ -290,7 +290,7 @@ def Axb_solver(A, b): catmap.pickle.dump(pickled_data, open(self.data_file, 'w')) else: # Fallback workaround for Py3 - catmap.pickle.dump(pickled_data, open(self.data_file, 'wb',protocol=2)) + catmap.pickle.dump(pickled_data, open(self.data_file, 'wb',2)) # Make logfile log_txt = self._log_imports