Skip to content

Commit 770759d

Browse files
committed
week 5 updates
1 parent 04db40c commit 770759d

3 files changed

Lines changed: 99 additions & 13 deletions

File tree

CH40208/course_contents/week_5.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**Geometry Optimisation**
44

5-
- [Geometry Optimisation](../geometry_optimisation/geometry_optimisation_new.md)
5+
- [Geometry Optimisation](../geometry_optimisation/geometry_optimisation.md)
66
- [Analytical Solution for a Harmonic Potential](../geometry_optimisation/analytical_solution_for_a_harmonic_potential.md)
77
- [The Grid Search Method](../geometry_optimisation/grid_search_method.ipynb)
88
- [The Gradient Descent Method](../geometry_optimisation/gradient_descent_method.ipynb)

CH40208/geometry_optimisation/newton_raphson_method.ipynb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,20 @@
7676
"\n",
7777
"1. Write a function to calculate the second derivative of a harmonic potential:\n",
7878
"\n",
79-
"$$U^{\\prime\\prime} = 2k$$\n",
79+
"$$U^{\\prime\\prime} = k$$\n",
8080
"\n",
81-
"2. Show that the Newton-Raphson method finds the optimal bond length for your harmonic potential in one step, irrespective of your starting point."
81+
"2. Show that the Newton-Raphson method finds the optimal bond length for your harmonic potential in one step, irrespective of your starting point.\n",
82+
"\n",
83+
"*Hint: Consider why the Newton-Raphson method works perfectly for quadratic functions.*"
8284
]
85+
},
86+
{
87+
"cell_type": "code",
88+
"execution_count": null,
89+
"id": "55ed4305-f9e0-47c0-b311-c2313f8dea29",
90+
"metadata": {},
91+
"outputs": [],
92+
"source": []
8393
}
8494
],
8595
"metadata": {

CH40208/geometry_optimisation/scipy_optimize_minimize.ipynb

Lines changed: 86 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
"id": "515697c6",
150150
"metadata": {},
151151
"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."
153153
]
154154
},
155155
{
@@ -159,27 +159,103 @@
159159
"source": [
160160
"### Exercises\n",
161161
"\n",
162-
"#### 1.\n",
162+
"#### Exercise 1: Lennard-Jones Potential with scipy\n",
163163
"\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",
165165
"\n",
166-
"#### 2.\n",
166+
"$$U_\\mathrm{LJ} = \\frac{A}{r^{12}} - \\frac{B}{r^6}$$\n",
167167
"\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",
169169
"\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",
171171
"\n",
172-
"with $A_1$ = 55.229 kJ mol<sup>&minus;1</sup>, $A_2$ = 3.3472 kJ mol<sup>&minus;1</sup>, and $A_3$ = -58.576 kJ mol<sup>&minus;1</sup>.\n",
172+
"Write a function `lennard_jones(r, A, B)` to calculate this potential.\n",
173173
"\n",
174-
"- Plot this function for $-\\pi \\leq \\theta \\leq \\pi$.\n",
174+
"**Part B:**\n",
175175
"\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"
177253
]
178254
},
179255
{
180256
"cell_type": "code",
181257
"execution_count": null,
182-
"id": "840a56c1-c19f-49c4-a083-e8576324a098",
258+
"id": "b3926a52-9f65-487b-984e-8e8ee670f0ae",
183259
"metadata": {},
184260
"outputs": [],
185261
"source": []

0 commit comments

Comments
 (0)