Skip to content

Commit

Permalink
Merge #2999
Browse files Browse the repository at this point in the history
2999: Update tutorials and visualizer r=KaiSzuttor a=jngrad

Description of changes:
- Make all tutorials start with the Python3 kernel
- Fix a plotting issue in the electrostatics tutorial
- Update try except statement to catch the new dependency issue with Mayavi in Ubuntu 18.04 (`RuntimeError: No pyface.toolkits plugin could be loaded for wx`)


Co-authored-by: Jean-Noël Grad <jgrad@icp.uni-stuttgart.de>
  • Loading branch information
bors[bot] and jngrad committed Jul 25, 2019
2 parents 7b957df + a1ab093 commit 958747c
Show file tree
Hide file tree
Showing 17 changed files with 235 additions and 230 deletions.
4 changes: 2 additions & 2 deletions doc/sphinx/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ screenshots without blocking the simulation script::

for i in range(100):
system.integrator.run(1)
visualizer.screenshot('screenshot_{}.jpg'.format(i))
visualizer.screenshot('screenshot_{:0>5}.png'.format(i))

# You may consider creating a video with ffmpeg:
# ffmpeg -f image2 -framerate 30 -i 'screenshot_%d.jpg' output.mp4
# ffmpeg -f image2 -framerate 30 -i 'screenshot_%05d.png' output.mp4

It is also possible to create a snapshot during online visualization.
Simply press the *enter* key to create a snapshot of the current window,
Expand Down
10 changes: 5 additions & 5 deletions doc/tutorials/01-lennard_jones/01-lennard_jones.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -598,21 +598,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.15rc1"
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
10 changes: 5 additions & 5 deletions doc/tutorials/02-charged_system/02-charged_system-1.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -461,21 +461,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.14"
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
21 changes: 14 additions & 7 deletions doc/tutorials/02-charged_system/02-charged_system-2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,15 @@
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"plt.ion()\n",
"\n",
"plt.ion()\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(10, 6), dpi=80)\n",
"plt.plot(z_values, z_dens_na, label='Na')\n",
"plt.plot(z_values, z_dens_cl, label='Cl')\n",
Expand Down Expand Up @@ -471,21 +478,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.14"
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
159 changes: 81 additions & 78 deletions doc/tutorials/02-charged_system/scripts/nacl_units_vis.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,88 +67,91 @@ def decreaseTemp():
'g', visualization_opengl.KeyboardFireEvent.Hold, decreaseTemp))


def main():
print("\n--->Setup system")

# System parameters
n_ppside = 10
n_part = int(n_ppside**3)
n_ionpairs = n_part / 2
density = 1.5736
time_step = 0.001823
temp = 298.0
gamma = 20.0
#l_bjerrum = 0.885^2 * e^2/(4*pi*epsilon_0*k_B*T)
l_bjerrum = 130878.0 / temp

num_steps_equilibration = 30

# Particle parameters
types = {"Cl": 0, "Na": 1}
numbers = {"Cl": n_ionpairs, "Na": n_ionpairs}
charges = {"Cl": -1.0, "Na": 1.0}
lj_sigmas = {"Cl": 3.85, "Na": 2.52}
lj_epsilons = {"Cl": 192.45, "Na": 17.44}

lj_cuts = {"Cl": 3.0 * lj_sigmas["Cl"],
"Na": 3.0 * lj_sigmas["Na"]}

masses = {"Cl": 35.453, "Na": 22.99}

# Setup System
box_l = (n_ionpairs * sum(masses.values()) / density)**(1. / 3.)
system.box_l = [box_l, box_l, box_l]
system.periodicity = [1, 1, 1]
system.time_step = time_step
system.cell_system.skin = 0.3
system.thermostat.set_langevin(kT=temp, gamma=gamma, seed=42)

# Place particles on a face-centered cubic lattice
q = 1
l = box_l / n_ppside
for i in range(n_ppside):
for j in range(n_ppside):
for k in range(n_ppside):
p = numpy.array([i, j, k]) * l
if q < 0:
system.part.add(id=len(
system.part), type=types["Cl"], pos=p, q=charges["Cl"], mass=masses["Cl"])
else:
system.part.add(id=len(
system.part), type=types["Na"], pos=p, q=charges["Na"], mass=masses["Na"])

print("\n--->Setup system")

# System parameters
n_ppside = 10
n_part = int(n_ppside**3)
n_ionpairs = n_part / 2
density = 1.5736
time_step = 0.001823
temp = 298.0
gamma = 20.0
#l_bjerrum = 0.885^2 * e^2/(4*pi*epsilon_0*k_B*T)
l_bjerrum = 130878.0 / temp

num_steps_equilibration = 30

# Particle parameters
types = {"Cl": 0, "Na": 1}
numbers = {"Cl": n_ionpairs, "Na": n_ionpairs}
charges = {"Cl": -1.0, "Na": 1.0}
lj_sigmas = {"Cl": 3.85, "Na": 2.52}
lj_epsilons = {"Cl": 192.45, "Na": 17.44}

