.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/hello_world.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_hello_world.py: Hello World! ================= Interface Tutorial Requirements: - HPC cluster - Python 3.x Author: DY .. GENERATED FROM PYTHON SOURCE LINES 14-19 .. code-block:: Python from pathlib import Path import os import time .. GENERATED FROM PYTHON SOURCE LINES 20-24 One of the motivations behind reForge was to provide a user- and beginner-friendly interface for managing potentially hundreds or thousands of MD simulations without having to switch between multiple scripts and constantly rewriting them—all while staying within comfort of Python. This is what the 'cli' module is for: .. GENERATED FROM PYTHON SOURCE LINES 24-26 .. code-block:: Python from reforge.cli import run, sbatch, dojob .. GENERATED FROM PYTHON SOURCE LINES 27-29 The idea is very simple: suppose you have "n" mutants and you need to perform "n" independent runs for each mutant to achieve sufficient sampling. .. GENERATED FROM PYTHON SOURCE LINES 29-32 .. code-block:: Python systems = [f'mutant_{i}' for i in range(4)] mdruns = [f'mdrun_{i}' for i in range(4)] .. GENERATED FROM PYTHON SOURCE LINES 33-34 The functions run, sbatch, and dojob allow you to execute the same script for all cases: .. GENERATED FROM PYTHON SOURCE LINES 34-38 .. code-block:: Python for system in systems: for mdrun in mdruns: run(f'echo "Hello, I\'m run {mdrun} of {system}"') .. GENERATED FROM PYTHON SOURCE LINES 39-40 Alternatively, you can call run like this: .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python for system in systems: for mdrun in mdruns: run('echo', 'Hello, I\'m run', f'{mdrun} of {system}') .. GENERATED FROM PYTHON SOURCE LINES 45-47 Alternatively, you can sbatch a script. This command passes all positional arguments to the script and keyword arguments to the SLURM scheduler. .. GENERATED FROM PYTHON SOURCE LINES 47-52 .. code-block:: Python if 0: # Set to 1 to actually submit jobs. for system in systems: for mdrun in mdruns: sbatch('hello.sh', mdrun, system, mem='50M', t='00:00:01', partition='htc', qos='public') .. GENERATED FROM PYTHON SOURCE LINES 53-54 By default, output is written to "slurm_jobs/output_file" and "slurm_jobs/error_file". .. GENERATED FROM PYTHON SOURCE LINES 54-60 .. code-block:: Python outfiles = [f for f in Path('slurm_jobs').glob('*output*')] for fpath in outfiles: with open(fpath, 'r') as file: # Print only the first line of each output file. print(file.readline(), end='') .. rst-class:: sphx-glr-script-out .. code-block:: none Hello I am run mdrun_0 of system mutant_1 Hello I am run mdrun_2 of system mutant_0 Hello I am run mdrun_2 of system mutant_3 Hello I am run mdrun_1 of system mutant_2 Hello I am run mdrun_0 of system mutant_2 Hello I am run mdrun_3 of system mutant_1 Hello I am run mdrun_2 of system mutant_1 Hello I am run mdrun_1 of system mutant_3 Hello I am run mdrun_3 of system mutant_0 Hello I am run mdrun_0 of system mutant_3 Hello I am run mdrun_1 of system mutant_0 Hello I am run mdrun_1 of system mutant_1 Hello I am run mdrun_3 of system mutant_2 Hello I am run mdrun_3 of system mutant_3 Hello I am run mdrun_0 of system mutant_0 Hello I am run mdrun_2 of system mutant_2 .. GENERATED FROM PYTHON SOURCE LINES 61-63 For convenience, dojob will either submit or run the script based on its first argument. In this case, we do not want to sbatch the script. .. GENERATED FROM PYTHON SOURCE LINES 63-67 .. code-block:: Python submit = False for system in systems: for mdrun in mdruns: dojob(submit, 'hello.sh', mdrun, system, mem='50M', t='00:00:01', partition='htc', qos='public') .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.175 seconds) .. _sphx_glr_download_auto_examples_hello_world.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: hello_world.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: hello_world.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: hello_world.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_