-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
load scene when both client and webpage are ready
- Loading branch information
Showing
4 changed files
with
116 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Molecular Dynamics Simulation\n", | ||
"\n", | ||
"In this example we will run an MD simulation using ASE and visualise it using ZnDraw." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from zndraw import ZnDraw\n", | ||
"\n", | ||
"from ase.lattice.cubic import FaceCenteredCubic\n", | ||
"from ase.md.velocitydistribution import MaxwellBoltzmannDistribution\n", | ||
"from ase.md.verlet import VelocityVerlet\n", | ||
"from ase import units\n", | ||
"\n", | ||
"from ase.calculators.emt import EMT\n", | ||
"size = 2\n", | ||
"\n", | ||
"# Set up a crystal\n", | ||
"atoms = FaceCenteredCubic(directions=[[1, 0, 0], [0, 1, 0], [0, 0, 1]],\n", | ||
" symbol=\"Cu\",\n", | ||
" size=(size, size, size),\n", | ||
" pbc=True)\n", | ||
"\n", | ||
"# Describe the interatomic interactions with the Effective Medium Theory\n", | ||
"atoms.calc = EMT()\n", | ||
"\n", | ||
"# Set the momenta corresponding to T=300K\n", | ||
"MaxwellBoltzmannDistribution(atoms, temperature_K=300)\n", | ||
"\n", | ||
"# We want to run MD with constant energy using the VelocityVerlet algorithm.\n", | ||
"dyn = VelocityVerlet(atoms, 5 * units.fs) # 5 fs time step.\n", | ||
"\n", | ||
"\n", | ||
"def printenergy(a=atoms): # store a reference to atoms in the definition.\n", | ||
" \"\"\"Function to print the potential, kinetic and total energy.\"\"\"\n", | ||
" epot = a.get_potential_energy() / len(a)\n", | ||
" ekin = a.get_kinetic_energy() / len(a)\n", | ||
" print('Energy per atom: Epot = %.3feV Ekin = %.3feV (T=%3.0fK) '\n", | ||
" 'Etot = %.3feV' % (epot, ekin, ekin / (1.5 * units.kB), epot + ekin))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"vis = ZnDraw(url=\"http://localhost:1234\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Now run the dynamics\n", | ||
"\n", | ||
"# dyn.attach(printenergy, interval=1)\n", | ||
"dyn.attach(lambda: vis.append(atoms), interval=1)\n", | ||
"printenergy()\n", | ||
"dyn.run(200)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "zndraw", | ||
"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.10.11" | ||
}, | ||
"orig_nbformat": 4 | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters