1 /* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; c-file-style: "stroustrup"; -*-
4 * This source code is part of
8 * GROningen MAchine for Chemical Simulations
11 * Written by David van der Spoel, Erik Lindahl, Berk Hess, and others.
12 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
13 * Copyright (c) 2001-2004, The GROMACS development team,
14 * check out http://www.gromacs.org for more information.
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * If you want to redistribute modifications, please consider that
22 * scientific software is very special. Version control is crucial -
23 * bugs must be traceable. We will be happy to consider code for
24 * inclusion in the official distribution, but derived work must not
25 * be called official GROMACS. Details are found in the README & COPYING
26 * files - if they are missing, get the official version at www.gromacs.org.
28 * To help us fund GROMACS development, we humbly ask that you cite
29 * the papers on the package - you can find them in the top README file.
31 * For more info, check our website at http://www.gromacs.org
34 * GROwing Monsters And Cloning Shrimps
40 #ifdef GMX_THREAD_SHM_FDECOMP
54 #include "nonbonded.h"
58 #include "gmx_fatal.h"
61 #include "mtop_util.h"
67 /* Uncomment the define below to use the generic charge group - charge group
68 * inner loops (in src/gmxlib/nonbonded/nb_generic_cg.c).
69 * All intra charge-group interaction should be excluded.
70 * There should be no inter charge group exclusions.
71 * There can be no perturbed LJ types or charges.
72 * mdrun currently does NOT check for this.
74 /* #define GMX_CG_INNERLOOP */
78 * E X C L U S I O N H A N D L I N G
82 static void SETEXCL_(t_excl e
[],atom_id i
,atom_id j
)
83 { e
[j
] = e
[j
] | (1<<i
); }
84 static void RMEXCL_(t_excl e
[],atom_id i
,atom_id j
)
85 { e
[j
]=e
[j
] & ~(1<<i
); }
86 static bool ISEXCL_(t_excl e
[],atom_id i
,atom_id j
)
87 { return (bool)(e
[j
] & (1<<i
)); }
88 static bool NOTEXCL_(t_excl e
[],atom_id i
,atom_id j
)
89 { return !(ISEXCL(e
,i
,j
)); }
91 #define SETEXCL(e,i,j) (e)[((atom_id) (j))] |= (1<<((atom_id) (i)))
92 #define RMEXCL(e,i,j) (e)[((atom_id) (j))] &= (~(1<<((atom_id) (i))))
93 #define ISEXCL(e,i,j) (bool) ((e)[((atom_id) (j))] & (1<<((atom_id) (i))))
94 #define NOTEXCL(e,i,j) !(ISEXCL(e,i,j))
97 /************************************************
99 * U T I L I T I E S F O R N S
101 ************************************************/
103 static void reallocate_nblist(t_nblist
*nl
)
107 fprintf(debug
,"reallocating neigborlist il_code=%d, maxnri=%d\n",
108 nl
->il_code
,nl
->maxnri
);
110 srenew(nl
->iinr
, nl
->maxnri
);
111 if (nl
->enlist
== enlistCG_CG
)
113 srenew(nl
->iinr_end
,nl
->maxnri
);
115 srenew(nl
->gid
, nl
->maxnri
);
116 srenew(nl
->shift
, nl
->maxnri
);
117 srenew(nl
->jindex
, nl
->maxnri
+1);
120 /* ivdw/icoul are used to determine the type of interaction, so we
121 * can set an innerloop index here. The obvious choice for this would have
122 * been the vdwtype/coultype values in the forcerecord, but unfortunately
123 * those types are braindead - for instance both Buckingham and normal
124 * Lennard-Jones use the same value (evdwCUT), and a separate boolean variable
125 * to determine which interaction is used. There is further no special value
126 * for 'no interaction'. For backward compatibility with old TPR files we won't
127 * change this in the 3.x series, so when calling this routine you should use:
129 * icoul=0 no coulomb interaction
130 * icoul=1 cutoff standard coulomb
131 * icoul=2 reaction-field coulomb
132 * icoul=3 tabulated coulomb
134 * ivdw=0 no vdw interaction
135 * ivdw=1 standard L-J interaction
137 * ivdw=3 tabulated vdw.
139 * Kind of ugly, but it works.
141 static void init_nblist(t_nblist
*nl_sr
,t_nblist
*nl_lr
,
144 bool bfree
, int enlist
)
176 nl
= (i
== 0) ? nl_sr
: nl_lr
;
177 homenr
= (i
== 0) ? maxsr
: maxlr
;
184 /* Set coul/vdw in neighborlist, and for the normal loops we determine
185 * an index of which one to call.
189 nl
->free_energy
= bfree
;
193 nl
->enlist
= enlistATOM_ATOM
;
194 nl
->il_code
= eNR_NBKERNEL_FREE_ENERGY
;
200 nn
= inloop
[4*icoul
+ ivdw
];
202 /* solvent loops follow directly after the corresponding
203 * ordinary loops, in the order:
205 * SPC, SPC-SPC, TIP4p, TIP4p-TIP4p
209 case enlistATOM_ATOM
:
212 case enlistSPC_ATOM
: nn
+= 1; break;
213 case enlistSPC_SPC
: nn
+= 2; break;
214 case enlistTIP4P_ATOM
: nn
+= 3; break;
215 case enlistTIP4P_TIP4P
: nn
+= 4; break;
222 fprintf(debug
,"Initiating neighbourlist type %d for %s interactions,\nwith %d SR, %d LR atoms.\n",
223 nl
->il_code
,ENLISTTYPE(enlist
),maxsr
,maxlr
);
225 /* maxnri is influenced by the number of shifts (maximum is 8)
226 * and the number of energy groups.
227 * If it is not enough, nl memory will be reallocated during the run.
228 * 4 seems to be a reasonable factor, which only causes reallocation
229 * during runs with tiny and many energygroups.
231 nl
->maxnri
= homenr
*4;
240 reallocate_nblist(nl
);
242 #ifdef GMX_THREAD_SHM_FDECOMP
245 pthread_mutex_init(nl
->mtx
,NULL
);
250 void init_neighbor_list(FILE *log
,t_forcerec
*fr
,int homenr
)
252 /* Make maxlr tunable! (does not seem to be a big difference though)
253 * This parameter determines the number of i particles in a long range
254 * neighbourlist. Too few means many function calls, too many means
257 int maxsr
,maxsr_wat
,maxlr
,maxlr_wat
;
258 int icoul
,icoulf
,ivdw
;
260 int enlist_def
,enlist_w
,enlist_ww
;
264 /* maxsr = homenr-fr->nWatMol*3; */
269 gmx_fatal(FARGS
,"%s, %d: Negative number of short range atoms.\n"
270 "Call your Gromacs dealer for assistance.",__FILE__
,__LINE__
);
272 /* This is just for initial allocation, so we do not reallocate
273 * all the nlist arrays many times in a row.
274 * The numbers seem very accurate, but they are uncritical.
276 maxsr_wat
= min(fr
->nWatMol
,(homenr
+2)/3);
280 maxlr_wat
= min(maxsr_wat
,maxlr
);
284 maxlr
= maxlr_wat
= 0;
287 /* Determine the values for icoul/ivdw. */
293 else if (fr
->bcoultab
)
297 else if (EEL_RF(fr
->eeltype
))
319 fr
->ns
.bCGlist
= (getenv("GMX_NBLISTCG") != 0);
322 enlist_def
= enlistATOM_ATOM
;
326 enlist_def
= enlistCG_CG
;
329 fprintf(log
,"\nUsing charge-group - charge-group neighbor lists and kernels\n\n");
333 if (fr
->solvent_opt
== esolTIP4P
) {
334 enlist_w
= enlistTIP4P_ATOM
;
335 enlist_ww
= enlistTIP4P_TIP4P
;
337 enlist_w
= enlistSPC_ATOM
;
338 enlist_ww
= enlistSPC_SPC
;
341 for(i
=0; i
<fr
->nnblists
; i
++)
343 nbl
= &(fr
->nblists
[i
]);
344 init_nblist(&nbl
->nlist_sr
[eNL_VDWQQ
],&nbl
->nlist_lr
[eNL_VDWQQ
],
345 maxsr
,maxlr
,ivdw
,icoul
,FALSE
,enlist_def
);
346 init_nblist(&nbl
->nlist_sr
[eNL_VDW
],&nbl
->nlist_lr
[eNL_VDW
],
347 maxsr
,maxlr
,ivdw
,0,FALSE
,enlist_def
);
348 init_nblist(&nbl
->nlist_sr
[eNL_QQ
],&nbl
->nlist_lr
[eNL_QQ
],
349 maxsr
,maxlr
,0,icoul
,FALSE
,enlist_def
);
350 init_nblist(&nbl
->nlist_sr
[eNL_VDWQQ_WATER
],&nbl
->nlist_lr
[eNL_VDWQQ_WATER
],
351 maxsr_wat
,maxlr_wat
,ivdw
,icoul
, FALSE
,enlist_w
);
352 init_nblist(&nbl
->nlist_sr
[eNL_QQ_WATER
],&nbl
->nlist_lr
[eNL_QQ_WATER
],
353 maxsr_wat
,maxlr_wat
,0,icoul
, FALSE
,enlist_w
);
354 init_nblist(&nbl
->nlist_sr
[eNL_VDWQQ_WATERWATER
],&nbl
->nlist_lr
[eNL_VDWQQ_WATERWATER
],
355 maxsr_wat
,maxlr_wat
,ivdw
,icoul
, FALSE
,enlist_ww
);
356 init_nblist(&nbl
->nlist_sr
[eNL_QQ_WATERWATER
],&nbl
->nlist_lr
[eNL_QQ_WATERWATER
],
357 maxsr_wat
,maxlr_wat
,0,icoul
, FALSE
,enlist_ww
);
359 if (fr
->efep
!= efepNO
)
370 init_nblist(&nbl
->nlist_sr
[eNL_VDWQQ_FREE
],&nbl
->nlist_lr
[eNL_VDWQQ_FREE
],
371 maxsr
,maxlr
,ivdw
,icoulf
,TRUE
,enlistATOM_ATOM
);
372 init_nblist(&nbl
->nlist_sr
[eNL_VDW_FREE
],&nbl
->nlist_lr
[eNL_VDW_FREE
],
373 maxsr
,maxlr
,ivdw
,0,TRUE
,enlistATOM_ATOM
);
374 init_nblist(&nbl
->nlist_sr
[eNL_QQ_FREE
],&nbl
->nlist_lr
[eNL_QQ_FREE
],
375 maxsr
,maxlr
,0,icoulf
,TRUE
,enlistATOM_ATOM
);
379 if (fr
->bQMMM
&& fr
->qr
->QMMMscheme
!= eQMMMschemeoniom
)
381 init_nblist(&fr
->QMMMlist
,NULL
,
382 maxsr
,maxlr
,0,icoul
,FALSE
,enlistATOM_ATOM
);
385 fr
->ns
.nblist_initialized
=TRUE
;
388 static void reset_nblist(t_nblist
*nl
)
399 static void reset_neighbor_list(t_forcerec
*fr
,bool bLR
,int nls
,int eNL
)
405 reset_nblist(&(fr
->nblists
[nls
].nlist_lr
[eNL
]));
409 for(n
=0; n
<fr
->nnblists
; n
++)
411 for(i
=0; i
<eNL_NR
; i
++)
413 reset_nblist(&(fr
->nblists
[n
].nlist_sr
[i
]));
418 /* only reset the short-range nblist */
419 reset_nblist(&(fr
->QMMMlist
));
427 static inline void new_i_nblist(t_nblist
*nlist
,
428 bool bLR
,atom_id i_atom
,int shift
,int gid
)
434 /* Check whether we have to increase the i counter */
436 (nlist
->iinr
[nri
] != i_atom
) ||
437 (nlist
->shift
[nri
] != shift
) ||
438 (nlist
->gid
[nri
] != gid
))
440 /* This is something else. Now see if any entries have
441 * been added in the list of the previous atom.
444 ((nlist
->jindex
[nri
+1] > nlist
->jindex
[nri
]) &&
445 (nlist
->gid
[nri
] != -1)))
447 /* If so increase the counter */
450 if (nlist
->nri
>= nlist
->maxnri
)
452 nlist
->maxnri
+= over_alloc_large(nlist
->nri
);
453 reallocate_nblist(nlist
);
456 /* Set the number of neighbours and the atom number */
457 nlist
->jindex
[nri
+1] = nlist
->jindex
[nri
];
458 nlist
->iinr
[nri
] = i_atom
;
459 nlist
->gid
[nri
] = gid
;
460 nlist
->shift
[nri
] = shift
;
464 static inline void close_i_nblist(t_nblist
*nlist
)
466 int nri
= nlist
->nri
;
471 nlist
->jindex
[nri
+1] = nlist
->nrj
;
473 len
=nlist
->nrj
- nlist
->jindex
[nri
];
475 /* nlist length for water i molecules is treated statically
478 if (len
> nlist
->maxlen
)
485 static inline void close_nblist(t_nblist
*nlist
)
487 /* Only close this nblist when it has been initialized */
494 static inline void close_neighbor_list(t_forcerec
*fr
,bool bLR
,int nls
,int eNL
,
495 bool bMakeQMMMnblist
)
499 if (bMakeQMMMnblist
) {
502 close_nblist(&(fr
->QMMMlist
));
509 close_nblist(&(fr
->nblists
[nls
].nlist_lr
[eNL
]));
513 for(n
=0; n
<fr
->nnblists
; n
++)
515 for(i
=0; (i
<eNL_NR
); i
++)
517 close_nblist(&(fr
->nblists
[n
].nlist_sr
[i
]));
524 static inline void add_j_to_nblist(t_nblist
*nlist
,atom_id j_atom
,bool bLR
)
528 if (nlist
->nrj
>= nlist
->maxnrj
)
530 nlist
->maxnrj
= over_alloc_small(nlist
->nrj
+ 1);
532 fprintf(debug
,"Increasing %s nblist %s j size to %d\n",
533 bLR
? "LR" : "SR",nrnb_str(nlist
->il_code
),nlist
->maxnrj
);
535 srenew(nlist
->jjnr
,nlist
->maxnrj
);
538 nlist
->jjnr
[nrj
] = j_atom
;
542 static inline void add_j_to_nblist_cg(t_nblist
*nlist
,
543 atom_id j_start
,int j_end
,
544 t_excl
*bexcl
,bool bLR
)
549 if (nlist
->nrj
>= nlist
->maxnrj
)
551 nlist
->maxnrj
= over_alloc_small(nlist
->nrj
+ 1);
553 fprintf(debug
,"Increasing %s nblist %s j size to %d\n",
554 bLR
? "LR" : "SR",nrnb_str(nlist
->il_code
),nlist
->maxnrj
);
556 srenew(nlist
->jjnr
,nlist
->maxnrj
);
557 srenew(nlist
->jjnr_end
,nlist
->maxnrj
);
558 srenew(nlist
->excl
,nlist
->maxnrj
*MAX_CGCGSIZE
);
561 nlist
->jjnr
[nrj
] = j_start
;
562 nlist
->jjnr_end
[nrj
] = j_end
;
564 if (j_end
- j_start
> MAX_CGCGSIZE
)
566 gmx_fatal(FARGS
,"The charge-group - charge-group neighborlist do not support charge groups larger than %d, found a charge group of size %d",MAX_CGCGSIZE
,j_end
-j_start
);
569 /* Set the exclusions */
570 for(j
=j_start
; j
<j_end
; j
++)
572 nlist
->excl
[nrj
*MAX_CGCGSIZE
+ j
- j_start
] = bexcl
[j
];
579 put_in_list_t(bool bHaveVdW
[],
595 put_in_list_at(bool bHaveVdW
[],
610 /* The a[] index has been removed,
611 * to put it back in i_atom should be a[i0] and jj should be a[jj].
616 t_nblist
* vdwc_free
= NULL
;
617 t_nblist
* vdw_free
= NULL
;
618 t_nblist
* coul_free
= NULL
;
619 t_nblist
* vdwc_ww
= NULL
;
620 t_nblist
* coul_ww
= NULL
;
622 int i
,j
,jcg
,igid
,gid
,nbl_ind
,ind_ij
;
623 atom_id jj
,jj0
,jj1
,i_atom
;
628 real
*charge
,*chargeB
;
630 bool bFreeEnergy
,bFree
,bFreeJ
,bNotEx
,*bPert
;
631 bool bDoVdW_i
,bDoCoul_i
,bDoCoul_i_sol
;
635 /* Copy some pointers */
637 charge
= md
->chargeA
;
638 chargeB
= md
->chargeB
;
641 bPert
= md
->bPerturbed
;
645 nicg
= index
[icg
+1]-i0
;
647 /* Get the i charge group info */
648 igid
= GET_CGINFO_GID(cginfo
[icg
]);
649 iwater
= GET_CGINFO_SOLOPT(cginfo
[icg
]);
654 /* Check if any of the particles involved are perturbed.
655 * If not we can do the cheaper normal put_in_list
656 * and use more solvent optimization.
658 for(i
=0; i
<nicg
; i
++)
660 bFreeEnergy
|= bPert
[i0
+i
];
662 /* Loop over the j charge groups */
663 for(j
=0; (j
<nj
&& !bFreeEnergy
); j
++)
668 /* Finally loop over the atoms in the j-charge group */
669 for(jj
=jj0
; jj
<jj1
; jj
++)
671 bFreeEnergy
|= bPert
[jj
];
676 /* Unpack pointers to neighbourlist structs */
677 if (fr
->nnblists
== 1)
683 nbl_ind
= fr
->gid2nblists
[GID(igid
,jgid
,ngid
)];
687 nlist
= fr
->nblists
[nbl_ind
].nlist_lr
;
691 nlist
= fr
->nblists
[nbl_ind
].nlist_sr
;
694 if (iwater
!= esolNO
)
696 vdwc
= &nlist
[eNL_VDWQQ_WATER
];
697 vdw
= &nlist
[eNL_VDW
];
698 coul
= &nlist
[eNL_QQ_WATER
];
699 #ifndef DISABLE_WATERWATER_NLIST
700 vdwc_ww
= &nlist
[eNL_VDWQQ_WATERWATER
];
701 coul_ww
= &nlist
[eNL_QQ_WATERWATER
];
706 vdwc
= &nlist
[eNL_VDWQQ
];
707 vdw
= &nlist
[eNL_VDW
];
708 coul
= &nlist
[eNL_QQ
];
713 if (iwater
!= esolNO
)
715 /* Loop over the atoms in the i charge group */
717 gid
= GID(igid
,jgid
,ngid
);
718 /* Create new i_atom for each energy group */
719 if (bDoCoul
&& bDoVdW
)
721 new_i_nblist(vdwc
,bLR
,i_atom
,shift
,gid
);
722 #ifndef DISABLE_WATERWATER_NLIST
723 new_i_nblist(vdwc_ww
,bLR
,i_atom
,shift
,gid
);
728 new_i_nblist(vdw
,bLR
,i_atom
,shift
,gid
);
732 new_i_nblist(coul
,bLR
,i_atom
,shift
,gid
);
733 #ifndef DISABLE_WATERWATER_NLIST
734 new_i_nblist(coul_ww
,bLR
,i_atom
,shift
,gid
);
737 /* Loop over the j charge groups */
738 for(j
=0; (j
<nj
); j
++)
748 jwater
= GET_CGINFO_SOLOPT(cginfo
[jcg
]);
750 if (iwater
== esolSPC
&& jwater
== esolSPC
)
752 /* Interaction between two SPC molecules */
755 /* VdW only - only first atoms in each water interact */
756 add_j_to_nblist(vdw
,jj0
,bLR
);
760 #ifdef DISABLE_WATERWATER_NLIST
761 /* Add entries for the three atoms - only do VdW if we need to */
764 add_j_to_nblist(coul
,jj0
,bLR
);
768 add_j_to_nblist(vdwc
,jj0
,bLR
);
770 add_j_to_nblist(coul
,jj0
+1,bLR
);
771 add_j_to_nblist(coul
,jj0
+2,bLR
);
773 /* One entry for the entire water-water interaction */
776 add_j_to_nblist(coul_ww
,jj0
,bLR
);
780 add_j_to_nblist(vdwc_ww
,jj0
,bLR
);
785 else if (iwater
== esolTIP4P
&& jwater
== esolTIP4P
)
787 /* Interaction between two TIP4p molecules */
790 /* VdW only - only first atoms in each water interact */
791 add_j_to_nblist(vdw
,jj0
,bLR
);
795 #ifdef DISABLE_WATERWATER_NLIST
796 /* Add entries for the four atoms - only do VdW if we need to */
799 add_j_to_nblist(vdw
,jj0
,bLR
);
801 add_j_to_nblist(coul
,jj0
+1,bLR
);
802 add_j_to_nblist(coul
,jj0
+2,bLR
);
803 add_j_to_nblist(coul
,jj0
+3,bLR
);
805 /* One entry for the entire water-water interaction */
808 add_j_to_nblist(coul_ww
,jj0
,bLR
);
812 add_j_to_nblist(vdwc_ww
,jj0
,bLR
);
819 /* j charge group is not water, but i is.
820 * Add entries to the water-other_atom lists; the geometry of the water
821 * molecule doesn't matter - that is taken care of in the nonbonded kernel,
822 * so we don't care if it is SPC or TIP4P...
829 for(jj
=jj0
; (jj
<jj1
); jj
++)
833 add_j_to_nblist(coul
,jj
,bLR
);
839 for(jj
=jj0
; (jj
<jj1
); jj
++)
841 if (bHaveVdW
[type
[jj
]])
843 add_j_to_nblist(vdw
,jj
,bLR
);
849 /* _charge_ _groups_ interact with both coulomb and LJ */
850 /* Check which atoms we should add to the lists! */
851 for(jj
=jj0
; (jj
<jj1
); jj
++)
853 if (bHaveVdW
[type
[jj
]])
857 add_j_to_nblist(vdwc
,jj
,bLR
);
861 add_j_to_nblist(vdw
,jj
,bLR
);
864 else if (charge
[jj
] != 0)
866 add_j_to_nblist(coul
,jj
,bLR
);
873 close_i_nblist(coul
);
874 close_i_nblist(vdwc
);
875 #ifndef DISABLE_WATERWATER_NLIST
876 close_i_nblist(coul_ww
);
877 close_i_nblist(vdwc_ww
);
882 /* no solvent as i charge group */
883 /* Loop over the atoms in the i charge group */
884 for(i
=0; i
<nicg
; i
++)
887 gid
= GID(igid
,jgid
,ngid
);
890 /* Create new i_atom for each energy group */
891 if (bDoVdW
&& bDoCoul
)
893 new_i_nblist(vdwc
,bLR
,i_atom
,shift
,gid
);
897 new_i_nblist(vdw
,bLR
,i_atom
,shift
,gid
);
901 new_i_nblist(coul
,bLR
,i_atom
,shift
,gid
);
903 bDoVdW_i
= (bDoVdW
&& bHaveVdW
[type
[i_atom
]]);
904 bDoCoul_i
= (bDoCoul
&& qi
!=0);
906 if (bDoVdW_i
|| bDoCoul_i
)
908 /* Loop over the j charge groups */
909 for(j
=0; (j
<nj
); j
++)
913 /* Check for large charge groups */
924 /* Finally loop over the atoms in the j-charge group */
925 for(jj
=jj0
; jj
<jj1
; jj
++)
927 bNotEx
= NOTEXCL(bExcl
,i
,jj
);
935 add_j_to_nblist(coul
,jj
,bLR
);
940 if (bHaveVdW
[type
[jj
]])
942 add_j_to_nblist(vdw
,jj
,bLR
);
947 if (bHaveVdW
[type
[jj
]])
951 add_j_to_nblist(vdwc
,jj
,bLR
);
955 add_j_to_nblist(vdw
,jj
,bLR
);
958 else if (charge
[jj
] != 0)
960 add_j_to_nblist(coul
,jj
,bLR
);
968 close_i_nblist(coul
);
969 close_i_nblist(vdwc
);
975 /* we are doing free energy */
976 vdwc_free
= &nlist
[eNL_VDWQQ_FREE
];
977 vdw_free
= &nlist
[eNL_VDW_FREE
];
978 coul_free
= &nlist
[eNL_QQ_FREE
];
979 /* Loop over the atoms in the i charge group */
980 for(i
=0; i
<nicg
; i
++)
983 gid
= GID(igid
,jgid
,ngid
);
985 qiB
= chargeB
[i_atom
];
987 /* Create new i_atom for each energy group */
988 if (bDoVdW
&& bDoCoul
)
989 new_i_nblist(vdwc
,bLR
,i_atom
,shift
,gid
);
991 new_i_nblist(vdw
,bLR
,i_atom
,shift
,gid
);
993 new_i_nblist(coul
,bLR
,i_atom
,shift
,gid
);
995 new_i_nblist(vdw_free
,bLR
,i_atom
,shift
,gid
);
996 new_i_nblist(coul_free
,bLR
,i_atom
,shift
,gid
);
997 new_i_nblist(vdwc_free
,bLR
,i_atom
,shift
,gid
);
999 bDoVdW_i
= (bDoVdW
&&
1000 (bHaveVdW
[type
[i_atom
]] || bHaveVdW
[typeB
[i_atom
]]));
1001 bDoCoul_i
= (bDoCoul
&& (qi
!=0 || qiB
!=0));
1002 /* For TIP4P the first atom does not have a charge,
1003 * but the last three do. So we should still put an atom
1004 * without LJ but with charge in the water-atom neighborlist
1005 * for a TIP4p i charge group.
1006 * For SPC type water the first atom has LJ and charge,
1007 * so there is no such problem.
1009 if (iwater
== esolNO
)
1011 bDoCoul_i_sol
= bDoCoul_i
;
1015 bDoCoul_i_sol
= bDoCoul
;
1018 if (bDoVdW_i
|| bDoCoul_i_sol
)
1020 /* Loop over the j charge groups */
1021 for(j
=0; (j
<nj
); j
++)
1025 /* Check for large charge groups */
1036 /* Finally loop over the atoms in the j-charge group */
1037 bFree
= bPert
[i_atom
];
1038 for(jj
=jj0
; (jj
<jj1
); jj
++)
1040 bFreeJ
= bFree
|| bPert
[jj
];
1041 /* Complicated if, because the water H's should also
1042 * see perturbed j-particles
1044 if (iwater
==esolNO
|| i
==0 || bFreeJ
)
1046 bNotEx
= NOTEXCL(bExcl
,i
,jj
);
1054 if (charge
[jj
]!=0 || chargeB
[jj
]!=0)
1056 add_j_to_nblist(coul_free
,jj
,bLR
);
1059 else if (!bDoCoul_i
)
1061 if (bHaveVdW
[type
[jj
]] || bHaveVdW
[typeB
[jj
]])
1063 add_j_to_nblist(vdw_free
,jj
,bLR
);
1068 if (bHaveVdW
[type
[jj
]] || bHaveVdW
[typeB
[jj
]])
1070 if (charge
[jj
]!=0 || chargeB
[jj
]!=0)
1072 add_j_to_nblist(vdwc_free
,jj
,bLR
);
1076 add_j_to_nblist(vdw_free
,jj
,bLR
);
1079 else if (charge
[jj
]!=0 || chargeB
[jj
]!=0)
1080 add_j_to_nblist(coul_free
,jj
,bLR
);
1085 /* This is done whether or not bWater is set */
1086 if (charge
[jj
] != 0)
1088 add_j_to_nblist(coul
,jj
,bLR
);
1091 else if (!bDoCoul_i_sol
)
1093 if (bHaveVdW
[type
[jj
]])
1095 add_j_to_nblist(vdw
,jj
,bLR
);
1100 if (bHaveVdW
[type
[jj
]])
1102 if (charge
[jj
] != 0)
1104 add_j_to_nblist(vdwc
,jj
,bLR
);
1108 add_j_to_nblist(vdw
,jj
,bLR
);
1111 else if (charge
[jj
] != 0)
1113 add_j_to_nblist(coul
,jj
,bLR
);
1121 close_i_nblist(vdw
);
1122 close_i_nblist(coul
);
1123 close_i_nblist(vdwc
);
1124 close_i_nblist(vdw_free
);
1125 close_i_nblist(coul_free
);
1126 close_i_nblist(vdwc_free
);
1132 put_in_list_qmmm(bool bHaveVdW
[],
1148 int i
,j
,jcg
,igid
,gid
;
1149 atom_id jj
,jj0
,jj1
,i_atom
;
1153 /* Get atom range */
1155 nicg
= index
[icg
+1]-i0
;
1157 /* Get the i charge group info */
1158 igid
= GET_CGINFO_GID(fr
->cginfo
[icg
]);
1160 coul
= &fr
->QMMMlist
;
1162 /* Loop over atoms in the ith charge group */
1163 for (i
=0;i
<nicg
;i
++)
1166 gid
= GID(igid
,jgid
,ngid
);
1167 /* Create new i_atom for each energy group */
1168 new_i_nblist(coul
,bLR
,i_atom
,shift
,gid
);
1170 /* Loop over the j charge groups */
1175 /* Charge groups cannot have QM and MM atoms simultaneously */
1180 /* Finally loop over the atoms in the j-charge group */
1181 for(jj
=jj0
; jj
<jj1
; jj
++)
1183 bNotEx
= NOTEXCL(bExcl
,i
,jj
);
1185 add_j_to_nblist(coul
,jj
,bLR
);
1189 close_i_nblist(coul
);
1194 put_in_list_cg(bool bHaveVdW
[],
1210 int igid
,gid
,nbl_ind
;
1214 cginfo
= fr
->cginfo
[icg
];
1216 igid
= GET_CGINFO_GID(cginfo
);
1217 gid
= GID(igid
,jgid
,ngid
);
1219 /* Unpack pointers to neighbourlist structs */
1220 if (fr
->nnblists
== 1)
1226 nbl_ind
= fr
->gid2nblists
[gid
];
1230 vdwc
= &fr
->nblists
[nbl_ind
].nlist_lr
[eNL_VDWQQ
];
1234 vdwc
= &fr
->nblists
[nbl_ind
].nlist_sr
[eNL_VDWQQ
];
1237 /* Make a new neighbor list for charge group icg.
1238 * Currently simply one neighbor list is made with LJ and Coulomb.
1239 * If required, zero interactions could be removed here
1240 * or in the force loop.
1242 new_i_nblist(vdwc
,bLR
,index
[icg
],shift
,gid
);
1243 vdwc
->iinr_end
[vdwc
->nri
] = index
[icg
+1];
1245 for(j
=0; (j
<nj
); j
++)
1248 /* Skip the icg-icg pairs if all self interactions are excluded */
1249 if (!(jcg
== icg
&& GET_CGINFO_EXCL_INTRA(cginfo
)))
1251 /* Here we add the j charge group jcg to the list,
1252 * exclusions are also added to the list.
1254 add_j_to_nblist_cg(vdwc
,index
[jcg
],index
[jcg
+1],bExcl
,bLR
);
1258 close_i_nblist(vdwc
);
1261 static void setexcl(atom_id start
,atom_id end
,t_blocka
*excl
,bool b
,
1268 for(i
=start
; i
<end
; i
++)
1270 for(k
=excl
->index
[i
]; k
<excl
->index
[i
+1]; k
++)
1272 SETEXCL(bexcl
,i
-start
,excl
->a
[k
]);
1278 for(i
=start
; i
<end
; i
++)
1280 for(k
=excl
->index
[i
]; k
<excl
->index
[i
+1]; k
++)
1282 RMEXCL(bexcl
,i
-start
,excl
->a
[k
]);
1288 int calc_naaj(int icg
,int cgtot
)
1292 if ((cgtot
% 2) == 1)
1294 /* Odd number of charge groups, easy */
1295 naaj
= 1 + (cgtot
/2);
1297 else if ((cgtot
% 4) == 0)
1299 /* Multiple of four is hard */
1336 fprintf(log
,"naaj=%d\n",naaj
);
1342 /************************************************
1344 * S I M P L E C O R E S T U F F
1346 ************************************************/
1348 static real
calc_image_tric(rvec xi
,rvec xj
,matrix box
,
1349 rvec b_inv
,int *shift
)
1351 /* This code assumes that the cut-off is smaller than
1352 * a half times the smallest diagonal element of the box.
1359 /* Compute diff vector */
1360 dz
= xj
[ZZ
] - xi
[ZZ
];
1361 dy
= xj
[YY
] - xi
[YY
];
1362 dx
= xj
[XX
] - xi
[XX
];
1364 /* Perform NINT operation, using trunc operation, therefore
1365 * we first add 2.5 then subtract 2 again
1367 tz
= dz
*b_inv
[ZZ
] + h25
;
1369 dz
-= tz
*box
[ZZ
][ZZ
];
1370 dy
-= tz
*box
[ZZ
][YY
];
1371 dx
-= tz
*box
[ZZ
][XX
];
1373 ty
= dy
*b_inv
[YY
] + h25
;
1375 dy
-= ty
*box
[YY
][YY
];
1376 dx
-= ty
*box
[YY
][XX
];
1378 tx
= dx
*b_inv
[XX
]+h25
;
1380 dx
-= tx
*box
[XX
][XX
];
1382 /* Distance squared */
1383 r2
= (dx
*dx
) + (dy
*dy
) + (dz
*dz
);
1385 *shift
= XYZ2IS(tx
,ty
,tz
);
1390 static real
calc_image_rect(rvec xi
,rvec xj
,rvec box_size
,
1391 rvec b_inv
,int *shift
)
1399 /* Compute diff vector */
1400 dx
= xj
[XX
] - xi
[XX
];
1401 dy
= xj
[YY
] - xi
[YY
];
1402 dz
= xj
[ZZ
] - xi
[ZZ
];
1404 /* Perform NINT operation, using trunc operation, therefore
1405 * we first add 1.5 then subtract 1 again
1407 tx
= dx
*b_inv
[XX
] + h15
;
1408 ty
= dy
*b_inv
[YY
] + h15
;
1409 tz
= dz
*b_inv
[ZZ
] + h15
;
1414 /* Correct diff vector for translation */
1415 ddx
= tx
*box_size
[XX
] - dx
;
1416 ddy
= ty
*box_size
[YY
] - dy
;
1417 ddz
= tz
*box_size
[ZZ
] - dz
;
1419 /* Distance squared */
1420 r2
= (ddx
*ddx
) + (ddy
*ddy
) + (ddz
*ddz
);
1422 *shift
= XYZ2IS(tx
,ty
,tz
);
1427 static void add_simple(t_ns_buf
*nsbuf
,int nrj
,atom_id cg_j
,
1428 bool bHaveVdW
[],int ngid
,t_mdatoms
*md
,
1429 int icg
,int jgid
,t_block
*cgs
,t_excl bexcl
[],
1430 int shift
,t_forcerec
*fr
,put_in_list_t
*put_in_list
)
1432 if (nsbuf
->nj
+ nrj
> MAX_CG
)
1434 put_in_list(bHaveVdW
,ngid
,md
,icg
,jgid
,nsbuf
->ncg
,nsbuf
->jcg
,
1435 cgs
->index
,bexcl
,shift
,fr
,FALSE
,TRUE
,TRUE
);
1436 /* Reset buffer contents */
1437 nsbuf
->ncg
= nsbuf
->nj
= 0;
1439 nsbuf
->jcg
[nsbuf
->ncg
++] = cg_j
;
1443 static void ns_inner_tric(rvec x
[],int icg
,int *i_egp_flags
,
1444 int njcg
,atom_id jcg
[],
1445 matrix box
,rvec b_inv
,real rcut2
,
1446 t_block
*cgs
,t_ns_buf
**ns_buf
,
1447 bool bHaveVdW
[],int ngid
,t_mdatoms
*md
,
1448 t_excl bexcl
[],t_forcerec
*fr
,
1449 put_in_list_t
*put_in_list
)
1453 int *cginfo
=fr
->cginfo
;
1454 atom_id cg_j
,*cgindex
;
1457 cgindex
= cgs
->index
;
1459 for(j
=0; (j
<njcg
); j
++)
1462 nrj
= cgindex
[cg_j
+1]-cgindex
[cg_j
];
1463 if (calc_image_tric(x
[icg
],x
[cg_j
],box
,b_inv
,&shift
) < rcut2
)
1465 jgid
= GET_CGINFO_GID(cginfo
[cg_j
]);
1466 if (!(i_egp_flags
[jgid
] & EGP_EXCL
))
1468 add_simple(&ns_buf
[jgid
][shift
],nrj
,cg_j
,
1469 bHaveVdW
,ngid
,md
,icg
,jgid
,cgs
,bexcl
,shift
,fr
,
1476 static void ns_inner_rect(rvec x
[],int icg
,int *i_egp_flags
,
1477 int njcg
,atom_id jcg
[],
1478 bool bBox
,rvec box_size
,rvec b_inv
,real rcut2
,
1479 t_block
*cgs
,t_ns_buf
**ns_buf
,
1480 bool bHaveVdW
[],int ngid
,t_mdatoms
*md
,
1481 t_excl bexcl
[],t_forcerec
*fr
,
1482 put_in_list_t
*put_in_list
)
1486 int *cginfo
=fr
->cginfo
;
1487 atom_id cg_j
,*cgindex
;
1490 cgindex
= cgs
->index
;
1494 for(j
=0; (j
<njcg
); j
++)
1497 nrj
= cgindex
[cg_j
+1]-cgindex
[cg_j
];
1498 if (calc_image_rect(x
[icg
],x
[cg_j
],box_size
,b_inv
,&shift
) < rcut2
)
1500 jgid
= GET_CGINFO_GID(cginfo
[cg_j
]);
1501 if (!(i_egp_flags
[jgid
] & EGP_EXCL
))
1503 add_simple(&ns_buf
[jgid
][shift
],nrj
,cg_j
,
1504 bHaveVdW
,ngid
,md
,icg
,jgid
,cgs
,bexcl
,shift
,fr
,
1512 for(j
=0; (j
<njcg
); j
++)
1515 nrj
= cgindex
[cg_j
+1]-cgindex
[cg_j
];
1516 if ((rcut2
== 0) || (distance2(x
[icg
],x
[cg_j
]) < rcut2
)) {
1517 jgid
= GET_CGINFO_GID(cginfo
[cg_j
]);
1518 if (!(i_egp_flags
[jgid
] & EGP_EXCL
))
1520 add_simple(&ns_buf
[jgid
][CENTRAL
],nrj
,cg_j
,
1521 bHaveVdW
,ngid
,md
,icg
,jgid
,cgs
,bexcl
,CENTRAL
,fr
,
1529 /* ns_simple_core needs to be adapted for QMMM still 2005 */
1531 static int ns_simple_core(t_forcerec
*fr
,
1532 gmx_localtop_t
*top
,
1534 matrix box
,rvec box_size
,
1535 t_excl bexcl
[],atom_id
*aaj
,
1536 int ngid
,t_ns_buf
**ns_buf
,
1537 put_in_list_t
*put_in_list
,bool bHaveVdW
[])
1541 int nsearch
,icg
,jcg
,igid
,i0
,nri
,nn
;
1544 /* atom_id *i_atoms; */
1545 t_block
*cgs
=&(top
->cgs
);
1546 t_blocka
*excl
=&(top
->excls
);
1549 bool bBox
,bTriclinic
;
1552 rlist2
= sqr(fr
->rlist
);
1554 bBox
= (fr
->ePBC
!= epbcNONE
);
1557 for(m
=0; (m
<DIM
); m
++)
1559 b_inv
[m
] = divide(1.0,box_size
[m
]);
1561 bTriclinic
= TRICLINIC(box
);
1568 cginfo
= fr
->cginfo
;
1571 for (icg
=fr
->cg0
; (icg
<fr
->hcg
); icg
++)
1574 i0 = cgs->index[icg];
1575 nri = cgs->index[icg+1]-i0;
1576 i_atoms = &(cgs->a[i0]);
1577 i_eg_excl = fr->eg_excl + ngid*md->cENER[*i_atoms];
1578 setexcl(nri,i_atoms,excl,TRUE,bexcl);
1580 igid
= GET_CGINFO_GID(cginfo
[icg
]);
1581 i_egp_flags
= fr
->egp_flags
+ ngid
*igid
;
1582 setexcl(cgs
->index
[icg
],cgs
->index
[icg
+1],excl
,TRUE
,bexcl
);
1584 naaj
=calc_naaj(icg
,cgs
->nr
);
1587 ns_inner_tric(fr
->cg_cm
,icg
,i_egp_flags
,naaj
,&(aaj
[icg
]),
1588 box
,b_inv
,rlist2
,cgs
,ns_buf
,
1589 bHaveVdW
,ngid
,md
,bexcl
,fr
,put_in_list
);
1593 ns_inner_rect(fr
->cg_cm
,icg
,i_egp_flags
,naaj
,&(aaj
[icg
]),
1594 bBox
,box_size
,b_inv
,rlist2
,cgs
,ns_buf
,
1595 bHaveVdW
,ngid
,md
,bexcl
,fr
,put_in_list
);
1599 for(nn
=0; (nn
<ngid
); nn
++)
1601 for(k
=0; (k
<SHIFTS
); k
++)
1603 nsbuf
= &(ns_buf
[nn
][k
]);
1606 put_in_list(bHaveVdW
,ngid
,md
,icg
,nn
,nsbuf
->ncg
,nsbuf
->jcg
,
1607 cgs
->index
,bexcl
,k
,fr
,FALSE
,TRUE
,TRUE
);
1608 nsbuf
->ncg
=nsbuf
->nj
=0;
1612 /* setexcl(nri,i_atoms,excl,FALSE,bexcl); */
1613 setexcl(cgs
->index
[icg
],cgs
->index
[icg
+1],excl
,FALSE
,bexcl
);
1615 close_neighbor_list(fr
,FALSE
,-1,-1,FALSE
);
1620 /************************************************
1622 * N S 5 G R I D S T U F F
1624 ************************************************/
1626 static inline void get_dx(int Nx
,real gridx
,real rc2
,int xgi
,real x
,
1627 int *dx0
,int *dx1
,real
*dcx2
)
1655 for(i
=xgi0
; i
>=0; i
--)
1657 dcx
= (i
+1)*gridx
-x
;
1664 for(i
=xgi1
; i
<Nx
; i
++)
1677 static inline void get_dx_dd(int Nx
,real gridx
,real rc2
,int xgi
,real x
,
1678 int ncpddc
,int shift_min
,int shift_max
,
1679 int *g0
,int *g1
,real
*dcx2
)
1682 int g_min
,g_max
,shift_home
;
1715 g_min
= (shift_min
== shift_home
? 0 : ncpddc
);
1716 g_max
= (shift_max
== shift_home
? ncpddc
- 1 : Nx
- 1);
1723 else if (shift_max
< 0)
1738 /* Check one grid cell down */
1739 dcx
= ((*g0
- 1) + 1)*gridx
- x
;
1751 /* Check one grid cell up */
1752 dcx
= (*g1
+ 1)*gridx
- x
;
1764 #define sqr(x) ((x)*(x))
1765 #define calc_dx2(XI,YI,ZI,y) (sqr(XI-y[XX]) + sqr(YI-y[YY]) + sqr(ZI-y[ZZ]))
1766 #define calc_cyl_dx2(XI,YI,y) (sqr(XI-y[XX]) + sqr(YI-y[YY]))
1767 /****************************************************
1769 * F A S T N E I G H B O R S E A R C H I N G
1771 * Optimized neighboursearching routine using grid
1772 * at least 1x1x1, see GROMACS manual
1774 ****************************************************/
1776 static void do_longrange(t_commrec
*cr
,gmx_localtop_t
*top
,t_forcerec
*fr
,
1777 int ngid
,t_mdatoms
*md
,int icg
,
1779 atom_id lr
[],t_excl bexcl
[],int shift
,
1780 rvec x
[],rvec box_size
,t_nrnb
*nrnb
,
1781 real lambda
,real
*dvdlambda
,
1782 gmx_grppairener_t
*grppener
,
1783 bool bDoVdW
,bool bDoCoul
,
1784 bool bEvaluateNow
,put_in_list_t
*put_in_list
,
1786 bool bDoForces
,rvec
*f
)
1791 for(n
=0; n
<fr
->nnblists
; n
++)
1793 for(i
=0; (i
<eNL_NR
); i
++)
1795 nl
= &fr
->nblists
[n
].nlist_lr
[i
];
1796 if ((nl
->nri
> nl
->maxnri
-32) || bEvaluateNow
)
1798 close_neighbor_list(fr
,TRUE
,n
,i
,FALSE
);
1799 /* Evaluate the energies and forces */
1800 do_nonbonded(cr
,fr
,x
,f
,md
,NULL
,
1801 grppener
->ener
[fr
->bBHAM
? egBHAMLR
: egLJLR
],
1802 grppener
->ener
[egCOULLR
],
1803 grppener
->ener
[egGB
],box_size
,
1804 nrnb
,lambda
,dvdlambda
,n
,i
,
1805 GMX_DONB_LR
| GMX_DONB_FORCES
);
1807 reset_neighbor_list(fr
,TRUE
,n
,i
);
1814 /* Put the long range particles in a list */
1815 /* do_longrange is never called for QMMM */
1816 put_in_list(bHaveVdW
,ngid
,md
,icg
,jgid
,nlr
,lr
,top
->cgs
.index
,
1817 bexcl
,shift
,fr
,TRUE
,bDoVdW
,bDoCoul
);
1821 static void get_cutoff2(t_forcerec
*fr
,bool bDoLongRange
,
1822 real
*rvdw2
,real
*rcoul2
,
1823 real
*rs2
,real
*rm2
,real
*rl2
)
1825 *rs2
= sqr(fr
->rlist
);
1826 if (bDoLongRange
&& fr
->bTwinRange
)
1828 /* The VdW and elec. LR cut-off's could be different,
1829 * so we can not simply set them to rlistlong.
1831 if (EVDW_MIGHT_BE_ZERO_AT_CUTOFF(fr
->vdwtype
) &&
1832 fr
->rvdw
> fr
->rlist
)
1834 *rvdw2
= sqr(fr
->rlistlong
);
1838 *rvdw2
= sqr(fr
->rvdw
);
1840 if (EEL_MIGHT_BE_ZERO_AT_CUTOFF(fr
->eeltype
) &&
1841 fr
->rcoulomb
> fr
->rlist
)
1843 *rcoul2
= sqr(fr
->rlistlong
);
1847 *rcoul2
= sqr(fr
->rcoulomb
);
1852 /* Workaround for a gcc -O3 or -ffast-math problem */
1856 *rm2
= min(*rvdw2
,*rcoul2
);
1857 *rl2
= max(*rvdw2
,*rcoul2
);
1860 static void init_nsgrid_lists(t_forcerec
*fr
,int ngid
,gmx_ns_t
*ns
)
1862 real rvdw2
,rcoul2
,rs2
,rm2
,rl2
;
1865 get_cutoff2(fr
,TRUE
,&rvdw2
,&rcoul2
,&rs2
,&rm2
,&rl2
);
1867 /* Short range buffers */
1868 snew(ns
->nl_sr
,ngid
);
1871 snew(ns
->nlr_ljc
,ngid
);
1872 snew(ns
->nlr_one
,ngid
);
1876 /* Long range VdW and Coul buffers */
1877 snew(ns
->nl_lr_ljc
,ngid
);
1881 /* Long range VdW or Coul only buffers */
1882 snew(ns
->nl_lr_one
,ngid
);
1884 for(j
=0; (j
<ngid
); j
++) {
1885 snew(ns
->nl_sr
[j
],MAX_CG
);
1888 snew(ns
->nl_lr_ljc
[j
],MAX_CG
);
1892 snew(ns
->nl_lr_one
[j
],MAX_CG
);
1898 "ns5_core: rs2 = %g, rm2 = %g, rl2 = %g (nm^2)\n",
1903 static int nsgrid_core(FILE *log
,t_commrec
*cr
,t_forcerec
*fr
,
1904 matrix box
,rvec box_size
,int ngid
,
1905 gmx_localtop_t
*top
,
1906 t_grid
*grid
,rvec x
[],
1907 t_excl bexcl
[],bool *bExcludeAlleg
,
1908 t_nrnb
*nrnb
,t_mdatoms
*md
,
1909 real lambda
,real
*dvdlambda
,
1910 gmx_grppairener_t
*grppener
,
1911 put_in_list_t
*put_in_list
,
1913 bool bDoLongRange
,bool bDoForces
,rvec
*f
,
1914 bool bMakeQMMMnblist
)
1917 atom_id
**nl_lr_ljc
,**nl_lr_one
,**nl_sr
;
1918 int *nlr_ljc
,*nlr_one
,*nsr
;
1919 gmx_domdec_t
*dd
=NULL
;
1920 t_block
*cgs
=&(top
->cgs
);
1921 int *cginfo
=fr
->cginfo
;
1922 /* atom_id *i_atoms,*cgsindex=cgs->index; */
1924 int cell_x
,cell_y
,cell_z
;
1925 int d
,tx
,ty
,tz
,dx
,dy
,dz
,cj
;
1926 #ifdef ALLOW_OFFDIAG_LT_HALFDIAG
1927 int zsh_ty
,zsh_tx
,ysh_tx
;
1929 int dx0
,dx1
,dy0
,dy1
,dz0
,dz1
;
1930 int Nx
,Ny
,Nz
,shift
=-1,j
,nrj
,nns
,nn
=-1;
1931 real gridx
,gridy
,gridz
,grid_x
,grid_y
,grid_z
;
1932 real
*dcx2
,*dcy2
,*dcz2
;
1934 int cg0
,cg1
,icg
=-1,cgsnr
,i0
,igid
,nri
,naaj
,max_jcg
;
1935 int jcg0
,jcg1
,jjcg
,cgj0
,jgid
;
1936 int *grida
,*gridnra
,*gridind
;
1937 bool rvdw_lt_rcoul
,rcoul_lt_rvdw
;
1938 rvec xi
,*cgcm
,grid_offset
;
1939 real r2
,rs2
,rvdw2
,rcoul2
,rm2
,rl2
,XI
,YI
,ZI
,dcx
,dcy
,dcz
,tmp1
,tmp2
;
1941 bool bDomDec
,bTriclinicX
,bTriclinicY
;
1946 bDomDec
= DOMAINDECOMP(cr
);
1952 bTriclinicX
= ((YY
< grid
->npbcdim
&&
1953 (!bDomDec
|| dd
->nc
[YY
]==1) && box
[YY
][XX
] != 0) ||
1954 (ZZ
< grid
->npbcdim
&&
1955 (!bDomDec
|| dd
->nc
[ZZ
]==1) && box
[ZZ
][XX
] != 0));
1956 bTriclinicY
= (ZZ
< grid
->npbcdim
&&
1957 (!bDomDec
|| dd
->nc
[ZZ
]==1) && box
[ZZ
][YY
] != 0);
1961 get_cutoff2(fr
,bDoLongRange
,&rvdw2
,&rcoul2
,&rs2
,&rm2
,&rl2
);
1963 rvdw_lt_rcoul
= (rvdw2
>= rcoul2
);
1964 rcoul_lt_rvdw
= (rcoul2
>= rvdw2
);
1966 if (bMakeQMMMnblist
)
1974 nl_lr_ljc
= ns
->nl_lr_ljc
;
1975 nl_lr_one
= ns
->nl_lr_one
;
1976 nlr_ljc
= ns
->nlr_ljc
;
1977 nlr_one
= ns
->nlr_one
;
1985 gridind
= grid
->index
;
1986 gridnra
= grid
->nra
;
1989 gridx
= grid
->cell_size
[XX
];
1990 gridy
= grid
->cell_size
[YY
];
1991 gridz
= grid
->cell_size
[ZZ
];
1995 copy_rvec(grid
->cell_offset
,grid_offset
);
1996 copy_ivec(grid
->ncpddc
,ncpddc
);
2001 #ifdef ALLOW_OFFDIAG_LT_HALFDIAG
2002 zsh_ty
= floor(-box
[ZZ
][YY
]/box
[YY
][YY
]+0.5);
2003 zsh_tx
= floor(-box
[ZZ
][XX
]/box
[XX
][XX
]+0.5);
2004 ysh_tx
= floor(-box
[YY
][XX
]/box
[XX
][XX
]+0.5);
2005 if (zsh_tx
!=0 && ysh_tx
!=0)
2007 /* This could happen due to rounding, when both ratios are 0.5 */
2016 /* We only want a list for the test particle */
2025 /* Set the shift range */
2026 for(d
=0; d
<DIM
; d
++)
2030 /* Check if we need periodicity shifts.
2031 * Without PBC or with domain decomposition we don't need them.
2033 if (d
>= ePBC2npbcdim(fr
->ePBC
) || (bDomDec
&& dd
->nc
[d
] > 1))
2040 box
[XX
][XX
] - fabs(box
[YY
][XX
]) - fabs(box
[ZZ
][XX
]) < sqrt(rl2
))
2051 /* Loop over charge groups */
2052 for(icg
=cg0
; (icg
< cg1
); icg
++)
2054 igid
= GET_CGINFO_GID(cginfo
[icg
]);
2055 /* Skip this charge group if all energy groups are excluded! */
2056 if (bExcludeAlleg
[igid
])
2061 i0
= cgs
->index
[icg
];
2063 if (bMakeQMMMnblist
)
2065 /* Skip this charge group if it is not a QM atom while making a
2066 * QM/MM neighbourlist
2068 if (md
->bQM
[i0
]==FALSE
)
2070 continue; /* MM particle, go to next particle */
2073 /* Compute the number of charge groups that fall within the control
2076 naaj
= calc_naaj(icg
,cgsnr
);
2083 /* make a normal neighbourlist */
2087 /* Get the j charge-group and dd cell shift ranges */
2088 dd_get_ns_ranges(cr
->dd
,icg
,&jcg0
,&jcg1
,sh0
,sh1
);
2093 /* Compute the number of charge groups that fall within the control
2096 naaj
= calc_naaj(icg
,cgsnr
);
2102 /* The i-particle is awlways the test particle,
2103 * so we want all j-particles
2105 max_jcg
= cgsnr
- 1;
2109 max_jcg
= jcg1
- cgsnr
;
2114 i_egp_flags
= fr
->egp_flags
+ igid
*ngid
;
2116 /* Set the exclusions for the atoms in charge group icg using a bitmask */
2117 setexcl(i0
,cgs
->index
[icg
+1],&top
->excls
,TRUE
,bexcl
);
2119 ci2xyz(grid
,icg
,&cell_x
,&cell_y
,&cell_z
);
2121 /* Changed iicg to icg, DvdS 990115
2122 * (but see consistency check above, DvdS 990330)
2125 fprintf(log
,"icg=%5d, naaj=%5d, cell %d %d %d\n",
2126 icg
,naaj
,cell_x
,cell_y
,cell_z
);
2128 /* Loop over shift vectors in three dimensions */
2129 for (tz
=-shp
[ZZ
]; tz
<=shp
[ZZ
]; tz
++)
2131 ZI
= cgcm
[icg
][ZZ
]+tz
*box
[ZZ
][ZZ
];
2132 /* Calculate range of cells in Z direction that have the shift tz */
2133 zgi
= cell_z
+ tz
*Nz
;
2136 get_dx(Nz
,gridz
,rl2
,zgi
,ZI
,&dz0
,&dz1
,dcz2
);
2138 get_dx_dd(Nz
,gridz
,rl2
,zgi
,ZI
-grid_offset
[ZZ
],
2139 ncpddc
[ZZ
],sh0
[ZZ
],sh1
[ZZ
],&dz0
,&dz1
,dcz2
);
2145 for (ty
=-shp
[YY
]; ty
<=shp
[YY
]; ty
++)
2147 YI
= cgcm
[icg
][YY
]+ty
*box
[YY
][YY
]+tz
*box
[ZZ
][YY
];
2148 /* Calculate range of cells in Y direction that have the shift ty */
2151 ygi
= (int)(Ny
+ (YI
- grid_offset
[YY
])*grid_y
) - Ny
;
2155 ygi
= cell_y
+ ty
*Ny
;
2158 get_dx(Ny
,gridy
,rl2
,ygi
,YI
,&dy0
,&dy1
,dcy2
);
2160 get_dx_dd(Ny
,gridy
,rl2
,ygi
,YI
-grid_offset
[YY
],
2161 ncpddc
[YY
],sh0
[YY
],sh1
[YY
],&dy0
,&dy1
,dcy2
);
2167 for (tx
=-shp
[XX
]; tx
<=shp
[XX
]; tx
++)
2169 XI
= cgcm
[icg
][XX
]+tx
*box
[XX
][XX
]+ty
*box
[YY
][XX
]+tz
*box
[ZZ
][XX
];
2170 /* Calculate range of cells in X direction that have the shift tx */
2173 xgi
= (int)(Nx
+ (XI
- grid_offset
[XX
])*grid_x
) - Nx
;
2177 xgi
= cell_x
+ tx
*Nx
;
2180 get_dx(Nx
,gridx
,rl2
,xgi
*Nx
,XI
,&dx0
,&dx1
,dcx2
);
2182 get_dx_dd(Nx
,gridx
,rl2
,xgi
,XI
-grid_offset
[XX
],
2183 ncpddc
[XX
],sh0
[XX
],sh1
[XX
],&dx0
,&dx1
,dcx2
);
2189 /* Adress: an explicit cg that has a weigthing function of 0 is excluded
2190 * from the neigbour list as it will not interact */
2191 if (fr
->adress_type
!= eAdressOff
){
2192 if (md
->wf
[cgs
->index
[icg
]]==0 && egp_explicit(fr
, igid
)){
2196 /* Get shift vector */
2197 shift
=XYZ2IS(tx
,ty
,tz
);
2199 range_check(shift
,0,SHIFTS
);
2201 for(nn
=0; (nn
<ngid
); nn
++)
2208 fprintf(log
,"shift: %2d, dx0,1: %2d,%2d, dy0,1: %2d,%2d, dz0,1: %2d,%2d\n",
2209 shift
,dx0
,dx1
,dy0
,dy1
,dz0
,dz1
);
2210 fprintf(log
,"cgcm: %8.3f %8.3f %8.3f\n",cgcm
[icg
][XX
],
2211 cgcm
[icg
][YY
],cgcm
[icg
][ZZ
]);
2212 fprintf(log
,"xi: %8.3f %8.3f %8.3f\n",XI
,YI
,ZI
);
2214 for (dx
=dx0
; (dx
<=dx1
); dx
++)
2216 tmp1
= rl2
- dcx2
[dx
];
2217 for (dy
=dy0
; (dy
<=dy1
); dy
++)
2219 tmp2
= tmp1
- dcy2
[dy
];
2222 for (dz
=dz0
; (dz
<=dz1
); dz
++) {
2223 if (tmp2
> dcz2
[dz
]) {
2224 /* Find grid-cell cj in which possible neighbours are */
2225 cj
= xyz2ci(Ny
,Nz
,dx
,dy
,dz
);
2227 /* Check out how many cgs (nrj) there in this cell */
2230 /* Find the offset in the cg list */
2233 /* Check if all j's are out of range so we
2234 * can skip the whole cell.
2235 * Should save some time, especially with DD.
2238 (grida
[cgj0
] >= max_jcg
&&
2239 (grida
[cgj0
] >= jcg1
|| grida
[cgj0
+nrj
-1] < jcg0
)))
2245 for (j
=0; (j
<nrj
); j
++)
2247 jjcg
= grida
[cgj0
+j
];
2249 /* check whether this guy is in range! */
2250 if ((jjcg
>= jcg0
&& jjcg
< jcg1
) ||
2253 r2
=calc_dx2(XI
,YI
,ZI
,cgcm
[jjcg
]);
2255 /* jgid = gid[cgsatoms[cgsindex[jjcg]]]; */
2256 jgid
= GET_CGINFO_GID(cginfo
[jjcg
]);
2257 /* check energy group exclusions */
2258 if (!(i_egp_flags
[jgid
] & EGP_EXCL
))
2262 if (nsr
[jgid
] >= MAX_CG
)
2264 put_in_list(bHaveVdW
,ngid
,md
,icg
,jgid
,
2265 nsr
[jgid
],nl_sr
[jgid
],
2266 cgs
->index
,/* cgsatoms, */ bexcl
,
2267 shift
,fr
,FALSE
,TRUE
,TRUE
);
2270 nl_sr
[jgid
][nsr
[jgid
]++]=jjcg
;
2274 if (nlr_ljc
[jgid
] >= MAX_CG
)
2276 do_longrange(cr
,top
,fr
,ngid
,md
,icg
,jgid
,
2278 nl_lr_ljc
[jgid
],bexcl
,shift
,x
,
2288 nl_lr_ljc
[jgid
][nlr_ljc
[jgid
]++]=jjcg
;
2292 if (nlr_one
[jgid
] >= MAX_CG
) {
2293 do_longrange(cr
,top
,fr
,ngid
,md
,icg
,jgid
,
2295 nl_lr_one
[jgid
],bexcl
,shift
,x
,
2299 rvdw_lt_rcoul
,rcoul_lt_rvdw
,FALSE
,
2305 nl_lr_one
[jgid
][nlr_one
[jgid
]++]=jjcg
;
2317 /* CHECK whether there is anything left in the buffers */
2318 for(nn
=0; (nn
<ngid
); nn
++)
2322 put_in_list(bHaveVdW
,ngid
,md
,icg
,nn
,nsr
[nn
],nl_sr
[nn
],
2323 cgs
->index
, /* cgsatoms, */ bexcl
,
2324 shift
,fr
,FALSE
,TRUE
,TRUE
);
2327 if (nlr_ljc
[nn
] > 0)
2329 do_longrange(cr
,top
,fr
,ngid
,md
,icg
,nn
,nlr_ljc
[nn
],
2330 nl_lr_ljc
[nn
],bexcl
,shift
,x
,box_size
,nrnb
,
2331 lambda
,dvdlambda
,grppener
,TRUE
,TRUE
,FALSE
,
2332 put_in_list
,bHaveVdW
,bDoForces
,f
);
2335 if (nlr_one
[nn
] > 0)
2337 do_longrange(cr
,top
,fr
,ngid
,md
,icg
,nn
,nlr_one
[nn
],
2338 nl_lr_one
[nn
],bexcl
,shift
,x
,box_size
,nrnb
,
2339 lambda
,dvdlambda
,grppener
,
2340 rvdw_lt_rcoul
,rcoul_lt_rvdw
,FALSE
,
2341 put_in_list
,bHaveVdW
,bDoForces
,f
);
2347 /* setexcl(nri,i_atoms,&top->atoms.excl,FALSE,bexcl); */
2348 setexcl(cgs
->index
[icg
],cgs
->index
[icg
+1],&top
->excls
,FALSE
,bexcl
);
2350 /* Perform any left over force calculations */
2351 for (nn
=0; (nn
<ngid
); nn
++)
2355 do_longrange(cr
,top
,fr
,0,md
,icg
,nn
,nlr_ljc
[nn
],
2356 nl_lr_ljc
[nn
],bexcl
,shift
,x
,box_size
,nrnb
,
2357 lambda
,dvdlambda
,grppener
,
2358 TRUE
,TRUE
,TRUE
,put_in_list
,bHaveVdW
,bDoForces
,f
);
2361 do_longrange(cr
,top
,fr
,0,md
,icg
,nn
,nlr_one
[nn
],
2362 nl_lr_one
[nn
],bexcl
,shift
,x
,box_size
,nrnb
,
2363 lambda
,dvdlambda
,grppener
,
2364 rvdw_lt_rcoul
,rcoul_lt_rvdw
,
2365 TRUE
,put_in_list
,bHaveVdW
,bDoForces
,f
);
2370 /* Close off short range neighbourlists */
2371 close_neighbor_list(fr
,FALSE
,-1,-1,bMakeQMMMnblist
);
2376 void ns_realloc_natoms(gmx_ns_t
*ns
,int natoms
)
2380 if (natoms
> ns
->nra_alloc
)
2382 ns
->nra_alloc
= over_alloc_dd(natoms
);
2383 srenew(ns
->bexcl
,ns
->nra_alloc
);
2384 for(i
=0; i
<ns
->nra_alloc
; i
++)
2391 void init_ns(FILE *fplog
,const t_commrec
*cr
,
2392 gmx_ns_t
*ns
,t_forcerec
*fr
,
2393 const gmx_mtop_t
*mtop
,
2396 int mt
,icg
,nr_in_cg
,maxcg
,i
,j
,jcg
,ngid
,ncg
;
2400 /* Compute largest charge groups size (# atoms) */
2402 for(mt
=0; mt
<mtop
->nmoltype
; mt
++) {
2403 cgs
= &mtop
->moltype
[mt
].cgs
;
2404 for (icg
=0; (icg
< cgs
->nr
); icg
++)
2406 nr_in_cg
=max(nr_in_cg
,(int)(cgs
->index
[icg
+1]-cgs
->index
[icg
]));
2410 /* Verify whether largest charge group is <= max cg.
2411 * This is determined by the type of the local exclusion type
2412 * Exclusions are stored in bits. (If the type is not large
2413 * enough, enlarge it, unsigned char -> unsigned short -> unsigned long)
2415 maxcg
= sizeof(t_excl
)*8;
2416 if (nr_in_cg
> maxcg
)
2418 gmx_fatal(FARGS
,"Max #atoms in a charge group: %d > %d\n",
2422 ngid
= mtop
->groups
.grps
[egcENER
].nr
;
2423 snew(ns
->bExcludeAlleg
,ngid
);
2424 for(i
=0; i
<ngid
; i
++) {
2425 ns
->bExcludeAlleg
[i
] = TRUE
;
2426 for(j
=0; j
<ngid
; j
++)
2428 if (!(fr
->egp_flags
[i
*ngid
+j
] & EGP_EXCL
))
2430 ns
->bExcludeAlleg
[i
] = FALSE
;
2437 ns
->grid
= init_grid(fplog
,fr
);
2438 init_nsgrid_lists(fr
,ngid
,ns
);
2443 snew(ns
->ns_buf
,ngid
);
2444 for(i
=0; (i
<ngid
); i
++)
2446 snew(ns
->ns_buf
[i
],SHIFTS
);
2448 ncg
= ncg_mtop(mtop
);
2449 snew(ns
->simple_aaj
,2*ncg
);
2450 for(jcg
=0; (jcg
<ncg
); jcg
++)
2452 ns
->simple_aaj
[jcg
] = jcg
;
2453 ns
->simple_aaj
[jcg
+ncg
] = jcg
;
2457 /* Create array that determines whether or not atoms have VdW */
2458 snew(ns
->bHaveVdW
,fr
->ntype
);
2459 for(i
=0; (i
<fr
->ntype
); i
++)
2461 for(j
=0; (j
<fr
->ntype
); j
++)
2463 ns
->bHaveVdW
[i
] = (ns
->bHaveVdW
[i
] ||
2465 ((BHAMA(fr
->nbfp
,fr
->ntype
,i
,j
) != 0) ||
2466 (BHAMB(fr
->nbfp
,fr
->ntype
,i
,j
) != 0) ||
2467 (BHAMC(fr
->nbfp
,fr
->ntype
,i
,j
) != 0)) :
2468 ((C6(fr
->nbfp
,fr
->ntype
,i
,j
) != 0) ||
2469 (C12(fr
->nbfp
,fr
->ntype
,i
,j
) != 0))));
2473 pr_bvec(debug
,0,"bHaveVdW",ns
->bHaveVdW
,fr
->ntype
,TRUE
);
2477 if (!DOMAINDECOMP(cr
))
2479 /* This could be reduced with particle decomposition */
2480 ns_realloc_natoms(ns
,mtop
->natoms
);
2483 ns
->nblist_initialized
=FALSE
;
2485 /* nbr list debug dump */
2487 char *ptr
=getenv("GMX_DUMP_NL");
2490 ns
->dump_nl
=strtol(ptr
,NULL
,10);
2493 fprintf(fplog
, "GMX_DUMP_NL = %d", ns
->dump_nl
);
2504 int search_neighbours(FILE *log
,t_forcerec
*fr
,
2505 rvec x
[],matrix box
,
2506 gmx_localtop_t
*top
,
2507 gmx_groups_t
*groups
,
2509 t_nrnb
*nrnb
,t_mdatoms
*md
,
2510 real lambda
,real
*dvdlambda
,
2511 gmx_grppairener_t
*grppener
,
2514 bool bDoForces
,rvec
*f
)
2516 t_block
*cgs
=&(top
->cgs
);
2517 rvec box_size
,grid_x0
,grid_x1
;
2519 real min_size
,grid_dens
;
2524 int cg_start
,cg_end
,start
,end
;
2527 gmx_domdec_zones_t
*dd_zones
;
2528 put_in_list_t
*put_in_list
;
2532 /* Set some local variables */
2534 ngid
= groups
->grps
[egcENER
].nr
;
2536 for(m
=0; (m
<DIM
); m
++)
2538 box_size
[m
] = box
[m
][m
];
2541 if (fr
->ePBC
!= epbcNONE
)
2543 if (sqr(fr
->rlistlong
) >= max_cutoff2(fr
->ePBC
,box
))
2545 gmx_fatal(FARGS
,"One of the box vectors has become shorter than twice the cut-off length or box_yy-|box_zy| or box_zz has become smaller than the cut-off.");
2549 min_size
= min(box_size
[XX
],min(box_size
[YY
],box_size
[ZZ
]));
2550 if (2*fr
->rlistlong
>= min_size
)
2551 gmx_fatal(FARGS
,"One of the box diagonal elements has become smaller than twice the cut-off length.");
2555 if (DOMAINDECOMP(cr
))
2557 ns_realloc_natoms(ns
,cgs
->index
[cgs
->nr
]);
2561 /* Reset the neighbourlists */
2562 reset_neighbor_list(fr
,FALSE
,-1,-1);
2564 if (bGrid
&& bFillGrid
)
2568 if (DOMAINDECOMP(cr
))
2570 dd_zones
= domdec_zones(cr
->dd
);
2576 get_nsgrid_boundaries(grid
,NULL
,box
,NULL
,NULL
,NULL
,
2577 cgs
->nr
,fr
->cg_cm
,grid_x0
,grid_x1
,&grid_dens
);
2579 grid_first(log
,grid
,NULL
,NULL
,fr
->ePBC
,box
,grid_x0
,grid_x1
,
2580 fr
->rlistlong
,grid_dens
);
2584 /* Don't know why this all is... (DvdS 3/99) */
2590 end
= (cgs
->nr
+1)/2;
2593 if (DOMAINDECOMP(cr
))
2596 fill_grid(log
,dd_zones
,grid
,end
,-1,end
,fr
->cg_cm
);
2598 grid
->icg1
= dd_zones
->izone
[dd_zones
->nizone
-1].cg1
;
2602 fill_grid(log
,NULL
,grid
,cgs
->nr
,fr
->cg0
,fr
->hcg
,fr
->cg_cm
);
2603 grid
->icg0
= fr
->cg0
;
2604 grid
->icg1
= fr
->hcg
;
2612 calc_elemnr(log
,grid
,start
,end
,cgs
->nr
);
2614 grid_last(log
,grid
,start
,end
,cgs
->nr
);
2618 check_grid(debug
,grid
);
2619 print_grid(debug
,grid
);
2624 /* Set the grid cell index for the test particle only.
2625 * The cell to cg index is not corrected, but that does not matter.
2627 fill_grid(log
,NULL
,ns
->grid
,fr
->hcg
,fr
->hcg
-1,fr
->hcg
,fr
->cg_cm
);
2631 if (!fr
->ns
.bCGlist
)
2633 put_in_list
= put_in_list_at
;
2637 put_in_list
= put_in_list_cg
;
2644 nsearch
= nsgrid_core(log
,cr
,fr
,box
,box_size
,ngid
,top
,
2645 grid
,x
,ns
->bexcl
,ns
->bExcludeAlleg
,
2646 nrnb
,md
,lambda
,dvdlambda
,grppener
,
2647 put_in_list
,ns
->bHaveVdW
,
2648 bDoLongRange
,bDoForces
,f
,
2651 /* neighbour searching withouth QMMM! QM atoms have zero charge in
2652 * the classical calculation. The charge-charge interaction
2653 * between QM and MM atoms is handled in the QMMM core calculation
2654 * (see QMMM.c). The VDW however, we'd like to compute classically
2655 * and the QM MM atom pairs have just been put in the
2656 * corresponding neighbourlists. in case of QMMM we still need to
2657 * fill a special QMMM neighbourlist that contains all neighbours
2658 * of the QM atoms. If bQMMM is true, this list will now be made:
2660 if (fr
->bQMMM
&& fr
->qr
->QMMMscheme
!=eQMMMschemeoniom
)
2662 nsearch
+= nsgrid_core(log
,cr
,fr
,box
,box_size
,ngid
,top
,
2663 grid
,x
,ns
->bexcl
,ns
->bExcludeAlleg
,
2664 nrnb
,md
,lambda
,dvdlambda
,grppener
,
2665 put_in_list_qmmm
,ns
->bHaveVdW
,
2666 bDoLongRange
,bDoForces
,f
,
2672 nsearch
= ns_simple_core(fr
,top
,md
,box
,box_size
,
2673 ns
->bexcl
,ns
->simple_aaj
,
2674 ngid
,ns
->ns_buf
,put_in_list
,ns
->bHaveVdW
);
2682 inc_nrnb(nrnb
,eNR_NS
,nsearch
);
2683 /* inc_nrnb(nrnb,eNR_LR,fr->nlr); */
2688 int natoms_beyond_ns_buffer(t_inputrec
*ir
,t_forcerec
*fr
,t_block
*cgs
,
2689 matrix scale_tot
,rvec
*x
)
2691 int cg0
,cg1
,cg
,a0
,a1
,a
,i
,j
;
2692 real rint
,hbuf2
,scale
;
2699 rint
= max(ir
->rcoulomb
,ir
->rvdw
);
2700 if (ir
->rlist
< rint
)
2702 gmx_fatal(FARGS
,"The neighbor search buffer has negative size: %f nm",
2710 if (!EI_DYNAMICS(ir
->eI
) || !DYNAMIC_BOX(*ir
))
2712 hbuf2
= sqr(0.5*(ir
->rlist
- rint
));
2713 for(cg
=cg0
; cg
<cg1
; cg
++)
2715 a0
= cgs
->index
[cg
];
2716 a1
= cgs
->index
[cg
+1];
2717 for(a
=a0
; a
<a1
; a
++)
2719 if (distance2(cg_cm
[cg
],x
[a
]) > hbuf2
)
2729 scale
= scale_tot
[0][0];
2730 for(i
=1; i
<DIM
; i
++)
2732 /* With anisotropic scaling, the original spherical ns volumes become
2733 * ellipsoids. To avoid costly transformations we use the minimum
2734 * eigenvalue of the scaling matrix for determining the buffer size.
2735 * Since the lower half is 0, the eigenvalues are the diagonal elements.
2737 scale
= min(scale
,scale_tot
[i
][i
]);
2738 if (scale_tot
[i
][i
] != scale_tot
[i
-1][i
-1])
2744 if (scale_tot
[i
][j
] != 0)
2750 hbuf2
= sqr(0.5*(scale
*ir
->rlist
- rint
));
2753 for(cg
=cg0
; cg
<cg1
; cg
++)
2755 svmul(scale
,cg_cm
[cg
],cgsc
);
2756 a0
= cgs
->index
[cg
];
2757 a1
= cgs
->index
[cg
+1];
2758 for(a
=a0
; a
<a1
; a
++)
2760 if (distance2(cgsc
,x
[a
]) > hbuf2
)
2769 /* Anistropic scaling */
2770 for(cg
=cg0
; cg
<cg1
; cg
++)
2772 /* Since scale_tot contains the transpose of the scaling matrix,
2773 * we need to multiply with the transpose.
2775 tmvmul_ur0(scale_tot
,cg_cm
[cg
],cgsc
);
2776 a0
= cgs
->index
[cg
];
2777 a1
= cgs
->index
[cg
+1];
2778 for(a
=a0
; a
<a1
; a
++)
2780 if (distance2(cgsc
,x
[a
]) > hbuf2
)