diff --git a/stochss/handlers/util/stochss_model.py b/stochss/handlers/util/stochss_model.py index 9063a8d150..237992ee38 100644 --- a/stochss/handlers/util/stochss_model.py +++ b/stochss/handlers/util/stochss_model.py @@ -19,7 +19,6 @@ import os import ast import json -import numpy import string import hashlib import tempfile @@ -391,7 +390,7 @@ def convert_to_spatial(self): model = self.load() model['is_spatial'] = True if model['defaultMode'] == "dynamic": - model['defaultMode'] == "discrete-concentration" + model['defaultMode'] = "discrete-concentration" if "timestepSize" not in self.model['modelSettings'].keys(): self.model['modelSettings']['timestepSize'] = 1e-5 if "domain" not in model.keys(): @@ -542,8 +541,9 @@ def save(self, model): path = self.get_path(full=True) self.log("debug", f"Full path to the model: {path}") if os.path.exists(path): + model = json.loads(model) with open(path, 'w', encoding="utf-8") as file: - file.write(model) + json.dump(model, file, sort_keys=True, indent=4) self.log("debug", f"Saved the model: {self.get_name()}") else: message = f"Could not find the model file: {self.get_path()}" diff --git a/stochss/handlers/util/stochss_spatial_model.py b/stochss/handlers/util/stochss_spatial_model.py index 3058dd5ac1..8594597f7d 100644 --- a/stochss/handlers/util/stochss_spatial_model.py +++ b/stochss/handlers/util/stochss_spatial_model.py @@ -24,7 +24,6 @@ import tempfile import traceback -import numpy import plotly from escapism import escape from spatialpy import Model, Species, Parameter, Reaction, Domain, DomainError, BoundaryCondition, \ @@ -436,6 +435,18 @@ def __update_domain(self, domain=None): @classmethod def apply_geometry(cls, particles, d_type, center): + ''' + Set the properties of the particles found within the geometry. + + Attributes + ---------- + particles : list + List of existing particles. + d_type : str + StochSS domain type. + center : list + Vector representing the center of the geometry. + ''' def inside(point): namespace = { 'cx': center[0], 'cy': center[1], 'cz': center[2], @@ -466,7 +477,7 @@ def convert_to_model(self): s_model = self.load() s_model['is_spatial'] = False if s_model['defaultMode'] == "discrete-concentration": - s_model['defaultMode'] == "dynamic" + s_model['defaultMode'] = "dynamic" if ".wkgp" in self.path: wkgp_path = self.get_dir_name() wkgp_path, _ = self.get_unique_path(name=self.get_file(path=wkgp_path), @@ -614,7 +625,7 @@ def get_domain_plot(self, path=None, new=False, domains=None): domain = domains[0] s_domain = domains[1] fig_temp_path = "/stochss/stochss_templates/domainPlotTemplate.json" - with open(fig_temp_path, "r") as fig_temp_file: + with open(fig_temp_path, "r", encoding="utf-8") as fig_temp_file: fig_temp = json.load(fig_temp_file) trace_temp = copy.deepcopy(fig_temp['data'][0]) if len(s_domain['particles']) == 0: @@ -785,7 +796,8 @@ def load(self): if self.model is None: self.__read_model_file() self.model['name'] = self.get_name() - if "template_version" not in self.model or self.model['template_version'] != self.TEMPLATE_VERSION: + if "template_version" not in self.model or \ + self.model['template_version'] != self.TEMPLATE_VERSION: if not self.model['defaultMode']: self.model['defaultMode'] = "discrete" elif self.model['defaultMode'] == "dynamic": @@ -799,7 +811,10 @@ def load(self): if "types" not in species.keys(): species['types'] = list(range(1, len(self.model['domain']['types']))) if "diffusionConst" not in species.keys(): - diff = 0.0 if "diffusionCoeff" not in species.keys() else species['diffusionCoeff'] + if "diffusionCoeff" not in species.keys(): + diff = 0.0 + else: + diff = species['diffusionCoeff'] species['diffusionConst'] = diff for reaction in self.model['reactions']: if "odePropensity" not in reaction.keys(): @@ -854,6 +869,7 @@ def save_domain(self, domain): domain : str Domain to be saved ''' + domain = json.loads(domain) path = self.get_path(full=True) with open(path, 'w', encoding="utf-8") as file: - file.write(domain) + json.dump(domain, file, sort_keys=True, indent=4)