#include "gromacs/fileio/tpxio.h"
#include "gromacs/fileio/trxio.h"
#include "gromacs/math/vec.h"
-#include "gromacs/topology/atomprop.h"
#include "gromacs/topology/atoms.h"
#include "gromacs/topology/block.h"
#include "gromacs/topology/mtop_util.h"
rvec **x, rvec **v, matrix box, gmx_bool bMass)
{
t_tpxheader header;
- int natoms, i;
+ int natoms;
gmx_bool bTop, bXNULL = FALSE;
gmx_mtop_t *mtop;
- gmx_atomprop_t aps;
bTop = fn2bTPX(infile);
if (ePBC != NULL)
}
if (bMass)
{
- aps = gmx_atomprop_init();
- for (i = 0; (i < natoms); i++)
- {
- if (!gmx_atomprop_query(aps, epropMass,
- *top->atoms.resinfo[top->atoms.atom[i].resind].name,
- *top->atoms.atomname[i],
- &(top->atoms.atom[i].m)))
- {
- if (debug)
- {
- fprintf(debug, "Can not find mass for atom %s %d %s, setting to 1\n",
- *top->atoms.resinfo[top->atoms.atom[i].resind].name,
- top->atoms.resinfo[top->atoms.atom[i].resind].nr,
- *top->atoms.atomname[i]);
- }
- }
- }
- gmx_atomprop_destroy(aps);
+ atomsSetMassesBasedOnNames(&top->atoms);
}
top->idef.ntypes = -1;
}
clear_mat(box);
+ atoms->haveMass = FALSE;
+ atoms->haveCharge = FALSE;
+ atoms->haveType = FALSE;
+ atoms->haveBState = FALSE;
+ atoms->havePdbInfo = FALSE;
+
fp = gmx_fio_fopen(infile, "r");
bFoundParticles = FALSE;
{
bFoundProp = TRUE;
prop[nprop++] = p;
- /* printf(" prop[%d] = %s\n",nprop-1,esp_prop[prop[nprop-1]]); */
+ if (p == espQ)
+ {
+ atoms->haveCharge = TRUE;
+ }
+
+ if (debug)
+ {
+ fprintf(debug, " prop[%d] = %s\n", nprop-1, esp_prop[prop[nprop-1]]);
+ }
}
}
if (!bFoundProp && word[0] != '}')
nwanted = fr->natoms;
atoms = fr->atoms;
+ if (atoms != NULL)
+ {
+ atoms->haveMass = FALSE;
+ atoms->haveCharge = FALSE;
+ atoms->haveType = FALSE;
+ atoms->haveBState = FALSE;
+ atoms->havePdbInfo = FALSE;
+ }
natoms = 0;
" (%d)\n", natoms, atoms->nr);
}
+ atoms->haveMass = FALSE;
+ atoms->haveCharge = FALSE;
+ atoms->haveType = FALSE;
+ atoms->haveBState = FALSE;
+ atoms->havePdbInfo = FALSE;
+
bFirst = TRUE;
bVel = FALSE;
{
gmx_write_pdb_box(out, ePBC, box);
}
- if (atoms->pdbinfo)
+ if (atoms->havePdbInfo)
{
/* Check whether any occupancies are set, in that case leave it as is,
* otherwise set them all to one
clear_mat(box);
}
+ atoms->haveMass = FALSE;
+ atoms->haveCharge = FALSE;
+ atoms->haveType = FALSE;
+ atoms->haveBState = FALSE;
+ atoms->havePdbInfo = (atoms->pdbinfo != NULL);
+
bCOMPND = FALSE;
title[0] = '\0';
natom = 0;
break;
case epdbANISOU:
- if (atoms->pdbinfo)
+ if (atoms->havePdbInfo)
{
read_anisou(line, natom, atoms);
}
#include "gromacs/utility/cstringutil.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/futil.h"
+#include "gromacs/utility/gmxassert.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/snprintf.h"
#include "gromacs/utility/txtdump.h"
}
if (bRead)
{
+ /* Since we have always written all t_atom properties in the tpr file
+ * (at least for all backward compatible versions), we don't store
+ * but simple set the booleans here.
+ */
+ atoms->haveMass = TRUE;
+ atoms->haveCharge = TRUE;
+ atoms->haveType = TRUE;
+ atoms->haveBState = TRUE;
+ atoms->havePdbInfo = FALSE;
+
snew(atoms->atom, atoms->nr);
snew(atoms->atomname, atoms->nr);
snew(atoms->atomtype, atoms->nr);
}
atoms->pdbinfo = NULL;
}
+ else
+ {
+ GMX_RELEASE_ASSERT(atoms->haveMass && atoms->haveCharge && atoms->haveType && atoms->haveBState, "Mass, charge, atomtype and B-state parameters should be present in t_atoms when writing a tpr file");
+ }
for (i = 0; (i < atoms->nr); i++)
{
do_atom(fio, &atoms->atom[i], egcNR, bRead, file_version, groups, i);
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016, 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.
atoms->atom[i] = atoms->atom[i+1];
}
- if (atoms->pdbinfo)
+ if (atoms->havePdbInfo)
{
/* Shift the pdbatom struct down */
for (i = inr; (i < atoms->nr-1); i++)
{
real x0, y0, z0;
+ atoms->havePdbInfo = TRUE;
+
if (NULL == atoms->pdbinfo)
{
snew(atoms->pdbinfo, atoms->nr);
srenew(atoms1->pdbinfo, atoms1->nr);
srenew(atoms1->atom, atoms1->nr); /* Why renew atom? */
+ atoms1->havePdbInfo = TRUE;
+
/* Avoid segfaults when writing the pdb-file */
for (i = 0; i < atoms1->nr; i++)
{
{
snew(atoms->pdbinfo, atoms->nr);
}
+ atoms->havePdbInfo = TRUE;
}
top = gmx_mtop_generate_local_top(&mtop, ir.efep != efepNO);
{
snew(atoms.pdbinfo, atoms.nr);
}
- natoms = atoms.nr;
+ atoms.havePdbInfo = TRUE;
+ natoms = atoms.nr;
snew(xout, natoms);
snew(vout, natoms);
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016, 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.
{
snew(atoms.pdbinfo, atoms.nr);
}
+ atoms.havePdbInfo = TRUE;
+
if (fn2ftp(infile) == efPDB)
{
get_pdb_atomnumber(&atoms, aps);
if (check_have_atoms(atoms, ostring) &&
parse_names(string, &n_names, names))
{
- if (atoms->atomtype == NULL)
+ if (!(atoms->haveType))
{
printf("Need a run input file to select atom types\n");
}
refatoms = &top.atoms;
pdbx = xref;
snew(pdbatoms->pdbinfo, pdbatoms->nr);
+ pdbatoms->havePdbInfo = TRUE;
copy_mat(box, pdbbox);
}
{
snew(atoms->pdbinfo, atoms->nr);
}
+ atoms->havePdbInfo = TRUE;
+
if (onedim == -1)
{
for (i = 0; i < isize; i++)
/* get memory for stuff to go in .pdb file, and initialize
* the pdbinfo structure part if the input has it.
*/
- init_t_atoms(&useatoms, atoms->nr, (atoms->pdbinfo != NULL));
+ init_t_atoms(&useatoms, atoms->nr, atoms->havePdbInfo);
sfree(useatoms.resinfo);
useatoms.resinfo = atoms->resinfo;
for (i = 0; (i < nout); i++)
{
useatoms.atomname[i] = atoms->atomname[index[i]];
useatoms.atom[i] = atoms->atom[index[i]];
- if (atoms->pdbinfo != NULL)
+ if (atoms->havePdbInfo)
{
useatoms.pdbinfo[i] = atoms->pdbinfo[index[i]];
}
push_molt(symtab, &nmol, molinfo, pline, wi);
srenew(block2, nmol);
- block2[nmol-1].nr = 0;
- mi0 = &((*molinfo)[nmol-1]);
+ block2[nmol-1].nr = 0;
+ mi0 = &((*molinfo)[nmol-1]);
+ mi0->atoms.haveMass = TRUE;
+ mi0->atoms.haveCharge = TRUE;
+ mi0->atoms.haveType = TRUE;
+ mi0->atoms.haveBState = TRUE;
+ mi0->atoms.havePdbInfo = FALSE;
break;
}
case d_atoms:
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016, 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.
int m, j, ai;
real mass, mtot;
- GMX_RELEASE_ASSERT(top != nullptr,
+ GMX_RELEASE_ASSERT(top != nullptr && top->atoms.haveMass,
"No masses available while mass weighting was requested");
clear_rvec(xout);
mtot = 0;
int m, j, ai;
real mass, mtot;
- GMX_RELEASE_ASSERT(top != nullptr,
+ GMX_RELEASE_ASSERT(top != nullptr && top->atoms.haveMass,
"No masses available while mass weighting was requested");
clear_rvec(fout);
mtot = 0;
real mass, mtot;
rvec dx, xtest;
- GMX_RELEASE_ASSERT(top != nullptr,
+ GMX_RELEASE_ASSERT(top != nullptr && top->atoms.haveMass,
"No masses available while mass weighting was requested");
/* First simple calculation */
clear_rvec(xout);
rvec xb;
real mass, mtot;
- GMX_RELEASE_ASSERT(top != nullptr,
+ GMX_RELEASE_ASSERT(top != nullptr && top->atoms.haveMass,
"No masses available while mass weighting was requested");
for (b = 0; b < block->nr; ++b)
{
rvec fb;
real mass, mtot;
- GMX_RELEASE_ASSERT(top != nullptr,
+ GMX_RELEASE_ASSERT(top != nullptr && top->atoms.haveMass,
"No masses available while mass weighting was requested");
for (b = 0; b < block->nr; ++b)
{
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2009,2010,2011,2012,2013,2014,2015, by the GROMACS development team, led by
+ * Copyright (c) 2009,2010,2011,2012,2013,2014,2015,2016, 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.
{
bool bOk;
- bOk = (top != NULL && top->atoms.atomtype != NULL);
+ bOk = (top != NULL && (top->atoms.haveType));
if (!bOk)
{
GMX_THROW(gmx::InconsistentInputError("Atom types not available in topology"));
{
top_->atoms.atom[i].m = (i % 3 == 0 ? 2.0 : 1.0);
}
+ top_->atoms.haveMass = TRUE;
if (frame_ != NULL)
{
frame_->natoms = count;
}
top_->atoms.atomtype[i] = &atomtypes_[j];
}
+ top_->atoms.haveType = TRUE;
}
void TopologyManager::initUniformResidues(int residueSize)
#include <algorithm>
+#include "gromacs/topology/atomprop.h"
#include "gromacs/topology/symtab.h"
#include "gromacs/utility/compare.h"
+#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/txtdump.h"
void init_atom(t_atoms *at)
{
- at->nr = 0;
- at->nres = 0;
- at->atom = NULL;
- at->resinfo = NULL;
- at->atomname = NULL;
- at->atomtype = NULL;
- at->atomtypeB = NULL;
- at->pdbinfo = NULL;
+ at->nr = 0;
+ at->nres = 0;
+ at->atom = NULL;
+ at->resinfo = NULL;
+ at->atomname = NULL;
+ at->atomtype = NULL;
+ at->atomtypeB = NULL;
+ at->pdbinfo = NULL;
+ at->haveMass = FALSE;
+ at->haveCharge = FALSE;
+ at->haveType = FALSE;
+ at->haveBState = FALSE;
+ at->havePdbInfo = FALSE;
}
void init_atomtypes(t_atomtypes *at)
atoms->atomtypeB = NULL;
snew(atoms->resinfo, natoms);
snew(atoms->atom, natoms);
- if (bPdbinfo)
+ atoms->haveMass = FALSE;
+ atoms->haveCharge = FALSE;
+ atoms->haveType = FALSE;
+ atoms->haveBState = FALSE;
+ atoms->havePdbInfo = bPdbinfo;
+ if (atoms->havePdbInfo)
{
snew(atoms->pdbinfo, natoms);
}
}
}
}
+
+void atomsSetMassesBasedOnNames(t_atoms *atoms)
+{
+ if (atoms->haveMass)
+ {
+ /* We could decide to anyhow assign then or generate a fatal error,
+ * but it's probably most useful to keep the masses we have.
+ */
+ return;
+ }
+
+ gmx_atomprop_t aps = gmx_atomprop_init();
+
+ for (int i = 0; i < atoms->nr; i++)
+ {
+ if (!gmx_atomprop_query(aps, epropMass,
+ *atoms->resinfo[atoms->atom[i].resind].name,
+ *atoms->atomname[i],
+ &atoms->atom[i].m))
+ {
+ if (debug)
+ {
+ fprintf(debug, "Can not find mass for atom %s %d %s, setting to 1\n",
+ *atoms->resinfo[atoms->atom[i].resind].name,
+ atoms->resinfo[atoms->atom[i].resind].nr,
+ *atoms->atomname[i]);
+ }
+ atoms->atom[i].m = 1;
+ }
+ }
+ gmx_atomprop_destroy(aps);
+
+ atoms->haveMass = TRUE;
+}
typedef struct t_atoms
{
- int nr; /* Nr of atoms */
- t_atom *atom; /* Array of atoms (dim: nr) */
+ int nr; /* Nr of atoms */
+ t_atom *atom; /* Array of atoms (dim: nr) */
/* The following entries will not */
/* always be used (nres==0) */
- char ***atomname; /* Array of pointers to atom name */
+ char ***atomname; /* Array of pointers to atom name */
/* use: (*(atomname[i])) */
- char ***atomtype; /* Array of pointers to atom types */
+ char ***atomtype; /* Array of pointers to atom types */
/* use: (*(atomtype[i])) */
- char ***atomtypeB; /* Array of pointers to B atom types */
+ char ***atomtypeB; /* Array of pointers to B atom types */
/* use: (*(atomtypeB[i])) */
- int nres; /* The number of resinfo entries */
- t_resinfo *resinfo; /* Array of residue names and numbers */
- t_pdbinfo *pdbinfo; /* PDB Information, such as aniso. Bfac */
+ int nres; /* The number of resinfo entries */
+ t_resinfo *resinfo; /* Array of residue names and numbers */
+ t_pdbinfo *pdbinfo; /* PDB Information, such as aniso. Bfac */
+
+ /* Flags that tell if properties are set for all nr atoms.
+ * For B-state parameters, both haveBState and the mass/charge/type
+ * flag should be TRUE.
+ */
+ gmx_bool haveMass; /* Mass available */
+ gmx_bool haveCharge; /* Charge available */
+ gmx_bool haveType; /* Atom type available */
+ gmx_bool haveBState; /* B-state parameters available */
+ gmx_bool havePdbInfo; /* pdbinfo available */
} t_atoms;
typedef struct t_atomtypes
void cmp_atoms(FILE *fp, const t_atoms *a1, const t_atoms *a2, real ftol, real abstol);
+/*! \brief Set mass for each atom using the atom and residue names using a database
+ *
+ * If atoms->haveMass = TRUE does nothing.
+ */
+void atomsSetMassesBasedOnNames(t_atoms *atoms);
+
#endif
int srcnr = src->nr;
int destnr = dest->nr;
+ if (dest->nr == 0)
+ {
+ dest->haveMass = src->haveMass;
+ dest->haveType = src->haveType;
+ dest->haveCharge = src->haveCharge;
+ dest->haveBState = src->haveBState;
+ dest->havePdbInfo = src->havePdbInfo;
+ }
+ else
+ {
+ dest->haveMass = dest->haveMass && src->haveMass;
+ dest->haveType = dest->haveType && src->haveType;
+ dest->haveCharge = dest->haveCharge && src->haveCharge;
+ dest->haveBState = dest->haveBState && src->haveBState;
+ dest->havePdbInfo = dest->havePdbInfo && src->havePdbInfo;
+ }
+
if (srcnr)
{
size = destnr+copies*srcnr;
srenew(dest->atom, size);
srenew(dest->atomname, size);
- srenew(dest->atomtype, size);
- srenew(dest->atomtypeB, size);
+ if (dest->haveType)
+ {
+ srenew(dest->atomtype, size);
+ if (dest->haveBState)
+ {
+ srenew(dest->atomtypeB, size);
+ }
+ }
+ if (dest->havePdbInfo)
+ {
+ srenew(dest->pdbinfo, size);
+ }
}
if (src->nres)
{
for (l = destnr, j = 0; (j < copies); j++, l += srcnr)
{
- memcpy((char *) &(dest->atomname[l]), (char *) &(src->atomname[0]),
- (size_t)(srcnr*sizeof(src->atomname[0])));
- memcpy((char *) &(dest->atomtype[l]), (char *) &(src->atomtype[0]),
- (size_t)(srcnr*sizeof(src->atomtype[0])));
- memcpy((char *) &(dest->atomtypeB[l]), (char *) &(src->atomtypeB[0]),
- (size_t)(srcnr*sizeof(src->atomtypeB[0])));
memcpy((char *) &(dest->atom[l]), (char *) &(src->atom[0]),
(size_t)(srcnr*sizeof(src->atom[0])));
+ memcpy((char *) &(dest->atomname[l]), (char *) &(src->atomname[0]),
+ (size_t)(srcnr*sizeof(src->atomname[0])));
+ if (dest->haveType)
+ {
+ memcpy((char *) &(dest->atomtype[l]), (char *) &(src->atomtype[0]),
+ (size_t)(srcnr*sizeof(src->atomtype[0])));
+ if (dest->haveBState)
+ {
+ memcpy((char *) &(dest->atomtypeB[l]), (char *) &(src->atomtypeB[0]),
+ (size_t)(srcnr*sizeof(src->atomtypeB[0])));
+ }
+ }
+ if (dest->havePdbInfo)
+ {
+ memcpy((char *) &(dest->pdbinfo[l]), (char *) &(src->pdbinfo[0]),
+ (size_t)(srcnr*sizeof(src->pdbinfo[0])));
+ }
}
/* Increment residue indices */