Skip to content

Commit

Permalink
demo2
Browse files Browse the repository at this point in the history
  • Loading branch information
eagmon committed Jan 27, 2025
1 parent a3d1518 commit 9636d67
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 242 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/notebook_to_html.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
paths:
- 'notebooks/demo.ipynb'
- 'notebooks/demo2.ipynb'
- 'notebooks/cell_sorting.ipynb'

jobs:
Expand All @@ -29,6 +30,7 @@ jobs:
- name: Convert Jupyter Notebook to HTML
run: |
jupyter nbconvert --to html notebooks/demo.ipynb
jupyter nbconvert --to html notebooks/demo2.ipynb
jupyter nbconvert --to html notebooks/cell_sorting.ipynb
- name: Commit and push HTML to gh-pages branch
Expand All @@ -37,12 +39,15 @@ jobs:
git config --local user.name "GitHub Action"
git fetch origin
mv notebooks/demo.html /tmp/demo.html
mv notebooks/demo2.html /tmp/demo2.html
mv notebooks/cell_sorting.html /tmp/cell_sorting.html
git checkout gh-pages || git checkout -b gh-pages
git pull origin gh-pages
mv /tmp/demo.html notebooks/demo.html
mv /tmp/demo2.html notebooks/demo2.html
mv /tmp/cell_sorting.html notebooks/cell_sorting.html
git add notebooks/demo.html
git add notebooks/demo2.html
git add notebooks/cell_sorting.html
git diff-index --quiet HEAD || git commit -m "Update HTML files"
git push origin gh-pages || true
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ This project contains models and schemas for validating and building JSON schema

