def main(top, bot, radius, title="box.pdb", output="", n_points=10, input_pdb=None, center=None, type_box="cylinder"):
    if output:
        if not os.path.exists(output):
            os.makedirs(output)
        title = os.path.join(output, title)
    if input_pdb is not None:
        in_PDB = atomset.PDB()
        in_PDB.initialise(input_pdb, resname="DUM")
        for atom in in_PDB.atoms.values():
            if atom.name == "DUMT":
                top = atom.getAtomCoords()
            if atom.name == "DUMB":
                bot = atom.getAtomCoords()
            if atom.name == "DUM":
                center = atom.getAtomCoords()
    if type_box == "cylinder":
        if top is None or bot is None:
            raise utilities.RequiredParameterMissingException("Coordinates for the top and bottom base center not specified!!!")
        coords = generate_cylinder_box(top, bot, radius, n_points)
    elif type_box == "sphere":
        if center is None:
            raise utilities.RequiredParameterMissingException("Coordinates for the center not specified!!!")
        coords = generate_sphere_box(center, radius, n_points)
    coords = np.array(coords)
    utilities.write_PDB_clusters(coords, title)
Exemplo n.º 2
0
def main(metricCol, lig_resname, nTrajs, filter_val, stride, atomId, saving_frequency, trajectory_name, report_name, topology=None):
    folders = utilities.get_epoch_folders(".")
    data = []
    minMetric = 1e6
    confData = []
    for epoch in folders:
        print("Processing epoch %s" % epoch)
        for iTraj in range(1, nTrajs):
            report = np.loadtxt("%s/%s_%d" % (epoch, report_name, iTraj))
            if len(report.shape) < 2:
                report = report[np.newaxis, :]
            traj_file = glob.glob("%s/%s_%d.*" % (epoch, trajectory_name, iTraj))[0]
            snapshots = utilities.getSnapshots(traj_file, topology=topology)
            for i, snapshot in enumerate(itertools.islice(snapshots, 0, None, stride)):
                report_line = i * stride * saving_frequency
                data.append(get_coords(snapshot, atomId, lig_resname) + [report[report_line, metricCol]])
                confData.append((epoch, iTraj, report_line))

    data = np.array(data)
    minInd = np.argmin(data[:, -1])
    minMetric = data[minInd, -1]
    data[:, -1] -= minMetric
    if filter_val is not None:
        data_filter = data.copy()
        data_filter[data_filter > filter_val] = filter_val
        namesPDB = utilities.write_PDB_clusters(data_filter, title="cluster_metric.pdb", use_beta=True)
    else:
        namesPDB = utilities.write_PDB_clusters(data, title="cluster_metric.pdb", use_beta=True)
    print("Min value for metric", minMetric, namesPDB[minInd])

    with open("conformation_data.dat", "w") as fw:
        fw.write("PDB name      Epoch Trajectory   Snapshot   COM x       y       z     Metric\n")
        for j, name in enumerate(namesPDB):
            info = [name.rjust(8)]+[str(x).rjust(10) for x in confData[j]]+[str(np.round(d, 3)).rjust(7) for d in data[j, :-1]] + [str(np.round(data[j, -1], 2)).rjust(10)]
            fw.write("{:s} {:s} {:s} {:s} {:s} {:s} {:s} {:s}\n".format(*tuple(info)))
Exemplo n.º 3
0
def main(path, resname, nProc):
    pdbs = glob.glob(os.path.join(path, "cluster_*.pdb"))
    pool = mp.Pool(nProc)
    workers = []
    for pdb_num in range(len(pdbs)):
        workers.append(pool.apply_async(get_com, args=(os.path.join(path, "cluster_%d.pdb" % pdb_num), resname)))
    pool.close()
    com = [worker.get() for worker in workers]
    utilities.write_PDB_clusters(com, title=os.path.join(path, "clusters.pdb"))
