Esempio n. 1
0
/*!
 * \param   d  Trajectory analysis data to free.
 */
void
gmx_ana_traj_free(gmx_ana_traj_t *d)
{
    int                 i;

    if (d->top)
    {
        done_top(d->top);
        sfree(d->top);
    }
    if (d->fr)
    {
        /* Gromacs does not seem to have a function for freeing frame data */
        sfree(d->fr->x);
        sfree(d->fr->v);
        sfree(d->fr->f);
        sfree(d->fr);
    }
    sfree(d->xtop);
    sfree(d->sel);
    gmx_ana_selcollection_free(d->sc);
    gmx_ana_poscalc_coll_free(d->pcc);
    sfree(d->grpnames);
    sfree(d);
}
Esempio n. 2
0
TopologyInformation::~TopologyInformation()
{
    if (top_)
    {
        free_t_atoms(&top_->atoms, TRUE);
        done_top(top_);
        sfree(top_);
    }
    sfree(xtop_);
}
Esempio n. 3
0
int gmx_genconf(int argc, char *argv[])
{
    const char       *desc[] = {
        "[THISMODULE] multiplies a given coordinate file by simply stacking them",
        "on top of each other, like a small child playing with wooden blocks.",
        "The program makes a grid of [IT]user-defined[it]",
        "proportions ([TT]-nbox[tt]), ",
        "and interspaces the grid point with an extra space [TT]-dist[tt].[PAR]",
        "When option [TT]-rot[tt] is used the program does not check for overlap",
        "between molecules on grid points. It is recommended to make the box in",
        "the input file at least as big as the coordinates + ",
        "van der Waals radius.[PAR]",
        "If the optional trajectory file is given, conformations are not",
        "generated, but read from this file and translated appropriately to",
        "build the grid."

    };
    const char       *bugs[] = {
        "The program should allow for random displacement of lattice points."
    };

    int               vol;
    t_atoms          *atoms;      /* list with all atoms */
    rvec             *x, *xx, *v; /* coordinates? */
    real              t;
    vec4             *xrot, *vrot;
    int               ePBC;
    matrix            box, boxx; /* box length matrix */
    rvec              shift;
    int               natoms;    /* number of atoms in one molecule  */
    int               nres;      /* number of molecules? */
    int               i, j, k, l, m, ndx, nrdx, nx, ny, nz;
    t_trxstatus      *status;
    gmx_bool          bTRX;
    gmx_output_env_t *oenv;

    t_filenm          fnm[] = {
        { efSTX, "-f", "conf", ffREAD  },
        { efSTO, "-o", "out",  ffWRITE },
        { efTRX, "-trj", NULL,  ffOPTRD }
    };
#define NFILE asize(fnm)
    static rvec       nrbox    = {1, 1, 1};
    static int        seed     = 0;               /* seed for random number generator */
    static gmx_bool   bRandom  = FALSE;           /* False: no random rotations */
    static gmx_bool   bRenum   = TRUE;            /* renumber residues */
    static rvec       dist     = {0, 0, 0};       /* space added between molecules ? */
    static rvec       max_rot  = {180, 180, 180}; /* maximum rotation */
    t_pargs           pa[]     = {
        { "-nbox",   FALSE, etRVEC, {nrbox},   "Number of boxes" },
        { "-dist",   FALSE, etRVEC, {dist},    "Distance between boxes" },
        { "-seed",   FALSE, etINT,  {&seed},
          "Random generator seed (0 means generate)" },
        { "-rot",    FALSE, etBOOL, {&bRandom}, "Randomly rotate conformations" },
        { "-maxrot", FALSE, etRVEC, {max_rot}, "Maximum random rotation" },
        { "-renumber", FALSE, etBOOL, {&bRenum},  "Renumber residues" }
    };

    if (!parse_common_args(&argc, argv, 0, NFILE, fnm, asize(pa), pa,
                           asize(desc), desc, asize(bugs), bugs, &oenv))
    {
        return 0;
    }

    if (seed == 0)
    {
        seed = static_cast<int>(gmx::makeRandomSeed());
    }
    gmx::DefaultRandomEngine rng(seed);

    bTRX = ftp2bSet(efTRX, NFILE, fnm);
    nx   = (int)(nrbox[XX]+0.5);
    ny   = (int)(nrbox[YY]+0.5);
    nz   = (int)(nrbox[ZZ]+0.5);

    if ((nx <= 0) || (ny <= 0) || (nz <= 0))
    {
        gmx_fatal(FARGS, "Number of boxes (-nbox) should be larger than zero");
    }

    vol = nx*ny*nz; /* calculate volume in grid points (= nr. molecules) */

    t_topology *top;
    snew(top, 1);
    atoms = &top->atoms;
    read_tps_conf(opt2fn("-f", NFILE, fnm), top, &ePBC, &x, &v, box, FALSE);
    natoms = atoms->nr;
    nres   = atoms->nres;          /* nr of residues in one element? */
    /* make space for all the atoms */
    add_t_atoms(atoms, natoms*(vol-1), nres*(vol-1));
    srenew(x, natoms*vol);         /* get space for coordinates of all atoms */
    srenew(v, natoms*vol);         /* velocities. not really needed? */
    snew(xrot, natoms);            /* get space for rotation matrix? */
    snew(vrot, natoms);

    if (bTRX)
    {
        if (!read_first_x(oenv, &status, ftp2fn(efTRX, NFILE, fnm), &t, &xx, boxx))
        {
            gmx_fatal(FARGS, "No atoms in trajectory %s", ftp2fn(efTRX, NFILE, fnm));
        }
    }
    else
    {
        snew(xx, natoms);
        for (i = 0; i < natoms; i++)
        {
            copy_rvec(x[i], xx[i]);
        }
    }


    for (k = 0; (k < nz); k++)     /* loop over all gridpositions    */
    {
        shift[ZZ] = k*(dist[ZZ]+box[ZZ][ZZ]);

        for (j = 0; (j < ny); j++)
        {
            shift[YY] = j*(dist[YY]+box[YY][YY])+k*box[ZZ][YY];

            for (i = 0; (i < nx); i++)
            {
                shift[XX] = i*(dist[XX]+box[XX][XX])+j*box[YY][XX]+k*box[ZZ][XX];

                ndx  = (i*ny*nz+j*nz+k)*natoms;
                nrdx = (i*ny*nz+j*nz+k)*nres;

                /* Random rotation on input coords */
                if (bRandom)
                {
                    rand_rot(natoms, xx, v, xrot, vrot, &rng, max_rot);
                }

                for (l = 0; (l < natoms); l++)
                {
                    for (m = 0; (m < DIM); m++)
                    {
                        if (bRandom)
                        {
                            x[ndx+l][m] = xrot[l][m];
                            v[ndx+l][m] = vrot[l][m];
                        }
                        else
                        {
                            x[ndx+l][m] = xx[l][m];
                            v[ndx+l][m] = v[l][m];
                        }
                    }
                    if (ePBC == epbcSCREW && i % 2 == 1)
                    {
                        /* Rotate around x axis */
                        for (m = YY; m <= ZZ; m++)
                        {
                            x[ndx+l][m] = box[YY][m] + box[ZZ][m] - x[ndx+l][m];
                            v[ndx+l][m] = -v[ndx+l][m];
                        }
                    }
                    for (m = 0; (m < DIM); m++)
                    {
                        x[ndx+l][m] += shift[m];
                    }
                    atoms->atom[ndx+l].resind = nrdx + atoms->atom[l].resind;
                    atoms->atomname[ndx+l]    = atoms->atomname[l];
                }

                for (l = 0; (l < nres); l++)
                {
                    atoms->resinfo[nrdx+l] = atoms->resinfo[l];
                    if (bRenum)
                    {
                        atoms->resinfo[nrdx+l].nr += nrdx;
                    }
                }
                if (bTRX)
                {
                    if (!read_next_x(oenv, status, &t, xx, boxx) &&
                        ((i+1)*(j+1)*(k+1) < vol))
                    {
                        gmx_fatal(FARGS, "Not enough frames in trajectory");
                    }
                }
            }
        }
    }
    if (bTRX)
    {
        close_trj(status);
    }

    /* make box bigger */
    for (m = 0; (m < DIM); m++)
    {
        box[m][m] += dist[m];
    }
    svmul(nx, box[XX], box[XX]);
    svmul(ny, box[YY], box[YY]);
    svmul(nz, box[ZZ], box[ZZ]);
    if (ePBC == epbcSCREW && nx % 2 == 0)
    {
        /* With an even number of boxes in x we can forgot about the screw */
        ePBC = epbcXYZ;
    }

    /*depending on how you look at it, this is either a nasty hack or the way it should work*/
    if (bRenum)
    {
        for (i = 0; i < atoms->nres; i++)
        {
            atoms->resinfo[i].nr = i+1;
        }
    }

    write_sto_conf(opt2fn("-o", NFILE, fnm), *top->name, atoms, x, v, ePBC, box);

    sfree(x);
    sfree(v);
    sfree(xrot);
    sfree(vrot);
    sfree(xx);
    done_top(top);
    sfree(top);
    done_filenms(NFILE, fnm);
    output_env_done(oenv);

    return 0;
}
Esempio n. 4
0
void read_stx_conf(const char *infile, char *title, t_atoms *atoms,
                   rvec x[], rvec *v, int *ePBC, matrix box)
{
    FILE       *in;
    char        buf[256];
    gmx_mtop_t *mtop;
    t_topology  top;
    t_trxframe  fr;
    int         i, ftp, natoms;
    real        d;
    char        g96_line[STRLEN+1];

    if (atoms->nr == 0)
    {
        fprintf(stderr, "Warning: Number of atoms in %s is 0\n", infile);
    }
    else if (atoms->atom == NULL)
    {
        gmx_mem("Uninitialized array atom");
    }

    if (ePBC)
    {
        *ePBC = -1;
    }

    ftp = fn2ftp(infile);
    switch (ftp)
    {
        case efGRO:
            read_whole_conf(infile, title, atoms, x, v, box);
            break;
        case efG96:
            fr.title  = NULL;
            fr.natoms = atoms->nr;
            fr.atoms  = atoms;
            fr.x      = x;
            fr.v      = v;
            fr.f      = NULL;
            in        = gmx_fio_fopen(infile, "r");
            read_g96_conf(in, infile, &fr, g96_line);
            gmx_fio_fclose(in);
            copy_mat(fr.box, box);
            strncpy(title, fr.title, STRLEN);
            break;
        case efPDB:
        case efBRK:
        case efENT:
            read_pdb_conf(infile, title, atoms, x, ePBC, box, TRUE, NULL);
            break;
        case efESP:
            read_espresso_conf(infile, atoms, x, v, box);
            break;
        case efTPR:
        case efTPB:
        case efTPA:
            snew(mtop, 1);
            i = read_tpx(infile, NULL, box, &natoms, x, v, NULL, mtop);
            if (ePBC)
            {
                *ePBC = i;
            }

            strcpy(title, *(mtop->name));

            /* Free possibly allocated memory */
            done_atom(atoms);

            *atoms = gmx_mtop_global_atoms(mtop);
            top    = gmx_mtop_t_to_t_topology(mtop);
            tpx_make_chain_identifiers(atoms, &top.mols);

            sfree(mtop);
            /* The strings in the symtab are still in use in the returned t_atoms
             * structure, so we should not free them. But there is no place to put the
             * symbols; the only choice is to leak the memory...
             * So we clear the symbol table before freeing the topology structure. */
            free_symtab(&top.symtab);
            done_top(&top);

            break;
        default:
            gmx_incons("Not supported in read_stx_conf");
    }
}
Esempio n. 5
0
void read_stx_conf(char *infile, char *title,t_atoms *atoms, 
		   rvec x[],rvec *v,int *ePBC,matrix box)
{
  FILE       *in;
  char       buf[256];
  gmx_mtop_t *mtop;
  t_topology top;
  t_trxframe fr;
  int        i,ftp,natoms,i1;
  real       d,r1,r2;

  if (atoms->nr == 0)
    fprintf(stderr,"Warning: Number of atoms in %s is 0\n",infile);
  else if (atoms->atom == NULL)
    gmx_mem("Uninitialized array atom");
  
  if (ePBC)
    *ePBC = -1;

  ftp=fn2ftp(infile);
  switch (ftp) {
  case efGRO:
    read_whole_conf(infile, title, atoms, x, v, box);
    break;
  case efG96:
    fr.title = title;
    fr.natoms = atoms->nr;
    fr.atoms = atoms;
    fr.x = x;
    fr.v = v;
    fr.f = NULL;
    in = gmx_fio_fopen(infile,"r");
    read_g96_conf(in, infile, &fr);
    gmx_fio_fclose(in);
    copy_mat(fr.box,box);
    break;
  case efPDB:
  case efBRK:
  case efENT:
    read_pdb_conf(infile, title, atoms, x, ePBC, box, TRUE, NULL);
    break;
  case efESP:
    read_espresso_conf(infile,atoms,x,v,box);
    break;
  case efTPR:
  case efTPB:
  case efTPA: 
    snew(mtop,1);
    i = read_tpx(infile,&i1,&r1,&r2,NULL,box,&natoms,x,v,NULL,mtop);
    if (ePBC)
      *ePBC = i;
    
    strcpy(title,*(mtop->name));
    
    /* Free possibly allocated memory */
    done_atom(atoms);
    
    *atoms = gmx_mtop_global_atoms(mtop);
    top = gmx_mtop_t_to_t_topology(mtop);
    tpx_make_chain_identifiers(atoms,&top.mols);
		
    sfree(mtop);
    done_top(&top);
		  
    break;
  default:
    gmx_incons("Not supported in read_stx_conf");
  }
}