mirror of
https://gitlab.com/pimnelissen/entropic-spring.git
synced 2025-11-30 19:33:07 +01:00
update RubberBand to add biasing feature
This commit is contained in:
@ -4,39 +4,48 @@ from Link import Link
|
|||||||
|
|
||||||
class RubberBand:
|
class RubberBand:
|
||||||
# class attributes
|
# class attributes
|
||||||
k_B = 1
|
|
||||||
|
def __init__(self, N, a=1., kBT=1., biased=False, force=0.):
|
||||||
def __init__(self, N, a=1., T=1.):
|
|
||||||
"""
|
"""
|
||||||
RubberBand is a class that can simulate a rubber band with N
|
RubberBand is a class that can simulate a rubber band with N
|
||||||
incompressible links of length a.
|
incompressible links of length a.
|
||||||
|
|
||||||
Parameters:
|
Parameters
|
||||||
N (int) The number of links.
|
----------
|
||||||
a (float) The fixed length of links.
|
N : int
|
||||||
T (float) Temperature of the system.
|
The number of links.
|
||||||
|
a : float, optional
|
||||||
|
The fixed length of the links. The default is 1..
|
||||||
|
kBT : float, optional
|
||||||
|
Temperature of the system (arb. units). The default is 1..
|
||||||
|
force : float, optional
|
||||||
|
Force applied to the RubberBand.
|
||||||
|
The default is 0, which is an unbiased RubberBand.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.N = N
|
self.N = N
|
||||||
self.a = a
|
self.a = a
|
||||||
self.T = T
|
self.kBT = kBT
|
||||||
self.links = self.__sample_links()
|
self.links = self.__sample_links(force=force)
|
||||||
|
|
||||||
def w(self, f, l):
|
def w(self, f, l):
|
||||||
beta = (self.k_B*self.T)**(-1)
|
beta = (self.kBT)**(-1)
|
||||||
return np.exp(beta*f*l)
|
return np.exp(beta*f*l)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def length(self):
|
def length(self):
|
||||||
return self.a * np.sum([l.direction for l in self.links])
|
return self.a * np.sum([l.direction for l in self.links])
|
||||||
|
|
||||||
def __sample_links(self):
|
def __sample_links(self, force):
|
||||||
"""
|
"""
|
||||||
Sample N Link objects with a random direction.
|
Sample N Link objects with a random direction.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
samples = np.random.random_sample((self.N,))
|
samples = np.random.random_sample((self.N,))
|
||||||
directions = np.ones(samples.shape)
|
directions = np.ones(samples.shape)
|
||||||
directions[samples < 0.5] = -1.
|
|
||||||
|
p_negative = 1 - 0.5*(1 + np.tanh(force*self.a/self.kBT))
|
||||||
|
|
||||||
|
directions[samples < p_negative] = -1.
|
||||||
directions = directions.astype(int)
|
directions = directions.astype(int)
|
||||||
return [Link(d) for d in directions]
|
return [Link(d) for d in directions]
|
||||||
Reference in New Issue
Block a user