Exemplo n.º 4
0
def main(lagtimes,
         clusters_file,
         disctraj,
         trajs,
         n_clusters,
         plots_path,
         save_plot,
         show_plot,
         lagtime_resolution=20):
    if disctraj is not None:
        dtraj_files = glob.glob(os.path.join(disctraj, "*traj*.disctraj"))
        dtrajs = [np.loadtxt(f, dtype=int) for f in dtraj_files]
        clusterCenters = np.loadtxt(clusters_file)
    else:
        clusteringObject = cluster.Cluster(n_clusters,
                                           trajs,
                                           "traj*",
                                           alwaysCluster=False,
                                           discretizedPath=disctraj)
        if clusters_file is not None:
            # only assign
            clusteringObject.clusterCentersFile = clusters_file
        clusteringObject.clusterTrajectories()
        clusterCenters = clusteringObject.clusterCenters
        dtrajs = clusteringObject.dtrajs
    Q = []
    for lag in lagtimes:
        msm_obj = msm.estimate_markov_model(dtrajs, lag)
        counts = msm_obj.count_matrix_full
        Q.append(counts.diagonal() / counts.sum())
    Q = np.array(Q)

    print("Clusters over 0.01 metastability")
    correlation_limit = 0.01
    states2 = np.where(Q[-1] > correlation_limit)[0]
    size2 = states2.size
    if len(states2):
        print(" ".join(map(str, states2)))
    print("Number of clusters:", size2,
          ", %.2f%% of the total" % (100 * size2 / float(n_clusters)))
    utilities.write_PDB_clusters(np.hstack((clusterCenters, Q[:-1].T)),
                                 use_beta=True,
                                 title="cluster_Q.pdb")
    if plots_path is None:
        plots_path = ""
    else:
        utilities.makeFolder(plots_path)
    create_plots(Q,
                 plots_path,
                 save_plot,
                 show_plot,
                 n_clusters,
                 lagtimes,
                 threshold=2.0)
Exemplo n.º 5
0
def writeCentersInfo(centersInfo,
                     folderPath,
                     ligand_resname,
                     nTICs,
                     numClusters,
                     trajsUniq,
                     clustersCentersFolder,
                     nTraj,
                     topology=None):
    if topology is not None:
        topology_contents = utilities.getTopologyFile(topology)
    else:
        topology_contents = None
    if not os.path.exists(clustersCentersFolder):
        os.makedirs(clustersCentersFolder)
    COM_list = []
    for clusterNum in centersInfo:
        epoch, trajNum, snap = centersInfo[clusterNum]['structure']
        COM_list.append(trajsUniq[int(epoch) * nTraj + (trajNum - 1)][snap])
        # Accept non-pdb trajectories
        trajFile = glob.glob(
            os.path.join(folderPath, "%s/trajectory_%d.*" % (epoch, trajNum)))
        trajFile = trajFile[0]
        snapshots = utilities.getSnapshots(trajFile, topology=topology)
        pdb_object = atomset.PDB()
        pdb_object.initialise(snapshots[snap],
                              resname=ligand_resname,
                              topology=topology_contents)
        pdb_object.writePDB(
            str(
                os.path.join(str(clustersCentersFolder),
                             "cluster_%d.pdb" % clusterNum)))

    distances = [[nC, centersInfo[nC]['minDist']] for nC in range(numClusters)]
    np.savetxt(
        os.path.join(clustersCentersFolder,
                     "clusterDistances_%dcl_%dTICs.dat" %
                     (numClusters, nTICs)), distances)
    utilities.write_PDB_clusters(
        COM_list,
        os.path.join(clustersCentersFolder,
                     "clustersCenters_%dcl_%dTICs.pdb" % (numClusters, nTICs)))
