VMD-L Mailing List
From: Daniel Brooks (danielbrooks20_at_gmail.com)
Date: Mon Mar 13 2017 - 16:05:15 CDT
Thanks Joshua, that worked like a charm.
For reference, here's a python script that can generate and export surfaces
to vmd in the .stl format.
import numpy as np
from skimage import measure
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
#Generates isosurfaces from a 3d array of points
#Creates an ascii stl output that can be read by vmd
#Load a 3D array of points
sum_gauss = np.load('array.txt.npy')
print "Loaded sum_gauss from file"
#Now, compute an iso-surface
level = 0.02
print "level =", level
verts, faces = measure.marching_cubes(sum_gauss, level)
#Load the surface in STL format
cube = stl.mesh.Mesh(np.zeros(faces.shape, dtype=stl.mesh.Mesh.dtype))
for i, f in enumerate(faces):
for j in range(3):
cube.vectors[i][j] = verts[f[j], : ]
#Write the mesh to file in stl ASCII format. This can be read by VMD
#Plot the isosurface in python
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_trisurf(verts[:, 0], verts[:,1], faces, verts[:, 2],
On Mon, Mar 13, 2017 at 9:25 AM, Vermaas, Joshua <Joshua.Vermaas_at_nrel.gov>
> Hi Daniel,
> The way I'd do it is to go via the STL interface. Its been a while since I
> tried this, but files with the stl extension are automatically picked up to
> be loaded via VMD's STL reader. Note that VMD cannot read binary ascii
> files (http://www.ks.uiuc.edu/Research/vmd/plugins/molfile/stlplugin.html),
> so if you use a library to write out the files, make sure you write out the
> ascii version (https://pypi.python.org/pypi/numpy-stl).
> On 03/13/2017 02:14 AM, Daniel Brooks wrote:
> Hi all,
> I am generating surface meshes that I would like to import into VMD. These
> meshes are stored in python as lists of verts and faces.
> It looks like MSMS surface meshes and polygon meshes are supported for
> file import - but I haven't seen documentation on the structure of these
> files. Anyone know how to import surfaces into VMD?
> Daniel Brooks
> PhD Candidate in Applied Physics
> California Institute of Technology