Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tutorial on GCMC #4670

Merged
merged 2 commits into from
Nov 7, 2023
Merged

Add tutorial on GCMC #4670

merged 2 commits into from
Nov 7, 2023

Conversation

lburth
Copy link
Contributor

@lburth lburth commented Feb 13, 2023

Fixes #4575

Description of changes:

  • Adds a tutorial, that teaches users how to simulate systems in the Grand-Canonical ensemble with the Grand-Canonical Monte Carlo.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Contributor

@christophlohrmann christophlohrmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very well written tutorial. I have a bunch of minor comments, the only thing major is that after the last plot, the physics should be discussed in more detail to interpret the main result.
Otherwise: Thanks a lot, well done

"source": [
"## Grand-Canonical Ensemble\n",
"The case of changing particle numbers is best described by the grand canonical ensemble <a href='#[1]'>[1]</a>.\n",
"In the grand canonical ensemble, the volume $V$, the temperature $T$ and the chemical potentials $\\mu_i$ of the exchangeable species $i$ rather than the particle numbers $N_i$ are fixed.The chemical potentials $\\mu_i$correspond to the free energy cost of adding a particle of type $i$ while keeping everything else fixed:\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space in last sentence

"The grand canonical ensemble is thus also referred to as the $(\\mu, V, T)$-ensemble.\n",
"In the grand canonical ensemble, the probability for the system to contain $N_i$ particles of type $i$, i.e. a total of $N=\\sum_{i=1}^{N_\\mathrm{s}}N_i$ and to be in a specific microstate $\\xi\\in\\Gamma_{N}$ is given by the probability distribution\n",
"\\begin{align}\n",
"p^\\mathrm{G}\\left(\\left\\{N_i\\right\\},\\xi\\right) = \\frac{\\exp\\left(-\\beta \\left(H(\\xi)-\\sum_{i=1}^{N_\\mathrm{s}}\\mu_iN_i\\right)\\right)}{Z^\\mathrm{G}h^{3N}\\prod_{i=1}^{N_\\mathrm{s}} N_i!}. \\quad \\tag{1}\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define N_s

"\\end{align}\n",
"Here, $H$ denotes the Hamiltonian of the system with $N_i$ particles of type $i$ and $Z^\\mathrm{G}$ is the grand-canonical partition function which is given by\n",
"\\begin{align}\n",
"Z^\\mathrm{G}\\left(\\left\\{\\mu_i\\right\\},V,T\\right) = \\sum_{N_1=0}^{\\infty}...\\sum_{N_\\mathrm{s}=0}^{\\infty}Z\\left(\\left\\{N_i\\right\\},V,T\\right)\\exp\\left(\\beta \\sum_{i=1}^{N_\\mathrm{s}}\\mu_iN_i\\right).\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define Z

"\\mu_i^{\\mathrm{sys}} = \\mu_i^{\\mathrm{res}}.\n",
"\\end{equation}\n",
"This condition is referred to as a chemical equilibrium between the two phases and is equivalent to a minimization of the free energy of the total system (system + reservoir).\n",
"In the case where one requires electroneutrality of the phases, due to the additional constraint, the electrochemical potential $\\overline{\\mu}_i=\\mu_i+z_ie\\psi$ rather than the chemical potential has to be equal."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define z, e, psi

"\\frac{P_{i\\rightarrow j}^\\mathrm{acc}}{P_{j\\rightarrow i}^\\mathrm{acc}} = \\frac{p_j^\\mathrm{eq}}{p_i^\\mathrm{eq}}. \n",
"\\quad \\tag{6}\n",
"\\end{align}\n",
"It is easy to see that the acceptance probability \n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid such phrases to not discourage beginners

"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 50/50 [00:04<00:00, 11.72it/s]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove output from tutorial before commiting/pushing

" K_XX =salt_concentration ** 2 * np.exp(excess_chemical_potential_monovalent_pairs_in_bulk(salt_concentration))\n",
" RE.change_reaction_constant(gamma= K_XX,reaction_id = 0)\n",
" for i in tqdm(range(warmup_loops),bar_format='{l_bar}{bar:60}{r_bar}{bar:-60b}'):\n",
" system.integrator.run(1000)\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe give these numbers as predefined variables

},
"source": [
"**Exercise**\n",
"* Plot the universal partition coeffiecients obtained by measuring the partition coefficient $\\xi_-$ and $\\xi_+$ in the simulation against $c_{\\mathrm{M}^-}/(2c_{\\mathrm{salt}}^{\\mathrm{res}})$\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure plotting is a meaningful exercise

"source": [
"**Exercise**\n",
"* Plot the universal partition coeffiecients obtained by measuring the partition coefficient $\\xi_-$ and $\\xi_+$ in the simulation against $c_{\\mathrm{M}^-}/(2c_{\\mathrm{salt}}^{\\mathrm{res}})$\n",
"* Interpret the deviation of the simulation results from the ideal prediction."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should definitely be a solution to this question

"<figcaption>Fig. 1: Schematic representation of the considered two phase setup.</figcaption>\n",
"</center>\n",
"</figure>\n",
"Here we want to investigate a polyelectrolyte solution that is coupled to a reservoir containing a monovalent salt, as shown schematically in figure 1. The small salt ions (X$^+$ and X$^-$) can be exchanged between the two phases while the polyelectrolyte is confined to the system. Experimentally such a setup could be realized by seperating the two phases with a semi-permeable membrane. Similiar setups also occur in the study of polyelectrolyte hydrogels.\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a sentence on the relevance/usefulness of this system

@lburth
Copy link
Contributor Author

lburth commented Aug 28, 2023

Thank you for your review and your annotations. I have now worked in your annotations and added an interpretation of the final plot. In addition I have changed the sample sizes a bit to speed up the runtimes.

@christophlohrmann
Copy link
Contributor

Looks really nice now, thanks for the work you put in.
For me, the solutions to the exercises are shown when I open the notebook. Please check if it looks the same for you and make the default not-shown if needed.
Otherwise this can be merged

@lburth
Copy link
Contributor Author

lburth commented Sep 27, 2023

Looks really nice now, thanks for the work you put in. For me, the solutions to the exercises are shown when I open the notebook. Please check if it looks the same for you and make the default not-shown if needed. Otherwise this can be merged
Thanks for the review. Now the default is that the solutions are hidden.

lburth and others added 2 commits November 6, 2023 19:24
Reduce sampling times. Improve testing. Redesign plots.
@jngrad jngrad added this to the ESPResSo 4.3.0 milestone Nov 7, 2023
@jngrad jngrad added Documentation automerge Merge with kodiak labels Nov 7, 2023
@kodiakhq kodiakhq bot merged commit cb3c23c into espressomd:python Nov 7, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a tutorial on GCMC
3 participants