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)
def testEpsilonCalculatorWithDensity(self): params = spawning.SpawningParams() params.epsilon = 0.5 params.metricWeights = "linear" params.nclusters = 100 clusters = clustering.Clusters() sizes = [6, 2, 3, 1] energies = [-4, -2, -2, 0] contacts = [4, 3, 2, 1] for size, energy, ncontacts in zip(sizes, energies, contacts): cluster = clustering.Cluster(None, None, None, None, metricCol=0) cluster.elements = size cluster.metrics = [energy] 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) epsilon = spawning.EpsilonDegeneracyCalculator(params, densityCalculator) trajs = 16 degeneracy = epsilon.calculate(clusters.clusters, trajs) golden = np.array([6, 4, 4, 2]) np.testing.assert_array_equal(degeneracy, golden)
def testDensityCalculatorContinuousParams(self): spawningBlock = {type: "irrelevant", "density": {"type": "continuous"}} densityCalculatorBuilder = densitycalculator.DensityCalculatorBuilder() densityCalculator = densityCalculatorBuilder.build(spawningBlock) self.assertAlmostEqual(densityCalculator.calculate(0.5, 8), 1) self.assertAlmostEqual(densityCalculator.calculate(1.5, 8), 8) self.assertAlmostEqual(densityCalculator.calculate(0.5, 6), 1) self.assertAlmostEqual(densityCalculator.calculate(1.5, 6), 8) self.assertAlmostEqual(densityCalculator.calculate(0.5, 4), 1) self.assertAlmostEqual(densityCalculator.calculate(1.5, 4), 8)
def testDensityCalculatorHeavisideNoParams(self): spawningBlock = {type: "irrelevant", "density": {"type": "heaviside"}} densityCalculatorBuilder = densitycalculator.DensityCalculatorBuilder() densityCalculator = densityCalculatorBuilder.build(spawningBlock) goldenValues = [1.] goldenConditions = [] self.assertEqual( densityCalculator.type, densitycalculatortypes.DENSITY_CALCULATOR_TYPES.heaviside) self.assertEqual(densityCalculator.values, goldenValues) self.assertEqual(densityCalculator.conditions, goldenConditions)
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 ""
"values": [0.2, 0.3, 0.5, 0.8], "conditions": [1.0, 0.75, 0.5] } } }) # correlation # similarityEvaluator = clustering.CMSimilarityEvaluator("correlation") # thresholdCalculatorAcc = thresholdCalculatorBuilder.build({ # "thresholdCalculator": { # "type": "constant", # "params": { # "value": 0.15 # } # } # }) densityCalculatorBuilder = densitycalculator.DensityCalculatorBuilder() # densityCalculator = densityCalculatorBuilder.build({ # "density": { # "type": "heaviside", # "params": { # "conditions": [1.5, 1.0, 0.0], # "values": [8.0, 2.37, 1.0, 0.5] # } # } # } # ) densityCalculator = densityCalculatorBuilder.build({}) densityCalculator = densityCalculatorBuilder.build( {"density": { "type": "continuous" }})
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)
def testDensityCalculatorUndefinedBlock(self): spawningBlock = {} densityCalculatorBuilder = densitycalculator.DensityCalculatorBuilder() densityCalculator = densityCalculatorBuilder.build(spawningBlock) self.assertEqual(densityCalculator.type, densitycalculatortypes.DENSITY_CALCULATOR_TYPES.null)
def testDensityCalculatorNullCalculator(self): spawningBlock = {type: "irrelevant", "density": {"type": "null"}} densityCalculatorBuilder = densitycalculator.DensityCalculatorBuilder() densityCalculator = densityCalculatorBuilder.build(spawningBlock) self.assertEqual(densityCalculator.type, densitycalculatortypes.DENSITY_CALCULATOR_TYPES.null)