Exemplo n.º 6
0
def main(metricCol, lig_resname, nTrajs, stride, atomId, saving_frequency):
    folders = utilities.get_epoch_folders(".")
    box_center = None
    templateLine = "HETATM%s    H BOX Z 501    %s%s%s  0.75%s            H  \n"
    for epoch in folders:
        print("Processing epoch %s" % epoch)
        data = []
        confData = []
        maxEpoch = -1
        maxEpochCoords = None
        for iTraj in range(1, nTrajs):
            report = np.loadtxt("%s/report_%d" % (epoch, iTraj))
            if len(report.shape) < 2:
                report = report[np.newaxis, :]
            maxTrajIndex = np.argmax(report[:, metricCol])
            snapshots = utilities.getSnapshots("%s/trajectory_%d.pdb" % (epoch, iTraj))
            for i, snapshot in enumerate(itertools.islice(snapshots, 0, None, stride)):
                report_line = i * stride * saving_frequency
                data.append(get_coords(snapshot, atomId, lig_resname) + [report[report_line, metricCol]])
                confData.append((epoch, iTraj, report_line))
            if report[maxTrajIndex, metricCol] > maxEpoch:
                maxEpoch = report[maxTrajIndex, metricCol]
                maxEpochCoords = get_coords(snapshots[maxTrajIndex], atomId, lig_resname)
            if box_center is None and iTraj == 1:
                box_center = data[0][:3]
        data = np.array(data)
        minInd = np.argmin(data[:, -1])
        minMetric = data[minInd, -1]
        data[:, -1] -= minMetric
        utilities.write_PDB_clusters(data, title="epoch_%s.pdb" % epoch, use_beta=True)
        print("Max value for metric", maxEpoch, maxEpochCoords)
        with open("epoch_%s.pdb" % epoch, "a") as fa:
            fa.write("TER\n")
            serial = ("%d" % data.shape[0]).rjust(5)
            x = ("%.3f" % box_center[0]).rjust(8)
            y = ("%.3f" % box_center[1]).rjust(8)
            z = ("%.3f" % box_center[2]).rjust(8)
            g = ("%.2f" % 0).rjust(6)
            fa.write(templateLine % (serial, x, y, z, g))
        box_center = maxEpochCoords
def main(lagtime,
         clusters_file,
         disctraj,
         trajs,
         n_clusters,
         plots_path,
         save_plot,
         show_plot,
         lagtime_resolution=20):
    lagtimes = list(range(1, lagtime, lagtime_resolution))
    n_lags = len(lagtimes)
    if disctraj is None:
        clusteringObject = cluster.Cluster(n_clusters,
                                           trajs,
                                           "traj*",
                                           alwaysCluster=False)
        if clusters_file is not None:
            # only assign
            utilities.makeFolder(clusteringObject.discretizedFolder)
            clusteringObject.clusterCentersFile = clusters_file
        clusteringObject.clusterTrajectories()
        disctraj = clusteringObject.discretizedFolder
        clusterCenters = clusteringObject.clusterCenters
    else:
        clusterCenters = utilities.loadtxtfile(clusters_file)
    if len(clusterCenters) != n_clusters:
        raise ValueError(
            "Number of clusters specified in the -n parameter does not match the provided clusters"
        )
    print("Calculating autocorrelation...")
    dtrajs = glob.glob(os.path.join(disctraj, "traj*"))
    dtrajs_loaded = [
        utilities.loadtxtfile(dtraj, dtype=int) for dtraj in dtrajs
    ]

    autoCorr = utils.calculateAutoCorrelation(lagtimes, dtrajs_loaded,
                                              n_clusters, n_lags)
    np.save("autoCorr.npy", autoCorr)
    # __cleanupFiles(parameters.trajWildcard, False)

    utilities.write_PDB_clusters(np.vstack(
        (clusterCenters.T, np.abs(autoCorr[:, -1]))).T,
                                 use_beta=True,
                                 title="cluster_autoCorr.pdb")
    print("Clusters over correlation time limit")
    correlation_limit = np.exp(-1)
    states2 = np.where(autoCorr[:, -1] > correlation_limit)[0]
    size2 = states2.size
    if len(states2):
        print(" ".join(map(str, states2)))
    print("Number of clusters:", size2,
          ", %.2f%% of the total" % (100 * size2 / float(n_clusters)))
    print("Clusters with more than 0.1 autocorrelation")
    states1 = np.where(autoCorr[:, -1] > 0.1)[0]
    size1 = states1.size
    if len(states1):
        print(" ".join(map(str, states1)))
    print("Number of clusters:", size1,
          ", %.2f%% of the total" % (100 * size1 / float(n_clusters)))
    if size2 > 0:
        print("Correlation time not achieved at lagtime %d" % lagtime)
    else:
        for i in range(len(lagtimes)):
            states = np.where(autoCorr[:, -i - 1] > correlation_limit)[0]
            if len(states):
                string_states = ", ".join(map(str, states))
                print("Correlation time %d, for states: %s" %
                      (lagtimes[-i], string_states))
                break

    if plots_path is None:
        plots_path = ""
    else:
        utilities.makeFolder(plots_path)
    create_plots(autoCorr,
                 plots_path,
                 save_plot,
                 show_plot,
                 n_clusters,
                 lagtimes,
                 threshold=2.0)
Exemplo n.º 8
0
    )
    args = parser.parse_args()
    return args.stride


