From f1f3d6d202bdf9d24937fe44d26ce1d43625152b Mon Sep 17 00:00:00 2001 From: Sarath Date: Tue, 16 Jul 2024 12:06:56 +0200 Subject: [PATCH] add workflow linking example --- .../06_linking_calculations.ipynb | 407 ++++++++++++++++++ 1 file changed, 407 insertions(+) create mode 100644 examples/workflow_examples/06_linking_calculations.ipynb diff --git a/examples/workflow_examples/06_linking_calculations.ipynb b/examples/workflow_examples/06_linking_calculations.ipynb new file mode 100644 index 0000000..c7120a0 --- /dev/null +++ b/examples/workflow_examples/06_linking_calculations.ipynb @@ -0,0 +1,407 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Linking calculations" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "%config IPCompleter.evaluation='unsafe'" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "10ca3afd28c24e45935e4673526b8e2c", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "from pyiron_atomistics import Project\n", + "from atomrdf import KnowledgeGraph\n", + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "project = 'wf9d52b'\n", + "pr = Project(project)\n", + "kg = KnowledgeGraph(store='db', store_file=f'{project}.db')\n", + "kg.enable_workflow(pr, workflow_environment='pyiron')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Run a MD simulation; and get the relaxed structure" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The job j1 was saved and received the ID: 1148\n" + ] + } + ], + "source": [ + "structure = pr.create.structure.annotated_structure.bulk('Cu', cubic=True, label='cu_min', repetitions=(3,3,3))\n", + "job = pr.create.job.Lammps('j1', delete_existing_job=True, delete_aborted_job=True)\n", + "job.structure = structure\n", + "job.potential = '2001--Mishin-Y--Cu-1--LAMMPS--ipr1'\n", + "job.calc_minimize(pressure=0)\n", + "job.run()\n", + "kg.add_workflow(job, workflow_environment='pyiron')" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[cu_min, sample:a7f6ce8a-ce7d-4609-9aa3-56d7ddf21947_from_cu_min]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kg.samples" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "sample = kg.samples[-1]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The relaxed structure values are also calculation outputs" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "TotalEnergy, TotalVolume, SimulationCellLength_x, SimulationCellLength_y, SimulationCellLength_z, Volume, NumberOfAtoms" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sample.outputs" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "a = sample.outputs.SimulationCellLength_x/3" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3.615 ANGSTROM" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now create a new structure with this and run a MD simulation" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "rel_struct = pr.create.structure.annotated_structure.bulk('Cu', cubic=True, label='cu_new',\n", + " a=a, repetitions=(3,3,3))" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The job j1 was saved and received the ID: 1148\n" + ] + } + ], + "source": [ + "job = pr.create.job.Lammps('j1', delete_existing_job=True, delete_aborted_job=True)\n", + "job.structure = rel_struct\n", + "job.potential = '2001--Mishin-Y--Cu-1--LAMMPS--ipr1'\n", + "job.calc_md(pressure=0, temperature=300)\n", + "job.run()\n", + "kg.add_workflow(job, workflow_environment='pyiron')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Check the KG" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "image/svg+xml": [ + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "sample_a7f6ce8a-ce7d-4609-9aa3-56d7ddf21947\n", + "\n", + "sample_a7f6ce8a-ce7d-4609-9aa3-56d7ddf21947\n", + "\n", + "\n", + "\n", + "sample_ef711752-603e-4b84-8f77-7b9e03132d48\n", + "\n", + "sample_ef711752-603e-4b84-8f77-7b9e03132d48\n", + "\n", + "\n", + "\n", + "sample_a7f6ce8a-ce7d-4609-9aa3-56d7ddf21947->sample_ef711752-603e-4b84-8f77-7b9e03132d48\n", + "\n", + "\n", + "wasDerivedFrom\n", + "\n", + "\n", + "\n", + "activity_4f1b4767-6502-4f00-b35b-c6bb613d26de\n", + "\n", + "activity_4f1b4767-6502-4f00-b35b-c6bb613d26de\n", + "\n", + "\n", + "\n", + "sample_a7f6ce8a-ce7d-4609-9aa3-56d7ddf21947->activity_4f1b4767-6502-4f00-b35b-c6bb613d26de\n", + "\n", + "\n", + "wasGeneratedBy\n", + "\n", + "\n", + "\n", + "sample_60996d0a-82b3-4812-a61f-9029e9e57ca8\n", + "\n", + "sample_60996d0a-82b3-4812-a61f-9029e9e57ca8\n", + "\n", + "\n", + "\n", + "sample_60996d0a-82b3-4812-a61f-9029e9e57ca8->sample_a7f6ce8a-ce7d-4609-9aa3-56d7ddf21947\n", + "\n", + "\n", + "wasDerivedFrom\n", + "\n", + "\n", + "\n", + "sample_536d4ce9-8b97-4f0e-a7d0-4d82beee4fe9\n", + "\n", + "sample_536d4ce9-8b97-4f0e-a7d0-4d82beee4fe9\n", + "\n", + "\n", + "\n", + "sample_536d4ce9-8b97-4f0e-a7d0-4d82beee4fe9->sample_60996d0a-82b3-4812-a61f-9029e9e57ca8\n", + "\n", + "\n", + "wasDerivedFrom\n", + "\n", + "\n", + "\n", + "activity_c2b6577c-a338-4276-90ca-f372f3085c00\n", + "\n", + "activity_c2b6577c-a338-4276-90ca-f372f3085c00\n", + "\n", + "\n", + "\n", + "sample_536d4ce9-8b97-4f0e-a7d0-4d82beee4fe9->activity_c2b6577c-a338-4276-90ca-f372f3085c00\n", + "\n", + "\n", + "wasGeneratedBy\n", + "\n", + "\n", + "\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kg.visualise(sample_view=True)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "We can also query and see the lattice parameter was calculated by an activity" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
LatticeParameterwasCalculatedBy
0sample:60996d0a-82b3-4812-a61f-9029e9e57ca8_La...operation:04fc5b80-11c0-4b7f-9125-0e04516807c6
\n", + "
" + ], + "text/plain": [ + " LatticeParameter \\\n", + "0 sample:60996d0a-82b3-4812-a61f-9029e9e57ca8_La... \n", + "\n", + " wasCalculatedBy \n", + "0 operation:04fc5b80-11c0-4b7f-9125-0e04516807c6 " + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kg.auto_query(kg.terms.cmso.LatticeParameter, [kg.terms.asmo.wasCalculatedBy])" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "workflow-rdf", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.8" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}