}
}
-void get_stx_coordnum(const char *infile, int *natoms)
+static void get_stx_coordnum(const char *infile, int *natoms)
{
FILE *in;
int ftp, tpxver, tpxgen;
}
}
-void read_stx_conf(const char *infile, char *title, t_atoms *atoms,
- rvec x[], rvec *v, int *ePBC, matrix box)
+static void read_stx_conf(const char *infile, char *title, t_atoms *atoms,
+ rvec x[], rvec *v, int *ePBC, matrix box)
{
FILE *in;
gmx_mtop_t *mtop;
gmx_atomprop_t aps;
bTop = fn2bTPX(infile);
- *ePBC = -1;
+ if (ePBC != NULL)
+ {
+ *ePBC = -1;
+ }
if (bTop)
{
read_tpxheader(infile, &header, TRUE, &version, &generation);
snew(*v, header.natoms);
}
snew(mtop, 1);
- *ePBC = read_tpx(infile, NULL, box, &natoms,
- (x == NULL) ? NULL : *x, (v == NULL) ? NULL : *v, NULL, mtop);
+ int ePBC_tmp
+ = read_tpx(infile, NULL, box, &natoms,
+ (x == NULL) ? NULL : *x, (v == NULL) ? NULL : *v, NULL, mtop);
+ if (ePBC != NULL)
+ {
+ *ePBC = ePBC_tmp;
+ }
*top = gmx_mtop_t_to_t_topology(mtop);
/* In this case we need to throw away the group data too */
done_gmx_groups_t(&mtop->groups);
rvec x[], rvec *v, int ePBC, matrix box);
/* As write_sto_conf, but uses a gmx_mtop_t struct */
-void get_stx_coordnum (const char *infile, int *natoms);
-/* read the number of atoms from an STX file */
-
-void read_stx_conf(const char *infile, char *title,
- struct t_atoms *atoms,
- rvec x[], rvec *v, int *ePBC, matrix box);
-/* Read atoms, x, v and box from an STX file.
- * If ePBC!=NULL return the type of pbc in *ePBC or -1 if unknown.
- */
-
gmx_bool read_tps_conf(const char *infile, char *title, struct t_topology *top,
int *ePBC, rvec **x, rvec **v, matrix box, gmx_bool bMass);
/* Read title, top.atoms, x, v (if not NULL) and box from an STX file,
refBox_);
}
- void readReferenceFileStx()
- {
- int natoms = -1;
- get_stx_coordnum(referenceFilename_.c_str(), &natoms);
- ASSERT_EQ(refTop_->atoms.nr, natoms)
- << "get_stx_coordnum() returned unexpected number of atoms";
- char title[STRLEN];
- snew(testTop_, 1);
- init_t_atoms(&testTop_->atoms, natoms, GetParam() == efPDB);
- snew(testX_, natoms);
- read_stx_conf(referenceFilename_.c_str(), title, &testTop_->atoms,
- testX_, NULL, NULL, testBox_);
- testTop_->name = put_symtab(&testTop_->symtab, title);
- }
-
void readReferenceFileTps()
{
snew(testTop_, 1);
matrix testBox_;
};
-TEST_P(StructureIORoundtripTest, ReadWriteStxConf)
-{
- writeReferenceFile();
- readReferenceFileStx();
- testTopologies();
- writeTestFileAndTest();
-}
-
TEST_P(StructureIORoundtripTest, ReadWriteTpsConf)
{
writeReferenceFile();
t_pdbfile *pdbf;
double e;
char buf[256], *ptr;
- int natoms;
FILE *fp;
snew(pdbf, 1);
- get_stx_coordnum (fn, &natoms);
- init_t_atoms(&(pdbf->atoms), natoms, FALSE);
- snew(pdbf->x, natoms);
- read_stx_conf(fn, buf, &pdbf->atoms, pdbf->x, NULL, &pdbf->ePBC, pdbf->box);
- fp = gmx_ffopen(fn, "r");
+ t_topology top;
+ read_tps_conf(fn, buf, &top, &pdbf->ePBC, &pdbf->x, NULL, pdbf->box, FALSE);
+ pdbf->atoms = top.atoms;
+ fp = gmx_ffopen(fn, "r");
do
{
ptr = fgets2(buf, 255, fp);
};
FILE *log;
- int natoms, nlist, idum, nbin;
- t_atoms atoms;
+ int nlist, idum, nbin;
rvec *x;
int ePBC;
matrix box;
nbin = 360/ndeg;
/* Find the chi angles using atoms struct and a list of amino acids */
- get_stx_coordnum(ftp2fn(efSTX, NFILE, fnm), &natoms);
- init_t_atoms(&atoms, natoms, TRUE);
- snew(x, natoms);
- read_stx_conf(ftp2fn(efSTX, NFILE, fnm), title, &atoms, x, NULL, &ePBC, box);
+ t_topology *top;
+ snew(top, 1);
+ read_tps_conf(ftp2fn(efSTX, NFILE, fnm), title, top, &ePBC, &x, NULL, box, FALSE);
+ t_atoms &atoms = top->atoms;
+ if (atoms.pdbinfo == NULL)
+ {
+ snew(atoms.pdbinfo, atoms.nr);
+ }
fprintf(log, "Title: %s\n", title);
gmx_residuetype_init(&rt);
#include "gromacs/math/vec.h"
#include "gromacs/topology/atoms.h"
#include "gromacs/topology/index.h"
+#include "gromacs/topology/topology.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/smalloc.h"
t_trxstatus *status;
atom_id *index = NULL, *index_all;
char title[256], *grpname;
- t_atoms atoms;
real angle, trans;
rvec *x, *v, *xout, *vout;
matrix box;
gmx_fatal(FARGS, "maxangle not given");
}
- get_stx_coordnum (opt2fn("-f", NFILE, fnm), &natoms);
- init_t_atoms(&atoms, natoms, TRUE);
- snew(x, natoms);
- snew(v, natoms);
- read_stx_conf(opt2fn("-f", NFILE, fnm), title, &atoms, x, v, NULL, box);
+ t_topology *top;
+ snew(top, 1);
+ read_tps_conf(opt2fn("-f", NFILE, fnm), title, top, NULL, &x, &v, box, FALSE);
+ t_atoms &atoms = top->atoms;
+ if (atoms.pdbinfo == NULL)
+ {
+ snew(atoms.pdbinfo, atoms.nr);
+ }
+ natoms = atoms.nr;
snew(xout, natoms);
snew(vout, natoms);
double *bfac = NULL, c6, c12;
int *bfac_nr = NULL;
t_topology *top = NULL;
- t_atoms atoms;
char *grpname, *sgrpname, *agrpname;
int isize, ssize, asize;
atom_id *index, *sindex, *aindex;
" when using the -mead option\n");
}
- get_stx_coordnum(infile, &natom);
- init_t_atoms(&atoms, natom, TRUE);
- snew(x, natom);
- snew(v, natom);
- read_stx_conf(infile, title, &atoms, x, v, &ePBC, box);
+ t_topology *top_tmp;
+ snew(top_tmp, 1);
+ read_tps_conf(infile, title, top_tmp, &ePBC, &x, &v, box, FALSE);
+ t_atoms &atoms = top_tmp->atoms;
+ natom = atoms.nr;
+ if (atoms.pdbinfo == NULL)
+ {
+ snew(atoms.pdbinfo, atoms.nr);
+ }
if (fn2ftp(infile) == efPDB)
{
get_pdb_atomnumber(&atoms, aps);
if (xfn != NULL)
{
- snew(atoms, 1);
- get_stx_coordnum(xfn, &(atoms->nr));
- init_t_atoms(atoms, atoms->nr, TRUE);
- snew(x, atoms->nr);
- snew(v, atoms->nr);
fprintf(stderr, "\nReading structure file\n");
- read_stx_conf(xfn, title, atoms, x, v, NULL, box);
+ t_topology *top;
+ snew(top, 1);
+ read_tps_conf(xfn, title, top, NULL, &x, &v, box, FALSE);
+ atoms = &top->atoms;
+ if (atoms->pdbinfo == NULL)
+ {
+ snew(atoms->pdbinfo, atoms->nr);
+ }
}
if (bFreeze)
write_t_edx(fp, edpars->sori, "NORIGIN, XORIGIN");
}
-int read_conffile(const char *confin, char *title, rvec *x[])
+int read_conffile(const char *confin, char *title, rvec **x)
{
-/* read coordinates out of STX file */
- int natoms;
- t_atoms confat;
- matrix box;
+ t_topology top;
+ matrix box;
printf("read coordnumber from file %s\n", confin);
- get_stx_coordnum(confin, &natoms);
- printf("number of coordinates in file %d\n", natoms);
-/* if (natoms != ncoords)
- gmx_fatal(FARGS,"number of coordinates in coordinate file (%s, %d)\n"
- " does not match topology (= %d)",
- confin,natoms,ncoords);
- else {*/
- /* make space for coordinates and velocities */
- init_t_atoms(&confat, natoms, FALSE);
- snew(*x, natoms);
- read_stx_conf(confin, title, &confat, *x, NULL, NULL, box);
- return natoms;
+ read_tps_conf(confin, title, &top, NULL, x, NULL, box, FALSE);
+ printf("number of coordinates in file %d\n", top.atoms.nr);
+ return top.atoms.nr;
}
if (stxfile)
{
- snew(atoms, 1);
- get_stx_coordnum(stxfile, &(atoms->nr));
- init_t_atoms(atoms, atoms->nr, TRUE);
- snew(x, atoms->nr);
- snew(v, atoms->nr);
+ t_topology *top;
+ snew(top, 1);
fprintf(stderr, "\nReading structure file\n");
- read_stx_conf(stxfile, title, atoms, x, v, &ePBC, box);
+ read_tps_conf(stxfile, title, top, &ePBC, &x, &v, box, FALSE);
+ atoms = &top->atoms;
+ if (atoms->pdbinfo == NULL)
+ {
+ snew(atoms->pdbinfo, atoms->nr);
+ }
natoms = atoms->nr;
bNatoms = TRUE;
}
#include "gromacs/math/do_fit.h"
#include "gromacs/topology/atoms.h"
#include "gromacs/topology/index.h"
+#include "gromacs/topology/topology.h"
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/smalloc.h"
int i, isize, is_lsq, nat1, nat2;
t_trxstatus *status;
atom_id *index, *index_lsq, *index_all, *dummy;
- t_atoms atoms;
- rvec *x1, *x2, *xx, *v;
+ rvec *x1, *x2, *xx;
matrix box;
real rms1, rms2, fac, *mass;
char title[STRLEN], *grpname;
{
return 0;
}
- get_stx_coordnum (opt2fn("-f1", NFILE, fnm), &nat1);
- get_stx_coordnum (opt2fn("-f2", NFILE, fnm), &nat2);
+
+ t_topology *top;
+ snew(top, 1);
+ read_tps_conf(opt2fn("-f1", NFILE, fnm), title, top, NULL, &x1, NULL, box, FALSE);
+ nat1 = top->atoms.nr;
+ read_tps_conf(opt2fn("-f2", NFILE, fnm), title, top, NULL, &x2, NULL, box, FALSE);
+ nat2 = top->atoms.nr;
if (nat1 != nat2)
{
gmx_fatal(FARGS, "Number of atoms in first structure is %d, in second %d",
nat1, nat2);
}
-
- init_t_atoms(&atoms, nat1, TRUE);
- snew(x1, nat1);
- snew(x2, nat1);
snew(xx, nat1);
- snew(v, nat1);
-
- read_stx_conf(opt2fn("-f1", NFILE, fnm), title, &atoms, x1, v, NULL, box);
- read_stx_conf(opt2fn("-f2", NFILE, fnm), title, &atoms, x2, v, NULL, box);
+ t_atoms &atoms = top->atoms;
snew(mass, nat1);
snew(index_all, nat1);
matrix box, pdbbox;
rvec *x, *pdbx, *xref;
t_trxstatus *status;
- int npdbatoms;
const char *label;
char title[STRLEN];
if (bReadPDB)
{
- get_stx_coordnum(opt2fn("-q", NFILE, fnm), &npdbatoms);
+ t_topology *top_pdb;
+ snew(top_pdb, 1);
+ /* Read coordinates twice */
+ read_tps_conf(opt2fn("-q", NFILE, fnm), title, top_pdb, NULL, NULL, NULL, pdbbox, FALSE);
snew(pdbatoms, 1);
+ *pdbatoms = top_pdb->atoms;
+ read_tps_conf(opt2fn("-q", NFILE, fnm), title, top_pdb, NULL, &pdbx, NULL, pdbbox, FALSE);
snew(refatoms, 1);
- init_t_atoms(pdbatoms, npdbatoms, TRUE);
- init_t_atoms(refatoms, npdbatoms, TRUE);
- snew(pdbx, npdbatoms);
- /* Read coordinates twice */
- read_stx_conf(opt2fn("-q", NFILE, fnm), title, pdbatoms, pdbx, NULL, NULL, pdbbox);
- read_stx_conf(opt2fn("-q", NFILE, fnm), title, refatoms, pdbx, NULL, NULL, pdbbox);
+ *refatoms = top_pdb->atoms;
+ sfree(top_pdb);
}
else
{
pdbatoms = &top.atoms;
refatoms = &top.atoms;
pdbx = xref;
- npdbatoms = pdbatoms->nr;
- snew(pdbatoms->pdbinfo, npdbatoms);
+ snew(pdbatoms->pdbinfo, pdbatoms->nr);
copy_mat(box, pdbbox);
}
vol = nx*ny*nz; /* calculate volume in grid points (= nr. molecules) */
- get_stx_coordnum(opt2fn("-f", NFILE, fnm), &natoms);
- snew(atoms, 1);
+ t_topology *top;
+ snew(top, 1);
+ atoms = &top->atoms;
+ read_tps_conf(opt2fn("-f", NFILE, fnm), title, top, &ePBC, &x, &v, box, FALSE);
+ natoms = atoms->nr;
+ nres = atoms->nres; /* nr of residues in one element? */
/* make space for all the atoms */
- init_t_atoms(atoms, natoms*vol, FALSE);
- snew(x, natoms*vol); /* get space for coordinates of all 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(v, natoms*vol); /* velocities. not really needed? */
snew(vrot, natoms);
- /* set atoms->nr to the number in one box *
- * to avoid complaints in read_stx_conf *
- */
- atoms->nr = natoms;
- read_stx_conf(opt2fn("-f", NFILE, fnm), title, atoms, x, v, &ePBC, box);
-
- nres = atoms->nres; /* nr of residues in one element? */
if (bTRX)
{
t_molinfo *molinfo = NULL;
int nmolblock;
gmx_molblock_t *molblock, *molbs;
- t_atoms *confat;
int mb, i, nrmols, nmismatch;
char buf[STRLEN];
gmx_bool bGB = FALSE;
fprintf(stderr, "processing coordinates...\n");
}
- get_stx_coordnum(confin, &state->natoms);
+ char title[STRLEN];
+ t_topology *conftop;
+ snew(conftop, 1);
+ init_state(state, 0, 0, 0, 0, 0);
+ read_tps_conf(confin, title, conftop, NULL, &state->x, &state->v, state->box, FALSE);
+ state->natoms = state->nalloc = conftop->atoms.nr;
if (state->natoms != sys->natoms)
{
gmx_fatal(FARGS, "number of coordinates in coordinate file (%s, %d)\n"
" does not match topology (%s, %d)",
confin, state->natoms, topfile, sys->natoms);
}
- else
- {
- /* make space for coordinates and velocities */
- char title[STRLEN];
- snew(confat, 1);
- init_t_atoms(confat, state->natoms, FALSE);
- init_state(state, state->natoms, 0, 0, 0, 0);
- read_stx_conf(confin, title, confat, state->x, state->v, NULL, state->box);
- /* This call fixes the box shape for runs with pressure scaling */
- set_box_rel(ir, state);
+ /* This call fixes the box shape for runs with pressure scaling */
+ set_box_rel(ir, state);
- nmismatch = check_atom_names(topfile, confin, sys, confat);
- free_t_atoms(confat, TRUE);
- sfree(confat);
+ nmismatch = check_atom_names(topfile, confin, sys, &conftop->atoms);
+ done_top(conftop);
+ sfree(conftop);
- if (nmismatch)
- {
- sprintf(buf, "%d non-matching atom name%s\n"
- "atom names from %s will be used\n"
- "atom names from %s will be ignored\n",
- nmismatch, (nmismatch == 1) ? "" : "s", topfile, confin);
- warning(wi, buf);
- }
+ if (nmismatch)
+ {
+ sprintf(buf, "%d non-matching atom name%s\n"
+ "atom names from %s will be used\n"
+ "atom names from %s will be ignored\n",
+ nmismatch, (nmismatch == 1) ? "" : "s", topfile, confin);
+ warning(wi, buf);
+ }
- /* Do more checks, mostly related to constraints */
- if (bVerbose)
- {
- fprintf(stderr, "double-checking input for internal consistency...\n");
- }
- {
- int bHasNormalConstraints = 0 < (nint_ftype(sys, molinfo, F_CONSTR) +
- nint_ftype(sys, molinfo, F_CONSTRNC));
- int bHasAnyConstraints = bHasNormalConstraints || 0 < nint_ftype(sys, molinfo, F_SETTLE);
- double_check(ir, state->box,
- bHasNormalConstraints,
- bHasAnyConstraints,
- wi);
- }
+ /* Do more checks, mostly related to constraints */
+ if (bVerbose)
+ {
+ fprintf(stderr, "double-checking input for internal consistency...\n");
+ }
+ {
+ int bHasNormalConstraints = 0 < (nint_ftype(sys, molinfo, F_CONSTR) +
+ nint_ftype(sys, molinfo, F_CONSTRNC));
+ int bHasAnyConstraints = bHasNormalConstraints || 0 < nint_ftype(sys, molinfo, F_SETTLE);
+ double_check(ir, state->box,
+ bHasNormalConstraints,
+ bHasAnyConstraints,
+ wi);
}
if (bGenVel)
rvec *x, *v, *xp;
dvec sum;
double totmass;
- t_atoms dumat;
+ t_topology *top;
matrix box, invbox;
int natoms, npbcdim = 0;
char warn_buf[STRLEN], title[STRLEN];
t_params *pr, *prfb;
t_atom *atom;
- get_stx_coordnum(fn, &natoms);
+ snew(top, 1);
+ read_tps_conf(fn, title, top, NULL, &x, &v, box, FALSE);
+ natoms = top->atoms.nr;
+ done_top(top);
+ sfree(top);
if (natoms != mtop->natoms)
{
sprintf(warn_buf, "The number of atoms in %s (%d) does not match the number of atoms in the topology (%d). Will assume that the first %d atoms in the topology and %s match.", fn, natoms, mtop->natoms, std::min(mtop->natoms, natoms), fn);
warning(wi, warn_buf);
}
- snew(x, natoms);
- snew(v, natoms);
- init_t_atoms(&dumat, natoms, FALSE);
- read_stx_conf(fn, title, &dumat, x, v, NULL, box);
npbcdim = ePBC2npbcdim(ePBC);
clear_rvec(com);
}
}
- free_t_atoms(&dumat, TRUE);
sfree(x);
sfree(v);
sfree(hadAtom);
/* READ IT */
printf("Reading %s...\n", inf);
- get_stx_coordnum(inf, &natom);
- init_t_atoms(atoms, natom, TRUE);
- snew(*x, natom);
- read_stx_conf(inf, title, atoms, *x, NULL, ePBC, box);
+ t_topology *top;
+ snew(top, 1);
+ read_tps_conf(inf, title, top, ePBC, x, NULL, box, FALSE);
+ *atoms = top->atoms;
+ sfree(top);
+ natom = atoms->nr;
+ if (atoms->pdbinfo == NULL)
+ {
+ snew(atoms->pdbinfo, atoms->nr);
+ }
if (fn2ftp(inf) == efPDB)
{
get_pdb_atomnumber(atoms, aps);
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
char *readConformation(const char *confin, t_atoms *atoms, rvec **x, rvec **v,
int *ePBC, matrix box, const char *statusTitle)
{
- char *title;
- int natoms;
+ t_topology *top;
+ char *title;
+ snew(top, 1);
snew(title, STRLEN);
- get_stx_coordnum(confin, &natoms);
- /* allocate memory for atom coordinates of configuration */
- snew(*x, natoms);
- if (v)
- {
- snew(*v, natoms);
- }
- init_t_atoms(atoms, natoms, FALSE);
-
- /* read residue number, residue names, atomnames, coordinates etc. */
fprintf(stderr, "Reading %s configuration%s\n", statusTitle, v ? " and velocities" : "");
- read_stx_conf(confin, title, atoms, *x, v ? *v : NULL, ePBC, box);
+ read_tps_conf(confin, title, top, ePBC, x, v, box, FALSE);
+ *atoms = top->atoms;
fprintf(stderr, "%s\nContaining %d atoms in %d residues\n",
title, atoms->nr, atoms->nres);
+ sfree(top);
return title;
}
FILE *fp;
t_params plist[F_NRE];
t_excls *excls;
- t_atoms *atoms; /* list with all atoms */
gpp_atomtype_t atype;
t_nextnb nnb;
t_nm2type *nm2t;
init_plist(plist);
/* Read coordinates */
- get_stx_coordnum(opt2fn("-f", NFILE, fnm), &natoms);
- snew(atoms, 1);
-
- /* make space for all the atoms */
- init_t_atoms(atoms, natoms, TRUE);
- snew(x, natoms);
-
- read_stx_conf(opt2fn("-f", NFILE, fnm), title, atoms, x, NULL, &epbc, box);
+ t_topology *top;
+ snew(top, 1);
+ read_tps_conf(opt2fn("-f", NFILE, fnm), title, top, &epbc, &x, NULL, box, FALSE);
+ t_atoms *atoms = &top->atoms;
+ natoms = atoms->nr;
+ if (atoms->pdbinfo == NULL)
+ {
+ snew(atoms->pdbinfo, natoms);
+ }
sprintf(n2t, "%s", ffdir);
nm2t = rd_nm2type(n2t, &nnm);