def calc_angle(self, d, h, a): """Calculate the angle (in degrees) between two atoms with H at apex.""" v1 = h.pos-d.pos v2 = h.pos-a.pos if numpy.all(v1 == v2): return 0.0 return numpy.rad2deg(angle(v1, v2))
def calculateangles(centeratom, atomlist, coordinates, k, boxvector, normvecmatrix): vectors = [] real1 = [] imag1 = [] for atom in atomlist: # print "coordinates",coordinates[centeratom],coordinates[atom] distancevector = coordinates[centeratom] - coordinates[atom] # print distancevector if all(coordinates[centeratom] == coordinates[atom]): print coordinates[centeratom], coordinates[atom] distancevectorpbc = np.where(distancevector > 0.5 * boxvector, distancevector - boxvector, distancevector) distancevectorpbc = np.where( distancevectorpbc < -0.5 * boxvector, distancevectorpbc + boxvector, distancevectorpbc ) # print "distances",distancevector,distancevectorpbc,boxvector vectors.append(np.dot(distancevectorpbc, normvecmatrix)) # vectors.append(distancevectorpbc) # print vectors vec0 = vectors.pop() for vec in vectors: angleij = angle(vec0, vec) if np.isnan(angleij): print angleij, vec0, vec real1.append(np.cos(k * angleij)) imag1.append(np.sin(k * angleij)) real1 = np.array(real1) imag1 = np.array(imag1) # sys.exit() return real1, imag1
def calc_angle(self, d, h, a): """Calculate the angle (in degrees) between two atoms with H at apex.""" v1 = h.pos - d.pos v2 = h.pos - a.pos if numpy.all(v1 == v2): return 0.0 return numpy.rad2deg(angle(v1, v2))
def calculateangles(centeratom, atomlist, coordinates, k, boxvector, normvecmatrix): vectors = [] real1 = [] imag1 = [] for atom in atomlist: #print "coordinates",coordinates[centeratom],coordinates[atom] distancevector = coordinates[centeratom] - coordinates[atom] #print distancevector if all(coordinates[centeratom] == coordinates[atom]): print coordinates[centeratom], coordinates[atom] distancevectorpbc = np.where(distancevector > 0.5 * boxvector, distancevector - boxvector, distancevector) distancevectorpbc = np.where(distancevectorpbc < -0.5 * boxvector, distancevectorpbc + boxvector, distancevectorpbc) #print "distances",distancevector,distancevectorpbc,boxvector vectors.append(np.dot(distancevectorpbc, normvecmatrix)) #vectors.append(distancevectorpbc) #print vectors vec0 = vectors.pop() for vec in vectors: angleij = angle(vec0, vec) if np.isnan(angleij): print angleij, vec0, vec real1.append(np.cos(k * angleij)) imag1.append(np.sin(k * angleij)) real1 = np.array(real1) imag1 = np.array(imag1) #sys.exit() return real1, imag1
def testAngleRandom(self): for x in numpy.random.uniform(0, pi, 20): r = numpy.random.uniform(0, 1000) v = r * numpy.array([cos(x), sin(x), 0]) assert_almost_equal(util.angle(self.e1, v), x, 6)
def testAnglePi(self): assert_almost_equal(util.angle(-2.3456e7 * self.e1, 3.4567e-6 * self.e1), pi) assert_almost_equal(util.angle(2.3456e7 * self.e1, 3.4567e-6 * self.e1), 0.0)
def testAngleColinear(self): assert_equal(util.angle(self.a, self.a), 0.0)
def testAngleNullVector(self): assert_equal(util.angle(self.e1, self.null), numpy.nan)
def testAngleVectors(self): assert_equal(util.angle(2 * self.e1, self.e2), pi / 2) assert_equal(util.angle(-2 * self.e1, self.e2), pi - pi / 2) assert_equal(util.angle(23.3 * self.e1, self.a), pi / 3)
def testAngleUnitvectors(self): assert_equal(util.angle(self.e1, self.e2), pi / 2) assert_equal(util.angle(self.e1, self.a), pi / 3)