From 32d2e1f99f5b77ba45594297b140f619a64fd290 Mon Sep 17 00:00:00 2001 From: MitchLahm Date: Wed, 1 Nov 2023 16:44:57 -0400 Subject: [PATCH 1/4] Added Molden and centroid coord functionality --- concordantmodes/algorithm.py | 15 +- concordantmodes/cma.py | 258 ++++----- concordantmodes/directory_tree.py | 260 +++++---- concordantmodes/f_convert.py | 43 +- concordantmodes/force_constant.py | 22 +- concordantmodes/g_matrix.py | 1 - concordantmodes/g_read.py | 22 + concordantmodes/gf_method.py | 22 +- concordantmodes/int2cart.py | 2 +- concordantmodes/molden_template.py | 10 + concordantmodes/molden_writer.py | 75 +++ concordantmodes/options.py | 3 + concordantmodes/reap.py | 213 ++++--- concordantmodes/rmsd.py | 194 +++---- concordantmodes/s_vectors.py | 718 +++++++++++++----------- concordantmodes/sapelo_template.py | 2 - concordantmodes/ted.py | 233 +------- concordantmodes/tests/test_f_read.py | 1 - concordantmodes/tests/test_s_vectors.py | 1 - concordantmodes/tests/test_zmat.py | 1 - concordantmodes/transf_disp.py | 664 +++++++++++++++++----- concordantmodes/zmat.py | 343 +++++++++-- 22 files changed, 1923 insertions(+), 1180 deletions(-) create mode 100644 concordantmodes/g_read.py create mode 100644 concordantmodes/molden_template.py create mode 100644 concordantmodes/molden_writer.py diff --git a/concordantmodes/algorithm.py b/concordantmodes/algorithm.py index bc9b647a..75abaf49 100644 --- a/concordantmodes/algorithm.py +++ b/concordantmodes/algorithm.py @@ -6,7 +6,7 @@ class Algorithm(object): """ - The purpose of this class is to return a list of indicies by which the force constants of the CMA method + The purpose of this class is to return a list of indices by which the force constants of the CMA method will be computed. These indices will be determined by user input or by a scoring function which takes into consideration the overlap of the normal coordinates and the difference in force constants for a particular normal mode. @@ -22,8 +22,11 @@ def run(self): initial_fc = self.initial_fc tolerance = 5e-32 - print(self.eigs) + # print(self.eigs) a = self.eigs + # print(self.options.off_diag) + # print(self.options.off_diag_limit) + self.options.mode_coupling_check = False if self.options.mode_coupling_check: self.indices = self.coupling_diagnostic(a, initial_fc, tolerance) else: @@ -61,20 +64,14 @@ def loop(self, a, off_diag, lim): def coupling_diagnostic(self, a, initial_fc, tolerance): indices = [] diag = np.zeros((a, a)) - # with open("S_p.npy", "rb") as x: - # S = np.load(x) for x in range(a): for y in range(a): if x == y: diag[x, x] = 0 elif x != y: diag[x, y] = S[x, y] / (initial_fc[x] - initial_fc[y]) - # print(diag, "printing diag") diag = np.absolute(diag) print(diag) - # with open("D.npy", "wb") as q: - # np.save(q, diag) - # diag[np.abs(diag) < 1e-31] = 1e-30 data = np.abs(diag) hist, bin_edges = np.histogram(data, bins=a) for index, i in np.ndenumerate(data): @@ -85,7 +82,5 @@ def coupling_diagnostic(self, a, initial_fc, tolerance): if index[1] > index[0]: indices_new.append(index) indices = indices_new - # if self.options.clean_house: - # os.system("rm D.npy S_p.npy") return indices diff --git a/concordantmodes/cma.py b/concordantmodes/cma.py index 06c2118a..b0f14153 100644 --- a/concordantmodes/cma.py +++ b/concordantmodes/cma.py @@ -15,7 +15,9 @@ from concordantmodes.force_constant import ForceConstant from concordantmodes.gf_method import GFMethod from concordantmodes.g_matrix import GMatrix +from concordantmodes.g_read import GrRead from concordantmodes.int2cart import Int2Cart +from concordantmodes.molden_writer import MoldenWriter from concordantmodes.reap import Reap from concordantmodes.rmsd import RMSD from concordantmodes.s_vectors import SVectors @@ -26,8 +28,6 @@ from concordantmodes.sapelo_template import SapeloTemplate from concordantmodes.zmat import Zmat -# from concordantmodes.second_order import SecOrder - class ConcordantModes(object): """ @@ -39,11 +39,12 @@ class ConcordantModes(object): BOHR_ANG: Standard uncertainty of 0.00000000080 """ - def __init__(self, options, proj=None): + def __init__(self, options, proj=None, extra_indices=np.array([])): self.options = options self.MDYNE_HART = 4.3597447222071 self.BOHR_ANG = 0.529177210903 self.proj = proj + self.extra_indices = extra_indices def run(self): t1 = time.time() @@ -62,6 +63,7 @@ def run(self): ) if self.options.man_proj: proj = self.proj + np.set_printoptions(precision=4, linewidth=240) print(proj.shape) print(proj) s_vec.run( @@ -76,7 +78,6 @@ def run(self): True, second_order=self.options.second_order, ) - self.TED_obj = TED(s_vec.proj, self.zmat_obj) # Print out the percentage composition of the projected coordinates @@ -91,15 +92,20 @@ def run(self): G = g_mat.G.copy() + if os.path.exists(rootdir + "/fc.grad"): + print("HERE") + g_read_obj = GrRead("fc.grad") + g_read_obj.run(self.zmat_obj.cartesians_init) + # Read in FC matrix in cartesians, then convert to internals. # Or compute an initial hessian in internal coordinates. - init_bool = False + self.options.init_bool = False if os.path.exists(rootdir + "/fc.dat"): f_read_obj = FcRead("fc.dat") elif os.path.exists(rootdir + "/FCMFINAL"): f_read_obj = FcRead("FCMFINAL") else: - init_bool = True + self.options.init_bool = True # First generate displacements in internal coordinates eigs_init = np.eye(len(s_vec.proj.T)) @@ -205,7 +211,6 @@ def run(self): indices, self.options.energy_regex_init, self.options.gradient_regex, - self.options.molly_regex_init, self.options.success_regex_init, deriv_level=self.options.deriv_level_init, # disp_sym = init_disp.disp_sym @@ -257,7 +262,7 @@ def run(self): self.options.deriv_level_init = 0 self.options.deriv_level = 0 - if not init_bool: + if not self.options.init_bool: f_read_obj.run() f_conv_obj = FcConv( f_read_obj.fc_mat, @@ -267,17 +272,23 @@ def run(self): False, self.TED_obj, self.options.units, + self.options.second_order, ) - f_conv_obj.run() + if self.options.second_order: + f_conv_obj.run(grad=g_read_obj.cart_grad) + else: + f_conv_obj.run() F = f_conv_obj.F else: F = fc_init.FC - if self.options.coords != "ZMAT" and not init_bool: + if self.options.coords != "ZMAT" and not self.options.init_bool: F = np.dot(self.TED_obj.proj.T, np.dot(F, self.TED_obj.proj)) if self.options.coords != "ZMAT": g_mat.G = np.dot(self.TED_obj.proj.T, np.dot(g_mat.G, self.TED_obj.proj)) + self.options.init_bool = False + # Run the GF matrix method with the internal F-Matrix and computed G-Matrix! print("Initial Frequencies:") init_GF = GFMethod( @@ -309,14 +320,34 @@ def run(self): ) TED_GF.run() - # S = TED_GF.S initial_fc = TED_GF.eig_v eigs = len(TED_GF.S) algo = Algorithm(eigs, initial_fc, self.options) + # algo.options.off_diag_bands = 2 + # algo.options.off_diag_limit = False + # algo.options.off_diag = True + algo.run() + if len(self.extra_indices): + algo.indices = np.append(algo.indices, self.extra_indices, axis=0) print(algo.indices) + # This is hacky code, will need to be updated + if self.options.pert_off_diag: + offdiag_indices = np.triu_indices(len(algo.indices)) + offdiag_indices = np.array(offdiag_indices).T + + del_array = np.array([]) + for i in range(len(offdiag_indices)): + if offdiag_indices[i][0] == offdiag_indices[i][1]: + del_array = np.append(del_array, i) + offdiag_indices = np.delete(offdiag_indices, del_array.astype(int), axis=0) + algo.indices = np.append(algo.indices, offdiag_indices, axis=0) + print(algo.indices) + # print(offdiag_indices) + + # raise RuntimeError # Recompute the B-Tensors to match the final geometry, # then generate the displacements. @@ -336,12 +367,9 @@ def run(self): self.options, algo.indices, GF=TED_GF, + # offdiag_indices=offdiag_indices ) - # B_tensor = s_vec.B - # second_B = SecOrder( - # self.zmat_obj, self.zmat_obj.cartesians_final, B_tensor, self.options - # ) - # second_B.run() + transf_disp.run() p_disp = transf_disp.p_disp m_disp = transf_disp.m_disp @@ -349,7 +377,6 @@ def run(self): raise RuntimeError # The displacements have been generated, now we have to run them! - prog = self.options.program progname = prog.split("@")[0] if self.options.gen_disps: @@ -422,9 +449,8 @@ def run(self): sub = Submit(disp_list, self.options) sub.run() - # After this point, all of the jobs will have finished, and its time - # to reap the energies as well as checking for sucesses on all of - # the jobs + # After this point, all of the jobs have finished, and it's time + # to reap the energies as well as checking for sucesses print(eigs) reap_obj = Reap( progname, @@ -436,9 +462,7 @@ def run(self): algo.indices, self.options.energy_regex, self.options.gradient_regex, - self.options.molly_regex_init, self.options.success_regex, - # disp_sym = transf_disp.disp_sym ) reap_obj.run() @@ -524,103 +548,107 @@ def run(self): True, self.TED_obj, self.options.units, + self.options.second_order, ) cart_conv.run() # if mol2.size != 0: - # print('I cant believe its not CMA1!') # if self.options.rmsd: - # # rmsd_geom = RMSD() # rmsd_geom.run(mol1,mol2) - t2 = time.time() print("Frequency Shift (cm^-1): ") print(final_GF.freq - init_GF.freq) + + # Write a molden file + molden = MoldenWriter(self.zmat_obj, transf_disp, final_GF.freq) + molden.run() + + t2 = time.time() print("This program took " + str(t2 - t1) + " seconds to run.") # after this point, you could loop through the full FC matrix and compute several other benchmark frequencies if self.options.benchmark_full: - self.options.off_diag = True - # nate - with open("Full_fc_levelB.npy", "rb") as z: - FC = np.load(z) - self.F = np.zeros((eigs, eigs)) - for q in range(eigs): - self.F = np.zeros((eigs, eigs)) - self.options.off_diag_bands = q - a = eigs - algo = Algorithm(eigs, initial_fc, self.options) - algo.run() - print(algo.indices) - if q == 0: - cma = None - else: - cma = False - for index in algo.indices: - i, j = index[0], index[1] - self.F[i, j] = FC[i, j] - cf = np.triu_indices(a, 1) - il = (cf[1], cf[0]) - self.F[il] = self.F[cf] - # Final GF Matrix run - print("Final Frequencies:") - final_GF = GFMethod( - self.G, - self.F, - self.options.tol, - self.options.proj_tol, - self.zmat_obj, - self.TED_obj, - cma=cma, - ) - final_GF.run() - - # This code below is a rudimentary table of the TED for the final - # frequencies. Actually right now it uses the initial L-matrix, - # which may need to be modified by the final L-matrix. - print("////////////////////////////////////////////") - print("//{:^40s}//".format(" Final TED")) - print("////////////////////////////////////////////") - self.TED_obj.run(np.dot(init_GF.L, final_GF.L), final_GF.freq) - - # This code prints out the frequencies in order of energy as well - # as the ZPVE in several different units. - print( - "Final ZPVE in: " - + "{:6.2f}".format(np.sum(final_GF.freq) / 2) - + " (cm^-1) " - + "{:6.2f}".format(0.5 * np.sum(final_GF.freq) / 349.7550881133) - + " (kcal mol^-1) " - + "{:6.2f}".format(0.5 * np.sum(final_GF.freq) / 219474.6313708) - + " (hartrees) " - ) - - # This code converts the force constants back into cartesian - # coordinates and writes out an "output.default.hess" file, which - # is of the same format as FCMFINAL of CFOUR. - # self.F = np.dot(np.dot(transf_disp.eig_inv.T, self.F), transf_disp.eig_inv) - # if self.options.coords != "ZMAT": - # self.F = np.dot(self.TED_obj.proj, np.dot(self.F, self.TED_obj.proj.T)) - # cart_conv = FcConv( - # self.F, - # s_vec, - # self.zmat_obj, - # "cartesian", - # True, - # self.TED_obj, - # self.options.units, - # ) - # cart_conv.run() - - t2 = time.time() - print("Frequency Shift (cm^-1): ") - print(final_GF.freq - init_GF.freq) - print("This program took " + str(t2 - t1) + " seconds to run.") - - print("////////////////////////////////////////////") - print("//{:^40s}//".format(" END OF LOOP")) - print("////////////////////////////////////////////") + # self.options.off_diag = True + # # nate + # with open("Full_fc_levelB.npy", "rb") as z: + # FC = np.load(z) + # self.F = np.zeros((eigs, eigs)) + # for q in range(eigs): + # self.F = np.zeros((eigs, eigs)) + # self.options.off_diag_bands = q + # a = eigs + # algo = Algorithm(eigs, initial_fc, self.options) + # algo.run() + # print(algo.indices) + # if q == 0: + # cma = None + # else: + # cma = False + # for index in algo.indices: + # i, j = index[0], index[1] + # self.F[i, j] = FC[i, j] + # cf = np.triu_indices(a, 1) + # il = (cf[1], cf[0]) + # self.F[il] = self.F[cf] + # # Final GF Matrix run + # print("Final Frequencies:") + # final_GF = GFMethod( + # self.G, + # self.F, + # self.options.tol, + # self.options.proj_tol, + # self.zmat_obj, + # self.TED_obj, + # cma=cma, + # ) + # final_GF.run() + + # # This code below is a rudimentary table of the TED for the final + # # frequencies. Actually right now it uses the initial L-matrix, + # # which may need to be modified by the final L-matrix. + # print("////////////////////////////////////////////") + # print("//{:^40s}//".format(" Final TED")) + # print("////////////////////////////////////////////") + # self.TED_obj.run(np.dot(init_GF.L, final_GF.L), final_GF.freq) + + # # This code prints out the frequencies in order of energy as well + # # as the ZPVE in several different units. + # print( + # "Final ZPVE in: " + # + "{:6.2f}".format(np.sum(final_GF.freq) / 2) + # + " (cm^-1) " + # + "{:6.2f}".format(0.5 * np.sum(final_GF.freq) / 349.7550881133) + # + " (kcal mol^-1) " + # + "{:6.2f}".format(0.5 * np.sum(final_GF.freq) / 219474.6313708) + # + " (hartrees) " + # ) + + # # This code converts the force constants back into cartesian + # # coordinates and writes out an "output.default.hess" file, which + # # is of the same format as FCMFINAL of CFOUR. + # # self.F = np.dot(np.dot(transf_disp.eig_inv.T, self.F), transf_disp.eig_inv) + # # if self.options.coords != "ZMAT": + # # self.F = np.dot(self.TED_obj.proj, np.dot(self.F, self.TED_obj.proj.T)) + # # cart_conv = FcConv( + # # self.F, + # # s_vec, + # # self.zmat_obj, + # # "cartesian", + # # True, + # # self.TED_obj, + # # self.options.units, + # # ) + # # cart_conv.run() + + # t2 = time.time() + # print("Frequency Shift (cm^-1): ") + # print(final_GF.freq - init_GF.freq) + # print("This program took " + str(t2 - t1) + " seconds to run.") + + # print("////////////////////////////////////////////") + # print("//{:^40s}//".format(" END OF LOOP")) + # print("////////////////////////////////////////////") print("////////////////////////////////////////////") print("//{:^40s}//".format("Begin Selective Diagnostic Benchmark")) @@ -632,17 +660,6 @@ def run(self): algo.run() print("printing algo indices", algo.indices) diagnostic_indices = algo.indices - # with open("L_full.npy", "rb") as w: - # L_full = np.load(w) - # with open("L_0.npy", "rb") as x: - # L_0 = np.load(x) - - # L_inv = LA.inv(L_full) - # S = np.dot(L_inv, L_0) - # print("printing overlap") - # print(S) - # with open("S.npy", "wb") as y: - # np.save(y, S) self.options.mode_coupling_check = False algo = Algorithm(eigs, initial_fc, self.options) algo.run() @@ -676,8 +693,6 @@ def run(self): print("//{:^40s}//".format(" Final TED")) print("////////////////////////////////////////////") self.TED_obj.run(np.dot(init_GF.L, final_GF.L), final_GF.freq) - # if self.options.clean_house: - # os.system("rm L_full.npy") # This code prints out the frequencies in order of energy as well # as the ZPVE in several different units. @@ -690,10 +705,3 @@ def run(self): + "{:6.2f}".format(0.5 * np.sum(final_GF.freq) / 219474.6313708) + " (hartrees) " ) - # if self.options.clean_house: - # os.system("rm L_0.npy L_full.npy S.npy Full_fc_levelB.npy") - # if self.options.clean_house: - # os.system("rm S_p.npy") - # path = os.getcwd() + "/L_full.npy" - # if os.path.isfile(path): - # os.system("rm L_full.npy") diff --git a/concordantmodes/directory_tree.py b/concordantmodes/directory_tree.py index 28d1acdc..9d39b717 100644 --- a/concordantmodes/directory_tree.py +++ b/concordantmodes/directory_tree.py @@ -20,13 +20,11 @@ def __init__( dir_name, deriv_level=0, ): - # self.dispSym = dispSym self.prog_name = prog_name self.zmat = zmat self.insertion_index = insertion_index self.dir_name = dir_name self.disps = disps # This should be the 'TransfDisp' object - # nate self.p_disp = p_disp self.m_disp = m_disp self.options = options @@ -34,30 +32,6 @@ def __init__( self.indices = indices self.deriv_level = deriv_level - def make_input(self, data, dispp, n_at, at, index): - space = " " - if self.prog_name == "cfour": - space = "" - if index == -1: - print( - "The user needs to specify a different value for the \ - cart_insert keyword." - ) - raise RuntimeError - else: - for i in range(int(n_at)): - data.insert( - index + i, - space - + at[i] - + "{:16.10f}".format(dispp[i][0]) - + "{:16.10f}".format(dispp[i][1]) - + "{:16.10f}".format(dispp[i][2]) - + "\n", - ) - - return data - def run(self): disp_dict = {} disp_dict["disp"] = [] @@ -72,23 +46,27 @@ def run(self): if prog_name == "molpro" or prog_name == "psi4" or prog_name == "cfour": with open(self.template, "r") as file: data = file.readlines() - # print(data) + if self.options.pert_off_diag: + with open("template_od.dat") as file: + data_od = file.readlines() else: print("Specified program not supported: " + prog_name) raise RuntimeError init = False genbas = False + ecp = False if os.path.exists(root + "/initden.dat"): init = True if os.path.exists(root + "/GENBAS"): genbas = True + if os.path.exists(root + "/ECPDATA"): + ecp = True data_buff = data.copy() - # print(os.getcwd()) + if self.options.pert_off_diag: + data_od_buff = data_od.copy() if os.path.exists(os.getcwd() + "/old" + self.dir_name): shutil.rmtree("old" + self.dir_name, ignore_errors=True) - # if os.path.exists(os.getcwd() + "/oldDisps"): - # shutil.rmtree("oldDisps", ignore_errors=True) inp = "" if self.prog_name == "cfour": inp = "ZMAT" @@ -116,6 +94,8 @@ def run(self): shutil.copy("../../initden.dat", ".") if genbas: shutil.copy("../../GENBAS", ".") + if ecp: + shutil.copy("../../ECPDATA", ".") os.chdir("..") # Not including the reference input, this function generates the directories for the displacement @@ -140,73 +120,113 @@ def run(self): # self.create_directory(direc+1,m_data) # direc += 2 + if self.options.pert_off_diag: + for index in indices: + i, j = index[0], index[1] + if i == j: + p_data = self.make_input( + data, + p_disp[i, j], + str(n_atoms), + self.zmat.atom_list, + self.insertion_index, + ) + data = data_buff.copy() + else: + p_data = self.make_input( + data_od, + p_disp[i, j], + str(n_atoms), + self.zmat.atom_list, + self.insertion_index, + ) + data_od = data_od_buff.copy() - for index in indices: - i, j = index[0], index[1] - # print(p_disp[i,j]) - # raise RuntimeError - p_data = self.make_input( - data, - p_disp[i, j], - str(n_atoms), - self.zmat.atom_list, - self.insertion_index, - ) - - # create_directory(direc,p_data) - os.mkdir(str(direc)) - os.chdir("./" + str(direc)) - with open(inp, "w") as file: - file.writelines(p_data) - data = data_buff.copy() - if init: - shutil.copy("../../initden.dat", ".") - if genbas: - shutil.copy("../../GENBAS", ".") - os.chdir("..") + os.mkdir(str(direc)) + os.chdir("./" + str(direc)) + with open(inp, "w") as file: + file.writelines(p_data) + if init: + shutil.copy("../../initden.dat", ".") + if genbas: + shutil.copy("../../GENBAS", ".") + if ecp: + shutil.copy("../../ECPDATA", ".") + os.chdir("..") + if i == j: + m_data = self.make_input( + data, + m_disp[i, j], + str(n_atoms), + self.zmat.atom_list, + self.insertion_index, + ) + data = data_buff.copy() + else: + m_data = self.make_input( + data_od, + m_disp[i, j], + str(n_atoms), + self.zmat.atom_list, + self.insertion_index, + ) + data_od = data_od_buff.copy() + os.mkdir(str(direc + 1)) + os.chdir("./" + str(direc + 1)) + with open(inp, "w") as file: + file.writelines(m_data) + if init: + shutil.copy("../../initden.dat", ".") + if genbas: + shutil.copy("../../GENBAS", ".") + if ecp: + shutil.copy("../../ECPDATA", ".") + os.chdir("..") + direc += 2 + else: + for index in indices: + i, j = index[0], index[1] + p_data = self.make_input( + data, + p_disp[i, j], + str(n_atoms), + self.zmat.atom_list, + self.insertion_index, + ) - # Don't generate a displacement if full symmetry is present - # if self.disps.disp_sym[i] and self.disps.disp_sym[j]: - # direc -= 1 - # else: - # m_data = self.make_input( - # data, - # m_disp[i, j], - # str(n_atoms), - # self.zmat.atom_list, - # self.insertion_index, - # ) - # os.mkdir(str(direc + 1)) - # os.chdir("./" + str(direc + 1)) - # with open(inp, "w") as file: - # file.writelines(m_data) - # data = data_buff.copy() - # if init: - # shutil.copy("../../initden.dat", ".") - # if genbas: - # shutil.copy("../../GENBAS", ".") - # os.chdir("..") + os.mkdir(str(direc)) + os.chdir("./" + str(direc)) + with open(inp, "w") as file: + file.writelines(p_data) + data = data_buff.copy() + if init: + shutil.copy("../../initden.dat", ".") + if genbas: + shutil.copy("../../GENBAS", ".") + if ecp: + shutil.copy("../../ECPDATA", ".") + os.chdir("..") - m_data = self.make_input( - data, - m_disp[i, j], - str(n_atoms), - self.zmat.atom_list, - self.insertion_index, - ) - os.mkdir(str(direc + 1)) - os.chdir("./" + str(direc + 1)) - with open(inp, "w") as file: - file.writelines(m_data) - data = data_buff.copy() - if init: - shutil.copy("../../initden.dat", ".") - if genbas: - shutil.copy("../../GENBAS", ".") - os.chdir("..") - # create_directory(direc+1,m_data) - # data = data_buff.copy() - direc += 2 + m_data = self.make_input( + data, + m_disp[i, j], + str(n_atoms), + self.zmat.atom_list, + self.insertion_index, + ) + os.mkdir(str(direc + 1)) + os.chdir("./" + str(direc + 1)) + with open(inp, "w") as file: + file.writelines(m_data) + data = data_buff.copy() + if init: + shutil.copy("../../initden.dat", ".") + if genbas: + shutil.copy("../../GENBAS", ".") + if ecp: + shutil.copy("../../ECPDATA", ".") + os.chdir("..") + direc += 2 elif self.deriv_level == 1: direc = 1 for index in self.indices: @@ -218,7 +238,6 @@ def run(self): self.insertion_index, ) - # create_directory(direc,p_data) os.mkdir(str(direc)) os.chdir("./" + str(direc)) with open(inp, "w") as file: @@ -228,28 +247,10 @@ def run(self): shutil.copy("../../initden.dat", ".") if genbas: shutil.copy("../../GENBAS", ".") + if ecp: + shutil.copy("../../ECPDATA", ".") os.chdir("..") - # if self.disps.disp_sym[i] and self.disps.disp_sym[j]: - # direc -= 1 - # else: - # m_data = self.make_input( - # data, - # self.m_disp[index], - # str(n_atoms), - # self.zmat.atom_list, - # self.insertion_index, - # ) - # os.mkdir(str(direc + 1)) - # os.chdir("./" + str(direc + 1)) - # with open(inp, "w") as file: - # file.writelines(m_data) - # data = data_buff.copy() - # if init: - # shutil.copy("../../initden.dat", ".") - # if genbas: - # shutil.copy("../../GENBAS", ".") - # os.chdir("..") m_data = self.make_input( data, self.m_disp[index], @@ -266,14 +267,37 @@ def run(self): shutil.copy("../../initden.dat", ".") if genbas: shutil.copy("../../GENBAS", ".") + if ecp: + shutil.copy("../../ECPDATA", ".") os.chdir("..") - # create_directory(direc+1,m_data) - # data = data_buff.copy() direc += 2 - # raise RuntimeError else: print( "Only energy and gradient derivatives are supported. Check your deriv_level keyword." ) raise RuntimeError + + def make_input(self, data, dispp, n_at, at, index): + space = " " + if self.prog_name == "cfour": + space = "" + if index == -1: + print( + "The user needs to specify a different value for the \ + cart_insert keyword." + ) + raise RuntimeError + else: + for i in range(int(n_at)): + data.insert( + index + i, + space + + at[i] + + "{:16.10f}".format(dispp[i][0]) + + "{:16.10f}".format(dispp[i][1]) + + "{:16.10f}".format(dispp[i][2]) + + "\n", + ) + + return data diff --git a/concordantmodes/f_convert.py b/concordantmodes/f_convert.py index 79cf22e8..6a436ef2 100644 --- a/concordantmodes/f_convert.py +++ b/concordantmodes/f_convert.py @@ -16,18 +16,21 @@ class FcConv(object): BOHR_ANG: Standard uncertainty of 0.00000000080 """ - def __init__(self, F, s_vec, zmat, coord, print_f, ted, units): + def __init__(self, fc_mat, s_vec, zmat, coord, print_f, ted, units, second_order): self.coord = coord - self.F = F + # self.F_read = F_read + self.F = fc_mat + self.second_order = second_order self.print_f = print_f self.s_vec = s_vec self.ted = ted self.units = units self.zmat = zmat + self.MDYNE_HART = 4.3597447222071 self.BOHR_ANG = 0.529177210903 - def run(self): + def run(self, grad=np.array([])): # First construct the transpose of the A matrix. if self.coord.lower() == "internal": # The cartesian force constants must be in units of Hartree/bohr^2. @@ -39,12 +42,42 @@ def run(self): if self.units == "MdyneAng": self.F /= self.BOHR_ANG self.F *= self.MDYNE_HART - self.F = np.einsum("ia,jb,ab->ij", self.A_T, self.A_T, self.F) + print(self.A_T.shape) + print(self.F.shape) + self.F = np.einsum("pi,rj,ij->pr", self.A_T, self.A_T, self.F) + + # Non-stationary, gradient correction to internal coordinate force constants + V2 = self.F.copy() * 0 + if len(grad) and self.second_order: + # Note: I may want to use projected A_T to reduce the size of the + # internal coordinate basis, thus speeding up the computation. + # The basis will eventually need to be projected anyways. + print("grad:") + print(grad.shape) + print(grad) + print("AT:") + print(self.A_T.shape) + print(self.A_T) + v_q = np.dot(self.A_T, grad) + print("v_q:") + print(v_q.shape) + print(v_q) + print("B2:") + print(self.s_vec.B2.shape) + print(self.s_vec.B2) + C2 = np.einsum("rij,pi,qj->rpq", self.s_vec.B2, self.A_T, self.A_T) + print("C2:") + print(C2.shape) + print(C2) + V2 = np.einsum("q,qpr->pr", v_q, C2) + + self.F = self.F - V2 + if self.print_f: self.N = len(G) self.print_const() elif self.coord.lower() == "cartesian": - self.F = np.einsum("ai,bj,ab->ij", self.s_vec.B, self.s_vec.B, self.F) + self.F = np.einsum("pi,rj,pr->ij", self.s_vec.B, self.s_vec.B, self.F) if self.print_f: self.N = len(self.zmat.atom_list) * 3 self.print_const() diff --git a/concordantmodes/force_constant.py b/concordantmodes/force_constant.py index cff40ec3..0f053349 100644 --- a/concordantmodes/force_constant.py +++ b/concordantmodes/force_constant.py @@ -44,17 +44,29 @@ def run(self): e_pp, e_mm = p_en_array[i, j], m_en_array[i, j] if i == j: self.FC[i, i] = self.diag_fc(e_pi, e_mi, e_r, disp.disp[i]) + # print("DIAG DISP:") + # print(disp.disp[i]) elif i != j: self.FC[i, j] = self.off_diag_fc( - e_pp, e_pi, e_pj, e_mi, e_mj, e_mm, e_r, disp.disp[i] + e_pp, + e_pi, + e_pj, + e_mi, + e_mj, + e_mm, + e_r, + disp.disp[i], + disp.disp[j], ) + # print("OFF-DIAG DISPS:") + # print(disp.disp[i]) + # print(disp.disp[j]) # Take advantage of FC[i,j] = FC[j,i] cf = np.triu_indices(a, 1) il = (cf[1], cf[0]) self.FC[il] = self.FC[cf] elif self.deriv_level == 1: self.FC = (self.p_array - self.m_array) / (2 * self.disp.disp[0]) - # raise RuntimeError else: print("Higher order deriv_level computations aren't yet supported") raise RuntimeError @@ -65,9 +77,9 @@ def first_deriv(self): # Functions for computing the diagonal and off-diagonal force constants def diag_fc(self, e_p, e_m, e_r, disp): - fc = (e_p - 2 * e_r + e_m) / (disp**2) + fc = (e_p - 2 * e_r + e_m) / (disp ** 2) return fc - def off_diag_fc(self, e_pp, e_pi, e_pj, e_mi, e_mj, e_mm, e_r, disp): - fc = (e_pp - e_pi - e_pj + 2 * e_r - e_mi - e_mj + e_mm) / (2 * (disp**2)) + def off_diag_fc(self, e_pp, e_pi, e_pj, e_mi, e_mj, e_mm, e_r, disp1, disp2): + fc = (e_pp - e_pi - e_pj + 2 * e_r - e_mi - e_mj + e_mm) / (2 * disp1 * disp2) return fc diff --git a/concordantmodes/g_matrix.py b/concordantmodes/g_matrix.py index 8418d96a..f9d6c991 100644 --- a/concordantmodes/g_matrix.py +++ b/concordantmodes/g_matrix.py @@ -28,6 +28,5 @@ def run(self): u[i] = 1.0 / u[i] u = np.repeat(u, 3) u = np.diag(u) - # u = inv(u) self.G = B.dot(u.dot(B.T)) self.G[np.abs(self.G) < tol] = 0 diff --git a/concordantmodes/g_read.py b/concordantmodes/g_read.py new file mode 100644 index 00000000..ce0a2630 --- /dev/null +++ b/concordantmodes/g_read.py @@ -0,0 +1,22 @@ +import numpy as np +import re +from numpy.linalg import inv +from numpy import linalg as LA + + +class GrRead(object): + """ + This class may be used to read in force constant information from the + standard 3-column formatted file. Idk what that format is called, but + it's pretty standard. + """ + + def __init__(self, file_name): + self.file_name = file_name + self.grad_regex = re.compile(r"(-?\d+\.\d+)") + + def run(self, cartesians): + with open(self.file_name, "r") as file: + grad = file.read() + self.grad = re.findall(self.grad_regex, grad) + self.cart_grad = np.array(self.grad).astype(float)[-len(cartesians.flatten()) :] diff --git a/concordantmodes/gf_method.py b/concordantmodes/gf_method.py index cc090766..936ef24c 100644 --- a/concordantmodes/gf_method.py +++ b/concordantmodes/gf_method.py @@ -34,21 +34,7 @@ def run(self): self.L = np.real(self.L) L = np.absolute(self.L) L_p = np.real(self.L_p) - # S_p = np.dot(np.absolute(LA.inv(L_p)), np.absolute(L_p)) self.L_p = L_p - # make sure the correct "primed" or unprimed version is being saved in each instance - # if self.cma: - # with open("L_full.npy", "wb") as z: - # np.save(z, L) - # # if self.cma == False: - # # with open("L_intermediate.npy", "wb") as z: - # # np.save(z, L) - # if self.cma is None: - # with open("L_0.npy", "wb") as z: - # np.save(z, L) - # if self.cma == "init": - # with open("S_p.npy", "wb") as z: - # np.save(z, S_p) # Construct the normal mode overlap matrix. Will be useful for off-diagonal diagnostics. L = np.absolute(np.real(self.L)) L_inv = LA.inv(L) @@ -65,11 +51,10 @@ def run(self): else: self.freq[i] = -np.imag(self.freq[i]) - # # This seems to fix the constant warning I get about casting out imaginary values from the complex numbers, - # # however I will need to test it on transition states to see if it captures the imaginary frequencies. - # self.freq = np.real(self.freq) - # print(self.freq) + # This seems to fix the constant warning I get about casting out imaginary values from the complex numbers, + # however I will need to test it on transition states to see if it captures the imaginary frequencies. self.freq = self.freq.astype(float) + # Convert from Hartrees to wavenumbers. self.freq *= self.HARTREE_WAVENUM for i in range(len(self.freq)): @@ -80,7 +65,6 @@ def run(self): + "{:10.2f}".format(self.freq[i]) ) # Compute and then print the TED. - # np.set_printoptions(suppress=True) print("////////////////////////////////////////////") print("//{:^40s}//".format("Total Energy Distribution (TED)")) print("////////////////////////////////////////////") diff --git a/concordantmodes/int2cart.py b/concordantmodes/int2cart.py index 1da99036..cdf23837 100644 --- a/concordantmodes/int2cart.py +++ b/concordantmodes/int2cart.py @@ -4,7 +4,7 @@ class Int2Cart(object): - def __init__(self, zmat, var_dict): + def __init__(self, zmat, var_dict=None): self.zmat = zmat self.var_dict = var_dict self.masses = [masses.get_mass(label) for label in zmat.atom_list] diff --git a/concordantmodes/molden_template.py b/concordantmodes/molden_template.py new file mode 100644 index 00000000..43003286 --- /dev/null +++ b/concordantmodes/molden_template.py @@ -0,0 +1,10 @@ +molden_template = """[Molden Format] +[ATOMS] AU +{geometry} +[Molden Format] + [FREQ] +{frequencies} + [FR-COORD] +{fr_geom} + [FR-NORM-COORD] +{normal_modes}""" diff --git a/concordantmodes/molden_writer.py b/concordantmodes/molden_writer.py new file mode 100644 index 00000000..b6a928f1 --- /dev/null +++ b/concordantmodes/molden_writer.py @@ -0,0 +1,75 @@ +from concordantmodes.molden_template import molden_template +import numpy as np +import json +import os +import qcelemental as qcel +import re +import shutil + + +class MoldenWriter(object): + def __init__( + self, + zmat, + disps, + freq, + # prog_name, + ): + # self.prog_name = prog_name + self.zmat = zmat + self.disps = disps + self.freq = freq + + def run(self): + geometry = "" + atom_num = np.array([]) + for i in self.zmat.atom_list: + atom_num = np.append(atom_num, int(qcel.periodictable.to_atomic_number(i))) + + for i in range(len(self.zmat.cartesians_final)): + geometry += "{:2<}{:>9}{:>5}{:-20.10f}{:-20.10f}{:-20.10f}\n".format( + self.zmat.atom_list[i], + str(i + 1), + str(int(atom_num[i])), + self.zmat.cartesians_final[i][0], + self.zmat.cartesians_final[i][1], + self.zmat.cartesians_final[i][2], + ) + + frequencies = "" + for i in self.freq: + frequencies += "{:-20.10f}\n".format(i) + + fr_geom = "" + + for i in range(len(self.zmat.cartesians_final)): + fr_geom += "{:<5}{:-20.10f}{:-20.10f}{:-20.10f}\n".format( + self.zmat.atom_list[i], + self.zmat.cartesians_final[i][0], + self.zmat.cartesians_final[i][1], + self.zmat.cartesians_final[i][2], + ) + + normal_modes = "" + for i in range(len(self.disps.p_disp)): + normal_modes += " vibration{:>23}\n".format(str(i + 1)) + disp = self.disps.p_disp[i, i] - self.zmat.cartesians_final + disp *= 30 + for j in range(len(disp)): + normal_modes += "{:-20.10f}{:-20.10f}{:-20.10f}\n".format( + disp[j][0], disp[j][1], disp[j][2] + ) + + molden_template = """[Molden Format]\n[ATOMS] AU\n{geometry}[Molden Format]\n [FREQ]\n{frequencies} [FR-COORD]\n{fr_geom} [FR-NORM-COORD]\n{normal_modes}""" + inout = { + "geometry": geometry, + "frequencies": frequencies, + "fr_geom": fr_geom, + "normal_modes": normal_modes, + } + molden_template = molden_template.format(**inout) + + # print(molden_template) + with open("MOLDEN", "w+") as file: + file.write(molden_template) + pass diff --git a/concordantmodes/options.py b/concordantmodes/options.py index eb1b53bc..42583610 100644 --- a/concordantmodes/options.py +++ b/concordantmodes/options.py @@ -18,11 +18,13 @@ def __init__(self, **kwargs): self.disp_check = kwargs.pop("disp_check", False) self.disp_tol = kwargs.pop("disp_tol", 0.0001) self.energy_regex = kwargs.pop("energy_regex", "") + self.energy_regex_add = kwargs.pop("energy_regex_add", []) self.energy_regex_init = kwargs.pop("energy_regex_init", "") self.gen_disps = kwargs.pop("gen_disps", True) self.gen_disps_init = kwargs.pop("gen_disps_init", True) self.geom_check = kwargs.pop("geom_check", False) self.gradient_regex = kwargs.pop("gradient_regex", "") + self.init_bool = kwargs.pop("init_bool", False) self.man_proj = kwargs.pop("man_proj", False) self.mode_coupling_check = kwargs.pop("mode_coupling_check", False) self.molly_regex_init = kwargs.pop("molly_regex_init", "") @@ -30,6 +32,7 @@ def __init__(self, **kwargs): self.off_diag = kwargs.pop("off_diag", False) self.off_diag_bands = kwargs.pop("off_diag_bands", 1) self.off_diag_limit = kwargs.pop("off_diag_limit", False) + self.pert_off_diag = kwargs.pop("pert_off_diag", False) self.printout_rel_e = kwargs.pop("printout_rel_e", True) self.program = kwargs.pop("program", "molpro@2010.1.67+mpi") self.program_init = kwargs.pop("program_init", "molpro@2010.1.67+mpi") diff --git a/concordantmodes/reap.py b/concordantmodes/reap.py index d62c5a93..34fcaa2e 100644 --- a/concordantmodes/reap.py +++ b/concordantmodes/reap.py @@ -17,7 +17,6 @@ def __init__( indices, energy_regex, gradient_regex, - molly_regex, success_regex, deriv_level=0, disp_sym=None, @@ -27,12 +26,9 @@ def __init__( self.disp_cart = disp_cart self.options = options self.n_coord = n_coord - # self.disp_sym =disp_sym - # nate self.eigs = eigs self.energy_regex = energy_regex self.gradient_regex = gradient_regex - self.molly_regex = molly_regex self.success_regex = success_regex self.indices = indices self.deriv_level = deriv_level @@ -46,14 +42,11 @@ def run(self): else: grad_regex1 = re.compile(self.gradient_regex[0]) grad_regex2 = re.compile(self.gradient_regex[1]) - # molly_regex1 = re.compile(self.molly_regex[0]) - # molly_regex2 = re.compile(self.molly_regex[1]) eigs = self.eigs if type(eigs) == int: size = eigs else: size = len(eigs) - # n_disp = len(self.disp_cart) if not self.deriv_level: print( @@ -61,7 +54,6 @@ def run(self): ) print("(Job number 1 == Reference energy) :D") print(os.getcwd()) - # self.options.dir_reap = True if self.options.dir_reap: os.chdir("./" + str(1)) with open("output.dat", "r") as file: @@ -77,12 +69,25 @@ def run(self): print("Energy failed at " + str("ref")) raise RuntimeError + # ref_en = float(re.findall(re.compile(self.options.energy_regex_add[-1]), data)[0]) ref_en = float(re.findall(energy_regex, data)[0]) print("Reference energy: " + str(ref_en)) + if len(self.options.energy_regex_add) and not self.options.init_bool: + energy_add = np.array([]) + for i in range(len(self.options.energy_regex_add)): + energy_add = np.append( + energy_add, + float(re.findall(self.options.energy_regex_add[i], data)[0]), + ) + np.set_printoptions(precision=8, linewidth=120) + + # energy_add = np.append(energy_add,ref_en) + energy_add -= energy_add[0] + energy_add = energy_add[1:] + self.energy_add_total = np.array([energy_add]) + # print(self.energy_add_total) indices = self.indices - # eigs = self.eigs - # eigs = len(eigs) p_en_array = np.zeros((size, size)) m_en_array = np.zeros((size, size)) rel_en_p = np.zeros((size, size)) @@ -93,56 +98,101 @@ def run(self): direc = 2 for index in indices: i, j = index[0], index[1] - p_en_array[i, j] = energy = self.reap_energies( - direc, success_regex, energy_regex - ) - # print(energy) - rel = energy - ref_en - print( - "Relative plus " - + "{:4d}".format(direc) - + "{:4d}".format(i) - + " " - + "{:4d}".format(j) - + ": " - + "{: 10.9f}".format(rel) - ) - rel_en_p[i, j] = rel - relative_energies.append([(i, j), "plus", rel, direc]) - absolute_energies.append([(i, j), "plus", energy, direc]) + # if i == j or self.options.init_bool: + if self.options.init_bool: + p_en_array[i, j] = energy = self.reap_energies( + direc, + success_regex, + energy_regex, + True + # direc, success_regex, re.compile(self.options.energy_regex_add[-1]), True + ) + # print(energy) + rel = energy - ref_en + print( + "Relative plus " + + "{:4d}".format(direc) + + "{:4d}".format(i) + + " " + + "{:4d}".format(j) + + ": " + + "{: 10.9f}".format(rel) + ) + rel_en_p[i, j] = rel + relative_energies.append([(i, j), "plus", rel, direc]) + absolute_energies.append([(i, j), "plus", energy, direc]) - # if self.disp_sym[i] and self.disp_sym[j]: - # direc -= 1 - # m_en_array[i, j] = energy = p_en_array[i, j] - # else: - # m_en_array[i, j] = energy = self.reap_energies( - # direc + 1, success_regex, energy_regex - # ) - # print(energy) - m_en_array[i, j] = energy = self.reap_energies( - direc + 1, success_regex, energy_regex - ) - # print(energy) - rel = energy - ref_en - # print("Relative minus " + str(i) + " " + str(j) + ": " + "{:10.6f}".format(rel)) - print( - "Relative minus " - + "{:4d}".format(direc + 1) - + "{:4d}".format(i) - + " " - + "{:4d}".format(j) - + ": " - + "{: 10.9f}".format(rel) - ) - rel_en_m[i, j] = rel - relative_energies.append([(i, j), "minus", rel, direc + 1]) - absolute_energies.append([(i, j), "minus", energy, direc + 1]) - direc += 2 + m_en_array[i, j] = energy = self.reap_energies( + direc + 1, + success_regex, + energy_regex, + True + # direc + 1, success_regex, re.compile(self.options.energy_regex_add[-1]), True + ) + rel = energy - ref_en + print( + "Relative minus " + + "{:4d}".format(direc + 1) + + "{:4d}".format(i) + + " " + + "{:4d}".format(j) + + ": " + + "{: 10.9f}".format(rel) + ) + rel_en_m[i, j] = rel + relative_energies.append([(i, j), "minus", rel, direc + 1]) + absolute_energies.append([(i, j), "minus", energy, direc + 1]) + direc += 2 + elif len(self.options.energy_regex_add): + p_en_array[i, j] = self.reap_energies( + direc, + success_regex, + energy_regex, + True + # direc, success_regex, energy_regex, False + ) + m_en_array[i, j] = self.reap_energies( + direc + 1, + success_regex, + energy_regex, + True + # direc + 1, success_regex, energy_regex, False + ) + direc += 2 + else: + p_en_array[i, j] = self.reap_energies( + direc, success_regex, energy_regex, False + ) + m_en_array[i, j] = energy = self.reap_energies( + direc + 1, success_regex, energy_regex, False + ) + direc += 2 + # if len(self.options.energy_regex_add) and not self.options.init_bool: + # self.energy_add_total = self.energy_add_total[1:] + # # print("P_array:") + # # print(p_en_array) + # # print("M_array:") + # # print(m_en_array) + # # print("energy_add_total: ") + # # print(len(self.energy_add_total)) + # # print(self.energy_add_total) + # # print(p_en_array) + # for i in range(len(p_en_array)): + # for j in range(len(p_en_array) - i - 1): + # # print(i) + # # print(i+j+1) + # k = i + j + 1 + # print(np.sqrt(self.energy_add_total[2*i][0]*self.energy_add_total[2*k][0])) + # p_en_array[i,k] -= np.sqrt(self.energy_add_total[2*i][0]*self.energy_add_total[2*k][0]) + # m_en_array[i,k] -= np.sqrt(self.energy_add_total[2*i+1][0]*self.energy_add_total[2*k+1][0]) + # # print(np.sqrt(self.energy_add_total[2*i][0]*self.energy_add_total[2*k][0])) + # # print(np.sqrt(self.energy_add_total[2*i+1][0]*self.energy_add_total[2*k+1][0])) + # # print(p_en_array) + # # raise RuntimeError self.p_en_array = p_en_array self.m_en_array = m_en_array self.ref_en = ref_en - # print_en = np.insert(absolute_energies,0,[("ref", "ref"), "ref", ref_en, 1],axis=0) print_en = absolute_energies np.set_printoptions(precision=2, linewidth=120) print( @@ -154,34 +204,16 @@ def run(self): ) print(rel_en_m) os.chdir("..") - # if self.options.printout_rel_e: - # auxiliary = "" - # header = "Index, relative energy, directory \n" - # print(json.dumps(energy)) - # with open("auxiliary", "a") as file: - # file.seek(0) - # file.truncate() - # file.writelines(header) - # for energy in print_en: - # with open("auxiliary", "a") as file: - # file.writelines(str(energy) + "\n") else: indices = self.indices p_grad_array = np.array([]) m_grad_array = np.array([]) Sum = 0 - # print(indices) for index in indices: grad = self.reap_gradients( 2 * index + 1 - Sum, grad_regex1, grad_regex2 ) p_grad_array = np.append(p_grad_array, grad, axis=0) - # if self.disp.disp_sym[i]: - # m_grad_array = np.append(m_grad_array, -grad, axis=0) - # Sum += 1 - # else: - # grad = self.reap_gradients(2 * index + 2 - Sum, grad_regex1, grad_regex2) - # m_grad_array = np.append(m_grad_array, grad, axis=0) grad = self.reap_gradients( 2 * index + 2 - Sum, grad_regex1, grad_regex2 ) @@ -246,7 +278,7 @@ def reap_molly(self, direc, molly1_regex, molly2_regex): os.chdir("..") return rearrange, insertion - def reap_energies(self, direc, success_regex, energy_regex): + def reap_energies(self, direc, success_regex, energy_regex, diag): if self.options.dir_reap: os.chdir("./" + str(direc)) with open("output.dat", "r") as file: @@ -255,7 +287,31 @@ def reap_energies(self, direc, success_regex, energy_regex): print("Energy failed at " + os.getcwd()) raise RuntimeError energy = float(re.findall(energy_regex, data)[0]) + if ( + len(self.options.energy_regex_add) + and not self.options.init_bool + and diag + ): + energy_add = [] + for i in range(len(self.options.energy_regex_add)): + energy_add = np.append( + energy_add, + float(re.findall(self.options.energy_regex_add[i], data)[0]), + ) + print("Multi energy check:") + print(self.options.energy_regex_add) + print(energy_add) + np.set_printoptions(precision=8, linewidth=120) + # energy_add = np.append(energy_add,energy) + energy_add -= energy_add[0] + # print(energy_add) + energy_add = energy_add[1:] + # print(energy_add) + + self.energy_add_total = np.append( + self.energy_add_total, [energy_add], axis=0 + ) os.chdir("..") else: with open("output." + str(direc) + ".dat", "r") as file: @@ -267,7 +323,6 @@ def reap_energies(self, direc, success_regex, energy_regex): return energy - # def reap_gradients(self, direc, grad_regex1, grad_regex2, shuffle,insertion): def reap_gradients(self, direc, grad_regex1, grad_regex2): os.chdir("./" + str(direc)) grad_array = [] @@ -290,18 +345,10 @@ def reap_gradients(self, direc, grad_regex1, grad_regex2): grad_array.append(temp) grad_array = np.array(grad_array) grad_array = grad_array.astype("float64") - # grad_array = grad_array[shuffle] - # if len(insertion) > 0: - # counter = 0 - # for x in insertion: - # grad_array = np.insert(grad_array, x, [0.0, 0.0, 0.0], axis = 0) - # counter += 1 - # grad_array = np.reshape(grad_array, (-1, 3)) grad_array = grad_array.flatten() if not grad1: print("Gradient failed at " + os.getcwd()) raise RuntimeError os.chdir("..") - # raise RuntimeError return grad_array diff --git a/concordantmodes/rmsd.py b/concordantmodes/rmsd.py index 2aa160fa..8b7f58be 100644 --- a/concordantmodes/rmsd.py +++ b/concordantmodes/rmsd.py @@ -166,24 +166,24 @@ def handwritten_hess(self, mol1, mol2, n): * ( -K3 * A * B + K2 * A * G - + K2 * B * np.sqrt(1 - A**2 - B**2 - G**2) - + K3 * G * np.sqrt(1 - A**2 - B**2 - G**2) + + K2 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + K3 * G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) ) + c2 * ( K1 * A * G - + 2 * K2 * A * np.sqrt(1 - A**2 - B**2 - G**2) - - K1 * B * np.sqrt(1 - A**2 - B**2 - G**2) - - K3 * (-1 + 2 * A**2 + B**2 + G**2) + + 2 * K2 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + - K1 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + - K3 * (-1 + 2 * A ** 2 + B ** 2 + G ** 2) ) + c3 * ( - 2 * K3 * A * np.sqrt(1 - A**2 - B**2 - G**2) - + K2 * (-1 + 2 * A**2 + B**2 + G**2) - - K1 * (A * B + G * np.sqrt(1 - A**2 - B**2 - G**2)) + 2 * K3 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + K2 * (-1 + 2 * A ** 2 + B ** 2 + G ** 2) + - K1 * (A * B + G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2)) ) ) - ) / np.sqrt(1 - A**2 - B**2 - G**2) + ) / np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) grad1 += -( 4 @@ -192,25 +192,25 @@ def handwritten_hess(self, mol1, mol2, n): * ( K3 * A * B - K1 * B * G - + K1 * A * np.sqrt(1 - A**2 - B**2 - G**2) - + K3 * G * np.sqrt(1 - A**2 - B**2 - G**2) + + K1 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + K3 * G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) ) + c3 * ( -K2 * A * B - - 2 * K3 * B * np.sqrt(1 - A**2 - B**2 - G**2) - + K2 * G * np.sqrt(1 - A**2 - B**2 - G**2) - + K1 * (-1 + 2 * A**2 + B**2 + G**2) + - 2 * K3 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + K2 * G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + K1 * (-1 + 2 * A ** 2 + B ** 2 + G ** 2) ) + c1 * ( K2 * B * G - + K2 * A * np.sqrt(1 - A**2 - B**2 - G**2) - - 2 * K1 * B * np.sqrt(1 - A**2 - B**2 - G**2) - - K3 * (-1 + A**2 - 2 * B**2 + G**2) + + K2 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + - 2 * K1 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + - K3 * (-1 + A ** 2 - 2 * B ** 2 + G ** 2) ) ) - ) / np.sqrt(1 - A**2 - B**2 - G**2) + ) / np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) grad2 += -( 4 @@ -219,180 +219,180 @@ def handwritten_hess(self, mol1, mol2, n): * ( -K2 * A * G + K1 * B * G - + K1 * A * np.sqrt(1 - A**2 - B**2 - G**2) - + K2 * B * np.sqrt(1 - A**2 - B**2 - G**2) + + K1 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + K2 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) ) + c2 * ( K3 * A * G - + K3 * B * np.sqrt(1 - A**2 - B**2 - G**2) - - 2 * K2 * G * np.sqrt(1 - A**2 - B**2 - G**2) - - K1 * (-1 + A**2 + B**2 + 2 * G**2) + + K3 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + - 2 * K2 * G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + - K1 * (-1 + A ** 2 + B ** 2 + 2 * G ** 2) ) + c1 * ( -K3 * B * G - + K3 * A * np.sqrt(1 - A**2 - B**2 - G**2) - - 2 * K1 * G * np.sqrt(1 - A**2 - B**2 - G**2) - + K2 * (-1 + A**2 + B**2 + 2 * G**2) + + K3 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + - 2 * K1 * G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + K2 * (-1 + A ** 2 + B ** 2 + 2 * G ** 2) ) ) - ) / np.sqrt(1 - A**2 - B**2 - G**2) + ) / np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) hess00 += -( ( 4 * ( - c1 * (K3 * B - K2 * G) * (-1 + B**2 + G**2) + c1 * (K3 * B - K2 * G) * (-1 + B ** 2 + G ** 2) + c3 * ( - 2 * K2 * A**3 - - 2 * K3 * (1 - A**2 - B**2 - G**2) ** (3 / 2) - + 3 * K2 * A * (-1 + B**2 + G**2) - - K1 * B * (-1 + B**2 + G**2) + 2 * K2 * A ** 3 + - 2 * K3 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + + 3 * K2 * A * (-1 + B ** 2 + G ** 2) + - K1 * B * (-1 + B ** 2 + G ** 2) ) + c2 * ( - -2 * K3 * A**3 - - 2 * K2 * (1 - A**2 - B**2 - G**2) ** (3 / 2) - - 3 * K3 * A * (-1 + B**2 + G**2) - + K1 * G * (-1 + B**2 + G**2) + -2 * K3 * A ** 3 + - 2 * K2 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + - 3 * K3 * A * (-1 + B ** 2 + G ** 2) + + K1 * G * (-1 + B ** 2 + G ** 2) ) ) ) - / (1 - A**2 - B**2 - G**2) ** (3 / 2) + / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) ) hess01 += ( 4 * ( - -c1 * K3 * A * (-1 + A**2 + G**2) - + c2 * K3 * B * (-1 + B**2 + G**2) + -c1 * K3 * A * (-1 + A ** 2 + G ** 2) + + c2 * K3 * B * (-1 + B ** 2 + G ** 2) + c3 * ( - K1 * A * (-1 + A**2 + G**2) - - K2 * B * (-1 + B**2 + G**2) + K1 * A * (-1 + A ** 2 + G ** 2) + - K2 * B * (-1 + B ** 2 + G ** 2) ) + c1 * K2 * ( -A * B * G - + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) - + np.sqrt(1 - A**2 - B**2 - G**2) - * (-1 + B**2 + G**2) + + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + * (-1 + B ** 2 + G ** 2) ) + c2 * K1 * ( A * B * G - + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) - + np.sqrt(1 - A**2 - B**2 - G**2) - * (-1 + B**2 + G**2) + + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + * (-1 + B ** 2 + G ** 2) ) ) - ) / (1 - A**2 - B**2 - G**2) ** (3 / 2) + ) / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) hess02 += ( 4 * ( - c1 * K2 * A * (-1 + A**2 + B**2) - - c3 * K2 * G * (-1 + B**2 + G**2) + c1 * K2 * A * (-1 + A ** 2 + B ** 2) + - c3 * K2 * G * (-1 + B ** 2 + G ** 2) + c2 * ( - -K1 * A * (-1 + A**2 + B**2) - - K3 * G * (-1 + B**2 + G**2) + -K1 * A * (-1 + A ** 2 + B ** 2) + - K3 * G * (-1 + B ** 2 + G ** 2) ) + c3 * K1 * ( -A * B * G - + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) - + np.sqrt(1 - A**2 - B**2 - G**2) - * (-1 + B**2 + G**2) + + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + * (-1 + B ** 2 + G ** 2) ) + c1 * K3 * ( A * B * G - + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) - + np.sqrt(1 - A**2 - B**2 - G**2) - * (-1 + B**2 + G**2) + + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + * (-1 + B ** 2 + G ** 2) ) ) - ) / (1 - A**2 - B**2 - G**2) ** (3 / 2) + ) / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) hess11 += -( ( 4 * ( - -c2 * (K3 * A - K1 * G) * (-1 + A**2 + G**2) + -c2 * (K3 * A - K1 * G) * (-1 + A ** 2 + G ** 2) + c3 * ( - -2 * K3 * (1 - A**2 - B**2 - G**2) ** (3 / 2) - + K2 * A * (-1 + A**2 + G**2) - - K1 * B * (-3 + 3 * A**2 + 2 * B**2 + 3 * G**2) + -2 * K3 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + + K2 * A * (-1 + A ** 2 + G ** 2) + - K1 * B * (-3 + 3 * A ** 2 + 2 * B ** 2 + 3 * G ** 2) ) + c1 * ( - -2 * K1 * (1 - A**2 - B**2 - G**2) ** (3 / 2) - - K2 * G * (-1 + A**2 + G**2) - + K3 * B * (-3 + 3 * A**2 + 2 * B**2 + 3 * G**2) + -2 * K1 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + - K2 * G * (-1 + A ** 2 + G ** 2) + + K3 * B * (-3 + 3 * A ** 2 + 2 * B ** 2 + 3 * G ** 2) ) ) ) - / (1 - A**2 - B**2 - G**2) ** (3 / 2) + / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) ) hess12 += ( 4 * ( - c1 * K2 * B * (-1 + A**2 + B**2) - + c3 * K1 * G * (-1 + A**2 + G**2) - - c1 * K3 * G * (-1 + A**2 + G**2) + c1 * K2 * B * (-1 + A ** 2 + B ** 2) + + c3 * K1 * G * (-1 + A ** 2 + G ** 2) + - c1 * K3 * G * (-1 + A ** 2 + G ** 2) + c3 * K2 * ( A * B * G - + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) - + np.sqrt(1 - A**2 - B**2 - G**2) - * (-1 + B**2 + G**2) + + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + * (-1 + B ** 2 + G ** 2) ) + c2 * ( - -K1 * B * (-1 + A**2 + B**2) + -K1 * B * (-1 + A ** 2 + B ** 2) + K3 * ( -A * B * G - + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) - + np.sqrt(1 - A**2 - B**2 - G**2) - * (-1 + B**2 + G**2) + + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + * (-1 + B ** 2 + G ** 2) ) ) ) - ) / (1 - A**2 - B**2 - G**2) ** (3 / 2) + ) / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) hess22 += -( ( 4 * ( - c3 * (K2 * A - K1 * B) * (-1 + A**2 + B**2) + c3 * (K2 * A - K1 * B) * (-1 + A ** 2 + B ** 2) + c1 * ( - K3 * B * (-1 + A**2 + B**2) - - 3 * K2 * (-1 + A**2 + B**2) * G - - 2 * K2 * G**3 - - 2 * K1 * (1 - A**2 - B**2 - G**2) ** (3 / 2) + K3 * B * (-1 + A ** 2 + B ** 2) + - 3 * K2 * (-1 + A ** 2 + B ** 2) * G + - 2 * K2 * G ** 3 + - 2 * K1 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) ) + c2 * ( - -K3 * A * (-1 + A**2 + B**2) - + 3 * K1 * (-1 + A**2 + B**2) * G - + 2 * K1 * G**3 - - 2 * K2 * (1 - A**2 - B**2 - G**2) ** (3 / 2) + -K3 * A * (-1 + A ** 2 + B ** 2) + + 3 * K1 * (-1 + A ** 2 + B ** 2) * G + + 2 * K1 * G ** 3 + - 2 * K2 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) ) ) ) - / (1 - A**2 - B**2 - G**2) ** (3 / 2) + / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) ) grud = np.array([grad0, grad1, grad2]) huss = np.array( @@ -421,19 +421,19 @@ def derive_opt_rotate(self, mol1_rot, mol2_rot, n): # , oilrod): rot_matrix = np.array( [ [ - 1 - 2 * b**2 - 2 * c**2, - 2 * (a * b + c * np.sqrt(1 - a**2 - b**2 - c**2)), - 2 * (a * c - b * np.sqrt(1 - a**2 - b**2 - c**2)), + 1 - 2 * b ** 2 - 2 * c ** 2, + 2 * (a * b + c * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), + 2 * (a * c - b * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), ], [ - 2 * (a * b - c * np.sqrt(1 - a**2 - b**2 - c**2)), - 1 - 2 * a**2 - 2 * c**2, - 2 * (b * c + a * np.sqrt(1 - a**2 - b**2 - c**2)), + 2 * (a * b - c * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), + 1 - 2 * a ** 2 - 2 * c ** 2, + 2 * (b * c + a * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), ], [ - 2 * (a * c + b * np.sqrt(1 - a**2 - b**2 - c**2)), - 2 * (b * c - a * np.sqrt(1 - a**2 - b**2 - c**2)), - 1 - 2 * a**2 - 2 * b**2, + 2 * (a * c + b * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), + 2 * (b * c - a * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), + 1 - 2 * a ** 2 - 2 * b ** 2, ], ] ) diff --git a/concordantmodes/s_vectors.py b/concordantmodes/s_vectors.py index da092387..0a2acec1 100644 --- a/concordantmodes/s_vectors.py +++ b/concordantmodes/s_vectors.py @@ -2,6 +2,7 @@ import shutil import numpy as np from concordantmodes.ted import TED +from concordantmodes.int2cart import Int2Cart from numpy.linalg import inv from numpy import linalg as LA @@ -18,13 +19,14 @@ def __init__(self, zmat, options, variable_dict): self.s_2center_dict = {} self.s_3center_dict = {} self.s_4center_dict = {} - self.bond_indices = np.array(zmat.bond_indices).astype(int) - self.angle_indices = np.array(zmat.angle_indices).astype(int) - self.torsion_indices = np.array(zmat.torsion_indices).astype(int) - self.oop_indices = np.array(zmat.oop_indices).astype(int) - self.lin_indices = np.array(zmat.lin_indices).astype(int) - self.linx_indices = np.array(zmat.linx_indices).astype(int) - self.liny_indices = np.array(zmat.liny_indices).astype(int) + self.s_ncenter_dict = {} + self.bond_indices = zmat.bond_indices + self.angle_indices = zmat.angle_indices + self.torsion_indices = zmat.torsion_indices + self.oop_indices = zmat.oop_indices + self.lin_indices = zmat.lin_indices + self.linx_indices = zmat.linx_indices + self.liny_indices = zmat.liny_indices self.options = options self.variable_dict = variable_dict self.zmat = zmat @@ -33,6 +35,7 @@ def run(self, carts, B_proj, proj=None, second_order=False): self.proj = proj # Initialize the cartesian coordinates self.carts = carts + self.int2cart = Int2Cart(self.zmat) # So, first things first I'll have to code up the # proper equations for the first order B-Tensors # for: @@ -43,352 +46,420 @@ def run(self, carts, B_proj, proj=None, second_order=False): # Linear Bends # LinX Bends # LinY Bends - # Toggle this to convert from bohr to angstrom - # self.carts = 0.5291772085936*self.carts # First, bonds. if len(self.bond_indices) > 0: for i in range(len(self.bond_indices)): + indies = self.bond_indices[i] + Len = len(np.array(indies[0]).shape) + if Len: + x1 = [0.0,0.0,0.0] + for j in indies[0]: + x1 += self.carts[int(j) - 1] + x1 /= len(indies[0]) + x2 = [0.0,0.0,0.0] + for j in indies[1]: + x2 += self.carts[int(j) - 1] + x2 /= len(indies[1]) + else: + x1 = self.carts[int(indies[0]) - 1] + x2 = self.carts[int(indies[1]) - 1] + self.s_2center_dict["B" + str(i + 1)] = self.carts.copy() self.s_2center_dict["B" + str(i + 1)] = ( 0 * self.s_2center_dict["B" + str(i + 1)] ) - r = self.compute_r( - self.carts, self.bond_indices[i][0] - 1, self.bond_indices[i][1] - 1 - ) - self.s_2center_dict["B" + str(i + 1)][ - self.bond_indices[i][0] - 1 - ] = self.compute_e( - self.carts, - self.bond_indices[i][0] - 1, - self.bond_indices[i][1] - 1, - r, - ) - self.s_2center_dict["B" + str(i + 1)][ - self.bond_indices[i][1] - 1 - ] = -self.s_2center_dict["B" + str(i + 1)][self.bond_indices[i][0] - 1] + b_1 = self.compute_e(x1,x2) + b_2 = -b_1 + if Len: + for j in indies[0]: + self.s_2center_dict["B" + str(i + 1)][int(j)-1] += b_1 / len(indies[0]) + for j in indies[1]: + self.s_2center_dict["B" + str(i + 1)][int(j)-1] += b_2 / len(indies[1]) + else: + self.s_2center_dict["B" + str(i + 1)][int(indies[0]) - 1] = b_1 + self.s_2center_dict["B" + str(i + 1)][int(indies[1]) - 1] = b_2 + # Next, angles. if len(self.angle_indices) > 0: for i in range(len(self.angle_indices)): + indies = self.angle_indices[i] + Len = len(np.array(indies[0]).shape) + if Len: + x1 = [0.0,0.0,0.0] + L = len(indies[0]) + for j in indies[0]: + x1 += self.carts[int(j) - 1] + x1 /= L + x2 = [0.0,0.0,0.0] + L = len(indies[1]) + for j in indies[1]: + x2 += self.carts[int(j) - 1] + x2 /= L + x3 = [0.0,0.0,0.0] + L = len(indies[2]) + for j in indies[2]: + x3 += self.carts[int(j) - 1] + x3 /= L + else: + x1 = self.carts[int(indies[0]) - 1] + x2 = self.carts[int(indies[1]) - 1] + x3 = self.carts[int(indies[2]) - 1] + self.s_3center_dict["A" + str(i + 1)] = self.carts.copy() self.s_3center_dict["A" + str(i + 1)] = ( 0 * self.s_3center_dict["A" + str(i + 1)] ) - r_1 = self.compute_r( - self.carts, - self.angle_indices[i][0] - 1, - self.angle_indices[i][1] - 1, - ) - r_2 = self.compute_r( - self.carts, - self.angle_indices[i][1] - 1, - self.angle_indices[i][2] - 1, - ) - e_1 = self.compute_e( - self.carts, - self.angle_indices[i][0] - 1, - self.angle_indices[i][1] - 1, - r_1, - ) - e_2 = self.compute_e( - self.carts, - self.angle_indices[i][2] - 1, - self.angle_indices[i][1] - 1, - r_2, - ) - phi = self.compute_phi(e_1, e_2) + r_1 = self.compute_r(x1,x2) + r_2 = self.compute_r(x2,x3) + e_1 = self.compute_e(x1,x2) + e_2 = self.compute_e(x3,x2) + phi = self.compute_phi(e_1,e_2) a_1 = self.compute_BEND(e_1, e_2, phi, r_1) - a_2 = self.compute_BEND(e_2, e_1, phi, r_2) - self.s_3center_dict["A" + str(i + 1)][ - self.angle_indices[i][0] - 1 - ] = a_1 - self.s_3center_dict["A" + str(i + 1)][ - self.angle_indices[i][2] - 1 - ] = a_2 - self.s_3center_dict["A" + str(i + 1)][self.angle_indices[i][1] - 1] = ( - -a_1 - a_2 - ) + a_3 = self.compute_BEND(e_2, e_1, phi, r_2) + a_2 = -a_1 - a_3 + + if Len: + for j in indies[0]: + self.s_3center_dict["A" + str(i + 1)][int(j)-1] += a_1 / len(indies[0]) + for j in indies[1]: + self.s_3center_dict["A" + str(i + 1)][int(j)-1] += a_2 / len(indies[1]) + for j in indies[2]: + self.s_3center_dict["A" + str(i + 1)][int(j)-1] += a_3 / len(indies[2]) + else: + self.s_3center_dict["A" + str(i + 1)][int(indies[0]) - 1] = a_1 + self.s_3center_dict["A" + str(i + 1)][int(indies[1]) - 1] = a_2 + self.s_3center_dict["A" + str(i + 1)][int(indies[2]) - 1] = a_3 + + # Next, torsions. if len(self.torsion_indices) > 0: for i in range(len(self.torsion_indices)): + indies = self.torsion_indices[i] + Len = len(np.array(indies[0]).shape) + if Len: + x1 = [0.0,0.0,0.0] + for j in indies[0]: + x1 += self.carts[int(j) - 1] + x1 /= len(indies[0]) + x2 = [0.0,0.0,0.0] + for j in indies[1]: + x2 += self.carts[int(j) - 1] + x2 /= len(indies[1]) + x3 = [0.0,0.0,0.0] + for j in indies[2]: + x3 += self.carts[int(j) - 1] + x3 /= len(indies[2]) + x4 = [0.0,0.0,0.0] + for j in indies[3]: + x4 += self.carts[int(j) - 1] + x4 /= len(indies[3]) + else: + x1 = self.carts[int(indies[0]) - 1] + x2 = self.carts[int(indies[1]) - 1] + x3 = self.carts[int(indies[2]) - 1] + x4 = self.carts[int(indies[3]) - 1] + + self.s_4center_dict["D" + str(i + 1)] = self.carts.copy() self.s_4center_dict["D" + str(i + 1)] = ( 0 * self.s_4center_dict["D" + str(i + 1)] ) - r_1 = self.compute_r( - self.carts, - self.torsion_indices[i][0] - 1, - self.torsion_indices[i][1] - 1, - ) - r_2 = self.compute_r( - self.carts, - self.torsion_indices[i][1] - 1, - self.torsion_indices[i][2] - 1, - ) - r_3 = self.compute_r( - self.carts, - self.torsion_indices[i][2] - 1, - self.torsion_indices[i][3] - 1, - ) - e_1 = self.compute_e( - self.carts, - self.torsion_indices[i][0] - 1, - self.torsion_indices[i][1] - 1, - r_1, - ) - e_2 = self.compute_e( - self.carts, - self.torsion_indices[i][1] - 1, - self.torsion_indices[i][2] - 1, - r_2, - ) - e_3 = self.compute_e( - self.carts, - self.torsion_indices[i][2] - 1, - self.torsion_indices[i][3] - 1, - r_3, - ) - phi_1 = self.compute_phi(e_1, -e_2) - phi_2 = self.compute_phi(e_2, -e_3) + + r_1 = self.compute_r(x1,x2) + r_2 = self.compute_r(x2,x3) + r_3 = self.compute_r(x3,x4) + e_1 = self.compute_e(x1,x2) + e_2 = self.compute_e(x2,x3) + e_3 = self.compute_e(x3,x4) + phi_1 = self.compute_phi(e_1,-e_2) + phi_2 = self.compute_phi(e_2,-e_3) + t_1 = self.compute_TORS1(e_1, -e_2, phi_1, r_1) t_4 = self.compute_TORS1(-e_3, e_2, phi_2, r_3) t_2 = self.compute_TORS2(e_1, -e_2, -e_3, phi_1, phi_2, r_1, r_2) - self.s_4center_dict["D" + str(i + 1)][ - self.torsion_indices[i][0] - 1 - ] = t_1 - self.s_4center_dict["D" + str(i + 1)][ - self.torsion_indices[i][3] - 1 - ] = t_4 - self.s_4center_dict["D" + str(i + 1)][ - self.torsion_indices[i][1] - 1 - ] = t_2 - self.s_4center_dict["D" + str(i + 1)][ - self.torsion_indices[i][2] - 1 - ] = (-t_1 - t_2 - t_4) + t_3 = -t_1 - t_2 - t_4 + + if Len: + for j in indies[0]: + self.s_4center_dict["D" + str(i + 1)][int(j)-1] += t_1 / len(indies[0]) + for j in indies[1]: + self.s_4center_dict["D" + str(i + 1)][int(j)-1] += t_2 / len(indies[1]) + for j in indies[2]: + self.s_4center_dict["D" + str(i + 1)][int(j)-1] += t_3 / len(indies[2]) + for j in indies[3]: + self.s_4center_dict["D" + str(i + 1)][int(j)-1] += t_4 / len(indies[3]) + else: + self.s_4center_dict["D" + str(i + 1)][int(indies[0]) - 1] = t_1 + self.s_4center_dict["D" + str(i + 1)][int(indies[1]) - 1] = t_2 + self.s_4center_dict["D" + str(i + 1)][int(indies[2]) - 1] = t_3 + self.s_4center_dict["D" + str(i + 1)][int(indies[3]) - 1] = t_4 + + # Now, out of plane bending. if len(self.oop_indices) > 0: for i in range(len(self.oop_indices)): + indies = self.oop_indices[i] + Len = len(np.array(indies[0]).shape) + if Len: + x1 = [0.0,0.0,0.0] + for j in indies[0]: + x1 += self.carts[int(j) - 1] + x1 /= len(indies[0]) + x2 = [0.0,0.0,0.0] + for j in indies[1]: + x2 += self.carts[int(j) - 1] + x2 /= len(indies[1]) + x3 = [0.0,0.0,0.0] + for j in indies[2]: + x3 += self.carts[int(j) - 1] + x3 /= len(indies[2]) + x4 = [0.0,0.0,0.0] + for j in indies[3]: + x4 += self.carts[int(j) - 1] + x4 /= len(indies[3]) + else: + x1 = self.carts[int(indies[0]) - 1] + x2 = self.carts[int(indies[1]) - 1] + x3 = self.carts[int(indies[2]) - 1] + x4 = self.carts[int(indies[3]) - 1] + + self.s_4center_dict["O" + str(i + 1)] = self.carts.copy() self.s_4center_dict["O" + str(i + 1)] = ( 0 * self.s_4center_dict["O" + str(i + 1)] ) - r_1 = self.compute_r( - self.carts, self.oop_indices[i][0] - 1, self.oop_indices[i][1] - 1 - ) - r_2 = self.compute_r( - self.carts, self.oop_indices[i][2] - 1, self.oop_indices[i][1] - 1 - ) - r_3 = self.compute_r( - self.carts, self.oop_indices[i][3] - 1, self.oop_indices[i][1] - 1 - ) - e_1 = self.compute_e( - self.carts, - self.oop_indices[i][0] - 1, - self.oop_indices[i][1] - 1, - r_1, - ) - e_2 = self.compute_e( - self.carts, - self.oop_indices[i][2] - 1, - self.oop_indices[i][1] - 1, - r_2, - ) - e_3 = self.compute_e( - self.carts, - self.oop_indices[i][3] - 1, - self.oop_indices[i][1] - 1, - r_3, - ) - phi = self.compute_phi(e_2, e_3) + + r_1 = self.compute_r(x1,x2) + r_2 = self.compute_r(x3,x2) + r_3 = self.compute_r(x4,x2) + e_1 = self.compute_e(x1,x2) + e_2 = self.compute_e(x3,x2) + e_3 = self.compute_e(x4,x2) + phi = self.compute_phi(e_2,e_3) + theta = self.calc_OOP(x1, x2, x3, x4) - theta = self.calc_OOP( - self.carts[self.oop_indices[i][0] - 1], - self.carts[self.oop_indices[i][1] - 1], - self.carts[self.oop_indices[i][2] - 1], - self.carts[self.oop_indices[i][3] - 1], - ) o_1 = self.compute_OOP1(e_1, e_2, e_3, r_1, theta, phi) o_3 = self.compute_OOP2(e_1, e_2, e_3, r_2, theta, phi) o_4 = self.compute_OOP2(-e_1, e_3, e_2, r_3, theta, phi) - self.s_4center_dict["O" + str(i + 1)][self.oop_indices[i][0] - 1] = o_1 - self.s_4center_dict["O" + str(i + 1)][self.oop_indices[i][2] - 1] = o_3 - self.s_4center_dict["O" + str(i + 1)][self.oop_indices[i][3] - 1] = o_4 - self.s_4center_dict["O" + str(i + 1)][self.oop_indices[i][1] - 1] = ( - -o_1 - o_3 - o_4 - ) + o_2 = -o_1 - o_3 - o_4 + + + if Len: + for j in indies[0]: + self.s_4center_dict["O" + str(i + 1)][int(j)-1] += o_1 / len(indies[0]) + for j in indies[1]: + self.s_4center_dict["O" + str(i + 1)][int(j)-1] += o_2 / len(indies[1]) + for j in indies[2]: + self.s_4center_dict["O" + str(i + 1)][int(j)-1] += o_3 / len(indies[2]) + for j in indies[3]: + self.s_4center_dict["O" + str(i + 1)][int(j)-1] += o_4 / len(indies[3]) + else: + self.s_4center_dict["O" + str(i + 1)][int(indies[0]) - 1] = o_1 + self.s_4center_dict["O" + str(i + 1)][int(indies[1]) - 1] = o_2 + self.s_4center_dict["O" + str(i + 1)][int(indies[2]) - 1] = o_3 + self.s_4center_dict["O" + str(i + 1)][int(indies[3]) - 1] = o_4 # Linear bending. if len(self.lin_indices) > 0: for i in range(len(self.lin_indices)): + indies = self.lin_indices[i] + Len = len(np.array(indies[0]).shape) + if Len: + x1 = [0.0,0.0,0.0] + for j in indies[0]: + x1 += self.carts[int(j) - 1] + x1 /= len(indies[0]) + x2 = [0.0,0.0,0.0] + for j in indies[1]: + x2 += self.carts[int(j) - 1] + x2 /= len(indies[1]) + x3 = [0.0,0.0,0.0] + for j in indies[2]: + x3 += self.carts[int(j) - 1] + x3 /= len(indies[2]) + x4 = [0.0,0.0,0.0] + for j in indies[3]: + x4 += self.carts[int(j) - 1] + x4 /= len(indies[3]) + else: + x1 = self.carts[int(indies[0]) - 1] + x2 = self.carts[int(indies[1]) - 1] + x3 = self.carts[int(indies[2]) - 1] + x4 = self.carts[int(indies[3]) - 1] + self.s_4center_dict["L" + str(i + 1)] = self.carts.copy() self.s_4center_dict["L" + str(i + 1)] = ( 0 * self.s_4center_dict["L" + str(i + 1)] ) - r_1 = self.compute_r( - self.carts, self.lin_indices[i][0] - 1, self.lin_indices[i][1] - 1 - ) - r_2 = self.compute_r( - self.carts, self.lin_indices[i][2] - 1, self.lin_indices[i][1] - 1 - ) - r_3 = self.compute_r( - self.carts, self.lin_indices[i][3] - 1, self.lin_indices[i][1] - 1 - ) - e_1 = self.compute_e( - self.carts, - self.lin_indices[i][0] - 1, - self.lin_indices[i][1] - 1, - r_1, - ) - e_2 = self.compute_e( - self.carts, - self.lin_indices[i][2] - 1, - self.lin_indices[i][1] - 1, - r_2, - ) - e_3 = self.compute_e( - self.carts, - self.lin_indices[i][3] - 1, - self.lin_indices[i][1] - 1, - r_3, - ) - theta = self.calc_Lin( - self.carts[self.lin_indices[i][0] - 1], - self.carts[self.lin_indices[i][1] - 1], - self.carts[self.lin_indices[i][2] - 1], - self.carts[self.lin_indices[i][3] - 1], - ) + r_1 = self.compute_r(x1,x2) + r_2 = self.compute_r(x3,x2) + r_3 = self.compute_r(x4,x2) + e_1 = self.compute_e(x1,x2) + e_2 = self.compute_e(x3,x2) + e_3 = self.compute_e(x4,x2) + theta = self.calc_Lin(x1,x2,x3,x4) + l_1 = self.compute_LIN(e_1, e_2, e_3, r_1, theta) l_3 = self.compute_LIN(e_2, e_3, e_1, r_2, theta) - l_4 = self.compute_LIN(e_3, e_1, e_2, r_3, theta) - self.s_4center_dict["L" + str(i + 1)][self.lin_indices[i][0] - 1] = l_1 - self.s_4center_dict["L" + str(i + 1)][self.lin_indices[i][2] - 1] = l_3 - self.s_4center_dict["L" + str(i + 1)][self.lin_indices[i][3] - 1] = l_4 - self.s_4center_dict["L" + str(i + 1)][self.lin_indices[i][1] - 1] = ( - -l_1 - l_3 - l_4 - ) + # l_4 = self.compute_LIN(e_3, e_1, e_2, r_3, theta) + l_2 = -l_1 - l_3 + # l_2 = -l_1 - l_3 - l_4 + + if Len: + for j in indies[0]: + self.s_4center_dict["L" + str(i + 1)][int(j)-1] += l_1 / len(indies[0]) + for j in indies[1]: + self.s_4center_dict["L" + str(i + 1)][int(j)-1] += l_2 / len(indies[1]) + for j in indies[2]: + self.s_4center_dict["L" + str(i + 1)][int(j)-1] += l_3 / len(indies[2]) + # for j in indies[3]: + # self.s_4center_dict["L" + str(i + 1)][int(j)-1] += l_4 / len(indies[3]) + else: + self.s_4center_dict["L" + str(i + 1)][int(indies[0]) - 1] = l_1 + self.s_4center_dict["L" + str(i + 1)][int(indies[1]) - 1] = l_2 + self.s_4center_dict["L" + str(i + 1)][int(indies[2]) - 1] = l_3 + # self.s_4center_dict["L" + str(i + 1)][int(indies[3]) - 1] = l_4 # LinX bending. if len(self.linx_indices) > 0: for i in range(len(self.linx_indices)): + indies = self.linx_indices[i] + Len = len(np.array(indies[0]).shape) + if Len: + x1 = [0.0,0.0,0.0] + for j in indies[0]: + x1 += self.carts[int(j) - 1] + x1 /= len(indies[0]) + x2 = [0.0,0.0,0.0] + for j in indies[1]: + x2 += self.carts[int(j) - 1] + x2 /= len(indies[1]) + x3 = [0.0,0.0,0.0] + for j in indies[2]: + x3 += self.carts[int(j) - 1] + x3 /= len(indies[2]) + x4 = [0.0,0.0,0.0] + for j in indies[3]: + x4 += self.carts[int(j) - 1] + x4 /= len(indies[3]) + else: + x1 = self.carts[int(indies[0]) - 1] + x2 = self.carts[int(indies[1]) - 1] + x3 = self.carts[int(indies[2]) - 1] + x4 = self.carts[int(indies[3]) - 1] + self.s_4center_dict["Lx" + str(i + 1)] = self.carts.copy() self.s_4center_dict["Lx" + str(i + 1)] = ( 0 * self.s_4center_dict["Lx" + str(i + 1)] ) - r_1 = self.compute_r( - self.carts, self.linx_indices[i][1] - 1, self.linx_indices[i][0] - 1 - ) - r_2 = self.compute_r( - self.carts, self.linx_indices[i][2] - 1, self.linx_indices[i][1] - 1 - ) - r_3 = self.compute_r( - self.carts, self.linx_indices[i][3] - 1, self.linx_indices[i][2] - 1 - ) - e_1 = self.compute_e( - self.carts, - self.linx_indices[i][0] - 1, - self.linx_indices[i][1] - 1, - r_1, - ) - e_2 = self.compute_e( - self.carts, - self.linx_indices[i][1] - 1, - self.linx_indices[i][2] - 1, - r_2, - ) - e_3 = self.compute_e( - self.carts, - self.linx_indices[i][2] - 1, - self.linx_indices[i][3] - 1, - r_3, - ) - ax = self.calc_alpha_x(e_1, e_2, e_3) - phi_1 = self.compute_phi(-e_1, e_2) - phi_2 = self.compute_phi(-e_2, e_3) + r_1 = self.compute_r(x2,x1) + r_2 = self.compute_r(x3,x2) + r_3 = self.compute_r(x4,x3) + e_1 = self.compute_e(x1,x2) + e_2 = self.compute_e(x2,x3) + e_3 = self.compute_e(x3,x4) + ax = self.calc_alpha_x(e_1,e_2,e_3) + phi_1 = self.compute_phi(-e_1,e_2) + phi_2 = self.compute_phi(-e_2,e_3) + lx_1 = self.compute_LINX1(e_1, e_2, e_3, r_1, phi_1, phi_2, ax) lx_2 = self.compute_LINX2(e_1, e_2, e_3, r_1, r_2, phi_1, phi_2, ax) lx_4 = self.compute_LINX4(e_1, e_2, e_3, r_3, phi_1, ax) - self.s_4center_dict["Lx" + str(i + 1)][ - self.linx_indices[i][0] - 1 - ] = lx_1 - self.s_4center_dict["Lx" + str(i + 1)][ - self.linx_indices[i][1] - 1 - ] = lx_2 - self.s_4center_dict["Lx" + str(i + 1)][ - self.linx_indices[i][3] - 1 - ] = lx_4 - self.s_4center_dict["Lx" + str(i + 1)][self.linx_indices[i][2] - 1] = ( - -lx_1 - lx_2 - lx_4 - ) + lx_3 = -lx_1 - lx_2 - lx_4 + + if Len: + for j in indies[0]: + self.s_4center_dict["Lx" + str(i + 1)][int(j)-1] += lx_1 / len(indies[0]) + for j in indies[1]: + self.s_4center_dict["Lx" + str(i + 1)][int(j)-1] += lx_2 / len(indies[1]) + for j in indies[2]: + self.s_4center_dict["Lx" + str(i + 1)][int(j)-1] += lx_3 / len(indies[2]) + for j in indies[3]: + self.s_4center_dict["Lx" + str(i + 1)][int(j)-1] += lx_4 / len(indies[3]) + else: + self.s_4center_dict["Lx" + str(i + 1)][int(indies[0]) - 1] = lx_1 + self.s_4center_dict["Lx" + str(i + 1)][int(indies[1]) - 1] = lx_2 + self.s_4center_dict["Lx" + str(i + 1)][int(indies[2]) - 1] = lx_3 + self.s_4center_dict["Lx" + str(i + 1)][int(indies[3]) - 1] = lx_4 # LinY bending. if len(self.liny_indices) > 0: for i in range(len(self.liny_indices)): + indies = self.liny_indices[i] + Len = len(np.array(indies[0]).shape) + if Len: + x1 = [0.0,0.0,0.0] + for j in indies[0]: + x1 += self.carts[int(j) - 1] + x1 /= len(indies[0]) + x2 = [0.0,0.0,0.0] + for j in indies[1]: + x2 += self.carts[int(j) - 1] + x2 /= len(indies[1]) + x3 = [0.0,0.0,0.0] + for j in indies[2]: + x3 += self.carts[int(j) - 1] + x3 /= len(indies[2]) + x4 = [0.0,0.0,0.0] + for j in indies[3]: + x4 += self.carts[int(j) - 1] + x4 /= len(indies[3]) + else: + x1 = self.carts[int(indies[0]) - 1] + x2 = self.carts[int(indies[1]) - 1] + x3 = self.carts[int(indies[2]) - 1] + x4 = self.carts[int(indies[3]) - 1] + self.s_4center_dict["Ly" + str(i + 1)] = self.carts.copy() self.s_4center_dict["Ly" + str(i + 1)] = ( 0 * self.s_4center_dict["Ly" + str(i + 1)] ) - r_1 = self.compute_r( - self.carts, self.liny_indices[i][1] - 1, self.liny_indices[i][0] - 1 - ) - r_2 = self.compute_r( - self.carts, self.liny_indices[i][2] - 1, self.liny_indices[i][1] - 1 - ) - r_3 = self.compute_r( - self.carts, self.liny_indices[i][3] - 1, self.liny_indices[i][2] - 1 - ) - e_1 = self.compute_e( - self.carts, - self.liny_indices[i][0] - 1, - self.liny_indices[i][1] - 1, - r_1, - ) - e_2 = self.compute_e( - self.carts, - self.liny_indices[i][1] - 1, - self.liny_indices[i][2] - 1, - r_2, - ) - e_3 = self.compute_e( - self.carts, - self.liny_indices[i][2] - 1, - self.liny_indices[i][3] - 1, - r_3, - ) + r_1 = self.compute_r(x2,x1) + r_2 = self.compute_r(x3,x2) + r_3 = self.compute_r(x4,x3) + e_1 = self.compute_e(x1,x2) + e_2 = self.compute_e(x2,x3) + e_3 = self.compute_e(x3,x4) ay = self.calc_alpha_y(e_1, e_2, e_3) - phi_1 = self.compute_phi(-e_1, e_2) - phi_2 = self.compute_phi(-e_2, e_3) + phi_1 = self.compute_phi(-e_1,e_2) + phi_2 = self.compute_phi(-e_2,e_3) + ly_1 = self.compute_LINY1(e_1, e_2, e_3, r_1, phi_1, ay) ly_2 = self.compute_LINY2(e_1, e_2, e_3, r_1, r_2, phi_1, ay) ly_4 = self.compute_LINY4(e_1, e_2, e_3, r_2, r_3, phi_1, ay) - self.s_4center_dict["Ly" + str(i + 1)][ - self.liny_indices[i][0] - 1 - ] = ly_1 - self.s_4center_dict["Ly" + str(i + 1)][ - self.liny_indices[i][1] - 1 - ] = ly_2 - self.s_4center_dict["Ly" + str(i + 1)][ - self.liny_indices[i][3] - 1 - ] = ly_4 - self.s_4center_dict["Ly" + str(i + 1)][self.liny_indices[i][2] - 1] = ( - -ly_1 - ly_2 - ly_4 - ) + ly_3 = -ly_1 - ly_2 - ly_4 + + if Len: + for j in indies[0]: + self.s_4center_dict["Ly" + str(i + 1)][int(j)-1] += ly_1 / len(indies[0]) + for j in indies[1]: + self.s_4center_dict["Ly" + str(i + 1)][int(j)-1] += ly_2 / len(indies[1]) + for j in indies[2]: + self.s_4center_dict["Ly" + str(i + 1)][int(j)-1] += ly_3 / len(indies[2]) + for j in indies[3]: + self.s_4center_dict["Ly" + str(i + 1)][int(j)-1] += ly_4 / len(indies[3]) + else: + self.s_4center_dict["Ly" + str(i + 1)][int(indies[0]) - 1] = ly_1 + self.s_4center_dict["Ly" + str(i + 1)][int(indies[1]) - 1] = ly_2 + self.s_4center_dict["Ly" + str(i + 1)][int(indies[2]) - 1] = ly_3 + self.s_4center_dict["Ly" + str(i + 1)][int(indies[3]) - 1] = ly_4 # The last step will be to concatenate all of the s-vectors into a singular B-tensor, in order of stretches, then bends, then torsions. # Note: I am going to modify this to hold all 2-center, 3-center, and 4-center internal coordinates. self.B = np.array([self.s_2center_dict["B1"].flatten()]) - # print("B-time Baby:") - # print(self.B.shape) - # print(self.B) + # Append stretches - for i in range(len(self.s_2center_dict) - 1): + for i in range(len(self.bond_indices) - 1): self.B = np.append( self.B, np.array([self.s_2center_dict["B" + str(i + 2)].flatten()]), axis=0, ) + # Append bends - for i in range(len(self.s_3center_dict)): + for i in range(len(self.angle_indices)): self.B = np.append( self.B, np.array([self.s_3center_dict["A" + str(i + 1)].flatten()]), @@ -429,14 +500,31 @@ def run(self, carts, B_proj, proj=None, second_order=False): np.array([self.s_4center_dict["Ly" + str(i + 1)].flatten()]), axis=0, ) - # raise RuntimeError + # print("B-tensor:") + # print(self.B.shape) + # print(self.B) + # Option to run numerical second order B-tensor here. + if second_order: + self.B2 = self.second_order_B() + self.B2[np.abs(self.B2) < 1e-14] = 0 + np.set_printoptions(precision=2, linewidth=2000) + + # Average the off-diagonal elements to mitigate the numerical errors + for i in range(len(self.B2)): + for j in range(len(self.B2[0]) - 1): + for k in range(j): + self.B2[i, j + 1, k] = ( + self.B2[i, j + 1, k] + self.B2[i, k, j + 1] + ) / 2 + self.B2[i, k, j + 1] = self.B2[i, j + 1, k] + self.B2 = self.B2.astype(float) + print(self.B2.shape) + print(self.B2) + tol = 1e-4 # Now we acquire a linearly independant set of internal coordinates from the diagonalized # BB^T Matrix if not self.options.man_proj: - # if self.options.man_proj: - # if True: - # print("just this once bb") if self.options.coords.upper() != "ZMAT": proj, eigs, _ = LA.svd(self.B) proj[np.abs(proj) < tol] = 0 @@ -446,8 +534,6 @@ def run(self, carts, B_proj, proj=None, second_order=False): proj_array = np.array(np.where(np.abs(eigs) > tol)) self.proj = proj.T[: len(proj_array[0])] self.proj = self.proj.T - # for i in range(len(self.proj.T)): - # self.proj.T[i][np.abs(self.proj.T[i]) < np.max(np.abs(self.proj.T[i]))*proj_tol] = 0 else: self.proj = np.eye(len(self.B)) # self.proj may be used to transfrom from full set of internal @@ -458,33 +544,11 @@ def run(self, carts, B_proj, proj=None, second_order=False): # Beware! The projected B matrix cannot be psuedo inverted to form # the A-matrix. You lose information. - # Option to run numerical second order B-tensor here. - # Update: I differentiated along internal coordinate when I should have differentiated along cartesians. - # I will need to update this code - # if second_order: - # B2 = self.second_order_B() - # B2[np.abs(B2) < 1e-10] = 0 - # np.set_printoptions(precision=2, linewidth=2000) - - # # Average the off-diagonal elements to mitigate the numerical errors - # for i in range(len(B2[0][0])): - # for j in range(len(B2)): - # for k in range(j): - # if j != k: - # B2[j,k,i] = (B2[j,k,i] + B2[k,j,i]) / 2 - # B2[k,j,i] = B2[j,k,i] - - # print(B2.shape) - # print(B2) - - # raise RuntimeError - - # Once we have confirmed these second order B-tensors are good, we can then project them in our standard fashion. - - def compute_STRE(self, bond_indices, carts, r): - s = (carts[bond_indices[0] - 1] - carts[bond_indices[1] - 1]) / r + def compute_STRE(self, x1, x2): + s = (x1 - x2) / self.compute_r(x1,x2) return s + def compute_BEND(self, e_1, e_2, phi, r): s = (e_1 * np.cos(phi) - e_2) / (r * np.sin(phi)) return s @@ -498,6 +562,7 @@ def compute_TORS2(self, e_1, e_2, e_3, phi_1, phi_2, r_1, r_2): e_2, e_1 ) + (np.cos(phi_2) / (r_2 * np.sin(phi_2) ** 2)) * np.cross(-e_2, e_3) return s + # See Wilson, Decius, and Cross' "Molecular Vibrations" page 60 for the # OOP1 and OOP2 formulae. @@ -559,7 +624,7 @@ def compute_LINX4(self, e_1, e_2, e_3, r, phi, ax): c = ax * e_3 / r s = a + b + c return s - + def compute_LINY1(self, e_1, e_2, e_3, r, phi, ay): a = -ay * (np.tan(phi) ** -1) * (e_1 * np.cos(phi) + e_2) / (r * np.sin(phi)) b = np.cross(e_2, -e_3) / (r * np.sin(phi)) @@ -609,16 +674,18 @@ def calc_Lin(self, x1, x2, x3, x4): e4 = (x4 - x2) / LA.norm(x4 - x2) theta = np.arcsin(np.dot(e4, np.cross(e3, e1))) return theta - - def compute_e(self, carts, ind1, ind2, r): - e = (carts[ind1] - carts[ind2]) / r + + def compute_e(self, x1, x2): + r = self.compute_r(x1,x2) + e = (x1 - x2) / r return e - - def compute_r(self, carts, ind1, ind2): - r = LA.norm(carts[ind1] - carts[ind2]) + + def compute_r(self, x1, x2): + r = LA.norm(x1 - x2) return r def compute_phi(self, e_1, e_2): + p = np.dot(e_1, e_2) if p > 1: p = 1 @@ -628,32 +695,32 @@ def compute_phi(self, e_1, e_2): return phi def calc_alpha_x(self, e_1, e_2, e_3): - # e_1 = (x1 - x2) / self.calc_bond(x1, x2) - # e_2 = (x3 - x2) / self.calc_bond(x2, x3) - # e_3 = (x4 - x3) / self.calc_bond(x3, x4) theta = self.compute_phi(e_1, e_2) s = np.dot(np.cross(e_1, e_2), np.cross(-e_2, e_3)) ax = s / np.sin(theta) return ax def calc_alpha_y(self, e_1, e_2, e_3): - # e_1 = (x1 - x2) / self.calc_bond(x1, x2) - # e_2 = (x3 - x2) / self.calc_bond(x2, x3) - # e_3 = (x4 - x3) / self.calc_bond(x3, x4) theta = self.compute_phi(e_1, e_2) s = np.dot(e_1, np.cross(-e_2, e_3)) ay = s / np.sin(theta) return ay + + def calc_r_com(self, cart1, cart2, mass1, mass2): + rc1 = self.int2cart.COM(cart1, mass1) + rc2 = self.int2cart.COM(cart2, mass2) + print(rc1) + print(rc2) + rc = rc1 - rc2 + rc = LA.norm(rc) + print(rc) + return rc def num_differentiate(self, B_list_p, B_list_m): disp_size = self.options.disp # Numerical first derivative - B = np.array([(B_list_p[0] - B_list_m[0]) / 2 * disp_size]) - for i in range(len(B_list_p) - 1): - B = np.append( - B, [(B_list_p[i + 1] - B_list_m[i + 1]) / 2 * disp_size], axis=0 - ) + B = (B_list_p - B_list_m) / (2 * disp_size) return B @@ -675,13 +742,14 @@ def second_order_B(self): TED_obj, self.options, np.arange(len(self.B)), - deriv_level=1, + # deriv_level=1, + coord_type="cartesian", ) B_disp.run() - self.run(B_disp.p_disp[0], False, second_order=False) + self.run(B_disp.p_disp[0], False, proj=self.proj, second_order=False) B_list_p = np.array([self.B], dtype=object) - self.run(B_disp.m_disp[0], False, second_order=False) + self.run(B_disp.m_disp[0], False, proj=self.proj, second_order=False) B_list_m = np.array([self.B], dtype=object) for i in range(len(B_disp.p_disp) - 1): @@ -693,4 +761,8 @@ def second_order_B(self): # And differentiate B2 = self.num_differentiate(B_list_p, B_list_m) + # Put B-tensor in canonical order and average out the numerical fuzz + B2 = np.swapaxes(B2, 0, 1) + B2 = (B2 + np.swapaxes(B2, 1, 2)) / 2 + return B2 diff --git a/concordantmodes/sapelo_template.py b/concordantmodes/sapelo_template.py index 02677c39..4b190a0d 100644 --- a/concordantmodes/sapelo_template.py +++ b/concordantmodes/sapelo_template.py @@ -24,8 +24,6 @@ def __init__(self, options, job_num, prog_name, prog): "prog": prog, "tc": str(job_num), "cline": self.progdict[prog_name], - # "job_name": options.job_name, - # "job_name": options.job_name, } # This can be inserted back in if the sync keyword is sorted # $ -sync y diff --git a/concordantmodes/ted.py b/concordantmodes/ted.py index fbdd9307..fd0df56c 100644 --- a/concordantmodes/ted.py +++ b/concordantmodes/ted.py @@ -73,23 +73,10 @@ def sub_table(self, freq, TED, int_div, div, rect_print): for j in range(len(freq)): if i < len(self.zmat.bond_indices) and j == 0: table_output += ( - "{:10s}".format(" ") + "{:15s}".format(" ") + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.bond_indices[i][0]) - 1 - ] - ) - + str(self.zmat.bond_indices[i][0]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.bond_indices[i][1]) - 1 - ] - ) - + str(self.zmat.bond_indices[i][1]) + "B" + + str(i+1) ) + " STRE: " ) @@ -97,42 +84,18 @@ def sub_table(self, freq, TED, int_div, div, rect_print): i < len(self.zmat.bond_indices) + len(self.zmat.angle_indices) and j == 0 ): - k = i - len(self.zmat.bond_indices) + k = i - len(self.zmat.bond_indices) table_output += ( - "{:5s}".format(" ") + "{:15s}".format(" ") + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.angle_indices[k][0]) - 1 - ] - ) - + str(self.zmat.angle_indices[k][0]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.angle_indices[k][1]) - 1 - ] - ) - + str(self.zmat.angle_indices[k][1]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.angle_indices[k][2]) - 1 - ] - ) - + str(self.zmat.angle_indices[k][2]) + "A" + + str(k+1) ) + " BEND: " ) elif ( i - < len(self.zmat.bond_indices) - + len(self.zmat.angle_indices) - + len(self.zmat.torsion_indices) + < len(self.zmat.bond_indices) + len(self.zmat.angle_indices) + len(self.zmat.torsion_indices) and j == 0 ): k = ( @@ -141,40 +104,10 @@ def sub_table(self, freq, TED, int_div, div, rect_print): - len(self.zmat.angle_indices) ) table_output += ( - "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.torsion_indices[k][0]) - 1 - ] - ) - + str(self.zmat.torsion_indices[k][0]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.torsion_indices[k][1]) - 1 - ] - ) - + str(self.zmat.torsion_indices[k][1]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.torsion_indices[k][2]) - 1 - ] - ) - + str(self.zmat.torsion_indices[k][2]) - ) - + " " + "{:15s}".format(" ") + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.torsion_indices[k][3]) - 1 - ] - ) - + str(self.zmat.torsion_indices[k][3]) + "D" + + str(k+1) ) + " TORS: " ) @@ -193,40 +126,10 @@ def sub_table(self, freq, TED, int_div, div, rect_print): - len(self.zmat.torsion_indices) ) table_output += ( - "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.oop_indices[k][0]) - 1 - ] - ) - + str(self.zmat.oop_indices[k][0]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.oop_indices[k][1]) - 1 - ] - ) - + str(self.zmat.oop_indices[k][1]) - ) - + " " + "{:15s}".format(" ") + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.oop_indices[k][2]) - 1 - ] - ) - + str(self.zmat.oop_indices[k][2]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.oop_indices[k][3]) - 1 - ] - ) - + str(self.zmat.oop_indices[k][3]) + "O" + + str(k+1) ) + " OOP: " ) @@ -247,40 +150,10 @@ def sub_table(self, freq, TED, int_div, div, rect_print): - len(self.zmat.oop_indices) ) table_output += ( - "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.lin_indices[k][0]) - 1 - ] - ) - + str(self.zmat.lin_indices[k][0]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.lin_indices[k][1]) - 1 - ] - ) - + str(self.zmat.lin_indices[k][1]) - ) - + " " + "{:15s}".format(" ") + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.lin_indices[k][2]) - 1 - ] - ) - + str(self.zmat.lin_indices[k][2]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.lin_indices[k][3]) - 1 - ] - ) - + str(self.zmat.lin_indices[k][3]) + "L" + + str(k+1) ) + " LIN: " ) @@ -303,40 +176,10 @@ def sub_table(self, freq, TED, int_div, div, rect_print): - len(self.zmat.lin_indices) ) table_output += ( - "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.linx_indices[k][0]) - 1 - ] - ) - + str(self.zmat.linx_indices[k][0]) - ) - + " " + "{:15s}".format(" ") + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.linx_indices[k][1]) - 1 - ] - ) - + str(self.zmat.linx_indices[k][1]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.linx_indices[k][2]) - 1 - ] - ) - + str(self.zmat.linx_indices[k][2]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.linx_indices[k][3]) - 1 - ] - ) - + str(self.zmat.linx_indices[k][3]) + "Lx" + + str(k+1) ) + " LINX: " ) @@ -361,40 +204,10 @@ def sub_table(self, freq, TED, int_div, div, rect_print): - len(self.zmat.linx_indices) ) table_output += ( - "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.liny_indices[k][0]) - 1 - ] - ) - + str(self.zmat.liny_indices[k][0]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.liny_indices[k][1]) - 1 - ] - ) - + str(self.zmat.liny_indices[k][1]) - ) - + " " - + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.liny_indices[k][2]) - 1 - ] - ) - + str(self.zmat.liny_indices[k][2]) - ) - + " " + "{:15s}".format(" ") + "{:4s}".format( - str( - self.zmat.atom_list[ - int(self.zmat.liny_indices[k][3]) - 1 - ] - ) - + str(self.zmat.liny_indices[k][3]) + "Ly" + + str(k+1) ) + " LINY: " ) diff --git a/concordantmodes/tests/test_f_read.py b/concordantmodes/tests/test_f_read.py index 5a7415cd..4c197c3b 100644 --- a/concordantmodes/tests/test_f_read.py +++ b/concordantmodes/tests/test_f_read.py @@ -383,4 +383,3 @@ def test_f_read(): os.chdir("../../") assert not errors, "errors occured:\n{}".format("\n".join(errors)) - diff --git a/concordantmodes/tests/test_s_vectors.py b/concordantmodes/tests/test_s_vectors.py index 1f2e6cae..b935639c 100644 --- a/concordantmodes/tests/test_s_vectors.py +++ b/concordantmodes/tests/test_s_vectors.py @@ -244,4 +244,3 @@ def test_compute_B(): s_vec.run(suite.ZMAT.cartesians_init, True) assert np.allclose(s_vec.B, B_ref_INTDER, rtol=0.0, atol=1e-8) - diff --git a/concordantmodes/tests/test_zmat.py b/concordantmodes/tests/test_zmat.py index 526f684a..91f2da36 100644 --- a/concordantmodes/tests/test_zmat.py +++ b/concordantmodes/tests/test_zmat.py @@ -355,4 +355,3 @@ def test_zmat_compile(): os.chdir("../../") assert not errors, "errors occured:\n{}".format("\n".join(errors)) - diff --git a/concordantmodes/transf_disp.py b/concordantmodes/transf_disp.py index 6be44c3c..f6be99bb 100644 --- a/concordantmodes/transf_disp.py +++ b/concordantmodes/transf_disp.py @@ -1,6 +1,7 @@ import numpy as np from numpy.linalg import inv from numpy import linalg as LA +from . import masses from concordantmodes.s_vectors import SVectors as s_vec @@ -36,8 +37,10 @@ def __init__( ted, options, indices, - GF=None, + coord_type="internal", deriv_level=0, + GF=None, + # offdiag_indices=np.array([]) ): # As is generally the case for Programmers, GF = None by default. self.disp_tol = disp_tol @@ -57,6 +60,7 @@ def __init__( if GF: self.GF = GF self.deriv_level = deriv_level + self.coord_type = coord_type def run(self): @@ -77,117 +81,145 @@ def run(self): # Generate the normal coordinate values for the reference structure self.n_coord = self.int_c(self.ref_carts, self.eig_inv, self.ted.proj) - # self.disp_sym = np.zeros(len(self.n_coord)) print("Normal Coordinate Values:") for i in range(len(self.n_coord)): print("Normal Coordinate #{:<4n}: {: 3.5f}".format(i + 1, self.n_coord[i])) - # if abs(self.n_coord[i]) < self.disp_tol: - # self.disp_sym[i] = 1 - - # print("List of symmetric displacements according to disp_tol:") - # print(self.disp_sym) # Next, we will have to specify our Normal mode internal coordinate # displacement sizes - Disp = self.disp - self.disp = [] - for i in range(len(self.n_coord)): - self.disp.append(Disp) - - # This code will be useful for submitting the computation with - # reduced displacements - # if self.options.reducedDisp: - # self.Freq = inv(np.diag(self.GF.Freq.copy())) - # redDisp = np.dot(self.disp,self.Freq) - # redDisp = redDisp / min(redDisp) - # redDisp = redDisp*self.disp - # self.disp = redDisp - - # raise RuntimeError + if self.coord_type == "internal": + self.Disp = self.disp + self.disp = [] + for i in range(len(self.n_coord)): + self.disp.append(self.Disp) - # This code loops through a list of indices that the force constants will be computed at and - # generates the displacements for the diagonal and (if specified) the off-diagonals. Where - # the displacement matrix D[i,j] = D[j,i]. - # a = p_disp.shape[0] - disp = np.zeros(len(self.eigs.T)) - buff = disp.copy() - if not self.deriv_level: - p_disp = np.zeros((len(self.eigs), len(self.eigs)), dtype=object) - m_disp = np.zeros((len(self.eigs), len(self.eigs)), dtype=object) - for index in self.indices: - i, j = index[0], index[1] - disp[i] = self.disp[i] - disp[j] = self.disp[j] - # a = self.coord_convert( - # print('['+str(i)+', '+str(j)+']') - p_disp[i, j] = self.coord_convert( - disp, - self.n_coord.copy(), - self.ref_carts.copy(), - 50, - 1.0e-7, - self.A.copy(), - False, - self.zmat, - self.options, + if self.options.reduced_disp: + self.redu_norm_masses = np.dot( + self.zmat.reduced_masses, np.abs(self.ted.proj) ) - # print(a.shape) - # raise RuntimeError - m_disp[i, j] = self.coord_convert( - -disp, - self.n_coord.copy(), - self.ref_carts.copy(), - 50, - 1.0e-7, - self.A.copy(), - False, - self.zmat, - self.options, + self.redu_norm_masses = np.dot( + np.abs(self.eig_inv), self.redu_norm_masses ) - disp = buff.copy() - - # raise RuntimeError - elif self.deriv_level == 1: - p_disp = np.zeros(len(self.eigs), dtype=object) - m_disp = np.zeros(len(self.eigs), dtype=object) - for i in range(len(self.eigs)): - disp[i] = self.disp[i] - # print(disp) - p_disp[i] = self.coord_convert( - disp, - self.n_coord.copy(), - self.ref_carts.copy(), - 50, - 1.0e-9, - self.A.copy(), - False, - self.zmat, - self.options, - ) - m_disp[i] = self.coord_convert( - -disp, - self.n_coord.copy(), - self.ref_carts.copy(), - 50, - 1.0e-9, - self.A.copy(), - False, - self.zmat, - self.options, + self.redu_norm_masses = self.redu_norm_masses ** (-1) + self.redu_norm_masses = np.sqrt(self.redu_norm_masses) + self.redu_norm_masses = np.diag(self.redu_norm_masses) + + print("THESE ARE THE DISPS:") + print(self.disp) + print("THESE ARE THE REDUCED MASSES:") + print(self.redu_norm_masses) + print(self.ted.proj.shape) + # This code will be useful for submitting the computation with + # reduced displacements + # if self.options.reducedDisp: + # self.Freq = inv(np.diag(self.GF.Freq.copy())) + # redDisp = np.dot(self.disp,self.Freq) + # redDisp = redDisp / min(redDisp) + # redDisp = redDisp*self.disp + # self.disp = redDisp + + # This code loops through a list of indices that the force constants will be computed at and + # generates the displacements for the diagonal and (if specified) the off-diagonals. Where + # the displacement matrix D[i,j] = D[j,i]. + disp = np.zeros(len(self.eigs.T)) + buff = disp.copy() + if not self.deriv_level: + p_disp = np.zeros((len(self.eigs), len(self.eigs)), dtype=object) + m_disp = np.zeros((len(self.eigs), len(self.eigs)), dtype=object) + for index in self.indices: + i, j = index[0], index[1] + disp[i] = self.disp[i] + disp[j] = self.disp[j] + if self.options.reduced_disp: + disp = np.dot(disp, self.redu_norm_masses) + p_disp[i, j] = self.coord_convert( + disp, + self.n_coord.copy(), + self.ref_carts.copy(), + 50, + 1.0e-7, + # 1.0e-10, + self.A.copy(), + False, + self.zmat, + self.options, + ) + m_disp[i, j] = self.coord_convert( + -disp, + self.n_coord.copy(), + self.ref_carts.copy(), + 50, + 1.0e-7, + # 1.0e-10, + self.A.copy(), + False, + self.zmat, + self.options, + ) + disp = buff.copy() + elif self.deriv_level == 1: + p_disp = np.zeros(len(self.eigs), dtype=object) + m_disp = np.zeros(len(self.eigs), dtype=object) + for i in range(len(self.eigs)): + disp[i] = self.disp[i] + p_disp[i] = self.coord_convert( + disp, + self.n_coord.copy(), + self.ref_carts.copy(), + 50, + 1.0e-10, + self.A.copy(), + False, + self.zmat, + self.options, + ) + m_disp[i] = self.coord_convert( + -disp, + self.n_coord.copy(), + self.ref_carts.copy(), + 50, + 1.0e-10, + self.A.copy(), + False, + self.zmat, + self.options, + ) + disp = buff.copy() + else: + print( + "Only energy and gradient derivatives are supported. Check your deriv_level_init keyword." ) - disp = buff.copy() - # print(p_disp) - # print(m_disp) + raise RuntimeError # raise RuntimeError + self.p_disp = p_disp + self.m_disp = m_disp + if self.options.reduced_disp: + self.disp = np.dot(self.disp, self.redu_norm_masses) + print("THESE ARE REALLY THE DISPS:") + print(self.disp) + elif self.coord_type == "cartesian": + p_disp = np.zeros(len(self.ref_carts.flatten()), dtype=object) + m_disp = np.zeros(len(self.ref_carts.flatten()), dtype=object) + print("THIS IS THE DISP SIZE") + print(self.disp) + for i in range(len(self.ref_carts.flatten())): + p_disp[i] = self.ref_carts.flatten().copy() + m_disp[i] = self.ref_carts.flatten().copy() + p_disp[i][i] = p_disp[i][i] + self.disp + m_disp[i][i] = m_disp[i][i] - self.disp + p_disp[i] = np.reshape(p_disp[i], (-1, 3)) + m_disp[i] = np.reshape(m_disp[i], (-1, 3)) + + self.p_disp = p_disp + self.m_disp = m_disp + else: print( - "Only energy and gradient derivatives are supported. Check your deriv_level_init keyword." + "Please input a displacement coordinate type of either cartesian or internal." ) raise RuntimeError - self.p_disp = p_disp - self.m_disp = m_disp def int_c(self, carts, eig_inv, proj): # This is a function that computes all currently implemented and @@ -196,17 +228,209 @@ def int_c(self, carts, eig_inv, proj): # together in the order of the for-loops below. All other methods # in this package which use the int_c generated variables MUST # abide by this ordering. - - # tol = 1.0e-3 int_coord = np.array([]) for i in range(len(self.zmat.bond_indices)): - x1 = np.array(carts[int(self.zmat.bond_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.bond_indices[i][1]) - 1]).astype(float) + for j in self.zmat.bond_indices[i]: + Len = len(np.array(j).shape) + if Len: + indies = self.zmat.bond_indices[i] + bond_carts = [] + for k in indies[0]: + bond_carts = np.append(bond_carts,np.array(carts[int(k) - 1]).astype(float)) + bond_carts = np.reshape(bond_carts, (-1, 3)) + x1 = self.calc_Centroid(bond_carts) + + bond_carts = [] + for k in indies[1]: + bond_carts = np.append(bond_carts,np.array(carts[int(k) - 1]).astype(float)) + bond_carts = np.reshape(bond_carts, (-1, 3)) + x2 = self.calc_Centroid(bond_carts) + else: + x1 = np.array(carts[int(self.zmat.bond_indices[i][0]) - 1]).astype(float) + x2 = np.array(carts[int(self.zmat.bond_indices[i][1]) - 1]).astype(float) + int_coord = np.append(int_coord, self.calc_bond(x1, x2)) + + for i in range(len(self.zmat.rcom_indices)): + mol1 = self.zmat.rcom_indices[i][0] + mol2 = self.zmat.rcom_indices[i][1] + rc = self.calc_Rcom(mol1, mol2, carts) + # raise RuntimeError + int_coord = np.append(int_coord, rc) + + # Prep interfragment coords here + # for i in range(len(self.zmat.int1_indices)): + # p1_points = np.array([]) + # for j in np.array(self.zmat.int1_indices[i]).astype(int): + # p1_points = np.append(p1_points, carts[j - 1]) + # p1_points = np.reshape(p1_points, (-1, 3)) + # p1 = self.calc_Centroid(p1_points) + # p2 = np.array([]) + # p3 = np.array([]) + # p4 = np.array([]) + # p5 = np.array([]) + # p6 = np.array([]) + # if len(self.zmat.int2_indices): + # p2_points = np.array([]) + # for j in np.array(self.zmat.int2_indices[i]).astype(int): + # p2_points = np.append(p2_points, carts[j - 1]) + # p2_points = np.reshape(p2_points, (-1, 3)) + # p2 = self.calc_Centroid(p2_points) + # if len(self.zmat.int3_indices): + # p3_points = np.array([]) + # for j in np.array(self.zmat.int3_indices[i]).astype(int): + # p3_points = np.append(p3_points, carts[j - 1]) + # p3_points = np.reshape(p3_points, (-1, 3)) + # p3 = self.calc_Centroid(p3_points) + # if len(self.zmat.int4_indices): + # p4_points = np.array([]) + # for j in np.array(self.zmat.int4_indices[i]).astype(int): + # p4_points = np.append(p4_points, carts[j - 1]) + # p4_points = np.reshape(p4_points, (-1, 3)) + # p4 = self.calc_Centroid(p4_points) + # if len(self.zmat.int5_indices): + # p5_points = np.array([]) + # for j in np.array(self.zmat.int5_indices[i]).astype(int): + # p5_points = np.append(p5_points, carts[j - 1]) + # p5_points = np.reshape(p5_points, (-1, 3)) + # p5 = self.calc_Centroid(p5_points) + # if len(self.zmat.int6_indices): + # p6_points = np.array([]) + # for j in np.array(self.zmat.int6_indices[i]).astype(int): + # p6_points = np.append(p6_points, carts[j - 1]) + # p6_points = np.reshape(p6_points, (-1, 3)) + # p6 = self.calc_Centroid(p6_points) + + # self.int_frag_points = np.array([p1, p2, p3, p4, p5, p6]) + + # inter_distance = self.calc_bond(p1, p4) + # int_coord = np.append(int_coord, inter_distance) + # if len(self.zmat.int2_indices): + # polar_angle1 = self.calc_angle(p2, p1, p4) + # if self.conv: + # condition_1 = ( + # float( + # self.zmat.variable_dictionary_final[ + # self.zmat.int2_variables[i] + # ] + # ) + # > 180.0 + # ) + # condition_2 = ( + # float( + # self.zmat.variable_dictionary_final[ + # self.zmat.int2_variables[i] + # ] + # ) + # < 0.0 + # ) + # if condition_1 or condition_2: + # polar_angle1 = 2 * np.pi - polar_angle1 + # int_coord = np.append(int_coord, polar_angle1) + # if len(self.zmat.int5_indices): + # polar_angle2 = self.calc_angle(p5, p4, p1) + # if self.conv: + # condition_1 = ( + # float( + # self.zmat.variable_dictionary_final[ + # self.zmat.int3_variables[i] + # ] + # ) + # > 180.0 + # ) + # condition_2 = ( + # float( + # self.zmat.variable_dictionary_final[ + # self.zmat.int3_variables[i] + # ] + # ) + # < 0.0 + # ) + # if condition_1 or condition_2: + # polar_angle2 = 2 * np.pi - polar_angle2 + # int_coord = np.append(int_coord, polar_angle2) + # if len(self.zmat.int5_indices): + # torsion_angle = self.calc_tors(p2, p1, p4, p5) + # if self.conv: + # condition_1 = float( + # self.zmat.variable_dictionary_final[self.zmat.int4_variables[i]] + # ) > 135.0 and (torsion_angle * 180.0 / np.pi < -135.0) + # condition_2 = float( + # self.zmat.variable_dictionary_final[self.zmat.int4_variables[i]] + # ) < -135.0 and (torsion_angle * 180.0 / np.pi > 135.0) + # if condition_1: + # torsion_angle += 2 * np.pi + # if condition_2: + # torsion_angle -= 2 * np.pi + # int_coord = np.append(int_coord, torsion_angle) + # if len(self.zmat.int3_indices): + # int_rot_angle1 = self.calc_tors(p3, p2, p1, p4) + # # int_rot_angle1 = self.calc_tors(p4, p1, p2, p3) + # if self.conv: + # condition_1 = float( + # self.zmat.variable_dictionary_final[self.zmat.int5_variables[i]] + # ) > 135.0 and (int_rot_angle1 * 180.0 / np.pi < -135.0) + # condition_2 = float( + # self.zmat.variable_dictionary_final[self.zmat.int5_variables[i]] + # ) < -135.0 and (int_rot_angle1 * 180.0 / np.pi > 135.0) + # if condition_1: + # int_rot_angle1 += 2 * np.pi + # if condition_2: + # int_rot_angle1 -= 2 * np.pi + # int_coord = np.append(int_coord, int_rot_angle1) + # if len(self.zmat.int6_indices): + # int_rot_angle2 = self.calc_tors(p6, p5, p4, p1) + # # int_rot_angle2 = self.calc_tors(p1, p4, p5, p6) + # if self.conv: + # condition_1 = float( + # self.zmat.variable_dictionary_final[self.zmat.int6_variables[i]] + # ) > 135.0 and (int_rot_angle2 * 180.0 / np.pi < -135.0) + # condition_2 = float( + # self.zmat.variable_dictionary_final[self.zmat.int6_variables[i]] + # ) < -135.0 and (int_rot_angle2 * 180.0 / np.pi > 135.0) + # if condition_1: + # int_rot_angle2 += 2 * np.pi + # if condition_2: + # int_rot_angle2 -= 2 * np.pi + # int_coord = np.append(int_coord, int_rot_angle2) + + # print(inter_distance) + # print(polar_angle1*180/np.pi) + # print(polar_angle2*180/np.pi) + # print(torsion_angle*180/np.pi) + # print(int_rot_angle1*180/np.pi) + # print(int_rot_angle2*180/np.pi) + + # raise RuntimeError + for i in range(len(self.zmat.angle_indices)): - x1 = np.array(carts[int(self.zmat.angle_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.angle_indices[i][1]) - 1]).astype(float) - x3 = np.array(carts[int(self.zmat.angle_indices[i][2]) - 1]).astype(float) + for j in self.zmat.angle_indices[i]: + Len = len(np.array(j).shape) + indies = self.zmat.angle_indices[i] + if Len: + angle_carts = [] + for k in indies[0]: + angle_carts = np.append(angle_carts,np.array(carts[int(k) - 1]).astype(float)) + angle_carts = np.reshape(angle_carts, (-1, 3)) + x1 = self.calc_Centroid(angle_carts) + + angle_carts = [] + for k in indies[1]: + angle_carts = np.append(angle_carts,np.array(carts[int(k) - 1]).astype(float)) + angle_carts = np.reshape(angle_carts, (-1, 3)) + x2 = self.calc_Centroid(angle_carts) + + angle_carts = [] + for k in indies[2]: + angle_carts = np.append(angle_carts,np.array(carts[int(k) - 1]).astype(float)) + angle_carts = np.reshape(angle_carts, (-1, 3)) + x3 = self.calc_Centroid(angle_carts) + else: + x1 = np.array(carts[int(indies[0]) - 1]).astype(float) + x2 = np.array(carts[int(indies[1]) - 1]).astype(float) + x3 = np.array(carts[int(indies[2]) - 1]).astype(float) + + a = self.calc_angle(x1, x2, x3) if self.conv: condition_1 = ( @@ -228,11 +452,41 @@ def int_c(self, carts, eig_inv, proj): if condition_1 or condition_2: a = 2 * np.pi - a int_coord = np.append(int_coord, a) + for i in range(len(self.zmat.torsion_indices)): - x1 = np.array(carts[int(self.zmat.torsion_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.torsion_indices[i][1]) - 1]).astype(float) - x3 = np.array(carts[int(self.zmat.torsion_indices[i][2]) - 1]).astype(float) - x4 = np.array(carts[int(self.zmat.torsion_indices[i][3]) - 1]).astype(float) + for j in self.zmat.torsion_indices[i]: + Len = len(np.array(j).shape) + if Len: + indies = self.zmat.torsion_indices[i] + torsion_carts = [] + for k in indies[0]: + torsion_carts = np.append(torsion_carts,np.array(carts[int(k) - 1]).astype(float)) + torsion_carts = np.reshape(torsion_carts, (-1, 3)) + x1 = self.calc_Centroid(torsion_carts) + + torsion_carts = [] + for k in indies[1]: + torsion_carts = np.append(torsion_carts,np.array(carts[int(k) - 1]).astype(float)) + torsion_carts = np.reshape(torsion_carts, (-1, 3)) + x2 = self.calc_Centroid(torsion_carts) + + torsion_carts = [] + for k in indies[2]: + torsion_carts = np.append(torsion_carts,np.array(carts[int(k) - 1]).astype(float)) + torsion_carts = np.reshape(torsion_carts, (-1, 3)) + x3 = self.calc_Centroid(torsion_carts) + + torsion_carts = [] + for k in indies[3]: + torsion_carts = np.append(torsion_carts,np.array(carts[int(k) - 1]).astype(float)) + torsion_carts = np.reshape(torsion_carts, (-1, 3)) + x4 = self.calc_Centroid(torsion_carts) + else: + x1 = np.array(carts[int(self.zmat.torsion_indices[i][0]) - 1]).astype(float) + x2 = np.array(carts[int(self.zmat.torsion_indices[i][1]) - 1]).astype(float) + x3 = np.array(carts[int(self.zmat.torsion_indices[i][2]) - 1]).astype(float) + x4 = np.array(carts[int(self.zmat.torsion_indices[i][3]) - 1]).astype(float) + t = self.calc_tors(x1, x2, x3, x4) if self.conv: condition_1 = float( @@ -246,11 +500,41 @@ def int_c(self, carts, eig_inv, proj): if condition_2: t -= 2 * np.pi int_coord = np.append(int_coord, t) + for i in range(len(self.zmat.oop_indices)): - x1 = np.array(carts[int(self.zmat.oop_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.oop_indices[i][1]) - 1]).astype(float) - x3 = np.array(carts[int(self.zmat.oop_indices[i][2]) - 1]).astype(float) - x4 = np.array(carts[int(self.zmat.oop_indices[i][3]) - 1]).astype(float) + for j in self.zmat.oop_indices[i]: + Len = len(np.array(j).shape) + if Len: + indies = self.zmat.oop_indices[i] + oop_carts = [] + for k in indies[0]: + oop_carts = np.append(oop_carts,np.array(carts[int(k) - 1]).astype(float)) + oop_carts = np.reshape(oop_carts, (-1, 3)) + x1 = self.calc_Centroid(oop_carts) + + oop_carts = [] + for k in indies[1]: + oop_carts = np.append(oop_carts,np.array(carts[int(k) - 1]).astype(float)) + oop_carts = np.reshape(oop_carts, (-1, 3)) + x2 = self.calc_Centroid(oop_carts) + + oop_carts = [] + for k in indies[2]: + oop_carts = np.append(oop_carts,np.array(carts[int(k) - 1]).astype(float)) + oop_carts = np.reshape(oop_carts, (-1, 3)) + x3 = self.calc_Centroid(oop_carts) + + oop_carts = [] + for k in indies[3]: + oop_carts = np.append(oop_carts,np.array(carts[int(k) - 1]).astype(float)) + oop_carts = np.reshape(oop_carts, (-1, 3)) + x4 = self.calc_Centroid(oop_carts) + else: + x1 = np.array(carts[int(self.zmat.oop_indices[i][0]) - 1]).astype(float) + x2 = np.array(carts[int(self.zmat.oop_indices[i][1]) - 1]).astype(float) + x3 = np.array(carts[int(self.zmat.oop_indices[i][2]) - 1]).astype(float) + x4 = np.array(carts[int(self.zmat.oop_indices[i][3]) - 1]).astype(float) + o = self.calc_OOP(x1, x2, x3, x4) if self.conv: condition_1 = ( @@ -273,32 +557,116 @@ def int_c(self, carts, eig_inv, proj): # These angles will have to be tempered at some point in the same manner as above. for i in range(len(self.zmat.lin_indices)): - x1 = np.array(carts[int(self.zmat.lin_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.lin_indices[i][1]) - 1]).astype(float) - x3 = np.array(carts[int(self.zmat.lin_indices[i][2]) - 1]).astype(float) - x4 = np.array(carts[int(self.zmat.lin_indices[i][3]) - 1]).astype(float) + for j in self.zmat.lin_indices[i]: + Len = len(np.array(j).shape) + if Len: + indies = self.zmat.lin_indices[i] + lin_carts = [] + for k in indies[0]: + lin_carts = np.append(lin_carts,np.array(carts[int(k) - 1]).astype(float)) + lin_carts = np.reshape(lin_carts, (-1, 3)) + x1 = self.calc_Centroid(lin_carts) + + lin_carts = [] + for k in indies[1]: + lin_carts = np.append(lin_carts,np.array(carts[int(k) - 1]).astype(float)) + lin_carts = np.reshape(lin_carts, (-1, 3)) + x2 = self.calc_Centroid(lin_carts) + + lin_carts = [] + for k in indies[2]: + lin_carts = np.append(lin_carts,np.array(carts[int(k) - 1]).astype(float)) + lin_carts = np.reshape(lin_carts, (-1, 3)) + x3 = self.calc_Centroid(lin_carts) + + lin_carts = [] + for k in indies[3]: + lin_carts = np.append(lin_carts,np.array(carts[int(k) - 1]).astype(float)) + lin_carts = np.reshape(lin_carts, (-1, 3)) + x4 = self.calc_Centroid(lin_carts) + else: + x1 = np.array(carts[int(self.zmat.lin_indices[i][0]) - 1]).astype(float) + x2 = np.array(carts[int(self.zmat.lin_indices[i][1]) - 1]).astype(float) + x3 = np.array(carts[int(self.zmat.lin_indices[i][2]) - 1]).astype(float) + x4 = np.array(carts[int(self.zmat.lin_indices[i][3]) - 1]).astype(float) l = self.calc_Lin(x1, x2, x3, x4) int_coord = np.append(int_coord, l) for i in range(len(self.zmat.linx_indices)): - x1 = np.array(carts[int(self.zmat.linx_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.linx_indices[i][1]) - 1]).astype(float) - x3 = np.array(carts[int(self.zmat.linx_indices[i][2]) - 1]).astype(float) - x4 = np.array(carts[int(self.zmat.linx_indices[i][3]) - 1]).astype(float) + for j in self.zmat.linx_indices[i]: + Len = len(np.array(j).shape) + if Len: + indies = self.zmat.linx_indices[i] + linx_carts = [] + for k in indies[0]: + linx_carts = np.append(linx_carts,np.array(carts[int(k) - 1]).astype(float)) + linx_carts = np.reshape(linx_carts, (-1, 3)) + x1 = self.calc_Centroid(linx_carts) + + linx_carts = [] + for k in indies[1]: + linx_carts = np.append(linx_carts,np.array(carts[int(k) - 1]).astype(float)) + linx_carts = np.reshape(linx_carts, (-1, 3)) + x2 = self.calc_Centroid(linx_carts) + + linx_carts = [] + for k in indies[2]: + linx_carts = np.append(linx_carts,np.array(carts[int(k) - 1]).astype(float)) + linx_carts = np.reshape(linx_carts, (-1, 3)) + x3 = self.calc_Centroid(linx_carts) + + linx_carts = [] + for k in indies[3]: + linx_carts = np.append(linx_carts,np.array(carts[int(k) - 1]).astype(float)) + linx_carts = np.reshape(linx_carts, (-1, 3)) + x4 = self.calc_Centroid(linx_carts) + else: + x1 = np.array(carts[int(self.zmat.linx_indices[i][0]) - 1]).astype(float) + x2 = np.array(carts[int(self.zmat.linx_indices[i][1]) - 1]).astype(float) + x3 = np.array(carts[int(self.zmat.linx_indices[i][2]) - 1]).astype(float) + x4 = np.array(carts[int(self.zmat.linx_indices[i][3]) - 1]).astype(float) lx = self.calc_Linx(x1, x2, x3, x4) int_coord = np.append(int_coord, lx) for i in range(len(self.zmat.liny_indices)): - x1 = np.array(carts[int(self.zmat.liny_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.liny_indices[i][1]) - 1]).astype(float) - x3 = np.array(carts[int(self.zmat.liny_indices[i][2]) - 1]).astype(float) - x4 = np.array(carts[int(self.zmat.liny_indices[i][3]) - 1]).astype(float) + for j in self.zmat.liny_indices[i]: + Len = len(np.array(j).shape) + if Len: + indies = self.zmat.liny_indices[i] + liny_carts = [] + for k in indies[0]: + liny_carts = np.append(liny_carts,np.array(carts[int(k) - 1]).astype(float)) + liny_carts = np.reshape(liny_carts, (-1, 3)) + x1 = self.calc_Centroid(liny_carts) + + liny_carts = [] + for k in indies[1]: + liny_carts = np.append(liny_carts,np.array(carts[int(k) - 1]).astype(float)) + liny_carts = np.reshape(liny_carts, (-1, 3)) + x2 = self.calc_Centroid(liny_carts) + + liny_carts = [] + for k in indies[2]: + liny_carts = np.append(liny_carts,np.array(carts[int(k) - 1]).astype(float)) + liny_carts = np.reshape(liny_carts, (-1, 3)) + x3 = self.calc_Centroid(liny_carts) + + liny_carts = [] + for k in indies[3]: + liny_carts = np.append(liny_carts,np.array(carts[int(k) - 1]).astype(float)) + liny_carts = np.reshape(liny_carts, (-1, 3)) + x4 = self.calc_Centroid(liny_carts) + else: + x1 = np.array(carts[int(self.zmat.liny_indices[i][0]) - 1]).astype(float) + x2 = np.array(carts[int(self.zmat.liny_indices[i][1]) - 1]).astype(float) + x3 = np.array(carts[int(self.zmat.liny_indices[i][2]) - 1]).astype(float) + x4 = np.array(carts[int(self.zmat.liny_indices[i][3]) - 1]).astype(float) ly = self.calc_Liny(x1, x2, x3, x4) int_coord = np.append(int_coord, ly) int_coord = np.dot(proj.T, int_coord) - # int_coord[np.abs(int_coord) < tol*np.max(np.abs(int_coord))] = 0 int_coord = np.dot(eig_inv, int_coord) + return int_coord def calc_bond(self, x1, x2): @@ -374,6 +742,41 @@ def calc_Liny(self, x1, x2, x3, x4): ay = s / np.sin(theta) return ay + def calc_Rcom(self, mol1, mol2, carts): + mass = [masses.get_mass(label) for label in self.zmat.atom_list] + mol1_carts = np.array([[0.0, 0.0, 0.0]]) + mol1_masses = np.array([]) + for j in range(len(mol1)): + mol1_carts = np.append(mol1_carts, [carts[int(mol1[j]) - 1]], axis=0) + mol1_masses = np.append(mol1_masses, mass[int(mol1[j]) - 1]) + mol1_carts = mol1_carts[1:] + mol2_carts = np.array([[0.0, 0.0, 0.0]]) + mol2_masses = np.array([]) + for j in range(len(mol2)): + mol2_carts = np.append(mol2_carts, [carts[int(mol2[j]) - 1]], axis=0) + mol2_masses = np.append(mol2_masses, mass[int(mol2[j]) - 1]) + mol2_carts = mol2_carts[1:] + + mass_weighted1 = np.dot(mol1_masses, mol1_carts) + mass_weighted2 = np.dot(mol2_masses, mol2_carts) + com1 = mass_weighted1 / np.sum(mol1_masses) + com2 = mass_weighted2 / np.sum(mol2_masses) + + com_len = com1 - com2 + + rc = LA.norm(com_len) + # raise RuntimeError + return rc + + def calc_Centroid(self, carts): + c = [0.0, 0.0, 0.0] + L = len(carts) + for i in carts: + c += i + c /= L + + return c + def coord_convert( self, n_disp, @@ -386,8 +789,9 @@ def coord_convert( zmat, options, ): - tol = 1.0e-3 + # tol = 1.0e-3 # conv_iter = 10 + disp = n_disp.copy() new_n = n_coord + n_disp new_carts = np.array(ref_carts).astype(float) for i in range(max_iter): @@ -396,7 +800,7 @@ def coord_convert( new_carts += cart_disp_shaped coord_check = self.int_c(new_carts, self.eig_inv, self.ted.proj) n_disp = new_n - coord_check - n_disp[np.abs(n_disp) < tol * np.max(np.abs(n_disp))] = 0 + # n_disp[np.abs(n_disp) < tol * np.max(np.abs(n_disp))] = 0 if tight_disp: sVec = s_vec(zmat, options, zmat.variable_dictionary_final) @@ -408,10 +812,14 @@ def coord_convert( break if LA.norm(n_disp) > tolerance: print("This displacement did not converge.") + if self.options.reduced_disp: + disp = np.dot(disp, LA.inv(self.redu_norm_masses)) + print(np.where(abs(disp) == self.Disp)) print("Norm:") print(LA.norm(n_disp)) print("Tolerance:") print(tolerance) + # raise RuntimeError return new_carts def compute_A(self, B, proj, eig_inv, u): @@ -420,12 +828,6 @@ def compute_A(self, B, proj, eig_inv, u): intensities later. The BB^T product must be linearly independent to work, so it will be projected into the symmetry adapted basis. """ - # BT = B.T # (3N x s) - # A = u.dot(BT) - # A = np.dot(B,BT) # (s x s) - # A = LA.pinv(A) # (s x s) - # A = BT.dot(A) # (3N x s) - # A = np.dot(A,proj).T # (S x 3N) L = inv(eig_inv) A = LA.pinv(B) diff --git a/concordantmodes/zmat.py b/concordantmodes/zmat.py index 61a09c06..a840cce5 100644 --- a/concordantmodes/zmat.py +++ b/concordantmodes/zmat.py @@ -54,6 +54,25 @@ def zmat_read(self, zmat_name): self.lin_regex = re.compile(r"^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*L\s*\n") self.linx_regex = re.compile(r"^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*Lx\s*\n") self.liny_regex = re.compile(r"^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*Ly\s*\n") + self.rcom_regex1 = re.compile(r";\s*((\d+\s+)+)\s*;\s*((\d+\s+)+)\s*Rc") + self.rcom_regex2 = re.compile(r"\s*(\d+)") + # self.int1_regex = re.compile(r"((\s+\d+)+)\s*I1") + # self.int2_regex = re.compile(r"((\s+\d+)+)\s*I2") + # self.int3_regex = re.compile(r"((\s+\d+)+)\s*I3") + # self.int4_regex = re.compile(r"((\s+\d+)+)\s*I4") + # self.int5_regex = re.compile(r"((\s+\d+)+)\s*I5") + # self.int6_regex = re.compile(r"((\s+\d+)+)\s*I6") + + # Centroid regexes + self.centroid_regex1 = re.compile(r";") + self.centroid_regex2 = re.compile(r"\s*(\d+)") + self.bond_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)\n") + self.angle_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)\n") + self.torsion_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)T\s*\n") + self.oop_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)O\s*\n") + self.lin_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)L\s*\n") + self.linx_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)Lx\s*\n") + self.liny_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)Ly\s*\n") # Cartesian regexes self.cart_begin_regex = re.compile(r"cart begin") @@ -106,6 +125,13 @@ def zmat_read(self, zmat_name): self.atom_list.append(atom[0]) self.cartesians_init = np.array(self.cartesians_init).astype(float) + # The masses are assigned to the respective atom from the masses.py file + self.masses = [masses.get_mass(label) for label in self.atom_list] + for i in range(len(self.masses)): + self.masses[i] = self.masses[i] / self.amu_elMass + + self.mass_weight = np.diag(np.array(self.masses).repeat(3)) + if self.divider: for i in range(len(cart_output_final)): if re.search(self.cartesian_regex, cart_output_final[i]): @@ -137,9 +163,6 @@ def zmat_read(self, zmat_name): zmat_output = output[zmat_range[0] + 1 : zmat_range[1]].copy() - # print(output) - # print(zmat_output) - return zmat_output def zmat_process(self, zmat_output): @@ -158,9 +181,24 @@ def zmat_process(self, zmat_output): self.linx_variables = [] self.liny_indices = [] self.liny_variables = [] + self.rcom_indices = [] + self.rcom_variables = [] + # self.int1_indices = [] + # self.int1_variables = [] + # self.int2_indices = [] + # self.int2_variables = [] + # self.int3_indices = [] + # self.int3_variables = [] + # self.int4_indices = [] + # self.int4_variables = [] + # self.int5_indices = [] + # self.int5_variables = [] + # self.int6_indices = [] + # self.int6_variables = [] self.variable_dictionary_init = {} self.variable_dictionary_final = {} self.index_dictionary = {} + self.reduced_masses = np.array([]) count = 0 if self.options.coords.upper() == "ZMAT": @@ -251,7 +289,6 @@ def zmat_process(self, zmat_output): print(self.options.bond_threshold) print("Resulting bond indices:") print(self.bond_indices) - # raise RuntimeError else: for i in range(len(zmat_output)): if re.search(self.bond_regex, zmat_output[i]): @@ -355,8 +392,6 @@ def zmat_process(self, zmat_output): count = 4 - # self.options.topo_max_it = 4 - prev_walks = self.torsion_indices.copy() while True: @@ -389,7 +424,6 @@ def zmat_process(self, zmat_output): new_walks = np.append(new_walks, new_walk) count += 1 - # print(count) new_walks = new_walks.reshape((-1, count)) new_walks = np.unique(new_walks, axis=0) @@ -457,8 +491,6 @@ def zmat_process(self, zmat_output): ) print(cycles_dict[str(i + 3)]) - # raise RuntimeError - elif self.options.coords.upper() == "CUSTOM": # This option will allow the user to specify a custom array of # internal coordinates. @@ -467,6 +499,19 @@ def zmat_process(self, zmat_output): for i in range(len(zmat_output)): if re.search(self.bond_regex, zmat_output[i]): List = re.findall(self.bond_regex, zmat_output[i])[0] + self.bond_indices.append(List) + self.bond_variables.append( + "R" + str(i + 1 - Sum + len(self.bond_variables)) + ) + elif re.search(self.bond_centroid_regex, zmat_output[i]): + List = re.findall(self.bond_centroid_regex, zmat_output[i])[0] + ListBuff = [] + for j in List: + if re.search(self.centroid_regex1, j): + SubList = re.findall(self.centroid_regex2,j) + ListBuff.append(SubList) + List = ListBuff + self.bond_indices.append(List) self.bond_variables.append( "R" + str(i + 1 - Sum + len(self.bond_variables)) @@ -477,36 +522,173 @@ def zmat_process(self, zmat_output): self.angle_variables.append( "A" + str(i + 1 - Sum + len(self.angle_variables)) ) + elif re.search(self.angle_centroid_regex, zmat_output[i]): + List = re.findall(self.angle_centroid_regex, zmat_output[i])[0] + ListBuff = [] + for j in List: + if re.search(self.centroid_regex1, j): + SubList = re.findall(self.centroid_regex2,j) + ListBuff.append(SubList) + List = ListBuff + self.angle_indices.append(List) + self.angle_variables.append( + "A" + str(i + 1 - Sum + len(self.angle_variables)) + ) elif re.search(self.torsion_regex, zmat_output[i]): List = re.findall(self.torsion_regex, zmat_output[i])[0] self.torsion_indices.append(List) self.torsion_variables.append( "D" + str(i + 1 - Sum + len(self.torsion_variables)) ) + elif re.search(self.torsion_centroid_regex, zmat_output[i]): + List = re.findall(self.torsion_centroid_regex, zmat_output[i])[0] + ListBuff = [] + for j in List: + if re.search(self.centroid_regex1, j): + SubList = re.findall(self.centroid_regex2,j) + ListBuff.append(SubList) + List = ListBuff + self.torsion_indices.append(List) + self.torsion_variables.append( + "D" + str(i + 1 - Sum + len(self.torsion_variables)) + ) elif re.search(self.oop_regex, zmat_output[i]): List = re.findall(self.oop_regex, zmat_output[i])[0] self.oop_indices.append(List) self.oop_variables.append( "O" + str(i + 1 - Sum + len(self.oop_variables)) ) + elif re.search(self.oop_centroid_regex, zmat_output[i]): + List = re.findall(self.oop_centroid_regex, zmat_output[i])[0] + ListBuff = [] + for j in List: + if re.search(self.centroid_regex1, j): + SubList = re.findall(self.centroid_regex2,j) + ListBuff.append(SubList) + List = ListBuff + self.oop_indices.append(List) + self.oop_variables.append( + "O" + str(i + 1 - Sum + len(self.oop_variables)) + ) elif re.search(self.lin_regex, zmat_output[i]): List = re.findall(self.lin_regex, zmat_output[i])[0] self.lin_indices.append(List) self.lin_variables.append( "L" + str(i + 1 - Sum + len(self.lin_variables)) ) + elif re.search(self.lin_centroid_regex, zmat_output[i]): + List = re.findall(self.lin_centroid_regex, zmat_output[i])[0] + ListBuff = [] + for j in List: + if re.search(self.centroid_regex1, j): + SubList = re.findall(self.centroid_regex2,j) + ListBuff.append(SubList) + List = ListBuff + self.lin_indices.append(List) + self.lin_variables.append( + "L" + str(i + 1 - Sum + len(self.lin_variables)) + ) elif re.search(self.linx_regex, zmat_output[i]): List = re.findall(self.linx_regex, zmat_output[i])[0] self.linx_indices.append(List) self.linx_variables.append( "Lx" + str(i + 1 - Sum + len(self.linx_variables)) ) + elif re.search(self.linx_centroid_regex, zmat_output[i]): + List = re.findall(self.linx_centroid_regex, zmat_output[i])[0] + ListBuff = [] + for j in List: + if re.search(self.centroid_regex1, j): + SubList = re.findall(self.centroid_regex2,j) + ListBuff.append(SubList) + List = ListBuff + self.linx_indices.append(List) + self.linx_variables.append( + "Lx" + str(i + 1 - Sum + len(self.linx_variables)) + ) elif re.search(self.liny_regex, zmat_output[i]): List = re.findall(self.liny_regex, zmat_output[i])[0] self.liny_indices.append(List) self.liny_variables.append( "Ly" + str(i + 1 - Sum + len(self.liny_variables)) ) + elif re.search(self.liny_centroid_regex, zmat_output[i]): + List = re.findall(self.liny_centroid_regex, zmat_output[i])[0] + ListBuff = [] + for j in List: + if re.search(self.centroid_regex1, j): + SubList = re.findall(self.centroid_regex2,j) + ListBuff.append(SubList) + List = ListBuff + self.liny_indices.append(List) + self.liny_variables.append( + "Ly" + str(i + 1 - Sum + len(self.liny_variables)) + ) + elif re.search(self.rcom_regex1, zmat_output[i]): + List = re.findall(self.rcom_regex1, zmat_output[i])[0] + List1 = re.findall(self.rcom_regex2, List[0]) + List2 = re.findall(self.rcom_regex2, List[2]) + List = [List1, List2] + print("RCOM List:") + print(List) + self.rcom_indices.append(List) + self.rcom_variables.append( + "Rc" + str(i + 1 - Sum + len(self.rcom_variables)) + ) + # elif re.search(self.int1_regex, zmat_output[i]): + # List = re.findall(self.int1_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT1 List:") + # print(List) + # self.int1_indices.append(List) + # self.int1_variables.append( + # "I1_" + str(i + 1 - Sum + len(self.int1_variables)) + # ) + # elif re.search(self.int2_regex, zmat_output[i]): + # List = re.findall(self.int2_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT2 List:") + # print(List) + # self.int2_indices.append(List) + # self.int2_variables.append( + # "I2_" + str(i + 1 - Sum + len(self.int2_variables)) + # ) + # elif re.search(self.int3_regex, zmat_output[i]): + # List = re.findall(self.int3_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT3 List:") + # print(List) + # self.int3_indices.append(List) + # self.int3_variables.append( + # "I3_" + str(i + 1 - Sum + len(self.int3_variables)) + # ) + # elif re.search(self.int4_regex, zmat_output[i]): + # List = re.findall(self.int4_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT4 List:") + # print(List) + # self.int4_indices.append(List) + # self.int4_variables.append( + # "I4_" + str(i + 1 - Sum + len(self.int4_variables)) + # ) + # elif re.search(self.int5_regex, zmat_output[i]): + # List = re.findall(self.int5_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT5 List:") + # print(List) + # self.int5_indices.append(List) + # self.int5_variables.append( + # "I5_" + str(i + 1 - Sum + len(self.int5_variables)) + # ) + # elif re.search(self.int6_regex, zmat_output[i]): + # List = re.findall(self.int6_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT6 List:") + # print(List) + # self.int6_indices.append(List) + # self.int6_variables.append( + # "I6_" + str(i + 1 - Sum + len(self.int6_variables)) + # ) else: blank += 1 Sum = ( @@ -517,6 +699,13 @@ def zmat_process(self, zmat_output): + len(self.lin_variables) + len(self.linx_variables) + len(self.liny_variables) + + len(self.rcom_variables) + # + len(self.int1_variables) + # + len(self.int2_variables) + # + len(self.int3_variables) + # + len(self.int4_variables) + # + len(self.int5_variables) + # + len(self.int6_variables) + blank ) @@ -524,34 +713,81 @@ def zmat_calc(self): # This code utilizes the INTC function from the TransfDisp module to # calculate the initial variable values from the cartesian # coordinates. + # raise RuntimeError indices = [] transdisp = TransfDisp( 1, self, 1, 1, False, self.disp_tol, np.array([]), self.options, indices ) I = np.eye( len(self.bond_indices) + + len(self.rcom_indices) + # + len(self.int1_indices) + # + len(self.int2_indices) + # + len(self.int3_indices) + # + len(self.int4_indices) + # + len(self.int5_indices) + # + len(self.int6_indices) + len(self.angle_indices) + len(self.torsion_indices) + len(self.oop_indices) + len(self.lin_indices) + len(self.linx_indices) + len(self.liny_indices) + # - 1 ) self.variables1 = transdisp.int_c(self.cartesians_init, I, I) self.variables2 = transdisp.int_c(self.cartesians_final, I, I) + + # if len(self.int1_indices): + # self.int_frag_points = transdisp.int_frag_points + # print(self.int_frag_points) + # raise RuntimeError + for i in range( - len(self.angle_indices) + # len(self.int2_indices) + # + len(self.int3_indices) + # + len(self.int4_indices) + # + len(self.int5_indices) + # + len(self.int6_indices) + + len(self.angle_indices) + len(self.torsion_indices) + len(self.oop_indices) + len(self.lin_indices) + len(self.linx_indices) + len(self.liny_indices) + # - 1 ): - self.variables1[len(self.bond_indices) + i] *= 180.0 / np.pi - self.variables2[len(self.bond_indices) + i] *= 180.0 / np.pi - self.variables = np.append( - self.bond_variables, np.append(self.angle_variables, self.torsion_variables) - ) + self.variables1[ + len(self.bond_indices) + + len(self.rcom_indices) + # + len(self.int1_indices) + + i + ] *= (180.0 / np.pi) + self.variables2[ + len(self.bond_indices) + + len(self.rcom_indices) + # + len(self.int1_indices) + + i + ] *= (180.0 / np.pi) + self.variables = np.array(self.bond_variables) + if len(self.rcom_variables): + self.variables = np.append(self.variables, self.rcom_variables) + # if len(self.int1_variables): + # self.variables = np.append(self.variables, self.int1_variables) + # if len(self.int2_variables): + # self.variables = np.append(self.variables, self.int2_variables) + # if len(self.int3_variables): + # self.variables = np.append(self.variables, self.int3_variables) + # if len(self.int4_variables): + # self.variables = np.append(self.variables, self.int4_variables) + # if len(self.int5_variables): + # self.variables = np.append(self.variables, self.int5_variables) + # if len(self.int6_variables): + # self.variables = np.append(self.variables, self.int6_variables) + if len(self.angle_variables): + self.variables = np.append(self.variables, self.angle_variables) + if len(self.torsion_variables): + self.variables = np.append(self.variables, self.torsion_variables) if len(self.oop_variables): self.variables = np.append(self.variables, self.oop_variables) if len(self.lin_variables): @@ -571,7 +807,6 @@ def zmat_calc(self): indices.append(self.angle_indices[i].tolist()) for i in range(len(self.torsion_indices)): indices.append(self.torsion_indices[i].tolist()) - # print(indices) for i in range(len(self.variables1)): self.variable_dictionary_init[self.variables[i]] = self.variables1[i] @@ -616,6 +851,7 @@ def zmat_calc(self): >= 270.0 ): self.variable_dictionary_init[self.torsion_variables[i]] -= 360.0 + # Then the Final. This can probably be structured more elegantly, but this works and isn't too computationally demanding. for i in range(len(self.torsion_variables)): condition_1 = ( @@ -656,13 +892,6 @@ def zmat_calc(self): self.variable_dictionary_final[self.torsion_variables[i]] -= 360.0 def zmat_compile(self): - # The masses are assigned to the respective atom from the masses.py file - self.masses = [masses.get_mass(label) for label in self.atom_list] - for i in range(len(self.masses)): - self.masses[i] = self.masses[i] / self.amu_elMass - - self.mass_weight = np.diag(np.array(self.masses).repeat(3)) - zmat_shift_a = 0 zmat_shift_d = 0 @@ -673,22 +902,58 @@ def zmat_compile(self): # Append all indices to index_dictionary for i in range(len(self.bond_indices)): self.index_dictionary["R" + str(i + 1)] = self.bond_indices[i] + # self.reduced_masses = np.append( + # self.reduced_masses, self.red_mass(self.bond_indices[i]) + # ) for i in range(len(self.angle_indices)): self.index_dictionary["A" + str(i + zmat_shift_a + 1)] = self.angle_indices[ i ] + # self.reduced_masses = np.append( + # self.reduced_masses, self.red_mass(self.angle_indices[i]) + # ) for i in range(len(self.torsion_indices)): self.index_dictionary[ "D" + str(i + zmat_shift_d + 1) ] = self.torsion_indices[i] + # self.reduced_masses = np.append( + # self.reduced_masses, self.red_mass(self.torsion_indices[i]) + # ) for i in range(len(self.oop_indices)): self.index_dictionary["O" + str(i + 1)] = self.oop_indices[i] + # self.reduced_masses = np.append( + # self.reduced_masses, self.red_mass(self.oop_indices[i]) + # ) for i in range(len(self.lin_indices)): self.index_dictionary["L" + str(i + 1)] = self.lin_indices[i] + # self.reduced_masses = np.append( + # self.reduced_masses, self.red_mass(self.lin_indices[i]) + # ) for i in range(len(self.linx_indices)): self.index_dictionary["Lx" + str(i + 1)] = self.linx_indices[i] + # self.reduced_masses = np.append( + # self.reduced_masses, self.red_mass(self.linx_indices[i]) + # ) for i in range(len(self.liny_indices)): self.index_dictionary["Ly" + str(i + 1)] = self.liny_indices[i] + # self.reduced_masses = np.append( + # self.reduced_masses, self.red_mass(self.liny_indices[i]) + # ) + for i in range(len(self.rcom_indices)): + self.index_dictionary["Rc" + str(i + 1)] = self.rcom_indices[i] + + # for i in range(len(self.int1_indices)): + # self.index_dictionary["I1_" + str(i + 1)] = self.int1_indices[i] + # for i in range(len(self.int2_indices)): + # self.index_dictionary["I2_" + str(i + 1)] = self.int2_indices[i] + # for i in range(len(self.int3_indices)): + # self.index_dictionary["I3_" + str(i + 1)] = self.int3_indices[i] + # for i in range(len(self.int4_indices)): + # self.index_dictionary["I4_" + str(i + 1)] = self.int4_indices[i] + # for i in range(len(self.int5_indices)): + # self.index_dictionary["I5_" + str(i + 1)] = self.int5_indices[i] + # for i in range(len(self.int6_indices)): + # self.index_dictionary["I6_" + str(i + 1)] = self.int6_indices[i] def zmat_print(self): # Print off the internal coordinate and its value in Bohr/Degree @@ -701,8 +966,6 @@ def zmat_print(self): + " = " + str(self.variable_dictionary_init[self.variables[i]]) ) - # if self.options.coords.upper() == "REDUNDANT": - # print(indices[i]) print("Final Geometric Internal Coordinate Values:") for i in range(len(self.variables)): print( @@ -712,8 +975,6 @@ def zmat_print(self): + " = " + str(self.variable_dictionary_final[self.variables[i]]) ) - # if self.options.coords.upper() == "REDUNDANT": - # print(indices[i]) print("Final - Initial Geometric Internal Coordinate Values:") for i in range(len(self.variables)): print( @@ -724,8 +985,6 @@ def zmat_print(self): - self.variable_dictionary_init[self.variables[i]] ) ) - # if self.options.coords.upper() == "REDUNDANT": - # print(indices[i]) if self.options.geom_check: Sum = 0 for i in range(len(self.bond_indices)): @@ -740,21 +999,11 @@ def zmat_print(self): # print(len(self.bond_indices)) # print("RMSD:") # print(np.sqrt(Sum / len(self.bond_indices))) - # Calculate Cartesians using ZMATs: Sadly this will have to go on the backburner. - # The cartesians must match those used to generate the cartesian force constants or you're gonna have a bad time. - - # This could be used for initHess option? - - # cartInit = int2cart(self,self.variable_dictionary_init) - # cartFinal = int2cart(self,self.variable_dictionary_final) - # cartInit.run() - # cartFinal.run() - # self.cartesians_init = cartInit.Carts - # self.cartesians_final = cartFinal.Carts - # print(self.cartesians_init) - # print(self.cartesians_final) - - # print(self.cartesians_init) - # print(self.cartesians_final) - # print(self.bond_variables) - # print(self.torsion_indices) + + def red_mass(self, indices): + r = 0 + + for i in indices: + r += 1 / self.masses[int(i) - 1] + + return r From 6a2e5881d68c06c09218b6615ef0f4ba1882f52b Mon Sep 17 00:00:00 2001 From: MitchLahm Date: Wed, 1 Nov 2023 16:50:35 -0400 Subject: [PATCH 2/4] some reformatting --- concordantmodes/s_vectors.py | 282 ++++++++++-------- concordantmodes/ted.py | 41 +-- concordantmodes/transf_disp.py | 517 +++++++++++++++++++-------------- concordantmodes/zmat.py | 180 ++++++------ 4 files changed, 574 insertions(+), 446 deletions(-) diff --git a/concordantmodes/s_vectors.py b/concordantmodes/s_vectors.py index 0a2acec1..86736a43 100644 --- a/concordantmodes/s_vectors.py +++ b/concordantmodes/s_vectors.py @@ -53,11 +53,11 @@ def run(self, carts, B_proj, proj=None, second_order=False): indies = self.bond_indices[i] Len = len(np.array(indies[0]).shape) if Len: - x1 = [0.0,0.0,0.0] + x1 = [0.0, 0.0, 0.0] for j in indies[0]: x1 += self.carts[int(j) - 1] x1 /= len(indies[0]) - x2 = [0.0,0.0,0.0] + x2 = [0.0, 0.0, 0.0] for j in indies[1]: x2 += self.carts[int(j) - 1] x2 /= len(indies[1]) @@ -69,13 +69,17 @@ def run(self, carts, B_proj, proj=None, second_order=False): self.s_2center_dict["B" + str(i + 1)] = ( 0 * self.s_2center_dict["B" + str(i + 1)] ) - b_1 = self.compute_e(x1,x2) + b_1 = self.compute_e(x1, x2) b_2 = -b_1 if Len: for j in indies[0]: - self.s_2center_dict["B" + str(i + 1)][int(j)-1] += b_1 / len(indies[0]) + self.s_2center_dict["B" + str(i + 1)][int(j) - 1] += b_1 / len( + indies[0] + ) for j in indies[1]: - self.s_2center_dict["B" + str(i + 1)][int(j)-1] += b_2 / len(indies[1]) + self.s_2center_dict["B" + str(i + 1)][int(j) - 1] += b_2 / len( + indies[1] + ) else: self.s_2center_dict["B" + str(i + 1)][int(indies[0]) - 1] = b_1 self.s_2center_dict["B" + str(i + 1)][int(indies[1]) - 1] = b_2 @@ -86,17 +90,17 @@ def run(self, carts, B_proj, proj=None, second_order=False): indies = self.angle_indices[i] Len = len(np.array(indies[0]).shape) if Len: - x1 = [0.0,0.0,0.0] + x1 = [0.0, 0.0, 0.0] L = len(indies[0]) for j in indies[0]: x1 += self.carts[int(j) - 1] x1 /= L - x2 = [0.0,0.0,0.0] + x2 = [0.0, 0.0, 0.0] L = len(indies[1]) for j in indies[1]: x2 += self.carts[int(j) - 1] x2 /= L - x3 = [0.0,0.0,0.0] + x3 = [0.0, 0.0, 0.0] L = len(indies[2]) for j in indies[2]: x3 += self.carts[int(j) - 1] @@ -110,47 +114,52 @@ def run(self, carts, B_proj, proj=None, second_order=False): self.s_3center_dict["A" + str(i + 1)] = ( 0 * self.s_3center_dict["A" + str(i + 1)] ) - r_1 = self.compute_r(x1,x2) - r_2 = self.compute_r(x2,x3) - e_1 = self.compute_e(x1,x2) - e_2 = self.compute_e(x3,x2) - phi = self.compute_phi(e_1,e_2) + r_1 = self.compute_r(x1, x2) + r_2 = self.compute_r(x2, x3) + e_1 = self.compute_e(x1, x2) + e_2 = self.compute_e(x3, x2) + phi = self.compute_phi(e_1, e_2) a_1 = self.compute_BEND(e_1, e_2, phi, r_1) a_3 = self.compute_BEND(e_2, e_1, phi, r_2) a_2 = -a_1 - a_3 - + if Len: for j in indies[0]: - self.s_3center_dict["A" + str(i + 1)][int(j)-1] += a_1 / len(indies[0]) + self.s_3center_dict["A" + str(i + 1)][int(j) - 1] += a_1 / len( + indies[0] + ) for j in indies[1]: - self.s_3center_dict["A" + str(i + 1)][int(j)-1] += a_2 / len(indies[1]) + self.s_3center_dict["A" + str(i + 1)][int(j) - 1] += a_2 / len( + indies[1] + ) for j in indies[2]: - self.s_3center_dict["A" + str(i + 1)][int(j)-1] += a_3 / len(indies[2]) + self.s_3center_dict["A" + str(i + 1)][int(j) - 1] += a_3 / len( + indies[2] + ) else: self.s_3center_dict["A" + str(i + 1)][int(indies[0]) - 1] = a_1 self.s_3center_dict["A" + str(i + 1)][int(indies[1]) - 1] = a_2 self.s_3center_dict["A" + str(i + 1)][int(indies[2]) - 1] = a_3 - # Next, torsions. if len(self.torsion_indices) > 0: for i in range(len(self.torsion_indices)): indies = self.torsion_indices[i] Len = len(np.array(indies[0]).shape) if Len: - x1 = [0.0,0.0,0.0] + x1 = [0.0, 0.0, 0.0] for j in indies[0]: x1 += self.carts[int(j) - 1] x1 /= len(indies[0]) - x2 = [0.0,0.0,0.0] + x2 = [0.0, 0.0, 0.0] for j in indies[1]: x2 += self.carts[int(j) - 1] x2 /= len(indies[1]) - x3 = [0.0,0.0,0.0] + x3 = [0.0, 0.0, 0.0] for j in indies[2]: x3 += self.carts[int(j) - 1] x3 /= len(indies[2]) - x4 = [0.0,0.0,0.0] + x4 = [0.0, 0.0, 0.0] for j in indies[3]: x4 += self.carts[int(j) - 1] x4 /= len(indies[3]) @@ -160,62 +169,67 @@ def run(self, carts, B_proj, proj=None, second_order=False): x3 = self.carts[int(indies[2]) - 1] x4 = self.carts[int(indies[3]) - 1] - self.s_4center_dict["D" + str(i + 1)] = self.carts.copy() self.s_4center_dict["D" + str(i + 1)] = ( 0 * self.s_4center_dict["D" + str(i + 1)] ) - - r_1 = self.compute_r(x1,x2) - r_2 = self.compute_r(x2,x3) - r_3 = self.compute_r(x3,x4) - e_1 = self.compute_e(x1,x2) - e_2 = self.compute_e(x2,x3) - e_3 = self.compute_e(x3,x4) - phi_1 = self.compute_phi(e_1,-e_2) - phi_2 = self.compute_phi(e_2,-e_3) + + r_1 = self.compute_r(x1, x2) + r_2 = self.compute_r(x2, x3) + r_3 = self.compute_r(x3, x4) + e_1 = self.compute_e(x1, x2) + e_2 = self.compute_e(x2, x3) + e_3 = self.compute_e(x3, x4) + phi_1 = self.compute_phi(e_1, -e_2) + phi_2 = self.compute_phi(e_2, -e_3) t_1 = self.compute_TORS1(e_1, -e_2, phi_1, r_1) t_4 = self.compute_TORS1(-e_3, e_2, phi_2, r_3) t_2 = self.compute_TORS2(e_1, -e_2, -e_3, phi_1, phi_2, r_1, r_2) t_3 = -t_1 - t_2 - t_4 - + if Len: for j in indies[0]: - self.s_4center_dict["D" + str(i + 1)][int(j)-1] += t_1 / len(indies[0]) + self.s_4center_dict["D" + str(i + 1)][int(j) - 1] += t_1 / len( + indies[0] + ) for j in indies[1]: - self.s_4center_dict["D" + str(i + 1)][int(j)-1] += t_2 / len(indies[1]) + self.s_4center_dict["D" + str(i + 1)][int(j) - 1] += t_2 / len( + indies[1] + ) for j in indies[2]: - self.s_4center_dict["D" + str(i + 1)][int(j)-1] += t_3 / len(indies[2]) + self.s_4center_dict["D" + str(i + 1)][int(j) - 1] += t_3 / len( + indies[2] + ) for j in indies[3]: - self.s_4center_dict["D" + str(i + 1)][int(j)-1] += t_4 / len(indies[3]) + self.s_4center_dict["D" + str(i + 1)][int(j) - 1] += t_4 / len( + indies[3] + ) else: self.s_4center_dict["D" + str(i + 1)][int(indies[0]) - 1] = t_1 self.s_4center_dict["D" + str(i + 1)][int(indies[1]) - 1] = t_2 self.s_4center_dict["D" + str(i + 1)][int(indies[2]) - 1] = t_3 self.s_4center_dict["D" + str(i + 1)][int(indies[3]) - 1] = t_4 - - # Now, out of plane bending. if len(self.oop_indices) > 0: for i in range(len(self.oop_indices)): indies = self.oop_indices[i] Len = len(np.array(indies[0]).shape) if Len: - x1 = [0.0,0.0,0.0] + x1 = [0.0, 0.0, 0.0] for j in indies[0]: x1 += self.carts[int(j) - 1] x1 /= len(indies[0]) - x2 = [0.0,0.0,0.0] + x2 = [0.0, 0.0, 0.0] for j in indies[1]: x2 += self.carts[int(j) - 1] x2 /= len(indies[1]) - x3 = [0.0,0.0,0.0] + x3 = [0.0, 0.0, 0.0] for j in indies[2]: x3 += self.carts[int(j) - 1] x3 /= len(indies[2]) - x4 = [0.0,0.0,0.0] + x4 = [0.0, 0.0, 0.0] for j in indies[3]: x4 += self.carts[int(j) - 1] x4 /= len(indies[3]) @@ -225,19 +239,18 @@ def run(self, carts, B_proj, proj=None, second_order=False): x3 = self.carts[int(indies[2]) - 1] x4 = self.carts[int(indies[3]) - 1] - self.s_4center_dict["O" + str(i + 1)] = self.carts.copy() self.s_4center_dict["O" + str(i + 1)] = ( 0 * self.s_4center_dict["O" + str(i + 1)] ) - - r_1 = self.compute_r(x1,x2) - r_2 = self.compute_r(x3,x2) - r_3 = self.compute_r(x4,x2) - e_1 = self.compute_e(x1,x2) - e_2 = self.compute_e(x3,x2) - e_3 = self.compute_e(x4,x2) - phi = self.compute_phi(e_2,e_3) + + r_1 = self.compute_r(x1, x2) + r_2 = self.compute_r(x3, x2) + r_3 = self.compute_r(x4, x2) + e_1 = self.compute_e(x1, x2) + e_2 = self.compute_e(x3, x2) + e_3 = self.compute_e(x4, x2) + phi = self.compute_phi(e_2, e_3) theta = self.calc_OOP(x1, x2, x3, x4) o_1 = self.compute_OOP1(e_1, e_2, e_3, r_1, theta, phi) @@ -245,16 +258,23 @@ def run(self, carts, B_proj, proj=None, second_order=False): o_4 = self.compute_OOP2(-e_1, e_3, e_2, r_3, theta, phi) o_2 = -o_1 - o_3 - o_4 - if Len: for j in indies[0]: - self.s_4center_dict["O" + str(i + 1)][int(j)-1] += o_1 / len(indies[0]) + self.s_4center_dict["O" + str(i + 1)][int(j) - 1] += o_1 / len( + indies[0] + ) for j in indies[1]: - self.s_4center_dict["O" + str(i + 1)][int(j)-1] += o_2 / len(indies[1]) + self.s_4center_dict["O" + str(i + 1)][int(j) - 1] += o_2 / len( + indies[1] + ) for j in indies[2]: - self.s_4center_dict["O" + str(i + 1)][int(j)-1] += o_3 / len(indies[2]) + self.s_4center_dict["O" + str(i + 1)][int(j) - 1] += o_3 / len( + indies[2] + ) for j in indies[3]: - self.s_4center_dict["O" + str(i + 1)][int(j)-1] += o_4 / len(indies[3]) + self.s_4center_dict["O" + str(i + 1)][int(j) - 1] += o_4 / len( + indies[3] + ) else: self.s_4center_dict["O" + str(i + 1)][int(indies[0]) - 1] = o_1 self.s_4center_dict["O" + str(i + 1)][int(indies[1]) - 1] = o_2 @@ -267,19 +287,19 @@ def run(self, carts, B_proj, proj=None, second_order=False): indies = self.lin_indices[i] Len = len(np.array(indies[0]).shape) if Len: - x1 = [0.0,0.0,0.0] + x1 = [0.0, 0.0, 0.0] for j in indies[0]: x1 += self.carts[int(j) - 1] x1 /= len(indies[0]) - x2 = [0.0,0.0,0.0] + x2 = [0.0, 0.0, 0.0] for j in indies[1]: x2 += self.carts[int(j) - 1] x2 /= len(indies[1]) - x3 = [0.0,0.0,0.0] + x3 = [0.0, 0.0, 0.0] for j in indies[2]: x3 += self.carts[int(j) - 1] x3 /= len(indies[2]) - x4 = [0.0,0.0,0.0] + x4 = [0.0, 0.0, 0.0] for j in indies[3]: x4 += self.carts[int(j) - 1] x4 /= len(indies[3]) @@ -293,29 +313,35 @@ def run(self, carts, B_proj, proj=None, second_order=False): self.s_4center_dict["L" + str(i + 1)] = ( 0 * self.s_4center_dict["L" + str(i + 1)] ) - r_1 = self.compute_r(x1,x2) - r_2 = self.compute_r(x3,x2) - r_3 = self.compute_r(x4,x2) - e_1 = self.compute_e(x1,x2) - e_2 = self.compute_e(x3,x2) - e_3 = self.compute_e(x4,x2) - theta = self.calc_Lin(x1,x2,x3,x4) + r_1 = self.compute_r(x1, x2) + r_2 = self.compute_r(x3, x2) + r_3 = self.compute_r(x4, x2) + e_1 = self.compute_e(x1, x2) + e_2 = self.compute_e(x3, x2) + e_3 = self.compute_e(x4, x2) + theta = self.calc_Lin(x1, x2, x3, x4) l_1 = self.compute_LIN(e_1, e_2, e_3, r_1, theta) l_3 = self.compute_LIN(e_2, e_3, e_1, r_2, theta) # l_4 = self.compute_LIN(e_3, e_1, e_2, r_3, theta) l_2 = -l_1 - l_3 - # l_2 = -l_1 - l_3 - l_4 - + # l_2 = -l_1 - l_3 - l_4 + if Len: for j in indies[0]: - self.s_4center_dict["L" + str(i + 1)][int(j)-1] += l_1 / len(indies[0]) + self.s_4center_dict["L" + str(i + 1)][int(j) - 1] += l_1 / len( + indies[0] + ) for j in indies[1]: - self.s_4center_dict["L" + str(i + 1)][int(j)-1] += l_2 / len(indies[1]) + self.s_4center_dict["L" + str(i + 1)][int(j) - 1] += l_2 / len( + indies[1] + ) for j in indies[2]: - self.s_4center_dict["L" + str(i + 1)][int(j)-1] += l_3 / len(indies[2]) + self.s_4center_dict["L" + str(i + 1)][int(j) - 1] += l_3 / len( + indies[2] + ) # for j in indies[3]: - # self.s_4center_dict["L" + str(i + 1)][int(j)-1] += l_4 / len(indies[3]) + # self.s_4center_dict["L" + str(i + 1)][int(j)-1] += l_4 / len(indies[3]) else: self.s_4center_dict["L" + str(i + 1)][int(indies[0]) - 1] = l_1 self.s_4center_dict["L" + str(i + 1)][int(indies[1]) - 1] = l_2 @@ -328,19 +354,19 @@ def run(self, carts, B_proj, proj=None, second_order=False): indies = self.linx_indices[i] Len = len(np.array(indies[0]).shape) if Len: - x1 = [0.0,0.0,0.0] + x1 = [0.0, 0.0, 0.0] for j in indies[0]: x1 += self.carts[int(j) - 1] x1 /= len(indies[0]) - x2 = [0.0,0.0,0.0] + x2 = [0.0, 0.0, 0.0] for j in indies[1]: x2 += self.carts[int(j) - 1] x2 /= len(indies[1]) - x3 = [0.0,0.0,0.0] + x3 = [0.0, 0.0, 0.0] for j in indies[2]: x3 += self.carts[int(j) - 1] x3 /= len(indies[2]) - x4 = [0.0,0.0,0.0] + x4 = [0.0, 0.0, 0.0] for j in indies[3]: x4 += self.carts[int(j) - 1] x4 /= len(indies[3]) @@ -354,30 +380,38 @@ def run(self, carts, B_proj, proj=None, second_order=False): self.s_4center_dict["Lx" + str(i + 1)] = ( 0 * self.s_4center_dict["Lx" + str(i + 1)] ) - r_1 = self.compute_r(x2,x1) - r_2 = self.compute_r(x3,x2) - r_3 = self.compute_r(x4,x3) - e_1 = self.compute_e(x1,x2) - e_2 = self.compute_e(x2,x3) - e_3 = self.compute_e(x3,x4) - ax = self.calc_alpha_x(e_1,e_2,e_3) - phi_1 = self.compute_phi(-e_1,e_2) - phi_2 = self.compute_phi(-e_2,e_3) - + r_1 = self.compute_r(x2, x1) + r_2 = self.compute_r(x3, x2) + r_3 = self.compute_r(x4, x3) + e_1 = self.compute_e(x1, x2) + e_2 = self.compute_e(x2, x3) + e_3 = self.compute_e(x3, x4) + ax = self.calc_alpha_x(e_1, e_2, e_3) + phi_1 = self.compute_phi(-e_1, e_2) + phi_2 = self.compute_phi(-e_2, e_3) + lx_1 = self.compute_LINX1(e_1, e_2, e_3, r_1, phi_1, phi_2, ax) lx_2 = self.compute_LINX2(e_1, e_2, e_3, r_1, r_2, phi_1, phi_2, ax) lx_4 = self.compute_LINX4(e_1, e_2, e_3, r_3, phi_1, ax) lx_3 = -lx_1 - lx_2 - lx_4 - + if Len: for j in indies[0]: - self.s_4center_dict["Lx" + str(i + 1)][int(j)-1] += lx_1 / len(indies[0]) + self.s_4center_dict["Lx" + str(i + 1)][ + int(j) - 1 + ] += lx_1 / len(indies[0]) for j in indies[1]: - self.s_4center_dict["Lx" + str(i + 1)][int(j)-1] += lx_2 / len(indies[1]) + self.s_4center_dict["Lx" + str(i + 1)][ + int(j) - 1 + ] += lx_2 / len(indies[1]) for j in indies[2]: - self.s_4center_dict["Lx" + str(i + 1)][int(j)-1] += lx_3 / len(indies[2]) + self.s_4center_dict["Lx" + str(i + 1)][ + int(j) - 1 + ] += lx_3 / len(indies[2]) for j in indies[3]: - self.s_4center_dict["Lx" + str(i + 1)][int(j)-1] += lx_4 / len(indies[3]) + self.s_4center_dict["Lx" + str(i + 1)][ + int(j) - 1 + ] += lx_4 / len(indies[3]) else: self.s_4center_dict["Lx" + str(i + 1)][int(indies[0]) - 1] = lx_1 self.s_4center_dict["Lx" + str(i + 1)][int(indies[1]) - 1] = lx_2 @@ -390,19 +424,19 @@ def run(self, carts, B_proj, proj=None, second_order=False): indies = self.liny_indices[i] Len = len(np.array(indies[0]).shape) if Len: - x1 = [0.0,0.0,0.0] + x1 = [0.0, 0.0, 0.0] for j in indies[0]: x1 += self.carts[int(j) - 1] x1 /= len(indies[0]) - x2 = [0.0,0.0,0.0] + x2 = [0.0, 0.0, 0.0] for j in indies[1]: x2 += self.carts[int(j) - 1] x2 /= len(indies[1]) - x3 = [0.0,0.0,0.0] + x3 = [0.0, 0.0, 0.0] for j in indies[2]: x3 += self.carts[int(j) - 1] x3 /= len(indies[2]) - x4 = [0.0,0.0,0.0] + x4 = [0.0, 0.0, 0.0] for j in indies[3]: x4 += self.carts[int(j) - 1] x4 /= len(indies[3]) @@ -411,21 +445,21 @@ def run(self, carts, B_proj, proj=None, second_order=False): x2 = self.carts[int(indies[1]) - 1] x3 = self.carts[int(indies[2]) - 1] x4 = self.carts[int(indies[3]) - 1] - + self.s_4center_dict["Ly" + str(i + 1)] = self.carts.copy() self.s_4center_dict["Ly" + str(i + 1)] = ( 0 * self.s_4center_dict["Ly" + str(i + 1)] ) - r_1 = self.compute_r(x2,x1) - r_2 = self.compute_r(x3,x2) - r_3 = self.compute_r(x4,x3) - e_1 = self.compute_e(x1,x2) - e_2 = self.compute_e(x2,x3) - e_3 = self.compute_e(x3,x4) + r_1 = self.compute_r(x2, x1) + r_2 = self.compute_r(x3, x2) + r_3 = self.compute_r(x4, x3) + e_1 = self.compute_e(x1, x2) + e_2 = self.compute_e(x2, x3) + e_3 = self.compute_e(x3, x4) ay = self.calc_alpha_y(e_1, e_2, e_3) - phi_1 = self.compute_phi(-e_1,e_2) - phi_2 = self.compute_phi(-e_2,e_3) - + phi_1 = self.compute_phi(-e_1, e_2) + phi_2 = self.compute_phi(-e_2, e_3) + ly_1 = self.compute_LINY1(e_1, e_2, e_3, r_1, phi_1, ay) ly_2 = self.compute_LINY2(e_1, e_2, e_3, r_1, r_2, phi_1, ay) ly_4 = self.compute_LINY4(e_1, e_2, e_3, r_2, r_3, phi_1, ay) @@ -433,13 +467,21 @@ def run(self, carts, B_proj, proj=None, second_order=False): if Len: for j in indies[0]: - self.s_4center_dict["Ly" + str(i + 1)][int(j)-1] += ly_1 / len(indies[0]) + self.s_4center_dict["Ly" + str(i + 1)][ + int(j) - 1 + ] += ly_1 / len(indies[0]) for j in indies[1]: - self.s_4center_dict["Ly" + str(i + 1)][int(j)-1] += ly_2 / len(indies[1]) + self.s_4center_dict["Ly" + str(i + 1)][ + int(j) - 1 + ] += ly_2 / len(indies[1]) for j in indies[2]: - self.s_4center_dict["Ly" + str(i + 1)][int(j)-1] += ly_3 / len(indies[2]) + self.s_4center_dict["Ly" + str(i + 1)][ + int(j) - 1 + ] += ly_3 / len(indies[2]) for j in indies[3]: - self.s_4center_dict["Ly" + str(i + 1)][int(j)-1] += ly_4 / len(indies[3]) + self.s_4center_dict["Ly" + str(i + 1)][ + int(j) - 1 + ] += ly_4 / len(indies[3]) else: self.s_4center_dict["Ly" + str(i + 1)][int(indies[0]) - 1] = ly_1 self.s_4center_dict["Ly" + str(i + 1)][int(indies[1]) - 1] = ly_2 @@ -449,7 +491,7 @@ def run(self, carts, B_proj, proj=None, second_order=False): # The last step will be to concatenate all of the s-vectors into a singular B-tensor, in order of stretches, then bends, then torsions. # Note: I am going to modify this to hold all 2-center, 3-center, and 4-center internal coordinates. self.B = np.array([self.s_2center_dict["B1"].flatten()]) - + # Append stretches for i in range(len(self.bond_indices) - 1): self.B = np.append( @@ -545,10 +587,9 @@ def run(self, carts, B_proj, proj=None, second_order=False): # the A-matrix. You lose information. def compute_STRE(self, x1, x2): - s = (x1 - x2) / self.compute_r(x1,x2) + s = (x1 - x2) / self.compute_r(x1, x2) return s - def compute_BEND(self, e_1, e_2, phi, r): s = (e_1 * np.cos(phi) - e_2) / (r * np.sin(phi)) return s @@ -562,7 +603,6 @@ def compute_TORS2(self, e_1, e_2, e_3, phi_1, phi_2, r_1, r_2): e_2, e_1 ) + (np.cos(phi_2) / (r_2 * np.sin(phi_2) ** 2)) * np.cross(-e_2, e_3) return s - # See Wilson, Decius, and Cross' "Molecular Vibrations" page 60 for the # OOP1 and OOP2 formulae. @@ -624,7 +664,7 @@ def compute_LINX4(self, e_1, e_2, e_3, r, phi, ax): c = ax * e_3 / r s = a + b + c return s - + def compute_LINY1(self, e_1, e_2, e_3, r, phi, ay): a = -ay * (np.tan(phi) ** -1) * (e_1 * np.cos(phi) + e_2) / (r * np.sin(phi)) b = np.cross(e_2, -e_3) / (r * np.sin(phi)) @@ -674,18 +714,18 @@ def calc_Lin(self, x1, x2, x3, x4): e4 = (x4 - x2) / LA.norm(x4 - x2) theta = np.arcsin(np.dot(e4, np.cross(e3, e1))) return theta - + def compute_e(self, x1, x2): - r = self.compute_r(x1,x2) + r = self.compute_r(x1, x2) e = (x1 - x2) / r return e - + def compute_r(self, x1, x2): r = LA.norm(x1 - x2) return r def compute_phi(self, e_1, e_2): - + p = np.dot(e_1, e_2) if p > 1: p = 1 @@ -705,7 +745,7 @@ def calc_alpha_y(self, e_1, e_2, e_3): s = np.dot(e_1, np.cross(-e_2, e_3)) ay = s / np.sin(theta) return ay - + def calc_r_com(self, cart1, cart2, mass1, mass2): rc1 = self.int2cart.COM(cart1, mass1) rc2 = self.int2cart.COM(cart2, mass2) diff --git a/concordantmodes/ted.py b/concordantmodes/ted.py index fd0df56c..2ce23d8b 100644 --- a/concordantmodes/ted.py +++ b/concordantmodes/ted.py @@ -74,28 +74,24 @@ def sub_table(self, freq, TED, int_div, div, rect_print): if i < len(self.zmat.bond_indices) and j == 0: table_output += ( "{:15s}".format(" ") - + "{:4s}".format( - "B" - + str(i+1) - ) + + "{:4s}".format("B" + str(i + 1)) + " STRE: " ) elif ( i < len(self.zmat.bond_indices) + len(self.zmat.angle_indices) and j == 0 ): - k = i - len(self.zmat.bond_indices) + k = i - len(self.zmat.bond_indices) table_output += ( "{:15s}".format(" ") - + "{:4s}".format( - "A" - + str(k+1) - ) + + "{:4s}".format("A" + str(k + 1)) + " BEND: " ) elif ( i - < len(self.zmat.bond_indices) + len(self.zmat.angle_indices) + len(self.zmat.torsion_indices) + < len(self.zmat.bond_indices) + + len(self.zmat.angle_indices) + + len(self.zmat.torsion_indices) and j == 0 ): k = ( @@ -105,10 +101,7 @@ def sub_table(self, freq, TED, int_div, div, rect_print): ) table_output += ( "{:15s}".format(" ") - + "{:4s}".format( - "D" - + str(k+1) - ) + + "{:4s}".format("D" + str(k + 1)) + " TORS: " ) elif ( @@ -127,10 +120,7 @@ def sub_table(self, freq, TED, int_div, div, rect_print): ) table_output += ( "{:15s}".format(" ") - + "{:4s}".format( - "O" - + str(k+1) - ) + + "{:4s}".format("O" + str(k + 1)) + " OOP: " ) elif ( @@ -151,10 +141,7 @@ def sub_table(self, freq, TED, int_div, div, rect_print): ) table_output += ( "{:15s}".format(" ") - + "{:4s}".format( - "L" - + str(k+1) - ) + + "{:4s}".format("L" + str(k + 1)) + " LIN: " ) elif ( @@ -177,10 +164,7 @@ def sub_table(self, freq, TED, int_div, div, rect_print): ) table_output += ( "{:15s}".format(" ") - + "{:4s}".format( - "Lx" - + str(k+1) - ) + + "{:4s}".format("Lx" + str(k + 1)) + " LINX: " ) elif ( @@ -205,10 +189,7 @@ def sub_table(self, freq, TED, int_div, div, rect_print): ) table_output += ( "{:15s}".format(" ") - + "{:4s}".format( - "Ly" - + str(k+1) - ) + + "{:4s}".format("Ly" + str(k + 1)) + " LINY: " ) table_output += "{:8.1f}".format(TED[i][j + div * int_div]) diff --git a/concordantmodes/transf_disp.py b/concordantmodes/transf_disp.py index f6be99bb..ff542b37 100644 --- a/concordantmodes/transf_disp.py +++ b/concordantmodes/transf_disp.py @@ -236,18 +236,26 @@ def int_c(self, carts, eig_inv, proj): indies = self.zmat.bond_indices[i] bond_carts = [] for k in indies[0]: - bond_carts = np.append(bond_carts,np.array(carts[int(k) - 1]).astype(float)) + bond_carts = np.append( + bond_carts, np.array(carts[int(k) - 1]).astype(float) + ) bond_carts = np.reshape(bond_carts, (-1, 3)) x1 = self.calc_Centroid(bond_carts) - + bond_carts = [] for k in indies[1]: - bond_carts = np.append(bond_carts,np.array(carts[int(k) - 1]).astype(float)) + bond_carts = np.append( + bond_carts, np.array(carts[int(k) - 1]).astype(float) + ) bond_carts = np.reshape(bond_carts, (-1, 3)) x2 = self.calc_Centroid(bond_carts) else: - x1 = np.array(carts[int(self.zmat.bond_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.bond_indices[i][1]) - 1]).astype(float) + x1 = np.array(carts[int(self.zmat.bond_indices[i][0]) - 1]).astype( + float + ) + x2 = np.array(carts[int(self.zmat.bond_indices[i][1]) - 1]).astype( + float + ) int_coord = np.append(int_coord, self.calc_bond(x1, x2)) @@ -260,148 +268,148 @@ def int_c(self, carts, eig_inv, proj): # Prep interfragment coords here # for i in range(len(self.zmat.int1_indices)): - # p1_points = np.array([]) - # for j in np.array(self.zmat.int1_indices[i]).astype(int): - # p1_points = np.append(p1_points, carts[j - 1]) - # p1_points = np.reshape(p1_points, (-1, 3)) - # p1 = self.calc_Centroid(p1_points) - # p2 = np.array([]) - # p3 = np.array([]) - # p4 = np.array([]) - # p5 = np.array([]) - # p6 = np.array([]) - # if len(self.zmat.int2_indices): - # p2_points = np.array([]) - # for j in np.array(self.zmat.int2_indices[i]).astype(int): - # p2_points = np.append(p2_points, carts[j - 1]) - # p2_points = np.reshape(p2_points, (-1, 3)) - # p2 = self.calc_Centroid(p2_points) - # if len(self.zmat.int3_indices): - # p3_points = np.array([]) - # for j in np.array(self.zmat.int3_indices[i]).astype(int): - # p3_points = np.append(p3_points, carts[j - 1]) - # p3_points = np.reshape(p3_points, (-1, 3)) - # p3 = self.calc_Centroid(p3_points) - # if len(self.zmat.int4_indices): - # p4_points = np.array([]) - # for j in np.array(self.zmat.int4_indices[i]).astype(int): - # p4_points = np.append(p4_points, carts[j - 1]) - # p4_points = np.reshape(p4_points, (-1, 3)) - # p4 = self.calc_Centroid(p4_points) - # if len(self.zmat.int5_indices): - # p5_points = np.array([]) - # for j in np.array(self.zmat.int5_indices[i]).astype(int): - # p5_points = np.append(p5_points, carts[j - 1]) - # p5_points = np.reshape(p5_points, (-1, 3)) - # p5 = self.calc_Centroid(p5_points) - # if len(self.zmat.int6_indices): - # p6_points = np.array([]) - # for j in np.array(self.zmat.int6_indices[i]).astype(int): - # p6_points = np.append(p6_points, carts[j - 1]) - # p6_points = np.reshape(p6_points, (-1, 3)) - # p6 = self.calc_Centroid(p6_points) - - # self.int_frag_points = np.array([p1, p2, p3, p4, p5, p6]) - - # inter_distance = self.calc_bond(p1, p4) - # int_coord = np.append(int_coord, inter_distance) - # if len(self.zmat.int2_indices): - # polar_angle1 = self.calc_angle(p2, p1, p4) - # if self.conv: - # condition_1 = ( - # float( - # self.zmat.variable_dictionary_final[ - # self.zmat.int2_variables[i] - # ] - # ) - # > 180.0 - # ) - # condition_2 = ( - # float( - # self.zmat.variable_dictionary_final[ - # self.zmat.int2_variables[i] - # ] - # ) - # < 0.0 - # ) - # if condition_1 or condition_2: - # polar_angle1 = 2 * np.pi - polar_angle1 - # int_coord = np.append(int_coord, polar_angle1) - # if len(self.zmat.int5_indices): - # polar_angle2 = self.calc_angle(p5, p4, p1) - # if self.conv: - # condition_1 = ( - # float( - # self.zmat.variable_dictionary_final[ - # self.zmat.int3_variables[i] - # ] - # ) - # > 180.0 - # ) - # condition_2 = ( - # float( - # self.zmat.variable_dictionary_final[ - # self.zmat.int3_variables[i] - # ] - # ) - # < 0.0 - # ) - # if condition_1 or condition_2: - # polar_angle2 = 2 * np.pi - polar_angle2 - # int_coord = np.append(int_coord, polar_angle2) - # if len(self.zmat.int5_indices): - # torsion_angle = self.calc_tors(p2, p1, p4, p5) - # if self.conv: - # condition_1 = float( - # self.zmat.variable_dictionary_final[self.zmat.int4_variables[i]] - # ) > 135.0 and (torsion_angle * 180.0 / np.pi < -135.0) - # condition_2 = float( - # self.zmat.variable_dictionary_final[self.zmat.int4_variables[i]] - # ) < -135.0 and (torsion_angle * 180.0 / np.pi > 135.0) - # if condition_1: - # torsion_angle += 2 * np.pi - # if condition_2: - # torsion_angle -= 2 * np.pi - # int_coord = np.append(int_coord, torsion_angle) - # if len(self.zmat.int3_indices): - # int_rot_angle1 = self.calc_tors(p3, p2, p1, p4) - # # int_rot_angle1 = self.calc_tors(p4, p1, p2, p3) - # if self.conv: - # condition_1 = float( - # self.zmat.variable_dictionary_final[self.zmat.int5_variables[i]] - # ) > 135.0 and (int_rot_angle1 * 180.0 / np.pi < -135.0) - # condition_2 = float( - # self.zmat.variable_dictionary_final[self.zmat.int5_variables[i]] - # ) < -135.0 and (int_rot_angle1 * 180.0 / np.pi > 135.0) - # if condition_1: - # int_rot_angle1 += 2 * np.pi - # if condition_2: - # int_rot_angle1 -= 2 * np.pi - # int_coord = np.append(int_coord, int_rot_angle1) - # if len(self.zmat.int6_indices): - # int_rot_angle2 = self.calc_tors(p6, p5, p4, p1) - # # int_rot_angle2 = self.calc_tors(p1, p4, p5, p6) - # if self.conv: - # condition_1 = float( - # self.zmat.variable_dictionary_final[self.zmat.int6_variables[i]] - # ) > 135.0 and (int_rot_angle2 * 180.0 / np.pi < -135.0) - # condition_2 = float( - # self.zmat.variable_dictionary_final[self.zmat.int6_variables[i]] - # ) < -135.0 and (int_rot_angle2 * 180.0 / np.pi > 135.0) - # if condition_1: - # int_rot_angle2 += 2 * np.pi - # if condition_2: - # int_rot_angle2 -= 2 * np.pi - # int_coord = np.append(int_coord, int_rot_angle2) - - # print(inter_distance) - # print(polar_angle1*180/np.pi) - # print(polar_angle2*180/np.pi) - # print(torsion_angle*180/np.pi) - # print(int_rot_angle1*180/np.pi) - # print(int_rot_angle2*180/np.pi) + # p1_points = np.array([]) + # for j in np.array(self.zmat.int1_indices[i]).astype(int): + # p1_points = np.append(p1_points, carts[j - 1]) + # p1_points = np.reshape(p1_points, (-1, 3)) + # p1 = self.calc_Centroid(p1_points) + # p2 = np.array([]) + # p3 = np.array([]) + # p4 = np.array([]) + # p5 = np.array([]) + # p6 = np.array([]) + # if len(self.zmat.int2_indices): + # p2_points = np.array([]) + # for j in np.array(self.zmat.int2_indices[i]).astype(int): + # p2_points = np.append(p2_points, carts[j - 1]) + # p2_points = np.reshape(p2_points, (-1, 3)) + # p2 = self.calc_Centroid(p2_points) + # if len(self.zmat.int3_indices): + # p3_points = np.array([]) + # for j in np.array(self.zmat.int3_indices[i]).astype(int): + # p3_points = np.append(p3_points, carts[j - 1]) + # p3_points = np.reshape(p3_points, (-1, 3)) + # p3 = self.calc_Centroid(p3_points) + # if len(self.zmat.int4_indices): + # p4_points = np.array([]) + # for j in np.array(self.zmat.int4_indices[i]).astype(int): + # p4_points = np.append(p4_points, carts[j - 1]) + # p4_points = np.reshape(p4_points, (-1, 3)) + # p4 = self.calc_Centroid(p4_points) + # if len(self.zmat.int5_indices): + # p5_points = np.array([]) + # for j in np.array(self.zmat.int5_indices[i]).astype(int): + # p5_points = np.append(p5_points, carts[j - 1]) + # p5_points = np.reshape(p5_points, (-1, 3)) + # p5 = self.calc_Centroid(p5_points) + # if len(self.zmat.int6_indices): + # p6_points = np.array([]) + # for j in np.array(self.zmat.int6_indices[i]).astype(int): + # p6_points = np.append(p6_points, carts[j - 1]) + # p6_points = np.reshape(p6_points, (-1, 3)) + # p6 = self.calc_Centroid(p6_points) + + # self.int_frag_points = np.array([p1, p2, p3, p4, p5, p6]) + + # inter_distance = self.calc_bond(p1, p4) + # int_coord = np.append(int_coord, inter_distance) + # if len(self.zmat.int2_indices): + # polar_angle1 = self.calc_angle(p2, p1, p4) + # if self.conv: + # condition_1 = ( + # float( + # self.zmat.variable_dictionary_final[ + # self.zmat.int2_variables[i] + # ] + # ) + # > 180.0 + # ) + # condition_2 = ( + # float( + # self.zmat.variable_dictionary_final[ + # self.zmat.int2_variables[i] + # ] + # ) + # < 0.0 + # ) + # if condition_1 or condition_2: + # polar_angle1 = 2 * np.pi - polar_angle1 + # int_coord = np.append(int_coord, polar_angle1) + # if len(self.zmat.int5_indices): + # polar_angle2 = self.calc_angle(p5, p4, p1) + # if self.conv: + # condition_1 = ( + # float( + # self.zmat.variable_dictionary_final[ + # self.zmat.int3_variables[i] + # ] + # ) + # > 180.0 + # ) + # condition_2 = ( + # float( + # self.zmat.variable_dictionary_final[ + # self.zmat.int3_variables[i] + # ] + # ) + # < 0.0 + # ) + # if condition_1 or condition_2: + # polar_angle2 = 2 * np.pi - polar_angle2 + # int_coord = np.append(int_coord, polar_angle2) + # if len(self.zmat.int5_indices): + # torsion_angle = self.calc_tors(p2, p1, p4, p5) + # if self.conv: + # condition_1 = float( + # self.zmat.variable_dictionary_final[self.zmat.int4_variables[i]] + # ) > 135.0 and (torsion_angle * 180.0 / np.pi < -135.0) + # condition_2 = float( + # self.zmat.variable_dictionary_final[self.zmat.int4_variables[i]] + # ) < -135.0 and (torsion_angle * 180.0 / np.pi > 135.0) + # if condition_1: + # torsion_angle += 2 * np.pi + # if condition_2: + # torsion_angle -= 2 * np.pi + # int_coord = np.append(int_coord, torsion_angle) + # if len(self.zmat.int3_indices): + # int_rot_angle1 = self.calc_tors(p3, p2, p1, p4) + # # int_rot_angle1 = self.calc_tors(p4, p1, p2, p3) + # if self.conv: + # condition_1 = float( + # self.zmat.variable_dictionary_final[self.zmat.int5_variables[i]] + # ) > 135.0 and (int_rot_angle1 * 180.0 / np.pi < -135.0) + # condition_2 = float( + # self.zmat.variable_dictionary_final[self.zmat.int5_variables[i]] + # ) < -135.0 and (int_rot_angle1 * 180.0 / np.pi > 135.0) + # if condition_1: + # int_rot_angle1 += 2 * np.pi + # if condition_2: + # int_rot_angle1 -= 2 * np.pi + # int_coord = np.append(int_coord, int_rot_angle1) + # if len(self.zmat.int6_indices): + # int_rot_angle2 = self.calc_tors(p6, p5, p4, p1) + # # int_rot_angle2 = self.calc_tors(p1, p4, p5, p6) + # if self.conv: + # condition_1 = float( + # self.zmat.variable_dictionary_final[self.zmat.int6_variables[i]] + # ) > 135.0 and (int_rot_angle2 * 180.0 / np.pi < -135.0) + # condition_2 = float( + # self.zmat.variable_dictionary_final[self.zmat.int6_variables[i]] + # ) < -135.0 and (int_rot_angle2 * 180.0 / np.pi > 135.0) + # if condition_1: + # int_rot_angle2 += 2 * np.pi + # if condition_2: + # int_rot_angle2 -= 2 * np.pi + # int_coord = np.append(int_coord, int_rot_angle2) + + # print(inter_distance) + # print(polar_angle1*180/np.pi) + # print(polar_angle2*180/np.pi) + # print(torsion_angle*180/np.pi) + # print(int_rot_angle1*180/np.pi) + # print(int_rot_angle2*180/np.pi) - # raise RuntimeError + # raise RuntimeError for i in range(len(self.zmat.angle_indices)): for j in self.zmat.angle_indices[i]: @@ -410,27 +418,32 @@ def int_c(self, carts, eig_inv, proj): if Len: angle_carts = [] for k in indies[0]: - angle_carts = np.append(angle_carts,np.array(carts[int(k) - 1]).astype(float)) + angle_carts = np.append( + angle_carts, np.array(carts[int(k) - 1]).astype(float) + ) angle_carts = np.reshape(angle_carts, (-1, 3)) x1 = self.calc_Centroid(angle_carts) - + angle_carts = [] for k in indies[1]: - angle_carts = np.append(angle_carts,np.array(carts[int(k) - 1]).astype(float)) + angle_carts = np.append( + angle_carts, np.array(carts[int(k) - 1]).astype(float) + ) angle_carts = np.reshape(angle_carts, (-1, 3)) x2 = self.calc_Centroid(angle_carts) - + angle_carts = [] for k in indies[2]: - angle_carts = np.append(angle_carts,np.array(carts[int(k) - 1]).astype(float)) + angle_carts = np.append( + angle_carts, np.array(carts[int(k) - 1]).astype(float) + ) angle_carts = np.reshape(angle_carts, (-1, 3)) x3 = self.calc_Centroid(angle_carts) else: x1 = np.array(carts[int(indies[0]) - 1]).astype(float) x2 = np.array(carts[int(indies[1]) - 1]).astype(float) x3 = np.array(carts[int(indies[2]) - 1]).astype(float) - - + a = self.calc_angle(x1, x2, x3) if self.conv: condition_1 = ( @@ -452,7 +465,7 @@ def int_c(self, carts, eig_inv, proj): if condition_1 or condition_2: a = 2 * np.pi - a int_coord = np.append(int_coord, a) - + for i in range(len(self.zmat.torsion_indices)): for j in self.zmat.torsion_indices[i]: Len = len(np.array(j).shape) @@ -460,32 +473,48 @@ def int_c(self, carts, eig_inv, proj): indies = self.zmat.torsion_indices[i] torsion_carts = [] for k in indies[0]: - torsion_carts = np.append(torsion_carts,np.array(carts[int(k) - 1]).astype(float)) + torsion_carts = np.append( + torsion_carts, np.array(carts[int(k) - 1]).astype(float) + ) torsion_carts = np.reshape(torsion_carts, (-1, 3)) x1 = self.calc_Centroid(torsion_carts) - + torsion_carts = [] for k in indies[1]: - torsion_carts = np.append(torsion_carts,np.array(carts[int(k) - 1]).astype(float)) + torsion_carts = np.append( + torsion_carts, np.array(carts[int(k) - 1]).astype(float) + ) torsion_carts = np.reshape(torsion_carts, (-1, 3)) x2 = self.calc_Centroid(torsion_carts) - + torsion_carts = [] for k in indies[2]: - torsion_carts = np.append(torsion_carts,np.array(carts[int(k) - 1]).astype(float)) + torsion_carts = np.append( + torsion_carts, np.array(carts[int(k) - 1]).astype(float) + ) torsion_carts = np.reshape(torsion_carts, (-1, 3)) x3 = self.calc_Centroid(torsion_carts) - + torsion_carts = [] for k in indies[3]: - torsion_carts = np.append(torsion_carts,np.array(carts[int(k) - 1]).astype(float)) + torsion_carts = np.append( + torsion_carts, np.array(carts[int(k) - 1]).astype(float) + ) torsion_carts = np.reshape(torsion_carts, (-1, 3)) x4 = self.calc_Centroid(torsion_carts) else: - x1 = np.array(carts[int(self.zmat.torsion_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.torsion_indices[i][1]) - 1]).astype(float) - x3 = np.array(carts[int(self.zmat.torsion_indices[i][2]) - 1]).astype(float) - x4 = np.array(carts[int(self.zmat.torsion_indices[i][3]) - 1]).astype(float) + x1 = np.array( + carts[int(self.zmat.torsion_indices[i][0]) - 1] + ).astype(float) + x2 = np.array( + carts[int(self.zmat.torsion_indices[i][1]) - 1] + ).astype(float) + x3 = np.array( + carts[int(self.zmat.torsion_indices[i][2]) - 1] + ).astype(float) + x4 = np.array( + carts[int(self.zmat.torsion_indices[i][3]) - 1] + ).astype(float) t = self.calc_tors(x1, x2, x3, x4) if self.conv: @@ -500,7 +529,7 @@ def int_c(self, carts, eig_inv, proj): if condition_2: t -= 2 * np.pi int_coord = np.append(int_coord, t) - + for i in range(len(self.zmat.oop_indices)): for j in self.zmat.oop_indices[i]: Len = len(np.array(j).shape) @@ -508,33 +537,49 @@ def int_c(self, carts, eig_inv, proj): indies = self.zmat.oop_indices[i] oop_carts = [] for k in indies[0]: - oop_carts = np.append(oop_carts,np.array(carts[int(k) - 1]).astype(float)) + oop_carts = np.append( + oop_carts, np.array(carts[int(k) - 1]).astype(float) + ) oop_carts = np.reshape(oop_carts, (-1, 3)) x1 = self.calc_Centroid(oop_carts) - + oop_carts = [] for k in indies[1]: - oop_carts = np.append(oop_carts,np.array(carts[int(k) - 1]).astype(float)) + oop_carts = np.append( + oop_carts, np.array(carts[int(k) - 1]).astype(float) + ) oop_carts = np.reshape(oop_carts, (-1, 3)) x2 = self.calc_Centroid(oop_carts) - + oop_carts = [] for k in indies[2]: - oop_carts = np.append(oop_carts,np.array(carts[int(k) - 1]).astype(float)) + oop_carts = np.append( + oop_carts, np.array(carts[int(k) - 1]).astype(float) + ) oop_carts = np.reshape(oop_carts, (-1, 3)) x3 = self.calc_Centroid(oop_carts) - + oop_carts = [] for k in indies[3]: - oop_carts = np.append(oop_carts,np.array(carts[int(k) - 1]).astype(float)) + oop_carts = np.append( + oop_carts, np.array(carts[int(k) - 1]).astype(float) + ) oop_carts = np.reshape(oop_carts, (-1, 3)) x4 = self.calc_Centroid(oop_carts) else: - x1 = np.array(carts[int(self.zmat.oop_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.oop_indices[i][1]) - 1]).astype(float) - x3 = np.array(carts[int(self.zmat.oop_indices[i][2]) - 1]).astype(float) - x4 = np.array(carts[int(self.zmat.oop_indices[i][3]) - 1]).astype(float) - + x1 = np.array(carts[int(self.zmat.oop_indices[i][0]) - 1]).astype( + float + ) + x2 = np.array(carts[int(self.zmat.oop_indices[i][1]) - 1]).astype( + float + ) + x3 = np.array(carts[int(self.zmat.oop_indices[i][2]) - 1]).astype( + float + ) + x4 = np.array(carts[int(self.zmat.oop_indices[i][3]) - 1]).astype( + float + ) + o = self.calc_OOP(x1, x2, x3, x4) if self.conv: condition_1 = ( @@ -563,32 +608,48 @@ def int_c(self, carts, eig_inv, proj): indies = self.zmat.lin_indices[i] lin_carts = [] for k in indies[0]: - lin_carts = np.append(lin_carts,np.array(carts[int(k) - 1]).astype(float)) + lin_carts = np.append( + lin_carts, np.array(carts[int(k) - 1]).astype(float) + ) lin_carts = np.reshape(lin_carts, (-1, 3)) x1 = self.calc_Centroid(lin_carts) - + lin_carts = [] for k in indies[1]: - lin_carts = np.append(lin_carts,np.array(carts[int(k) - 1]).astype(float)) + lin_carts = np.append( + lin_carts, np.array(carts[int(k) - 1]).astype(float) + ) lin_carts = np.reshape(lin_carts, (-1, 3)) x2 = self.calc_Centroid(lin_carts) - + lin_carts = [] for k in indies[2]: - lin_carts = np.append(lin_carts,np.array(carts[int(k) - 1]).astype(float)) + lin_carts = np.append( + lin_carts, np.array(carts[int(k) - 1]).astype(float) + ) lin_carts = np.reshape(lin_carts, (-1, 3)) x3 = self.calc_Centroid(lin_carts) - + lin_carts = [] for k in indies[3]: - lin_carts = np.append(lin_carts,np.array(carts[int(k) - 1]).astype(float)) + lin_carts = np.append( + lin_carts, np.array(carts[int(k) - 1]).astype(float) + ) lin_carts = np.reshape(lin_carts, (-1, 3)) x4 = self.calc_Centroid(lin_carts) else: - x1 = np.array(carts[int(self.zmat.lin_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.lin_indices[i][1]) - 1]).astype(float) - x3 = np.array(carts[int(self.zmat.lin_indices[i][2]) - 1]).astype(float) - x4 = np.array(carts[int(self.zmat.lin_indices[i][3]) - 1]).astype(float) + x1 = np.array(carts[int(self.zmat.lin_indices[i][0]) - 1]).astype( + float + ) + x2 = np.array(carts[int(self.zmat.lin_indices[i][1]) - 1]).astype( + float + ) + x3 = np.array(carts[int(self.zmat.lin_indices[i][2]) - 1]).astype( + float + ) + x4 = np.array(carts[int(self.zmat.lin_indices[i][3]) - 1]).astype( + float + ) l = self.calc_Lin(x1, x2, x3, x4) int_coord = np.append(int_coord, l) @@ -599,32 +660,48 @@ def int_c(self, carts, eig_inv, proj): indies = self.zmat.linx_indices[i] linx_carts = [] for k in indies[0]: - linx_carts = np.append(linx_carts,np.array(carts[int(k) - 1]).astype(float)) + linx_carts = np.append( + linx_carts, np.array(carts[int(k) - 1]).astype(float) + ) linx_carts = np.reshape(linx_carts, (-1, 3)) x1 = self.calc_Centroid(linx_carts) - + linx_carts = [] for k in indies[1]: - linx_carts = np.append(linx_carts,np.array(carts[int(k) - 1]).astype(float)) + linx_carts = np.append( + linx_carts, np.array(carts[int(k) - 1]).astype(float) + ) linx_carts = np.reshape(linx_carts, (-1, 3)) x2 = self.calc_Centroid(linx_carts) - + linx_carts = [] for k in indies[2]: - linx_carts = np.append(linx_carts,np.array(carts[int(k) - 1]).astype(float)) + linx_carts = np.append( + linx_carts, np.array(carts[int(k) - 1]).astype(float) + ) linx_carts = np.reshape(linx_carts, (-1, 3)) x3 = self.calc_Centroid(linx_carts) - + linx_carts = [] for k in indies[3]: - linx_carts = np.append(linx_carts,np.array(carts[int(k) - 1]).astype(float)) + linx_carts = np.append( + linx_carts, np.array(carts[int(k) - 1]).astype(float) + ) linx_carts = np.reshape(linx_carts, (-1, 3)) x4 = self.calc_Centroid(linx_carts) else: - x1 = np.array(carts[int(self.zmat.linx_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.linx_indices[i][1]) - 1]).astype(float) - x3 = np.array(carts[int(self.zmat.linx_indices[i][2]) - 1]).astype(float) - x4 = np.array(carts[int(self.zmat.linx_indices[i][3]) - 1]).astype(float) + x1 = np.array(carts[int(self.zmat.linx_indices[i][0]) - 1]).astype( + float + ) + x2 = np.array(carts[int(self.zmat.linx_indices[i][1]) - 1]).astype( + float + ) + x3 = np.array(carts[int(self.zmat.linx_indices[i][2]) - 1]).astype( + float + ) + x4 = np.array(carts[int(self.zmat.linx_indices[i][3]) - 1]).astype( + float + ) lx = self.calc_Linx(x1, x2, x3, x4) int_coord = np.append(int_coord, lx) @@ -635,38 +712,54 @@ def int_c(self, carts, eig_inv, proj): indies = self.zmat.liny_indices[i] liny_carts = [] for k in indies[0]: - liny_carts = np.append(liny_carts,np.array(carts[int(k) - 1]).astype(float)) + liny_carts = np.append( + liny_carts, np.array(carts[int(k) - 1]).astype(float) + ) liny_carts = np.reshape(liny_carts, (-1, 3)) x1 = self.calc_Centroid(liny_carts) - + liny_carts = [] for k in indies[1]: - liny_carts = np.append(liny_carts,np.array(carts[int(k) - 1]).astype(float)) + liny_carts = np.append( + liny_carts, np.array(carts[int(k) - 1]).astype(float) + ) liny_carts = np.reshape(liny_carts, (-1, 3)) x2 = self.calc_Centroid(liny_carts) - + liny_carts = [] for k in indies[2]: - liny_carts = np.append(liny_carts,np.array(carts[int(k) - 1]).astype(float)) + liny_carts = np.append( + liny_carts, np.array(carts[int(k) - 1]).astype(float) + ) liny_carts = np.reshape(liny_carts, (-1, 3)) x3 = self.calc_Centroid(liny_carts) - + liny_carts = [] for k in indies[3]: - liny_carts = np.append(liny_carts,np.array(carts[int(k) - 1]).astype(float)) + liny_carts = np.append( + liny_carts, np.array(carts[int(k) - 1]).astype(float) + ) liny_carts = np.reshape(liny_carts, (-1, 3)) x4 = self.calc_Centroid(liny_carts) else: - x1 = np.array(carts[int(self.zmat.liny_indices[i][0]) - 1]).astype(float) - x2 = np.array(carts[int(self.zmat.liny_indices[i][1]) - 1]).astype(float) - x3 = np.array(carts[int(self.zmat.liny_indices[i][2]) - 1]).astype(float) - x4 = np.array(carts[int(self.zmat.liny_indices[i][3]) - 1]).astype(float) + x1 = np.array(carts[int(self.zmat.liny_indices[i][0]) - 1]).astype( + float + ) + x2 = np.array(carts[int(self.zmat.liny_indices[i][1]) - 1]).astype( + float + ) + x3 = np.array(carts[int(self.zmat.liny_indices[i][2]) - 1]).astype( + float + ) + x4 = np.array(carts[int(self.zmat.liny_indices[i][3]) - 1]).astype( + float + ) ly = self.calc_Liny(x1, x2, x3, x4) int_coord = np.append(int_coord, ly) int_coord = np.dot(proj.T, int_coord) int_coord = np.dot(eig_inv, int_coord) - + return int_coord def calc_bond(self, x1, x2): diff --git a/concordantmodes/zmat.py b/concordantmodes/zmat.py index a840cce5..c7b8a5fe 100644 --- a/concordantmodes/zmat.py +++ b/concordantmodes/zmat.py @@ -66,13 +66,27 @@ def zmat_read(self, zmat_name): # Centroid regexes self.centroid_regex1 = re.compile(r";") self.centroid_regex2 = re.compile(r"\s*(\d+)") - self.bond_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)\n") - self.angle_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)\n") - self.torsion_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)T\s*\n") - self.oop_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)O\s*\n") - self.lin_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)L\s*\n") - self.linx_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)Lx\s*\n") - self.liny_centroid_regex = re.compile(r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)Ly\s*\n") + self.bond_centroid_regex = re.compile( + r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)\n" + ) + self.angle_centroid_regex = re.compile( + r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)\n" + ) + self.torsion_centroid_regex = re.compile( + r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)T\s*\n" + ) + self.oop_centroid_regex = re.compile( + r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)O\s*\n" + ) + self.lin_centroid_regex = re.compile( + r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)L\s*\n" + ) + self.linx_centroid_regex = re.compile( + r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)Lx\s*\n" + ) + self.liny_centroid_regex = re.compile( + r"^\s*(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)(;\s*(\d+\s+)*\d+\s*)Ly\s*\n" + ) # Cartesian regexes self.cart_begin_regex = re.compile(r"cart begin") @@ -508,7 +522,7 @@ def zmat_process(self, zmat_output): ListBuff = [] for j in List: if re.search(self.centroid_regex1, j): - SubList = re.findall(self.centroid_regex2,j) + SubList = re.findall(self.centroid_regex2, j) ListBuff.append(SubList) List = ListBuff @@ -527,7 +541,7 @@ def zmat_process(self, zmat_output): ListBuff = [] for j in List: if re.search(self.centroid_regex1, j): - SubList = re.findall(self.centroid_regex2,j) + SubList = re.findall(self.centroid_regex2, j) ListBuff.append(SubList) List = ListBuff self.angle_indices.append(List) @@ -545,7 +559,7 @@ def zmat_process(self, zmat_output): ListBuff = [] for j in List: if re.search(self.centroid_regex1, j): - SubList = re.findall(self.centroid_regex2,j) + SubList = re.findall(self.centroid_regex2, j) ListBuff.append(SubList) List = ListBuff self.torsion_indices.append(List) @@ -563,7 +577,7 @@ def zmat_process(self, zmat_output): ListBuff = [] for j in List: if re.search(self.centroid_regex1, j): - SubList = re.findall(self.centroid_regex2,j) + SubList = re.findall(self.centroid_regex2, j) ListBuff.append(SubList) List = ListBuff self.oop_indices.append(List) @@ -581,7 +595,7 @@ def zmat_process(self, zmat_output): ListBuff = [] for j in List: if re.search(self.centroid_regex1, j): - SubList = re.findall(self.centroid_regex2,j) + SubList = re.findall(self.centroid_regex2, j) ListBuff.append(SubList) List = ListBuff self.lin_indices.append(List) @@ -599,7 +613,7 @@ def zmat_process(self, zmat_output): ListBuff = [] for j in List: if re.search(self.centroid_regex1, j): - SubList = re.findall(self.centroid_regex2,j) + SubList = re.findall(self.centroid_regex2, j) ListBuff.append(SubList) List = ListBuff self.linx_indices.append(List) @@ -617,7 +631,7 @@ def zmat_process(self, zmat_output): ListBuff = [] for j in List: if re.search(self.centroid_regex1, j): - SubList = re.findall(self.centroid_regex2,j) + SubList = re.findall(self.centroid_regex2, j) ListBuff.append(SubList) List = ListBuff self.liny_indices.append(List) @@ -636,59 +650,59 @@ def zmat_process(self, zmat_output): "Rc" + str(i + 1 - Sum + len(self.rcom_variables)) ) # elif re.search(self.int1_regex, zmat_output[i]): - # List = re.findall(self.int1_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT1 List:") - # print(List) - # self.int1_indices.append(List) - # self.int1_variables.append( - # "I1_" + str(i + 1 - Sum + len(self.int1_variables)) - # ) + # List = re.findall(self.int1_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT1 List:") + # print(List) + # self.int1_indices.append(List) + # self.int1_variables.append( + # "I1_" + str(i + 1 - Sum + len(self.int1_variables)) + # ) # elif re.search(self.int2_regex, zmat_output[i]): - # List = re.findall(self.int2_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT2 List:") - # print(List) - # self.int2_indices.append(List) - # self.int2_variables.append( - # "I2_" + str(i + 1 - Sum + len(self.int2_variables)) - # ) + # List = re.findall(self.int2_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT2 List:") + # print(List) + # self.int2_indices.append(List) + # self.int2_variables.append( + # "I2_" + str(i + 1 - Sum + len(self.int2_variables)) + # ) # elif re.search(self.int3_regex, zmat_output[i]): - # List = re.findall(self.int3_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT3 List:") - # print(List) - # self.int3_indices.append(List) - # self.int3_variables.append( - # "I3_" + str(i + 1 - Sum + len(self.int3_variables)) - # ) + # List = re.findall(self.int3_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT3 List:") + # print(List) + # self.int3_indices.append(List) + # self.int3_variables.append( + # "I3_" + str(i + 1 - Sum + len(self.int3_variables)) + # ) # elif re.search(self.int4_regex, zmat_output[i]): - # List = re.findall(self.int4_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT4 List:") - # print(List) - # self.int4_indices.append(List) - # self.int4_variables.append( - # "I4_" + str(i + 1 - Sum + len(self.int4_variables)) - # ) + # List = re.findall(self.int4_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT4 List:") + # print(List) + # self.int4_indices.append(List) + # self.int4_variables.append( + # "I4_" + str(i + 1 - Sum + len(self.int4_variables)) + # ) # elif re.search(self.int5_regex, zmat_output[i]): - # List = re.findall(self.int5_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT5 List:") - # print(List) - # self.int5_indices.append(List) - # self.int5_variables.append( - # "I5_" + str(i + 1 - Sum + len(self.int5_variables)) - # ) + # List = re.findall(self.int5_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT5 List:") + # print(List) + # self.int5_indices.append(List) + # self.int5_variables.append( + # "I5_" + str(i + 1 - Sum + len(self.int5_variables)) + # ) # elif re.search(self.int6_regex, zmat_output[i]): - # List = re.findall(self.int6_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT6 List:") - # print(List) - # self.int6_indices.append(List) - # self.int6_variables.append( - # "I6_" + str(i + 1 - Sum + len(self.int6_variables)) - # ) + # List = re.findall(self.int6_regex, zmat_output[i])[0][0] + # List = List.split(" ")[1:] + # print("INT6 List:") + # print(List) + # self.int6_indices.append(List) + # self.int6_variables.append( + # "I6_" + str(i + 1 - Sum + len(self.int6_variables)) + # ) else: blank += 1 Sum = ( @@ -739,7 +753,7 @@ def zmat_calc(self): self.variables2 = transdisp.int_c(self.cartesians_final, I, I) # if len(self.int1_indices): - # self.int_frag_points = transdisp.int_frag_points + # self.int_frag_points = transdisp.int_frag_points # print(self.int_frag_points) # raise RuntimeError @@ -749,7 +763,7 @@ def zmat_calc(self): # + len(self.int4_indices) # + len(self.int5_indices) # + len(self.int6_indices) - + len(self.angle_indices) + +len(self.angle_indices) + len(self.torsion_indices) + len(self.oop_indices) + len(self.lin_indices) @@ -773,17 +787,17 @@ def zmat_calc(self): if len(self.rcom_variables): self.variables = np.append(self.variables, self.rcom_variables) # if len(self.int1_variables): - # self.variables = np.append(self.variables, self.int1_variables) + # self.variables = np.append(self.variables, self.int1_variables) # if len(self.int2_variables): - # self.variables = np.append(self.variables, self.int2_variables) + # self.variables = np.append(self.variables, self.int2_variables) # if len(self.int3_variables): - # self.variables = np.append(self.variables, self.int3_variables) + # self.variables = np.append(self.variables, self.int3_variables) # if len(self.int4_variables): - # self.variables = np.append(self.variables, self.int4_variables) + # self.variables = np.append(self.variables, self.int4_variables) # if len(self.int5_variables): - # self.variables = np.append(self.variables, self.int5_variables) + # self.variables = np.append(self.variables, self.int5_variables) # if len(self.int6_variables): - # self.variables = np.append(self.variables, self.int6_variables) + # self.variables = np.append(self.variables, self.int6_variables) if len(self.angle_variables): self.variables = np.append(self.variables, self.angle_variables) if len(self.torsion_variables): @@ -903,57 +917,57 @@ def zmat_compile(self): for i in range(len(self.bond_indices)): self.index_dictionary["R" + str(i + 1)] = self.bond_indices[i] # self.reduced_masses = np.append( - # self.reduced_masses, self.red_mass(self.bond_indices[i]) + # self.reduced_masses, self.red_mass(self.bond_indices[i]) # ) for i in range(len(self.angle_indices)): self.index_dictionary["A" + str(i + zmat_shift_a + 1)] = self.angle_indices[ i ] # self.reduced_masses = np.append( - # self.reduced_masses, self.red_mass(self.angle_indices[i]) + # self.reduced_masses, self.red_mass(self.angle_indices[i]) # ) for i in range(len(self.torsion_indices)): self.index_dictionary[ "D" + str(i + zmat_shift_d + 1) ] = self.torsion_indices[i] # self.reduced_masses = np.append( - # self.reduced_masses, self.red_mass(self.torsion_indices[i]) + # self.reduced_masses, self.red_mass(self.torsion_indices[i]) # ) for i in range(len(self.oop_indices)): self.index_dictionary["O" + str(i + 1)] = self.oop_indices[i] # self.reduced_masses = np.append( - # self.reduced_masses, self.red_mass(self.oop_indices[i]) + # self.reduced_masses, self.red_mass(self.oop_indices[i]) # ) for i in range(len(self.lin_indices)): self.index_dictionary["L" + str(i + 1)] = self.lin_indices[i] # self.reduced_masses = np.append( - # self.reduced_masses, self.red_mass(self.lin_indices[i]) + # self.reduced_masses, self.red_mass(self.lin_indices[i]) # ) for i in range(len(self.linx_indices)): self.index_dictionary["Lx" + str(i + 1)] = self.linx_indices[i] # self.reduced_masses = np.append( - # self.reduced_masses, self.red_mass(self.linx_indices[i]) + # self.reduced_masses, self.red_mass(self.linx_indices[i]) # ) for i in range(len(self.liny_indices)): self.index_dictionary["Ly" + str(i + 1)] = self.liny_indices[i] # self.reduced_masses = np.append( - # self.reduced_masses, self.red_mass(self.liny_indices[i]) + # self.reduced_masses, self.red_mass(self.liny_indices[i]) # ) for i in range(len(self.rcom_indices)): self.index_dictionary["Rc" + str(i + 1)] = self.rcom_indices[i] # for i in range(len(self.int1_indices)): - # self.index_dictionary["I1_" + str(i + 1)] = self.int1_indices[i] + # self.index_dictionary["I1_" + str(i + 1)] = self.int1_indices[i] # for i in range(len(self.int2_indices)): - # self.index_dictionary["I2_" + str(i + 1)] = self.int2_indices[i] + # self.index_dictionary["I2_" + str(i + 1)] = self.int2_indices[i] # for i in range(len(self.int3_indices)): - # self.index_dictionary["I3_" + str(i + 1)] = self.int3_indices[i] + # self.index_dictionary["I3_" + str(i + 1)] = self.int3_indices[i] # for i in range(len(self.int4_indices)): - # self.index_dictionary["I4_" + str(i + 1)] = self.int4_indices[i] + # self.index_dictionary["I4_" + str(i + 1)] = self.int4_indices[i] # for i in range(len(self.int5_indices)): - # self.index_dictionary["I5_" + str(i + 1)] = self.int5_indices[i] + # self.index_dictionary["I5_" + str(i + 1)] = self.int5_indices[i] # for i in range(len(self.int6_indices)): - # self.index_dictionary["I6_" + str(i + 1)] = self.int6_indices[i] + # self.index_dictionary["I6_" + str(i + 1)] = self.int6_indices[i] def zmat_print(self): # Print off the internal coordinate and its value in Bohr/Degree From 7e38d1d693fd6d31bc226f858bf5629f53fe5919 Mon Sep 17 00:00:00 2001 From: MitchLahm Date: Wed, 1 Nov 2023 16:56:00 -0400 Subject: [PATCH 3/4] removed some fat --- concordantmodes/s_vectors.py | 2 - concordantmodes/transf_disp.py | 147 --------------------------------- concordantmodes/zmat.py | 121 --------------------------- 3 files changed, 270 deletions(-) diff --git a/concordantmodes/s_vectors.py b/concordantmodes/s_vectors.py index 86736a43..f0b14435 100644 --- a/concordantmodes/s_vectors.py +++ b/concordantmodes/s_vectors.py @@ -340,8 +340,6 @@ def run(self, carts, B_proj, proj=None, second_order=False): self.s_4center_dict["L" + str(i + 1)][int(j) - 1] += l_3 / len( indies[2] ) - # for j in indies[3]: - # self.s_4center_dict["L" + str(i + 1)][int(j)-1] += l_4 / len(indies[3]) else: self.s_4center_dict["L" + str(i + 1)][int(indies[0]) - 1] = l_1 self.s_4center_dict["L" + str(i + 1)][int(indies[1]) - 1] = l_2 diff --git a/concordantmodes/transf_disp.py b/concordantmodes/transf_disp.py index ff542b37..f289ddc7 100644 --- a/concordantmodes/transf_disp.py +++ b/concordantmodes/transf_disp.py @@ -192,7 +192,6 @@ def run(self): "Only energy and gradient derivatives are supported. Check your deriv_level_init keyword." ) raise RuntimeError - # raise RuntimeError self.p_disp = p_disp self.m_disp = m_disp if self.options.reduced_disp: @@ -263,154 +262,8 @@ def int_c(self, carts, eig_inv, proj): mol1 = self.zmat.rcom_indices[i][0] mol2 = self.zmat.rcom_indices[i][1] rc = self.calc_Rcom(mol1, mol2, carts) - # raise RuntimeError int_coord = np.append(int_coord, rc) - # Prep interfragment coords here - # for i in range(len(self.zmat.int1_indices)): - # p1_points = np.array([]) - # for j in np.array(self.zmat.int1_indices[i]).astype(int): - # p1_points = np.append(p1_points, carts[j - 1]) - # p1_points = np.reshape(p1_points, (-1, 3)) - # p1 = self.calc_Centroid(p1_points) - # p2 = np.array([]) - # p3 = np.array([]) - # p4 = np.array([]) - # p5 = np.array([]) - # p6 = np.array([]) - # if len(self.zmat.int2_indices): - # p2_points = np.array([]) - # for j in np.array(self.zmat.int2_indices[i]).astype(int): - # p2_points = np.append(p2_points, carts[j - 1]) - # p2_points = np.reshape(p2_points, (-1, 3)) - # p2 = self.calc_Centroid(p2_points) - # if len(self.zmat.int3_indices): - # p3_points = np.array([]) - # for j in np.array(self.zmat.int3_indices[i]).astype(int): - # p3_points = np.append(p3_points, carts[j - 1]) - # p3_points = np.reshape(p3_points, (-1, 3)) - # p3 = self.calc_Centroid(p3_points) - # if len(self.zmat.int4_indices): - # p4_points = np.array([]) - # for j in np.array(self.zmat.int4_indices[i]).astype(int): - # p4_points = np.append(p4_points, carts[j - 1]) - # p4_points = np.reshape(p4_points, (-1, 3)) - # p4 = self.calc_Centroid(p4_points) - # if len(self.zmat.int5_indices): - # p5_points = np.array([]) - # for j in np.array(self.zmat.int5_indices[i]).astype(int): - # p5_points = np.append(p5_points, carts[j - 1]) - # p5_points = np.reshape(p5_points, (-1, 3)) - # p5 = self.calc_Centroid(p5_points) - # if len(self.zmat.int6_indices): - # p6_points = np.array([]) - # for j in np.array(self.zmat.int6_indices[i]).astype(int): - # p6_points = np.append(p6_points, carts[j - 1]) - # p6_points = np.reshape(p6_points, (-1, 3)) - # p6 = self.calc_Centroid(p6_points) - - # self.int_frag_points = np.array([p1, p2, p3, p4, p5, p6]) - - # inter_distance = self.calc_bond(p1, p4) - # int_coord = np.append(int_coord, inter_distance) - # if len(self.zmat.int2_indices): - # polar_angle1 = self.calc_angle(p2, p1, p4) - # if self.conv: - # condition_1 = ( - # float( - # self.zmat.variable_dictionary_final[ - # self.zmat.int2_variables[i] - # ] - # ) - # > 180.0 - # ) - # condition_2 = ( - # float( - # self.zmat.variable_dictionary_final[ - # self.zmat.int2_variables[i] - # ] - # ) - # < 0.0 - # ) - # if condition_1 or condition_2: - # polar_angle1 = 2 * np.pi - polar_angle1 - # int_coord = np.append(int_coord, polar_angle1) - # if len(self.zmat.int5_indices): - # polar_angle2 = self.calc_angle(p5, p4, p1) - # if self.conv: - # condition_1 = ( - # float( - # self.zmat.variable_dictionary_final[ - # self.zmat.int3_variables[i] - # ] - # ) - # > 180.0 - # ) - # condition_2 = ( - # float( - # self.zmat.variable_dictionary_final[ - # self.zmat.int3_variables[i] - # ] - # ) - # < 0.0 - # ) - # if condition_1 or condition_2: - # polar_angle2 = 2 * np.pi - polar_angle2 - # int_coord = np.append(int_coord, polar_angle2) - # if len(self.zmat.int5_indices): - # torsion_angle = self.calc_tors(p2, p1, p4, p5) - # if self.conv: - # condition_1 = float( - # self.zmat.variable_dictionary_final[self.zmat.int4_variables[i]] - # ) > 135.0 and (torsion_angle * 180.0 / np.pi < -135.0) - # condition_2 = float( - # self.zmat.variable_dictionary_final[self.zmat.int4_variables[i]] - # ) < -135.0 and (torsion_angle * 180.0 / np.pi > 135.0) - # if condition_1: - # torsion_angle += 2 * np.pi - # if condition_2: - # torsion_angle -= 2 * np.pi - # int_coord = np.append(int_coord, torsion_angle) - # if len(self.zmat.int3_indices): - # int_rot_angle1 = self.calc_tors(p3, p2, p1, p4) - # # int_rot_angle1 = self.calc_tors(p4, p1, p2, p3) - # if self.conv: - # condition_1 = float( - # self.zmat.variable_dictionary_final[self.zmat.int5_variables[i]] - # ) > 135.0 and (int_rot_angle1 * 180.0 / np.pi < -135.0) - # condition_2 = float( - # self.zmat.variable_dictionary_final[self.zmat.int5_variables[i]] - # ) < -135.0 and (int_rot_angle1 * 180.0 / np.pi > 135.0) - # if condition_1: - # int_rot_angle1 += 2 * np.pi - # if condition_2: - # int_rot_angle1 -= 2 * np.pi - # int_coord = np.append(int_coord, int_rot_angle1) - # if len(self.zmat.int6_indices): - # int_rot_angle2 = self.calc_tors(p6, p5, p4, p1) - # # int_rot_angle2 = self.calc_tors(p1, p4, p5, p6) - # if self.conv: - # condition_1 = float( - # self.zmat.variable_dictionary_final[self.zmat.int6_variables[i]] - # ) > 135.0 and (int_rot_angle2 * 180.0 / np.pi < -135.0) - # condition_2 = float( - # self.zmat.variable_dictionary_final[self.zmat.int6_variables[i]] - # ) < -135.0 and (int_rot_angle2 * 180.0 / np.pi > 135.0) - # if condition_1: - # int_rot_angle2 += 2 * np.pi - # if condition_2: - # int_rot_angle2 -= 2 * np.pi - # int_coord = np.append(int_coord, int_rot_angle2) - - # print(inter_distance) - # print(polar_angle1*180/np.pi) - # print(polar_angle2*180/np.pi) - # print(torsion_angle*180/np.pi) - # print(int_rot_angle1*180/np.pi) - # print(int_rot_angle2*180/np.pi) - - # raise RuntimeError - for i in range(len(self.zmat.angle_indices)): for j in self.zmat.angle_indices[i]: Len = len(np.array(j).shape) diff --git a/concordantmodes/zmat.py b/concordantmodes/zmat.py index c7b8a5fe..dcb20484 100644 --- a/concordantmodes/zmat.py +++ b/concordantmodes/zmat.py @@ -56,12 +56,6 @@ def zmat_read(self, zmat_name): self.liny_regex = re.compile(r"^\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s*Ly\s*\n") self.rcom_regex1 = re.compile(r";\s*((\d+\s+)+)\s*;\s*((\d+\s+)+)\s*Rc") self.rcom_regex2 = re.compile(r"\s*(\d+)") - # self.int1_regex = re.compile(r"((\s+\d+)+)\s*I1") - # self.int2_regex = re.compile(r"((\s+\d+)+)\s*I2") - # self.int3_regex = re.compile(r"((\s+\d+)+)\s*I3") - # self.int4_regex = re.compile(r"((\s+\d+)+)\s*I4") - # self.int5_regex = re.compile(r"((\s+\d+)+)\s*I5") - # self.int6_regex = re.compile(r"((\s+\d+)+)\s*I6") # Centroid regexes self.centroid_regex1 = re.compile(r";") @@ -197,18 +191,6 @@ def zmat_process(self, zmat_output): self.liny_variables = [] self.rcom_indices = [] self.rcom_variables = [] - # self.int1_indices = [] - # self.int1_variables = [] - # self.int2_indices = [] - # self.int2_variables = [] - # self.int3_indices = [] - # self.int3_variables = [] - # self.int4_indices = [] - # self.int4_variables = [] - # self.int5_indices = [] - # self.int5_variables = [] - # self.int6_indices = [] - # self.int6_variables = [] self.variable_dictionary_init = {} self.variable_dictionary_final = {} self.index_dictionary = {} @@ -649,60 +631,6 @@ def zmat_process(self, zmat_output): self.rcom_variables.append( "Rc" + str(i + 1 - Sum + len(self.rcom_variables)) ) - # elif re.search(self.int1_regex, zmat_output[i]): - # List = re.findall(self.int1_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT1 List:") - # print(List) - # self.int1_indices.append(List) - # self.int1_variables.append( - # "I1_" + str(i + 1 - Sum + len(self.int1_variables)) - # ) - # elif re.search(self.int2_regex, zmat_output[i]): - # List = re.findall(self.int2_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT2 List:") - # print(List) - # self.int2_indices.append(List) - # self.int2_variables.append( - # "I2_" + str(i + 1 - Sum + len(self.int2_variables)) - # ) - # elif re.search(self.int3_regex, zmat_output[i]): - # List = re.findall(self.int3_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT3 List:") - # print(List) - # self.int3_indices.append(List) - # self.int3_variables.append( - # "I3_" + str(i + 1 - Sum + len(self.int3_variables)) - # ) - # elif re.search(self.int4_regex, zmat_output[i]): - # List = re.findall(self.int4_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT4 List:") - # print(List) - # self.int4_indices.append(List) - # self.int4_variables.append( - # "I4_" + str(i + 1 - Sum + len(self.int4_variables)) - # ) - # elif re.search(self.int5_regex, zmat_output[i]): - # List = re.findall(self.int5_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT5 List:") - # print(List) - # self.int5_indices.append(List) - # self.int5_variables.append( - # "I5_" + str(i + 1 - Sum + len(self.int5_variables)) - # ) - # elif re.search(self.int6_regex, zmat_output[i]): - # List = re.findall(self.int6_regex, zmat_output[i])[0][0] - # List = List.split(" ")[1:] - # print("INT6 List:") - # print(List) - # self.int6_indices.append(List) - # self.int6_variables.append( - # "I6_" + str(i + 1 - Sum + len(self.int6_variables)) - # ) else: blank += 1 Sum = ( @@ -714,12 +642,6 @@ def zmat_process(self, zmat_output): + len(self.linx_variables) + len(self.liny_variables) + len(self.rcom_variables) - # + len(self.int1_variables) - # + len(self.int2_variables) - # + len(self.int3_variables) - # + len(self.int4_variables) - # + len(self.int5_variables) - # + len(self.int6_variables) + blank ) @@ -735,12 +657,6 @@ def zmat_calc(self): I = np.eye( len(self.bond_indices) + len(self.rcom_indices) - # + len(self.int1_indices) - # + len(self.int2_indices) - # + len(self.int3_indices) - # + len(self.int4_indices) - # + len(self.int5_indices) - # + len(self.int6_indices) + len(self.angle_indices) + len(self.torsion_indices) + len(self.oop_indices) @@ -752,52 +668,28 @@ def zmat_calc(self): self.variables1 = transdisp.int_c(self.cartesians_init, I, I) self.variables2 = transdisp.int_c(self.cartesians_final, I, I) - # if len(self.int1_indices): - # self.int_frag_points = transdisp.int_frag_points - # print(self.int_frag_points) - # raise RuntimeError for i in range( - # len(self.int2_indices) - # + len(self.int3_indices) - # + len(self.int4_indices) - # + len(self.int5_indices) - # + len(self.int6_indices) +len(self.angle_indices) + len(self.torsion_indices) + len(self.oop_indices) + len(self.lin_indices) + len(self.linx_indices) + len(self.liny_indices) - # - 1 ): self.variables1[ len(self.bond_indices) + len(self.rcom_indices) - # + len(self.int1_indices) + i ] *= (180.0 / np.pi) self.variables2[ len(self.bond_indices) + len(self.rcom_indices) - # + len(self.int1_indices) + i ] *= (180.0 / np.pi) self.variables = np.array(self.bond_variables) if len(self.rcom_variables): self.variables = np.append(self.variables, self.rcom_variables) - # if len(self.int1_variables): - # self.variables = np.append(self.variables, self.int1_variables) - # if len(self.int2_variables): - # self.variables = np.append(self.variables, self.int2_variables) - # if len(self.int3_variables): - # self.variables = np.append(self.variables, self.int3_variables) - # if len(self.int4_variables): - # self.variables = np.append(self.variables, self.int4_variables) - # if len(self.int5_variables): - # self.variables = np.append(self.variables, self.int5_variables) - # if len(self.int6_variables): - # self.variables = np.append(self.variables, self.int6_variables) if len(self.angle_variables): self.variables = np.append(self.variables, self.angle_variables) if len(self.torsion_variables): @@ -956,19 +848,6 @@ def zmat_compile(self): for i in range(len(self.rcom_indices)): self.index_dictionary["Rc" + str(i + 1)] = self.rcom_indices[i] - # for i in range(len(self.int1_indices)): - # self.index_dictionary["I1_" + str(i + 1)] = self.int1_indices[i] - # for i in range(len(self.int2_indices)): - # self.index_dictionary["I2_" + str(i + 1)] = self.int2_indices[i] - # for i in range(len(self.int3_indices)): - # self.index_dictionary["I3_" + str(i + 1)] = self.int3_indices[i] - # for i in range(len(self.int4_indices)): - # self.index_dictionary["I4_" + str(i + 1)] = self.int4_indices[i] - # for i in range(len(self.int5_indices)): - # self.index_dictionary["I5_" + str(i + 1)] = self.int5_indices[i] - # for i in range(len(self.int6_indices)): - # self.index_dictionary["I6_" + str(i + 1)] = self.int6_indices[i] - def zmat_print(self): # Print off the internal coordinate and its value in Bohr/Degree print("Initial Geometric Internal Coordinate Values:") From cc3a26298ff2ad354e53a8fdc87e58b8f3f7a06c Mon Sep 17 00:00:00 2001 From: MitchLahm Date: Thu, 2 Nov 2023 11:55:16 -0400 Subject: [PATCH 4/4] Updated Black --- concordantmodes/algorithm.py | 2 - concordantmodes/force_constant.py | 2 +- concordantmodes/reap.py | 1 - concordantmodes/rmsd.py | 195 +++++++++++++++--------------- concordantmodes/s_vectors.py | 1 - concordantmodes/ted.py | 1 - concordantmodes/transf_disp.py | 1 - concordantmodes/zmat.py | 18 +-- 8 files changed, 104 insertions(+), 117 deletions(-) diff --git a/concordantmodes/algorithm.py b/concordantmodes/algorithm.py index 75abaf49..5e95435d 100644 --- a/concordantmodes/algorithm.py +++ b/concordantmodes/algorithm.py @@ -13,7 +13,6 @@ class Algorithm(object): """ def __init__(self, eigs, initial_fc, options): - self.eigs = eigs self.options = options self.initial_fc = initial_fc @@ -42,7 +41,6 @@ def run(self): self.indices = self.loop(a, off_diag, lim) def loop(self, a, off_diag, lim): - a = self.eigs indices = [] Sum = 2 diff --git a/concordantmodes/force_constant.py b/concordantmodes/force_constant.py index 0f053349..7548795a 100644 --- a/concordantmodes/force_constant.py +++ b/concordantmodes/force_constant.py @@ -77,7 +77,7 @@ def first_deriv(self): # Functions for computing the diagonal and off-diagonal force constants def diag_fc(self, e_p, e_m, e_r, disp): - fc = (e_p - 2 * e_r + e_m) / (disp ** 2) + fc = (e_p - 2 * e_r + e_m) / (disp**2) return fc def off_diag_fc(self, e_pp, e_pi, e_pj, e_mi, e_mj, e_mm, e_r, disp1, disp2): diff --git a/concordantmodes/reap.py b/concordantmodes/reap.py index 34fcaa2e..4c329b00 100644 --- a/concordantmodes/reap.py +++ b/concordantmodes/reap.py @@ -273,7 +273,6 @@ def reap_molly(self, direc, molly1_regex, molly2_regex): for i, initial in enumerate(molly_init): for j, final in enumerate(molly_array): if sum(np.abs(initial - final)) < 1e-6: - rearrange.append(j) os.chdir("..") return rearrange, insertion diff --git a/concordantmodes/rmsd.py b/concordantmodes/rmsd.py index 8b7f58be..485dcfd2 100644 --- a/concordantmodes/rmsd.py +++ b/concordantmodes/rmsd.py @@ -166,24 +166,24 @@ def handwritten_hess(self, mol1, mol2, n): * ( -K3 * A * B + K2 * A * G - + K2 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + K3 * G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + K2 * B * np.sqrt(1 - A**2 - B**2 - G**2) + + K3 * G * np.sqrt(1 - A**2 - B**2 - G**2) ) + c2 * ( K1 * A * G - + 2 * K2 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - - K1 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - - K3 * (-1 + 2 * A ** 2 + B ** 2 + G ** 2) + + 2 * K2 * A * np.sqrt(1 - A**2 - B**2 - G**2) + - K1 * B * np.sqrt(1 - A**2 - B**2 - G**2) + - K3 * (-1 + 2 * A**2 + B**2 + G**2) ) + c3 * ( - 2 * K3 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + K2 * (-1 + 2 * A ** 2 + B ** 2 + G ** 2) - - K1 * (A * B + G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2)) + 2 * K3 * A * np.sqrt(1 - A**2 - B**2 - G**2) + + K2 * (-1 + 2 * A**2 + B**2 + G**2) + - K1 * (A * B + G * np.sqrt(1 - A**2 - B**2 - G**2)) ) ) - ) / np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + ) / np.sqrt(1 - A**2 - B**2 - G**2) grad1 += -( 4 @@ -192,25 +192,25 @@ def handwritten_hess(self, mol1, mol2, n): * ( K3 * A * B - K1 * B * G - + K1 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + K3 * G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + K1 * A * np.sqrt(1 - A**2 - B**2 - G**2) + + K3 * G * np.sqrt(1 - A**2 - B**2 - G**2) ) + c3 * ( -K2 * A * B - - 2 * K3 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + K2 * G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + K1 * (-1 + 2 * A ** 2 + B ** 2 + G ** 2) + - 2 * K3 * B * np.sqrt(1 - A**2 - B**2 - G**2) + + K2 * G * np.sqrt(1 - A**2 - B**2 - G**2) + + K1 * (-1 + 2 * A**2 + B**2 + G**2) ) + c1 * ( K2 * B * G - + K2 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - - 2 * K1 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - - K3 * (-1 + A ** 2 - 2 * B ** 2 + G ** 2) + + K2 * A * np.sqrt(1 - A**2 - B**2 - G**2) + - 2 * K1 * B * np.sqrt(1 - A**2 - B**2 - G**2) + - K3 * (-1 + A**2 - 2 * B**2 + G**2) ) ) - ) / np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + ) / np.sqrt(1 - A**2 - B**2 - G**2) grad2 += -( 4 @@ -219,180 +219,180 @@ def handwritten_hess(self, mol1, mol2, n): * ( -K2 * A * G + K1 * B * G - + K1 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + K2 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + + K1 * A * np.sqrt(1 - A**2 - B**2 - G**2) + + K2 * B * np.sqrt(1 - A**2 - B**2 - G**2) ) + c2 * ( K3 * A * G - + K3 * B * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - - 2 * K2 * G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - - K1 * (-1 + A ** 2 + B ** 2 + 2 * G ** 2) + + K3 * B * np.sqrt(1 - A**2 - B**2 - G**2) + - 2 * K2 * G * np.sqrt(1 - A**2 - B**2 - G**2) + - K1 * (-1 + A**2 + B**2 + 2 * G**2) ) + c1 * ( -K3 * B * G - + K3 * A * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - - 2 * K1 * G * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + K2 * (-1 + A ** 2 + B ** 2 + 2 * G ** 2) + + K3 * A * np.sqrt(1 - A**2 - B**2 - G**2) + - 2 * K1 * G * np.sqrt(1 - A**2 - B**2 - G**2) + + K2 * (-1 + A**2 + B**2 + 2 * G**2) ) ) - ) / np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) + ) / np.sqrt(1 - A**2 - B**2 - G**2) hess00 += -( ( 4 * ( - c1 * (K3 * B - K2 * G) * (-1 + B ** 2 + G ** 2) + c1 * (K3 * B - K2 * G) * (-1 + B**2 + G**2) + c3 * ( - 2 * K2 * A ** 3 - - 2 * K3 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) - + 3 * K2 * A * (-1 + B ** 2 + G ** 2) - - K1 * B * (-1 + B ** 2 + G ** 2) + 2 * K2 * A**3 + - 2 * K3 * (1 - A**2 - B**2 - G**2) ** (3 / 2) + + 3 * K2 * A * (-1 + B**2 + G**2) + - K1 * B * (-1 + B**2 + G**2) ) + c2 * ( - -2 * K3 * A ** 3 - - 2 * K2 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) - - 3 * K3 * A * (-1 + B ** 2 + G ** 2) - + K1 * G * (-1 + B ** 2 + G ** 2) + -2 * K3 * A**3 + - 2 * K2 * (1 - A**2 - B**2 - G**2) ** (3 / 2) + - 3 * K3 * A * (-1 + B**2 + G**2) + + K1 * G * (-1 + B**2 + G**2) ) ) ) - / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + / (1 - A**2 - B**2 - G**2) ** (3 / 2) ) hess01 += ( 4 * ( - -c1 * K3 * A * (-1 + A ** 2 + G ** 2) - + c2 * K3 * B * (-1 + B ** 2 + G ** 2) + -c1 * K3 * A * (-1 + A**2 + G**2) + + c2 * K3 * B * (-1 + B**2 + G**2) + c3 * ( - K1 * A * (-1 + A ** 2 + G ** 2) - - K2 * B * (-1 + B ** 2 + G ** 2) + K1 * A * (-1 + A**2 + G**2) + - K2 * B * (-1 + B**2 + G**2) ) + c1 * K2 * ( -A * B * G - + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - * (-1 + B ** 2 + G ** 2) + + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) + + np.sqrt(1 - A**2 - B**2 - G**2) + * (-1 + B**2 + G**2) ) + c2 * K1 * ( A * B * G - + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - * (-1 + B ** 2 + G ** 2) + + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) + + np.sqrt(1 - A**2 - B**2 - G**2) + * (-1 + B**2 + G**2) ) ) - ) / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + ) / (1 - A**2 - B**2 - G**2) ** (3 / 2) hess02 += ( 4 * ( - c1 * K2 * A * (-1 + A ** 2 + B ** 2) - - c3 * K2 * G * (-1 + B ** 2 + G ** 2) + c1 * K2 * A * (-1 + A**2 + B**2) + - c3 * K2 * G * (-1 + B**2 + G**2) + c2 * ( - -K1 * A * (-1 + A ** 2 + B ** 2) - - K3 * G * (-1 + B ** 2 + G ** 2) + -K1 * A * (-1 + A**2 + B**2) + - K3 * G * (-1 + B**2 + G**2) ) + c3 * K1 * ( -A * B * G - + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - * (-1 + B ** 2 + G ** 2) + + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) + + np.sqrt(1 - A**2 - B**2 - G**2) + * (-1 + B**2 + G**2) ) + c1 * K3 * ( A * B * G - + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - * (-1 + B ** 2 + G ** 2) + + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) + + np.sqrt(1 - A**2 - B**2 - G**2) + * (-1 + B**2 + G**2) ) ) - ) / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + ) / (1 - A**2 - B**2 - G**2) ** (3 / 2) hess11 += -( ( 4 * ( - -c2 * (K3 * A - K1 * G) * (-1 + A ** 2 + G ** 2) + -c2 * (K3 * A - K1 * G) * (-1 + A**2 + G**2) + c3 * ( - -2 * K3 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) - + K2 * A * (-1 + A ** 2 + G ** 2) - - K1 * B * (-3 + 3 * A ** 2 + 2 * B ** 2 + 3 * G ** 2) + -2 * K3 * (1 - A**2 - B**2 - G**2) ** (3 / 2) + + K2 * A * (-1 + A**2 + G**2) + - K1 * B * (-3 + 3 * A**2 + 2 * B**2 + 3 * G**2) ) + c1 * ( - -2 * K1 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) - - K2 * G * (-1 + A ** 2 + G ** 2) - + K3 * B * (-3 + 3 * A ** 2 + 2 * B ** 2 + 3 * G ** 2) + -2 * K1 * (1 - A**2 - B**2 - G**2) ** (3 / 2) + - K2 * G * (-1 + A**2 + G**2) + + K3 * B * (-3 + 3 * A**2 + 2 * B**2 + 3 * G**2) ) ) ) - / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + / (1 - A**2 - B**2 - G**2) ** (3 / 2) ) hess12 += ( 4 * ( - c1 * K2 * B * (-1 + A ** 2 + B ** 2) - + c3 * K1 * G * (-1 + A ** 2 + G ** 2) - - c1 * K3 * G * (-1 + A ** 2 + G ** 2) + c1 * K2 * B * (-1 + A**2 + B**2) + + c3 * K1 * G * (-1 + A**2 + G**2) + - c1 * K3 * G * (-1 + A**2 + G**2) + c3 * K2 * ( A * B * G - + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - * (-1 + B ** 2 + G ** 2) + + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) + + np.sqrt(1 - A**2 - B**2 - G**2) + * (-1 + B**2 + G**2) ) + c2 * ( - -K1 * B * (-1 + A ** 2 + B ** 2) + -K1 * B * (-1 + A**2 + B**2) + K3 * ( -A * B * G - + (A ** 2) * np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - + np.sqrt(1 - A ** 2 - B ** 2 - G ** 2) - * (-1 + B ** 2 + G ** 2) + + (A**2) * np.sqrt(1 - A**2 - B**2 - G**2) + + np.sqrt(1 - A**2 - B**2 - G**2) + * (-1 + B**2 + G**2) ) ) ) - ) / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + ) / (1 - A**2 - B**2 - G**2) ** (3 / 2) hess22 += -( ( 4 * ( - c3 * (K2 * A - K1 * B) * (-1 + A ** 2 + B ** 2) + c3 * (K2 * A - K1 * B) * (-1 + A**2 + B**2) + c1 * ( - K3 * B * (-1 + A ** 2 + B ** 2) - - 3 * K2 * (-1 + A ** 2 + B ** 2) * G - - 2 * K2 * G ** 3 - - 2 * K1 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + K3 * B * (-1 + A**2 + B**2) + - 3 * K2 * (-1 + A**2 + B**2) * G + - 2 * K2 * G**3 + - 2 * K1 * (1 - A**2 - B**2 - G**2) ** (3 / 2) ) + c2 * ( - -K3 * A * (-1 + A ** 2 + B ** 2) - + 3 * K1 * (-1 + A ** 2 + B ** 2) * G - + 2 * K1 * G ** 3 - - 2 * K2 * (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + -K3 * A * (-1 + A**2 + B**2) + + 3 * K1 * (-1 + A**2 + B**2) * G + + 2 * K1 * G**3 + - 2 * K2 * (1 - A**2 - B**2 - G**2) ** (3 / 2) ) ) ) - / (1 - A ** 2 - B ** 2 - G ** 2) ** (3 / 2) + / (1 - A**2 - B**2 - G**2) ** (3 / 2) ) grud = np.array([grad0, grad1, grad2]) huss = np.array( @@ -404,7 +404,6 @@ def handwritten_hess(self, mol1, mol2, n): ) bars = np.dot(grud, np.linalg.inv(huss)) if self.norm(grud) < 1e-12: - print("Optimization of Euler-angles optimization has converged") print(f"Norm of gradient is {self.norm(grud)}") break @@ -421,19 +420,19 @@ def derive_opt_rotate(self, mol1_rot, mol2_rot, n): # , oilrod): rot_matrix = np.array( [ [ - 1 - 2 * b ** 2 - 2 * c ** 2, - 2 * (a * b + c * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), - 2 * (a * c - b * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), + 1 - 2 * b**2 - 2 * c**2, + 2 * (a * b + c * np.sqrt(1 - a**2 - b**2 - c**2)), + 2 * (a * c - b * np.sqrt(1 - a**2 - b**2 - c**2)), ], [ - 2 * (a * b - c * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), - 1 - 2 * a ** 2 - 2 * c ** 2, - 2 * (b * c + a * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), + 2 * (a * b - c * np.sqrt(1 - a**2 - b**2 - c**2)), + 1 - 2 * a**2 - 2 * c**2, + 2 * (b * c + a * np.sqrt(1 - a**2 - b**2 - c**2)), ], [ - 2 * (a * c + b * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), - 2 * (b * c - a * np.sqrt(1 - a ** 2 - b ** 2 - c ** 2)), - 1 - 2 * a ** 2 - 2 * b ** 2, + 2 * (a * c + b * np.sqrt(1 - a**2 - b**2 - c**2)), + 2 * (b * c - a * np.sqrt(1 - a**2 - b**2 - c**2)), + 1 - 2 * a**2 - 2 * b**2, ], ] ) diff --git a/concordantmodes/s_vectors.py b/concordantmodes/s_vectors.py index f0b14435..d70805b3 100644 --- a/concordantmodes/s_vectors.py +++ b/concordantmodes/s_vectors.py @@ -723,7 +723,6 @@ def compute_r(self, x1, x2): return r def compute_phi(self, e_1, e_2): - p = np.dot(e_1, e_2) if p > 1: p = 1 diff --git a/concordantmodes/ted.py b/concordantmodes/ted.py index 2ce23d8b..4db7be69 100644 --- a/concordantmodes/ted.py +++ b/concordantmodes/ted.py @@ -16,7 +16,6 @@ def __init__(self, proj, zmat): self.zmat = zmat def run(self, eigs, freq, rect_print=True): - proj_eigs = eigs if len(np.shape(self.proj)) > 2 and np.shape(self.proj)[0] > 1: proj_buff = self.proj[0] diff --git a/concordantmodes/transf_disp.py b/concordantmodes/transf_disp.py index f289ddc7..44887e92 100644 --- a/concordantmodes/transf_disp.py +++ b/concordantmodes/transf_disp.py @@ -63,7 +63,6 @@ def __init__( self.coord_type = coord_type def run(self): - self.B = self.s_vectors.B.copy() # (redundant internals (s) x cartesians (3N)) # Invert the L-matrix and then normalize the rows. proj_tol = 1.0e-3 diff --git a/concordantmodes/zmat.py b/concordantmodes/zmat.py index dcb20484..968e90db 100644 --- a/concordantmodes/zmat.py +++ b/concordantmodes/zmat.py @@ -16,7 +16,6 @@ def __init__(self, options): self.Bohr_Ang = 0.529177210903 def run(self, zmat_name="zmat"): - # Read in the ZMAT file zmat_output = self.zmat_read(zmat_name) @@ -668,7 +667,6 @@ def zmat_calc(self): self.variables1 = transdisp.int_c(self.cartesians_init, I, I) self.variables2 = transdisp.int_c(self.cartesians_final, I, I) - for i in range( +len(self.angle_indices) + len(self.torsion_indices) @@ -677,16 +675,12 @@ def zmat_calc(self): + len(self.linx_indices) + len(self.liny_indices) ): - self.variables1[ - len(self.bond_indices) - + len(self.rcom_indices) - + i - ] *= (180.0 / np.pi) - self.variables2[ - len(self.bond_indices) - + len(self.rcom_indices) - + i - ] *= (180.0 / np.pi) + self.variables1[len(self.bond_indices) + len(self.rcom_indices) + i] *= ( + 180.0 / np.pi + ) + self.variables2[len(self.bond_indices) + len(self.rcom_indices) + i] *= ( + 180.0 / np.pi + ) self.variables = np.array(self.bond_variables) if len(self.rcom_variables): self.variables = np.append(self.variables, self.rcom_variables)