/* calculate charge density */
static void calc_q2all(
        gmx_mtop_t *mtop,   /* molecular topology */
        real *q2all, real *q2allnr)
{
    int imol,iatom;  /* indices for loops */
    real q2_all=0;   /* Sum of squared charges */
    int  nrq_mol;    /* Number of charges in a single molecule */
    int  nrq_all;    /* Total number of charges in the MD system */
    real nrq_all_r;  /* No of charges in real format */
    real qi,q2_mol;
    gmx_moltype_t *molecule;
    gmx_molblock_t *molblock;
    
#ifdef DEBUG
        fprintf(stderr, "\nCharge density:\n");
#endif
    q2_all = 0.0;  /* total q squared */
    nrq_all = 0;   /* total number of charges in the system */
    for (imol=0; imol<mtop->nmolblock; imol++) /* Loop over molecule types */
    {
        q2_mol=0.0; /* q squared value of this molecule */
        nrq_mol=0;  /* number of charges this molecule carries */
        molecule = &(mtop->moltype[imol]);
        molblock = &(mtop->molblock[imol]);
        for (iatom=0; iatom<molblock->natoms_mol; iatom++) /* Loop over atoms in this molecule */
        {
            qi = molecule->atoms.atom[iatom].q; /* Charge of this atom */
            /* Is this charge worth to be considered? */
            if (is_charge(qi))
            {
                q2_mol += qi*qi;
                nrq_mol++;                
            }
        }
        /* Multiply with the number of molecules present of this type and add */
        q2_all  += q2_mol*molblock->nmol;
        nrq_all += nrq_mol*molblock->nmol;
#ifdef DEBUG
        fprintf(stderr, "Molecule %2d (%5d atoms) q2_mol=%10.3e nr.mol.charges=%5d (%6dx)  q2_all=%10.3e  tot.charges=%d\n", 
                imol,molblock->natoms_mol,q2_mol,nrq_mol,molblock->nmol,q2_all,nrq_all);
#endif
    }
    nrq_all_r = nrq_all;

    *q2all=q2_all;
    *q2allnr=nrq_all;

}
예제 #2
0
/* Allocate and fill an array with coordinates and charges,
 * returns the number of charges found
 */
static int prepare_x_q(real *q[], rvec *x[], gmx_mtop_t *mtop, rvec x_orig[], t_commrec *cr)
{
    int                     i;
    int                     nq; /* number of charged particles */
    gmx_mtop_atomloop_all_t aloop;
    t_atom                 *atom;


    if (MASTER(cr))
    {
        snew(*q, mtop->natoms);
        snew(*x, mtop->natoms);
        nq = 0;

        aloop = gmx_mtop_atomloop_all_init(mtop);

        while (gmx_mtop_atomloop_all_next(aloop, &i, &atom))
        {
            if (is_charge(atom->q))
            {
                (*q)[nq]     = atom->q;
                (*x)[nq][XX] = x_orig[i][XX];
                (*x)[nq][YY] = x_orig[i][YY];
                (*x)[nq][ZZ] = x_orig[i][ZZ];
                nq++;
            }
        }
        /* Give back some unneeded memory */
        srenew(*q, nq);
        srenew(*x, nq);
    }
    /* Broadcast x and q in the parallel case */
    if (PAR(cr))
    {
        /* Transfer the number of charges */
        block_bc(cr, nq);
        snew_bc(cr, *x, nq);
        snew_bc(cr, *q, nq);
        nblock_bc(cr, nq, *x);
        nblock_bc(cr, nq, *q);
    }

    return nq;
}
/* Allocate and fill an array with coordinates and charges,
 * returns the number of charges found
 */
static int prepare_x_q(real *q[], rvec *x[], gmx_mtop_t *mtop, rvec x_orig[], t_commrec *cr)
{
    int i,anr_global;
    int nq; /* number of charged particles */
    t_atom *atom;
    
    
    if (MASTER(cr))
    {
        snew(*q, mtop->natoms);
        snew(*x, mtop->natoms);
        nq=0;
        for (i=0; i<mtop->natoms; i++)
        {
            anr_global = i;
            gmx_mtop_atomnr_to_atom(mtop,anr_global,&atom);
            if (is_charge(atom->q))
            {
                (*q)[nq] = atom->q;
                (*x)[nq][XX] = x_orig[i][XX];
                (*x)[nq][YY] = x_orig[i][YY];
                (*x)[nq][ZZ] = x_orig[i][ZZ];
                nq++;
            }
        }
        /* Give back some unneeded memory */
        srenew(*q, nq);
        srenew(*x, nq);
    }
    /* Broadcast x and q in the parallel case */
    if (PAR(cr))
    {
        /* Transfer the number of charges */
        block_bc(cr,nq);
        snew_bc(cr, *x, nq);
        snew_bc(cr, *q, nq);
        nblock_bc(cr,nq,*x);
        nblock_bc(cr,nq,*q);
    }
    
    return nq;
}