PEATSA/Core/Goodvibes/Utilities.py
def eigenv_calccomb(matrix_hessian, jobid, verbose, l_rem = []):

    '''Calculates eigenvectors and eigenvalues of a matrix.'''
    if verbose == True:
        print 'calculating eigenvalues and eigenvectors of the '+str(len(matrix_hessian))+'x'+str(len(matrix_hessian))+' Hessian matrix'
    import math

##    import time
##
##    import numpy
##    
##    t1 = time.clock()
##    eigen_tuple = numpy.linalg.eig(matrix_hessian)
##    t2 = time.clock()
##    print t2-t1
##    eigenvalues = list(eigen_tuple[0])
##    eigenvectors = list(eigen_tuple[1])
##    eigenvectors = numpy.transpose(eigenvectors) ## transpose when diagonalization with numpy instead of Numeric
##    eigen_list = zip(eigenvalues, eigenvectors)
##    eigen_list.sort()
##    eigenvalues = [eigen_list[eigen][0] for eigen in range(len(eigen_list))]
##    eigenvectors = [eigen_list[eigen][1] for eigen in range(len(eigen_list))]
##
##    t1 = time.clock()
##    eigen_tupleh = numpy.linalg.eigh(matrix_hessian)
##    t2 = time.clock()
##    print t2-t1
##    eigenvaluesh = list(eigen_tupleh[0])
##    eigenvectorsh = list(eigen_tupleh[1])
##    eigenvectors = numpy.transpose(eigenvectors) ## transpose when diagonalization with numpy instead of Numeric
##    eigen_listh = zip(eigenvaluesh, eigenvectorsh)
##    eigen_listh.sort()
##    eigenvaluesh = [eigen_listh[eigen][0] for eigen in range(len(eigen_listh))]
##    eigenvectorsh = [eigen_listh[eigen][1] for eigen in range(len(eigen_listh))]
##
####    import Numeric, LinearAlgebra
####
####    t1 = time.clock()
####    eigen_tuple = LinearAlgebra.eigenvectors(matrix_hessian)
####    t2 = time.clock()
####    print t2-t1
####    eigenvalues = list(eigen_tuple[0])
####    eigenvectors = list(eigen_tuple[1])
######    eigenvectors = numpy.transpose(eigenvectors) ## transpose when diagonalization with numpy instead of Numeric
####    eigen_list = zip(eigenvalues, eigenvectors)
####    eigen_list.sort()
####    eigenvalues = [eigen_list[eigen][0] for eigen in range(len(eigen_list))]
####    eigenvectors = [eigen_list[eigen][1] for eigen in range(len(eigen_list))]
####
####    t1 = time.clock()
####    eigen_tupleh = LinearAlgebra.Heigenvectors(matrix_hessian)
####    t2 = time.clock()
####    print t2-t1
####    eigenvaluesh = list(eigen_tupleh[0])
####    eigenvectorsh = list(eigen_tupleh[1])
######    eigenvectors = numpy.transpose(eigenvectors) ## transpose when diagonalization with numpy instead of Numeric
####    eigen_listh = zip(eigenvaluesh, eigenvectorsh)
####    eigen_listh.sort()
####    eigenvaluesh = [eigen_listh[eigen][0] for eigen in range(len(eigen_listh))]
####    eigenvectorsh = [eigen_listh[eigen][1] for eigen in range(len(eigen_listh))]
##
##    print eigenvalues[0], eigenvalues[-1]
##    print eigenvaluesh[0], eigenvaluesh[-1]
##
##    print eigenvectors[0][0], eigenvectors[0][-1], eigenvectors[-1][0], eigenvectors[-1][-1]
##    print eigenvectorsh[0][0], eigenvectorsh[0][-1], eigenvectorsh[-1][0], eigenvectorsh[-1][-1]
##
##    print eigen_tuple[0]
##    print min(eigen_tuple[0])
##    print max(eigen_tuple[0])
##
##    stop

    import numpy
    ## diagonalize hessian matrix
    eigen_tuple = numpy.linalg.eigh(matrix_hessian)
    ## parse eigenvalues and eigenvectors
    eigenvalues = list(eigen_tuple[0])
    eigenvectors = list(eigen_tuple[1])
    eigenvectors = numpy.transpose(eigenvectors) ## transpose when diagonalization with numpy instead of Numeric
    ## organize eigenvalues and eigenvectors in list
    eigen_list = zip(eigenvalues, eigenvectors)
    ## sort list
    eigen_list.sort()
    ## parse sorted eigenvalues and eigenvectors
    eigenvalues = [eigen_list[eigen][0] for eigen in range(len(eigen_list))]
    eigenvectors = [eigen_list[eigen][1] for eigen in range(len(eigen_list))]
    if verbose == True:
        lines = ['rows=modes, cols=coordinates\n']
        for mode in range(6,len(eigenvectors)):
            lines += [str(eigenvectors[mode])+'\n']
        fd = open('%s_eigenvectors.txt' %(jobid),'w')
        fd.writelines(lines)
        fd.close()

    ## calculate length of mode 7 (equals 1 when using module linearalgebra)
    len7 = math.sqrt(sum(numpy.array(eigenvectors[6])*numpy.array(eigenvectors[6])))

    ## loop over modes
    for i in range(7+3*len(l_rem),len(eigenvalues)-1):

        ## calculate length of mode i
        leni = math.sqrt(sum(numpy.array(eigenvectors[i])*numpy.array(eigenvectors[i])))

        ## scale length of mode i relative to length of mode 7
        try:
            lenfactor = (len7/leni)/(eigenvalues[i]/eigenvalues[6+3*len(l_rem)])
        except:
            print eigenvalues
            print l_rem
            print i, len7, leni, eigenvalues[i], eigenvalues[6+3*len(l_rem)]
            stop_float_divison
        for j in range(len(eigenvectors[i])):
            eigenvectors[i][j] *= lenfactor

    ## copy lists of eigenvectors to eigenvectors_combined
    eigenvectors_combined = []
    for mode in range(len(eigenvalues)):
        eigenvectors_combined.append(list(eigenvectors[mode]))
    ## change mode i to be the sum of modes 7 to i
    for mode in range(7,len(eigenvalues)):
        for coordinate in range(len(eigenvalues)):
            eigenvectors_combined[mode][coordinate] += eigenvectors_combined[mode-1][coordinate]

    if verbose == True:
        print 'calculated eigenvalues and eigenvectors of the '+str(len(matrix_hessian))+'x'+str(len(matrix_hessian))+' Hessian matrix'

    return eigenvectors, eigenvalues, eigenvectors_combined
