<jupyter_start><jupyter_text>Implementing a new simulation codeAppendix C in the pyiron paperhttps://www.sciencedirect.com/science/article/pii/S0927025618304786<jupyter_code>from os.path import join
from pyiron_base.job.generic import GenericJob
from pyiron_base.generic.parameters import GenericParameters
class ToyJob(GenericJob):
    def __init__(self, project, job_name):
        super().__init__(project, job_name) 
        self.input = GenericParameters(table_name="input")
        self.input['input_energy'] = 100
        self.executable = "cat input > output"

    def write_input(self): 
        self.input.write_file( 
            file_name="input",
            cwd=self.working_directory
        )

    def collect_output(self):
        file = join(self.working_directory, "output") 
        with open(file) as f:
            line = f.readlines()[0]
        energy = float(line.split()[1]) 
        with self.project_hdf5.open("output/generic") as h5out: 
            h5out["energy_tot"] = energy

    def to_hdf(self, hdf=None, group_name=None): 
        super().to_hdf(
            hdf=hdf,
            group_name=group_name
        )
        with self.project_hdf5.open("input") as h5in:
            self.input.to_hdf(h5in)

    def from_hdf(self, hdf=None, group_name=None): 
        super().from_hdf(
            hdf=hdf,
            group_name=group_name
        )
        with self.project_hdf5.open("input") as h5in:
            self.input.from_hdf(h5in)
from pyiron_base import Project
pr = Project('test')
pr.remove_jobs_silently(recursive=True)
job = pr.create_job(job_type=ToyJob, job_name="toy")
print(job.input)
job.run()
job['output/generic/energy_tot']<jupyter_output>Parameter  Value Comment
0  input_energy    100        
The job toy was saved and received the ID: 1
{'fraction_non_alphanumeric': 0.10584958217270195, 'fraction_numerical': 0.019498607242339833, 'mean_word_length': 2.89587852494577, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '42890', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 611, 'n_tokens_neox': 580, 'n_words': 113, 'path': 'notebooks/pyiron_paper.ipynb', 'repo_name': 'pmrv/pyiron_base', 'size': '1795'}