예제 #1
0
 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))
예제 #2
0
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
예제 #3
0
 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))
예제 #4
0
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
예제 #5
0
 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)
예제 #6
0
 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)
예제 #7
0
 def testAngleColinear(self):
     assert_equal(util.angle(self.a, self.a), 0.0)
예제 #8
0
 def testAngleNullVector(self):
     assert_equal(util.angle(self.e1, self.null), numpy.nan)
예제 #9
0
 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)
예제 #10
0
 def testAngleUnitvectors(self):
     assert_equal(util.angle(self.e1, self.e2), pi / 2)
     assert_equal(util.angle(self.e1, self.a), pi / 3)