From: Rossen Apostolov Date: Wed, 3 Sep 2014 13:54:35 +0000 (+0200) Subject: Converted pulling code to C++. X-Git-Url: http://biod.pnpi.spb.ru/gitweb/?a=commitdiff_plain;h=98f8274fca4745d9311d625ed74233d67f12f0e9;p=alexxy%2Fgromacs.git Converted pulling code to C++. Removed unused variables and changed some pointers to const char. Added some static_cast to make explicit the old casting behaviour. Added a missing default clause in pull code Change-Id: I14708cf15799c564b77e466d73a9e8bc4488d192 --- diff --git a/src/gromacs/pulling/CMakeLists.txt b/src/gromacs/pulling/CMakeLists.txt index 9c9f21883d..afac1ee686 100644 --- a/src/gromacs/pulling/CMakeLists.txt +++ b/src/gromacs/pulling/CMakeLists.txt @@ -1,7 +1,7 @@ # # 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. @@ -32,7 +32,7 @@ # To help us fund GROMACS development, we humbly ask that you cite # the research papers on the package. Check out http://www.gromacs.org. -file(GLOB PULLING_SOURCES *.cpp *.c) +file(GLOB PULLING_SOURCES *.cpp) set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${PULLING_SOURCES} PARENT_SCOPE) if (BUILD_TESTING) diff --git a/src/gromacs/pulling/pull.c b/src/gromacs/pulling/pull.cpp similarity index 99% rename from src/gromacs/pulling/pull.c rename to src/gromacs/pulling/pull.cpp index a252388ef5..a1960ea9d7 100644 --- a/src/gromacs/pulling/pull.c +++ b/src/gromacs/pulling/pull.cpp @@ -43,6 +43,8 @@ #include #include +#include + #include "gromacs/fileio/filenm.h" #include "gromacs/fileio/gmxfio.h" #include "gromacs/fileio/xvgr.h" @@ -431,7 +433,7 @@ static double max_pull_distance2(const t_pull_coord *pcrd, const t_pbc *pbc) { if (pcrd->dim[m] != 0) { - max_d2 = min(max_d2, norm2(pbc->box[m])); + max_d2 = std::min(max_d2, static_cast(norm2(pbc->box[m]))); } } @@ -447,13 +449,12 @@ static void low_get_pull_coord_dr(const t_pull *pull, dvec xg, dvec xref, double max_dist2, dvec dr) { - const t_pull_group *pgrp0, *pgrp1; + const t_pull_group *pgrp0; int m; dvec xrefr, dref = {0, 0, 0}; double dr2; pgrp0 = &pull->group[pcrd->group[0]]; - pgrp1 = &pull->group[pcrd->group[1]]; /* Only the first group can be an absolute reference, in that case nat=0 */ if (pgrp0->nat == 0) @@ -522,7 +523,6 @@ static void get_pull_coord_dr(t_pull *pull, const t_pull_group *pgrp2, *pgrp3; dvec vec; int m; - double invlen; pgrp2 = &pull->group[pcrd->group[2]]; pgrp3 = &pull->group[pcrd->group[3]]; @@ -692,7 +692,6 @@ static void do_constraint(t_pull *pull, t_pbc *pbc, gmx_bool bConverged_all, bConverged = FALSE; int niter = 0, g, c, ii, j, m, max_iter = 100; double a; - dvec f; /* the pull force */ dvec tmp, tmp3; t_pull_group *pgrp0, *pgrp1; t_pull_coord *pcrd; @@ -853,6 +852,11 @@ static void do_constraint(t_pull *pull, t_pbc *pbc, dsvmul( lambda*rm*pgrp0->invtm, vec, dr0); dr_tot[c] += -lambda; break; + default: + gmx_incons("Invalid enumeration value for eGeom"); + /* Keep static analyzer happy */ + clear_dvec(dr0); + clear_dvec(dr1); } /* DEBUG */ diff --git a/src/gromacs/pulling/pull_rotation.c b/src/gromacs/pulling/pull_rotation.cpp similarity index 99% rename from src/gromacs/pulling/pull_rotation.c rename to src/gromacs/pulling/pull_rotation.cpp index 5b7358a761..187fef017f 100644 --- a/src/gromacs/pulling/pull_rotation.c +++ b/src/gromacs/pulling/pull_rotation.cpp @@ -3,7 +3,7 @@ * * Copyright (c) 1991-2000, University of Groningen, The Netherlands. * Copyright (c) 2001-2008, The GROMACS development team. - * Copyright (c) 2013,2014, by the GROMACS development team, led by + * Copyright (c) 2013,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. @@ -44,6 +44,8 @@ #include #include +#include + #include "gromacs/domdec/domdec.h" #include "gromacs/fileio/gmxfio.h" #include "gromacs/fileio/trnio.h" @@ -67,7 +69,7 @@ #include "gromacs/utility/qsort_threadsafe.h" #include "gromacs/utility/smalloc.h" -static char *RotStr = {"Enforced rotation:"}; +static char const *RotStr = {"Enforced rotation:"}; /* Set the minimum weight for the determination of the slab centers */ #define WEIGHT_MIN (10*GMX_FLOAT_MIN) @@ -594,16 +596,11 @@ static real get_slab_weight(int j, t_rotgrp *rotg, rvec xc[], real mc[], rvec *x real gaussian; /* A single gaussian weight */ real wgauss; /* gaussian times current mass */ real slabweight = 0.0; /* The sum of weights in the slab */ - int i, islab; - gmx_enfrotgrp_t erg; /* Pointer to enforced rotation group data */ + int i; - erg = rotg->enfrotgrp; clear_rvec(*x_weighted_sum); - /* Slab index */ - islab = j - erg->slab_first; - /* Loop over all atoms in the rotation group */ for (i = 0; i < rotg->nat; i++) { @@ -633,6 +630,7 @@ static void get_slab_centers( init_rot_group we need to store the reference slab centers */ { + /* Slab index */ int j, islab; gmx_enfrotgrp_t erg; /* Pointer to enforced rotation group data */ @@ -754,14 +752,14 @@ static gmx_inline real torque( /* Right-aligned output of value with standard width */ -static void print_aligned(FILE *fp, char *str) +static void print_aligned(FILE *fp, char const *str) { fprintf(fp, "%12s", str); } /* Right-aligned output of value with standard short width */ -static void print_aligned_short(FILE *fp, char *str) +static void print_aligned_short(FILE *fp, char const *str) { fprintf(fp, "%6s", str); } @@ -937,7 +935,6 @@ static FILE *open_rot_out(const char *fn, t_rot *rot, const output_env_t oenv) for (g = 0; g < rot->ngrp; g++) { - rotg = &rot->grp[g]; sprintf(buf, "theta_ref%d", g); add_to_string_aligned(&LegendStr, buf); @@ -2469,7 +2466,7 @@ static gmx_inline int get_first_slab( rvec firstatom) /* First atom after sorting along the rotation vector v */ { /* Find the first slab for the first atom */ - return ceil((iprod(firstatom, rotg->vec) - max_beta)/rotg->slab_dist); + return static_cast(ceil(static_cast((iprod(firstatom, rotg->vec) - max_beta)/rotg->slab_dist))); } @@ -2479,7 +2476,7 @@ static gmx_inline int get_last_slab( rvec lastatom) /* Last atom along v */ { /* Find the last slab for the last atom */ - return floor((iprod(lastatom, rotg->vec) + max_beta)/rotg->slab_dist); + return static_cast(floor(static_cast((iprod(lastatom, rotg->vec) + max_beta)/rotg->slab_dist))); } @@ -3009,7 +3006,7 @@ static void radial_motion2_precalc_inner_sum(t_rotgrp *rotg, rvec innersumvec) gmx_enfrotgrp_t erg; /* Pointer to enforced rotation group data */ rvec xi_xc; /* xj - xc */ rvec tmpvec, tmpvec2; - real fac, fac2; + real fac; rvec ri, si; real siri; rvec v_xi_xc; /* v x (xj - u) */ @@ -3047,10 +3044,7 @@ static void radial_motion2_precalc_inner_sum(t_rotgrp *rotg, rvec innersumvec) svmul(psii, v_xi_xc, si); /* si = psii * (v x (xi-xc) ) */ - fac = iprod(v_xi_xc, ri); /* fac = (v x (xi-xc)).ri */ - fac2 = fac*fac; - - siri = iprod(si, ri); /* siri = si.ri */ + siri = iprod(si, ri); /* siri = si.ri */ svmul(psiistar/psii, ri, tmpvec); svmul(psiistar*psiistar/(psii*psii*psii) * siri, si, tmpvec2); @@ -3232,7 +3226,6 @@ static void get_firstlast_atom_ref( int *firstindex, int *lastindex) { - gmx_enfrotgrp_t erg; /* Pointer to enforced rotation group data */ int i; real xcproj; /* The projection of a reference position on the rotation vector */ @@ -3240,8 +3233,6 @@ static void get_firstlast_atom_ref( - erg = rotg->enfrotgrp; - /* Start with some value */ minproj = iprod(rotg->x_ref[0], rotg->vec); maxproj = minproj; @@ -3756,7 +3747,7 @@ extern void init_rot(FILE *fplog, t_inputrec *ir, int nfile, const t_filenm fnm[ snew(rotg->enfrotgrp, 1); erg = rotg->enfrotgrp; - nat_max = max(nat_max, rotg->nat); + nat_max = std::max(nat_max, rotg->nat); if (PAR(cr)) { @@ -3913,7 +3904,7 @@ extern void do_rotation( t_rot *rot; t_rotgrp *rotg; gmx_bool outstep_slab, outstep_rot; - gmx_bool bFlex, bColl; + gmx_bool bColl; gmx_enfrot_t er; /* Pointer to the enforced rotation buffer variables */ gmx_enfrotgrp_t erg; /* Pointer to enforced rotation group data */ rvec transvec; @@ -3950,8 +3941,6 @@ extern void do_rotation( rotg = &rot->grp[g]; erg = rotg->enfrotgrp; - /* Do we have a flexible axis? */ - bFlex = ISFLEX(rotg); /* Do we use a collective (global) set of coordinates? */ bColl = ISCOLL(rotg); @@ -4011,9 +4000,6 @@ extern void do_rotation( rotg = &rot->grp[g]; erg = rotg->enfrotgrp; - bFlex = ISFLEX(rotg); - bColl = ISCOLL(rotg); - if (outstep_rot && MASTER(cr)) { fprintf(er->out_rot, "%12.4f", erg->degangle); diff --git a/src/gromacs/pulling/pullutil.c b/src/gromacs/pulling/pullutil.cpp similarity index 99% rename from src/gromacs/pulling/pullutil.c rename to src/gromacs/pulling/pullutil.cpp index abfcda8ae6..852acc9521 100644 --- a/src/gromacs/pulling/pullutil.c +++ b/src/gromacs/pulling/pullutil.cpp @@ -80,7 +80,7 @@ static void pull_set_pbcatoms(t_commrec *cr, t_pull *pull, rvec *x, rvec *x_pbc) { - int g, n, m; + int g, n; n = 0; for (g = 0; g < pull->ngroup; g++) @@ -264,7 +264,7 @@ static void make_cyl_refgrps(t_commrec *cr, t_pull *pull, t_mdatoms *md, if (pcrd->eGeom == epullgCYL) { - double wmass, wwmass, inp, dist; + double wmass, wwmass, dist; pdyna = &pull->dyna[c]; pgrp = &pull->group[pcrd->group[1]];