def test_orthogonalize(self): '''Can correctly create an orthogonal basis from vectors.''' x = np.linspace(0, np.pi, 1001) # Create sin and cos vectors of unit length sin_h = np.sin(x) sin_h /= np.linalg.norm(sin_h) cos_h = np.cos(x) cos_h /= np.linalg.norm(cos_h) X = np.array([50 * sin_h, 75 * cos_h]) Y = spy.orthogonalize(X) assert (np.allclose(Y.dot(Y.T), np.array([[1, 0], [0, 1]]))) assert (np.allclose(X.dot(Y.T), np.array([[50, 0], [0, 75]])))
def test_orthogonalize_subset(self): '''Can correctly create an orthogonal basis from vector subset.''' x = np.linspace(0, np.pi, 1001) # Create sin and cos vectors of unit length sin_h = np.sin(x) sin_h /= np.linalg.norm(sin_h) cos_h = np.cos(x) cos_h /= np.linalg.norm(cos_h) # First vector in X will already be a unit vector X = np.array([sin_h, 75 * cos_h]) Y = spy.orthogonalize(X, start=1) assert (np.allclose(Y.dot(Y.T), np.array([[1, 0], [0, 1]]))) assert (np.allclose(X.dot(Y.T), np.array([[1, 0], [0, 75]])))
def extMain(hamFname, inValue, timePS, timestepFS, outFname): """Method to run the entire calculation externally, useful for running multiple calculations in series Parameters ---------- hamFname : the header for the input matrix file inValue : the values to replace in the matrix timePS : the time in picosecond to run the calculation for timestepFS : the timestep in femtoseconds outFname : the header for the output files """ #First need to get the matrix ham = np.loadtxt(hamFname, dtype=bytes, delimiter='\t').astype(str) #now get the variables varList = getVar(ham) #Now need to add in value to the Ham ham = repHam(ham, varList, inValue) eigenVal, eigenVec = np.linalg.eigh(ham) print('System eigenvalues are: ') print(eigenVal) orthEVec = spec.orthogonalize(eigenVec) #the value for time in in units of ps scaledTime = 1000 * timePS #Calculate the integration constants intConst = solveIC(orthEVec, eigenVal) #Now do the calculation, timestep is in units femtoseconds godMat = simCalc(orthEVec, eigenVal, intConst, scaledTime, timestepFS) writeOut(outFname, godMat) #Should also print out a readme file readME(outFname, ham, eigenVal, orthEVec, intConst, timePS, timestepFS) print('Have a nice day :)')
[(w, weights_b[w][0]) for w in weights_b if not weights_b[w] is 0]) if not average: if args.ortho.startswith("ld"): v_a = array([ weights_a[w][0] * weights_a[w][1] for w in weights_a if weights_a[w] != 0 ]).sum(axis=0).reshape(1, -1) v_b = array([ weights_b[w][0] * weights_b[w][1] for w in weights_b if weights_b[w] != 0 ]).sum(axis=0).reshape(1, -1) elif args.ortho.startswith("orth"): v_a = spectral.orthogonalize( array([ weights_a[w][1] for w in weights_a if weights_a[w] != 0 ])) w_a = array( [weights_a[w][0] for w in weights_a if weights_a[w] != 0]) v_a = multiply(v_a.T, w_a).T.sum(axis=0).reshape(1, -1) v_b = spectral.orthogonalize( array([ weights_b[w][1] for w in weights_b if weights_b[w] != 0 ])) w_b = array( [weights_b[w][0] for w in weights_b if weights_b[w] != 0]) v_b = multiply(v_b.T, w_b).T.sum(axis=0).reshape(1, -1) elif average.startswith("moving"): if args.ortho.startswith("ld"): v_a = array( [weights_a[w][1] for w in weights_a if weights_a[w] != 0])
if __name__ == "__main__": #Prompt the user for a valid input file ham = getMat() #Then ask for the variables varList = getVar(ham) #Now need to get values for the variables valVec = getVal(varList) #Now use these to replace the gen Ham with the actual values ham = repHam(ham, varList, valVec) #Now begins the heavy lifting #First get the eigensystem and orthonormal eigenvectors eigenVal, eigenVec = np.linalg.eigh(ham) print('System eigenvalues are: ') print(eigenVal) orthEVec = spec.orthogonalize(eigenVec) #Figure out how many points to calculate inTime = int(input('How many picoseconds do you want to calculate? ')) #Always do 10 femtosecond steps scaledTime = 1000 * inTime timeStep = int(input('How many femtoseconds per step? ')) #Calculate the integration constants intConst = solveIC(orthEVec, eigenVal) #Now do the calculation godMat = simCalc(orthEVec, eigenVal, intConst, scaledTime, timeStep) #The output matrix has time as the row index and the coeff as the column #index while True: test = input( 'Calculation finished, would you like to plot the results? (y/n)') if test is 'y':
def GS(S): Y = spectral.orthogonalize(S) return Y