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: Model Presentations #1450

Merged
merged 3 commits into from
May 1, 2023
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
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