def write_salt_bridges(data: np.ndarray, mapping: DataFrame, mol: Molecule, outputname: str) -> None: """ This function outputs the salt bridges into a VMD session :param data: A MetricDistance object :param mapping: A DataFrame object including the index - residue mapping :param mol: The pdb filename. :param outputname: The file prefix name to output the VMD session to. Example: "protein2" :return: A file with the VMD session named outputname+"-salt-bridges.txt" """ f = open(outputname[:-4] + "-salt-bridges.txt", "w") mol.reps.add(sel='protein', style='NewCartoon', color=8) f.write(f"resid\tresid\n") for bond in mapping[data].atomIndexes.values: mol.reps.add(f"chain A and same residue as index {bond[0]}", style="Licorice", color="1") mol.reps.add(f"chain A and same residue as index {bond[1]}", style="Licorice", color="0") f.write(f"{bond[0]}\t" f"{bond[1]}\n") vmdobject = viewer(dispdev='text') vmdobject.loadMol(mol) vmdobject.send("save_state " + outputname) vmdobject.close() f.close()
def write_clusters(g: Graph, components: PropertyArray, inputmolfile: str, outputname: str) -> None: """ This function prints the clusters to the terminal and outputs them into a VMD session :param g: A Graph object :param outputname: The pdb filename. :param outputname: The file name to output the VMD session to. :return: """ f = open(outputname[:-4] + ".txt", "w") mol = Molecule(f"{inputmolfile[:-4]}-chainA.pdb") mol.reps.add(sel='protein', style='NewCartoon', color=8) for cluster_index in range(max(components) + 1): cluster = [i for i, x in enumerate(components) if x == cluster_index] if len(cluster) < 2: continue vfilt = g.new_vertex_property('bool') for i in cluster: vfilt[i] = True sub = GraphView(g, vfilt) area = np.sum([g.ep.area[edge] for edge in sub.edges()]) f.write(f"Cluster index {cluster_index}:\t" f"Residues {len(cluster)}. Total area {area} A^2.\t " f"Number of contacts: {sub.num_edges()}.\t " f"Contacts / Residue: {sub.num_edges() / len(cluster) }.\t " f"Area / Residue {area / sub.num_edges()}\n") # sum reverse and inverse resid_cluster = [g.vp.resid[i] for i in cluster] mol.reps.add('chain A and noh and not backbone and resid %s' % ' '.join(map(str, resid_cluster)), style="VDW", color=cluster_index) vmdobject = viewer(dispdev='text') vmdobject.loadMol(mol, name=inputmolfile) vmdobject.send("save_state " + outputname) vmdobject.close() f.close()
def write_networks(g: Graph, components: PropertyArray, inputmolfile: str, outputname: str) -> None: """ This function outputs the HH networks into a VMD session :param g: A Graph object :param outputname: The pdb filename. :param outputname: The file name to output the VMD session to. :return: """ f = open(outputname[:-4] + "hh-networks.txt", "w") mol = Molecule(inputmolfile) mol.reps.add(sel='protein', style='NewCartoon', color=8) f.write(f"Atom index\tAtom index\tresid\tresid\n") for network_index in range(max(components) + 1): f.write(f"Network index {network_index}\n") network = [i for i, x in enumerate(components) if x == network_index] # these are the vertices resid_network = [g.vp.resid[i] for i in network] # these are the resids vfilt = g.new_vertex_property('bool') for i in network: vfilt[i] = True sub = GraphView(g, vfilt) # print for each edge the atoms and resid of the two pairs for edge in sub.edges(): f.write(f"{sub.vp.atom[edge.source()]}\t" f"{sub.vp.atom[edge.target()]}\t" f"{sub.vp.resid[edge.source()]}\t" f"{sub.vp.resid[edge.target()]}\n") mol.reps.add('chain A and noh and resid %s' % ' '.join(map(str, resid_network)), style="Licorice", color=network_index) mol.reps.add('chain A and noh and resid %s' % ' '.join(map(str, resid_network)), style="HBonds", color=network_index) vmdobject = viewer(dispdev='text') vmdobject.loadMol(mol, name=inputmolfile) vmdobject.send("save_state " + outputname) vmdobject.close() f.close()
def write_largest_cluster(g: Graph, inputmolfile: str, outputname: str) -> None: """ This function prints the clusters to the terminal and outputs them into a VMD session :param g: A Graph object :param outputname: The pdb filename. :param outputname: The file name to output the VMD session to. :return: """ mol = Molecule(f"{inputmolfile[:-4]}-chainA.pdb") mol.reps.add(sel='protein', style='NewCartoon', color=8) l = label_largest_component(g) sub = GraphView(g, vfilt=l) resid_cluster = [g.vp.resid[i] for i in sub.vertices()] mol.reps.add('chain A and noh and not backbone and resid %s' % ' '.join(map(str, resid_cluster)), style="VDW", color=1) # red vmdobject = viewer(dispdev='text') vmdobject.loadMol(mol, name=inputmolfile) vmdobject.send("save_state " + outputname) vmdobject.close()