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 __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