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

Refactor/update operation syntax #56

Merged
merged 14 commits into from
Nov 15, 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 notebooks/signac_301_Aggregation_Tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"\n",
"Aggregation allows a **signac-flow** operation to act on multiple jobs, rather than one job at a time.\n",
"\n",
"An aggregate is defined as a subset of the jobs in a **signac** project. Aggregates are generated when the `@flow.aggregator` decorator is applied to an operation.\n",
"An aggregate is defined as a subset of the jobs in a **signac** project. Aggregates are generated when a `flow.aggregator` object is provided to the `FlowProject.operation` decorator.\n",
"\n",
"Please refer to the [documentation](https://docs.signac.io/en/latest/aggregation.html) for detailed instructions on how to use aggregation."
]
Expand Down
33 changes: 14 additions & 19 deletions projects/flow.gmx-lysozyme-in-water/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from flow import FlowProject

gmx_exec = "gmx" # or use gmx_mpi if available
mpi_exec = "mpirun"

"""Define file level constants."""

Expand Down Expand Up @@ -84,16 +83,10 @@ def _grompp_str(op_name, gro_name, checkpoint_file=None):
return cmd


def _mdrun_str(op_name, np=1, nt=None, verbose=False):
def _mdrun_str(op_name, nt=None, verbose=False):
"""Helper function, returns mdrun command string for operation."""
num_threads = 1 if nt is None else nt
num_nodes = np // num_threads
cmd = (
"OMP_NUM_THREADS={num_threads} {mpi_exec} -n {np} {gmx} "
"mdrun -ntomp {num_threads} {verbose} -deffnm {op}"
).format(
np=num_nodes,
mpi_exec=mpi_exec,
cmd = ("{gmx} mdrun -ntomp {num_threads} {verbose} -deffnm {op}").format(
b-butler marked this conversation as resolved.
Show resolved Hide resolved
gmx=gmx_exec,
num_threads=num_threads,
op=op_name,
Expand Down Expand Up @@ -165,7 +158,7 @@ def solvate(job):
@MyProject.post.isfile(ionization_config)
@MyProject.operation(cmd=True, with_job=True)
def grompp_add_ions(job):
return _grompp_str("ions", solvated_file)
return _grompp_str("ions", solvated_file).format(job)


@MyProject.pre.after(grompp_add_ions)
Expand Down Expand Up @@ -197,58 +190,60 @@ def ionize(job):
@MyProject.post.isfile(em_op + ".tpr")
@MyProject.operation(cmd=True, with_job=True)
def grompp_minim(job):
return _grompp_str("minim", ionized_file)
return _grompp_str("minim", ionized_file).format(job)


@MyProject.pre.after(grompp_minim)
@MyProject.post.isfile(em_file)
@MyProject.operation(cmd=True, with_job=True)
def minim(job):
return _mdrun_str("minim")
return _mdrun_str("minim").format(job)


# Equilibration: NVT then NPT
@MyProject.pre.after(minim)
@MyProject.post.isfile(nvt_op + ".tpr")
@MyProject.operation(cmd=True, with_job=True)
def grompp_nvt(job):
return _grompp_str("nvt", em_file)
return _grompp_str("nvt", em_file).format(job)


@MyProject.pre.after(grompp_nvt)
@MyProject.post.isfile(nvt_file)
@MyProject.operation(cmd=True, directives={"np": 16}, with_job=True)
def nvt(job):
return _mdrun_str("nvt")
return _mdrun_str("nvt").format(job)


@MyProject.pre.after(nvt)
@MyProject.post.isfile(npt_op + ".tpr")
@MyProject.operation(cmd=True, with_job=True)
def grompp_npt(job):
return _grompp_str("npt", nvt_file)
return _grompp_str("npt", nvt_file).format(job)


@MyProject.pre.isfile(npt_op + ".tpr")
@MyProject.post.isfile(npt_file)
@MyProject.operation(cmd=True, directives={"np": 16}, with_job=True)
def npt(job):
return _mdrun_str("npt")
return _mdrun_str("npt").format(job)


# Final run
@MyProject.pre.isfile(npt_file)
@MyProject.post.isfile(production_op + ".tpr")
@MyProject.operation(cmd=True, with_job=True)
def grompp_md(job):
return _grompp_str("md", npt_file)
return _grompp_str("md", npt_file).format(job)


@MyProject.pre.after(grompp_md)
@MyProject.post(finished)
@MyProject.operation(cmd=True, directives={"np": 16}, with_job=True)
@MyProject.operation(
cmd=True, directives={"nranks": 4, "omp_num_threads": 4}, with_job=True
)
def md(job):
return _mdrun_str("md")
return _mdrun_str("md", nt=4).format(job)


if __name__ == "__main__":
Expand Down
6 changes: 3 additions & 3 deletions projects/flow.gmx-mtools/src/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ def initialize(job):
@MyProject.post(minimized)
@MyProject.operation(cmd=True, with_job=True)
def em(job):
return gromacs_command(name="em", gro="init", sys="init")
return gromacs_command(name="em", gro="init", sys="init").format(job)


@MyProject.pre(minimized)
@MyProject.post(equilibrated)
@MyProject.operation(cmd=True, with_job=True)
def equil(job):
return gromacs_command(name="equil", gro="em", sys="init")
return gromacs_command(name="equil", gro="em", sys="init").format(job)


@MyProject.pre(equilibrated)
@MyProject.post(sampled)
@MyProject.operation(cmd=True, with_job=True)
def sample(job):
return gromacs_command(name="sample", gro="equil", sys="init")
return gromacs_command(name="sample", gro="equil", sys="init").format(job)


if __name__ == "__main__":
Expand Down
Loading