void MatrixHeatImaging(const DoubleMatrix &m, double minimum, double maximum, QPixmap &pixmap, int width, int height) { pixmap = QPixmap(QSize(width, height)); pixmap.fill(Qt::white); QPainter painter(&pixmap); unsigned int rows = m.rows(); unsigned int cols = m.cols(); for (unsigned int j=0; j<rows; j++) { for (unsigned int i=0; i<cols; i++) { double u = m.at(j,i); double ratio = 0.0; if (minimum!=maximum) ratio = 2.0 * (u-minimum) / (maximum - minimum); int b = int(MAX(0, 255*(1 - ratio))); int r = int(MAX(0, 255*(ratio - 1))); int g = 255 - b - r; QColor c(r, g, b); painter.setPen(c); painter.drawPoint(i,height-j-1); } } }
void HeatControl2Delta::write(const char *fileName, const DoubleMatrix& m) { FILE* f = fopen(fileName, "w"); for (unsigned int j=0; j<m.rows(); j++) { for (unsigned int i=0; i<m.cols(); i++) { if (i==0) fprintf(f, "%.10f", m[j][i]); else fprintf(f, " %.10f", m[j][i]); } fprintf(f, "\n"); } fclose(f); }
int main(int argc, char *argv[]) { string hdr = invocationHeader(argc, argv); cout << "# " << hdr << endl; parseArgs(argc, argv); DoubleMatrix eigvals; readAsciiMatrix(eigvals_name, eigvals); DoubleMatrix eigvecs; readAsciiMatrix(eigvecs_name, eigvecs); if (modes.empty()) for (uint i=0; i<eigvals.rows(); ++i) modes.push_back(i); uint n = modes.size(); uint m = eigvecs.rows(); // V = m x n matrix of eigenvectors DoubleMatrix V(m, n); for (uint i=0; i<n; ++i) for (uint j=0; j<m; ++j) V(j, i) = eigvecs(j, modes[i]); // Make a copy and scale by the appropriate eigenvalue, // remembering that eigenvalues are inverted for ENM, // or squaring and not inverting in the case of PCA DoubleMatrix VS = V.copy(); for (uint i=0; i<n; ++i) { double e = eigvals[modes[i]]; double s = (pca_input) ? (scale * e * e): (scale / e); for (uint j=0; j<m; ++j) VS(j, i) *= s; } // U = Covariance matrix DoubleMatrix U = loos::Math::MMMultiply(VS,V,false,true); // B-factors come from trace of diagonal 3x3 superblocks vector<double> B; double prefactor = 8.0 * M_PI * M_PI / 3.0; for (uint i=0; i<m; i += 3) { double b = prefactor * (U(i,i) + U(i+1, i+1) + U(i+2, i+2)); B.push_back(b); cout << boost::format("%-8d %g\n") % (i/3) % b; } if (!pdb_name.empty()) { AtomicGroup model = createSystem(pdb_name); AtomicGroup subset = selectAtoms(model, selection); if ((unsigned int)subset.size() != B.size()) { cerr << boost::format("Error- selection has %d atoms, but %d were expected.\n") % subset.size() % B.size(); exit(-10); } for (uint i=0; i<B.size(); ++i) subset[i]->bfactor(B[i]); PDB pdb = PDB::fromAtomicGroup(model); pdb.remarks().add(hdr); ofstream ofs(out_name.c_str()); ofs << pdb; } }
/*! Linear assignment problem solution [modifies matrix in-place.] matrix(row,col): row major format assumed. Assignments are remaining 0 values on 'matrix' (extra 0 values are replaced with -1) The correspondence results are stored in the variables row2colMap and col2rowMap s.t. row2colMap(r) = c means that col c is assigned to row r col2rowMap(c) = r means that row r is assigned to column c @param initMaps if true the row/col maps are init to invalid values, which help check the mapping by calling CheckMapping() */ double Munkres::Solve(const DoubleMatrix& m, UIntVector* row2colMap, UIntVector* col2rowMap) { #ifdef MUNKRES_DEBUG std::cout << "Munkres input matrix:" << std::endl; for ( int row = 0 ; row < m.rows() ; row++ ) { for ( int col = 0 ; col < m.columns() ; col++ ) { std::cout.width(8); std::cout << m(row,col) << ","; } std::cout << std::endl; } std::cout << std::endl; #endif bool notdone = true; int step = 1; // Copy m, because it need to be modified matrix = m; // Z_STAR == 1 == starred, Z_PRIME == 2 == primed mask_matrix.set_size(matrix.rows(), matrix.columns()); mask_matrix.fill(0); row_mask = new bool[matrix.rows()]; col_mask = new bool[matrix.columns()]; for ( unsigned i = 0 ; i < matrix.rows() ; i++ ) { row_mask[i] = false; } for ( unsigned i = 0 ; i < matrix.columns() ; i++ ) { col_mask[i] = false; } while ( notdone ) { switch ( step ) { case 0: notdone = false; break; case 1: step = step1(); break; case 2: step = step2(); break; case 3: step = step3(); break; case 4: step = step4(); break; case 5: step = step5(); break; } } delete[] row_mask; delete[] col_mask; // Store results /* for ( unsigned row = 0 ; row < matrix.rows() ; row++ ) for ( unsigned col = 0 ; col < matrix.columns() ; col++ ) if ( mask_matrix(row,col) == Z_STAR ) matrix(row,col) = 0; else matrix(row,col) = -1; #ifdef MUNKRES_DEBUG std::cout << "Munkres output matrix:" << std::endl; for ( int row = 0 ; row < matrix.rows() ; row++ ) { for ( int col = 0 ; col < matrix.columns() ; col++ ) { std::cout.width(1); std::cout << matrix(row,col) << ","; } std::cout << std::endl; } std::cout << std::endl; #endif */ // Store results in the row and col maps s.t. // row2colMap(r) = c means that col c is assigned to row r // col2rowMap(c) = r means that row r is assigned to column c // Init vector to "known" invalid values if (row2colMap) { row2colMap->set_size(matrix.rows()); row2colMap->fill(UINT_MAX); } // Init vector to "known" invalid values if (col2rowMap) { col2rowMap->set_size(matrix.cols()); col2rowMap->fill(UINT_MAX); } double matchCost = 0; for (unsigned row = 0 ; row < matrix.rows() ; ++row) { for (unsigned col = 0 ; col < matrix.columns() ; ++col) { if (mask_matrix(row,col) == Z_STAR) { if (row2colMap) (*row2colMap)[row] = col; if (col2rowMap) (*col2rowMap)[col] = row; matchCost += m[row][col]; // use given 'm' not 'matrix'! } } } return matchCost; }