def linePlaneIntersectionNumeric(p1, p2, p3, p4, p5): if not useNumeric: return linePlaneIntersection(p1, p2, p3, p4, p5) if useNumpy: top = [[1., 1., 1., 1.], [p1[0], p2[0], p3[0], p4[0]], [p1[1], p2[1], p3[1], p4[1]], [p1[2], p2[2], p3[2], p4[2]]] topDet = numpy.linalg.det(top) bottom = [[1., 1., 1., 0.], [p1[0], p2[0], p3[0], p5[0] - p4[0]], [p1[1], p2[1], p3[1], p5[1] - p4[1]], [p1[2], p2[2], p3[2], p5[2] - p4[2]]] botDet = numpy.linalg.det(bottom) else: # actually use numeric top = Matrix.Matrix([[1., 1., 1., 1.], [p1[0], p2[0], p3[0], p4[0]], [p1[1], p2[1], p3[1], p4[1]], [p1[2], p2[2], p3[2], p4[2]]]) topDet = LinearAlgebra.determinant(top) bottom = Matrix.Matrix([[1., 1., 1., 0.], [p1[0], p2[0], p3[0], p5[0] - p4[0]], [p1[1], p2[1], p3[1], p5[1] - p4[1]], [p1[2], p2[2], p3[2], p5[2] - p4[2]]]) botDet = LinearAlgebra.determinant(bottom) if topDet == 0.0 or botDet == 0.0: return False t = -topDet / botDet x = p4[0] + (p5[0] - p4[0]) * t y = p4[1] + (p5[1] - p4[1]) * t z = p4[2] + (p5[2] - p4[2]) * t return [x, y, z]
def linePlaneIntersectionNumeric(p1, p2, p3, p4, p5): if not useNumeric: return linePlaneIntersection(p1, p2, p3, p4, p5) if useNumpy: top = [ [1., 1., 1., 1.], [p1[0], p2[0], p3[0], p4[0]], [p1[1], p2[1], p3[1], p4[1]], [p1[2], p2[2], p3[2], p4[2]]] topDet = numpy.linalg.det(top) bottom = [ [1., 1., 1., 0.], [p1[0], p2[0], p3[0], p5[0]-p4[0]], [p1[1], p2[1], p3[1], p5[1]-p4[1]], [p1[2], p2[2], p3[2], p5[2]-p4[2]]] botDet = numpy.linalg.det(bottom) else: # actually use numeric top = Matrix.Matrix( [[1., 1., 1., 1.], [p1[0], p2[0], p3[0], p4[0]], [p1[1], p2[1], p3[1], p4[1]], [p1[2], p2[2], p3[2], p4[2]]]) topDet = LinearAlgebra.determinant(top) bottom = Matrix.Matrix( [[1., 1., 1., 0.], [p1[0], p2[0], p3[0], p5[0]-p4[0]], [p1[1], p2[1], p3[1], p5[1]-p4[1]], [p1[2], p2[2], p3[2], p5[2]-p4[2]]]) botDet = LinearAlgebra.determinant(bottom) if topDet == 0.0 or botDet == 0.0: return False t = -topDet/botDet x = p4[0] + (p5[0]-p4[0]) * t y = p4[1] + (p5[1]-p4[1]) * t z = p4[2] + (p5[2]-p4[2]) * t return [x, y, z]
def _gaussian(self, mean, cvm, x): m = len(mean) assert cvm.shape == (m, m), \ 'bad sized covariance matrix, %s' % str(cvm.shape) try: det = LinearAlgebra.determinant(cvm) inv = LinearAlgebra.inverse(cvm) a = det**-0.5 * (2 * Numeric.pi)**(-m / 2.0) dx = x - mean b = -0.5 * Numeric.matrixmultiply( \ Numeric.matrixmultiply(dx, inv), dx) return a * Numeric.exp(b) except OverflowError: # happens when the exponent is negative infinity - i.e. b = 0 # i.e. the inverse of cvm is huge (cvm is almost zero) return 0
def EnergyFromBoxShape(self, strain): if self.atoms == None: return if self.debug: unstrainedEnergy = self.atoms.GetPotentialEnergy() unstrainedSCVs = ApplyStrain(self.atoms, strain) if self.debug >= 2: print "volume:",LA.determinant(self.atoms.GetUnitCell()) energy = self.atoms.GetPotentialEnergy() # restore original state self.atoms.GetUnitCell().SetBasis(unstrainedSCVs) if self.debug: if abs(unstrainedEnergy - self.atoms.GetPotentialEnergy()) > 1.e-10: print unstrainedEnergy,self.atoms.GetPotentialEnergy() raise StandardError return energy
def EnergyFromBoxShape(self, strain): if self.atoms == None: return if self.debug: unstrainedEnergy = self.atoms.GetPotentialEnergy() unstrainedSCVs = ApplyStrain(self.atoms, strain) if self.debug >= 2: print "volume:", LA.determinant(self.atoms.GetUnitCell()) energy = self.atoms.GetPotentialEnergy() # restore original state self.atoms.GetUnitCell().SetBasis(unstrainedSCVs) if self.debug: if abs(unstrainedEnergy - self.atoms.GetPotentialEnergy()) > 1.e-10: print unstrainedEnergy, self.atoms.GetPotentialEnergy() raise StandardError return energy