Calculates eigenvectors and eigenvalues of a matrix.
Calculates eigenvectors and eigenvalues of a matrix.
Calculates eigenvectors and eigenvalues of a matrix .
def eigenv_calccomb(matrix_hessian, jobid, verbose, l_rem = []):
    if verbose == True:
        print 'calculating eigenvalues and eigenvectors of the '+str(len(matrix_hessian))+'x'+str(len(matrix_hessian))+' Hessian matrix'
    import math
    import numpy
    t1 = time.clock()
    eigen_tuple = numpy.linalg.eig(matrix_hessian)
    t2 = time.clock()
    print t2-t1
    eigenvalues = list(eigen_tuple[0])
    eigenvectors = list(eigen_tuple[1])
    eigenvectors = numpy.transpose(eigenvectors)  transpose when diagonalization with numpy instead of Numeric
    eigen_list = zip(eigenvalues, eigenvectors)
    eigen_list.sort()
    eigenvalues = [eigen_list[eigen][0] for eigen in range(len(eigen_list))]
    eigenvectors = [eigen_list[eigen][1] for eigen in range(len(eigen_list))]
    t1 = time.clock()
    eigen_tupleh = numpy.linalg.eigh(matrix_hessian)
    t2 = time.clock()
    print t2-t1
    eigenvaluesh = list(eigen_tupleh[0])
    eigenvectorsh = list(eigen_tupleh[1])
    eigenvectors = numpy.transpose(eigenvectors)  transpose when diagonalization with numpy instead of Numeric
    eigen_listh = zip(eigenvaluesh, eigenvectorsh)
    eigen_listh.sort()
    eigenvaluesh = [eigen_listh[eigen][0] for eigen in range(len(eigen_listh))]
    eigenvectorsh = [eigen_listh[eigen][1] for eigen in range(len(eigen_listh))]
    import Numeric, LinearAlgebra
    t1 = time.clock()
    eigen_tuple = LinearAlgebra.eigenvectors(matrix_hessian)
    t2 = time.clock()
    print t2-t1
    eigenvalues = list(eigen_tuple[0])
    eigenvectors = list(eigen_tuple[1])
    eigenvectors = numpy.transpose(eigenvectors)  transpose when diagonalization with numpy instead of Numeric
    eigen_list = zip(eigenvalues, eigenvectors)
    eigen_list.sort()
    eigenvalues = [eigen_list[eigen][0] for eigen in range(len(eigen_list))]
    eigenvectors = [eigen_list[eigen][1] for eigen in range(len(eigen_list))]
    t1 = time.clock()
    eigen_tupleh = LinearAlgebra.Heigenvectors(matrix_hessian)
    t2 = time.clock()
    print t2-t1
    eigenvaluesh = list(eigen_tupleh[0])
    eigenvectorsh = list(eigen_tupleh[1])
    eigenvectors = numpy.transpose(eigenvectors)  transpose when diagonalization with numpy instead of Numeric
    eigen_listh = zip(eigenvaluesh, eigenvectorsh)
    eigen_listh.sort()
    eigenvaluesh = [eigen_listh[eigen][0] for eigen in range(len(eigen_listh))]
    eigenvectorsh = [eigen_listh[eigen][1] for eigen in range(len(eigen_listh))]
    print eigenvalues[0], eigenvalues[-1]
    print eigenvaluesh[0], eigenvaluesh[-1]
    print eigenvectors[0][0], eigenvectors[0][-1], eigenvectors[-1][0], eigenvectors[-1][-1]
    print eigenvectorsh[0][0], eigenvectorsh[0][-1], eigenvectorsh[-1][0], eigenvectorsh[-1][-1]
    print eigen_tuple[0]
    print min(eigen_tuple[0])
    print max(eigen_tuple[0])
    stop
    import numpy
     diagonalize hessian matrix
    eigen_tuple = numpy.linalg.eigh(matrix_hessian)
     parse eigenvalues and eigenvectors
    eigenvalues = list(eigen_tuple[0])
    eigenvectors = list(eigen_tuple[1])
    eigenvectors = numpy.transpose(eigenvectors)  transpose when diagonalization with numpy instead of Numeric
     organize eigenvalues and eigenvectors in list
    eigen_list = zip(eigenvalues, eigenvectors)
     sort list
    eigen_list.sort()
     parse sorted eigenvalues and eigenvectors
    eigenvalues = [eigen_list[eigen][0] for eigen in range(len(eigen_list))]
    eigenvectors = [eigen_list[eigen][1] for eigen in range(len(eigen_list))]
    if verbose == True:
        lines = ['rows=modes, cols=coordinates\n']
        for mode in range(6,len(eigenvectors)):
            lines += [str(eigenvectors[mode])+'\n']
        fd = open('%s_eigenvectors.txt' %(jobid),'w')
        fd.writelines(lines)
        fd.close()
     calculate length of mode 7 (equals 1 when using module linearalgebra)
    len7 = math.sqrt(sum(numpy.array(eigenvectors[6])*numpy.array(eigenvectors[6])))
     loop over modes
    for i in range(7+3*len(l_rem),len(eigenvalues)-1):
         calculate length of mode i
        leni = math.sqrt(sum(numpy.array(eigenvectors[i])*numpy.array(eigenvectors[i])))
         scale length of mode i relative to length of mode 7
        try:
            lenfactor = (len7/leni)/(eigenvalues[i]/eigenvalues[6+3*len(l_rem)])
        except:
            print eigenvalues
            print l_rem
            print i, len7, leni, eigenvalues[i], eigenvalues[6+3*len(l_rem)]
            stop_float_divison
        for j in range(len(eigenvectors[i])):
            eigenvectors[i][j] *= lenfactor
     copy lists of eigenvectors to eigenvectors_combined
    eigenvectors_combined = []
    for mode in range(len(eigenvalues)):
        eigenvectors_combined.append(list(eigenvectors[mode]))
     change mode i to be the sum of modes 7 to i
    for mode in range(7,len(eigenvalues)):
        for coordinate in range(len(eigenvalues)):
            eigenvectors_combined[mode][coordinate] += eigenvectors_combined[mode-1][coordinate]
    if verbose == True:
        print 'calculated eigenvalues and eigenvectors of the '+str(len(matrix_hessian))+'x'+str(len(matrix_hessian))+' Hessian matrix'
    return eigenvectors, eigenvalues, eigenvectors_combined
