from numpy import array, dot import math def generateSeparations (symmetry_points, route): """ Given a dict of 3D vector points and the route which connects them, generate the so-called separations and separation sums. """ separations = [] # The first point is always placed at x=0 separationsums = [0.0] # The last symmetry point is of course not included # except as endpoint for the last segment for p in range(len(route)-1): delta = array(symmetry_points[route[p+1]]) - array(symmetry_points[route[p]]) # Calculate and store the vector distance between subsequent points separations.append(math.sqrt(dot(delta,delta))) # Cumulative sum of the distances separationsums.append(separationsums[-1] + separations[-1]) return separations, separationsums def convertVectorPointToX (N, id, separations, separationsums): """ Use the separations and separation sums to map 3D vector points onto a one-dimensional dummy coordinate for the horizontal axis, e.g. to be used in a bandstructure plot. id is the segment number. """ x = [] for i in range(N): # If changes are made to the definition of the vector points # in generateLineBetweenVectorsPoints below, # the denominator here must be changed accordingly x.append(float(i)/(N-1)*separations[id] + separationsums[id]) return x def generateLineBetweenVectorsPoints (start_point,end_point,N): """ Given two points (given as lists), generate a sequence of N points between them, evenly distributed and return in a list. """ b = [] for i in range(N): # The end-point is included; to exclude it, use N in the denominator instead # If this is changed, the change should be mirrored in convertVectorPointToX above a = (float(i)/(N-1),)*3*(array(end_point)-array(start_point)) + start_point b.append(a) return b