def correlate_xccs(xcc_t,symbols_t,xcc_0,symbols_0,fconnect=1.3,pp=False): ''' xcc_0 --> geometry xcc_t --> enantiomer ''' if len(xcc_0) != len(xcc_t) : raise Exception if len(xcc_0) != len(symbols_0)*3: raise Exception # Adjacency matrices amatrix_0 = np.matrix(intl.get_adjmatrix(xcc_0,symbols_0,fconnect,"int")[0]) amatrix_t = np.matrix(intl.get_adjmatrix(xcc_t,symbols_t,fconnect,"int")[0]) # autoconnect! amatrix_0 = np.matrix(intl.link_fragments(xcc_0,amatrix_0.tolist(),1)[0]) amatrix_t = np.matrix(intl.link_fragments(xcc_t,amatrix_t.tolist(),1)[0]) # correlate amatrices dcorr = correlate_amatrices(amatrix_t,amatrix_0,symbols_t,symbols_0,xcc_t,xcc_0) if pp: print("forced: %i"%nforce) assign_print(dcorr) return dcorr
def correlate_enantio(xcc1, xcc2, symbols, fconnect=1.3, pp=False): ''' xcc1 --> geometry xcc2 --> enantiomer ''' if len(xcc1) != len(xcc2): raise Exception if len(xcc1) != len(symbols) * 3: raise Exception # Adjacency matrices amatrix1 = np.matrix(intl.get_adjmatrix(xcc1, symbols, fconnect, "int")[0]) amatrix2 = np.matrix(intl.get_adjmatrix(xcc2, symbols, fconnect, "int")[0]) # autoconnect! amatrix1 = np.matrix(intl.link_fragments(xcc1, amatrix1.tolist(), 1)[0]) amatrix2 = np.matrix(intl.link_fragments(xcc2, amatrix2.tolist(), 1)[0]) # Graphs graph1 = UGRAPH() graph1.set_from_amatrix(amatrix1) graph2 = UGRAPH() graph2.set_from_amatrix(amatrix2) # Correlations dcorr, na_0 = assign_initialize(symbols) nforce = 0 for ii in range(10): # it should be a while True but... just in case # use symbols of neighbors dcorr, na_1 = assign_neighbors(dcorr, graph1, graph2, symbols) if na_1 == 0: break # use symbols of layers dcorr, na_2 = assign_layers(dcorr, graph1, graph2, symbols) if na_2 == 0: break # use spatial disposition dcorr, na_3 = assign_spatial(dcorr, graph1, graph2, xcc1, xcc2, symbols) if na_3 == 0: break # assign CX3 groups dcorr, na_4 = assign_cx3(dcorr, graph1, graph2, xcc1, xcc2, symbols) if na_4 == 0: break # assign based on torsions dcorr, na_5 = assign_torsions(dcorr, graph1, graph2, xcc1, xcc2, symbols) if na_5 == 0: break # force assignation if na_0 == na_5: nforce += 1 dcorr, na_5 = assign_force(dcorr, graph1, graph2) # update na_0 na_0 = na_5 if pp: print("forced: %i" % nforce) assign_print(dcorr) return dcorr
def equivalent_atoms(xcc, symbols, fconnect=1.3): xcc1 = [xi for xi in xcc] xcc2 = [xi for xi in xcc] # Adjacency matrices amatrix1 = np.matrix(intl.get_adjmatrix(xcc1, symbols, fconnect, "int")[0]) amatrix2 = np.matrix(intl.get_adjmatrix(xcc2, symbols, fconnect, "int")[0]) # autoconnect! amatrix1 = np.matrix(intl.link_fragments(xcc1, amatrix1.tolist(), 1)[0]) amatrix2 = np.matrix(intl.link_fragments(xcc2, amatrix2.tolist(), 1)[0]) # Correlate dcorr = equivalent_atoms_in_graphs(amatrix1, amatrix2, symbols) return dcorr
def adjmatrix_from_zmatrix(lzmat, zmatvals, cfactor): # convert to cartesian coordinates xcc = intl.zmat2xcc(lzmat, zmatvals) # symbols symbols = [pack[0] for pack in lzmat] # Get connection matrix cmatrix = intl.get_adjmatrix(xcc, symbols, scale=cfactor, mode="bool")[0] return cmatrix
def __init__(self, xcc, symbols, cscal=1.3, nfrags=1, epslin=4.5): # initialize data for UGRAPH self._ugdict = {} self._nnodes = 0 self._nedges = 0 self._cnumber = 0 # calculate connectivity matrix cmatrix = intl.get_adjmatrix(xcc, symbols, cscal, mode="int")[0] # autoconnect cmatrix = intl.link_fragments(xcc, cmatrix, nfrags)[0] # save cmatrix cmatrix = np.matrix(cmatrix) # set graph self.set_from_amatrix(cmatrix) # detect atoms in cycles nodes_cycles = self.nodes_in_cycles() # save data self._xcc = [xi for xi in xcc] self._symbols = symbols self._incycle = nodes_cycles self._cmatrix = cmatrix self._epslin = epslin self._cscal = cscal self._angles = {} # see if dummy is required by checking all atoms with two connections (B-A-C) dummies = [] nodeX = int(self._nnodes) - 1 for nodeA, neighbors in self._ugdict.items(): if len(neighbors) != 2: continue nodeB, nodeC = neighbors # add dummy atom?? if self.islinear((nodeB, nodeA, nodeC)): xB = self._xcc[3 * nodeB:3 * nodeB + 3] xA = self._xcc[3 * nodeA:3 * nodeA + 3] # coordinates of dummy atom xX = intl.zmat_thirdatom(xB, xA, dist=1.0, angle=np.pi / 2) # save data nodeX += 1 dummies.append((nodeA, nodeX, xX)) #---------------------# # Include dummy atoms # #---------------------# nn = int(self._nnodes) nd = len(dummies) if nd > 0: # increase cmatrix zerocols = np.zeros((nn, nd), dtype=int) zerorows = np.zeros((nd, nn + nd), dtype=int) self._cmatrix = np.hstack((self._cmatrix, zerocols)) self._cmatrix = np.vstack((self._cmatrix, zerorows)) # Add dummy atoms!! for nodeA, nodeX, xX in dummies: # add connection in graph self.add_node(nodeX) self.add_edge(nodeX, nodeA) # add connection in cmatrix self._cmatrix[nodeA, nodeX] = 1 self._cmatrix[nodeX, nodeA] = 1 # add dummy to symbols and xcc self._symbols.append("X") self._xcc += [xi for xi in xX]
def equivalent_atoms_by_connectivity(xcc,symbols,fconnect=1.3): amatrix = np.matrix(intl.get_adjmatrix(xcc,symbols,fconnect,"int")[0]) amatrix = np.matrix(intl.link_fragments(xcc,amatrix.tolist(),1)[0]) dcorr = correlate_amatrices(amatrix,amatrix,symbols,symbols,onlyconn=True) return dcorr
def zmat_preparation(inpvars): # Read zmat file pp.print_found(inpvars._zmatfile) try: xcc, zmat, symbols, masses, other, string = rw.readfile_xyz( inpvars._zmatfile) dwithout, molecule, natoms, ndummy = other for line in string.split("\n"): print(" " + line) except: pp.print_sthwrong(inpvars._zmatfile) raise Exception # Get connectivity matrix sprint(" * calculating adjacency (connection) matrix...", tvars.NIBS) sprint(" - connectivity scale factor: %.3f" % inpvars._cfactor, tvars.NIBS) cmatrix, dmatrix, nbonds = intl.get_adjmatrix(xcc, symbols, scale=inpvars._cfactor, mode="bool") fragments = list(intl.get_fragments_from_adjmatrix(cmatrix)) sprint(" - number of bonds: %i" % nbonds, tvars.NIBS) # print bonds nrows, ncols = dmatrix.shape bonds = [] for idx1 in range(nrows): for idx2 in range(idx1 + 1, ncols): if not cmatrix[idx1][idx2]: continue bonds.append("%s%i-%s%i" % (symbols[idx1], idx1 + 1, symbols[idx2], idx2 + 1)) ml = max([len(bond) for bond in bonds]) for idx in range(0, len(bonds), 5): line = " ".join(["%%-%is" % ml % bond for bond in bonds[idx:idx + 5]]) sprint(line, tvars.NIBS + 7) sprint() # fragments sprint(" - number of fragments: %i" % len(fragments), tvars.NIBS) for count, fragment in enumerate(fragments): frag_mformu = fncs.get_molformula([symbols[idx] for idx in fragment]) sprint(" (%i) %s" % (count + 1, frag_mformu), tvars.NIBS) sprint() # pairs to be skipped if inpvars._skipconn != []: sprint( " - Pair(s) of atoms to be skipped in the connectivity test", tvars.NIBS) for at1, at2 in inpvars._skipconn: sprint( " (%s%i,%s%i)" % (symbols[at1], at1 + 1, symbols[at2], at2 + 1), tvars.NIBS) sprint() # Get atoms of target torsions sprint(" * identifying target torsions in z-matrix...", tvars.NIBS) lzmat, zmatvals, zmatatoms = zmat for X, ic in zip(inpvars._ttorsions, inpvars._tic): if ic not in zmatatoms.keys(): sprint(" ERROR: Unable to find '%s' in z-matrix..." % ic, tvars.NIBS) raise Exception inpvars._tatoms[X] = list(zmatatoms[ic]) storsion = "-".join( [symbols[atom] + "%i" % (atom + 1) for atom in inpvars._tatoms[X]]) sprint(" torsion%s (%s): %s" % (X, ic, storsion), tvars.NIBS + 3) sprint() # Check lists and dicts related to torsions sthwrong = False for idx, X in enumerate(inpvars._ttorsions): sprint(" * variables for torsion%s (angles in degrees):" % X, tvars.NIBS) sprint("tsigma : %i" % (inpvars._tsigma[idx]), tvars.NIBS + 5) sprint("maxvalue: %.0f" % (inpvars._tlimit[idx]), tvars.NIBS + 5) values = "U".join("(%i,%i)" % (phi1, phi2) for phi1, phi2 in inpvars._tdomain[idx]) sprint("tdomain : %s" % (values), tvars.NIBS + 5) values = ",".join("%i" % val for val in inpvars._precond[idx]) sprint("precond : %s" % (values), tvars.NIBS + 5) sprint() if len(inpvars._tdomain[idx]) == 0: sprint("ERROR! Something wrong with this torsion!", tvars.NIBS + 5) raise exc.END # Important variable not defined status, variable = inpvars.check() if status == -1: pp.print_readerror(variable) end_program = True raise Exception # Detect CH3 groups lCH3 = detect_ch3(cmatrix, symbols, inpvars) if len(lCH3) != 0: sprint("* CH3 group(s) detected!", tvars.NIBS + 3) for CH3 in lCH3: sprint( "dihedral: " + "-".join(["%s%i" % (symbols[idx], idx + 1) for idx in CH3]), tvars.NIBS2 + 2) if len(lCH3) == 1: sprint("It will be considered when using --mstor", tvars.NIBS + 5) else: sprint("They will be considered when using --mstor", tvars.NIBS + 5) sprint() # Detect NH2 groups lNH2 = detect_nh2(cmatrix, symbols, lzmat, zmatvals, inpvars) if len(lNH2) != 0: sprint("* NH2 group(s) detected!", tvars.NIBS + 3) for HNRH_atoms, HNRH_value, HNRH_bool in lNH2: H1, N, R, H2 = HNRH_atoms nh2 = "H%i-N%i-H%i" % (H1 + 1, N + 1, H2 + 1) angle_args = (H1 + 1, N + 1, symbols[R], R + 1, H2 + 1, np.rad2deg(HNRH_value)) angle = "angle(H%i-N%i-%s%i...H%i) = %.0f degrees" % angle_args sprint("%s --> %s" % (nh2, angle), tvars.NIBS2 + 2) sprint() return inpvars, zmat, symbols, masses, cmatrix, lCH3, lNH2, ndummy