if __name__ == "__main__":
    stride = parse_arguments()
    data_folder = "tica_COM/"
    COM_tica = []
    files = glob.glob(data_folder + "traj_*")
    files.sort(key=sort_split_by_numbers)
    for traj in files:
        traj_data = np.loadtxt(traj)
        if len(traj_data.shape) < 2:
            COM_tica.append(traj_data.tolist())
        else:
            COM_tica.extend(traj_data[::stride].tolist())

    COM_tica = np.array(COM_tica)
    # process each TICA so the beta value visualization works (shift to 0)
    COM_tica[:, 3:] -= np.min(COM_tica[:, 3:], axis=0)

    utilities.makeFolder("tica_pdb")
    nConf, nTICS = COM_tica.shape
    ind = [0, 1, 2, 0]
    for i in range(3, nTICS):
        ind[-1] = i
        utilities.write_PDB_clusters(COM_tica[:, ind],
                                     title="tica_pdb/tica_%d.pdb" % (i - 2),
                                     use_beta=True)
Exemplo n.º 9
0
def main(nEigenvectors,
         nRuns,
         m,
         outputFolder,
         plotEigenvectors,
         plotGMRQ,
         plotPMF,
         clusters,
         lagtimes,
         native,
         save_plots,
         showPlots,
         filtered,
         destFolder,
         resname,
         plotTransitions=True):
    minPos = get_min_Pos(native, resname)
    if save_plots and outputFolder is None:
        outputFolder = "plots_MSM"
    eigenPlots = os.path.join(outputFolder, "eigenvector_plots")
    GMRQPlots = os.path.join(outputFolder, "GMRQ_plots")
    PMFPlots = os.path.join(outputFolder, "PMF_plots")
    TransitionPlots = os.path.join(outputFolder, "transitions")
    if save_plots and not os.path.exists(outputFolder):
        os.makedirs(outputFolder)
    if filtered is not None:
        filter_str = "_filtered"
    else:
        filter_str = ""
    if plotEigenvectors and save_plots and not os.path.exists(eigenPlots):
        os.makedirs(eigenPlots)
    if plotGMRQ and save_plots and not os.path.exists(GMRQPlots):
        os.makedirs(GMRQPlots)
    if plotPMF and save_plots and not os.path.exists(PMFPlots):
        os.makedirs(PMFPlots)
    if plotTransitions and save_plots and not os.path.exists(TransitionPlots):
        os.makedirs(TransitionPlots)
    minPos = np.array(minPos)
    GMRQValues = {}
    print("Running from " + destFolder)
    if plotGMRQ:
        GMRQValues = []

    if not os.path.exists(os.path.join(destFolder, "eigenvectors")):
        os.makedirs(os.path.join(destFolder, "eigenvectors"))
    for i in range(nRuns):
        titleVar = "%s, run %d" % (destFolder, i)
        if plotGMRQ or plotEigenvectors:
            msm_object = utilities.readClusteringObject(
                os.path.join(destFolder, "MSM_object_%d.pkl" % i))
        if plotGMRQ:
            GMRQValues.append(np.sum(msm_object.eigenvalues()[:m]))
        if plotEigenvectors or plotPMF:
            clusters = np.loadtxt(
                os.path.join(destFolder, "clusterCenters_%d.dat" % i))
            distance = np.linalg.norm(clusters - minPos, axis=1)
            volume = np.loadtxt(
                os.path.join(destFolder, "volumeOfClusters_%d.dat" % i))
            print("Total volume for system %s , run %d" % (destFolder, i),
                  volume.sum())
            if filtered is not None:
                volume = volume[filtered]
                clusters = clusters[filtered]
                distance = distance[filtered]
        if plotEigenvectors:
            if clusters.size != msm_object.stationary_distribution.size:
                mat = computeDeltaG.reestimate_transition_matrix(
                    msm_object.count_matrix_full)
            else:
                mat = msm_object.transition_matrix
            _, _, L = rdl_decomposition(mat)
            figures = []
            axes = []
            for _ in range((nEigenvectors - 1) // 4 + 1):
                f, axarr = plt.subplots(2, 2, figsize=(12, 12))
                f.suptitle(titleVar)
                figures.append(f)
                axes.append(axarr)

            for j, row in enumerate(L[:nEigenvectors]):
                pdb_filename = os.path.join(destFolder, "eigenvectors",
                                            "eigen_%d_run_%d.pdb" % (j + 1, i))
                if j:
                    atomnames = utilities.getAtomNames(
                        utilities.sign(row, tol=1e-3))
                    utilities.write_PDB_clusters(clusters,
                                                 use_beta=False,
                                                 elements=atomnames,
                                                 title=pdb_filename)
                else:
                    utilities.write_PDB_clusters(np.vstack(
                        (clusters.T, row)).T,
                                                 use_beta=True,
                                                 elements=None,
                                                 title=pdb_filename)
                if filtered is not None:
                    row = row[filtered]
                np.savetxt(
                    os.path.join(
                        destFolder, "eigenvectors",
                        "eigen_%d_run_%d%s.dat" % (j + 1, i, filter_str)), row)
                axes[j // 4][(j // 2) % 2, j % 2].scatter(distance, row)
                axes[j // 4][(j // 2) % 2,
                             j % 2].set_xlabel("Distance to minimum")
                axes[j // 4][(j // 2) % 2,
                             j % 2].set_ylabel("Eigenvector %d" % (j + 1))
            if save_plots:
                for j, fg in enumerate(figures):
                    fg.savefig(
                        os.path.join(
                            eigenPlots, "eigenvector_%d_run_%d%s.png" %
                            (j + 1, i, filter_str)))
                plt.figure()
                plt.scatter(distance, L[0])
                plt.xlabel("Distance to minimum")
                plt.ylabel("Eigenvector 1")
                plt.savefig(
                    os.path.join(
                        eigenPlots,
                        "eigenvector_1_alone_run_%d%s.png" % (i, filter_str)))
        if plotPMF:
            data = np.loadtxt(os.path.join(destFolder, "pmf_xyzg_%d.dat" % i))
            g = data[:, -1]
            if filtered is not None:
                g = g[filtered]
            print("Clusters with less than 2 PMF:")
            print(" ".join(map(str, np.where(g < 2)[0])))
            print("")
            plt.figure()
            plt.title("%s" % (destFolder))
            plt.scatter(distance, g)
            plt.xlabel("Distance to minima")
            plt.ylabel("PMF")
            if save_plots:
                plt.savefig(
                    os.path.join(PMFPlots,
                                 "pmf_run_%d%s.png" % (i, filter_str)))
    if plotGMRQ:
        for t in GMRQValues:
            plt.figure()
            plt.title("%s" % (destFolder))
            plt.xlabel("Number of states")
            plt.ylabel("GMRQ")
            plt.boxplot(GMRQValues)
            if save_plots:
                plt.savefig(os.path.join(GMRQPlots, "GMRQ.png" % t))
    if plotTransitions:
        sasas = []
        for file in glob.glob("*/repor*"):
            sasas.extend(
                pd.read_csv(file, sep='    ',
                            engine='python')["sasaLig"].values)
        sasas = np.array(sasas)
        plt.figure()
        plt.title("%s" % (destFolder))
        plt.xlabel("SASA")
        plt.ylabel("Transition Counts")
        plt.hist(sasas, 50, alpha=0.75)
        if save_plots:
            plt.savefig(os.path.join(TransitionPlots, "transition_hist.png"))
    if showPlots and (plotEigenvectors or plotGMRQ or plotPMF):
        plt.show()
Exemplo n.º 10
0
def main(nEigenvectors, nRuns, m, outputFolder, plotEigenvectors, plotGMRQ,
         plotPMF, clusters, lagtimes, minPos, save_plots, showPlots, filtered,
         destFolder, sasa_col, path_to_report):
    if save_plots and outputFolder is None:
        outputFolder = "plots_MSM"
    if outputFolder is not None:
        eigenPlots = os.path.join(outputFolder, "eigenvector_plots")
        GMRQPlots = os.path.join(outputFolder, "GMRQ_plots")
        PMFPlots = os.path.join(outputFolder, "PMF_plots")
        if save_plots and not os.path.exists(outputFolder):
            os.makedirs(outputFolder)
    if filtered is not None:
        filter_str = "_filtered"
    else:
        filter_str = ""
    if plotEigenvectors and save_plots and not os.path.exists(eigenPlots):
        os.makedirs(eigenPlots)
    if plotGMRQ and save_plots and not os.path.exists(GMRQPlots):
        os.makedirs(GMRQPlots)
    if plotPMF and save_plots and not os.path.exists(PMFPlots):
        os.makedirs(PMFPlots)
    minPos = np.array(minPos)
    GMRQValues = {}
    print("Running from", destFolder)
    if plotGMRQ:
        GMRQValues = []

    if not os.path.exists(os.path.join(destFolder, "eigenvectors")):
        os.makedirs(os.path.join(destFolder, "eigenvectors"))
    for i in range(nRuns):
        if sasa_col is not None:
            representatives_files = os.path.join(
                destFolder,
                "representative_structures/representative_structures_%d.dat" %
                i)
            sasa = getSASAvalues(representatives_files, sasa_col,
                                 path_to_report)

        titleVar = "%s, run %d" % (destFolder, i)
        if plotGMRQ or plotEigenvectors:
            msm_object = utilities.readClusteringObject(
                os.path.join(destFolder, "MSM_object_%d.pkl" % i))
        if plotGMRQ:
            GMRQValues.append(np.sum(msm_object.eigenvalues()[:m]))
        if plotEigenvectors or plotPMF:
            clusters = np.loadtxt(
                os.path.join(destFolder, "clusterCenters_%d.dat" % i))
            distance = np.linalg.norm(clusters - minPos, axis=1)
            volume = np.loadtxt(
                os.path.join(destFolder, "volumeOfClusters_%d.dat" % i))
            print("Total volume for system %s , run %d" % (destFolder, i),
                  volume.sum())
            if filtered is not None:
                volume = volume[filtered]
                clusters = clusters[filtered]
                distance = distance[filtered]
                if sasa_col is not None:
                    sasa = sasa[filtered]
        if plotEigenvectors:
            if clusters.size != msm_object.stationary_distribution.size:
                mat = computeDeltaG.reestimate_transition_matrix(
                    msm_object.count_matrix_full)
            else:
                mat = msm_object.transition_matrix
            _, _, L = rdl_decomposition(mat)
            figures = []
            axes = []
            for _ in range((nEigenvectors - 1) // 4 + 1):
                f, axarr = plt.subplots(2, 2, figsize=(12, 12))
                f.suptitle(titleVar)
                figures.append(f)
                axes.append(axarr)

            for j, row in enumerate(L[:nEigenvectors]):
                pdb_filename = os.path.join(destFolder, "eigenvectors",
                                            "eigen_%d_run_%d.pdb" % (j + 1, i))
                if j:
                    atomnames = utilities.getAtomNames(
                        utilities.sign(row, tol=1e-3))
                    utilities.write_PDB_clusters(clusters,
                                                 use_beta=False,
                                                 elements=atomnames,
                                                 title=pdb_filename)
                else:
                    utilities.write_PDB_clusters(np.vstack(
                        (clusters.T, row)).T,
                                                 use_beta=True,
                                                 elements=None,
                                                 title=pdb_filename)
                if filtered is not None:
                    row = row[filtered]
                np.savetxt(
                    os.path.join(
                        destFolder, "eigenvectors",
                        "eigen_%d_run_%d%s.dat" % (j + 1, i, filter_str)), row)
                axes[j // 4][(j // 2) % 2, j % 2].scatter(distance, row)
                axes[j // 4][(j // 2) % 2,
                             j % 2].set_xlabel("Distance to minimum")
                axes[j // 4][(j // 2) % 2,
                             j % 2].set_ylabel("Eigenvector %d" % (j + 1))
            Q = msm_object.count_matrix_full.diagonal(
            ) / msm_object.count_matrix_full.sum()
            plt.figure()
            plt.scatter(distance, Q)
            plt.xlabel("Distance to minimum")
            plt.ylabel("Metastability")
            if save_plots:
                plt.savefig(
                    os.path.join(eigenPlots,
                                 "Q_run_%d%s.png" % (i, filter_str)))
            if save_plots:
                for j, fg in enumerate(figures):
                    fg.savefig(
                        os.path.join(
                            eigenPlots, "eigenvector_%d_run_%d%s.png" %
                            (j + 1, i, filter_str)))
                plt.figure()
                plt.scatter(distance, L[0])
                plt.xlabel("Distance to minimum")
                plt.ylabel("Eigenvector 1")
                plt.savefig(
                    os.path.join(
                        eigenPlots,
                        "eigenvector_1_alone_run_%d%s.png" % (i, filter_str)))
        if plotPMF:
            data = np.loadtxt(os.path.join(destFolder, "pmf_xyzg_%d.dat" % i))
            g = data[:, -1]
            annotations = ["Cluster %d" % i for i in range(g.size)]
            if filtered is not None:
                g = g[filtered]
                annotations = np.array(annotations)[filtered].tolist()
            print("Clusters with less than 2 PMF:")
            print(" ".join(map(str, np.where(g < 2)[0])))
            print("")
            fig_pmf, axarr = plt.subplots(2, 2, figsize=(12, 12))
            fig_pmf.suptitle(titleVar)
            sc1 = axarr[1, 0].scatter(distance, g)
            sc2 = axarr[0, 1].scatter(distance, volume)
            sc3 = axarr[0, 0].scatter(g, volume)
            axes = [axarr[0, 1], axarr[1, 0], axarr[0, 0]]
            scs = [sc2, sc1, sc3]
            if sasa_col is not None:
                axarr[1, 1].scatter(sasa, g)
            axarr[1, 0].set_xlabel("Distance to minima")
            axarr[1, 0].set_ylabel("PMF")
            axarr[0, 1].set_xlabel("Distance to minima")
            axarr[0, 1].set_ylabel("Volume")
            axarr[0, 0].set_xlabel("PMF")
            axarr[0, 0].set_ylabel("Volume")
            annot1 = axarr[1, 0].annotate("",
                                          xy=(0, 0),
                                          xytext=(20, 20),
                                          textcoords="offset points",
                                          bbox=dict(boxstyle="round", fc="w"),
                                          arrowprops=dict(arrowstyle="->"))
            annot1.set_visible(False)
            annot2 = axarr[0, 1].annotate("",
                                          xy=(0, 0),
                                          xytext=(20, 20),
                                          textcoords="offset points",
                                          bbox=dict(boxstyle="round", fc="w"),
                                          arrowprops=dict(arrowstyle="->"))
            annot2.set_visible(False)
            annot3 = axarr[0, 0].annotate("",
                                          xy=(0, 0),
                                          xytext=(20, 20),
                                          textcoords="offset points",
                                          bbox=dict(boxstyle="round", fc="w"),
                                          arrowprops=dict(arrowstyle="->"))
            annot3.set_visible(False)
            annot_list = [annot2, annot1, annot3]
            if sasa_col is not None:
                axarr[1, 1].set_xlabel("SASA")
                axarr[1, 1].set_ylabel("PMF")
            if save_plots:
                fig_pmf.savefig(
                    os.path.join(PMFPlots,
                                 "pmf_run_%d%s.png" % (i, filter_str)))
    if plotGMRQ:
        for t in GMRQValues:
            plt.figure()
            plt.title("%s" % (destFolder))
            plt.xlabel("Number of states")
            plt.ylabel("GMRQ")
            plt.boxplot(GMRQValues)
            if save_plots:
                plt.savefig(os.path.join(GMRQPlots, "GMRQ.png" % t))
    if showPlots and (plotEigenvectors or plotGMRQ or plotPMF):
        if plotPMFs:

            def update_annot(ind, sc, annot):
                """Update the information box of the selected point"""
                pos = sc.get_offsets()[ind["ind"][0]]
                annot.xy = pos
                annot.set_text(annotations[int(ind["ind"][0])])
                # annot.get_bbox_patch().set_facecolor(cmap(norm( z_values[ind["ind"][0]])))

            def hover(event):
                """Action to perform when hovering the mouse on a point"""
                # vis = any([annot.get_visible() for annot in annot_list])
                for i, ax_comp in enumerate(axes):
                    vis = annot_list[i].get_visible()
                    if event.inaxes == ax_comp:
                        for j in range(len(axes)):
                            if j != i:
                                annot_list[j].set_visible(False)
                        cont, ind = scs[i].contains(event)
                        if cont:
                            update_annot(ind, scs[i], annot_list[i])
                            annot_list[i].set_visible(True)
                            fig_pmf.canvas.draw_idle()
                        else:
                            if vis:
                                annot_list[i].set_visible(False)
                                fig_pmf.canvas.draw_idle()

            fig_pmf.canvas.mpl_connect("motion_notify_event", hover)
        plt.show()