def inertia_eigenvectors(basepos, already_centered=False):
    """
    Given basepos (an array of positions),
    compute and return (as a 2-tuple) the lists of eigenvalues and
    eigenvectors of the inertia tensor (computed as if all points had the same
    mass). These lists are always length 3, even for len(basepos) of 0,1, or 2,
    overlapping or colinear points, etc, though some evals will be 0 in these cases.
       Optional small speedup: if caller knows basepos is centered at the origin, it can say so.
    """
    #bruce 060119 split this out of shakedown_poly_evals_evecs_axis() in chunk.py
    basepos = A(basepos)  # make sure it's a Numeric array
    if not already_centered and len(basepos):
        center = add.reduce(basepos) / len(basepos)
        basepos = basepos - center
    # compute inertia tensor
    tensor = zeros((3, 3), Float)
    for p in basepos:
        rsq = dot(p, p)
        m = -multiply.outer(p, p)
        m[0, 0] += rsq
        m[1, 1] += rsq
        m[2, 2] += rsq
        tensor += m
    evals, evecs = eigenvectors(tensor)
    assert len(evals) == len(evecs) == 3
    return evals, evecs
def inertia_eigenvectors(basepos, already_centered = False):
    """
    Given basepos (an array of positions),
    compute and return (as a 2-tuple) the lists of eigenvalues and
    eigenvectors of the inertia tensor (computed as if all points had the same
    mass). These lists are always length 3, even for len(basepos) of 0,1, or 2,
    overlapping or colinear points, etc, though some evals will be 0 in these cases.
       Optional small speedup: if caller knows basepos is centered at the origin, it can say so.
    """
    #bruce 060119 split this out of shakedown_poly_evals_evecs_axis() in chunk.py
    basepos = A(basepos) # make sure it's a Numeric array
    if not already_centered and len(basepos):
        center = add.reduce(basepos)/len(basepos)
        basepos = basepos - center
    # compute inertia tensor
    tensor = zeros((3,3),Float)
    for p in basepos:
        rsq = dot(p, p)
        m= - multiply.outer(p, p)
        m[0,0] += rsq
        m[1,1] += rsq
        m[2,2] += rsq
        tensor += m
    evals, evecs = eigenvectors(tensor)
    assert len(evals) == len(evecs) == 3
    return evals, evecs
Example #3
0
    def setup_quat_center(self, atomList = None):
        """
        Setup the plane's quat using a list of atoms.

        If no atom list is supplied, the plane is centered in the glpane
        and parallel to the screen.

        @param atomList: A list of atoms.
        @type  atomList: list

        """
        if atomList:    
            self.atomPos = []
            for a in atomList:
                self.atomPos += [a.posn()]    
            planeNorm = self._getPlaneOrientation(self.atomPos)
            if dot(planeNorm, self.glpane.lineOfSight) < 0:
                planeNorm = -planeNorm                
            self.center = add.reduce(self.atomPos) / len(self.atomPos)
            self.quat   = Q(V(0.0, 0.0, 1.0), planeNorm) 
        else:       
            self.center = V(0.0, 0.0, 0.0)
            # Following makes sure that Plane edges are parallel to
            # the 3D workspace borders. Fixes bug 2448
            x, y ,z = self.glpane.right, self.glpane.up, self.glpane.out
            self.quat  = Q(x, y, z) 
            self.quat += Q(self.glpane.right, pi)
Example #4
0
    def __init_quat_center(self, list):

        for a in list:  #[:3]:
            self.atomPos += [a.posn()]

        planeNorm = self._getPlaneOrientation(self.atomPos)
        self.quat = Q(V(0.0, 0.0, 1.0), planeNorm)
        self.center = add.reduce(self.atomPos) / len(self.atomPos)
Example #5
0
 def __init_quat_center(self, list):
     
     for a in list:#[:3]:
         self.atomPos += [a.posn()]
 
     planeNorm = self._getPlaneOrientation(self.atomPos)
     self.quat = Q(V(0.0, 0.0, 1.0), planeNorm)
     self.center = add.reduce(self.atomPos)/len(self.atomPos)
Example #6
0
	def IntegrateUnitCell(self,integralfunction):
		"""Integrates the unit cell using Cartesian coordinates

		This method can be used to obtain the integral of a single
		unit cell. The function is expected to take the position in
		cartesian coordinates as an argument. The function value is 
		then at each grid point multiplied with the value of the grid 
		"""

		from Numeric import add
		from grid import RealFunction

		integratefunc=RealFunction(lambda grid,xyz,func=integralfunction : grid*func(xyz))
		integrategrid=self.Map(integratefunc)
		integral=add.reduce(integrategrid.flat)
		return integral
Example #7
0
	def GetAverageAlongAxis(self,axis):
		"""Returns a NumPy array with the average of the grid points 
		along the specified axis."""
		from Numeric import add,multiply
		
		#Finding the axes to average, starting with the largest value
		otheraxes=range(len(self.GetShape())-1,-1,-1)
		otheraxes.remove(axis)

		#Finding the spape of otheraxes
		shape=list(self.GetShape())
		del shape[axis]

		# Averaging and number of entries along line
		array=self.GetArray()
		for averageaxis in otheraxes:
			array=add.reduce(array,averageaxis)
		return array/multiply.reduce(shape)
Example #8
0
 def center(self):
     if self.data:
         return add.reduce(self.data)/2.0
     else:
         return V(0, 0, 0)
Example #9
0
 def draw(self):
     if self.data:
         drawwirebox(black, add.reduce(self.data)/2,
                     subtract.reduce(self.data)/2)
Example #10
0
 def center(self):
     if self.data:
         return add.reduce(self.data) / 2.0
     else:
         return V(0, 0, 0)
Example #11
0
 def draw(self):
     if self.data:
         drawwirebox(black,
                     add.reduce(self.data) / 2,
                     subtract.reduce(self.data) / 2)
Example #12
0
	def GetAverage(self):
		"""Returns the average value of array."""
		from Numeric import add,multiply
		return add.reduce(self.GetArray().flat)/multiply.reduce(self.GetShape())