Before starting anything with tSNE let’s read what is tSNE and how it has been compared with PCA. You can read it here. Several implementations of t-SNE are available here. A great introductory video on tSNE can be found here.
The dataset used in this explanation can be accessed here (named combine_times_ca.dcd and corresponding GRO file prot_ca.gro . Use VMD to open them and crosscheck).
# Download Matlab_r2017b
# Add the path of .dcd file reader for MatLab.Download the package from here
addpath('/home/sbhakat/matdcd-1.0')
# Give the path of your dcd file. In my case I am using a dcd file named combine_times_ca.dcd which has atoms starting from 1 to 331.
x=readdcd('/home/sbhakat/Plasmepsin_r1_r2_PCA/Gromacs_plmr2/Combine/combine_times_ca.dcd',1:331);
This will produce a following output
h = struct with fields: fid: 3 endoffile: 42789396 NSET: 10560 ISTART: 0 NSAVC: 1 NAMNF: 0 charmm: 1 charmm_extrablock: 1 charmm_4dims: 0 DELTA: 1 N: 331
# Perform Pincipal Component Analysis
[pc, score, latent, tsquare] = pca(x(2:end,:));
# Plot first two principal components
plot(score(:,1),score(:,2),'.')
# Label the plot
xlabel('PC1') ylabel('PC2')
# It will pop up a window with PCA plot something the following
# Carrying on the calculation on the same Matlab window
rng default % for reproducibility
# Perform tSNE analysis with Barneshut algorithm
Y = tsne(x,'Algorithm','barneshut','NumPCAComponents',50);
#Produce the figure
figure gscatter(Y(:,1),Y(:,2)) xlabel('tSNE1') ylabel('tSNE2')
# It will produce something like the following
Reference
The initial part of the tutorial was inspired by this one.
Collaboration on use of tSNE in molecular dynamics simulation is highly appreciated.