Interactively stepping through KIMMDY

Setup

Code
from kimmdy.config import Config
from kimmdy.runmanager import RunManager, State
from kimmdy.plugins import reaction_plugins, discover_plugins, parameterization_plugins
from kimmdy.analysis import concat_traj, plot_rates
from kimmdy.tasks import TaskFiles
from kimmdy_hydrolysis.reaction import HydrolysisReaction

discover_plugins()

Note, that In order for kimmdy in our python session to know about the plugins we have installed, we need to discover them (see above).

Check that your plugin is registered with kimmdy:

Code
reaction_plugins
{'hat_reaction': HATreaction.reaction.HAT_reaction,
 'dummyreaction': dummyreaction.reaction.DummyReaction,
 'hat_naive': hat_naive.reaction.NaiveHAT,
 'homolysis': homolysis.reaction.Homolysis,
 'hydrolysis': kimmdy_hydrolysis.reaction.HydrolysisReaction,
 'specbond': specbond.reaction.SpecBond}
Code
parameterization_plugins
{'grappa': kimmdy_grappa.grappa_interface.GrappaInterface}

Full kimmdy run with hydrolysis

Create a configuration object from python:

Code
config = Config(
  opts={
    "name": "run",
    "cwd": "./examples/triplehelix-hydrolysis/",
    "sequence": ["pull-short", "reactions", "pull", "reactions", "pull"],
    "reactions": {
      "hydrolysis_naive": {
        "arrhenius_equation": {
          "frequency_factor": 0.288,
          "temperature": 300
        }
      },
      "homolysis": {
        "arrhenius_equation": {
          "frequency_factor": 0.288,
          "temperature": 300
        },
        "edis": "assets/edissoc.dat",
        "itp": "assets/ffbonded.itp"
      }
    },
    "plumed": "assets/plumed.dat",
    "mds": {
      "pull-short": {
        "mdp": "pull-short.mdp",
      },
      "pull": {
        "mdp": "pull.mdp",
      },
      "relax": {
        "mdp": "relax.mdp",
      },
    },
    "topology": {
      "reactive": {"include": "SOL"},
    },
    "parameterize_at_setup": False,
    "changer": {
      "topology": {
        "parameterization": "grappa",
      },
      "coordinates": {
        "md": "relax",
        "slow_growth": True,
      },
    },
    "kmc": "rfkmc",
    "top": "triple.top",
    "gro": "triple-eq.gro",
    "ndx": "index.ndx",
    # by supplying already pre-caculated trajectories, we can skip the md part
    # for testing purposes
    "tpr": "pull.tpr",
    "xtc": "pull.xtc",
    "trr": "pull.trr"
  }
)

Explore

Code
run = RunManager(config=config)

Explore Hydrolysis

Code
hyd = HydrolysisReaction('hydrolysis_naive', run)
Code
files = TaskFiles(run.get_latest)
Code
result = hyd.get_recipe_collection(files)
Code
result.recipes[0]

We can check again what tasks are currently planned:

Code
run.tasks.queue

We could run all the tasks

Code
while run.state != State.DONE:
    next(run)

Or instead step thorugh one by one.

Note, that tasks can also add intermediate tasks to a queue that will be cleared before the next task in the tasks queue is executed. Right now it is empty:

Code
run.priority_tasks.queue

Calling the next function on the RunManager instance will execute the next task in the queue. Let’s do this three times:

Code
for i in range(2):
    next(run)

The place_reaction_tasks task should now have filled the priority_tasks queue:

Code
run.priority_tasks.queue

Because of this, the next task will be query_rection (one tasks per reaction, but in this case we only have one reaction):

Code
next(run)

priority_tasks is now empty:

Code
run.priority_tasks.queue

So the next task will decide on a Recipe based on the results it got from the reaction plugins:

Code
run.tasks.queue
Code
run.recipe_collection.recipes[:3]
Code
next(run)

Our Kinetic Monte Carlo (KMC) result is now available:

Code
run.kmcresult

So the next task will execute the chosen reaction’s recipe.

Code
next(run)

Just the reaction

Code
opts_for_just_reaction = {
    "name": "run",
    "cwd": "./examples/settles/",
    "sequence": ["reactions"],
    "reactions": {
        "hydrolysis_naive": {
            "rates_per_frame": True,
            "manual_residuetypes": False,
            "relax": False,
        }
    },
    "mds": {
        "relax": {
            "mdp": "relax.mdp",
        },
    },
    "topology": {
        "reactive": {"include": "SOL"},
    },
    "parameterize_at_setup": False,
    "changer": {
        "topology": {
            "parameterization": "grappa",
        },
        "coordinates": {
            "md": "relax",
            "slow_growth": True,
        },
    },
    "kmc": "rfkmc",
    "top": "triple.top",
    "gro": "triple-eq.gro",
    "ndx": "index.ndx",
    "tpr": "pull.tpr",
    "xtc": "pull.xtc",
    "trr": "pull.trr"
}
config = Config(opts=opts_for_just_reaction)
run = RunManager(config=config)
run.run()

Archiv

Code
opts_for_just_reaction = {
    "name": "run",
    "cwd": "./examples/triplehelix-hydrolysis/",
    "sequence": ["reactions"],
    "reactions": {
        "hydrolysis_naive": {
        }
    },
    "mds": {
        "relax": {
            "mdp": "pull-slow-growth.mdp",
        },
    },
    "topology": {
        "reactive": {"include": "SOL"},
    },
    "parameterize_at_setup": False,
    "changer": {
        "topology": {
            "parameterization": "grappa",
        },
        "coordinates": {
            "md": "relax",
            "slow_growth": True,
        },
    },
    "kmc": "rfkmc",
    "top": "triple.top",
    "gro": "triple-eq.gro",
    "ndx": "index.ndx",
    "tpr": "pull.tpr",
    "xtc": "pull.xtc",
    "trr": "pull.trr"
}
Code
run2 = RunManager(config=Config(opts=opts_for_just_reaction))
Code
for i in range(3):
    next(run2)
Code
next(run2)
Code
run2.recipe_collection
Code
run2.tasks.queue
Code
run2.kmcresult
Code
next(run2)
Code
while run2.state != State.DONE:
    next(run2)

kimmdy.3_apply_recipe INFO: Recipe: 642⚡644 131300⚡131301 131300⚡131302 131300➡642 131301➡644 131302➡64

Code
concat_traj(
  dir = "./examples/triplehelix-hydrolysis/run_010/",
  filetype="xtc",
  steps="all",
  output_group="System",
  open_vmd=True
)
Code
plot_rates(
  dir = "./examples/triplehelix-hydrolysis/run_022/",
)