Exemplo n.º 1
0
    def testInverselyProportionalToPopulationCalculatorWithDensity(self):
        # test 3
        clusters = clustering.Clusters()
        sizes = [6, 2, 3, 1]
        contacts = [4, 3, 2, 1]
        for size, ncontacts in zip(sizes, contacts):
            cluster = clustering.Cluster(None, None, None, None)
            cluster.elements = size
            cluster.contacts = ncontacts
            clusters.addCluster(cluster)

        clusteringBlock = {
            "density": {
                "type": "heaviside",
                "params": {
                    "values": [6, 2, 3, 1],
                    "conditions": [3, 2, 1]
                }
            }
        }
        densityCalculatorBuilder = densitycalculator.DensityCalculatorBuilder()
        densityCalculator = densityCalculatorBuilder.build(clusteringBlock)
        params = spawning.SpawningParams()

        inverselyProp = spawning.InverselyProportionalToPopulationCalculator(
            params, densityCalculator)
        trajs = 8
        degeneracy = inverselyProp.calculate(clusters.clusters, trajs)
        golden = [2, 2, 2, 2]

        self.assertEqual(degeneracy, golden)
Exemplo n.º 2
0
    def testInverselyProportionalToPopulationCalculator(self):
        clusters = clustering.Clusters()
        sizes = [6, 2, 3, 1]
        for size in sizes:
            cluster = clustering.Cluster(None, None, None, None)
            cluster.elements = size
            clusters.addCluster(cluster)

        params = spawning.SpawningParams()
        inverselyProp = spawning.InverselyProportionalToPopulationCalculator(
            params)
        trajs = 10
        degeneracy = inverselyProp.calculate(clusters.clusters, trajs)
        golden = [1, 2, 2, 5]

        self.assertEqual(degeneracy, golden)
Exemplo n.º 3
0
def main(args):

    # Parameters
    clusteringObj = utilities.readClusteringObject(args.clusteringObj)
    native = args.native
    pathwayFilename = args.pathwayFilename
    ntrajs = args.ntrajs
    threshold = args.threshold
    RMSDCalc = RMSDCalculator.RMSDCalculator(clusteringObj.symmetries)

    # use graph algorithm to establish a path
    initial_cluster = 0
    final_cluster = getOptimalCluster(clusteringObj, native, RMSDCalc)
    distanceMatrix = createNetworkMatrix(clusteringObj, threshold, RMSDCalc)
    predecessors = obtainShortestPath(distanceMatrix)
    pathway = createPathway(initial_cluster, final_cluster, predecessors)
    print "Pathway clusters:"
    print pathway

    # write pathway into a single trajectory
    writePathwayTrajectory(clusteringObj, pathway, pathwayFilename, native)

    # create clustering object with only the pathway clusters
    ClPath = clustering.Clustering()
    ClPath.clusters.clusters = map(
        lambda x: clusteringObj.clusters.clusters[x], pathway)

    # spawning along the trajectory
    spawningParams = spawning.SpawningParams()
    densityCalculatorBuilder = densitycalculator.DensityCalculatorBuilder()
    densityCalculator = densityCalculatorBuilder.build({})
    spawningPathway = spawning.InverselyProportionalToPopulationCalculator(
        densityCalculator)
    # Set a least 1 processors from the extrems of the path
    degeneracies = spawningPathway.calculate(ClPath.clusters.clusters,
                                             ntrajs - 2, spawningParams)
    degeneracies[0] += 1
    degeneracies[-1] += 1
    print "degeneracies over pathway:"
    print degeneracies
    print ""
