Skip to content

Commit

Permalink
Began writing the getSpringPotential() function.
Browse files Browse the repository at this point in the history
  • Loading branch information
harrisj committed Mar 26, 2011
1 parent 6d71d33 commit fd28f6a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 49 deletions.
31 changes: 23 additions & 8 deletions equitube/equitube.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self,argv):
variables, arguments = self._parseOptions(argv, parser)

self._count = variables.count
self._springconst = variables.spring
self._length = variables.length

def _parseOptions(self, argv, parser):
Expand All @@ -50,23 +51,37 @@ def _parseOptions(self, argv, parser):
parser.add_option('--count', '-c', default=50,
help=''.join(count_help_list))
length_help_list = [
"This option allows you to specity the length of the ",
"This option allows you to specify the length of the ",
"field on which the nanotubes are oriented, the field ",
"is square for simplicity."
]
parser.add_option('--length', '-l', default=10,
help=''.join(length_help_list))

spring_help_list = [
"This option allos you to specify the strength of the ",
"spring constant and control the elasticity of the ",
"substrate the tubes are adhered to."
]
parser.add_option('--spring', '-k', default=10,
help=''.join(spring_help_list))

return parser.parse_args()

def Run(self):
try:
field = Field(self._length)
field = Field(self._length, self._springconst)
field.addTubes(self._count)
field.calculateIntercepts()
tube_dict = field.getTubes()
field.getVanderPotential()


""" This is pretty much the bulk of it.
"""
#while vander > spring:
# plot.paintCanvas()
# field.calculateIntercepts()
# field.getVanderPotential()
# field.rotateTubes()
# field.getSpringPotential()


except EquitubeException, e:
raise EquitubeException(e.get_message())

Expand Down
41 changes: 28 additions & 13 deletions equitube/field/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from equitube.tube import Tube
import numpy as np
import random

class Field:
"""An object for creating the field that holds the tube network.
Expand All @@ -30,9 +31,10 @@ class Field:
tube object and calculate the energies of the entire field.
"""

def __init__(self,length):
def __init__(self,length,k):
"""Initializes the field
"""
self._k = k # spring constant
self._startP = {}
self._startQ = {}
self._tubes = {}
Expand All @@ -46,8 +48,10 @@ def addTubes(self, number = 1):
"""

for x in range(number):
self._tubes[x] = Tube(self._length)
self._tubes[x].createLine()
self._tubes[x] = Tube()
m = random.uniform(-50,50)
cm = [random.uniform(0,self._length),random.uniform(0,self._length)]
self._tubes[x].createLine(m,cm)
params = self._tubes[x].getParams()
self._startP[x] = list()
self._startP[x] = params['P']
Expand Down Expand Up @@ -114,10 +118,29 @@ def getVanderPotential(self):
Fq += torque/Rq

force_dict[tube_id] = [Fp,Fq]
# TODO Understand how to calculate this correctly.
vdw_potential = 42

return vdw_potential,force_dict

#return potential,force dict
return None
def getSpringPotential(self):
"""Calculates the Spring Potential energy stored in the substate.
This function will consider small changes in center and end
point position and use it to calculate the spring potential energy.
of the entire system.
"""
ttl_spring_potential = 0.0

for tube_id in self._tubes.keys():
tube = self._tubes[tube_id].getParams()
p_dist = np.sqrt((tube['P'][0]-self._startP[tube_id][0])**2 + (tube['P'][1]-self._startP[tube_id][1])**2)
q_dist = np.sqrt((tube['Q'][0]-self._startQ[tube_id][0])**2 + (tube['Q'][1]-self._startQ[tube_id][1])**2)

# TODO Understand how to calculate this correctly.
ttl_spring_potential += .5*self._k*(p_dist+q_dist)**2

return ttl_spring_potential

def rotateTubes(self):
"""This function rotates the tubes about a calculated point.
Expand All @@ -128,14 +151,6 @@ def rotateTubes(self):
This function takes the direction of rotation and the pivot
and uses them to rotate the tobe by a small amount.
"""

def getSpringPotential(self):
"""Calculates the Spring Potential energy stored in the substate.
This function will consider small changes in center and end
point position and use it to calculate the spring potential energy.
of the entire system.
"""
return None

def calculateIntercepts(self):
Expand Down
40 changes: 12 additions & 28 deletions equitube/tube/tube.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import random

class Tube:
def __init__(self,length = False):
def __init__(self):
""" Initializes a clean tube
the length parameter specifies the dimensions
Expand All @@ -38,18 +38,23 @@ def __init__(self,length = False):
self._l = None
self._b = None
self._theta = None
self._length = length
self._neighbours = {}
self._cm = [] #[Xcm,Ycm]
self._P = [] #[Xp,Yp]
self._Q = [] #[Xq,Yq]

def createLine(self):
""" Generating a random Line segment
def createLine(self,slope,center):
""" Generates a Line segment
This function generates the initial line segment, It also
modifies the variables that are based on slope and center
point after each iteration.
"""
self._m = random.uniform(-50,50)
self._l = random.uniform(3,10)
self._cm = [random.uniform(0,self._length),random.uniform(0,self._length)]

if self._l == None:
self._l = random.uniform(3,10)
self._m = slope
self._cm = center
self._theta = np.arctan(self._m)
self._b = self._cm[1] - self._m*self._cm[0]

Expand Down Expand Up @@ -88,24 +93,3 @@ def getParams(self):

return params

def setParams(self, paramList):
""" Change tube information.
this function accepts a list [param_name,new_value] and
applies the new value to the tube. I.E. ['m',new_slope]
The only variables required to fully define the tube are
length, cm, and slope.
"""

if paramList[0] == 'm':
self._m = paramList[1]
elif paramList[0] == 'cm':
self._cm = paramList[1]
elif paramList[0] == 'l':
self._l = paramList[1]

return None




0 comments on commit fd28f6a

Please sign in to comment.