## Notebooks
* [Demo](https://vivarium-collective.github.io/multicell-schema/notebooks/demo.html)
* [Demo 2](https://vivarium-collective.github.io/multicell-schema/notebooks/demo2.html)
* [Cell Sorting](https://vivarium-collective.github.io/multicell-schema/notebooks/cell_sorting.html)

## Directory Structure
Expand Down
59 changes: 59 additions & 0 deletions models/cell_sorting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"id": "model_000016",
"name": "cell_sorting",
"objects": {
"dark": {
"type": "CellPopulation",
"attributes": {},
"boundary_conditions": {},
"contained_objects": []
},
"light": {
"type": "CellPopulation",
"attributes": {},
"boundary_conditions": {},
"contained_objects": []
},
"environment": {
"type": "CellField",
"attributes": {},
"boundary_conditions": {},
"contained_objects": [
"dark",
"light"
]
},
"external_material": {
"type": "Material",
"attributes": {},
"boundary_conditions": {},
"contained_objects": []
}
},
"processes": {
"volume exclusion": {
"type": "VolumeExclusion",
"attributes": {},
"participating_objects": [
"dark",
"light",
"external_material"
]
},
"contact": {
"type": "ContactForce",
"attributes": {},
"participating_objects": [
"environment"
]
},
"fluctuation": {
"type": "MotileForce",
"attributes": {},
"participating_objects": [
"dark",
"light"
]
}
}
}
27 changes: 14 additions & 13 deletions multicell_utils/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ def validate(self):
def register(self, overwrite=False):
try:
if self.schema_type == "object":
schema_registry.register_object(self.schema, self.schema["type"])
schema_registry.register_object(self.schema, self.schema["type"], overwrite)
elif self.schema_type == "process":
schema_registry.register_process(self.schema, self.schema["type"])
schema_registry.register_process(self.schema, self.schema["type"], overwrite)
except ValueError as e:
if not overwrite:
print(f"Failed to register schema: {e}")
Expand All @@ -67,14 +67,14 @@ def save(self, filename, directory="schema"):
except ValidationError as e:
raise ValidationError(f"Schema validation failed: {e.message}")

# directory = os.path.join(project_root, directory, self.schema_type) # objects or processes
directory = os.path.join(directory, self.schema_type)

if not os.path.exists(directory):
os.makedirs(directory)
with open(os.path.join(directory, filename), 'w') as file:
# make absolute path to directory
absolute_directory = os.path.join(project_root, directory, self.schema_type) # objects or processes
local_directory = os.path.join(directory, self.schema_type)
if not os.path.exists(absolute_directory):
os.makedirs(absolute_directory)
with open(os.path.join(absolute_directory, filename), 'w') as file:
json.dump(self.schema, file, indent=4)
print(f"Schema saved to {os.path.join(directory, filename)}")
print(f"Schema saved to {os.path.join(local_directory, filename)}")

def load_from_json(self, json_path, name):
assert name is not None, "Name must be provided when loading from JSON"
Expand Down Expand Up @@ -230,10 +230,11 @@ def save(self, filename, directory="models"):
print(f"Model validation failed: {e.message}")
return

# absolute_directory = os.path.join(project_root, directory)
if not os.path.exists(directory):
os.makedirs(directory)
with open(os.path.join(directory, filename), 'w') as file:
# make absolute path to directory
absolute_directory = os.path.join(project_root, directory)
if not os.path.exists(absolute_directory):
os.makedirs(absolute_directory)
with open(os.path.join(absolute_directory, filename), 'w') as file:
json.dump(self.model, file, indent=4)
print(f"Model saved to {os.path.join(directory, filename)}")

Expand Down
12 changes: 7 additions & 5 deletions multicell_utils/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ def validate_containment(self, model):
if not any(base_type in allowed_children_types for base_type in self.object_inheritance.get(child_type, [])):
print(f"Invalid containment: {child_type} object is not contained by {parent_type}")

def register_object(self, schema, object_type):
def register_object(self, schema, object_type, overwrite=False):
if 'type' in schema:
object_type = schema['type']
if object_type in self.object_types:
if object_type in self.object_types and not overwrite:
raise ValueError(f"Object schema '{object_type}' is already registered.")
try:
self.validate_schema(schema, self.object_meta_schema)
Expand All @@ -151,10 +151,10 @@ def register_object(self, schema, object_type):
self.object_inheritance[object_type] = inherits_from


def register_process(self, schema, process_type=None):
def register_process(self, schema, process_type=None, overwrite=False):
if 'type' in schema:
process_type = schema['type']
if process_type in self.process_types:
if process_type in self.process_types and not overwrite:
raise ValueError(f"Process schema type '{process_type}' is already registered.")
try:
self.validate_schema(schema, self.process_meta_schema)
Expand All @@ -174,9 +174,11 @@ def register_process(self, schema, process_type=None):
self.process_inheritance[process_type] = schema.get('inherits_from', [])

except ValidationError as e:
print(f"Failed to register process schema '{process_name}': {e.message}")
print(f"Failed to register process schema '{process_type}': {e.message}")


def register_template(self, schema, template_name):
# TODO implement template registration
schema_name = schema['name']
pass

Expand Down
32 changes: 16 additions & 16 deletions notebooks/cell_sorting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"metadata": {
"collapsed": true,
"ExecuteTime": {
"end_time": "2025-01-26T16:42:13.442699Z",
"start_time": "2025-01-26T16:42:13.380688Z"
"end_time": "2025-01-27T16:30:26.830260Z",
"start_time": "2025-01-27T16:30:26.769855Z"
}
},
"source": [
Expand Down Expand Up @@ -36,8 +36,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-26T16:42:13.448126Z",
"start_time": "2025-01-26T16:42:13.445524Z"
"end_time": "2025-01-27T16:30:26.898720Z",
"start_time": "2025-01-27T16:30:26.895943Z"
}
},
"cell_type": "code",
Expand All @@ -59,8 +59,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-26T16:42:13.495657Z",
"start_time": "2025-01-26T16:42:13.491402Z"
"end_time": "2025-01-27T16:30:26.947836Z",
"start_time": "2025-01-27T16:30:26.943558Z"
}
},
"cell_type": "code",
Expand All @@ -72,8 +72,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-26T16:42:13.504588Z",
"start_time": "2025-01-26T16:42:13.499796Z"
"end_time": "2025-01-27T16:30:26.955825Z",
"start_time": "2025-01-27T16:30:26.951474Z"
}
},
"cell_type": "code",
Expand All @@ -93,8 +93,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-26T16:42:13.526863Z",
"start_time": "2025-01-26T16:42:13.509757Z"
"end_time": "2025-01-27T16:30:26.976223Z",
"start_time": "2025-01-27T16:30:26.959334Z"
}
},
"cell_type": "code",
Expand All @@ -105,7 +105,7 @@
"data": {
"image/svg+xml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n<!-- Generated by graphviz version 9.0.0 (0)\n -->\n<!-- Pages: 1 -->\n<svg width=\"733pt\" height=\"505pt\"\n viewBox=\"0.00 0.00 733.25 505.13\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 501.13)\">\n<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-501.13 729.25,-501.13 729.25,4 -4,4\"/>\n<!-- dark -->\n<g id=\"node1\" class=\"node\">\n<title>dark</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"308.39\" cy=\"-176.39\" rx=\"81.34\" ry=\"81.34\"/>\n<text text-anchor=\"middle\" x=\"308.39\" y=\"-172.19\" font-family=\"Times,serif\" font-size=\"14.00\">dark:CellPopulation</text>\n</g>\n<!-- volume exclusion -->\n<g id=\"node5\" class=\"node\">\n<title>volume exclusion</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"396.55,-36 178.22,-36 178.22,0 396.55,0 396.55,-36\"/>\n<text text-anchor=\"middle\" x=\"287.39\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">volume exclusion:VolumeExclusion</text>\n</g>\n<!-- dark&#45;&gt;volume exclusion -->\n<g id=\"edge1\" class=\"edge\">\n<title>dark&#45;&gt;volume exclusion</title>\n<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M296.14,-84.2C293.69,-65.92 291.36,-48.61 289.73,-36.43\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"292.64,-84.42 297.44,-93.86 299.58,-83.48 292.64,-84.42\"/>\n</g>\n<!-- fluctuation -->\n<g id=\"node7\" class=\"node\">\n<title>fluctuation</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"563.88,-36 414.9,-36 414.9,0 563.88,0 563.88,-36\"/>\n<text text-anchor=\"middle\" x=\"489.39\" y=\"-13.8\" font-family=\"Times,serif\" font-size=\"14.00\">fluctuation:MotileForce</text>\n</g>\n<!-- dark&#45;&gt;fluctuation -->\n<g id=\"edge5\" class=\"edge\">\n<title>dark&#45;&gt;fluctuation</title>\n<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M365.84,-103.11C376.11,-92.09 387.14,-81.31 398.39,-72 415.15,-58.14 436,-45.71 453.5,-36.38\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"363.31,-100.69 359.17,-110.44 368.49,-105.4 363.31,-100.69\"/>\n</g>\n<!-- light -->\n<g id=\"node2\" class=\"node\">\n<title>light</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"489.39\" cy=\"-176.39\" rx=\"81.84\" ry=\"81.84\"/>\n<text text-anchor=\"middle\" x=\"489.39\" y=\"-172.19\" font-family=\"Times,serif\" font-size=\"14.00\">light:CellPopulation</text>\n</g>\n<!-- light&#45;&gt;volume exclusion -->\n<g id=\"edge2\" class=\"edge\">\n<title>light&#45;&gt;volume exclusion</title>\n<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M432.38,-102.85C421.78,-91.74 410.28,-80.99 398.39,-72 379.05,-57.38 355.04,-45.31 334.31,-36.4\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"429.53,-104.92 438.89,-109.88 434.66,-100.17 429.53,-104.92\"/>\n</g>\n<!-- light&#45;&gt;fluctuation -->\n<g id=\"edge6\" class=\"edge\">\n<title>light&#45;&gt;fluctuation</title>\n<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M489.39,-82.95C489.39,-65.15 489.39,-48.37 489.39,-36.47\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"485.89,-82.93 489.39,-92.93 492.89,-82.93 485.89,-82.93\"/>\n</g>\n<!-- environment -->\n<g id=\"node3\" class=\"node\">\n<title>environment</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"489.39\" cy=\"-406.95\" rx=\"90.18\" ry=\"90.18\"/>\n<text text-anchor=\"middle\" x=\"489.39\" y=\"-402.75\" font-family=\"Times,serif\" font-size=\"14.00\">environment:CellField</text>\n</g>\n<!-- environment&#45;&gt;dark -->\n<g id=\"edge7\" class=\"edge\">\n<title>environment&#45;&gt;dark</title>\n<path fill=\"none\" stroke=\"black\" stroke-width=\"2\" d=\"M433.61,-335.51C409.61,-305.21 381.78,-270.07 358.46,-240.61\"/>\n</g>\n<!-- environment&#45;&gt;light -->\n<g id=\"edge8\" class=\"edge\">\n<title>environment&#45;&gt;light</title>\n<path fill=\"none\" stroke=\"black\" stroke-width=\"2\" d=\"M489.39,-316.6C489.39,-297.45 489.39,-277.31 489.39,-258.48\"/>\n</g>\n<!-- contact -->\n<g id=\"node6\" class=\"node\">\n<title>contact</title>\n<polygon fill=\"none\" stroke=\"black\" points=\"725.25,-194.39 589.52,-194.39 589.52,-158.39 725.25,-158.39 725.25,-194.39\"/>\n<text text-anchor=\"middle\" x=\"657.39\" y=\"-172.19\" font-family=\"Times,serif\" font-size=\"14.00\">contact:ContactForce</text>\n</g>\n<!-- environment&#45;&gt;contact -->\n<g id=\"edge4\" class=\"edge\">\n<title>environment&#45;&gt;contact</title>\n<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M549.16,-324.63C583.83,-277.47 624.51,-222.13 644.69,-194.66\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"546.54,-322.28 543.44,-332.41 552.18,-326.43 546.54,-322.28\"/>\n</g>\n<!-- external_material -->\n<g id=\"node4\" class=\"node\">\n<title>external_material</title>\n<ellipse fill=\"none\" stroke=\"black\" cx=\"104.39\" cy=\"-176.39\" rx=\"104.39\" ry=\"104.39\"/>\n<text text-anchor=\"middle\" x=\"104.39\" y=\"-172.19\" font-family=\"Times,serif\" font-size=\"14.00\">external_material:Material</text>\n</g>\n<!-- external_material&#45;&gt;volume exclusion -->\n<g id=\"edge3\" class=\"edge\">\n<title>external_material&#45;&gt;volume exclusion</title>\n<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M189.13,-97.16C198.9,-88.55 208.79,-80.01 218.39,-72 233.11,-59.7 250.21,-46.56 263.7,-36.44\"/>\n<polygon fill=\"black\" stroke=\"black\" points=\"186.89,-94.47 181.72,-103.72 191.53,-99.71 186.89,-94.47\"/>\n</g>\n</g>\n</svg>\n",
"text/plain": [
"<graphviz.graphs.Digraph at 0x10458b190>"
"<graphviz.graphs.Digraph at 0x114eb54d0>"
]
},
"execution_count": 5,
Expand All @@ -118,8 +118,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-26T16:42:13.534693Z",
"start_time": "2025-01-26T16:42:13.532329Z"
"end_time": "2025-01-27T16:30:26.983095Z",
"start_time": "2025-01-27T16:30:26.980842Z"
}
},
"cell_type": "code",
Expand All @@ -129,7 +129,7 @@
{
"data": {
"text/plain": [
"ModelBuilder({ 'id': 'model_000006',\n",
"ModelBuilder({ 'id': 'model_000016',\n",
" 'name': 'cell_sorting',\n",
" 'objects': { 'dark': { 'attributes': {},\n",
" 'boundary_conditions': {},\n",
Expand Down Expand Up @@ -170,8 +170,8 @@
{
"metadata": {
"ExecuteTime": {
"end_time": "2025-01-26T16:42:13.603866Z",
"start_time": "2025-01-26T16:42:13.602653Z"
"end_time": "2025-01-27T16:30:26.988508Z",
"start_time": "2025-01-27T16:30:26.987299Z"
}
},
"cell_type": "code",
Expand Down
Loading

0 comments on commit 9636d67

Please sign in to comment.