Gromacs源码收获(四)

 mdrunner函数在runner.c和runner_openmm.c中均有,是MD模拟的主要程序之一。但是对另一个do_md函数的调用一直是个谜,今天终于看出了点头绪。

这里以runner.c中的mdrunner作为例子:

先看一个Interator的定义,在这里我们发现了do_md的影子。

Interator有积分器,综合者的意思

/* The array should match theeI array in include/types/enums.h */

const gmx_intp_t  Interator[eiNR] = { {do_md},{do_steep}, {do_cg}, {do_md}, {do_md}, {do_nm}, {do_lbfgs}, {do_tpi}, {do_tpi},{do_md}, {do_md}, {do_md}};

就好奇gmx_intp_t是什么类型的结构,看一下:

typedef struct {

    gmx_integrator_t *func;

} gmx_intp_t;

位置就在其定义上面,然后看下gmx_integrator_t的定义:

typedef doublegmx_integrator_t (FILE *log, t_commrec *cr,

                                 int nfile,const t_filenm fnm[],

                                 const output_env_toenv, gmx_bool bVerbose,

                                 gmx_boolbCompact, int nstglobalcomm,

                                 gmx_vsite_t*vsite, gmx_constr_t constr,

                                 int stepout,

                                 t_inputrec*inputrec,

                                 gmx_mtop_t*mtop, t_fcdata *fcd,

                                 t_state*state,

                                 t_mdatoms*mdatoms,

                                 t_nrnb *nrnb, gmx_wallcycle_t wcycle,

                                 gmx_edsam_ted,

                                 t_forcerec*fr,

                                 intrepl_ex_nst, int repl_ex_nex, int repl_ex_seed,

                                 gmx_membed_t membed,

                                 realcpt_period, real max_hours,

                                 const char*deviceOptions,

                                 unsigned longFlags,

                                 gmx_runtime_t*runtime);

原来是一个方法的typedef声明,那integrator就是eiNR个包含gmx_integrator_t函数的gmx_intp_t结构体数组。有点绕。

通过integrator定义前面的注释,我们找到了eiNR在enums.h中的定义

enum {

    eiMD, eiSteep, eiCG, eiBD,eiSD2, eiNM, eiLBFGS, eiTPI, eiTPIC, eiSD1, eiVV, eiVVAK, eiNR

};

但是不理解里面说的match是怎么match的。

下一次对主要嫌疑人的integrator见面在这:

    if (integrator[inputrec->eI].func ==do_md)

    {

        /* Turn on signal handling on all nodes*/

        /*

         * (A user signal from the PME nodes(if any)

         * is communicated to the PP nodes.

         */

        signal_handler_install();

    }

这里好像注册了一个信号,具体是干什么的,还未知。

然后就是:

/* Now do whatever the userwants us to do (how flexible...) */

        integrator[inputrec->eI].func(fplog,cr, nfile, fnm,

                                      oenv,bVerbose, bCompact,

                                      nstglobalcomm,

                                      vsite,constr,

                                      nstepout,inputrec, mtop,

                                      fcd,state,

                                      mdatoms,nrnb, wcycle, ed, fr,

                                     repl_ex_nst, repl_ex_nex, repl_ex_seed,

                                      membed,

                                     cpt_period, max_hours,

                                      deviceOptions,

                                      Flags,

                                     &runtime);

呵呵,找到函数调用了,看一下。首先看看inputrec->eI:

t_inputrec     *inputrec;                                 //mdrunner函数中的变量

//结构定义

