def add_orbitals(X, dic): o_d = basis.orbitals() s_d = atom_data.data(sys.argv[0]) d = atom_data.data(sys.argv[0]) for i in range(len(X)): #print X[i]#d[X[i][0]]#['electronegativity'] for j in range(len(X[i])): X[i][j].append(o_d[s_d[int(X[i][j][0])]['symbol']]['1s']) X[i][j].append(o_d[s_d[int(X[i][j][0])]['symbol']]['2s']) X[i][j].append(o_d[s_d[int(X[i][j][0])]['symbol']]['2p']) return X
def make_dat(path): filename = path[:-4] + '.xyz' #print filename[:-4]+'_hessian' h = open(filename[:-4] + '_hessian', 'r') hess0 = h.readlines()[1:] h.close() hess = [] for line in hess0: hess += line.strip().split() amass, za, xyz = [], [], [] f = open(filename, 'r') lines = f.readlines() f.close() data = atom_data.data(sys.argv[0]) sym = atom_data.symbol_dict(sys.argv[0]) for line in lines[2:]: if len(line.strip().split()) == 0: continue s, x, y, z = line.strip().split() amass.append(data[sym[s]]['atomicMass'][:-3]) za.append(str(sym[s])) xyz += [x, y, z] g = open(filename[:-4] + '.dat', 'w') s = '' s += 'Eventually the world will end in singularity !! \n' s += 'NATM\n ' + lines[0].strip().split()[0] + '\nAMASS' + sub_s(amass) s += '\nZA' + sub_s(za) s += '\nXYZ' + sub_s(xyz) s += '\nNOAPT' s += '\nFFX' + sub_s(hess) g.write(s) g.close()
def coord(path): file_o = open(path, 'r') file = file_o.readlines() file_o.close() energy = [] lowest_energy = 99999 bl = [] ref = 0 last = 0.0 key = "Normal termination of Gaussian" index = 0 e0 = atom_data.data(sys.argv[0]) e = {} for i in e0: #print i e[str(i)] = e0[i]['symbol'] for line in file: #print line if key in line: energy.append(last) if 'Z-Matrix orientation:' in line: last = save_coord(file, index, e) index += 1 return energy
def save_xyz(self, reward=0): d = ad.data(sys.argv[0]) a = self.atoms sd = [d[i]['symbol'] for i in a] c = self.dcoord print('Reward:', reward) f = open('render.xyz', 'a') f.write(str(len(a)) + '\nReward : ' + str(reward) + '\n') for j in range(len(a)): st = sd[j] + ' ' + ' '.join(list(map(str, c[j]))) + '\n' f.write(st) f.close()
def add_electron(X, dic): if len(dic['3D']) == 0: return X d = atom_data.data(sys.argv[0]) for i in range(len(X)): #print X[i]#d[X[i][0]]#['electronegativity'] for j in range(len(X[i])): for k in dic['3D']: if k == 'add_valance': X[i][j].append(add_valance(d, int(X[i][j][0]))) elif k == 'atomicMass': X[i][j].append(float(d[int(X[i][j][0])][k][:4])) else: X[i][j].append(float(d[int(X[i][j][0])][k])) return X
def xyz_value(path): data = subprocess.check_output('gcartesian '+path, shell=True) data=data.split('\n') d=atom_data.data(sys.argv[0]) ref=1 for l in data[1:]: a,x,y,z=l.strip().split() try: int(a) a=d[int(a)]['Symbol'] except TypeError: pass data[ref]=' '.join([a,x,y,z]) ref+=1 '\n'.join(data) return '* xyz '+data+'\n'
def job(file): f = open(file, 'r') lines = f.readlines() f.close() atoms, coords = get_lis(lines) names = make_(atoms, coords[0]) for h in range(len(coords)): render_(names, coords[h], atoms, h + 1) dic = {} count = 0 a_data = ad.data() s_data = {} for i in a_data: s_data[a_data[i]['symbol']] = a_data[i] initiate() job('/Users/47510753/Downloads/6-6_318_28.xyz') #cmds.setKeyframe(v = 0, at = 'visibility', t = 5)
def convert(pdb, PSF, ff, parameter_file, output): atomData = ad.data(ff, parameter_file) graph = nx.Graph() u = None #getting nodes u = MDAnalysis.Universe(pdb) sel = None try: sel = u.select_atoms("protein") except: sel = u.selectAtoms("protein") for atom in sel: graph.add_node(str(int(atom.index + 1))) nodes = graph.nodes() ############################################## ## ## if psf File was provided ## ############################################## if PSF: psf = open(PSF, "r") flag = 0 ###################################################### ##we will extract conection data and create the graph ###################################################### for line in psf: #parsing bonds if line == "\n": flag = 0 if flag == 1: splitted = line[:-1].split(" ") auxList = [] for element in splitted: if element != "": auxList.append(element) i = 0 while i < len(auxList): if str(int(auxList[i])) in nodes and str( int(auxList[i + 1])) in nodes: graph.add_edge(str(int(auxList[i])), str(int(auxList[i + 1]))) i += 2 if "!NBOND" in line: flag = 1 psf.close() #parsing atom data psf = open(PSF, "r") flag = 0 for line in psf: if line == "\n": flag = 0 if flag == 1: splitted = line[:-1].split(" ") auxList = [] for element in splitted: if element != "": auxList.append(element) try: graph.node[auxList[0]]['resname'] = auxList[3] except: pass try: graph.node[auxList[0]]['segid'] = auxList[1] except: pass try: graph.node[auxList[0]]['resnum'] = auxList[2] except: pass try: graph.node[auxList[0]]['atomName'] = auxList[4] except: pass try: graph.node[auxList[0]]['atomType'] = auxList[5] except: pass try: graph.node[auxList[0]]['charge'] = auxList[6] except: pass try: for item in atomData["resids"][auxList[3]].items(): for item2 in (item[1].items()): if item2[0] == auxList[4]: graph.node[auxList[0]]['group'] = item[0] graph.node[auxList[0]]['epsilon'] = item2[1][ "epsilon"] graph.node[ auxList[0]]['radius'] = item2[1]["radius"] except: pass if "!NATOM" in line: flag = 1 psf.close() ################################################# ## ## else, if only pdb file was provided ## ################################################# else: #parsing atom info dictAtomData = atomParser(atomData) #looping structure for residue in sel.residues: res = residue.resname for atom in residue.atoms: if res == "HIS": flag = 0 pos = None try: pos = res.atoms.HD1.position print pos flag += 1 res = "HSD" except: pass try: pos = res.atoms.HD2.position print pos flag += 1 res = "HSE" except: pass if flag == 2: #we found HD1 and HD2 so we have aHSP res = "HSP" elif flag == 0: res = "HSD" try: graph.node[str(atom.index + 1)]['resname'] = str( atom.resname) graph.node[str(atom.index + 1)]['segid'] = str(atom.segid) graph.node[str(atom.index + 1)]['resnum'] = str( residue.resid) graph.node[str(atom.index + 1)]['atomName'] = str( dictAtomData[res + ":" + atom.name]["atomName"]) graph.node[str(atom.index + 1)]['atomType'] = str( dictAtomData[res + ":" + atom.name]["atomType"]) graph.node[str(atom.index + 1)]['charge'] = str( dictAtomData[res + ":" + atom.name]["charge"]) graph.node[str(atom.index + 1)]['group'] = str( dictAtomData[res + ":" + atom.name]["group"]) graph.node[str(atom.index + 1)]['epsilon'] = str( dictAtomData[res + ":" + atom.name]["epsilon"]) graph.node[str(atom.index + 1)]['radius'] = str( dictAtomData[res + ":" + atom.name]["radius"]) graph.node[str(atom.index + 1)]['bonds'] = "" aux = "" for i in range( len(dictAtomData[res + ":" + atom.name]["bonds"])): aux += dictAtomData[res + ":" + atom.name]["bonds"][i] + "," aux = aux[:-1] graph.node[str(atom.index + 1)]['bonds'] = str(aux) except: pass #creating peptidic bond for res in sel.residues: for res2 in sel.residues: try: if res.atoms.C.segid == res2.atoms.N.segid and res.resnum == res2.resnum - 1: graph.add_edge(str(res.atoms.C.index + 1), str(res2.atoms.N.index + 1)) except: pass #creating conections nodeList = graph.nodes() nodeList2 = graph.nodes() for node in nodeList: nodeAtomName = None try: nodeAtomName = graph.node[node]["atomName"] for node2 in nodeList2: bondedToNode2 = None try: bondedToNode2 = graph.node[node2]["bonds"] splitted = bondedToNode2.split(",") for atom in splitted: if atom == nodeAtomName: if graph.node[node]["segid"] == graph.node[ node2]["segid"] and graph.node[node][ "resname"] == graph.node[node2][ "resname"] and graph.node[node][ "resnum"] == graph.node[ node2]["resnum"]: graph.add_edge(node, node2) except: pass except: pass print "saving topology graph on " + output + "/RIP-MD_Results/topology.gml" nx.write_gml(graph, output + "/RIP-MD_Results/topology.gml") return graph
def __init__(self, file): self.file = file self.F, self.g, self.cc, self.s, self.E, self.atoms = self.load() self.num = len(self.atoms) self.sym = atom_data.data(sys.argv[0])
def load(self): f = open(self.file, 'r') lines = f.readlines() f.close() K, g, coord, s, E, atoms = [], [], [], [], [], [] var = -1 ref = 0 for line in lines: if 'BL,Alpha,Beta' in line or 'FX_ZMat_Orientation' in line or 'FFX_ZMat_Orientation' in line or 'IPoCou,' in line or 'END' in line: ref = 2 if ref == 3: st = line.strip() if var == 0: coord += self.extract_coord(st) elif var == 1: g += self.extract_coord(st) else: K += self.extract_coord(st) if ref == 1 and 'BL,Alpha,Beta' not in line: atoms.append(line.strip().split()[0]) if ref == 4: line = line.replace('D', 'E') kl = line.strip().split() s.append(float(kl[-1])) E.append(float(kl[1])) if 'CC' == line.strip().split()[0]: ref = 3 var = 0 if 'FX_ZMat_Orientation' == line.strip().split()[0]: ref = 3 var = 1 if 'FFX_ZMat_Orientation' == line.strip().split()[0]: ref = 3 var = 2 if 'XXIRC' in line: ref = 4 if 'IAnZ' in line and ref == 0: ref = 1 # Mass weighting for coord and gradients mass_dict = atom_data.data(sys.argv[0]) for i in range(0, len(coord), len(atoms) * 3): for j in range(len(atoms)): for k in range(3): mi = math.sqrt( float(mass_dict[int(atoms[j])]['atomicMass'][:5])) coord[i + j + k] = mi * coord[i + j + k] g[i + j + k] = mi * g[i + j + k] g = np.array(g).reshape((len(s), len(atoms) * 3)) coord = np.array(coord).reshape((len(s), len(atoms) * 3)) #extract hessian from lower triangular form h_dic = {} ref = 0 for i in range(len(s)): for j in range(3 * len(atoms)): for k in range(j + 1): mj = math.sqrt( float(mass_dict[int(atoms[j / 3])]['atomicMass'][:5])) mk = math.sqrt( float(mass_dict[int(atoms[k / 3])]['atomicMass'][:5])) val = K[ref] / (mj * mk) h_dic[(i, j, k)] = val h_dic[(i, k, j)] = val ref += 1 # Mass weighting hessian F = [] for i in range(len(s)): F.append([]) for j in range(3 * len(atoms)): F[-1].append([]) for k in range(3 * len(atoms)): F[-1][-1].append(h_dic[(i, j, k)]) F = np.array(F) return F, g, coord, s, E, atoms