From: Bruininks, B.M.H. (b.m.h.bruininks_at_rug.nl)
Date: Wed Sep 01 2021 - 08:35:14 CDT

Dear VMDers,

A while ago I asked for help using python and VMD to visualize dynamic
segmentation of molecular systems
<https://urldefense.com/v3/__https://github.com/marrink-lab/MDVoxelSegmentation__;!!DZ3fjg!u97BRTLa62glZFwoN6WosdIloozOsFY76535byxJxhMjfl03FNReD4ud4jpzewiNBQ$ >. A script came out of
it and it is working like a charm! Thanks for that again. However, it still
requires a special compilation for VMD which is not really approachable for
many users. As the segmentation is working very well now and the paper has
been accepted, I was hoping we could maybe circumvent the python dependency
completely.

During development our output for segmentation was saved as an npz file.
However, we can easily change this to a type which is support by VMD.
Hopefully then the reading of dynamic segmentation data can be achieved
completely through TCL and allows reading of such data using the default
VMD version. It would be great if I could get in contact with a developer
and work on the TCL script. I think the answer must not be difficult, I
just feel like I do not see it.

Cheers and thanks in advance,

Bart

*The current script we have is:*
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 8 12:38:38 2019
This file is used to run within VMD with python2 and numpy compiled.
After succesfully running this file you can used the 'user' selection
identiyfer in VMD followed by a cluster number to visualize that cluster.
You can save the visualization state after having the right settings in
vmd, but you will always have to excecute this file first before loading
the visualization state (you should remove the load .gro and .xtc from
the VMD statefile).
@author: bart
"""
from Molecule import Molecule
from atomsel import *
# needed for opening the array.npy (possibly compressed)
import numpy as np

mol = Molecule()
# The .gro file should have the same order as the tpr used for clustering.
mol.load("../md.gro")
mol.delFrame() # Reading in a .gro file adds coordinates, which you don't
want.
mol.load("../all.xtc") # This should be the same .xtc used for clustering.

# The cluster file generated to visualize in vmd.
clusters = np.load('clusters_ordered.npy')
asel = atomsel("all")

for frame, cluster in enumerate(clusters):
    try:
        asel.frame = frame
    except IndexError:
        print ('Not all frames could have their clusters assigned. Stopped
in \
frame ' + str(frame) + '.')
        break
    print cluster, len(asel), len(cluster), frame
    asel.set('user', cluster)