def plot(mol, save_as="null", show=True): colors = np.zeros((mol.array_length(), 3)) colors[mol.element == "H"] = (0.8, 0.8, 0.8) # gray colors[mol.element == "C"] = (0.0, 0.8, 0.0) # green colors[mol.element == "N"] = (0.0, 0.0, 0.8) # blue colors[mol.element == "O"] = (0.8, 0.0, 0.0) # red fig = plt.figure(figsize=(8.0, 8.0)) ax = fig.add_subplot(1, 1, 1, projection="3d") graphics.plot_atoms(ax, mol, colors, line_width=3, zoom=1.5) ax.view_init(elev=165, azim=115) fig.tight_layout() if save_as != "null": plt.savefig(save_as) plt.close() if show: plt.show()
### Superimpose backbone onto first model for better visualization ### rotamers, _ = struc.superimpose(rotamers[0], rotamers, atom_mask=struc.filter_backbone(rotamers)) ### Visualize rotamers ### colors = np.zeros((residue.array_length(), 3)) colors[residue.element == "H"] = (0.8, 0.8, 0.8) # gray colors[residue.element == "C"] = (0.0, 0.8, 0.0) # green colors[residue.element == "N"] = (0.0, 0.0, 0.8) # blue colors[residue.element == "O"] = (0.8, 0.0, 0.0) # red # For consistency, each subplot has the same box size coord = rotamers.coord size = np.array([ coord[:, :, 0].max() - coord[:, :, 0].min(), coord[:, :, 1].max() - coord[:, :, 1].min(), coord[:, :, 2].max() - coord[:, :, 2].min() ]).max() * 0.5 fig = plt.figure(figsize=(8.0, 8.0)) fig.suptitle("Rotamers of tyrosine", fontsize=20, weight="bold") for i, rotamer in enumerate(rotamers): ax = fig.add_subplot(3, 3, i + 1, projection="3d") graphics.plot_atoms(ax, rotamer, colors, line_width=3, size=size, zoom=0.9) fig.tight_layout() plt.show() ### Write rotamers to structure file ### #strucio.save_structure("rotamers.pdb", rotamers)
) for base in (purine, pyrimidine) ] pairs[i] = (purine, pyrimidine) # Plot base pairs # Merge bases into a single atom array atoms = pairs[0][0] + pairs[0][1] + pairs[1][0] + pairs[1][1] # Color by element colors = np.zeros((atoms.array_length(), 3)) colors[atoms.element == "H"] = (0.8, 0.8, 0.8) # gray colors[atoms.element == "C"] = (0.2, 0.2, 0.2) # darkgray colors[atoms.element == "N"] = (0.0, 0.0, 0.8) # blue colors[atoms.element == "O"] = (0.8, 0.0, 0.0) # red colors[atoms.element == "P"] = (0.0, 0.6, 0.0) # green graphics.plot_atoms( ax, atoms, colors, line_width=3, background_color="white" ) # Plot hydrogen bonds for purine, pyrimidine in pairs: pair = purine + pyrimidine bonds = struc.hbond(pair) for donor, hydrogen, acceptor in bonds: hydrogen_coord = pair.coord[hydrogen] acceptor_coord = pair.coord[acceptor] x, y, z = zip(hydrogen_coord, acceptor_coord) ax.plot(x, y, z, linestyle=":", color="gold", linewidth=2) # Label bases for pair in pairs: for base in pair:
normal = np.cross(n1.coord - n3.coord, n1.coord - n7.coord) # Align ring plane normal to z-axis caffeine = struc.align_vectors(caffeine, normal, np.array([0, 0, 1])) # Caffeine should be colored by element colors = np.zeros((caffeine.array_length(), 3)) colors[caffeine.element == "H"] = (0.8, 0.8, 0.8) # gray colors[caffeine.element == "C"] = (0.0, 0.8, 0.0) # green colors[caffeine.element == "N"] = (0.0, 0.0, 0.8) # blue colors[caffeine.element == "O"] = (0.8, 0.0, 0.0) # red fig = plt.figure(figsize=(8.0, 8.0)) ax = fig.add_subplot(111, projection="3d") graphics.plot_atoms(ax, caffeine, colors, line_width=5, background_color="white", zoom=1.5) fig.tight_layout() # Create an animation that rotates the molecule about the x-axis def update(angle): ax.elev = angle FPS = 50 DURATION = 4 angles = np.linspace(-180, 180, DURATION * FPS) # Start at 90 degrees angles = np.concatenate([