[gmx-developers] Help needed with hacking mdrun

Mark Abraham Mark.Abraham at anu.edu.au
Thu Apr 7 14:16:05 CEST 2011


On 7/04/2011 7:11 PM, Semen Esilevsky wrote:
> Dear All,
> I need to hack mdrun in rather complex way and need some help from people, who
> understand Gromacs internals really well.
> My  problem is the following. Each N MD steps I want to pass current
> coordinates and forces to custom function, which transforms them in a  certain
> way (doesn't matter how at this point). Then I want to pass  modified forces and
>
> coordinates back and continue simulation. Currently I  got stuck with domain
> decomposition stuff. I figured out how to collect  data on master node and pass
> it to my function. However,  I have no  idea how to distribute it back to all
> nodes correctly after  modification.
> Here is my additional code in md.c  so far:
>
> ...
> /* ########  END FIRST UPDATE STEP  ############## */
> /* ########  If doing VV, we now have v(dt)  ###### */
>
>   /* ################## START TRAJECTORY OUTPUT ################# */
>
> /* Some preparations goes here */
> ...
> /* Collecting data*/
> if (DOMAINDECOMP(cr))
>      {
>          /*We need to collect x and f only*/
>          dd_collect_vec(cr->dd,state_local,state_local->x,state_global->x);
>          dd_collect_vec(cr->dd,state_local,f_local,f_global);
>      }
>
> if (MASTER(cr))
>      {
>          printf("Collected %d atoms at step: %d\n",top_global->natoms,step);
>          /* Actually pass data */
>          pass_to(top_global->natoms, t, state_global->x, f_global);
>           ...
>          /* Processing data here */
>          ...
>         /*  Get data back */
>         pass_from(state_global->x, f_global);
>      }
> ...
> if (DOMAINDECOMP(cr)){
>      /* Here I have to redistribute it back from state_global->x and I'm totally
> stuck :(  */
> }
>
> The problem is that functions like dd_distribute_vector(...) are only used
> deep inside domain decomposition code and they use some data structures, which
> are not exposed in .h files.

dd_collect_vec() calls dd_collect_cg() which fills dd->comm->cgs_gl if 
it is out of date. dd_partition_system() calls dd_distribute_state() 
which calls dd_distribute_vec(). However get_cg_distribution fills() 
dd->comm->cgs_gl immediately before dd_distribute state().

So if your modifications to positions are small, then I suspect you can 
just call dd_distribute_vec() passing dd->comm->cgs_gl. The UI and 
documentation (ahem) could be better, I think.

Otherwise, call dd_partition_system to re-do the DD partition.

> Is there any other more elegant way of plugging custom code to mdrun?

No.

Mark



More information about the gromacs.org_gmx-developers mailing list