File size: 1,524 Bytes
10f2621 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | import pymesh
import numpy
"""
read_ply.py: Read a ply file from disk using pymesh and load the attributes used by MaSIF.
Pablo Gainza - LPDI STI EPFL 2019
Released under an Apache License 2.0
"""
def read_ply(filename):
# Read a ply file from disk using pymesh and load the attributes used by MaSIF.
# filename: the input ply file.
# returns data as tuple.
mesh = pymesh.load_mesh(filename)
attributes = mesh.get_attribute_names()
if "vertex_nx" in attributes:
nx = mesh.get_attribute("vertex_nx")
ny = mesh.get_attribute("vertex_ny")
nz = mesh.get_attribute("vertex_nz")
normals = numpy.column_stack((nx, ny, nz))
else:
normals = None
if "vertex_charge" in attributes:
charge = mesh.get_attribute("vertex_charge")
else:
charge = numpy.array([0.0] * len(mesh.vertices))
if "vertex_cb" in attributes:
vertex_cb = mesh.get_attribute("vertex_cb")
else:
vertex_cb = numpy.array([0.0] * len(mesh.vertices))
if "vertex_hbond" in attributes:
vertex_hbond = mesh.get_attribute("vertex_hbond")
else:
vertex_hbond = numpy.array([0.0] * len(mesh.vertices))
if "vertex_hphob" in attributes:
vertex_hphob = mesh.get_attribute("vertex_hphob")
else:
vertex_hphob = numpy.array([0.0] * len(mesh.vertices))
return (
mesh.vertices,
mesh.faces,
normals,
charge,
vertex_cb,
vertex_hbond,
vertex_hphob,
)
|