vtkProteinRibbonFilter usage without using vtkPDBReader

Hi all!
I’m trying to use vtk (via python) to render Ribbon diagrams for proteins and vtkProteinRibbonFilter has been quite helpful in this. I am able to render Ribbon diagrams for PDB files by using the code below -

# reader to read PDB files
reader = vtk.vtkPDBReader()
protein_name = '2hhb.pdb' 
reader.SetFileName(protein_name)

# Filter for ribbon diagram
ribbonFilter = vtk.vtkProteinRibbonFilter()
ribbonFilter.SetInputConnection(reader.GetOutputPort())

# mapper to draw the filter output
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(ribbonFilter.GetOutputPort())

# actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)

This works fine and I’m able to generate Ribbons but I’m only able to view PDB files via this method, PDBx/mmCIF files are the norm nowadays but vtk has no PDBx reader. Is there a way to pass arguments of my own to vtkProteinRibbonFilter which it can then use to render the ribbon diagram?

Thanks in advance,
Sajag

I managed to do this by creating a polydata and passing the required arrays to the polydata which I then passed to the vtkProteinRibbonFilter. To see what arrays vtkProteinRibbonFilter requires and their contents, refer to this post.
The code to send the arrays to the polydata (I haven’t included the code to parse PDB files which fills these arrays, if someone wants it, please let me know) -

output = vtk.vtkPolyData()

# for atom type
AtomType = np.array(AtomType)
atom_type = numpy_to_vtk(num_array=AtomType, deep=True, array_type=vtk.VTK_ID_TYPE)
atom_type.SetName("atom_type")

output.GetPointData().AddArray(atom_type)

# for atom type strings
atom_types = vtk.vtkStringArray()
atom_types.SetName("atom_types")
atom_types.SetNumberOfTuples(len(AtomTypeStrings))
for i in range(len(AtomTypeStrings)):
    atom_types.SetValue(i, AtomTypeStrings[i])

AtomTypeStrings = np.array(AtomTypeStrings)

output.GetPointData().AddArray(atom_types)

# for residue
residue = numpy_to_vtk(num_array=Residue, deep=True, array_type=vtk.VTK_ID_TYPE)
residue.SetName("residue")
output.GetPointData().AddArray(residue)

# for chain
Chain = np.array(Chain)
chain = numpy_to_vtk(num_array=Chain, deep=True, array_type=vtk.VTK_UNSIGNED_CHAR)
chain.SetName("chain")
output.GetPointData().AddArray(chain)

# for secondary structures
s_s = numpy_to_vtk(num_array=SecondaryStructures, deep=True, array_type=vtk.VTK_UNSIGNED_CHAR)
s_s.SetName("secondary_structures")
output.GetPointData().AddArray(s_s)


# for secondary structures begin, required but not used by vtkProteinRibbonFilter, pass an array of ones
newarr = np.ones(n)
s_sb = numpy_to_vtk(num_array=newarr, array_type=vtk.VTK_UNSIGNED_CHAR)
s_sb.SetName("secondary_structures_begin")
output.GetPointData().AddArray(s_sb)

# for secondary structures end, required but not used by vtkProteinRibbonFilter, pass an array of ones
newarr = np.ones(n)
s_se = numpy_to_vtk(num_array=newarr, array_type=vtk.VTK_UNSIGNED_CHAR)
s_se.SetName("secondary_structures_end")
output.GetPointData().AddArray(s_se)


# for ishetatm
IsHetatm = np.array(IsHetatm)
ishetatm = numpy_to_vtk(num_array=IsHetatm, deep=True, array_type=vtk.VTK_UNSIGNED_CHAR)
ishetatm.SetName("ishetatm")
output.GetPointData().AddArray(ishetatm)

# for model
Model = np.array(Model)
model = numpy_to_vtk(num_array=Model, deep=True, array_type=vtk.VTK_UNSIGNED_INT)
model.SetName("model")
output.GetPointData().AddArray(model)

# for colors
rgb = vtk.vtkUnsignedCharArray()
rgb.SetNumberOfComponents(3)
rgb.Allocate(3 * NumberOfAtoms)
rgb.SetName("rgb_colors")

for i in range(NumberOfAtoms):
    rgb.InsertNextTuple(table.GetDefaultRGBTuple(AtomType[i]))

output.GetPointData().SetScalars(rgb)


# for radii
Radii = vtk.vtkFloatArray()
Radii.SetNumberOfComponents(3)
Radii.Allocate(3 * NumberOfAtoms)
Radii.SetName("radius")

for i in range(NumberOfAtoms):
    Radii.InsertNextTuple3(table.GetVDWRadius(AtomType[i]),
                           table.GetVDWRadius(AtomType[i]),
                           table.GetVDWRadius(AtomType[i]))

output.GetPointData().SetVectors(Radii)

from fury.utils import numpy_to_vtk_points
Points = np.array(Points)
points = numpy_to_vtk_points(Points)
output.SetPoints(points)

# send the polydata to the filter
ribbonFilter = vtk.vtkProteinRibbonFilter()
ribbonFilter.SetInputData(output)