def test_item_access(self): condensed_matrix_1 = CondensedMatrix([1.0, 4.5, 7.2, 8.5, 4.5, 7.8]) condensed_matrix_2 = CondensedMatrix([.0] * 6) complete_matrix = [[0.0, 1.0, 4.5, 7.2], [1.0, 0.0, 8.5, 4.5], [4.5, 8.5, 0.0, 7.8], [7.2, 4.5, 7.8, 0.0]] row_len = condensed_matrix_1.row_length for i in range(row_len): for j in range(row_len): condensed_matrix_2[i, j] = complete_matrix[i][j] ## The access for a complete and a condensed matrix is exactly the same for i in range(row_len): for j in range(row_len): self.assertAlmostEqual( condensed_matrix_1[i, j], complete_matrix[i][j], 6) #-> there are some errors, as it stores floats instead # of doubles ## And we can build a condensed matrix as a complete matrix self.assertItemsEqual(condensed_matrix_1.get_data(), condensed_matrix_2.get_data())
def test_item_access(self): condensed_matrix_1 = CondensedMatrix([1.0, 4.5,7.2, 8.5, 4.5, 7.8]) condensed_matrix_2 = CondensedMatrix([.0]*6) complete_matrix = [[0.0, 1.0, 4.5, 7.2], [1.0, 0.0, 8.5, 4.5], [4.5, 8.5, 0.0, 7.8], [7.2, 4.5, 7.8, 0.0]] row_len = condensed_matrix_1.row_length for i in range(row_len): for j in range(row_len): condensed_matrix_2[i,j] = complete_matrix[i][j] ## The access for a complete and a condensed matrix is exactly the same for i in range(row_len): for j in range(row_len): self.assertAlmostEqual(condensed_matrix_1[i,j],complete_matrix[i][j],6) #-> there are some errors, as it stores floats instead # of doubles ## And we can build a condensed matrix as a complete matrix self.assertItemsEqual(condensed_matrix_1.get_data(), condensed_matrix_2.get_data())
def test_list_creation(self): MAX_ELEMENTS = 30 DATA_LEN = (MAX_ELEMENTS * (MAX_ELEMENTS-1))/2 numpy_matrix_data = numpy.abs(numpy.random.rand(DATA_LEN)) np_matrix = CondensedMatrix(numpy_matrix_data) ls_matrix = CondensedMatrix(list(numpy_matrix_data)) self.assertEqual(ls_matrix.row_length, MAX_ELEMENTS) self.assertEqual(np_matrix.row_length, MAX_ELEMENTS) numpy.testing.assert_almost_equal(numpy_matrix_data, ls_matrix.get_data(), 7) numpy.testing.assert_almost_equal(numpy_matrix_data, np_matrix.get_data(), 7) numpy.testing.assert_almost_equal(np_matrix.get_data(), ls_matrix.get_data(), 7)
def get_rmsds_matrix(conforms, mode, sup, cores): print "Mode:", mode, "Superposition:", sup, "Number of cores:", cores if (mode == "cpu_serial" and not sup): calculator = pyRMSD.RMSDCalculator.RMSDCalculator( "NOSUP_OMP_CALCULATOR", conforms) elif (mode == "cpu_omp" and not sup): calculator = pyRMSD.RMSDCalculator.RMSDCalculator( "NOSUP_OMP_CALCULATOR", conforms) calculator.setNumberOfOpenMPThreads(int(cores)) elif (mode == "cpu_omp" and sup): calculator = pyRMSD.RMSDCalculator.RMSDCalculator( "QCP_OMP_CALCULATOR", conforms) calculator.setNumberOfOpenMPThreads(int(cores)) elif (mode == "cuda" and sup): calculator = pyRMSD.RMSDCalculator.RMSDCalculator( "QCP_CUDA_MEM_CALCULATOR", conforms) else: print "Wrong values to pyRMSD ! Please Fix" exit() rmsd = calculator.pairwiseRMSDMatrix() rmsd_matrix = CondensedMatrix(rmsd) inner_data = rmsd_matrix.get_data() np.save("Distances_Matrix.data", inner_data) return inner_data
def get_rmsds_matrix(conforms, mode, sup, cores, symm_groups=None): print("Mode:", mode, "Superposition:", sup, "Number of cores:", cores) if (mode == "cpu_serial" and not sup) or (mode == "cpu_omp" and not sup): calculator_name = "NOSUP_OMP_CALCULATOR" elif mode == "cpu_omp" and sup: calculator_name = "QCP_OMP_CALCULATOR" elif mode == "cuda" and sup: calculator_name = "QCP_CUDA_MEM_CALCULATOR" else: print("Wrong values to pyRMSD ! Please Fix") exit() if symm_groups: calculator = pyRMSD.RMSDCalculator.RMSDCalculator( calculator_name, fittingCoordsets=conforms, calculationCoordsets=conforms, calcSymmetryGroups=symm_groups) else: calculator = pyRMSD.RMSDCalculator.RMSDCalculator( calculator_name, conforms) # additionally set number of cores for parallel calculator if mode == "cpu_omp": calculator.setNumberOfOpenMPThreads(int(cores)) rmsd = calculator.pairwiseRMSDMatrix() rmsd_matrix = CondensedMatrix(rmsd) inner_data = rmsd_matrix.get_data() np.save("Distances_Matrix.data", inner_data) return inner_data
def test_force_sparsity(self): data = numpy.array([1., 4., 6., 2., 5., 3., 9., 7., 2., 4., 1., 1., 9.,3., 8.]) W = CondensedMatrix(data) SpectralTools.force_sparsity(W) W_expected = [ 0., 0., 6., 0., 5., 0., 9., 7., 0., 0., 0., 0., 9., 0., 8.] numpy.testing.assert_array_equal(W_expected, W.get_data())
def test_force_sparsity(self): data = numpy.array([1., 4., 6., 2., 5., 3., 9., 7., 2., 4., 1., 1., 9.,3., 8.]) W = CondensedMatrix(data) SpectralTools.force_sparsity(W) W_expected = [ 0., 0., 6., 0., 5., 0., 9., 7., 0., 0., 0., 0., 9., 0., 8.] numpy.testing.assert_array_equal(W_expected, W.get_data())
def get_rmsds_matrix(conforms, mode, sup, cores, symm_groups=None): if (mode == "cpu_serial" and not sup) or (mode == "cpu_omp" and not sup): calculator_name = "NOSUP_OMP_CALCULATOR" elif mode == "cpu_omp" and sup: calculator_name = "QCP_OMP_CALCULATOR" print("we are using QCP_OMP to compute RMSD") elif mode == "cuda" and sup: calculator_name = "QCP_CUDA_MEM_CALCULATOR" else: print("Wrong values to pyRMSD ! Please Fix") exit() if symm_groups: print("We have ambiguity.") s1 = parse_symm_groups_for_pyrmsd(symm_groups) calculator = pyRMSD.RMSDCalculator.RMSDCalculator( calculator_name, fittingCoordsets=conforms, calcSymmetryGroups=s1, fitSymmetryGroups=s1) else: calculator = pyRMSD.RMSDCalculator.RMSDCalculator( calculator_name, conforms) # additionally set number of cores for parallel calculator if mode == "cpu_omp": calculator.setNumberOfOpenMPThreads(int(cores)) if not symm_groups: rmsd = calculator.pairwiseRMSDMatrix() else: rmsd = [] for i in range(len(conforms) - 1): rmsd += list(calculator.oneVsFollowing(i)) rmsd_matrix = CondensedMatrix(rmsd) inner_data = rmsd_matrix.get_data() np.save("Distances_Matrix.data", inner_data) return inner_data