|
149 | 149 | "id": "515697c6", |
150 | 150 | "metadata": {}, |
151 | 151 | "source": [ |
152 | | - "Here, we are optimisation a one-dimensional function (the energy varies with bond-length), and we get back a one-dimensional solution array. If we were minimising a function over more dimensions (e.g., the energy of a linear triatomic molecule, which then depends on two bond lengths) then the solution array would contain the minimisation solution for each dimension." |
| 152 | + "Here, we are optimising a one-dimensional function (the energy varies with bond-length), and we get back a one-dimensional solution array. If we were minimising a function over more dimensions (e.g., the energy of a linear triatomic molecule, which then depends on two bond lengths) then the solution array would contain the minimisation solution for each dimension." |
153 | 153 | ] |
154 | 154 | }, |
155 | 155 | { |
|
159 | 159 | "source": [ |
160 | 160 | "### Exercises\n", |
161 | 161 | "\n", |
162 | | - "#### 1.\n", |
| 162 | + "#### Exercise 1: Lennard-Jones Potential with scipy\n", |
163 | 163 | "\n", |
164 | | - "Use `scipy.optimize.minimize()` to perform a geometry optimisation for your Lennard-Jones potential, again with starting values of $r$ = 3.2 Å, $r$ = 4.4 Å, and $r$ = 6.0 Å.\n", |
| 164 | + "Use `scipy.optimize.minimize()` to perform a geometry optimisation for the Lennard-Jones potential:\n", |
165 | 165 | "\n", |
166 | | - "#### 2.\n", |
| 166 | + "$$U_\\mathrm{LJ} = \\frac{A}{r^{12}} - \\frac{B}{r^6}$$\n", |
167 | 167 | "\n", |
168 | | - "The potential energy associated with changes in the Cl-C-C-Cl dihedral angle, $\\theta$ in 1,2-dichloroethane can be modelled as\n", |
| 168 | + "with $A$ = 1 × 10<sup>5</sup> eV Å<sup>12</sup> and $B$ = 40 eV Å<sup>6</sup>.\n", |
169 | 169 | "\n", |
170 | | - "$$U = \\frac{1}{2}\\left\\{A_1\\left[1+\\cos\\theta\\right] + A_2\\left[1+\\cos2\\theta\\right]+ A_3\\left[1+\\cos3\\theta\\right]\\right\\}$$\n", |
| 170 | + "**Part A:**\n", |
171 | 171 | "\n", |
172 | | - "with $A_1$ = 55.229 kJ mol<sup>−1</sup>, $A_2$ = 3.3472 kJ mol<sup>−1</sup>, and $A_3$ = -58.576 kJ mol<sup>−1</sup>.\n", |
| 172 | + "Write a function `lennard_jones(r, A, B)` to calculate this potential.\n", |
173 | 173 | "\n", |
174 | | - "- Plot this function for $-\\pi \\leq \\theta \\leq \\pi$.\n", |
| 174 | + "**Part B:**\n", |
175 | 175 | "\n", |
176 | | - "- Using `scipy.optimize.minimize()` test the optimisation behaviour for different initial guesses of $\\theta$. In what ways does the minimisation result depend on the choice of initial guess?" |
| 176 | + "Run `minimize()` with three different starting values: $r$ = 3.2 Å, $r$ = 4.4 Å, and $r$ = 6.0 Å.\n", |
| 177 | + "\n", |
| 178 | + "**Part C:** \n", |
| 179 | + "\n", |
| 180 | + "For each starting point, print:\n", |
| 181 | + "- The starting position\n", |
| 182 | + "- The final optimised position\n", |
| 183 | + "- The number of iterations required\n", |
| 184 | + "\n", |
| 185 | + "**Part D:** \n", |
| 186 | + "\n", |
| 187 | + "Do all starting points converge to the same minimum? Why or why not?" |
| 188 | + ] |
| 189 | + }, |
| 190 | + { |
| 191 | + "cell_type": "markdown", |
| 192 | + "id": "712334cc-0c94-4df1-af33-7f5506f2a433", |
| 193 | + "metadata": {}, |
| 194 | + "source": [ |
| 195 | + "#### Exercise 2. Multiple Minima in 1,2-Dichloroethane\n", |
| 196 | + "\n", |
| 197 | + "The potential energy associated with changes in the Cl-C-C-Cl dihedral angle, $\\theta$, in 1,2-dichloroethane can be modelled as\n", |
| 198 | + "\n", |
| 199 | + "$$U(\\theta) = \\frac{1}{2}\\left\\{A_1\\left[1+\\cos\\theta\\right] + A_2\\left[1+\\cos2\\theta\\right]+ A_3\\left[1+\\cos3\\theta\\right]\\right\\}$$\n", |
| 200 | + "\n", |
| 201 | + "with $A_1$ = 55.229 kJ mol$^{-1}$, $A_2$ = 3.3472 kJ mol$^{-1}$, and $A_3$ = -58.576 kJ mol$^{-1}$.\n", |
| 202 | + "\n", |
| 203 | + "This exercise explores how the choice of starting geometry affects which minimum the optimiser finds.\n", |
| 204 | + "\n", |
| 205 | + "**Part A: Define and Visualise the Potential Energy Surface**\n", |
| 206 | + "\n", |
| 207 | + "1. Write a function `dihedral_potential(theta, A1, A2, A3)` that calculates the potential energy for a given dihedral angle $\\theta$ (in radians).\n", |
| 208 | + "\n", |
| 209 | + "2. Create an array of $\\theta$ values from $-\\pi$ to $\\pi$ using `np.linspace()` with at least 200 points.\n", |
| 210 | + "\n", |
| 211 | + "3. Calculate the potential energy at each point and create a plot showing $U(\\theta)$ vs $\\theta$.\n", |
| 212 | + "\n", |
| 213 | + "4. By examining your plot, identify approximately how many minima exist and roughly where they are located.\n", |
| 214 | + "\n", |
| 215 | + "**Part B: Test Individual Starting Points**\n", |
| 216 | + "\n", |
| 217 | + "5. Use `scipy.optimize.minimize()` to find the minimum, starting with $\\theta_0 = 0$ radians as your initial guess. What minimum does the optimiser find?\n", |
| 218 | + "\n", |
| 219 | + "6. Repeat the optimisation starting from $\\theta_0 = \\pi$ radians. Does it find the same minimum?\n", |
| 220 | + "\n", |
| 221 | + "7. Try one more starting point of your choice. Based on these three tests, what pattern do you observe?\n", |
| 222 | + "\n", |
| 223 | + "**Part C: Systematic Exploration of Starting Points**\n", |
| 224 | + "\n", |
| 225 | + "Now we will systematically test many different starting points to understand the overall behaviour.\n", |
| 226 | + "\n", |
| 227 | + "8. Create an array of 20 equally spaced starting angles between $-\\pi$ and $\\pi$ using `np.linspace()`. Store this in a variable called `start_angles`.\n", |
| 228 | + "\n", |
| 229 | + "9. Create two empty lists called `start_positions` and `final_positions`.\n", |
| 230 | + "\n", |
| 231 | + "10. Write a `for` loop that:\n", |
| 232 | + " - Iterates through each angle in `start_angles`\n", |
| 233 | + " - Performs an optimisation starting from that angle\n", |
| 234 | + " - Appends the starting angle to `start_positions`\n", |
| 235 | + " - Appends the optimised angle (from `result.x[0]`) to `final_positions`\n", |
| 236 | + "\n", |
| 237 | + "**Part D: Visualise the Basins of Attraction**\n", |
| 238 | + "\n", |
| 239 | + "11. Create a scatter plot with:\n", |
| 240 | + " - Starting angles on the x-axis (`start_positions`)\n", |
| 241 | + " - Final optimised angles on the y-axis (`final_positions`)\n", |
| 242 | + " - Appropriate axis labels and title\n", |
| 243 | + " \n", |
| 244 | + " This plot shows you which starting positions lead to which minima. Each horizontal band of points represents a different minimum (basin of attraction).\n", |
| 245 | + "\n", |
| 246 | + "**Part E: Analysis**\n", |
| 247 | + "\n", |
| 248 | + "12. How many distinct minima does your scatter plot reveal? (Look for horizontal bands of points.)\n", |
| 249 | + "\n", |
| 250 | + "13. For each minimum, estimate the range of starting angles that lead to that minimum. These ranges are called the \"basin of attraction\" for each minimum.\n", |
| 251 | + "\n", |
| 252 | + "14. Based on your results, if you wanted to find the global minimum (the lowest energy structure), what strategy would you need to use? (Hint: look back at your potential energy plot from Part A to see which minimum has the lowest energy.)\n" |
177 | 253 | ] |
178 | 254 | }, |
179 | 255 | { |
180 | 256 | "cell_type": "code", |
181 | 257 | "execution_count": null, |
182 | | - "id": "840a56c1-c19f-49c4-a083-e8576324a098", |
| 258 | + "id": "b3926a52-9f65-487b-984e-8e8ee670f0ae", |
183 | 259 | "metadata": {}, |
184 | 260 | "outputs": [], |
185 | 261 | "source": [] |
|
0 commit comments