void visualize_box(FILE *out, int a0, int r0, matrix box, rvec gridsize)
{
    int  *edge;
    rvec *vert, shift;
    int   nx, ny, nz, nbox, nat;
    int   i, j, x, y, z;
    int   rectedge[24] =
    {
        0, 1, 1, 3, 3, 2, 0, 2, 0, 4, 1, 5, 3, 7, 2, 6, 4, 5, 5, 7, 7, 6, 6,
        4
    };

    a0++;
    r0++;

    nx   = static_cast<int>(gridsize[XX] + 0.5);
    ny   = static_cast<int>(gridsize[YY] + 0.5);
    nz   = static_cast<int>(gridsize[ZZ] + 0.5);
    nbox = nx * ny * nz;
    if (TRICLINIC(box))
    {
        nat = nbox * NCUCVERT;
        snew(vert, nat);
        calc_compact_unitcell_vertices(ecenterDEF, box, vert);
        j = 0;
        for (z = 0; z < nz; z++)
        {
            for (y = 0; y < ny; y++)
            {
                for (x = 0; x < nx; x++)
                {
                    for (i = 0; i < DIM; i++)
                    {
                        shift[i] = x * box[0][i] + y * box[1][i] + z
                            * box[2][i];
                    }
                    for (i = 0; i < NCUCVERT; i++)
                    {
                        rvec_add(vert[i], shift, vert[j]);
                        j++;
                    }
                }
            }
        }

        for (i = 0; i < nat; i++)
        {
            gmx_fprintf_pdb_atomline(out, epdbATOM, a0 + i, "C", ' ', "BOX", 'K' + i / NCUCVERT, r0 + i, ' ',
                                     10*vert[i][XX], 10*vert[i][YY], 10*vert[i][ZZ], 1.0, 0.0, "");
        }

        edge = compact_unitcell_edges();
        for (j = 0; j < nbox; j++)
        {
            for (i = 0; i < NCUCEDGE; i++)
            {
                fprintf(out, "CONECT%5d%5d\n", a0 + j * NCUCVERT + edge[2 * i],
                        a0 + j * NCUCVERT + edge[2 * i + 1]);
            }
        }

        sfree(vert);
    }
    else
    {
        i = 0;
        for (z = 0; z <= 1; z++)
        {
            for (y = 0; y <= 1; y++)
            {
                for (x = 0; x <= 1; x++)
                {
                    gmx_fprintf_pdb_atomline(out, epdbATOM, a0 + i, "C", ' ', "BOX", 'K' + i/8, r0+i, ' ',
                                             x * 10 * box[XX][XX], y * 10 * box[YY][YY], z * 10 * box[ZZ][ZZ], 1.0, 0.0, "");
                    i++;
                }
            }
        }
        for (i = 0; i < 24; i += 2)
        {
            fprintf(out, "CONECT%5d%5d\n", a0 + rectedge[i], a0 + rectedge[i + 1]);
        }
    }
}
Example #2
0
int copy_pmegrid_to_fftgrid(struct gmx_pme_t *pme, real *pmegrid, real *fftgrid, int grid_index)
{
    ivec    local_fft_ndata, local_fft_offset, local_fft_size;
    ivec    local_pme_size;
    int     ix, iy, iz;
    int     pmeidx, fftidx;

    /* Dimensions should be identical for A/B grid, so we just use A here */
    gmx_parallel_3dfft_real_limits(pme->pfft_setup[grid_index],
                                   local_fft_ndata,
                                   local_fft_offset,
                                   local_fft_size);

    local_pme_size[0] = pme->pmegrid_nx;
    local_pme_size[1] = pme->pmegrid_ny;
    local_pme_size[2] = pme->pmegrid_nz;

    /* The fftgrid is always 'justified' to the lower-left corner of the PME grid,
       the offset is identical, and the PME grid always has more data (due to overlap)
     */
    {
#ifdef DEBUG_PME
        FILE *fp, *fp2;
        char  fn[STRLEN];
        real  val;
        sprintf(fn, "pmegrid%d.pdb", pme->nodeid);
        fp = gmx_ffopen(fn, "w");
        sprintf(fn, "pmegrid%d.txt", pme->nodeid);
        fp2 = gmx_ffopen(fn, "w");
#endif

        for (ix = 0; ix < local_fft_ndata[XX]; ix++)
        {
            for (iy = 0; iy < local_fft_ndata[YY]; iy++)
            {
                for (iz = 0; iz < local_fft_ndata[ZZ]; iz++)
                {
                    pmeidx          = ix*(local_pme_size[YY]*local_pme_size[ZZ])+iy*(local_pme_size[ZZ])+iz;
                    fftidx          = ix*(local_fft_size[YY]*local_fft_size[ZZ])+iy*(local_fft_size[ZZ])+iz;
                    fftgrid[fftidx] = pmegrid[pmeidx];
#ifdef DEBUG_PME
                    val = 100*pmegrid[pmeidx];
                    if (pmegrid[pmeidx] != 0)
                    {
                        gmx_fprintf_pdb_atomline(fp, epdbATOM, pmeidx, "CA", ' ', "GLY", ' ', pmeidx, ' ',
                                                 5.0*ix, 5.0*iy, 5.0*iz, 1.0, val, "");
                    }
                    if (pmegrid[pmeidx] != 0)
                    {
                        fprintf(fp2, "%-12s  %5d  %5d  %5d  %12.5e\n",
                                "qgrid",
                                pme->pmegrid_start_ix + ix,
                                pme->pmegrid_start_iy + iy,
                                pme->pmegrid_start_iz + iz,
                                pmegrid[pmeidx]);
                    }
#endif
                }
            }
        }
#ifdef DEBUG_PME
        gmx_ffclose(fp);
        gmx_ffclose(fp2);
#endif
    }
    return 0;
}
Example #3
0
void write_pdbfile_indexed(FILE *out, const char *title,
                           t_atoms *atoms, rvec x[],
                           int ePBC, matrix box, char chainid,
                           int model_nr, int nindex, const int index[],
                           gmx_conect conect, gmx_bool bTerSepChains)
{
    gmx_conect_t     *gc = (gmx_conect_t *)conect;
    char              resnm[6], nm[6];
    int               i, ii;
    int               resind, resnr;
    enum PDB_record   type;
    unsigned char     resic, ch;
    char              altloc;
    real              occup, bfac;
    gmx_bool          bOccup;
    int               chainnum, lastchainnum;
    gmx_residuetype_t*rt;
    const char       *p_restype;
    const char       *p_lastrestype;

    gmx_residuetype_init(&rt);

    fprintf(out, "TITLE     %s\n", (title && title[0]) ? title : gmx::bromacs().c_str());
    if (box && ( norm2(box[XX]) || norm2(box[YY]) || norm2(box[ZZ]) ) )
    {
        gmx_write_pdb_box(out, ePBC, box);
    }
    if (atoms->pdbinfo)
    {
        /* Check whether any occupancies are set, in that case leave it as is,
         * otherwise set them all to one
         */
        bOccup = TRUE;
        for (ii = 0; (ii < nindex) && bOccup; ii++)
        {
            i      = index[ii];
            bOccup = bOccup && (atoms->pdbinfo[i].occup == 0.0);
        }
    }
    else
    {
        bOccup = FALSE;
    }

    fprintf(out, "MODEL %8d\n", model_nr > 0 ? model_nr : 1);

    lastchainnum      = -1;
    p_restype         = NULL;

    for (ii = 0; ii < nindex; ii++)
    {
        i             = index[ii];
        resind        = atoms->atom[i].resind;
        chainnum      = atoms->resinfo[resind].chainnum;
        p_lastrestype = p_restype;
        gmx_residuetype_get_type(rt, *atoms->resinfo[resind].name, &p_restype);

        /* Add a TER record if we changed chain, and if either the previous or this chain is protein/DNA/RNA. */
        if (bTerSepChains && ii > 0 && chainnum != lastchainnum)
        {
            /* Only add TER if the previous chain contained protein/DNA/RNA. */
            if (gmx_residuetype_is_protein(rt, p_lastrestype) || gmx_residuetype_is_dna(rt, p_lastrestype) || gmx_residuetype_is_rna(rt, p_lastrestype))
            {
                fprintf(out, "TER\n");
            }
            lastchainnum    = chainnum;
        }

        strncpy(resnm, *atoms->resinfo[resind].name, sizeof(resnm)-1);
        resnm[sizeof(resnm)-1] = 0;
        strncpy(nm, *atoms->atomname[i], sizeof(nm)-1);
        nm[sizeof(nm)-1] = 0;

        /* rename HG12 to 2HG1, etc. */
        xlate_atomname_gmx2pdb(nm);
        resnr = atoms->resinfo[resind].nr;
        resic = atoms->resinfo[resind].ic;
        if (chainid != ' ')
        {
            ch = chainid;
        }
        else
        {
            ch = atoms->resinfo[resind].chainid;

            if (ch == 0)
            {
                ch = ' ';
            }
        }
        if (resnr >= 10000)
        {
            resnr = resnr % 10000;
        }
        if (atoms->pdbinfo)
        {
            type   = static_cast<enum PDB_record>(atoms->pdbinfo[i].type);
            altloc = atoms->pdbinfo[i].altloc;
            if (!isalnum(altloc))
            {
                altloc = ' ';
            }
            occup = bOccup ? 1.0 : atoms->pdbinfo[i].occup;
            bfac  = atoms->pdbinfo[i].bfac;
        }
        else
        {
            type   = epdbATOM;
            occup  = 1.0;
            bfac   = 0.0;
            altloc = ' ';
        }

        gmx_fprintf_pdb_atomline(out,
                                 type,
                                 i+1,
                                 nm,
                                 altloc,
                                 resnm,
                                 ch,
                                 resnr,
                                 resic,
                                 10*x[i][XX], 10*x[i][YY], 10*x[i][ZZ],
                                 occup,
                                 bfac,
                                 atoms->atom[i].elem);

        if (atoms->pdbinfo && atoms->pdbinfo[i].bAnisotropic)
        {
            fprintf(out, "ANISOU%5d  %-4.4s%4.4s%c%4d%c %7d%7d%7d%7d%7d%7d\n",
                    (i+1)%100000, nm, resnm, ch, resnr,
                    (resic == '\0') ? ' ' : resic,
                    atoms->pdbinfo[i].uij[0], atoms->pdbinfo[i].uij[1],
                    atoms->pdbinfo[i].uij[2], atoms->pdbinfo[i].uij[3],
                    atoms->pdbinfo[i].uij[4], atoms->pdbinfo[i].uij[5]);
        }
    }

    fprintf(out, "TER\n");
    fprintf(out, "ENDMDL\n");

    if (NULL != gc)
    {
        /* Write conect records */
        for (i = 0; (i < gc->nconect); i++)
        {
            fprintf(out, "CONECT%5d%5d\n", gc->conect[i].ai+1, gc->conect[i].aj+1);
        }
    }

    gmx_residuetype_destroy(rt);
}