lj_cuts = {"Cl": 3.0 * lj_sigmas["Cl"],
"Na": 3.0 * lj_sigmas["Na"]}

masses = {"Cl": 35.453, "Na": 22.99}

# Setup System
box_l = (n_ionpairs * sum(masses.values()) / density)**(1. / 3.)
system.box_l = [box_l, box_l, box_l]
system.periodicity = [1, 1, 1]
system.time_step = time_step
system.cell_system.skin = 0.3
system.thermostat.set_langevin(kT=temp, gamma=gamma, seed=42)

# Place particles on a face-centered cubic lattice
q = 1
l = box_l / n_ppside
for i in range(n_ppside):
for j in range(n_ppside):
for k in range(n_ppside):
p = numpy.array([i, j, k]) * l
if q < 0:
system.part.add(id=len(
system.part), type=types["Cl"], pos=p, q=charges["Cl"], mass=masses["Cl"])
else:
system.part.add(id=len(
system.part), type=types["Na"], pos=p, q=charges["Na"], mass=masses["Na"])

q *= -1
q *= -1
q *= -1
q *= -1


def combination_rule_epsilon(rule, eps1, eps2):
if rule == "Lorentz":
return (eps1 * eps2)**0.5
else:
return ValueError("No combination rule defined")


def combination_rule_sigma(rule, sig1, sig2):
if rule == "Berthelot":
return (sig1 + sig2) * 0.5
else:
return ValueError("No combination rule defined")

# Lennard-Jones interactions parameters
for s in [["Cl", "Na"], ["Cl", "Cl"], ["Na", "Na"]]:
lj_sig = combination_rule_sigma(
"Berthelot", lj_sigmas[s[0]], lj_sigmas[s[1]])
lj_cut = combination_rule_sigma(
"Berthelot", lj_cuts[s[0]], lj_cuts[s[1]])
lj_eps = combination_rule_epsilon(
"Lorentz", lj_epsilons[s[0]], lj_epsilons[s[1]])

system.non_bonded_inter[types[s[0]], types[s[1]]].lennard_jones.set_params(
epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto")

def combination_rule_epsilon(rule, eps1, eps2):
if rule == "Lorentz":
return (eps1 * eps2)**0.5
else:
return ValueError("No combination rule defined")

def combination_rule_sigma(rule, sig1, sig2):
if rule == "Berthelot":
return (sig1 + sig2) * 0.5
else:
return ValueError("No combination rule defined")

# Lennard-Jones interactions parameters
for s in [["Cl", "Na"], ["Cl", "Cl"], ["Na", "Na"]]:
lj_sig = combination_rule_sigma(
"Berthelot", lj_sigmas[s[0]], lj_sigmas[s[1]])
lj_cut = combination_rule_sigma(
"Berthelot", lj_cuts[s[0]], lj_cuts[s[1]])
lj_eps = combination_rule_epsilon(
"Lorentz", lj_epsilons[s[0]], lj_epsilons[s[1]])

system.non_bonded_inter[types[s[0]], types[s[1]]].lennard_jones.set_params(
epsilon=lj_eps, sigma=lj_sig, cutoff=lj_cut, shift="auto")

print("\n--->Tuning Electrostatics")
p3m = electrostatics.P3M(prefactor=l_bjerrum, accuracy=1e-2)
system.actors.add(p3m)
print("\n--->Tuning Electrostatics")
p3m = electrostatics.P3M(prefactor=l_bjerrum, accuracy=1e-2)
system.actors.add(p3m)


def main():

print("\n--->Temperature Equilibration")
system.time = 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@
"\n",
"### Notes on the **ESPResSo** version you will need\n",
"\n",
"With version 3.1 **ESPResSo** offers GPU support for LB. We recommend however\n",
"version 3.3, which has more features. We absolutely recommend using the GPU code,\n",
"**ESPResSo** offers both CPU and GPU support for LB. We recommend using the GPU code,\n",
"as it is much (100x) faster than the CPU code.\n",
"\n",
"For the tutorial you will have to compile in the following features: \n",
Expand Down Expand Up @@ -381,7 +380,6 @@
"espressomd.assert_features(['CUDA', 'LB_BOUNDARIES_GPU'])\n",
"from espressomd import System, lb, lbboundaries, shapes\n",
"import numpy as np\n",
"import sys\n",
"\n",
"# System setup\n",
"system = System(box_l=[1.0, 1.0, 1.0]) # The box_l is specified below.\n",
Expand Down Expand Up @@ -453,8 +451,7 @@
"for i in range(10):\n",
" system.integrator.run(400)\n",
" lbf.print_vtk_velocity(\"fluid%04i.vtk\" % i)\n",
" sys.stdout.write(\"\\rloop: %02i\" % i)\n",
" sys.stdout.flush()\n",
" print(\"\\rloop: %02i\" % (i+1), end=\"\")\n",
"\n",
"\n",
"print(\"\\nIntegration finished.\")\n",
Expand Down Expand Up @@ -521,21 +518,21 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"display_name": "Python 3",
"language": "python",
"name": "python2"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
"pygments_lexer": "ipython3",
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 958747c

Please sign in to comment.