Skip to content

Commit

Permalink
Merge pull request #1450 from StochSS/hotfix-model-presentations
Browse files Browse the repository at this point in the history
HOTFIX: Model Presentations
  • Loading branch information
seanebum authored May 1, 2023
2 parents eea88e4 + 305ba8e commit 34c2c29
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
2 changes: 1 addition & 1 deletion client/pages/model-presentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let ModelPresentationPage = PageView.extend({
app.getXHR(endpoint, {
success: (err, response, body) => {
this.model.set(body.model);
if(Object.keys(body.model.domain).includes("particles")) {
if(this.model.is_spatial && Object.keys(body.model.domain).includes("particles")) {
let particles = new Particles(body.model.domain.particles);
this.model.domain.particles = particles;
}
Expand Down
49 changes: 42 additions & 7 deletions jupyterhub/model_presentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,24 @@ def process_smodel_presentation(path, file=None, for_download=False):
file_obj.print_logs(log)
return model_pres

template = {
"is_spatial": False, "defaultID": 1, "defaultMode": "", "annotation": "", "volume": 1,
"modelSettings": {"endSim": 20, "timeStep": 0.05, "timestepSize": 1e-5 },
"domain": {
"actions": [],
"boundary_condition": {"reflect_x": True, "reflect_y": True, "reflect_z": True},
"c_0": 10, "gravity": [0, 0, 0], "p_0": 100.0, "rho_0": 1.0, "shapes": [],
"size": None, "static": True, "template_version": 2, "transformations": [],
"types": [{
"c":10, "fixed":False, "mass":1.0, "name":"Un-Assigned",
"nu":0.0, "rho":1.0, "typeID":0, "volume":1.0
}],
"x_lim": [0, 0], "y_lim": [0, 0], "z_lim": [0, 0]
},
"species": [], "initialConditions": [], "parameters": [], "reactions": [], "rules": [],
"eventsCollection": [], "functionDefinitions": [], "boundaryConditions": []
}

class StochSSModel(StochSSBase):
'''
################################################################################################
Expand Down Expand Up @@ -215,6 +233,8 @@ def __update_reactions(self):
if "reactions" not in self.model.keys():
return
for reaction in self.model['reactions']:
if "odePropensity" not in reaction.keys():
reaction['odePropensity'] = reaction['propensity']
try:
if reaction['rate'].keys() and isinstance(reaction['rate']['expression'], str):
expression = ast.literal_eval(reaction['rate']['expression'])
Expand All @@ -237,25 +257,40 @@ def __update_rules(self, param_ids):
except ValueError:
pass

def load(self):
'''
Reads the model file, updates the model to the current format, and stores it in self.model
def __update_model_to_current(self):
if self.model['template_version'] == self.TEMPLATE_VERSION:
return

Attributes
----------
'''
if "annotation" not in self.model.keys():
self.model['annotation'] = ""
if "volume" not in self.model.keys():
if "volume" in self.model['modelSettings'].keys():
self.model['volume'] = self.model['modelSettings']['volume']
else:
self.model['volume'] = 1

param_ids = self.__update_parameters()
self.__update_reactions()
self.__update_events(param_ids=param_ids)
self.__update_rules(param_ids=param_ids)
return {"model": self.model}

if "refLinks" not in self.model.keys():
self.model['refLinks'] = []

self.model['template_version'] = self.TEMPLATE_VERSION

def load(self):
'''
Reads the model file, updates the model to the current format, and stores it in self.model
Attributes
----------
'''
if "template_version" not in self.model:
self.model['template_version'] = 0
self.__update_model_to_current()

return {"model": self.model, "diff": self.diff}


class StochSSSpatialModel(StochSSBase):
Expand Down

0 comments on commit 34c2c29

Please sign in to comment.