Commit 18169ae7 authored by Sudarsan Surendralal's avatar Sudarsan Surendralal
Browse files

Final cleanup

parent 90a83e24
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"cells": [ "cells": [
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "naval-truck", "id": "appointed-stylus",
"metadata": {}, "metadata": {},
"source": [ "source": [
"# [**Workflows for atomistic simulations**](http://potentials.rub.de/) " "# [**Workflows for atomistic simulations**](http://potentials.rub.de/) "
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "pregnant-battery", "id": "straight-bicycle",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## **Day 1 - Atomistic simulations with [pyiron](https://pyiron.org)**\n", "## **Day 1 - Atomistic simulations with [pyiron](https://pyiron.org)**\n",
...@@ -27,10 +27,20 @@ ...@@ -27,10 +27,20 @@
"* Creating structure databases and working with them for potential fitting (day 2)" "* Creating structure databases and working with them for potential fitting (day 2)"
] ]
}, },
{
"cell_type": "markdown",
"id": "durable-leone",
"metadata": {},
"source": [
"## **Importing necessary modules and creating a project**\n",
"\n",
"This is done the same way as shown in the first exercise"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"id": "roman-wilderness", "id": "novel-wisconsin",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -42,68 +52,91 @@ ...@@ -42,68 +52,91 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 2, "execution_count": 2,
"id": "charming-furniture", "id": "sitting-religious",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from pyiron import Project\n", "from pyiron import Project"
"import pyiron_contrib"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 3,
"id": "bibliographic-honey", "id": "technical-newport",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"pr = Project(\"creating_datasets\")" "pr = Project(\"creating_datasets\")"
] ]
}, },
{
"cell_type": "markdown",
"id": "based-kentucky",
"metadata": {},
"source": [
"## Creating a structure \"container\" from the data\n",
"\n",
"We now go over the jobs generated in the first notebook to store structures, energies, and forces into a structure container which will later be used for potential fitting\n",
"\n",
"**Note**: Usually these datasets are created using highly accurate DFT calculations. But for practical reasons, we only demonstrate how to do this using data from LAMMPS calculations (the workflow remain the same)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 4, "execution_count": 9,
"id": "relative-subscriber", "id": "attached-germany",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Access the project created in exercise 1 \n",
"pr_fs = pr[\"../first_steps\"]" "pr_fs = pr[\"../first_steps\"]"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 5, "execution_count": 16,
"id": "solved-sight", "id": "filled-natural",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Create a TrainingContainer job (to store structures and databases)\n",
"container = pr.create.job.TrainingContainer('dataset_example')" "container = pr.create.job.TrainingContainer('dataset_example')"
] ]
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "falling-spouse", "id": "married-storm",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## **Add structures from the E-V curves**" "## **Add structures from the E-V curves**\n",
"\n",
"For starters, we append structures from the energy volume curves we calculated earlier"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 17,
"id": "secure-tract", "id": "mediterranean-upset",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"\n", "# Iterate over the jobs in this sub-project and append the final structure, potential energy, and forces\n",
"for job in pr_fs[\"E_V_curve\"].iter_jobs(status=\"finished\"):\n", "for job in pr_fs[\"E_V_curve\"].iter_jobs(status=\"finished\"):\n",
" container.include_job(job, iteration_step=-1)" " container.include_job(job, iteration_step=-1)"
] ]
}, },
{
"cell_type": "markdown",
"id": "acquired-missile",
"metadata": {},
"source": [
"We can obtain this data as a `pandas` table"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 18,
"id": "wicked-defeat", "id": "greatest-person",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -762,7 +795,7 @@ ...@@ -762,7 +795,7 @@
"46 1.0 " "46 1.0 "
] ]
}, },
"execution_count": 7, "execution_count": 18,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -773,33 +806,36 @@ ...@@ -773,33 +806,36 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "transsexual-journalist", "id": "imperial-belarus",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## **Add structures from the MD**\n", "## **Add structures from the MD**\n",
"\n", "\n",
"Structures sampled every 10 snapshots (we may need to minimize the structures from the MD)" "We also add some structures obtained from the MD simulations"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 20,
"id": "earlier-static", "id": "healthy-structure",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Reloading the MD job\n",
"job_md = pr_fs[\"lammps_job\"]" "job_md = pr_fs[\"lammps_job\"]"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 9, "execution_count": 21,
"id": "narrative-earth", "id": "outside-bhutan",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"# Iterate over the MD-trajectory to append structures\n",
"\n",
"traj_length = len(job_md[\"output/generic/positions\"])\n", "traj_length = len(job_md[\"output/generic/positions\"])\n",
"stride = 10\n", "stride = 10 # append structures every 10 steps\n",
"\n", "\n",
"for i in range(0, traj_length, stride):\n", "for i in range(0, traj_length, stride):\n",
" container.include_job(job_md, iteration_step=i)" " container.include_job(job_md, iteration_step=i)"
...@@ -807,27 +843,30 @@ ...@@ -807,27 +843,30 @@
}, },
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "enclosed-wheel", "id": "minus-blink",
"metadata": {}, "metadata": {},
"source": [ "source": [
"## **Add some defect structures (vacancies, surfaces, etc)**" "## **Add some defect structures (vacancies, surfaces, etc)**\n",
"\n",
"It's necessary to also include some defect structures, and surfaces to the training dataset"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 10, "execution_count": 22,
"id": "broad-symphony", "id": "loaded-sheriff",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"2021-03-06 08:30:54,890 - pyiron_log - WARNING - The job lammps_job_vac is being loaded instead of running. To re-run use the argument 'delete_existing_job=True in create_job'\n" "2021-03-08 11:55:40,043 - pyiron_log - WARNING - The job lammps_job_vac is being loaded instead of running. To re-run use the argument 'delete_existing_job=True in create_job'\n"
] ]
} }
], ],
"source": [ "source": [
"# Setup a MD calculation for a structure with a vacancy\n",
"job_lammps = pr.create.job.Lammps(\"lammps_job_vac\")\n", "job_lammps = pr.create.job.Lammps(\"lammps_job_vac\")\n",
"job_lammps.structure = pr.create_ase_bulk('Cu', cubic=True, a=3.61).repeat([3, 3, 3])\n", "job_lammps.structure = pr.create_ase_bulk('Cu', cubic=True, a=3.61).repeat([3, 3, 3])\n",
"del job_lammps.structure[0]\n", "del job_lammps.structure[0]\n",
...@@ -838,19 +877,20 @@ ...@@ -838,19 +877,20 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 11, "execution_count": 28,
"id": "compatible-planet", "id": "billion-shade",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"2021-03-06 08:30:56,197 - pyiron_log - WARNING - The job lammps_job_surf is being loaded instead of running. To re-run use the argument 'delete_existing_job=True in create_job'\n" "2021-03-08 11:56:36,874 - pyiron_log - WARNING - The job lammps_job_surf is being loaded instead of running. To re-run use the argument 'delete_existing_job=True in create_job'\n"
] ]
} }
], ],
"source": [ "source": [
"# Setup a MD calculation for a surface structure\n",
"job_lammps = pr.create.job.Lammps(\"lammps_job_surf\")\n", "job_lammps = pr.create.job.Lammps(\"lammps_job_surf\")\n",
"job_lammps.structure = pr.create_surface(\"Cu\", surface_type=\"fcc111\", size=(4, 4, 8), vacuum=12, orthogonal=True)\n", "job_lammps.structure = pr.create_surface(\"Cu\", surface_type=\"fcc111\", size=(4, 4, 8), vacuum=12, orthogonal=True)\n",
"job_lammps.potential = '2012--Mendelev-M-I--Cu--LAMMPS--ipr1'\n", "job_lammps.potential = '2012--Mendelev-M-I--Cu--LAMMPS--ipr1'\n",
...@@ -860,8 +900,8 @@ ...@@ -860,8 +900,8 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 12, "execution_count": 29,
"id": "known-helena", "id": "constitutional-throw",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -870,7 +910,7 @@ ...@@ -870,7 +910,7 @@
"{'groups': ['tc'], 'nodes': ['lammps_job_vac', 'lammps_job_surf', 'dataset_example']}" "{'groups': ['tc'], 'nodes': ['lammps_job_vac', 'lammps_job_surf', 'dataset_example']}"
] ]
}, },
"execution_count": 12, "execution_count": 29,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -879,17 +919,24 @@ ...@@ -879,17 +919,24 @@
"pr" "pr"
] ]
}, },
{
"cell_type": "markdown",
"id": "alpine-cooking",
"metadata": {},
"source": [
"We now add these structures to the dataset"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 13, "execution_count": 33,
"id": "committed-leeds", "id": "italian-cleanup",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"for job_md in pr.iter_jobs(convert_to_object=True, status=\"finished\"):\n", "for job_name in [\"lammps_job_vac\", \"lammps_job_surf\"]:\n",
" # only check Lammps jobs\n", " job_md = pr.load(job_name)\n",
" pos = job_md[\"output/generic/positions\"]\n", " pos = job_md[\"output/generic/positions\"]\n",
" if pos is not None:\n",
" traj_length = len(pos)\n", " traj_length = len(pos)\n",
" stride = 10\n", " stride = 10\n",
" for i in range(0, traj_length, stride):\n", " for i in range(0, traj_length, stride):\n",
...@@ -898,26 +945,27 @@ ...@@ -898,26 +945,27 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 14, "execution_count": 34,
"id": "juvenile-animal", "id": "exotic-asset",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"name": "stderr", "name": "stderr",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"2021-03-06 08:31:06,560 - pyiron_log - WARNING - The job dataset_example is being loaded instead of running. To re-run use the argument 'delete_existing_job=True in create_job'\n" "2021-03-08 11:59:00,874 - pyiron_log - WARNING - The job dataset_example is being loaded instead of running. To re-run use the argument 'delete_existing_job=True in create_job'\n"
] ]
} }
], ],
"source": [ "source": [
"# We run the job sto store this dataset in the pyiron database\n",
"container.run()" "container.run()"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 15, "execution_count": 32,
"id": "sensitive-limit", "id": "british-kelly",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1039,7 +1087,7 @@ ...@@ -1039,7 +1087,7 @@
"2 pyiron@cmdell17#1 TrainingContainer 0.4 None None " "2 pyiron@cmdell17#1 TrainingContainer 0.4 None None "
] ]
}, },
"execution_count": 15, "execution_count": 32,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1048,10 +1096,20 @@ ...@@ -1048,10 +1096,20 @@
"pr.job_table()" "pr.job_table()"
] ]
}, },
{
"cell_type": "markdown",
"id": "ideal-volunteer",
"metadata": {},
"source": [
"## **Reloading the dataset**\n",
"\n",
"This dataset can ow be reloaded anywhere to use in the potential fitting procedures"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 16, "execution_count": 35,
"id": "fifteen-farming", "id": "numeric-museum",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
...@@ -1619,7 +1677,7 @@ ...@@ -1619,7 +1677,7 @@
"39 128.0 " "39 128.0 "
] ]
}, },
"execution_count": 16, "execution_count": 35,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
...@@ -1629,10 +1687,18 @@ ...@@ -1629,10 +1687,18 @@
"dataset.to_pandas()" "dataset.to_pandas()"
] ]
}, },
{
"cell_type": "markdown",
"id": "level-dimension",
"metadata": {},
"source": [
"We can now inspect the data in this dataset quite easily"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 17, "execution_count": 36,
"id": "regional-matrix", "id": "visible-execution",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
...@@ -1641,18 +1707,26 @@ ...@@ -1641,18 +1707,26 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 18, "execution_count": 37,
"id": "stupid-palmer", "id": "becoming-integral",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"structures, energies, forces, num_atoms = dataset.to_list()" "structures, energies, forces, num_atoms = dataset.to_list()"
] ]
}, },
{
"cell_type": "markdown",
"id": "novel-usage",
"metadata": {},
"source": [
"The datasets used in the potential fitting procedure for day 2 (obtained from accurate DFT calculations) will be accessed in the same way"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "integrated-knitting", "id": "forced-scotland",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": []
......
%% Cell type:markdown id:naval-truck tags: %% Cell type:markdown id:appointed-stylus tags:
# [**Workflows for atomistic simulations**](http://potentials.rub.de/) # [**Workflows for atomistic simulations**](http://potentials.rub.de/)
%% Cell type:markdown id:pregnant-battery tags: %% Cell type:markdown id:straight-bicycle tags:
## **Day 1 - Atomistic simulations with [pyiron](https://pyiron.org)** ## **Day 1 - Atomistic simulations with [pyiron](https://pyiron.org)**
### **Exercise 2: Creating and working with structure databases** ### **Exercise 2: Creating and working with structure databases**
Before the excercise, you should: Before the excercise, you should:
* Finish exercise 1 * Finish exercise 1
The aim of this exercise is to make you familiar with: The aim of this exercise is to make you familiar with:
* Creating structure databases and working with them for potential fitting (day 2) * Creating structure databases and working with them for potential fitting (day 2)
%% Cell type:code id:roman-wilderness tags: %% Cell type:markdown id:durable-leone tags:
## **Importing necessary modules and creating a project**
This is done the same way as shown in the first exercise
%% Cell type:code id:novel-wisconsin tags:
``` python ``` python
import numpy as np import numpy as np
%matplotlib inline %matplotlib inline
import matplotlib.pylab as plt import matplotlib.pylab as plt
``` ```
%% Cell type:code id:charming-furniture tags: %% Cell type:code id:sitting-religious tags:
``` python ``` python
from pyiron import Project from pyiron import Project
import pyiron_contrib
``` ```
%% Cell type:code id:bibliographic-honey tags: %% Cell type:code id:technical-newport tags:
``` python ``` python
pr = Project("creating_datasets") pr = Project("creating_datasets")
``` ```
%% Cell type:code id:relative-subscriber tags: %% Cell type:markdown id:based-kentucky tags: