def main(trajsPerEpoch, clusters, lagtimes, nruns):
    runFolder = os.getcwd()
    print("Running from " + runFolder)
    for tau, k in itertools.product(lagtimes, clusters):
        destFolder = "%dlag/%dcl" % (tau, k)
        if not os.path.exists(destFolder):
            os.makedirs(destFolder)
        os.chdir(destFolder)
        folders_MSM = glob.glob("MSM_*")
        if isfinished(folders_MSM):
            print("Skipping run with lagtime %d, clusters %d" % (tau, k))
            os.chdir(runFolder)
            continue
        else:
            for folder in folders_MSM:
                shutil.rmtree(folder)
        prepareMSMFolders.main(trajsPath=runFolder)
        os.chdir("MSM_0")
        print("***************")
        print("Estimating dG value in folder" + os.getcwd())
        parameters = estimateDG.Parameters(ntrajs=None, length=None, lagtime=tau,
                                           nclusters=k, nruns=nruns, skipFirstSteps=0,
                                           useAllTrajInFirstRun=True,
                                           computeDetailedBalance=True,
                                           trajWildcard="traj_*",
                                           folderWithTraj="rawData",
                                           lagtimes=[1, 10, 25, 50, 100, 250, 400, 500, 600, 1000],
                                           clusterCountsThreshold=0)
        try:
            estimateDG.estimateDG(parameters, cleanupClusterCentersAtStart=True)
        except Exception as err:
            if "distribution contains entries smaller" in str(err):
                print("Caught exception in step with lag %d and k %d, moving to next iteration" % (tau, k))
                with open("error.txt", "w") as fe:
                    fe.write("Caught exception in step with lag %d and k %d, moving to next iteration\n" % (tau, k))
            else:
                raise_(*sys.exc_info())
        os.chdir(runFolder)
Example #2
0
def main(trajsPerEpoch,
         lagtime,
         nclusters,
         clusteringStride=1,
         nruns=10,
         lagtimes=[1, 10, 25, 50, 100, 250, 400, 500, 600, 1000]):
    allFolders = np.array(glob.glob("MSM_*"))
    epochs = [int(folder[4:]) for folder in allFolders]
    args = np.argsort(epochs)
    sortedFolders = allFolders[args]
    origDir = os.getcwd()
    resultsFile = os.path.join(origDir, "results.txt")

    with open(resultsFile, "a") as f:
        f.write("#Epoch DG StdDG Db StdDb\n")
        f.write("#=======================\n")

    resultsEpoch = []
    initialEpoch = 0
    for i, folder in enumerate(sortedFolders[initialEpoch:]):
        epoch = i + initialEpoch
        print(epoch, folder)
        os.chdir(folder)
        parameters = estimateDG.Parameters(ntrajs=trajsPerEpoch * (epoch + 1),
                                           length=None,
                                           lagtime=lagtime,
                                           lagtimes=lagtimes,
                                           nclusters=nclusters,
                                           nruns=nruns,
                                           useAllTrajInFirstRun=True,
                                           computeDetailedBalance=True,
                                           trajWildcard="traj_*",
                                           folderWithTraj="rawData",
                                           clusterCountsThreshold=0,
                                           clusteringStride=clusteringStride)
        try:
            dG, stdDg, db, stdDb = estimateDG.estimateDG(
                parameters, cleanupClusterCentersAtStart=True)
            print(
                "FINAL RESULTS EPOCH %d: dG: %f +- %f, asymmetric fluxes: %f +- %f"
                % (epoch, dG, stdDg, db, stdDb))
            resultsEpoch.append([dG, stdDg, db, stdDb])
            with open(resultsFile, "a") as f:
                f.write("%d %.3f %.3f %.3f %.3f\n" %
                        (epoch, dG, stdDg, db, stdDb))
        except Exception as err:
            resultsEpoch.append(["Estimation in this epoch crashed"])
            if "distribution contains entries smaller" in str(err):
                print(
                    "Caught exception in folder %s with lag %d and k %d, moving to next iteration"
                    % (folder, lagtime, nclusters))
                with open("error.txt", "w") as fe:
                    fe.write(
                        "Caught exception in folder %s with lag %d and k %d, moving to next iteration\n"
                        % (folder, lagtime, nclusters))
            else:
                raise_(*sys.exc_info())
        os.chdir("..")

    print("Results")
    print("epoch, DG, stdDg, DB, stdDb")
    print("=====")
    for i, results in enumerate(resultsEpoch):
        print(i, results)