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

Fixes to model files #11

Merged
merged 8 commits into from
Jan 15, 2024
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
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
_build
examples/example1/mesh/
meshes/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
266 changes: 155 additions & 111 deletions ca2+-examples/dendritic_spine.ipynb

Large diffs are not rendered by default.

23 changes: 15 additions & 8 deletions ca2+-examples/pre_process_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ def main(input_mesh_file, output_mesh_file, num_refinements):
spine_mesh = d.Mesh(Path(input_mesh_file).as_posix())
cell_markers = d.MeshFunction("size_t", spine_mesh, 3, spine_mesh.domains())
facet_markers = d.MeshFunction("size_t", spine_mesh, 2, spine_mesh.domains())
int_domain = d.MeshFunction("size_t", spine_mesh, 3)
psd_domain = d.MeshFunction("size_t", spine_mesh, 2, spine_mesh.domains())
for i in range(len(int_domain.mesh().coordinates())):
if int_domain.mesh().coordinates()[i][2] > 0.5:
int_domain.array()[i] = 1

if num_refinements > 0:
print(
Expand All @@ -25,21 +30,23 @@ def main(input_mesh_file, output_mesh_file, num_refinements):
spine_mesh = d.adapt(spine_mesh)
cell_markers = d.adapt(cell_markers, spine_mesh)
facet_markers = d.adapt(facet_markers, spine_mesh)
psd_domain = d.adapt(psd_domain, spine_mesh)
int_domain = d.adapt(int_domain, spine_mesh)
print(
f"Refined mesh has {spine_mesh.num_cells()} cells, "
f"{spine_mesh.num_facets()} facets and "
f"{spine_mesh.num_vertices()} vertices"
)


# for i in range(len(facet_array)):
# if (
# facet_array[i] == 11
# ): # this indicates PSD; in this case, set to 10 to indicate it is a part of the PM
# facet_array[i] = 10
facet_array = facet_markers.array()[:]
for i in range(len(facet_array)):
if (
facet_array[i] == 11
): # this indicates PSD; in this case, set to 10 to indicate it is a part of the PM
facet_array[i] = 10

Path(output_mesh_file).parent.mkdir(exist_ok=True, parents=True)
mesh_tools.write_mesh(spine_mesh, facet_markers, cell_markers, output_mesh_file)
mesh_tools.write_mesh(spine_mesh, facet_markers, cell_markers, output_mesh_file, [psd_domain, int_domain])


if __name__ == "__main__":
Expand Down
126 changes: 126 additions & 0 deletions ex3_scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,111 @@ def add_argument_preprocess_mech_mesh(parser: argparse.ArgumentParser):

mech_parser_args.add_preprocess_mech_mesh_arguments(parser)

def add_argument_mito_example(parser: argparse.ArgumentParser):
sys.path.insert(0, (here / ".." / "mito-example").as_posix())
import mito_parser_args

mito_parser_args.add_run_mito_arguments(parser)


def add_argument_preprocess_mito_mesh(parser: argparse.ArgumentParser):
sys.path.insert(0, (here / ".." / "mito-example").as_posix())
import mito_parser_args

mito_parser_args.add_preprocess_mito_mesh_arguments(parser)

def run_preprocess_mito_mesh(
input_mesh_file: Path,
output_mesh_file: Path,
input_curv_file: Path,
output_curv_file: Path,
dry_run: bool,
num_refinements: int,
**kwargs,
):
args = [
"--input-mesh-file",
Path(input_mesh_file).as_posix(),
"--output-mesh-file",
Path(output_mesh_file).as_posix(),
"--input-curv-file",
Path(input_curv_file).as_posix(),
"--output-curv-file",
Path(output_curv_file).as_posix(),
"--num-refinements",
num_refinements,
]

script = (
(here / ".." / "mito-example" / "pre_process_mesh.py")
.absolute()
.resolve()
.as_posix()
)
args = list(map(str, args))
if dry_run:
print(f"Run command: {sys.executable} {script} {' '.join(args)}")
return

sp.run([sys.executable, script, *args])


def run_mito_example(
mesh_file: Path,
curv_file: Path,
outdir: Path,
time_step: float,
curv_dep: float,
enforce_mass_conservation: bool,
dry_run: bool = False,
submit_ex3: bool = False,
**kwargs,
):
args = [
"--mesh-file",
Path(mesh_file).as_posix(),
"--curv-file",
Path(curv_file).as_posix(),
"--time-step",
time_step,
"--curv-dep",
curv_dep,
]
if enforce_mass_conservation:
args.append("--enforce-mass-conservation")

if not submit_ex3:
args.extend(["--outdir", Path(outdir).as_posix()])

script = (
(here / ".." / "mito-example" / "mito_atp_dynamics.py")
.absolute()
.resolve()
.as_posix()
)
# Turn all arguments into strings
args = list(map(str, args))
args_str = " ".join(args)
if dry_run:
print(f"Run command: {sys.executable} {script} {args_str}")
return

if submit_ex3:
job_file = Path("tmp_job.sbatch")
job_file.write_text(
ex3_template.format(
job_name="mito",
python=sys.executable,
script=script,
args=args_str,
)
)

sp.run(["sbatch", job_file])
job_file.unlink()
else:
sp.run([sys.executable, script, *args])


def run_pre_preprocess_mech_mesh(
mesh_folder: Path,
Expand Down Expand Up @@ -104,6 +209,7 @@ def run_mechanotransduction_example(
e_val: float,
z_cutoff: float,
axisymmetric: bool,
well_mixed: bool,
no_enforce_mass_conservation: bool = False,
dry_run: bool = False,
submit_ex3: bool = False,
Expand All @@ -119,6 +225,7 @@ def run_mechanotransduction_example(
"--z-cutoff",
z_cutoff,
"--axisymmetric" if axisymmetric else "",
"--well-mixed" if well_mixed else "",
]
if no_enforce_mass_conservation:
args.append("--no-enforce-mass-conservation")
Expand Down Expand Up @@ -296,6 +403,17 @@ def main():
)
add_argument_mechanotransduction_example(dendritic_spine)

# Mito example
preprocess_spine_mesh = subparsers.add_parser(
"preprocess-mito-mesh", help="Preprocess mesh for mito example"
)
add_argument_preprocess_mito_mesh(preprocess_spine_mesh)

mito = subparsers.add_parser(
"mito", help="Run mito example"
)
add_argument_mito_example(mito)

args = vars(parser.parse_args())
# if args[""]

Expand All @@ -318,6 +436,14 @@ def main():
elif args["command"] == "mechanotransduction":
print("Run mechanotransduction example")
run_mechanotransduction_example(**args)

elif args["command"] == "preprocess-mito-mesh":
print("Run preprocess mito mesh")
run_preprocess_mito_mesh(**args)

elif args["command"] == "mito":
print("Run mito example")
run_mito_example(**args)


if __name__ == "__main__":
Expand Down
12 changes: 12 additions & 0 deletions ex3_scripts/run_mito.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
python3 main.py preprocess-mito-mesh --input-mesh-file /root/shared/gitrepos/smart-comp-sci/meshes/mito1_mesh.xml --output-mesh-file meshes/mito_mesh.h5 --input-curv-file /root/shared/gitrepos/smart-comp-sci/meshes/mito1_curvature.xml --output-curv-file meshes/mito_curv.xdmf
python3 main.py mito --mesh-file meshes/mito_mesh.h5 --curv-file meshes/mito_curv.xdmf --outdir /root/scratch/eafrancis/mito/sweep_gamer_curv/results_curvdepneg40 --curv-dep=-40 --enforce-mass-conservation &
sleep 10
python3 main.py mito --mesh-file meshes/mito_mesh.h5 --curv-file meshes/mito_curv.xdmf --outdir /root/scratch/eafrancis/mito/sweep_gamer_curv/results_curvdepneg20 --curv-dep=-20 --enforce-mass-conservation &
sleep 10
python3 main.py mito --mesh-file meshes/mito_mesh.h5 --curv-file meshes/mito_curv.xdmf --outdir /root/scratch/eafrancis/mito/sweep_gamer_curv/results_curvdepneg10 --curv-dep=-10 --enforce-mass-conservation &
sleep 10
python3 main.py mito --mesh-file meshes/mito_mesh.h5 --curv-file meshes/mito_curv.xdmf --outdir /root/scratch/eafrancis/mito/sweep_gamer_curv/results_curvdep10 --curv-dep 10 --enforce-mass-conservation &
sleep 10
python3 main.py mito --mesh-file meshes/mito_mesh.h5 --curv-file meshes/mito_curv.xdmf --outdir /root/scratch/eafrancis/mito/sweep_gamer_curv/results_curvdep20 --curv-dep 20 --enforce-mass-conservation &
sleep 10
python3 main.py mito --mesh-file meshes/mito_mesh.h5 --curv-file meshes/mito_curv.xdmf --outdir /root/scratch/eafrancis/mito/sweep_gamer_curv/results_curvdep40 --curv-dep 40 --enforce-mass-conservation
5 changes: 5 additions & 0 deletions mechanotransduction-example/mech_parser_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ def add_mechanotransduction_arguments(parser: argparse.ArgumentParser) -> None:
action="store_true",
default=False,
)
parser.add_argument(
"--well-mixed",
action="store_true",
default=False,
)
parser.add_argument(
"--no-enforce-mass-conservation",
action="store_true",
Expand Down
Loading