-
Notifications
You must be signed in to change notification settings - Fork 0
/
muller_brown.py
60 lines (46 loc) · 1.81 KB
/
muller_brown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
This module contains functions that are needed to calculate the forces and the energies of a 2D point particle in
a Muller Brown potential.
"""
import numpy as np
def MB_force(x, y):
"""
This function calculates the force acting on a point particle with position (x,y) in a Muller Brown potential.
:param x: float
:param y: float
:return: numpy array of shape (2,)
"""
current_force = np.array([0.0, 0.0])
# Parameters of the Muller-brown potential
A = np.array([-200, -100, -170, 15])
a = np.array([-1, -1, -6.5, 0.7])
b = np.array([0, 0, 11, 0.6])
c = np.array([-10, -10, -6.5, 0.7])
xk = np.array([1, 0, -0.5, -1])
yk = np.array([0, 0.5, 1.5, 1])
# The force is calculated from the analytical differentiation of the Muller-Brown potential (with minus sign)
for i in range(0,4):
exp_arg = a[i]*(x-xk[i])**2 + b[i]*(x-xk[i])*(y-yk[i]) + c[i]*(y-yk[i])**2
current_force[0] += -A[i] * np.exp(exp_arg) * (2*a[i]*(x-xk[i]) + b[i]*(y-yk[i]))
current_force[1] += -A[i] * np.exp(exp_arg) * (2*c[i]*(y-yk[i]) + b[i]*(x-xk[i]))
return current_force
def MB_potential(x,y):
"""
This function calculates the energy of a point particle with position (x,y) in a Muller Brown potential.
:param x: float
:param y: float
:return: float
"""
# Parameters of the Muller-brown potential
A = np.array([-200, -100, -170, 15])
a = np.array([-1, -1, -6.5, 0.7])
b = np.array([0, 0, 11, 0.6])
c = np.array([-10, -10, -6.5, 0.7])
xk = np.array([1, 0, -0.5, -1])
yk = np.array([0, 0.5, 1.5, 1])
# Calculating the value of the potential:
MB_pot = 0
for i in range(0,4):
exp_arg = a[i]*(x-xk[i])**2 + b[i]*(x-xk[i])*(y-yk[i]) + c[i]*(y-yk[i])**2
MB_pot += A[i] * np.exp(exp_arg)
return MB_pot