Beispiel #1
0
/* Get the center from local positions that already have the correct
 * PBC representation */
extern void get_center_comm(
        const t_commrec *cr,
        rvec             x_loc[],      /* Local positions */
        real             weight_loc[], /* Local masses or other weights */
        int              nr_loc,       /* Local number of atoms */
        int              nr_group,     /* Total number of atoms of the group */
        rvec             center)       /* Weighted center */
{
    double weight_sum, denom;
    dvec   dsumvec;
    double buf[4];


    weight_sum = get_sum_of_positions(x_loc, weight_loc, nr_loc, dsumvec);

    /* Add the local contributions from all nodes. Put the sum vector and the
     * weight in a buffer array so that we get along with a single communication
     * call. */
    if (PAR(cr))
    {
        buf[0] = dsumvec[XX];
        buf[1] = dsumvec[YY];
        buf[2] = dsumvec[ZZ];
        buf[3] = weight_sum;

        /* Communicate buffer */
        gmx_sumd(4, buf, cr);

        dsumvec[XX] = buf[0];
        dsumvec[YY] = buf[1];
        dsumvec[ZZ] = buf[2];
        weight_sum  = buf[3];
    }

    if (weight_loc != nullptr)
    {
        denom = 1.0/weight_sum; /* Divide by the sum of weight to get center of mass e.g. */
    }
    else
    {
        denom = 1.0/nr_group;   /* Divide by the number of atoms to get the geometrical center */

    }
    center[XX] = dsumvec[XX]*denom;
    center[YY] = dsumvec[YY]*denom;
    center[ZZ] = dsumvec[ZZ]*denom;
}
Beispiel #2
0
/* Determine center of structure from collective positions x */
extern void get_center(rvec x[], real weight[], const int nr, rvec rcenter)
{
    dvec   dcenter;
    double weight_sum, denom;

    
    weight_sum = get_sum_of_positions(x, weight, nr, dcenter);
    
    if (weight != NULL)
        denom = weight_sum; /* Divide by the sum of weight */
    else
        denom = nr;        /* Divide by the number of atoms */
        
    dsvmul(1.0/denom, dcenter, dcenter);
    
    rcenter[XX] = dcenter[XX];
    rcenter[YY] = dcenter[YY];
    rcenter[ZZ] = dcenter[ZZ];
}