Skip to content

Commit 34a3ec0

Browse files
committed
Initial commit
0 parents  commit 34a3ec0

File tree

8 files changed

+4820
-0
lines changed

8 files changed

+4820
-0
lines changed

.gitignore

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
exclude: '.git|.tox'
2+
default_stages: [commit]
3+
fail_fast: true
4+
5+
repos:
6+
- repo: https://github.com/psf/black
7+
rev: 22.8.0
8+
hooks:
9+
- id: black
10+
11+
- repo: https://github.com/timothycrosley/isort
12+
rev: 5.10.1
13+
hooks:
14+
- id: isort
15+
16+
- repo: https://github.com/charliermarsh/ruff-pre-commit
17+
rev: v0.0.133
18+
hooks:
19+
- id: ruff

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Write a ZnTrack Node
2+
3+
## Setup environment
4+
1. Install miniconda https://docs.conda.io/en/latest/miniconda.html
5+
2. Install poetry https://python-poetry.org/docs/
6+
3. Create an environment `conda create -n asemd python`
7+
4. Activate environment `conda activate asemd`
8+
5. Install package `poetry install`
9+
10+
## Test package
11+
run `pytest .` to check if all the tests pass.
12+
13+
The package should work as follows:
14+
15+
```python
16+
import ase_md
17+
18+
atoms = ase_md.simulator.generate_atoms(size=2)
19+
20+
atoms_list = ase_md.simulator.run_simulation(
21+
atoms=atoms, temperature=300, timestep=1.0, dump_interval=5, steps=20
22+
)
23+
24+
rdf = ase_md.simulator.compute_rdf(
25+
atoms_list=atoms_list, rmax=1.0, nbins=50, elements="Cu"
26+
)
27+
```
28+
29+
which builds a DAG like:
30+
31+
[![](https://mermaid.ink/img/pako:eNpNj7EOwjAMRH8l8twOwJYBCRFg6lKYIAxW40KlJqlSRwhV_XdCSyU82ffOtm6AyhsCCXXrX9UTA4uL0k78yiW4umk4EYsde9truIs8305gnUAZnSjUv7pJ6t7bLjKJUh0TggwsBYuNSX-G73EN_CRLGmRqDdUYW9ag3ZissTPIdDAN-wCSQ6QMMLI_v121zLNHNfgIaEHW2PZJpWmnmPNMsTLo0F29XzzjBz3ATgs?type=png)](https://mermaid.live/edit#pako:eNpNj7EOwjAMRH8l8twOwJYBCRFg6lKYIAxW40KlJqlSRwhV_XdCSyU82ffOtm6AyhsCCXXrX9UTA4uL0k78yiW4umk4EYsde9truIs8305gnUAZnSjUv7pJ6t7bLjKJUh0TggwsBYuNSX-G73EN_CRLGmRqDdUYW9ag3ZissTPIdDAN-wCSQ6QMMLI_v121zLNHNfgIaEHW2PZJpWmnmPNMsTLo0F29XzzjBz3ATgs)
32+
33+
## Rewrite the package
34+
- Add an Example using DVC (without ZnTrack)
35+
- Add an Example using ZnTrack
36+
- Add an Example using MLFlow
37+
- Add an Example using Hydra
38+
39+
You can also consider other packages you want to try out.
40+
Some can be found here https://github.com/pditommaso/awesome-pipeline.
41+
42+
## Run experiments:
43+
Test your workflow with different parameters for all Nodes and compare them.

ase_md/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""ASE MD package."""
2+
import importlib.metadata
3+
import logging
4+
import sys
5+
6+
from ase_md import simulator
7+
8+
__all__ = ["simulator"]
9+
10+
__version__ = importlib.metadata.version("ase_md")
11+
12+
13+
logger = logging.getLogger(__name__)
14+
logger.setLevel(logging.INFO)
15+
16+
# Formatter for advanced logging
17+
# formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s : %(message)s')
18+
formatter = logging.Formatter("%(asctime)s (%(levelname)s): %(message)s")
19+
20+
channel = logging.StreamHandler(sys.stdout)
21+
channel.setLevel(logging.DEBUG)
22+
channel.setFormatter(formatter)
23+
24+
logger.addHandler(channel)

ase_md/simulator.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""The ASE MD simulator.
2+
3+
References
4+
----------
5+
https://wiki.fysik.dtu.dk/ase/tutorials/md/md.html
6+
7+
"""
8+
import typing
9+
10+
import ase
11+
import ase.geometry.analysis
12+
import numpy as np
13+
import tqdm
14+
from ase import units
15+
from ase.calculators.emt import EMT
16+
from ase.lattice.cubic import FaceCenteredCubic
17+
from ase.md.velocitydistribution import MaxwellBoltzmannDistribution
18+
from ase.md.verlet import VelocityVerlet
19+
20+
21+
def generate_atoms(size: int = 3) -> ase.Atoms:
22+
"""Generate fcc of Cu."""
23+
return FaceCenteredCubic(
24+
directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
25+
symbol="Cu",
26+
size=(size, size, size),
27+
pbc=True,
28+
)
29+
30+
31+
def printenergy(a: ase.Atoms) -> None:
32+
"""Function to print the potential, kinetic and total energy."""
33+
epot = a.get_potential_energy() / len(a)
34+
ekin = a.get_kinetic_energy() / len(a)
35+
print(
36+
"Energy per atom: Epot = %.3feV Ekin = %.3feV (T=%3.0fK) Etot = %.3feV"
37+
% (epot, ekin, ekin / (1.5 * units.kB), epot + ekin)
38+
)
39+
40+
41+
def run_simulation(
42+
atoms: ase.Atoms,
43+
temperature: float = 300,
44+
timestep: float = 5.0,
45+
steps: int = 20,
46+
dump_interval: int = 10,
47+
) -> typing.List[ase.Atoms]:
48+
"""Run an MD Simulation using ase."""
49+
# Describe the interatomic interactions with the Effective Medium Theory
50+
atoms.calc = EMT()
51+
52+
# Set the momenta corresponding to T=300K
53+
MaxwellBoltzmannDistribution(atoms, temperature_K=temperature)
54+
55+
# We want to run MD with constant energy using the VelocityVerlet algorithm.
56+
dyn = VelocityVerlet(atoms, timestep * units.fs) # fs time step.
57+
58+
atoms_list = []
59+
60+
# Now run the dynamics
61+
printenergy(atoms)
62+
for _ in tqdm.trange(steps, ncols=100):
63+
dyn.run(dump_interval)
64+
printenergy(atoms)
65+
atoms_list.append(atoms.copy())
66+
67+
return atoms_list
68+
69+
70+
def compute_rdf(
71+
atoms_list: typing.List[ase.Atoms], rmax: float, nbins: int, elements: str
72+
) -> dict:
73+
"""Compute RDF."""
74+
analysis = ase.geometry.analysis.Analysis(atoms_list)
75+
data = analysis.get_rdf(rmax=rmax, nbins=nbins, elements=elements)
76+
return {"x": np.linspace(0, rmax, nbins), "y": np.mean(data, axis=0)}

0 commit comments

Comments
 (0)