typedef struct {

    int             eI;                   /* Integration method                 */

    gmx_large_int_t nsteps;               /* number of steps to be taken                   */

    int             simulation_part;      /* Used in checkpointing to separatechunks */

    gmx_large_int_t init_step;            /* start at a stepcount >0 (usedw. tpbconv)    */

    int             nstcalcenergy;        /* frequency of energy calc. and T/Pcoupl. upd.       */

    int             cutoff_scheme;        /* group or verlet cutoffs     */

    int             ns_type;              /* which ns method should weuse?               */

    int             nstlist;              /* number of steps beforepairlist is generated         */

    int             ndelta;               /* number of cells per rlong                       */

    int             nstcomm;              /* number of steps after which center of mass   */

    /* motion is removed                                   */

    int             comm_mode;            /* Center of mass motion removalalgorithm      */

    int             nstcheckpoint;        /* checkpointing frequency                      */

    int             nstlog;               /* number of steps after whichprint to logfile         */

    int             nstxout;              /* number of steps after which Xis output     */

    int             nstvout;              /* id. for V                                              */

   int             nstfout;              /* id. for F                                      */

    int             nstenergy;            /* number of steps after whichenergies printed */

    int             nstxtcout;            /* id. for compressed trj (.xtc)           */

    double          init_t;               /* initial time (ps)              */

    double          delta_t;              /* time step (ps)                                   */

    real            xtcprec;              /* precision of xtc file                        */

    real            fourier_spacing;      /*requested fourier_spacing, when nk? not set */

    int             nkx, nky, nkz;        /* number of k vectors in each spatialdimension*/

                                          /*for fourier methods for long range electrost.*/

    int             pme_order;            /* interpolation order for PME                  */

    real            ewald_rtol;           /* Real space tolerance for Ewald,determines   */

                                          /*the real/reciprocal space relative weight   */

    int             ewald_geometry;       /* normal/3d ewald, or pseudo-2d LRcorrections */

    real            epsilon_surface;      /* Epsilon for PME dipole correction            */

    gmx_bool        bOptFFT;              /* optimize the fft plan atstart               */

    int             ePBC;                 /* Type of periodic boundaryconditions                  */

    int             bPeriodicMols;        /* Periodic molecules                           */

    gmx_bool        bContinuation;        /* Continuation run: starting state iscorrect */

    int             etc;                  /* temperature coupling               */

    int             nsttcouple;           /* interval in steps for temperaturecoupling   */

    gmx_bool        bPrintNHChains;       /*whether to print nose-hoover chains       */

    int             epc;                  /* pressure coupling                            */

    int             epct;                 /* pressure coupling type                          */

    int             nstpcouple;           /* interval in steps for pressurecoupling      */

    real            tau_p;                /* pressure coupling time (ps)                           */

    tensor          ref_p;                /* reference pressure (kJ/(molnm^3))            */

    tensor          compress;             /* compressability ((mol nm^3)/kJ)        */

    int             refcoord_scaling;     /* How to scale absolute referencecoordinates  */

    rvec            posres_com;           /* The COM of the posres atoms                  */

    rvec            posres_comB;          /* The B-state COM of the posresatoms          */

    int             andersen_seed;        /* Random seed for Andersen thermostat(obsolete) */

    real            verletbuf_drift;      /* Max. drift (kJ/mol/ps/atom) for listbuffer  */

    real            rlist;                /* short range pairlist cut-off(nm)             */

    real            rlistlong;            /* long range pairlist cut-off (nm)                 */

    int             nstcalclr;            /* Frequency of evaluating directspace long-range interactions */

    real            rtpi;                 /* Radius for test particleinsertion           */

    int             coulombtype;          /* Type of electrostaticstreatment             */

    int             coulomb_modifier;     /* Modify the Coulomb interaction              */

    real            rcoulomb_switch;      /* Coulomb switch range start (nm)                  */

    real            rcoulomb;             /* Coulomb cutoff (nm)                            */

    real            epsilon_r;            /* relative dielectricconstant                 */

    real            epsilon_rf;           /* relative dielectric constant ofthe RF       */

    int             implicit_solvent;     /* No (=explicit water), or GBSA solventmodels */

    int             gb_algorithm;         /* Algorithm to use for calculationBorn radii  */

    int             nstgbradii;           /* Frequency of updating GeneralizedBorn radii */

    real            rgbradii;             /* Cutoff for GB radiicalculation              */

    real            gb_saltconc;          /* Salt concentration (M) for GBSAmodels       */

    real            gb_epsilon_solvent;   /* dielectric coeff. of implicitsolvent     */

    real            gb_obc_alpha;         /* 1st scaling factor for Bashford-CaseGB      */

    real            gb_obc_beta;          /* 2nd scaling factor forBashford-Case GB      */

    real            gb_obc_gamma;         /* 3rd scaling factor forBashford-Case GB      */

    real            gb_dielectric_offset; /* Dielectricoffset for Still/HCT/OBC     */

    int             sa_algorithm;         /* Algorithm for SA part of GBSA                */

    real            sa_surface_tension;   /* Energy factor for SA part of GBSA */

    int             vdwtype;              /* Type of Van der Waalstreatment              */

    int             vdw_modifier;         /* Modify the VdW interaction                   */

    real            rvdw_switch;          /* Van der Waals switch range start(nm)        */

    real            rvdw;                 /* Van der Waals cutoff (nm)        */

    int             eDispCorr;            /* Perform Long range dispersioncorrections    */

    real            tabext;               /* Extension of the table beyondthe cut-off,   *

                                           * as well asthe table length for 1-4 interac. */

    real            shake_tol;            /* tolerance for shake                                  */

    int             efep;                 /* free energycalculations                     */

    t_lambda       *fepvals;              /* Data for the FEP state                       */

    gmx_bool        bSimTemp;             /* Whether to do simulatedtempering            */

    t_simtemp      *simtempvals;          /* Variables for simulated tempering            */

    gmx_bool        bExpanded;            /* Whether expanded ensembles areused          */

    t_expanded     *expandedvals;         /* Expanded ensemble parameters              */

    int             eDisre;               /* Type of distancerestraining                 */

    real            dr_fc;                /* force constant for ta_disre                    */

    int             eDisreWeighting;      /* type of weighting of pairs in onerestraints */

    gmx_bool        bDisreMixed;          /* Use comb of time averaged andinstan. viol's   */

    int             nstdisreout;          /* frequency of writing pairdistances to enx   */

    real            dr_tau;               /* time constant for memoryfunction in disres    */

    real            orires_fc;            /* force constant for orientationalrestraints  */

    real            orires_tau;           /* time constant for memory functionin orires    */

    int             nstorireout;          /* frequency of writing tr(SD) toenx           */

    real            dihre_fc;             /* force constant for dihedralrestraints (obsolete) */

    real            em_stepsize;          /* The stepsize for updating                      */

    real            em_tol;               /* The tolerance                                 */

    int            niter;                /* Number of iterations forconvergence of      */

                                          /*steepest descent in relax_shells            */

    real            fc_stepsize;          /* Stepsize for directionalminimization        */

                                          /* inrelax_shells                             */

    int             nstcgsteep;           /* number of steps after which asteepest       */

                                          /*descents step is done while doing cg        */

    int             nbfgscorr;            /* Number of corrections to thehessian to keep */

    int             eConstrAlg;           /* Type of constraint algorithm                 */

    int             nProjOrder;           /* Order of the LINCS ProjectionAlgorithm      */

    real            LincsWarnAngle;       /* If bond rotates more than %g degrees,warn   */

    int             nLincsIter;           /* Number of iterations in the finalLincs step */

    gmx_bool       bShakeSOR;            /* Use successive overrelaxationfor shake      */

    real            bd_fric;              /* Friction coefficient for BD(amu/ps)         */

    int             ld_seed;              /* Random seed for SD and BD                    */

    int             nwall;                /* The number of walls                          */

    int             wall_type;            /* The type of walls                            */

    real            wall_r_linpot;        /* The potentail is linear forr<=wall_r_linpot */

    int             wall_atomtype[2];     /* The atom type for walls                      */

    real            wall_density[2];      /* Number density for walls                     */

    real            wall_ewald_zfac;      /*Scaling factor for the box for Ewald        */

    int             ePull;                /* Type of pulling: no,umbrella or constraint  */

    t_pull         *pull;                 /* The data for center of masspulling          */

    gmx_bool        bRot;                 /* Calculate enforced rotationpotential(s)?    */

    t_rot          *rot;                  /* The data for enforcedrotation potentials    */

    real            cos_accel;            /* Acceleration for viscositycalculation       */

    tensor          deform;               /* Triclinic deformationvelocities (nm/ps)     */

    int             userint1;             /* User determined parameters                   */

    int             userint2;

    int             userint3;

    int             userint4;

    real            userreal1;

    real            userreal2;

    real            userreal3;

    real            userreal4;

    t_grpopts       opts;          /* Group options                               */

    t_cosines       ex[DIM];       /* Electric field stuff       (spatial part)             */

    t_cosines       et[DIM];       /* Electric field stuff       (time part)                 */

    gmx_bool        bQMMM;         /* QM/MM calculation                            */

    int             QMconstraints; /* constraints onQM bonds                      */

    int             QMMMscheme;    /* Scheme: ONIOM or normal                      */

    real            scalefactor;   /* factor for scaling the MM charges in QMcalc.*/

                                   /* parameterneeded for AdResS simulation       */

    gmx_bool        bAdress;       /* Is AdResS enabled ? */

    t_adress       *adress;        /* The data for adress simulations */

} t_inputrec;

然后调用对应的func函数完成函数调用,但是还有一个疑问inputrec的初始化和值的标定在哪里?继续找

snew(inputrec, 1);这里是申请空间。

这里

* Read (nearly) all datarequired for the simulation */

        read_tpx_state(ftp2fn(efTPX, nfile,fnm), inputrec, state, NULL, mtop);

看下t_filenm的定义:

typedef struct {

    int           ftp;    /* File type (see enum above)          */

    const char  *opt;    /* Command line option                     */

    const char  *fn;     /* File name (as set insource code) */

    unsigned long flag;   /* Flag for all kinds of info (see defs)*/

    int           nfiles; /* number of files                           */

    char       **fns;    /* File names                              */

} t_filenm;

总之是读取一个类型的文件,然后通过文件初始化。

通过Gromacs网站了解到调用的方法取决于mdp文件中的整型量。但是一般情况是调用的do_md方法。

你可能感兴趣的:(C++,Gromacs源码)