Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOTFIX: Save Format #1369

Merged
merged 1 commit into from
Sep 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stochss/handlers/util/stochss_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import os
import ast
import json
import numpy
import string
import hashlib
import tempfile
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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()}"
Expand Down
28 changes: 22 additions & 6 deletions stochss/handlers/util/stochss_spatial_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down Expand Up @@ -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],
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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":
Expand All @@ -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():
Expand Down Expand Up @@ -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)