示例#1
0
static void
nma_sparse_hessian(gmx_sparsematrix_t     *     sparse_hessian,
                   gmx_bool                     bM,
                   t_topology     *             top,
                   int                          neig,
                   real     *                   eigenvalues,
                   real     *                   eigenvectors)
{
    int  i, j, k;
    int  row, col;
    real mass_fac;
    int  iatom, katom;
    int  natoms;
    int  ndim;

    natoms = top->atoms.nr;
    ndim   = DIM*natoms;

    /* Cannot check symmetry since we only store half matrix */
    /* divide elements hess[i][j] by sqrt(mas[i])*sqrt(mas[j]) when required */

    if (bM)
    {
        for (iatom = 0; (iatom < natoms); iatom++)
        {
            for (j = 0; (j < DIM); j++)
            {
                row = DIM*iatom+j;
                for (k = 0; k < sparse_hessian->ndata[row]; k++)
                {
                    col      = sparse_hessian->data[row][k].col;
                    katom    = col/3;
                    mass_fac = gmx_invsqrt(top->atoms.atom[iatom].m*top->atoms.atom[katom].m);
                    sparse_hessian->data[row][k].value *= mass_fac;
                }
            }
        }
    }
    fprintf(stderr, "\nDiagonalizing to find eigenvectors 1 through %d...\n", neig);
    fflush(stderr);

    sparse_eigensolver(sparse_hessian, neig, eigenvalues, eigenvectors, 10000000);

    /* Scale output eigenvectors */
    if (bM && eigenvectors != NULL)
    {
        for (i = 0; i < neig; i++)
        {
            for (j = 0; j < natoms; j++)
            {
                mass_fac = gmx_invsqrt(top->atoms.atom[j].m);
                for (k = 0; (k < DIM); k++)
                {
                    eigenvectors[i*ndim+j*DIM+k] *= mass_fac;
                }
            }
        }
    }
}
示例#2
0
static void
nma_sparse_hessian(gmx_sparsematrix_t        *sparse_hessian,
                   gmx_bool                   bM,
                   const t_topology          *top,
                   const std::vector<size_t> &atom_index,
                   int                        neig,
                   real                      *eigenvalues,
                   real                      *eigenvectors)
{
    int    i, k;
    int    row, col;
    real   mass_fac;
    int    katom;
    size_t ndim;

    ndim = DIM*atom_index.size();

    /* Cannot check symmetry since we only store half matrix */
    /* divide elements hess[i][j] by sqrt(mas[i])*sqrt(mas[j]) when required */

    GMX_RELEASE_ASSERT(sparse_hessian != NULL, "NULL matrix pointer provided to nma_sparse_hessian");

    if (bM)
    {
        for (size_t iatom = 0; (iatom < atom_index.size()); iatom++)
        {
            size_t ai = atom_index[iatom];
            for (size_t j = 0; (j < DIM); j++)
            {
                row = DIM*iatom+j;
                for (k = 0; k < sparse_hessian->ndata[row]; k++)
                {
                    col       = sparse_hessian->data[row][k].col;
                    katom     = col/3;
                    size_t ak = atom_index[katom];
                    mass_fac  = gmx::invsqrt(top->atoms.atom[ai].m*top->atoms.atom[ak].m);
                    sparse_hessian->data[row][k].value *= mass_fac;
                }
            }
        }
    }
    fprintf(stderr, "\nDiagonalizing to find eigenvectors 1 through %d...\n", neig);
    fflush(stderr);

    sparse_eigensolver(sparse_hessian, neig, eigenvalues, eigenvectors, 10000000);

    /* Scale output eigenvectors */
    if (bM && eigenvectors != NULL)
    {
        for (i = 0; i < neig; i++)
        {
            for (size_t j = 0; j < atom_index.size(); j++)
            {
                size_t aj = atom_index[j];
                mass_fac = gmx::invsqrt(top->atoms.atom[aj].m);
                for (k = 0; (k < DIM); k++)
                {
                    eigenvectors[i*ndim+j*DIM+k] *= mass_fac;
                }
            }
        }
    }
}