Combine Multiple Nodes¶
The mlipx command line interface provides you with recipes for specific tasks. In this notebook, we will write a script to include different aspects from different recipes into a single workflow.
[1]:
# Only install the packages if they are not already installed
!pip show mlipx > /dev/null 2>&1 || pip install mlipx
!pip show rdkit2ase > /dev/null 2>&1 || pip install rdkit2ase
[2]:
# We will create a GIT and DVC repository in a temporary directory
import os
import tempfile
temp_dir = tempfile.TemporaryDirectory()
os.chdir(temp_dir.name)
Like all mlipx Nodes we will use a GIT and DVC repository to run experiments. To make our custom code available, we structure our project like
relaxation/
├── .git/
├── .dvc/
├── src/__init__.py
├── src/relaxation.py
├── models.py
└── main.py
to allow us to import our code from src.relaxation import Relax. Alternatively, you can package your code and import it like any other Python package.
[3]:
!git init
!dvc init --quiet
Initialized empty Git repository in /private/var/folders/81/0x90c4yd0cz6tz104v9syf580000gn/T/tmpqt0ewb9_/.git/
Let us configure now configure a workflow, creating a structure from SMILES, relax it, run molecular dynamics and compute the homonuclear diatomics.
[4]:
import mlipx
project = mlipx.Project()
emt = mlipx.GenericASECalculator(
module="ase.calculators.emt",
class_name="EMT",
)
with project.group("initialize"):
confs = mlipx.Smiles2Conformers(smiles="CCCC", num_confs=1)
with project.group("structure-optimization"):
struct_optim = mlipx.StructureOptimization(
data=confs.frames, data_id=-1, optimizer="LBFGS", model=emt
)
thermostat = mlipx.LangevinConfig(
timestep=0.5,
temperature=300,
friction=0.001,
)
with project.group("molecular-dynamics"):
md = mlipx.MolecularDynamics(
data=struct_optim.frames,
data_id=-1,
model=emt,
thermostat=thermostat,
steps=1000,
)
with project.group("homonuclear-diatomics"):
ev = mlipx.HomonuclearDiatomics(
data=confs.frames,
model=emt,
n_points=100,
min_distance=0.75,
max_distance=2.0,
elements=[],
)
project.repro()
2024-12-04 08:57:41,326 - INFO: Saving params.yaml
100%|██████████| 4/4 [00:00<00:00, 721.91it/s]
Running stage 'initialize_Smiles2Conformers':
> zntrack run mlipx.nodes.smiles.Smiles2Conformers --name initialize_Smiles2Conformers
Generating lock file 'dvc.lock'
Updating lock file 'dvc.lock'
Running stage 'homonuclear-diatomics_HomonuclearDiatomics':
> zntrack run mlipx.nodes.diatomics.HomonuclearDiatomics --name homonuclear-diatomics_HomonuclearDiatomics
H-H bond (0.62 Å): 100%|██████████| 100/100 [00:00<00:00, 1730.64it/s]
C-C bond (1.52 Å): 100%|██████████| 100/100 [00:00<00:00, 2193.13it/s]
Updating lock file 'dvc.lock'
Running stage 'structure-optimization_StructureOptimization':
> zntrack run mlipx.nodes.structure_optimization.StructureOptimization --name structure-optimization_StructureOptimization
Step Time Energy fmax
LBFGS: 0 08:57:45 4.724808 4.228024
LBFGS: 1 08:57:45 3.694983 2.695507
LBFGS: 2 08:57:45 3.002409 1.492604
LBFGS: 3 08:57:45 2.821451 1.084243
LBFGS: 4 08:57:45 2.664413 1.026595
LBFGS: 5 08:57:45 2.491459 0.799510
LBFGS: 6 08:57:45 2.425135 0.284369
LBFGS: 7 08:57:45 2.421406 0.196046
LBFGS: 8 08:57:45 2.419364 0.177538
LBFGS: 9 08:57:45 2.415200 0.195117
LBFGS: 10 08:57:45 2.410975 0.242129
LBFGS: 11 08:57:45 2.406195 0.232087
LBFGS: 12 08:57:45 2.403611 0.114803
LBFGS: 13 08:57:45 2.402815 0.057201
LBFGS: 14 08:57:45 2.402620 0.064960
LBFGS: 15 08:57:45 2.401299 0.147884
LBFGS: 16 08:57:45 2.398543 0.279003
LBFGS: 17 08:57:45 2.378905 0.736798
LBFGS: 18 08:57:45 2.422713 0.995216
LBFGS: 19 08:57:45 2.389691 0.811611
LBFGS: 20 08:57:45 2.399295 0.767810
LBFGS: 21 08:57:45 2.421218 0.350004
LBFGS: 22 08:57:45 2.392677 0.721292
LBFGS: 23 08:57:45 2.362266 0.852960
LBFGS: 24 08:57:45 2.404921 0.574016
LBFGS: 25 08:57:45 2.466467 0.712450
LBFGS: 26 08:57:45 2.396067 0.563970
LBFGS: 27 08:57:45 2.373340 0.661065
LBFGS: 28 08:57:45 2.413167 0.279068
LBFGS: 29 08:57:45 2.480018 0.862628
LBFGS: 30 08:57:45 2.410237 0.274582
LBFGS: 31 08:57:45 2.394107 0.418984
LBFGS: 32 08:57:45 2.335191 0.600363
LBFGS: 33 08:57:45 2.393647 0.408179
LBFGS: 34 08:57:45 2.447513 0.560576
LBFGS: 35 08:57:45 2.391865 0.393705
LBFGS: 36 08:57:45 2.373368 0.492743
LBFGS: 37 08:57:45 2.435855 0.493584
LBFGS: 38 08:57:45 2.373998 0.454940
LBFGS: 39 08:57:45 2.360254 0.638154
LBFGS: 40 08:57:45 2.407103 0.315460
LBFGS: 41 08:57:45 2.365838 0.715909
LBFGS: 42 08:57:45 2.368027 1.033230
LBFGS: 43 08:57:45 2.399865 0.369117
LBFGS: 44 08:57:45 2.365658 0.981589
LBFGS: 45 08:57:45 2.363580 0.951514
LBFGS: 46 08:57:45 2.344455 0.266927
LBFGS: 47 08:57:45 2.320914 0.617892
LBFGS: 48 08:57:45 2.299608 0.886820
LBFGS: 49 08:57:45 2.294743 0.876087
LBFGS: 50 08:57:45 2.282608 0.753598
LBFGS: 51 08:57:45 2.273683 0.641003
LBFGS: 52 08:57:45 2.254499 0.394442
LBFGS: 53 08:57:45 2.243769 0.411168
LBFGS: 54 08:57:45 2.222896 0.379403
LBFGS: 55 08:57:45 2.202550 0.509002
LBFGS: 56 08:57:45 2.180746 0.453338
LBFGS: 57 08:57:45 2.160522 0.440702
LBFGS: 58 08:57:45 2.140143 0.477836
LBFGS: 59 08:57:45 2.126674 0.253944
LBFGS: 60 08:57:45 2.109673 0.346025
LBFGS: 61 08:57:45 2.088406 0.491314
LBFGS: 62 08:57:45 2.064287 0.622375
LBFGS: 63 08:57:45 2.072785 0.665291
LBFGS: 64 08:57:45 2.032567 0.270466
LBFGS: 65 08:57:45 2.027569 0.165839
LBFGS: 66 08:57:45 2.023181 0.242900
LBFGS: 67 08:57:45 2.019414 0.279579
LBFGS: 68 08:57:45 2.013816 0.201534
LBFGS: 69 08:57:45 2.009762 0.216292
LBFGS: 70 08:57:45 2.005202 0.245885
LBFGS: 71 08:57:45 1.999113 0.277390
LBFGS: 72 08:57:45 1.992085 0.345559
LBFGS: 73 08:57:45 1.977779 0.379235
LBFGS: 74 08:57:45 1.976412 0.845377
LBFGS: 75 08:57:45 1.962979 0.595975
LBFGS: 76 08:57:45 1.980746 0.597380
LBFGS: 77 08:57:45 1.928990 0.296365
LBFGS: 78 08:57:45 1.914401 0.341064
LBFGS: 79 08:57:45 1.901031 0.248728
LBFGS: 80 08:57:45 1.874226 0.331118
LBFGS: 81 08:57:45 1.866228 0.381243
LBFGS: 82 08:57:45 1.858389 0.312143
LBFGS: 83 08:57:45 1.849670 0.214870
LBFGS: 84 08:57:45 1.840588 0.212578
LBFGS: 85 08:57:45 1.831122 0.208976
LBFGS: 86 08:57:45 1.816450 0.284739
LBFGS: 87 08:57:45 1.808331 0.264167
LBFGS: 88 08:57:45 1.804893 0.140377
LBFGS: 89 08:57:45 1.803125 0.126006
LBFGS: 90 08:57:45 1.800239 0.157320
LBFGS: 91 08:57:45 1.794588 0.209665
LBFGS: 92 08:57:45 1.784398 0.267433
LBFGS: 93 08:57:45 1.766477 0.405933
LBFGS: 94 08:57:45 1.750226 0.504541
LBFGS: 95 08:57:45 1.731663 0.463239
LBFGS: 96 08:57:45 1.740648 0.581978
LBFGS: 97 08:57:45 1.714884 0.197589
LBFGS: 98 08:57:45 1.711533 0.212479
LBFGS: 99 08:57:45 1.705468 0.200734
LBFGS: 100 08:57:45 1.698790 0.215090
LBFGS: 101 08:57:45 1.694107 0.218013
LBFGS: 102 08:57:45 1.687245 0.261569
LBFGS: 103 08:57:45 1.679483 0.235316
LBFGS: 104 08:57:45 1.672388 0.212389
LBFGS: 105 08:57:45 1.667900 0.204184
LBFGS: 106 08:57:45 1.664014 0.206811
LBFGS: 107 08:57:45 1.659842 0.174513
LBFGS: 108 08:57:45 1.655629 0.134345
LBFGS: 109 08:57:45 1.653944 0.117043
LBFGS: 110 08:57:45 1.651874 0.137774
LBFGS: 111 08:57:45 1.650047 0.118101
LBFGS: 112 08:57:45 1.648620 0.097428
LBFGS: 113 08:57:45 1.647591 0.078790
LBFGS: 114 08:57:45 1.646531 0.073324
LBFGS: 115 08:57:45 1.645431 0.086058
LBFGS: 116 08:57:45 1.644287 0.077183
LBFGS: 117 08:57:45 1.643064 0.067262
LBFGS: 118 08:57:45 1.641630 0.077393
LBFGS: 119 08:57:45 1.639628 0.122925
LBFGS: 120 08:57:45 1.637171 0.153202
LBFGS: 121 08:57:45 1.633396 0.151970
LBFGS: 122 08:57:45 1.631406 0.123032
LBFGS: 123 08:57:45 1.629801 0.138668
LBFGS: 124 08:57:45 1.628508 0.076032
LBFGS: 125 08:57:45 1.626819 0.090770
LBFGS: 126 08:57:45 1.625614 0.097005
LBFGS: 127 08:57:45 1.624000 0.120846
LBFGS: 128 08:57:45 1.621755 0.153207
LBFGS: 129 08:57:45 1.617995 0.175126
LBFGS: 130 08:57:45 1.612236 0.167277
LBFGS: 131 08:57:45 1.607476 0.125770
LBFGS: 132 08:57:45 1.605520 0.112356
LBFGS: 133 08:57:45 1.604348 0.074151
LBFGS: 134 08:57:45 1.603837 0.047431
Updating lock file 'dvc.lock'
Running stage 'molecular-dynamics_MolecularDynamics':
> zntrack run mlipx.nodes.molecular_dynamics.MolecularDynamics --name molecular-dynamics_MolecularDynamics
1001it [00:02, 338.00it/s]
Updating lock file 'dvc.lock'
To track the changes with git, run:
git add nodes/homonuclear-diatomics/HomonuclearDiatomics/.gitignore nodes/initialize/Smiles2Conformers/.gitignore nodes/structure-optimization/StructureOptimization/.gitignore nodes/molecular-dynamics/MolecularDynamics/.gitignore dvc.lock
To enable auto staging, run:
dvc config core.autostage true
Use `dvc push` to send your updates to remote storage.
Once the graph has been executed, we can look at the resulting structures.
[5]:
print(md.figures.keys())
print(struct_optim.figures.keys())
print(ev.figures.keys())
dict_keys(['energy', 'fmax', 'fnorm'])
dict_keys(['energy_vs_steps', 'fmax_vs_steps'])
dict_keys(['H-H bond', 'C-C bond'])
[6]:
temp_dir.cleanup()
[ ]: