Skip to content

Commit

Permalink
fix make file, add README, add CI check (#25)
Browse files Browse the repository at this point in the history
* add contrib info

* run pre-commit hooks

* remove make.bat

* update structure relax

* update notebook

* glob and update notebook
  • Loading branch information
PythonFZ authored Nov 26, 2024
1 parent b7bbca2 commit e6f4167
Show file tree
Hide file tree
Showing 7 changed files with 237 additions and 637 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/pre-comit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
6 changes: 3 additions & 3 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
BUILDDIR = ../build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@cd "$(SOURCEDIR)" && $(SPHINXBUILD) -M help "." "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
@cd "$(SOURCEDIR)" && $(SPHINXBUILD) -M $@ "." "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 0 additions & 35 deletions docs/make.bat

This file was deleted.

3 changes: 2 additions & 1 deletion docs/source/build_graph.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ You will learn how to include :term:`MLIP` that can not be interfaced with the :
With your own custom Nodes you can build more comprehensive test cases or go even beyond :term:`MLIP` testing and build workflows for other scenarios, such as :term:`MLIP` training with :code:`mlipx` and :term:`IPSuite`.

.. toctree::
:glob:

notebooks/structure_relaxation.ipynb
notebooks/*
195 changes: 195 additions & 0 deletions docs/source/notebooks/combine.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/basf/mlipx/blob/main/docs/source/notebooks/combine.ipynb)\n",
"\n",
"# Combine Multiple Nodes\n",
"\n",
"The `mlipx` command line interface provides you with recipes for specific tasks.\n",
"In this notebook, we will write a script to include different aspects from different recipes into a single workflow."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Only install the packages if they are not already installed\n",
"!pip show mlipx > /dev/null 2>&1 || pip install mlipx\n",
"!pip show rdkit2ase > /dev/null 2>&1 || pip install rdkit2ase"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# We will create a GIT and DVC repository in a temporary directory\n",
"import os\n",
"import tempfile\n",
"\n",
"temp_dir = tempfile.TemporaryDirectory()\n",
"os.chdir(temp_dir.name)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Like all `mlipx` Nodes we will use a GIT and DVC repository to run experiments.\n",
"To make our custom code available, we structure our project like\n",
"\n",
"```\n",
"relaxation/\n",
" ├── .git/\n",
" ├── .dvc/\n",
" ├── src/__init__.py\n",
" ├── src/relaxation.py\n",
" ├── models.py\n",
" └── main.py\n",
"```\n",
"\n",
"to allow us to import our code `from src.relaxation import Relax`.\n",
"Alternatively, you can package your code and import it like any other Python package."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!git init\n",
"!dvc init --quiet"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let us configure now configure a workflow, creating a structure from `SMILES`, relax it, run molecular dynamics and compute the homonuclear diatomics."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import mlipx\n",
"\n",
"project = mlipx.Project()\n",
"\n",
"emt = mlipx.GenericASECalculator(\n",
" module=\"ase.calculators.emt\",\n",
" class_name=\"EMT\",\n",
")\n",
"\n",
"with project.group(\"initialize\"):\n",
" confs = mlipx.Smiles2Conformers(smiles=\"CCCC\", num_confs=1)\n",
"\n",
"with project.group(\"structure-optimization\"):\n",
" struct_optim = mlipx.StructureOptimization(\n",
" data=confs.frames, data_id=-1, optimizer=\"LBFGS\", model=emt\n",
" )\n",
"\n",
"thermostat = mlipx.LangevinConfig(\n",
" timestep=0.5,\n",
" temperature=300,\n",
" friction=0.001,\n",
")\n",
"\n",
"with project.group(\"molecular-dynamics\"):\n",
" md = mlipx.MolecularDynamics(\n",
" data=struct_optim.frames,\n",
" data_id=-1,\n",
" model=emt,\n",
" thermostat=thermostat,\n",
" steps=1000,\n",
" )\n",
"\n",
"with project.group(\"homonuclear-diatomics\"):\n",
" ev = mlipx.HomonuclearDiatomics(\n",
" data=confs.frames,\n",
" model=emt,\n",
" n_points=100,\n",
" min_distance=0.75,\n",
" max_distance=2.0,\n",
" elements=[],\n",
" )\n",
"\n",
"project.repro()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Once the graph has been executed, we can look at the resulting structures."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"struct_optim.figures[\"energy_vs_steps\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"md.figures[\"energy\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(ev.figures.keys())\n",
"ev.figures[\"C-C bond\"]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"temp_dir.cleanup()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "mlipx",
"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.10"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit e6f4167

Please sign in to comment.