*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
"CONECT"
};
-
#define REMARK_SIM_BOX "REMARK THIS IS A SIMULATION BOX"
static void xlate_atomname_pdb2gmx(char *name)
}
}
-void get_pdb_atomnumber(const t_atoms *atoms, gmx_atomprop_t aps)
+void get_pdb_atomnumber(const t_atoms *atoms, AtomProperties *aps)
{
int i, atomnumber, len;
size_t k;
- char anm[6], anm_copy[6], *ptr;
+ char anm[6], anm_copy[6];
char nc = '\0';
real eval;
if ((anm[0] != ' ') && ((len <= 2) || !std::isdigit(anm[2])))
{
anm_copy[2] = nc;
- if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
+ if (aps->setAtomProperty(epropElement, "???", anm_copy, &eval))
{
atomnumber = gmx::roundToInt(eval);
atomNumberSet = true;
else
{
anm_copy[1] = nc;
- if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
+ if (aps->setAtomProperty(epropElement, "???", anm_copy, &eval))
{
atomnumber = gmx::roundToInt(eval);
atomNumberSet = true;
}
anm_copy[0] = anm[k];
anm_copy[1] = nc;
- if (gmx_atomprop_query(aps, epropElement, "???", anm_copy, &eval))
+ if (aps->setAtomProperty(epropElement, "???", anm_copy, &eval))
{
atomnumber = gmx::roundToInt(eval);
atomNumberSet = true;
}
}
+ std::string buf;
if (atomNumberSet)
{
atoms->atom[i].atomnumber = atomnumber;
- ptr = gmx_atomprop_element(aps, atomnumber);
+ buf = aps->elementFromAtomNumber(atomnumber);
if (debug)
{
fprintf(debug, "Atomnumber for atom '%s' is %d\n",
anm, atomnumber);
}
}
- else
- {
- ptr = nullptr;
- }
- std::strncpy(atoms->atom[i].elem, ptr == nullptr ? "" : ptr, 4);
+ buf.resize(3);
+ std::strncpy(atoms->atom[i].elem, buf.c_str(), 4);
}
}
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
#include "gromacs/utility/basedefinitions.h"
#include "gromacs/utility/real.h"
-struct gmx_atomprop;
+class AtomProperties;
struct t_atoms;
struct t_symtab;
struct t_topology;
* which may be useful for visualization purposes.
*/
-void get_pdb_atomnumber(const t_atoms *atoms, struct gmx_atomprop *aps);
+void get_pdb_atomnumber(const t_atoms *atoms, AtomProperties *aps);
/* Routine to extract atomic numbers from the atom names */
int read_pdbfile(FILE *in, char *title, int *model_nr,
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/strdb.h"
-
-static real calc_mass(t_atoms *atoms, gmx_bool bGetMass, gmx_atomprop_t aps)
+static real calc_mass(t_atoms *atoms, gmx_bool bGetMass, AtomProperties *aps)
{
real tmass;
int i;
{
if (bGetMass)
{
- gmx_atomprop_query(aps, epropMass,
- *atoms->resinfo[atoms->atom[i].resind].name,
- *atoms->atomname[i], &(atoms->atom[i].m));
+ aps->setAtomProperty(epropMass,
+ *atoms->resinfo[atoms->atom[i].resind].name,
+ *atoms->atomname[i], &(atoms->atom[i].m));
}
tmass += atoms->atom[i].m;
}
gmx_bool bIndex, bSetSize, bSetAng, bDist, bSetCenter, bAlign;
gmx_bool bHaveV, bScale, bRho, bTranslate, bRotate, bCalcGeom, bCalcDiam;
real diam = 0, mass = 0, d, vdw;
- gmx_atomprop_t aps;
gmx_conect conect;
gmx_output_env_t *oenv;
t_filenm fnm[] =
outftp = fn2ftp(outfile);
inftp = fn2ftp(infile);
- aps = gmx_atomprop_init();
+ AtomProperties aps;
if (bMead && bGrasp)
{
if (fn2ftp(infile) == efPDB)
{
- get_pdb_atomnumber(&atoms, aps);
+ get_pdb_atomnumber(&atoms, &aps);
}
printf("Read %d atoms\n", atoms.nr);
/* Get the element numbers if available in a pdb file */
if (fn2ftp(infile) == efPDB)
{
- get_pdb_atomnumber(&atoms, aps);
+ get_pdb_atomnumber(&atoms, &aps);
}
if (ePBC != epbcNONE)
/* Determine the Van der Waals radius from the force field */
if (bReadVDW)
{
- if (!gmx_atomprop_query(aps, epropVDW,
- *top->atoms.resinfo[top->atoms.atom[i].resind].name,
- *top->atoms.atomname[i], &vdw))
+ if (!aps.setAtomProperty(epropVDW,
+ *top->atoms.resinfo[top->atoms.atom[i].resind].name,
+ *top->atoms.atomname[i], &vdw))
{
vdw = rvdw;
}
if (bRho || bOrient || bAlign)
{
- mass = calc_mass(&atoms, !fn2bTPX(infile), aps);
+ mass = calc_mass(&atoms, !fn2bTPX(infile), &aps);
}
if (bOrient)
write_sto_conf(outfile, *top_tmp->name, &atoms, x, bHaveV ? v : nullptr, ePBC, box);
}
}
- gmx_atomprop_destroy(aps);
-
do_view(oenv, outfile, nullptr);
return 0;
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
RotationType enum_rot)
{
fprintf(stderr, "Initialising inter-atomic distances...\n");
- gmx_atomprop_t aps = gmx_atomprop_init();
+ AtomProperties aps;
std::vector<real> exclusionDistances(
- makeExclusionDistances(atoms, aps, defaultDistance, scaleFactor));
+ makeExclusionDistances(atoms, &aps, defaultDistance, scaleFactor));
const std::vector<real> exclusionDistances_insrt(
- makeExclusionDistances(&atoms_insrt, aps, defaultDistance, scaleFactor));
- gmx_atomprop_destroy(aps);
+ makeExclusionDistances(&atoms_insrt, &aps, defaultDistance, scaleFactor));
const real maxInsertRadius
= *std::max_element(exclusionDistances_insrt.begin(),
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015,2016,2017,2018,2019, 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.
#include "gromacs/topology/atoms.h"
std::vector<real>
-makeExclusionDistances(const t_atoms *a, gmx_atomprop_t aps,
+makeExclusionDistances(const t_atoms *a, AtomProperties *aps,
real defaultDistance, real scaleFactor)
{
std::vector<real> exclusionDistances;
for (int i = 0; i < a->nr; ++i)
{
real value;
- if (!gmx_atomprop_query(aps, epropVDW,
- *(a->resinfo[a->atom[i].resind].name),
- *(a->atomname[i]), &value))
+ if (!aps->setAtomProperty(epropVDW,
+ *(a->resinfo[a->atom[i].resind].name),
+ *(a->atomname[i]), &value))
{
value = defaultDistance;
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2014,2015,2016,2018, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015,2016,2018,2019, 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.
#include "gromacs/utility/real.h"
-struct gmx_atomprop;
+class AtomProperties;
struct t_atoms;
/*! \brief Allocate and fill an array of inter-atomic half distances
* insert-molecules for deciding whether molecules clash. The return
* pointer should be freed by the caller. */
std::vector<real>
-makeExclusionDistances(const t_atoms *a, gmx_atomprop *aps,
+makeExclusionDistances(const t_atoms *a, AtomProperties *aps,
real defaultDistance, real scaleFactor);
#endif
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
t_atoms *atoms, rvec **x,
int *ePBC, matrix box, bool bRemoveH,
t_symtab *symtab, gmx_residuetype_t *rt, const char *watres,
- gmx_atomprop_t aps, bool bVerbose)
+ AtomProperties *aps, bool bVerbose)
/* Read a pdb file. (containing proteins) */
{
int natom, new_natom, i;
watres = "HOH";
}
- gmx_atomprop_t aps = gmx_atomprop_init();
+ AtomProperties aps;
char *title;
int ePBC;
t_atoms pdba_all;
rvec *pdbx;
int natom = read_pdball(inputConfFile_.c_str(), bOutputSet_, outFile_.c_str(),
&title, &pdba_all, &pdbx, &ePBC, box, bRemoveH_,
- &symtab, rt, watres, aps, bVerbose_);
+ &symtab, rt, watres, &aps, bVerbose_);
if (natom == 0)
{
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
const gmx::TopologyInformation &topInfo,
t_atoms *atoms,
std::vector<RVec> *x, std::vector<RVec> *v,
- matrix box, gmx_atomprop_t aps,
+ matrix box, AtomProperties *aps,
real defaultDistance, real scaleFactor,
real rshell, int max_sol)
{
}
}
-static void update_top(t_atoms *atoms, int firstSolventResidueIndex, matrix box, int NFILE, t_filenm fnm[],
- gmx_atomprop_t aps)
+static void update_top(t_atoms *atoms,
+ int firstSolventResidueIndex,
+ matrix box,
+ int NFILE,
+ t_filenm fnm[],
+ AtomProperties *aps)
{
FILE *fpin, *fpout;
char buf[STRLEN*2], buf2[STRLEN], *temp;
mtot = 0;
for (i = 0; (i < atoms->nr); i++)
{
- gmx_atomprop_query(aps, epropMass,
- *atoms->resinfo[atoms->atom[i].resind].name,
- *atoms->atomname[i], &mm);
+ aps->setAtomProperty(epropMass,
+ *atoms->resinfo[atoms->atom[i].resind].name,
+ *atoms->atomname[i], &mm);
mtot += mm;
}
/* parameter data */
gmx_bool bProt, bBox;
const char *conf_prot, *confout;
- gmx_atomprop_t aps;
t_filenm fnm[] = {
{ efSTX, "-cp", "protein", ffOPTRD },
"a box size (-box) must be specified");
}
- aps = gmx_atomprop_init();
+ AtomProperties aps;
gmx::TopologyInformation topInfo;
std::vector<RVec> x, v;
}
add_solv(solventFileName, topInfo, atoms.get(), &x, &v, box,
- aps, defaultDistance, scaleFactor, r_shell, max_sol);
+ &aps, defaultDistance, scaleFactor, r_shell, max_sol);
/* write new configuration 1 to file confout */
confout = ftp2fn(efSTO, NFILE, fnm);
/* print size of generated configuration */
fprintf(stderr, "\nOutput configuration contains %d atoms in %d residues\n",
atoms->nr, atoms->nres);
- update_top(atoms.get(), firstSolventResidueIndex, box, NFILE, fnm, aps);
-
- gmx_atomprop_destroy(aps);
+ update_top(atoms.get(), firstSolventResidueIndex, box, NFILE, fnm, &aps);
output_env_done(oenv);
return 0;
gmx_bool bV, bX, bB, bFirst, bOut;
real r2, ekin, temp1, temp2, dist2, vdwfac2, bonlo2, bonhi2;
real *atom_vdw;
- gmx_atomprop_t aps;
fprintf(stderr, "Checking coordinate file %s\n", fn);
read_tps_conf(fn, &top, &ePBC, &x, &v, box, TRUE);
"relative to sum of Van der Waals distance:\n",
vdw_fac, bon_lo, bon_hi);
snew(atom_vdw, natom);
- aps = gmx_atomprop_init();
+ AtomProperties aps;
for (i = 0; (i < natom); i++)
{
- gmx_atomprop_query(aps, epropVDW,
- *(atoms->resinfo[atoms->atom[i].resind].name),
- *(atoms->atomname[i]), &(atom_vdw[i]));
+ aps.setAtomProperty(epropVDW,
+ *(atoms->resinfo[atoms->atom[i].resind].name),
+ *(atoms->atomname[i]), &(atom_vdw[i]));
if (debug)
{
fprintf(debug, "%5d %4s %4s %7g\n", i+1,
atom_vdw[i]);
}
}
- gmx_atomprop_destroy(aps);
if (bB)
{
set_pbc(&pbc, ePBC, box);
#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2014,2015,2018, by the GROMACS development team, led by
+# Copyright (c) 2014,2015,2018,2019, 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.
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2017,2018,2019, 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.
#include <cstdio>
#include <cstring>
+#include "gromacs/compat/make_unique.h"
#include "gromacs/math/functions.h"
#include "gromacs/math/utilities.h"
#include "gromacs/topology/residuetypes.h"
#include "gromacs/utility/smalloc.h"
#include "gromacs/utility/strdb.h"
-typedef struct {
- gmx_bool bSet;
- int nprop, maxprop;
- char *db;
- double def;
- char **atomnm;
- char **resnm;
- gmx_bool *bAvail;
- real *value;
-} aprop_t;
-
-typedef struct gmx_atomprop {
- gmx_bool bWarned, bWarnVDW;
- aprop_t prop[epropNR];
- gmx_residuetype_t *restype;
-} gmx_atomprop;
-
-
-
/* NOTFOUND should be smallest, others larger in increasing priority */
enum {
NOTFOUND = -4, WILDCARD, WILDPROT, PROTEIN
};
-/* return number of matching characters,
- or NOTFOUND if not at least all characters in char *database match */
-static int dbcmp_len(const char *search, const char *database)
+//! Conglomeration of atom property entries.
+struct AtomProperty {
+ //! Has property been set.
+ bool isSet = false;
+ //! Number of properties.
+ int nprop = 0;
+ //! Max number of properties.
+ int maxprop = 0;
+ //! Database the property is coming from.
+ char *db = nullptr;
+ //! Default value for property.
+ double def = 0.0;
+ //! Array of names for atoms.
+ char **atomName = nullptr;
+ //! Array of names for residues.
+ char **residueName = nullptr;
+ //! Array of flags if property is available.
+ bool *isAvailable = nullptr;
+ //! Array of values for property.
+ real *value = nullptr;
+};
+
+//! Implementation detail type for Atomproperties.
+class AtomProperties::Impl
{
- int i;
+ public:
+ //! Should user be warned about error.
+ bool bWarned = false;
+ //! Should user be warned about vdW not found.
+ bool bWarnVDW = false;
+ //! The different atom properties.
+ AtomProperty prop[epropNR];
+ //! The residue types.
+ gmx_residuetype_t *restype = nullptr;
+};
- i = 0;
+/*! \brief
+ * Find number of matching characters in entry.
+ *
+ * If not all characters are matching, return NOTFOUND.
+ * If the length of the database entry is different from the search,
+ * also return NOTFOUND.
+ *
+ * \param[in] search Entry to compare to database.
+ * \param[in] database Name of the database entry to compare to.
+ * \returns Number of matching characters or NOTFOUND.
+ */
+static int findNumberOfMatches(const char *search, const char *database)
+{
+ int i = 0;
while (search[i] && database[i] && (search[i] == database[i]) )
{
i++;
return i;
}
-static int get_prop_index(aprop_t *ap, gmx_residuetype_t *restype,
- char *resnm, char *atomnm,
- gmx_bool *bExact)
+/*! \brief
+ * Finds the index for the property being searched.
+ *
+ * \param[in] ap Property to search for.
+ * \param[in] restype Residuetypes in database.
+ * \param[in] residueName The name of the residue to look for.
+ * \param[in] atomName The name of the atom to look for.
+ * \param[in] bExact Do we have the correct match.
+ * \returns The index for the property.
+ */
+static int findPropertyIndex(AtomProperty *ap, gmx_residuetype_t *restype,
+ char *residueName, char *atomName,
+ gmx_bool *bExact)
{
- int i, j = NOTFOUND;
- long int alen, rlen;
- long int malen, mrlen;
- gmx_bool bProtein, bProtWild;
-
- bProtein = gmx_residuetype_is_protein(restype, resnm);
- bProtWild = (strcmp(resnm, "AAA") == 0);
- malen = NOTFOUND;
- mrlen = NOTFOUND;
- for (i = 0; (i < ap->nprop); i++)
+ int j = NOTFOUND;
+
+ bool bProtein = gmx_residuetype_is_protein(restype, residueName);
+ bool bProtWild = (strcmp(residueName, "AAA") == 0);
+ int malen = NOTFOUND;
+ int mrlen = NOTFOUND;
+ for (int i = 0; (i < ap->nprop); i++)
{
- rlen = dbcmp_len(resnm, ap->resnm[i]);
+ int rlen = findNumberOfMatches(residueName, ap->residueName[i]);
if (rlen == NOTFOUND)
{
- if ( (strcmp(ap->resnm[i], "*") == 0) ||
- (strcmp(ap->resnm[i], "???") == 0) )
+ if ( (strcmp(ap->residueName[i], "*") == 0) ||
+ (strcmp(ap->residueName[i], "???") == 0) )
{
rlen = WILDCARD;
}
- else if (strcmp(ap->resnm[i], "AAA") == 0)
+ else if (strcmp(ap->residueName[i], "AAA") == 0)
{
rlen = WILDPROT;
}
}
- alen = dbcmp_len(atomnm, ap->atomnm[i]);
+ int alen = findNumberOfMatches(atomName, ap->atomName[i]);
if ( (alen > NOTFOUND) && (rlen > NOTFOUND))
{
if ( ( (alen > malen) && (rlen >= mrlen)) ||
}
}
- *bExact = ((malen == static_cast<long int>(strlen(atomnm))) &&
- ((mrlen == static_cast<long int>(strlen(resnm))) ||
+ *bExact = ((malen == static_cast<long int>(strlen(atomName))) &&
+ ((mrlen == static_cast<long int>(strlen(residueName))) ||
((mrlen == WILDPROT) && bProtWild) ||
((mrlen == WILDCARD) && !bProtein && !bProtWild)));
if (debug)
{
- fprintf(debug, "searching residue: %4s atom: %4s\n", resnm, atomnm);
+ fprintf(debug, "searching residue: %4s atom: %4s\n", residueName, atomName);
if (j == NOTFOUND)
{
fprintf(debug, " not successful\n");
}
else
{
- fprintf(debug, " match: %4s %4s\n", ap->resnm[j], ap->atomnm[j]);
+ fprintf(debug, " match: %4s %4s\n", ap->residueName[j], ap->atomName[j]);
}
}
return j;
}
-static void add_prop(aprop_t *ap, gmx_residuetype_t *restype,
- char *resnm, char *atomnm,
- real p, int line)
+/*! \brief
+ * Add new property to list.
+ *
+ * \param[in] ap Atomproperty to add.
+ * \param[in] restype Residue type database to use.
+ * \param[in] residueName Name of the residue.
+ * \param[in] atomName Name of the atom.
+ * \param[in] propValue Value of property.
+ * \param[in] line Where to add property.
+ */
+static void addProperty(AtomProperty *ap, gmx_residuetype_t *restype,
+ char *residueName, char *atomName,
+ real propValue, int line)
{
- int i, j;
- gmx_bool bExact;
-
- j = get_prop_index(ap, restype, resnm, atomnm, &bExact);
+ bool bExact;
+ int j = findPropertyIndex(ap, restype, residueName, atomName, &bExact);
if (!bExact)
{
if (ap->nprop >= ap->maxprop)
{
ap->maxprop += 10;
- srenew(ap->resnm, ap->maxprop);
- srenew(ap->atomnm, ap->maxprop);
+ srenew(ap->residueName, ap->maxprop);
+ srenew(ap->atomName, ap->maxprop);
srenew(ap->value, ap->maxprop);
- srenew(ap->bAvail, ap->maxprop);
- for (i = ap->nprop; (i < ap->maxprop); i++)
+ srenew(ap->isAvailable, ap->maxprop);
+ for (int i = ap->nprop; (i < ap->maxprop); i++)
{
- ap->atomnm[i] = nullptr;
- ap->resnm[i] = nullptr;
- ap->value[i] = 0;
- ap->bAvail[i] = FALSE;
+ ap->atomName[i] = nullptr;
+ ap->residueName[i] = nullptr;
+ ap->value[i] = 0;
+ ap->isAvailable[i] = FALSE;
}
}
- ap->atomnm[ap->nprop] = gmx_strdup(atomnm);
- ap->resnm[ap->nprop] = gmx_strdup(resnm);
- j = ap->nprop;
+ ap->atomName[ap->nprop] = gmx_strdup(atomName);
+ ap->residueName[ap->nprop] = gmx_strdup(residueName);
+ j = ap->nprop;
ap->nprop++;
}
- if (ap->bAvail[j])
+ if (ap->isAvailable[j])
{
- if (ap->value[j] == p)
+ if (ap->value[j] == propValue)
{
fprintf(stderr, "Warning double identical entries for %s %s %g on line %d in file %s\n",
- resnm, atomnm, p, line, ap->db);
+ residueName, atomName, propValue, line, ap->db);
}
else
{
fprintf(stderr, "Warning double different entries %s %s %g and %g on line %d in file %s\n"
"Using last entry (%g)\n",
- resnm, atomnm, p, ap->value[j], line, ap->db, p);
- ap->value[j] = p;
+ residueName, atomName, propValue, ap->value[j], line, ap->db, propValue);
+ ap->value[j] = propValue;
}
}
else
{
- ap->bAvail[j] = TRUE;
- ap->value[j] = p;
+ ap->isAvailable[j] = TRUE;
+ ap->value[j] = propValue;
}
}
-static void read_prop(gmx_atomprop_t aps, int eprop, double factor)
+/*! \brief
+ * Read property value into structure.
+ *
+ * \param[in] ap Atomproperty to be read in.
+ * \param[in] restype Library of residue types.
+ * \param[in] factor Scaling factor for property.
+ */
+static void readProperty(AtomProperty *ap, gmx_residuetype_t *restype, double factor)
{
- gmx_atomprop *ap2 = static_cast<gmx_atomprop*>(aps);
char line[STRLEN], resnm[32], atomnm[32];
- double pp;
- int line_no;
- aprop_t *ap;
-
- ap = &ap2->prop[eprop];
- gmx::FilePtr fp = gmx::openLibraryFile(ap->db);
- line_no = 0;
+ gmx::FilePtr fp = gmx::openLibraryFile(ap->db);
+ int line_no = 0;
while (get_a_line(fp.get(), line, STRLEN))
{
line_no++;
+ double pp;
if (sscanf(line, "%31s %31s %20lf", resnm, atomnm, &pp) == 3)
{
pp *= factor;
- add_prop(ap, aps->restype, resnm, atomnm, pp, line_no);
+ addProperty(ap, restype, resnm, atomnm, pp, line_no);
}
else
{
ap->db, line_no);
}
}
- ap->bSet = TRUE;
+ ap->isSet = TRUE;
}
-static void set_prop(gmx_atomprop_t aps, int eprop)
+/*! \brief
+ * Set value for properties.
+ *
+ * \param[in] ap Atomproperty to set.
+ * \param[in] restype Library of residue types.
+ * \param[in] eprop Which property to set.
+ * \param[in] haveBeenWarned If we already set a warning before
+ * \returns True of warning should be printed.
+ */
+static bool setProperties(AtomProperty *ap, gmx_residuetype_t *restype, int eprop, bool haveBeenWarned)
{
- gmx_atomprop *ap2 = static_cast<gmx_atomprop*>(aps);
- const char *fns[epropNR] = { "atommass.dat", "vdwradii.dat", "dgsolv.dat", "electroneg.dat", "elements.dat" };
- double fac[epropNR] = { 1.0, 1.0, 418.4, 1.0, 1.0 };
- double def[epropNR] = { 12.011, 0.14, 0.0, 2.2, -1 };
- aprop_t *ap;
-
- ap = &ap2->prop[eprop];
- if (!ap->bSet)
+ const char *fns[epropNR] = { "atommass.dat", "vdwradii.dat", "dgsolv.dat", "electroneg.dat", "elements.dat" };
+ double fac[epropNR] = { 1.0, 1.0, 418.4, 1.0, 1.0 };
+ double def[epropNR] = { 12.011, 0.14, 0.0, 2.2, -1 };
+
+ bool printWarning = false;
+ if (!ap->isSet)
{
ap->db = gmx_strdup(fns[eprop]);
ap->def = def[eprop];
- read_prop(aps, eprop, fac[eprop]);
+ readProperty(ap, restype, fac[eprop]);
if (debug)
{
fprintf(debug, "Entries in %s: %d\n", ap->db, ap->nprop);
}
- if ( ( (!aps->bWarned) && (eprop == epropMass) ) || (eprop == epropVDW))
+ if ( (!haveBeenWarned && (eprop == epropMass) ) || (eprop == epropVDW))
{
- printf("\n"
- "WARNING: Masses and atomic (Van der Waals) radii will be guessed\n"
- " based on residue and atom names, since they could not be\n"
- " definitively assigned from the information in your input\n"
- " files. These guessed numbers might deviate from the mass\n"
- " and radius of the atom type. Please check the output\n"
- " files if necessary.\n\n");
- aps->bWarned = TRUE;
+ printWarning = true;
}
+
}
+ return printWarning;
}
-gmx_atomprop_t gmx_atomprop_init()
+AtomProperties::AtomProperties()
+ : impl_(new Impl)
{
- gmx_atomprop *aps;
-
- snew(aps, 1);
-
- gmx_residuetype_init(&aps->restype);
- aps->bWarned = FALSE;
- aps->bWarnVDW = FALSE;
-
- return static_cast<gmx_atomprop_t>(aps);
+ gmx_residuetype_init(&impl_->restype);
}
-static void destroy_prop(aprop_t *ap)
+static void destroy_prop(AtomProperty *ap)
{
- int i;
-
- if (ap->bSet)
+ if (ap->isSet)
{
sfree(ap->db);
- for (i = 0; i < ap->nprop; i++)
+ for (int i = 0; i < ap->nprop; i++)
{
- sfree(ap->atomnm[i]);
- sfree(ap->resnm[i]);
+ sfree(ap->atomName[i]);
+ sfree(ap->residueName[i]);
}
- sfree(ap->atomnm);
- sfree(ap->resnm);
- sfree(ap->bAvail);
+ sfree(ap->atomName);
+ sfree(ap->residueName);
+ sfree(ap->isAvailable);
sfree(ap->value);
}
}
-void gmx_atomprop_destroy(gmx_atomprop_t aps)
+AtomProperties::~AtomProperties()
{
- gmx_atomprop *ap = static_cast<gmx_atomprop*>(aps);
- int p;
-
- if (aps == nullptr)
+ for (int p = 0; p < epropNR; p++)
{
- printf("\nWARNING: gmx_atomprop_destroy called with a NULL pointer\n\n");
- return;
+ destroy_prop(&impl_->prop[p]);
}
+ gmx_residuetype_destroy(impl_->restype);
+}
- for (p = 0; p < epropNR; p++)
- {
- destroy_prop(&ap->prop[p]);
- }
+AtomProperty *AtomProperties::prop(int eprop)
+{
+ return &impl_->prop[eprop];
+}
- gmx_residuetype_destroy(ap->restype);
+gmx_residuetype_t *AtomProperties::restype()
+{
+ return impl_->restype;
+}
- sfree(ap);
+//! Print warning about vdW to terminal.
+static void printWarning()
+{
+ printf("\n"
+ "WARNING: Masses and atomic (Van der Waals) radii will be guessed\n"
+ " based on residue and atom names, since they could not be\n"
+ " definitively assigned from the information in your input\n"
+ " files. These guessed numbers might deviate from the mass\n"
+ " and radius of the atom type. Please check the output\n"
+ " files if necessary.\n\n");
}
-static void vdw_warning(FILE *fp)
+static void printvdwWarning(FILE *fp)
{
if (nullptr != fp)
{
}
}
-gmx_bool gmx_atomprop_query(gmx_atomprop_t aps,
- int eprop, const char *resnm, const char *atomnm,
- real *value)
+bool AtomProperties::setAtomProperty(int eprop,
+ const char *residueName,
+ const char *atomName,
+ real *value)
{
- gmx_atomprop *ap = static_cast<gmx_atomprop*>(aps);
- int j;
+ int j;
#define MAXQ 32
- char atomname[MAXQ], resname[MAXQ];
- gmx_bool bExact;
+ char atomname[MAXQ], resname[MAXQ];
+ bool bExact;
- set_prop(aps, eprop);
- if ((strlen(atomnm) > MAXQ-1) || (strlen(resnm) > MAXQ-1))
+ if (setProperties(prop(eprop), restype(), eprop, impl_->bWarned))
+ {
+ printWarning();
+ impl_->bWarned = true;
+ }
+ if ((strlen(atomName) > MAXQ-1) || (strlen(residueName) > MAXQ-1))
{
if (debug)
{
MAXQ-1);
}
}
- if (isdigit(atomnm[0]))
+ if (isdigit(atomName[0]))
{
int i;
/* put digit after atomname */
- for (i = 1; i < MAXQ-1 && atomnm[i] != '\0'; i++)
+ for (i = 1; i < MAXQ-1 && atomName[i] != '\0'; i++)
{
- atomname[i-1] = atomnm[i];
+ atomname[i-1] = atomName[i];
}
- atomname[i-1] = atomnm[0];
+ atomname[i-1] = atomName[0];
atomname[i] = '\0';
}
else
{
- strncpy(atomname, atomnm, MAXQ-1);
+ strncpy(atomname, atomName, MAXQ-1);
}
- strncpy(resname, resnm, MAXQ-1);
+ strncpy(resname, residueName, MAXQ-1);
- j = get_prop_index(&(ap->prop[eprop]), ap->restype, resname,
- atomname, &bExact);
+ j = findPropertyIndex(&(impl_->prop[eprop]), impl_->restype, resname,
+ atomname, &bExact);
- if (eprop == epropVDW && !ap->bWarnVDW)
+ if (eprop == epropVDW && !impl_->bWarnVDW)
{
- vdw_warning(stdout);
- ap->bWarnVDW = TRUE;
+ printvdwWarning(stdout);
+ impl_->bWarnVDW = true;
}
if (j >= 0)
{
- *value = ap->prop[eprop].value[j];
- return TRUE;
+ *value = impl_->prop[eprop].value[j];
+ return true;
}
else
{
- *value = ap->prop[eprop].def;
- return FALSE;
+ *value = impl_->prop[eprop].def;
+ return false;
}
}
-char *gmx_atomprop_element(gmx_atomprop_t aps, int atomnumber)
-{
- gmx_atomprop *ap = static_cast<gmx_atomprop*>(aps);
- int i;
- set_prop(aps, epropElement);
- for (i = 0; (i < ap->prop[epropElement].nprop); i++)
+const char *AtomProperties::elementFromAtomNumber(int atomNumber)
+{
+ if (setProperties(prop(epropElement), restype(), epropElement, impl_->bWarned))
{
- if (std::round(ap->prop[epropElement].value[i]) == atomnumber)
+ printWarning();
+ impl_->bWarned = true;
+ }
+ for (int i = 0; (i < impl_->prop[epropElement].nprop); i++)
+ {
+ if (std::round(impl_->prop[epropElement].value[i]) == atomNumber)
{
- return ap->prop[epropElement].atomnm[i];
+ return impl_->prop[epropElement].atomName[i];
}
}
return nullptr;
}
-int gmx_atomprop_atomnumber(gmx_atomprop_t aps, const char *elem)
+int AtomProperties::atomNumberFromElement(const char *element)
{
- gmx_atomprop *ap = static_cast<gmx_atomprop*>(aps);
- int i;
-
- set_prop(aps, epropElement);
- for (i = 0; (i < ap->prop[epropElement].nprop); i++)
+ if (setProperties(prop(epropElement), restype(), epropElement, impl_->bWarned))
+ {
+ printWarning();
+ impl_->bWarned = true;
+ }
+ for (int i = 0; (i < impl_->prop[epropElement].nprop); i++)
{
- if (gmx_strcasecmp(ap->prop[epropElement].atomnm[i], elem) == 0)
+ if (gmx_strcasecmp(impl_->prop[epropElement].atomName[i], element) == 0)
{
- return gmx::roundToInt(ap->prop[epropElement].value[i]);
+ return gmx::roundToInt(impl_->prop[epropElement].value[i]);
}
}
return -1;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
- * Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2010,2014,2018, by the GROMACS development team, led by
+ * Copyright (c) 2019, 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.
#define GMX_TOPOLOGY_ATOMPROP_H
#include "gromacs/utility/basedefinitions.h"
+#include "gromacs/utility/classhelpers.h"
#include "gromacs/utility/real.h"
-/* Abstract type for the atom property database */
-typedef struct gmx_atomprop *gmx_atomprop_t;
-
enum {
epropMass, epropVDW, epropDGsol, epropElectroneg, epropElement,
epropNR
};
-gmx_atomprop_t gmx_atomprop_init();
-/* Initializes and returns the atom properties struct */
-
-void gmx_atomprop_destroy(gmx_atomprop_t aps);
-/* Get rid of memory after use */
+struct AtomProperty;
+struct gmx_residuetype_t;
+/*! \brief
+ * Holds all the atom property information loaded.
+ */
+class AtomProperties
+{
+ public:
+ //! Default constructor.
+ AtomProperties();
+ //! Default destructor
+ ~AtomProperties();
-char *gmx_atomprop_element(gmx_atomprop_t aps, int atomnumber);
+ /*! \brief
+ * Get element string from atom number.
+ *
+ * \param[in] atomNumber Atomnumber to check.
+ * \returns Name of the element.
+ *
+ * \todo This should be made const once the lazy
+ * implementation is done properly for the class.
+ */
+ const char *elementFromAtomNumber(int atomNumber);
+ /*! \brief
+ * Get atom number from element string.
+ *
+ * \param[in] element Name of element.
+ * \returns AtomNumber that was being looked for.
+ *
+ * \todo This should be made const once the lazy
+ * implementation is done properly for the class.
+ */
+ int atomNumberFromElement(const char *element);
+ /*! \brief
+ * Set atom property based on atomname.
+ *
+ * Extract a \p value from the database. Returns true
+ * if this is successful, or false if not. Sets default value
+ * in the later case. The first time this function is called
+ * for this property the database will be initialized.
+ *
+ * \param[in] eprop Property to set.
+ * \param[in] residueName Residue name for entry.
+ * \param[in] atomName Atom name for entry.
+ * \param[out] value New value to set or default.
+ * \returns If the operation has been succesful.
+ */
+ bool setAtomProperty(int eprop,
+ const char* residueName,
+ const char* atomName,
+ real *value);
+ /*! \brief
+ * Get handle to property.
+ *
+ * \param[in] eprop Which property we need a handle to.
+ * \returns Pointer to property entry.
+ */
+ AtomProperty *prop(int eprop);
+ //! Get handle to residuetype library.
+ gmx_residuetype_t *restype();
-int gmx_atomprop_atomnumber(gmx_atomprop_t aps, const char *element);
+ private:
+ //! Implementation pointer.
+ class Impl;
-gmx_bool gmx_atomprop_query(gmx_atomprop_t aps,
- int eprop, const char *resnm, const char *atomnm,
- real *value);
-/* Extract a value from the database. Returns TRUE on succes,
- * FALSE otherwise. In the latter case, value is a deafult value.
- * The first time this function is called for this property
- * the database will be read.
- */
+ gmx::PrivateImplPointer<Impl> impl_;
+};
#endif
int maxWarn = (printMissingMasses ? 10 : 0);
int numWarn = 0;
- gmx_atomprop_t aps = gmx_atomprop_init();
+ AtomProperties aps;
- gmx_bool haveMass = TRUE;
+ bool haveMass = true;
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 (!aps.setAtomProperty(epropMass,
+ *atoms->resinfo[atoms->atom[i].resind].name,
+ *atoms->atomname[i],
+ &atoms->atom[i].m))
{
- haveMass = FALSE;
+ haveMass = false;
if (numWarn < maxWarn)
{
}
}
atoms->haveMass = haveMass;
-
- gmx_atomprop_destroy(aps);
}
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2018,2019, 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.
// Initiate variable
cutoff_ = 0;
int nnovdw = 0;
- gmx_atomprop_t aps = gmx_atomprop_init();
+ AtomProperties aps;
auto atoms = top.copyAtoms();
// Compute total mass
// Lookup the Van der Waals radius of this atom
int resnr = atoms->atom[i].resind;
- if (gmx_atomprop_query(aps, epropVDW,
- *(atoms->resinfo[resnr].name),
- *(atoms->atomname[i]),
- &value))
+ if (aps.setAtomProperty(epropVDW,
+ *(atoms->resinfo[resnr].name),
+ *(atoms->atomname[i]),
+ &value))
{
vdw_radius_.push_back(value);
if (value > cutoff_)
vdw_radius_.push_back(0.0);
}
}
- gmx_atomprop_destroy(aps);
// Increase cutoff by proberadius to make sure we do not miss
// anything
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2006, The GROMACS development team.
- * Copyright (c) 2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by
+ * Copyright (c) 2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019, 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.
// TODO: Not exception-safe, but nice solution would be to have a C++
// atom properties class...
- gmx_atomprop_t aps = gmx_atomprop_init();
+ AtomProperties aps;
ArrayRef<const int> atomIndices = surfaceSel_.atomIndices();
int ndefault = 0;
const int ii = atomIndices[i];
const int resind = atoms_->atom[ii].resind;
real radius;
- if (!gmx_atomprop_query(aps, epropVDW,
- *(atoms_->resinfo[resind].name),
- *(atoms_->atomname[ii]), &radius))
+ if (!aps.setAtomProperty(epropVDW,
+ *(atoms_->resinfo[resind].name),
+ *(atoms_->atomname[ii]), &radius))
{
ndefault++;
}
if (bDGsol)
{
real dgsFactor;
- if (!gmx_atomprop_query(aps, epropDGsol,
- *(atoms_->resinfo[resind].name),
- *(atoms_->atomtype[ii]), &dgsFactor))
+ if (!aps.setAtomProperty(epropDGsol,
+ *(atoms_->resinfo[resind].name),
+ *(atoms_->atomtype[ii]), &dgsFactor))
{
dgsFactor = dgsDefault_;
}
{
fprintf(stderr, "WARNING: could not find a Van der Waals radius for %d atoms\n", ndefault);
}
- gmx_atomprop_destroy(aps);
// Pre-compute mapping from the output groups to the calculation group,
// and store it in the selection ID map for easy lookup.
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2019, 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.
#define XTextHeight(font) ((font)->max_bounds.ascent+(font)->max_bounds.descent)
#define XDrawCircle(disp, win, gc, x, y, rad) \
- XDrawArc(disp, win, gc, x-rad, y-rad, 2*rad, 2*rad, 0, 64*360)
+ XDrawArc(disp, win, gc, (x)-(rad), (y)-(rad), 2*(rad), 2*(rad), 0, 64*360)
#define XFillCircle(disp, win, gc, x, y, rad) \
- XFillArc(disp, win, gc, x-rad, y-rad, 2*rad, 2*rad, 0, 64*360)
+ XFillArc(disp, win, gc, (x)-(rad), (y)-(rad), 2*(rad), 2*(rad), 0, 64*360)
#ifdef NEED_XSTUFF
*
* Copyright (c) 1991-2000, University of Groningen, The Netherlands.
* Copyright (c) 2001-2004, The GROMACS development team.
- * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by
+ * Copyright (c) 2013,2014,2015,2016,2017,2019, 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.
man->obj[man->nobj-1].z = 0.0;
}
-static void add_bonds(t_manager *man, t_functype func[],
+static void add_bonds(t_manager *man, const t_functype func[],
t_ilist *b, bool bB[])
{
bool *bH = man->bHydro;
{
if (man->bVis[i])
{
- return (int) i;
+ return i;
}
}
}
void set_file(t_x11 *x11, t_manager *man, const char *trajectory,
const char *status)
{
- gmx_atomprop_t aps;
t_tpxheader sh;
t_atoms *at;
bool *bB;
man->title.text = gmx_strdup(gmx::formatString("%s: %s", *man->top.name, gmx::getCoolQuote().c_str()).c_str());
man->view = init_view(man->box);
at = &(man->top.atoms);
- aps = gmx_atomprop_init();
+ AtomProperties aps;
for (i = 0; (i < man->natom); i++)
{
char *aname = *(at->atomname[i]);
{
man->vdw[i] = 0;
}
- else if (!gmx_atomprop_query(aps, epropVDW, *ri->name, aname, &(man->vdw[i])))
+ else if (!aps.setAtomProperty(epropVDW, *ri->name, aname, &(man->vdw[i])))
{
man->vdw[i] = 0;
}
}
- gmx_atomprop_destroy(aps);
add_bpl(man, &(man->top.idef), bB);
for (i = 0; (i < man->natom); i++)
{
if (!bB[i])
{
- add_object(man, eOSingle, (int) i, 0);
+ add_object(man, eOSingle, i, 0);
}
}
sfree(bB);
return bEof;
}
-static void HandleClient(t_x11 *x11, t_manager *man, long data[])
+static void HandleClient(t_x11 *x11, t_manager *man, const long data[])
{
int ID, button, x, y;
bool bPos;
*
* 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,2019, 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.
extern void map_man(t_x11 *x11, t_manager *man);
-extern void move_man(t_x11 *x11, t_manager *man, int width, int height);
+
extern bool toggle_animate (t_x11 *x11, t_manager *man);