def eigenv_calccomb ( matrix_hessian , jobid , verbose , l_rem = [ ] ) : if verbose == True : print 'calculating eigenvalues and eigenvectors of the ' + str ( len ( matrix_hessian ) ) + 'x' + str ( len ( matrix_hessian ) ) + ' Hessian matrix' import math import numpy eigen_tuple = numpy . linalg . eigh ( matrix_hessian ) eigenvalues = list ( eigen_tuple [ 0 ] ) eigenvectors = list ( eigen_tuple [ 1 ] ) eigenvectors = numpy . transpose ( eigenvectors ) eigen_list = zip ( eigenvalues , eigenvectors ) eigen_list . sort ( ) eigenvalues = [ eigen_list [ eigen ] [ 0 ] for eigen in range ( len ( eigen_list ) ) ] eigenvectors = [ eigen_list [ eigen ] [ 1 ] for eigen in range ( len ( eigen_list ) ) ] if verbose == True : lines = [ 'rows=modes, cols=coordinates\n' ] for mode in range ( 6 , len ( eigenvectors ) ) : lines += [ str ( eigenvectors [ mode ] ) + '\n' ] fd = open ( '%s_eigenvectors.txt' % ( jobid ) , 'w' ) fd . writelines ( lines ) fd . close ( ) len7 = math . sqrt ( sum ( numpy . array ( eigenvectors [ 6 ] ) * numpy . array ( eigenvectors [ 6 ] ) ) ) for i in range ( 7 + 3 * len ( l_rem ) , len ( eigenvalues ) - 1 ) : leni = math . sqrt ( sum ( numpy . array ( eigenvectors [ i ] ) * numpy . array ( eigenvectors [ i ] ) ) ) try : lenfactor = ( len7 / leni ) / ( eigenvalues [ i ] / eigenvalues [ 6 + 3 * len ( l_rem ) ] ) except : print eigenvalues print l_rem print i , len7 , leni , eigenvalues [ i ] , eigenvalues [ 6 + 3 * len ( l_rem ) ] stop_float_divison for j in range ( len ( eigenvectors [ i ] ) ) : eigenvectors [ i ] [ j ] *= lenfactor eigenvectors_combined = [ ] for mode in range ( len ( eigenvalues ) ) : eigenvectors_combined . append ( list ( eigenvectors [ mode ] ) ) for mode in range ( 7 , len ( eigenvalues ) ) : for coordinate in range ( len ( eigenvalues ) ) : eigenvectors_combined [ mode ] [ coordinate ] += eigenvectors_combined [ mode - 1 ] [ coordinate ] if verbose == True : print 'calculated eigenvalues and eigenvectors of the ' + str ( len ( matrix_hessian ) ) + 'x' + str ( len ( matrix_hessian ) ) + ' Hessian matrix' return eigenvectors , eigenvalues , eigenvectors_combined
Calculates eigenvectors and eigenvalues of a matrix.
Calculates eigenvectors and eigenvalues of a matrix .
'''Calculates eigenvectors and eigenvalues of a matrix.''' ##    import time ## ##    import numpy ##     ##    t1 = time.clock() ##    eigen_tuple = numpy.linalg.eig(matrix_hessian) ##    t2 = time.clock() ##    print t2-t1 ##    eigenvalues = list(eigen_tuple[0]) ##    eigenvectors = list(eigen_tuple[1]) ##    eigenvectors = numpy.transpose(eigenvectors) ## transpose when diagonalization with numpy instead of Numeric ##    eigen_list = zip(eigenvalues, eigenvectors) ##    eigen_list.sort() ##    eigenvalues = [eigen_list[eigen][0] for eigen in range(len(eigen_list))] ##    eigenvectors = [eigen_list[eigen][1] for eigen in range(len(eigen_list))] ## ##    t1 = time.clock() ##    eigen_tupleh = numpy.linalg.eigh(matrix_hessian) ##    t2 = time.clock() ##    print t2-t1 ##    eigenvaluesh = list(eigen_tupleh[0]) ##    eigenvectorsh = list(eigen_tupleh[1]) ##    eigenvectors = numpy.transpose(eigenvectors) ## transpose when diagonalization with numpy instead of Numeric ##    eigen_listh = zip(eigenvaluesh, eigenvectorsh) ##    eigen_listh.sort() ##    eigenvaluesh = [eigen_listh[eigen][0] for eigen in range(len(eigen_listh))] ##    eigenvectorsh = [eigen_listh[eigen][1] for eigen in range(len(eigen_listh))] ## ####    import Numeric, LinearAlgebra #### ####    t1 = time.clock() ####    eigen_tuple = LinearAlgebra.eigenvectors(matrix_hessian) ####    t2 = time.clock() ####    print t2-t1 ####    eigenvalues = list(eigen_tuple[0]) ####    eigenvectors = list(eigen_tuple[1]) ######    eigenvectors = numpy.transpose(eigenvectors) ## transpose when diagonalization with numpy instead of Numeric ####    eigen_list = zip(eigenvalues, eigenvectors) ####    eigen_list.sort() ####    eigenvalues = [eigen_list[eigen][0] for eigen in range(len(eigen_list))] ####    eigenvectors = [eigen_list[eigen][1] for eigen in range(len(eigen_list))] #### ####    t1 = time.clock() ####    eigen_tupleh = LinearAlgebra.Heigenvectors(matrix_hessian) ####    t2 = time.clock() ####    print t2-t1 ####    eigenvaluesh = list(eigen_tupleh[0]) ####    eigenvectorsh = list(eigen_tupleh[1]) ######    eigenvectors = numpy.transpose(eigenvectors) ## transpose when diagonalization with numpy instead of Numeric ####    eigen_listh = zip(eigenvaluesh, eigenvectorsh) ####    eigen_listh.sort() ####    eigenvaluesh = [eigen_listh[eigen][0] for eigen in range(len(eigen_listh))] ####    eigenvectorsh = [eigen_listh[eigen][1] for eigen in range(len(eigen_listh))] ## ##    print eigenvalues[0], eigenvalues[-1] ##    print eigenvaluesh[0], eigenvaluesh[-1] ## ##    print eigenvectors[0][0], eigenvectors[0][-1], eigenvectors[-1][0], eigenvectors[-1][-1] ##    print eigenvectorsh[0][0], eigenvectorsh[0][-1], eigenvectorsh[-1][0], eigenvectorsh[-1][-1] ## ##    print eigen_tuple[0] ##    print min(eigen_tuple[0]) ##    print max(eigen_tuple[0]) ## ##    stop ## diagonalize hessian matrix ## parse eigenvalues and eigenvectors ## transpose when diagonalization with numpy instead of Numeric ## organize eigenvalues and eigenvectors in list ## sort list ## parse sorted eigenvalues and eigenvectors ## calculate length of mode 7 (equals 1 when using module linearalgebra) ## loop over modes ## calculate length of mode i ## scale length of mode i relative to length of mode 7 ## copy lists of eigenvectors to eigenvectors_combined ## change mode i to be the sum of modes 7 to i
matrix_hessian
jobid
verbose
l_rem