<jupyter_start><jupyter_text>This Jupyter Notebook will cover all the different methods capable of approximating molecular volumes using geometric methods available in PyMoVE including examples of visualizing the results from each.   General import statements<jupyter_code>import os,json

import numpy as np

from pymove import Structure
from pymove.io import read,write
from pymove.crystals import preprocess
from pymove.molecules.marching_cubes import MarchingCubes
from pymove.molecules.molecule_surface import MoleculeSurface

from mpl_toolkits.mplot3d import Axes3D  

import matplotlib.pyplot as plt

from plotly.offline import plot,iplot
import plotly.figure_factory as FF
import plotly.graph_objs as go


def get_limits(coords,offset=0.2):
    """
    Gets the limits for 3D plotting such that the range of each axis is 
    the same.
    
    """
    min_lim = np.min(coords,axis=0)
    max_lim = np.max(coords,axis=0)
    diff = max_lim - min_lim
    
    max_diff = np.max(diff)
    
    min_lim -= offset
    max_lim = min_lim + max_diff + 2*offset
    
    xlim = [min_lim[0],max_lim[0]]
    ylim = [min_lim[1],max_lim[1]]
    zlim = [min_lim[2],max_lim[2]]
    
    return xlim,ylim,zlim
struct_dict = read("../Example_Structures/molecules")<jupyter_output><empty_output><jupyter_text>Voxel Representation<jupyter_code>### Uncomment for more information and documentation on using the marching cubes algorithm
# help(MarchingCubes)
mc = MarchingCubes(spacing=0.3)
molecule_voxels,colors = mc.struct_to_volume_colors(struct_dict["rdx"])<jupyter_output><empty_output><jupyter_text>Visualization of voxel representation using matplotlib. Matplotlib is not very good at visualizing volumes in 3D. If images of voxels of large molecules are required, pyvista or mayavi are recommended.<jupyter_code>fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(111,projection='3d')
ax.voxels(molecule_voxels, facecolors=colors, edgecolor='k')
plt.show()<jupyter_output><empty_output><jupyter_text>Marching Cubes<jupyter_code>ms = MoleculeSurface(spacing=0.2)
molecule_voxels,colors = ms.m.struct_to_volume_colors(struct_dict["rdx"])
total_volume,voxel_coords,cube_coords,coords,triangles = ms.m.marching_cubes_basic(molecule_voxels)
tri_atom_idx = ms.assign_triangles_nearest(
                                struct_dict["rdx"], 
                                coords, 
                                triangles)
colors = ms.get_plotly_colors(struct_dict["rdx"], tri_atom_idx)
print("Total Volume of Molecule: {:.2f} Angstroms^3".format(total_volume))<jupyter_output><empty_output><jupyter_text>Visualization of surface triangulation using the marching cubes method is performed using Plotly. Note that the representation of the molecular surface, constructed from many overlapping van der Waals spheres, is poorly approximated using the traditional marching cubes algorithm.<jupyter_code>fig1 = FF.create_trisurf(
            coords[:,0],
            coords[:,1],
            coords[:,2],
            color_func=colors,
            simplices=triangles,
            plot_edges=True,
            )
fig1.show()<jupyter_output><empty_output><jupyter_text>Atomic Surface Projected Marching Cubes<jupyter_code>ms = MoleculeSurface(spacing=0.15)
molecule_voxels,colors = ms.m.struct_to_volume_colors(struct_dict["rdx"])
total_volume,voxel_coords,cube_coords,coords,triangles = ms.m.marching_cubes(molecule_voxels)
tri_atom_idx = ms.assign_triangles_nearest(
                                struct_dict["rdx"], 
                                coords, 
                                triangles)
colors = ms.get_plotly_colors(struct_dict["rdx"], tri_atom_idx)
print("Total Volume of Molecule: {:.2f} Angstroms^3".format(total_volume))<jupyter_output><empty_output><jupyter_text>Visualization of surface triangulation using the marching cubes method is performed using Plotly. Note the significant improvement in the representation of the molecular surface using the newly invented, atomic surface projected marching cubes algorithm.<jupyter_code>fig1 = FF.create_trisurf(
            coords[:,0],
            coords[:,1],
            coords[:,2],
            color_func=colors,
            simplices=triangles,
            plot_edges=True,
            )
fig1.show()<jupyter_output><empty_output><jupyter_text>Packing Accessible Surface<jupyter_code>ms = MoleculeSurface(spacing=0.15, probe_radius=3.0)
total_volume = ms.calc_struct(struct_dict["rdx"])
coords, triangles, colors = ms.get_plot_info()
print("Total Volume of Molecule: {:.2f} Angstroms^3".format(total_volume))<jupyter_output><empty_output><jupyter_text>Visualization of packing accessible surface using Plotly. The pink areas are regions that have been added to the surface of the molecule due to the definition and construction of the packing accessible surface.<jupyter_code>fig1 = FF.create_trisurf(
            coords[:,0],
            coords[:,1],
            coords[:,2],
            color_func=colors,
            simplices=triangles,
            plot_edges=True,
            )
fig1.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08910306845003933, 'fraction_numerical': 0.010621557828481511, 'mean_word_length': 4.0546719681908545, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '415209', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1594, 'n_words': 358, 'path': 'examples/4_Packing_Accessible_Surface/Visualize.ipynb', 'repo_name': 'manny405/PyMoVE', 'size': '5084'}