Exemplo n.º 4
0
def main(jsonBlock):
    # Parameters
    firstControlFile = jsonBlock["firstControlFile"]
    ntrajs = jsonBlock["ntrajs"]
    resname = jsonBlock["resname"]
    symmetries = jsonBlock["symmetries"]
    trajFolder = jsonBlock["trajFolder"]
    clusteringObject = jsonBlock["clusteringObject"]
    clusteringThreshold = jsonBlock["clusteringThreshold"]
    pathwayFilename = jsonBlock["pathwayFilename"]
    templetizedInitialName = jsonBlock["templetizedInitialName"].encode()
    secondControlFileTemp = jsonBlock["secondControlFileTemp"]
    secondControlFile = jsonBlock["secondControlFile"]
    distanceThreshold = jsonBlock["distanceThreshold"]

    if firstControlFile:
        # Run first adaptive
        adaptiveSampling.main(firstControlFile)

    # Cluster trajectories

    ClOrd, thresholdCalculator = clusterTrajectories(resname,
                                                     trajFolder,
                                                     clusteringObject,
                                                     clusteringThreshold,
                                                     symmetries=symmetries)

    # use graph algorithm to establish a path
    initial_cluster = 0
    final_cluster = ClOrd.getOptimalMetric()
    pathway = createPathway(initial_cluster, final_cluster, ClOrd,
                            distanceThreshold)

    # write pathway into a single trajectory
    writePathwayTrajectory(ClOrd, pathway, pathwayFilename)

    # create clustering object with only the pathway clusters
    ClPath = OrderedContactsClustering(thresholdCalculator,
                                       resname=resname,
                                       reportBaseFilename="report",
                                       columnOfReportFile=4,
                                       symmetries=symmetries)
    ClPath.clusters.clusters = map(lambda x: ClOrd.clusters.clusters[x],
                                   pathway)

    # spawning along the trajectory
    spawningParams = spawning.SpawningParams()
    densityCalculatorBuilder = densitycalculator.DensityCalculatorBuilder()
    densityCalculator = densityCalculatorBuilder.build({})
    spawningPathway = spawning.InverselyProportionalToPopulationCalculator(
        densityCalculator)
    # Set a least 1 processors from the extrems of the path
    degeneracies = spawningPathway.calculate(ClPath.clusters.clusters,
                                             ntrajs - 2, spawningParams)
    degeneracies[0] += 1
    degeneracies[-1] += 1
    print "degeneracies over pathway:"
    print degeneracies
    print ""
    plots = False
    if plots:
        plotMetricsDegeneracy(ClPath, resname, degeneracies)

    # Prepare second adaptive
    makeNewControlFile(degeneracies, ClPath, templetizedInitialName,
                       secondControlFileTemp, secondControlFile)
    adaptiveSampling.main(secondControlFile)
    #     })

    ClCont = clustering.ContactsClustering(thresholdCalculator, resname=resname,
                                           reportBaseFilename="report",
                                           columnOfReportFile=4,
                                           contactThresholdDistance=contactThresholdDistance,
                                           symmetries=[], altSelection=altSel)

    ClAcc = clustering.ContactMapAccumulativeClustering(thresholdCalculatorAcc,
                                                        similarityEvaluator,
                                                        resname=resname,
                                                        reportBaseFilename="report",
                                                        columnOfReportFile=4,
                                                        contactThresholdDistance=contactThresholdDistance,
                                                        altSelection=altSel)
    spawningObject = spawning.InverselyProportionalToPopulationCalculator(densityCalculator)
    # spawningObject = spawning.UCBCalculator(densityCalculator)
    # spawningObject = spawning.EpsilonDegeneracyCalculator(densityCalculator)
    # spawningObject = spawning.REAPCalculator()
    # ClAcc.clusterInitialStructures(["/home/jgilaber/PR/PR_prog_initial_adaptive.pdb"])
    # ClCont.clusterInitialStructures(["/home/jgilaber/4DAJ/4DAJ_initial_adaptive.pdb"])
    # processorMapping = [0 for i in range(ntrajs-1)]
    if not os.path.exists("results"):
        os.makedirs("results")

    for i in range(nEpochs):
        path = ["%s/%d/traj*" % (simulation_path, i)]
        paths_report = ["%s/%d/report*" % (simulation_path, i)]
        trajs = clustering.getAllTrajectories(paths_report)
        total_snapshots = 0
        for traj in trajs: