#include "solvate.h"
-#include <string.h>
+#include <cstring>
#include <algorithm>
#include <vector>
int res0;
} t_moltypes;
-static void sort_molecule(t_atoms **atoms_solvt, std::vector<RVec> *x,
+static void sort_molecule(t_atoms **atoms_solvt,
+ t_atoms **newatoms,
+ std::vector<RVec> *x,
std::vector<RVec> *v)
{
int atnr, i, j, moltp = 0, nrmoltypes, resi_o, resi_n, resnr;
t_moltypes *moltypes;
- t_atoms *atoms, *newatoms;
+ t_atoms *atoms;
fprintf(stderr, "Sorting configuration\n");
moltp = -1;
for (j = 0; (j < nrmoltypes) && (moltp == -1); j++)
{
- /* cppcheck-suppress nullPointer
- * moltypes is guaranteed to be allocated because otherwise
+ /* moltypes is guaranteed to be allocated because otherwise
* nrmoltypes is 0. */
if (strcmp(*(atoms->resinfo[atoms->atom[i].resind].name), moltypes[j].name) == 0)
{
}
/* now put them there: */
- snew(newatoms, 1);
- init_t_atoms(newatoms, atoms->nr, FALSE);
- newatoms->nres = atoms->nres;
- snew(newatoms->resinfo, atoms->nres);
+ snew(*newatoms, 1);
+ init_t_atoms(*newatoms, atoms->nr, FALSE);
+ (*newatoms)->nres = atoms->nres;
+ srenew((*newatoms)->resinfo, atoms->nres);
std::vector<RVec> newx(x->size());
std::vector<RVec> newv(v->size());
if (strcmp(*atoms->resinfo[resi_o].name, moltypes[moltp].name) == 0)
{
/* Copy the residue info */
- newatoms->resinfo[resi_n] = atoms->resinfo[resi_o];
- newatoms->resinfo[resi_n].nr = resnr;
+ (*newatoms)->resinfo[resi_n] = atoms->resinfo[resi_o];
+ (*newatoms)->resinfo[resi_n].nr = resnr;
/* Copy the atom info */
do
{
- newatoms->atom[j] = atoms->atom[i];
- newatoms->atomname[j] = atoms->atomname[i];
- newatoms->atom[j].resind = resi_n;
+ (*newatoms)->atom[j] = atoms->atom[i];
+ (*newatoms)->atomname[j] = atoms->atomname[i];
+ (*newatoms)->atom[j].resind = resi_n;
copy_rvec((*x)[i], newx[j]);
if (!v->empty())
{
/* put them back into the original arrays and throw away temporary arrays */
done_atom(atoms);
- *atoms_solvt = newatoms;
+ *atoms_solvt = (*newatoms);
std::swap(*x, newx);
std::swap(*v, newv);
}
}
/* Sort the solvent mixture, not the protein... */
- sort_molecule(&atoms_solvt, &x_solvt, &v_solvt);
+ t_atoms *newatoms = nullptr;
+ sort_molecule(&atoms_solvt, &newatoms, &x_solvt, &v_solvt);
// Merge the two configurations.
x->insert(x->end(), x_solvt.begin(), x_solvt.end());
done_top(top_solvt);
sfree(top_solvt);
+ if (newatoms)
+ {
+ done_atom(newatoms);
+ sfree(newatoms);
+ }
}
static void update_top(t_atoms *atoms, int firstSolventResidueIndex, matrix box, int NFILE, t_filenm fnm[],
char buf[STRLEN], buf2[STRLEN], *temp;
const char *topinout;
int line;
- gmx_bool bSystem;
+ bool bSystem;
int i;
double mtot;
real vol, mm;
- int nsol = atoms->nres - firstSolventResidueIndex;
+ int nsol = atoms->nres - firstSolventResidueIndex;
- mtot = 0;
+ mtot = 0;
for (i = 0; (i < atoms->nr); i++)
{
gmx_atomprop_query(aps, epropMass,
fpin = gmx_ffopen(topinout, "r");
fpout = gmx_fopen_temporary(temporary_filename);
line = 0;
- bSystem = FALSE;
+ bSystem = false;
while (fgets(buf, STRLEN, fpin))
{
line++;
if (buf2[0] && (!strstr(buf2, " water")) )
{
sprintf(buf, "%s in water\n", buf2);
- bSystem = FALSE;
+ bSystem = false;
}
}
fprintf(fpout, "%s", buf);
// Iterate through solvent molecules and increment a count until new resname found
for (int i = firstSolventResidueIndex; i < atoms->nres; i++)
{
- if ((currRes.compare(*atoms->resinfo[i].name) == 0))
+ if ((currRes == *atoms->resinfo[i].name))
{
resCount += 1;
}
done_top(top);
sfree(top);
output_env_done(oenv);
- done_filenms(NFILE, fnm);
return 0;
}