ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE-3.0/src/UseTheForce/doForces.F90
(Generate patch)

Comparing trunk/OOPSE-3.0/src/UseTheForce/doForces.F90 (file contents):
Revision 2085 by gezelter, Tue Mar 8 21:05:46 2005 UTC vs.
Revision 2350 by chuckv, Mon Oct 10 21:20:46 2005 UTC

# Line 45 | Line 45
45  
46   !! @author Charles F. Vardeman II
47   !! @author Matthew Meineke
48 < !! @version $Id: doForces.F90,v 1.11 2005-03-08 21:05:46 gezelter Exp $, $Date: 2005-03-08 21:05:46 $, $Name: not supported by cvs2svn $, $Revision: 1.11 $
48 > !! @version $Id: doForces.F90,v 1.51 2005-10-10 21:20:46 chuckv Exp $, $Date: 2005-10-10 21:20:46 $, $Name: not supported by cvs2svn $, $Revision: 1.51 $
49  
50  
51   module doForces
# Line 58 | Line 58 | module doForces
58    use lj
59    use sticky
60    use electrostatic_module
61 <  use reaction_field
61 >  use reaction_field_module
62    use gb_pair
63    use shapes
64    use vector_class
# Line 73 | Line 73 | module doForces
73  
74   #define __FORTRAN90
75   #include "UseTheForce/fSwitchingFunction.h"
76 + #include "UseTheForce/fCutoffPolicy.h"
77 + #include "UseTheForce/DarkSide/fInteractionMap.h"
78 + #include "UseTheForce/DarkSide/fElectrostaticSummationMethod.h"
79  
80 +
81    INTEGER, PARAMETER:: PREPAIR_LOOP = 1
82    INTEGER, PARAMETER:: PAIR_LOOP    = 2
83  
80  logical, save :: haveRlist = .false.
84    logical, save :: haveNeighborList = .false.
85    logical, save :: haveSIMvariables = .false.
83  logical, save :: havePropertyMap = .false.
86    logical, save :: haveSaneForceField = .false.
87 <  
87 >  logical, save :: haveInteractionHash = .false.
88 >  logical, save :: haveGtypeCutoffMap = .false.
89 >  logical, save :: haveDefaultCutoffs = .false.
90 >  logical, save :: haveRlist = .false.
91 >
92    logical, save :: FF_uses_DirectionalAtoms
87  logical, save :: FF_uses_LennardJones
88  logical, save :: FF_uses_Electrostatics
89  logical, save :: FF_uses_Charges
93    logical, save :: FF_uses_Dipoles
91  logical, save :: FF_uses_Quadrupoles
92  logical, save :: FF_uses_sticky
94    logical, save :: FF_uses_GayBerne
95    logical, save :: FF_uses_EAM
95  logical, save :: FF_uses_Shapes
96  logical, save :: FF_uses_FLARB
97  logical, save :: FF_uses_RF
96  
97    logical, save :: SIM_uses_DirectionalAtoms
100  logical, save :: SIM_uses_LennardJones
101  logical, save :: SIM_uses_Electrostatics
102  logical, save :: SIM_uses_Charges
103  logical, save :: SIM_uses_Dipoles
104  logical, save :: SIM_uses_Quadrupoles
105  logical, save :: SIM_uses_Sticky
106  logical, save :: SIM_uses_GayBerne
98    logical, save :: SIM_uses_EAM
108  logical, save :: SIM_uses_Shapes
109  logical, save :: SIM_uses_FLARB
110  logical, save :: SIM_uses_RF
99    logical, save :: SIM_requires_postpair_calc
100    logical, save :: SIM_requires_prepair_calc
101    logical, save :: SIM_uses_PBC
114  logical, save :: SIM_uses_molecular_cutoffs
102  
103 <  real(kind=dp), save :: rlist, rlistsq
103 >  integer, save :: electrostaticSummationMethod
104  
105    public :: init_FF
106 +  public :: setDefaultCutoffs
107    public :: do_force_loop
108 <  public :: setRlistDF
108 >  public :: createInteractionHash
109 >  public :: createGtypeCutoffMap
110 >  public :: getStickyCut
111 >  public :: getStickyPowerCut
112 >  public :: getGayBerneCut
113 >  public :: getEAMCut
114 >  public :: getShapeCut
115  
116   #ifdef PROFILE
117    public :: getforcetime
# Line 125 | Line 119 | module doForces
119    real :: forceTimeInitial, forceTimeFinal
120    integer :: nLoops
121   #endif
122 +  
123 +  !! Variables for cutoff mapping and interaction mapping
124 +  ! Bit hash to determine pair-pair interactions.
125 +  integer, dimension(:,:), allocatable :: InteractionHash
126 +  real(kind=dp), dimension(:), allocatable :: atypeMaxCutoff
127 +  real(kind=dp), dimension(:), allocatable, target :: groupMaxCutoffRow
128 +  real(kind=dp), dimension(:), pointer :: groupMaxCutoffCol
129  
130 <  type :: Properties
131 <     logical :: is_Directional   = .false.
131 <     logical :: is_LennardJones  = .false.
132 <     logical :: is_Electrostatic = .false.
133 <     logical :: is_Charge        = .false.
134 <     logical :: is_Dipole        = .false.
135 <     logical :: is_Quadrupole    = .false.
136 <     logical :: is_Sticky        = .false.
137 <     logical :: is_GayBerne      = .false.
138 <     logical :: is_EAM           = .false.
139 <     logical :: is_Shape         = .false.
140 <     logical :: is_FLARB         = .false.
141 <  end type Properties
130 >  integer, dimension(:), allocatable, target :: groupToGtypeRow
131 >  integer, dimension(:), pointer :: groupToGtypeCol => null()
132  
133 <  type(Properties), dimension(:),allocatable :: PropertyMap
133 >  real(kind=dp), dimension(:), allocatable,target :: gtypeMaxCutoffRow
134 >  real(kind=dp), dimension(:), pointer :: gtypeMaxCutoffCol
135 >  type ::gtypeCutoffs
136 >     real(kind=dp) :: rcut
137 >     real(kind=dp) :: rcutsq
138 >     real(kind=dp) :: rlistsq
139 >  end type gtypeCutoffs
140 >  type(gtypeCutoffs), dimension(:,:), allocatable :: gtypeCutoffMap
141  
142 +  integer, save :: cutoffPolicy = TRADITIONAL_CUTOFF_POLICY
143 +  real(kind=dp),save :: defaultRcut, defaultRsw, defaultRlist
144 +  real(kind=dp),save :: listSkin
145 +  
146   contains
147  
148 <  subroutine setRlistDF( this_rlist )
148 <    
149 <    real(kind=dp) :: this_rlist
150 <
151 <    rlist = this_rlist
152 <    rlistsq = rlist * rlist
153 <    
154 <    haveRlist = .true.
155 <
156 <  end subroutine setRlistDF    
157 <
158 <  subroutine createPropertyMap(status)
148 >  subroutine createInteractionHash(status)
149      integer :: nAtypes
150 <    integer :: status
150 >    integer, intent(out) :: status
151      integer :: i
152 <    logical :: thisProperty
153 <    real (kind=DP) :: thisDPproperty
152 >    integer :: j
153 >    integer :: iHash
154 >    !! Test Types
155 >    logical :: i_is_LJ
156 >    logical :: i_is_Elect
157 >    logical :: i_is_Sticky
158 >    logical :: i_is_StickyP
159 >    logical :: i_is_GB
160 >    logical :: i_is_EAM
161 >    logical :: i_is_Shape
162 >    logical :: j_is_LJ
163 >    logical :: j_is_Elect
164 >    logical :: j_is_Sticky
165 >    logical :: j_is_StickyP
166 >    logical :: j_is_GB
167 >    logical :: j_is_EAM
168 >    logical :: j_is_Shape
169 >    real(kind=dp) :: myRcut
170  
171 <    status = 0
171 >    status = 0  
172  
173 +    if (.not. associated(atypes)) then
174 +       call handleError("atype", "atypes was not present before call of createInteractionHash!")
175 +       status = -1
176 +       return
177 +    endif
178 +    
179      nAtypes = getSize(atypes)
180 <
180 >    
181      if (nAtypes == 0) then
182         status = -1
183         return
184      end if
185 <        
186 <    if (.not. allocated(PropertyMap)) then
187 <       allocate(PropertyMap(nAtypes))
185 >
186 >    if (.not. allocated(InteractionHash)) then
187 >       allocate(InteractionHash(nAtypes,nAtypes))
188      endif
189  
190 +    if (.not. allocated(atypeMaxCutoff)) then
191 +       allocate(atypeMaxCutoff(nAtypes))
192 +    endif
193 +        
194      do i = 1, nAtypes
195 <       call getElementProperty(atypes, i, "is_Directional", thisProperty)
196 <       PropertyMap(i)%is_Directional = thisProperty
195 >       call getElementProperty(atypes, i, "is_LennardJones", i_is_LJ)
196 >       call getElementProperty(atypes, i, "is_Electrostatic", i_is_Elect)
197 >       call getElementProperty(atypes, i, "is_Sticky", i_is_Sticky)
198 >       call getElementProperty(atypes, i, "is_StickyPower", i_is_StickyP)
199 >       call getElementProperty(atypes, i, "is_GayBerne", i_is_GB)
200 >       call getElementProperty(atypes, i, "is_EAM", i_is_EAM)
201 >       call getElementProperty(atypes, i, "is_Shape", i_is_Shape)
202  
203 <       call getElementProperty(atypes, i, "is_LennardJones", thisProperty)
183 <       PropertyMap(i)%is_LennardJones = thisProperty
184 <      
185 <       call getElementProperty(atypes, i, "is_Electrostatic", thisProperty)
186 <       PropertyMap(i)%is_Electrostatic = thisProperty
203 >       do j = i, nAtypes
204  
205 <       call getElementProperty(atypes, i, "is_Charge", thisProperty)
206 <       PropertyMap(i)%is_Charge = thisProperty
190 <      
191 <       call getElementProperty(atypes, i, "is_Dipole", thisProperty)
192 <       PropertyMap(i)%is_Dipole = thisProperty
205 >          iHash = 0
206 >          myRcut = 0.0_dp
207  
208 <       call getElementProperty(atypes, i, "is_Quadrupole", thisProperty)
209 <       PropertyMap(i)%is_Quadrupole = thisProperty
208 >          call getElementProperty(atypes, j, "is_LennardJones", j_is_LJ)
209 >          call getElementProperty(atypes, j, "is_Electrostatic", j_is_Elect)
210 >          call getElementProperty(atypes, j, "is_Sticky", j_is_Sticky)
211 >          call getElementProperty(atypes, j, "is_StickyPower", j_is_StickyP)
212 >          call getElementProperty(atypes, j, "is_GayBerne", j_is_GB)
213 >          call getElementProperty(atypes, j, "is_EAM", j_is_EAM)
214 >          call getElementProperty(atypes, j, "is_Shape", j_is_Shape)
215  
216 <       call getElementProperty(atypes, i, "is_Sticky", thisProperty)
217 <       PropertyMap(i)%is_Sticky = thisProperty
216 >          if (i_is_LJ .and. j_is_LJ) then
217 >             iHash = ior(iHash, LJ_PAIR)            
218 >          endif
219 >          
220 >          if (i_is_Elect .and. j_is_Elect) then
221 >             iHash = ior(iHash, ELECTROSTATIC_PAIR)
222 >          endif
223 >          
224 >          if (i_is_Sticky .and. j_is_Sticky) then
225 >             iHash = ior(iHash, STICKY_PAIR)
226 >          endif
227  
228 <       call getElementProperty(atypes, i, "is_GayBerne", thisProperty)
229 <       PropertyMap(i)%is_GayBerne = thisProperty
228 >          if (i_is_StickyP .and. j_is_StickyP) then
229 >             iHash = ior(iHash, STICKYPOWER_PAIR)
230 >          endif
231  
232 <       call getElementProperty(atypes, i, "is_EAM", thisProperty)
233 <       PropertyMap(i)%is_EAM = thisProperty
232 >          if (i_is_EAM .and. j_is_EAM) then
233 >             iHash = ior(iHash, EAM_PAIR)
234 >          endif
235  
236 <       call getElementProperty(atypes, i, "is_Shape", thisProperty)
237 <       PropertyMap(i)%is_Shape = thisProperty
236 >          if (i_is_GB .and. j_is_GB) iHash = ior(iHash, GAYBERNE_PAIR)
237 >          if (i_is_GB .and. j_is_LJ) iHash = ior(iHash, GAYBERNE_LJ)
238 >          if (i_is_LJ .and. j_is_GB) iHash = ior(iHash, GAYBERNE_LJ)
239  
240 <       call getElementProperty(atypes, i, "is_FLARB", thisProperty)
241 <       PropertyMap(i)%is_FLARB = thisProperty
240 >          if (i_is_Shape .and. j_is_Shape) iHash = ior(iHash, SHAPE_PAIR)
241 >          if (i_is_Shape .and. j_is_LJ) iHash = ior(iHash, SHAPE_LJ)
242 >          if (i_is_LJ .and. j_is_Shape) iHash = ior(iHash, SHAPE_LJ)
243 >
244 >
245 >          InteractionHash(i,j) = iHash
246 >          InteractionHash(j,i) = iHash
247 >
248 >       end do
249 >
250      end do
251  
252 <    havePropertyMap = .true.
252 >    haveInteractionHash = .true.
253 >  end subroutine createInteractionHash
254  
255 <  end subroutine createPropertyMap
255 >  subroutine createGtypeCutoffMap(stat)
256 >
257 >    integer, intent(out), optional :: stat
258 >    logical :: i_is_LJ
259 >    logical :: i_is_Elect
260 >    logical :: i_is_Sticky
261 >    logical :: i_is_StickyP
262 >    logical :: i_is_GB
263 >    logical :: i_is_EAM
264 >    logical :: i_is_Shape
265 >    logical :: GtypeFound
266 >
267 >    integer :: myStatus, nAtypes,  i, j, istart, iend, jstart, jend
268 >    integer :: n_in_i, me_i, ia, g, atom1
269 >    integer :: nGroupsInRow
270 >    integer :: nGroupsInCol
271 >    integer :: nGroupTypesRow,nGroupTypesCol
272 >    real(kind=dp):: thisSigma, bigSigma, thisRcut, tradRcut, tol, skin
273 >    real(kind=dp) :: biggestAtypeCutoff
274 >
275 >    stat = 0
276 >    if (.not. haveInteractionHash) then
277 >       call createInteractionHash(myStatus)      
278 >       if (myStatus .ne. 0) then
279 >          write(default_error, *) 'createInteractionHash failed in doForces!'
280 >          stat = -1
281 >          return
282 >       endif
283 >    endif
284 > #ifdef IS_MPI
285 >    nGroupsInRow = getNgroupsInRow(plan_group_row)
286 >    nGroupsInCol = getNgroupsInCol(plan_group_col)
287 > #endif
288 >    nAtypes = getSize(atypes)
289 > ! Set all of the initial cutoffs to zero.
290 >    atypeMaxCutoff = 0.0_dp
291 >    do i = 1, nAtypes
292 >       if (SimHasAtype(i)) then    
293 >          call getElementProperty(atypes, i, "is_LennardJones", i_is_LJ)
294 >          call getElementProperty(atypes, i, "is_Electrostatic", i_is_Elect)
295 >          call getElementProperty(atypes, i, "is_Sticky", i_is_Sticky)
296 >          call getElementProperty(atypes, i, "is_StickyPower", i_is_StickyP)
297 >          call getElementProperty(atypes, i, "is_GayBerne", i_is_GB)
298 >          call getElementProperty(atypes, i, "is_EAM", i_is_EAM)
299 >          call getElementProperty(atypes, i, "is_Shape", i_is_Shape)
300 >          
301 >
302 >          if (haveDefaultCutoffs) then
303 >             atypeMaxCutoff(i) = defaultRcut
304 >          else
305 >             if (i_is_LJ) then          
306 >                thisRcut = getSigma(i) * 2.5_dp
307 >                if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
308 >             endif
309 >             if (i_is_Elect) then
310 >                thisRcut = defaultRcut
311 >                if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
312 >             endif
313 >             if (i_is_Sticky) then
314 >                thisRcut = getStickyCut(i)
315 >                if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
316 >             endif
317 >             if (i_is_StickyP) then
318 >                thisRcut = getStickyPowerCut(i)
319 >                if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
320 >             endif
321 >             if (i_is_GB) then
322 >                thisRcut = getGayBerneCut(i)
323 >                if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
324 >             endif
325 >             if (i_is_EAM) then
326 >                thisRcut = getEAMCut(i)
327 >                if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
328 >             endif
329 >             if (i_is_Shape) then
330 >                thisRcut = getShapeCut(i)
331 >                if (thisRCut .gt. atypeMaxCutoff(i)) atypeMaxCutoff(i) = thisRCut
332 >             endif
333 >          endif
334 >          
335 >          
336 >          if (atypeMaxCutoff(i).gt.biggestAtypeCutoff) then
337 >             biggestAtypeCutoff = atypeMaxCutoff(i)
338 >          endif
339 >
340 >       endif
341 >    enddo
342 >  
343 >
344 >    
345 >    istart = 1
346 >    jstart = 1
347 > #ifdef IS_MPI
348 >    iend = nGroupsInRow
349 >    jend = nGroupsInCol
350 > #else
351 >    iend = nGroups
352 >    jend = nGroups
353 > #endif
354 >    
355 >    !! allocate the groupToGtype and gtypeMaxCutoff here.
356 >    if(.not.allocated(groupToGtypeRow)) then
357 >     !  allocate(groupToGtype(iend))
358 >       allocate(groupToGtypeRow(iend))
359 >    else
360 >       deallocate(groupToGtypeRow)
361 >       allocate(groupToGtypeRow(iend))
362 >    endif
363 >    if(.not.allocated(groupMaxCutoffRow)) then
364 >       allocate(groupMaxCutoffRow(iend))
365 >    else
366 >       deallocate(groupMaxCutoffRow)
367 >       allocate(groupMaxCutoffRow(iend))
368 >    end if
369 >
370 >    if(.not.allocated(gtypeMaxCutoffRow)) then
371 >       allocate(gtypeMaxCutoffRow(iend))
372 >    else
373 >       deallocate(gtypeMaxCutoffRow)
374 >       allocate(gtypeMaxCutoffRow(iend))
375 >    endif
376 >
377 >
378 > #ifdef IS_MPI
379 >       ! We only allocate new storage if we are in MPI because Ncol /= Nrow
380 >    if(.not.allocated(groupToGtypeCol)) then
381 >       allocate(groupToGtypeCol(jend))
382 >    else
383 >       deallocate(groupToGtypeCol)
384 >       allocate(groupToGtypeCol(jend))
385 >    end if
386 >
387 >    if(.not.allocated(groupToGtypeCol)) then
388 >       allocate(groupToGtypeCol(jend))
389 >    else
390 >       deallocate(groupToGtypeCol)
391 >       allocate(groupToGtypeCol(jend))
392 >    end if
393 >    if(.not.allocated(gtypeMaxCutoffCol)) then
394 >       allocate(gtypeMaxCutoffCol(jend))
395 >    else
396 >       deallocate(gtypeMaxCutoffCol)      
397 >       allocate(gtypeMaxCutoffCol(jend))
398 >    end if
399 >
400 >       groupMaxCutoffCol = 0.0_dp
401 >       gtypeMaxCutoffCol = 0.0_dp
402 >
403 > #endif
404 >       groupMaxCutoffRow = 0.0_dp
405 >       gtypeMaxCutoffRow = 0.0_dp
406 >
407 >
408 >    !! first we do a single loop over the cutoff groups to find the
409 >    !! largest cutoff for any atypes present in this group.  We also
410 >    !! create gtypes at this point.
411 >    
412 >    tol = 1.0d-6
413 >    nGroupTypesRow = 0
414 >
415 >    do i = istart, iend      
416 >       n_in_i = groupStartRow(i+1) - groupStartRow(i)
417 >       groupMaxCutoffRow(i) = 0.0_dp
418 >       do ia = groupStartRow(i), groupStartRow(i+1)-1
419 >          atom1 = groupListRow(ia)
420 > #ifdef IS_MPI
421 >          me_i = atid_row(atom1)
422 > #else
423 >          me_i = atid(atom1)
424 > #endif          
425 >          if (atypeMaxCutoff(me_i).gt.groupMaxCutoffRow(i)) then
426 >             groupMaxCutoffRow(i)=atypeMaxCutoff(me_i)
427 >          endif          
428 >       enddo
429 >
430 >       if (nGroupTypesRow.eq.0) then
431 >          nGroupTypesRow = nGroupTypesRow + 1
432 >          gtypeMaxCutoffRow(nGroupTypesRow) = groupMaxCutoffRow(i)
433 >          groupToGtypeRow(i) = nGroupTypesRow
434 >       else
435 >          GtypeFound = .false.
436 >          do g = 1, nGroupTypesRow
437 >             if ( abs(groupMaxCutoffRow(i) - gtypeMaxCutoffRow(g)).lt.tol) then
438 >                groupToGtypeRow(i) = g
439 >                GtypeFound = .true.
440 >             endif
441 >          enddo
442 >          if (.not.GtypeFound) then            
443 >             nGroupTypesRow = nGroupTypesRow + 1
444 >             gtypeMaxCutoffRow(nGroupTypesRow) = groupMaxCutoffRow(i)
445 >             groupToGtypeRow(i) = nGroupTypesRow
446 >          endif
447 >       endif
448 >    enddo    
449  
450 + #ifdef IS_MPI
451 +    do j = jstart, jend      
452 +       n_in_j = groupStartCol(j+1) - groupStartCol(j)
453 +       groupMaxCutoffCol(j) = 0.0_dp
454 +       do ja = groupStartCol(j), groupStartCol(j+1)-1
455 +          atom1 = groupListCol(ja)
456 +
457 +          me_j = atid_col(atom1)
458 +
459 +          if (atypeMaxCutoff(me_j).gt.groupMaxCutoffCol(j)) then
460 +             groupMaxCutoffCol(j)=atypeMaxCutoff(me_j)
461 +          endif          
462 +       enddo
463 +
464 +       if (nGroupTypesCol.eq.0) then
465 +          nGroupTypesCol = nGroupTypesCol + 1
466 +          gtypeMaxCutoffCol(nGroupTypesCol) = groupMaxCutoffCol(j)
467 +          groupToGtypeCol(j) = nGroupTypesCol
468 +       else
469 +          GtypeFound = .false.
470 +          do g = 1, nGroupTypesCol
471 +             if ( abs(groupMaxCutoffCol(j) - gtypeMaxCutoffCol(g)).lt.tol) then
472 +                groupToGtypeCol(j) = g
473 +                GtypeFound = .true.
474 +             endif
475 +          enddo
476 +          if (.not.GtypeFound) then            
477 +             nGroupTypesCol = nGroupTypesCol + 1
478 +             gtypeMaxCutoffCol(nGroupTypesCol) = groupMaxCutoffCol(j)
479 +             groupToGtypeCol(j) = nGroupTypesCol
480 +          endif
481 +       endif
482 +    enddo    
483 +
484 + #else
485 + ! Set pointers to information we just found
486 +    nGroupTypesCol = nGroupTypesRow
487 +    groupToGtypeCol => groupToGtypeRow
488 +    gtypeMaxCutoffCol => gtypeMaxCutoffRow
489 +    groupMaxCutoffCol => groupMaxCutoffRow
490 + #endif
491 +
492 +
493 +
494 +
495 +
496 +    !! allocate the gtypeCutoffMap here.
497 +    allocate(gtypeCutoffMap(nGroupTypesRow,nGroupTypesCol))
498 +    !! then we do a double loop over all the group TYPES to find the cutoff
499 +    !! map between groups of two types
500 +    tradRcut = max(maxval(gtypeMaxCutoffRow),maxval(gtypeMaxCutoffCol))
501 +
502 +    do i = 1, nGroupTypesRow
503 +       do j = 1, nGroupTypesCol
504 +      
505 +          select case(cutoffPolicy)
506 +          case(TRADITIONAL_CUTOFF_POLICY)
507 +             thisRcut = tradRcut
508 +          case(MIX_CUTOFF_POLICY)
509 +             thisRcut = 0.5_dp * (gtypeMaxCutoffRow(i) + gtypeMaxCutoffCol(j))
510 +          case(MAX_CUTOFF_POLICY)
511 +             thisRcut = max(gtypeMaxCutoffRow(i), gtypeMaxCutoffCol(j))
512 +          case default
513 +             call handleError("createGtypeCutoffMap", "Unknown Cutoff Policy")
514 +             return
515 +          end select
516 +          gtypeCutoffMap(i,j)%rcut = thisRcut
517 +          gtypeCutoffMap(i,j)%rcutsq = thisRcut*thisRcut
518 +          skin = defaultRlist - defaultRcut
519 +          listSkin = skin ! set neighbor list skin thickness
520 +          gtypeCutoffMap(i,j)%rlistsq = (thisRcut + skin)**2
521 +
522 +          ! sanity check
523 +
524 +          if (haveDefaultCutoffs) then
525 +             if (abs(gtypeCutoffMap(i,j)%rcut - defaultRcut).gt.0.0001) then
526 +                call handleError("createGtypeCutoffMap", "user-specified rCut does not match computed group Cutoff")
527 +             endif
528 +          endif
529 +       enddo
530 +    enddo
531 +    if(allocated(gtypeMaxCutoffRow)) deallocate(gtypeMaxCutoffRow)
532 +    if(allocated(groupMaxCutoffRow)) deallocate(groupMaxCutoffRow)
533 +    if(allocated(atypeMaxCutoff)) deallocate(atypeMaxCutoff)
534 + #ifdef IS_MPI
535 +    if(associated(groupMaxCutoffCol)) deallocate(groupMaxCutoffCol)
536 +    if(associated(gtypeMaxCutoffCol)) deallocate(gtypeMaxCutoffCol)
537 + #endif
538 +    groupMaxCutoffCol => null()
539 +    gtypeMaxCutoffCol => null()
540 +    
541 +    haveGtypeCutoffMap = .true.
542 +   end subroutine createGtypeCutoffMap
543 +
544 +   subroutine setDefaultCutoffs(defRcut, defRsw, defRlist, cutPolicy)
545 +     real(kind=dp),intent(in) :: defRcut, defRsw, defRlist
546 +     integer, intent(in) :: cutPolicy
547 +
548 +     defaultRcut = defRcut
549 +     defaultRsw = defRsw
550 +     defaultRlist = defRlist
551 +     cutoffPolicy = cutPolicy
552 +
553 +     haveDefaultCutoffs = .true.
554 +   end subroutine setDefaultCutoffs
555 +
556 +   subroutine setCutoffPolicy(cutPolicy)
557 +
558 +     integer, intent(in) :: cutPolicy
559 +     cutoffPolicy = cutPolicy
560 +     call createGtypeCutoffMap()
561 +   end subroutine setCutoffPolicy
562 +    
563 +    
564    subroutine setSimVariables()
565      SIM_uses_DirectionalAtoms = SimUsesDirectionalAtoms()
219    SIM_uses_LennardJones = SimUsesLennardJones()
220    SIM_uses_Electrostatics = SimUsesElectrostatics()
221    SIM_uses_Charges = SimUsesCharges()
222    SIM_uses_Dipoles = SimUsesDipoles()
223    SIM_uses_Sticky = SimUsesSticky()
224    SIM_uses_GayBerne = SimUsesGayBerne()
566      SIM_uses_EAM = SimUsesEAM()
226    SIM_uses_Shapes = SimUsesShapes()
227    SIM_uses_FLARB = SimUsesFLARB()
228    SIM_uses_RF = SimUsesRF()
567      SIM_requires_postpair_calc = SimRequiresPostpairCalc()
568      SIM_requires_prepair_calc = SimRequiresPrepairCalc()
569      SIM_uses_PBC = SimUsesPBC()
# Line 241 | Line 579 | contains
579      integer :: myStatus
580  
581      error = 0
244    
245    if (.not. havePropertyMap) then
582  
583 <       myStatus = 0
583 >    if (.not. haveInteractionHash) then      
584 >       myStatus = 0      
585 >       call createInteractionHash(myStatus)      
586 >       if (myStatus .ne. 0) then
587 >          write(default_error, *) 'createInteractionHash failed in doForces!'
588 >          error = -1
589 >          return
590 >       endif
591 >    endif
592  
593 <       call createPropertyMap(myStatus)
594 <
593 >    if (.not. haveGtypeCutoffMap) then        
594 >       myStatus = 0      
595 >       call createGtypeCutoffMap(myStatus)      
596         if (myStatus .ne. 0) then
597 <          write(default_error, *) 'createPropertyMap failed in doForces!'
597 >          write(default_error, *) 'createGtypeCutoffMap failed in doForces!'
598            error = -1
599            return
600         endif
# Line 259 | Line 604 | contains
604         call setSimVariables()
605      endif
606  
607 <    if (.not. haveRlist) then
608 <       write(default_error, *) 'rList has not been set in doForces!'
609 <       error = -1
610 <       return
611 <    endif
607 >  !  if (.not. haveRlist) then
608 >  !     write(default_error, *) 'rList has not been set in doForces!'
609 >  !     error = -1
610 >  !     return
611 >  !  endif
612  
613      if (.not. haveNeighborList) then
614         write(default_error, *) 'neighbor list has not been initialized in doForces!'
# Line 286 | Line 631 | contains
631   #endif
632      return
633    end subroutine doReadyCheck
289    
634  
291  subroutine init_FF(use_RF_c, thisStat)
635  
636 <    logical, intent(in) :: use_RF_c
636 >  subroutine init_FF(thisESM, thisStat)
637  
638 +    integer, intent(in) :: thisESM
639      integer, intent(out) :: thisStat  
640      integer :: my_status, nMatches
641      integer, pointer :: MatchList(:) => null()
# Line 300 | Line 644 | contains
644      !! assume things are copacetic, unless they aren't
645      thisStat = 0
646  
647 <    !! Fortran's version of a cast:
648 <    FF_uses_RF = use_RF_c
305 <    
647 >    electrostaticSummationMethod = thisESM
648 >
649      !! init_FF is called *after* all of the atom types have been
650      !! defined in atype_module using the new_atype subroutine.
651      !!
652      !! this will scan through the known atypes and figure out what
653      !! interactions are used by the force field.    
654 <  
654 >
655      FF_uses_DirectionalAtoms = .false.
313    FF_uses_LennardJones = .false.
314    FF_uses_Electrostatics = .false.
315    FF_uses_Charges = .false.    
656      FF_uses_Dipoles = .false.
317    FF_uses_Sticky = .false.
657      FF_uses_GayBerne = .false.
658      FF_uses_EAM = .false.
659 <    FF_uses_Shapes = .false.
321 <    FF_uses_FLARB = .false.
322 <    
659 >
660      call getMatchingElementList(atypes, "is_Directional", .true., &
661           nMatches, MatchList)
662      if (nMatches .gt. 0) FF_uses_DirectionalAtoms = .true.
663  
327    call getMatchingElementList(atypes, "is_LennardJones", .true., &
328         nMatches, MatchList)
329    if (nMatches .gt. 0) FF_uses_LennardJones = .true.
330    
331    call getMatchingElementList(atypes, "is_Electrostatic", .true., &
332         nMatches, MatchList)
333    if (nMatches .gt. 0) then
334       FF_uses_Electrostatics = .true.
335    endif
336
337    call getMatchingElementList(atypes, "is_Charge", .true., &
338         nMatches, MatchList)
339    if (nMatches .gt. 0) then
340       FF_uses_Charges = .true.  
341       FF_uses_Electrostatics = .true.
342    endif
343    
664      call getMatchingElementList(atypes, "is_Dipole", .true., &
665           nMatches, MatchList)
666 <    if (nMatches .gt. 0) then
347 <       FF_uses_Dipoles = .true.
348 <       FF_uses_Electrostatics = .true.
349 <       FF_uses_DirectionalAtoms = .true.
350 <    endif
351 <
352 <    call getMatchingElementList(atypes, "is_Quadrupole", .true., &
353 <         nMatches, MatchList)
354 <    if (nMatches .gt. 0) then
355 <       FF_uses_Quadrupoles = .true.
356 <       FF_uses_Electrostatics = .true.
357 <       FF_uses_DirectionalAtoms = .true.
358 <    endif
666 >    if (nMatches .gt. 0) FF_uses_Dipoles = .true.
667      
360    call getMatchingElementList(atypes, "is_Sticky", .true., nMatches, &
361         MatchList)
362    if (nMatches .gt. 0) then
363       FF_uses_Sticky = .true.
364       FF_uses_DirectionalAtoms = .true.
365    endif
366    
668      call getMatchingElementList(atypes, "is_GayBerne", .true., &
669           nMatches, MatchList)
670 <    if (nMatches .gt. 0) then
671 <       FF_uses_GayBerne = .true.
371 <       FF_uses_DirectionalAtoms = .true.
372 <    endif
373 <    
670 >    if (nMatches .gt. 0) FF_uses_GayBerne = .true.
671 >
672      call getMatchingElementList(atypes, "is_EAM", .true., nMatches, MatchList)
673      if (nMatches .gt. 0) FF_uses_EAM = .true.
376    
377    call getMatchingElementList(atypes, "is_Shape", .true., &
378         nMatches, MatchList)
379    if (nMatches .gt. 0) then
380       FF_uses_Shapes = .true.
381       FF_uses_DirectionalAtoms = .true.
382    endif
674  
384    call getMatchingElementList(atypes, "is_FLARB", .true., &
385         nMatches, MatchList)
386    if (nMatches .gt. 0) FF_uses_FLARB = .true.
675  
388    !! Assume sanity (for the sake of argument)
676      haveSaneForceField = .true.
677 <    
678 <    !! check to make sure the FF_uses_RF setting makes sense
679 <    
680 <    if (FF_uses_dipoles) then
681 <       if (FF_uses_RF) then
677 >
678 >    !! check to make sure the reaction field setting makes sense
679 >
680 >    if (FF_uses_Dipoles) then
681 >       if (electrostaticSummationMethod == REACTION_FIELD) then
682            dielect = getDielect()
683            call initialize_rf(dielect)
684         endif
685      else
686 <       if (FF_uses_RF) then          
686 >       if (electrostaticSummationMethod == REACTION_FIELD) then
687            write(default_error,*) 'Using Reaction Field with no dipoles?  Huh?'
688            thisStat = -1
689            haveSaneForceField = .false.
690            return
691         endif
692 <    endif
692 >    endif
693  
407    !sticky module does not contain check_sticky_FF anymore
408    !if (FF_uses_sticky) then
409    !   call check_sticky_FF(my_status)
410    !   if (my_status /= 0) then
411    !      thisStat = -1
412    !      haveSaneForceField = .false.
413    !      return
414    !   end if
415    !endif
416
694      if (FF_uses_EAM) then
695 <         call init_EAM_FF(my_status)
695 >       call init_EAM_FF(my_status)
696         if (my_status /= 0) then
697            write(default_error, *) "init_EAM_FF returned a bad status"
698            thisStat = -1
# Line 433 | Line 710 | contains
710         endif
711      endif
712  
436    if (FF_uses_GayBerne .and. FF_uses_LennardJones) then
437    endif
438    
713      if (.not. haveNeighborList) then
714         !! Create neighbor lists
715         call expandNeighborList(nLocal, my_status)
# Line 445 | Line 719 | contains
719            return
720         endif
721         haveNeighborList = .true.
722 <    endif    
723 <    
722 >    endif
723 >
724    end subroutine init_FF
451  
725  
726 +
727    !! Does force loop over i,j pairs. Calls do_pair to calculates forces.
728    !------------------------------------------------------------->
729    subroutine do_force_loop(q, q_group, A, eFrame, f, t, tau, pot, &
# Line 499 | Line 773 | contains
773      integer :: localError
774      integer :: propPack_i, propPack_j
775      integer :: loopStart, loopEnd, loop
776 +    integer :: iHash
777 +  
778  
503    real(kind=dp) :: listSkin = 1.0  
504    
779      !! initialize local variables  
780 <    
780 >
781   #ifdef IS_MPI
782      pot_local = 0.0_dp
783      nAtomsInRow   = getNatomsInRow(plan_atom_row)
# Line 513 | Line 787 | contains
787   #else
788      natoms = nlocal
789   #endif
790 <    
790 >
791      call doReadyCheck(localError)
792      if ( localError .ne. 0 ) then
793         call handleError("do_force_loop", "Not Initialized")
# Line 521 | Line 795 | contains
795         return
796      end if
797      call zero_work_arrays()
798 <        
798 >
799      do_pot = do_pot_c
800      do_stress = do_stress_c
801 <    
801 >
802      ! Gather all information needed by all force loops:
803 <    
803 >
804   #ifdef IS_MPI    
805 <    
805 >
806      call gather(q, q_Row, plan_atom_row_3d)
807      call gather(q, q_Col, plan_atom_col_3d)
808  
809      call gather(q_group, q_group_Row, plan_group_row_3d)
810      call gather(q_group, q_group_Col, plan_group_col_3d)
811 <        
811 >
812      if (FF_UsesDirectionalAtoms() .and. SIM_uses_DirectionalAtoms) then
813         call gather(eFrame, eFrame_Row, plan_atom_row_rotation)
814         call gather(eFrame, eFrame_Col, plan_atom_col_rotation)
815 <      
815 >
816         call gather(A, A_Row, plan_atom_row_rotation)
817         call gather(A, A_Col, plan_atom_col_rotation)
818      endif
819 <    
819 >
820   #endif
821 <    
821 >
822      !! Begin force loop timing:
823   #ifdef PROFILE
824      call cpu_time(forceTimeInitial)
825      nloops = nloops + 1
826   #endif
827 <    
827 >
828      loopEnd = PAIR_LOOP
829      if (FF_RequiresPrepairCalc() .and. SIM_requires_prepair_calc) then
830         loopStart = PREPAIR_LOOP
# Line 565 | Line 839 | contains
839         if (loop .eq. loopStart) then
840   #ifdef IS_MPI
841            call checkNeighborList(nGroupsInRow, q_group_row, listSkin, &
842 <             update_nlist)
842 >               update_nlist)
843   #else
844            call checkNeighborList(nGroups, q_group, listSkin, &
845 <             update_nlist)
845 >               update_nlist)
846   #endif
847         endif
848 <      
848 >
849         if (update_nlist) then
850            !! save current configuration and construct neighbor list
851   #ifdef IS_MPI
# Line 582 | Line 856 | contains
856            neighborListSize = size(list)
857            nlist = 0
858         endif
859 <      
859 >
860         istart = 1
861   #ifdef IS_MPI
862         iend = nGroupsInRow
# Line 592 | Line 866 | contains
866         outer: do i = istart, iend
867  
868            if (update_nlist) point(i) = nlist + 1
869 <          
869 >
870            n_in_i = groupStartRow(i+1) - groupStartRow(i)
871 <          
871 >
872            if (update_nlist) then
873   #ifdef IS_MPI
874               jstart = 1
# Line 609 | Line 883 | contains
883               ! make sure group i has neighbors
884               if (jstart .gt. jend) cycle outer
885            endif
886 <          
886 >
887            do jnab = jstart, jend
888               if (update_nlist) then
889                  j = jnab
# Line 618 | Line 892 | contains
892               endif
893  
894   #ifdef IS_MPI
895 +             me_j = atid_col(j)
896               call get_interatomic_vector(q_group_Row(:,i), &
897                    q_group_Col(:,j), d_grp, rgrpsq)
898   #else
899 +             me_j = atid(j)
900               call get_interatomic_vector(q_group(:,i), &
901                    q_group(:,j), d_grp, rgrpsq)
902 < #endif
902 > #endif      
903  
904 <             if (rgrpsq < rlistsq) then
904 >             if (rgrpsq < gtypeCutoffMap(groupToGtypeRow(i),groupToGtypeCol(j))%rListsq) then
905                  if (update_nlist) then
906                     nlist = nlist + 1
907 <                  
907 >
908                     if (nlist > neighborListSize) then
909   #ifdef IS_MPI                
910                        call expandNeighborList(nGroupsInRow, listerror)
# Line 642 | Line 918 | contains
918                        end if
919                        neighborListSize = size(list)
920                     endif
921 <                  
921 >
922                     list(nlist) = j
923                  endif
924 <                
924 >
925                  if (loop .eq. PAIR_LOOP) then
926                     vij = 0.0d0
927                     fij(1:3) = 0.0d0
928                  endif
929 <                
929 >
930                  call get_switch(rgrpsq, sw, dswdr, rgrp, group_switch, &
931                       in_switching_region)
932 <                
932 >
933                  n_in_j = groupStartCol(j+1) - groupStartCol(j)
934 <                
934 >
935                  do ia = groupStartRow(i), groupStartRow(i+1)-1
936 <                  
936 >
937                     atom1 = groupListRow(ia)
938 <                  
938 >
939                     inner: do jb = groupStartCol(j), groupStartCol(j+1)-1
940 <                      
940 >
941                        atom2 = groupListCol(jb)
942 <                      
942 >
943                        if (skipThisPair(atom1, atom2)) cycle inner
944  
945                        if ((n_in_i .eq. 1).and.(n_in_j .eq. 1)) then
# Line 705 | Line 981 | contains
981                        endif
982                     enddo inner
983                  enddo
984 <                
984 >
985                  if (loop .eq. PAIR_LOOP) then
986                     if (in_switching_region) then
987                        swderiv = vij*dswdr/rgrp
988                        fij(1) = fij(1) + swderiv*d_grp(1)
989                        fij(2) = fij(2) + swderiv*d_grp(2)
990                        fij(3) = fij(3) + swderiv*d_grp(3)
991 <                      
991 >
992                        do ia=groupStartRow(i), groupStartRow(i+1)-1
993                           atom1=groupListRow(ia)
994                           mf = mfactRow(atom1)
# Line 726 | Line 1002 | contains
1002                           f(3,atom1) = f(3,atom1) + swderiv*d_grp(3)*mf
1003   #endif
1004                        enddo
1005 <                      
1005 >
1006                        do jb=groupStartCol(j), groupStartCol(j+1)-1
1007                           atom2=groupListCol(jb)
1008                           mf = mfactCol(atom2)
# Line 741 | Line 1017 | contains
1017   #endif
1018                        enddo
1019                     endif
1020 <                  
1020 >
1021                     if (do_stress) call add_stress_tensor(d_grp, fij)
1022                  endif
1023               end if
1024            enddo
1025 +
1026         enddo outer
1027 <      
1027 >
1028         if (update_nlist) then
1029   #ifdef IS_MPI
1030            point(nGroupsInRow + 1) = nlist + 1
# Line 761 | Line 1038 | contains
1038               update_nlist = .false.                              
1039            endif
1040         endif
1041 <            
1041 >
1042         if (loop .eq. PREPAIR_LOOP) then
1043            call do_preforce(nlocal, pot)
1044         endif
1045 <      
1045 >
1046      enddo
1047 <    
1047 >
1048      !! Do timing
1049   #ifdef PROFILE
1050      call cpu_time(forceTimeFinal)
1051      forceTime = forceTime + forceTimeFinal - forceTimeInitial
1052   #endif    
1053 <    
1053 >
1054   #ifdef IS_MPI
1055      !!distribute forces
1056 <    
1056 >
1057      f_temp = 0.0_dp
1058      call scatter(f_Row,f_temp,plan_atom_row_3d)
1059      do i = 1,nlocal
1060         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
1061      end do
1062 <    
1062 >
1063      f_temp = 0.0_dp
1064      call scatter(f_Col,f_temp,plan_atom_col_3d)
1065      do i = 1,nlocal
1066         f(1:3,i) = f(1:3,i) + f_temp(1:3,i)
1067      end do
1068 <    
1068 >
1069      if (FF_UsesDirectionalAtoms() .and. SIM_uses_DirectionalAtoms) then
1070         t_temp = 0.0_dp
1071         call scatter(t_Row,t_temp,plan_atom_row_3d)
# Line 797 | Line 1074 | contains
1074         end do
1075         t_temp = 0.0_dp
1076         call scatter(t_Col,t_temp,plan_atom_col_3d)
1077 <      
1077 >
1078         do i = 1,nlocal
1079            t(1:3,i) = t(1:3,i) + t_temp(1:3,i)
1080         end do
1081      endif
1082 <    
1082 >
1083      if (do_pot) then
1084         ! scatter/gather pot_row into the members of my column
1085         call scatter(pot_Row, pot_Temp, plan_atom_row)
1086 <      
1086 >
1087         ! scatter/gather pot_local into all other procs
1088         ! add resultant to get total pot
1089         do i = 1, nlocal
1090            pot_local = pot_local + pot_Temp(i)
1091         enddo
1092 <      
1092 >
1093         pot_Temp = 0.0_DP
1094 <      
1094 >
1095         call scatter(pot_Col, pot_Temp, plan_atom_col)
1096         do i = 1, nlocal
1097            pot_local = pot_local + pot_Temp(i)
1098         enddo
1099 <      
1099 >
1100      endif
1101   #endif
1102 <    
1102 >
1103      if (FF_RequiresPostpairCalc() .and. SIM_requires_postpair_calc) then
1104 <      
1105 <       if (FF_uses_RF .and. SIM_uses_RF) then
1106 <          
1104 >
1105 >       if (electrostaticSummationMethod == REACTION_FIELD) then
1106 >
1107   #ifdef IS_MPI
1108            call scatter(rf_Row,rf,plan_atom_row_3d)
1109            call scatter(rf_Col,rf_Temp,plan_atom_col_3d)
# Line 834 | Line 1111 | contains
1111               rf(1:3,i) = rf(1:3,i) + rf_Temp(1:3,i)
1112            end do
1113   #endif
1114 <          
1114 >
1115            do i = 1, nLocal
1116 <            
1116 >
1117               rfpot = 0.0_DP
1118   #ifdef IS_MPI
1119               me_i = atid_row(i)
1120   #else
1121               me_i = atid(i)
1122   #endif
1123 +             iHash = InteractionHash(me_i,me_j)
1124              
1125 <             if (PropertyMap(me_i)%is_Dipole) then
1126 <                
1125 >             if ( iand(iHash, ELECTROSTATIC_PAIR).ne.0 ) then
1126 >
1127                  mu_i = getDipoleMoment(me_i)
1128 <                
1128 >
1129                  !! The reaction field needs to include a self contribution
1130                  !! to the field:
1131                  call accumulate_self_rf(i, mu_i, eFrame)
# Line 858 | Line 1136 | contains
1136                  pot_local = pot_local + rfpot
1137   #else
1138                  pot = pot + rfpot
1139 <      
1139 >
1140   #endif
1141 <             endif            
1141 >             endif
1142            enddo
1143         endif
1144      endif
1145 <    
1146 <    
1145 >
1146 >
1147   #ifdef IS_MPI
1148 <    
1148 >
1149      if (do_pot) then
1150         pot = pot + pot_local
1151         !! we assume the c code will do the allreduce to get the total potential
1152         !! we could do it right here if we needed to...
1153      endif
1154 <    
1154 >
1155      if (do_stress) then
1156         call mpi_allreduce(tau_Temp, tau, 9,mpi_double_precision,mpi_sum, &
1157              mpi_comm_world,mpi_err)
1158         call mpi_allreduce(virial_Temp, virial,1,mpi_double_precision,mpi_sum, &
1159              mpi_comm_world,mpi_err)
1160      endif
1161 <    
1161 >
1162   #else
1163 <    
1163 >
1164      if (do_stress) then
1165         tau = tau_Temp
1166         virial = virial_Temp
1167      endif
1168 <    
1168 >
1169   #endif
1170 <      
1170 >
1171    end subroutine do_force_loop
1172 <  
1172 >
1173    subroutine do_pair(i, j, rijsq, d, sw, do_pot, &
1174         eFrame, A, f, t, pot, vpair, fpair)
1175  
# Line 910 | Line 1188 | contains
1188      real ( kind = dp ), intent(inout) :: d(3)
1189      integer :: me_i, me_j
1190  
1191 +    integer :: iHash
1192 +
1193      r = sqrt(rijsq)
1194      vpair = 0.0d0
1195      fpair(1:3) = 0.0d0
# Line 922 | Line 1202 | contains
1202      me_j = atid(j)
1203   #endif
1204  
1205 < !    write(*,*) i, j, me_i, me_j
1206 <    
1207 <    if (FF_uses_LennardJones .and. SIM_uses_LennardJones) then
1208 <      
929 <       if ( PropertyMap(me_i)%is_LennardJones .and. &
930 <            PropertyMap(me_j)%is_LennardJones ) then
931 <          call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
932 <       endif
933 <      
1205 >    iHash = InteractionHash(me_i, me_j)
1206 >
1207 >    if ( iand(iHash, LJ_PAIR).ne.0 ) then
1208 >       call do_lj_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, do_pot)
1209      endif
935    
936    if (FF_uses_Electrostatics .and. SIM_uses_Electrostatics) then
937      
938       if (PropertyMap(me_i)%is_Electrostatic .and. &
939            PropertyMap(me_j)%is_Electrostatic) then
940          call doElectrostaticPair(i, j, d, r, rijsq, sw, vpair, fpair, &
941               pot, eFrame, f, t, do_pot)
942       endif
943      
944       if (FF_uses_dipoles .and. SIM_uses_dipoles) then      
945          if ( PropertyMap(me_i)%is_Dipole .and. &
946               PropertyMap(me_j)%is_Dipole) then
947             if (FF_uses_RF .and. SIM_uses_RF) then
948                call accumulate_rf(i, j, r, eFrame, sw)
949                call rf_correct_forces(i, j, d, r, eFrame, sw, f, fpair)
950             endif
951          endif
952       endif
953    endif
1210  
1211 +    if ( iand(iHash, ELECTROSTATIC_PAIR).ne.0 ) then
1212 +       call doElectrostaticPair(i, j, d, r, rijsq, sw, vpair, fpair, &
1213 +            pot, eFrame, f, t, do_pot)
1214  
1215 <    if (FF_uses_Sticky .and. SIM_uses_sticky) then
1215 >       if (electrostaticSummationMethod == REACTION_FIELD) then
1216  
1217 <       if ( PropertyMap(me_i)%is_Sticky .and. PropertyMap(me_j)%is_Sticky) then
1218 <          call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1219 <               pot, A, f, t, do_pot)
1217 >          ! CHECK ME (RF needs to know about all electrostatic types)
1218 >          call accumulate_rf(i, j, r, eFrame, sw)
1219 >          call rf_correct_forces(i, j, d, r, eFrame, sw, f, fpair)
1220         endif
1221 <      
1221 >
1222      endif
1223  
1224 +    if ( iand(iHash, STICKY_PAIR).ne.0 ) then
1225 +       call do_sticky_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1226 +            pot, A, f, t, do_pot)
1227 +    endif
1228  
1229 <    if (FF_uses_GayBerne .and. SIM_uses_GayBerne) then
1230 <      
1231 <       if ( PropertyMap(me_i)%is_GayBerne .and. &
969 <            PropertyMap(me_j)%is_GayBerne) then
970 <          call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
971 <               pot, A, f, t, do_pot)
972 <       endif
973 <      
1229 >    if ( iand(iHash, STICKYPOWER_PAIR).ne.0 ) then
1230 >       call do_sticky_power_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1231 >            pot, A, f, t, do_pot)
1232      endif
1233 +
1234 +    if ( iand(iHash, GAYBERNE_PAIR).ne.0 ) then
1235 +       call do_gb_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1236 +            pot, A, f, t, do_pot)
1237 +    endif
1238      
1239 <    if (FF_uses_EAM .and. SIM_uses_EAM) then
1240 <      
1241 <       if ( PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) then
979 <          call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, &
980 <               do_pot)
981 <       endif
982 <      
1239 >    if ( iand(iHash, GAYBERNE_LJ).ne.0 ) then
1240 > !      call do_gblj_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1241 > !           pot, A, f, t, do_pot)
1242      endif
1243  
1244 +    if ( iand(iHash, EAM_PAIR).ne.0 ) then      
1245 +       call do_eam_pair(i, j, d, r, rijsq, sw, vpair, fpair, pot, f, &
1246 +            do_pot)
1247 +    endif
1248  
1249 < !    write(*,*) PropertyMap(me_i)%is_Shape,PropertyMap(me_j)%is_Shape
1249 >    if ( iand(iHash, SHAPE_PAIR).ne.0 ) then      
1250 >       call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1251 >            pot, A, f, t, do_pot)
1252 >    endif
1253  
1254 <    if (FF_uses_Shapes .and. SIM_uses_Shapes) then
1255 <       if ( PropertyMap(me_i)%is_Shape .and. &
1256 <            PropertyMap(me_j)%is_Shape ) then
991 <          call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
992 <               pot, A, f, t, do_pot)
993 <       endif
994 <      
1254 >    if ( iand(iHash, SHAPE_LJ).ne.0 ) then      
1255 >       call do_shape_pair(i, j, d, r, rijsq, sw, vpair, fpair, &
1256 >            pot, A, f, t, do_pot)
1257      endif
1258      
1259    end subroutine do_pair
# Line 999 | Line 1261 | contains
1261    subroutine do_prepair(i, j, rijsq, d, sw, rcijsq, dc, &
1262         do_pot, do_stress, eFrame, A, f, t, pot)
1263  
1264 <   real( kind = dp ) :: pot, sw
1265 <   real( kind = dp ), dimension(9,nLocal) :: eFrame
1266 <   real (kind=dp), dimension(9,nLocal) :: A
1267 <   real (kind=dp), dimension(3,nLocal) :: f
1268 <   real (kind=dp), dimension(3,nLocal) :: t
1007 <  
1008 <   logical, intent(inout) :: do_pot, do_stress
1009 <   integer, intent(in) :: i, j
1010 <   real ( kind = dp ), intent(inout)    :: rijsq, rcijsq
1011 <   real ( kind = dp )                :: r, rc
1012 <   real ( kind = dp ), intent(inout) :: d(3), dc(3)
1013 <  
1014 <   logical :: is_EAM_i, is_EAM_j
1015 <  
1016 <   integer :: me_i, me_j
1017 <  
1264 >    real( kind = dp ) :: pot, sw
1265 >    real( kind = dp ), dimension(9,nLocal) :: eFrame
1266 >    real (kind=dp), dimension(9,nLocal) :: A
1267 >    real (kind=dp), dimension(3,nLocal) :: f
1268 >    real (kind=dp), dimension(3,nLocal) :: t
1269  
1270 +    logical, intent(inout) :: do_pot, do_stress
1271 +    integer, intent(in) :: i, j
1272 +    real ( kind = dp ), intent(inout)    :: rijsq, rcijsq
1273 +    real ( kind = dp )                :: r, rc
1274 +    real ( kind = dp ), intent(inout) :: d(3), dc(3)
1275 +
1276 +    integer :: me_i, me_j, iHash
1277 +
1278      r = sqrt(rijsq)
1020    if (SIM_uses_molecular_cutoffs) then
1021       rc = sqrt(rcijsq)
1022    else
1023       rc = r
1024    endif
1025  
1279  
1280   #ifdef IS_MPI  
1281 <   me_i = atid_row(i)
1282 <   me_j = atid_col(j)  
1281 >    me_i = atid_row(i)
1282 >    me_j = atid_col(j)  
1283   #else  
1284 <   me_i = atid(i)
1285 <   me_j = atid(j)  
1284 >    me_i = atid(i)
1285 >    me_j = atid(j)  
1286   #endif
1034  
1035   if (FF_uses_EAM .and. SIM_uses_EAM) then
1036      
1037      if (PropertyMap(me_i)%is_EAM .and. PropertyMap(me_j)%is_EAM) &
1038           call calc_EAM_prepair_rho(i, j, d, r, rijsq )
1039      
1040   endif
1041  
1042 end subroutine do_prepair
1043
1044
1045 subroutine do_preforce(nlocal,pot)
1046   integer :: nlocal
1047   real( kind = dp ) :: pot
1048  
1049   if (FF_uses_EAM .and. SIM_uses_EAM) then
1050      call calc_EAM_preforce_Frho(nlocal,pot)
1051   endif
1052  
1053  
1054 end subroutine do_preforce
1055
1056
1057 subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
1058  
1059   real (kind = dp), dimension(3) :: q_i
1060   real (kind = dp), dimension(3) :: q_j
1061   real ( kind = dp ), intent(out) :: r_sq
1062   real( kind = dp ) :: d(3), scaled(3)
1063   integer i
1064  
1065   d(1:3) = q_j(1:3) - q_i(1:3)
1066  
1067   ! Wrap back into periodic box if necessary
1068   if ( SIM_uses_PBC ) then
1069      
1070      if( .not.boxIsOrthorhombic ) then
1071         ! calc the scaled coordinates.
1072        
1073         scaled = matmul(HmatInv, d)
1074        
1075         ! wrap the scaled coordinates
1076        
1077         scaled = scaled  - anint(scaled)
1078        
1079        
1080         ! calc the wrapped real coordinates from the wrapped scaled
1081         ! coordinates
1082        
1083         d = matmul(Hmat,scaled)
1084        
1085      else
1086         ! calc the scaled coordinates.
1087        
1088         do i = 1, 3
1089            scaled(i) = d(i) * HmatInv(i,i)
1090            
1091            ! wrap the scaled coordinates
1092            
1093            scaled(i) = scaled(i) - anint(scaled(i))
1094            
1095            ! calc the wrapped real coordinates from the wrapped scaled
1096            ! coordinates
1097            
1098            d(i) = scaled(i)*Hmat(i,i)
1099         enddo
1100      endif
1101      
1102   endif
1103  
1104   r_sq = dot_product(d,d)
1105  
1106 end subroutine get_interatomic_vector
1107
1108 subroutine zero_work_arrays()
1109  
1110 #ifdef IS_MPI
1111  
1112   q_Row = 0.0_dp
1113   q_Col = 0.0_dp
1287  
1288 <   q_group_Row = 0.0_dp
1289 <   q_group_Col = 0.0_dp  
1290 <  
1291 <   eFrame_Row = 0.0_dp
1292 <   eFrame_Col = 0.0_dp
1293 <  
1294 <   A_Row = 0.0_dp
1295 <   A_Col = 0.0_dp
1296 <  
1297 <   f_Row = 0.0_dp
1298 <   f_Col = 0.0_dp
1299 <   f_Temp = 0.0_dp
1300 <  
1301 <   t_Row = 0.0_dp
1302 <   t_Col = 0.0_dp
1303 <   t_Temp = 0.0_dp
1304 <  
1305 <   pot_Row = 0.0_dp
1306 <   pot_Col = 0.0_dp
1307 <   pot_Temp = 0.0_dp
1308 <  
1309 <   rf_Row = 0.0_dp
1310 <   rf_Col = 0.0_dp
1311 <   rf_Temp = 0.0_dp
1312 <  
1313 < #endif
1314 <
1315 <   if (FF_uses_EAM .and. SIM_uses_EAM) then
1316 <      call clean_EAM()
1317 <   endif
1318 <  
1319 <   rf = 0.0_dp
1320 <   tau_Temp = 0.0_dp
1321 <   virial_Temp = 0.0_dp
1322 < end subroutine zero_work_arrays
1323 <
1324 < function skipThisPair(atom1, atom2) result(skip_it)
1325 <   integer, intent(in) :: atom1
1326 <   integer, intent(in), optional :: atom2
1327 <   logical :: skip_it
1328 <   integer :: unique_id_1, unique_id_2
1329 <   integer :: me_i,me_j
1330 <   integer :: i
1331 <  
1332 <   skip_it = .false.
1333 <  
1334 <   !! there are a number of reasons to skip a pair or a particle
1335 <   !! mostly we do this to exclude atoms who are involved in short
1336 <   !! range interactions (bonds, bends, torsions), but we also need
1337 <   !! to exclude some overcounted interactions that result from
1338 <   !! the parallel decomposition
1339 <  
1340 < #ifdef IS_MPI
1341 <   !! in MPI, we have to look up the unique IDs for each atom
1342 <   unique_id_1 = AtomRowToGlobal(atom1)
1343 < #else
1344 <   !! in the normal loop, the atom numbers are unique
1345 <   unique_id_1 = atom1
1288 >    iHash = InteractionHash(me_i, me_j)
1289 >
1290 >    if ( iand(iHash, EAM_PAIR).ne.0 ) then      
1291 >            call calc_EAM_prepair_rho(i, j, d, r, rijsq )
1292 >    endif
1293 >    
1294 >  end subroutine do_prepair
1295 >
1296 >
1297 >  subroutine do_preforce(nlocal,pot)
1298 >    integer :: nlocal
1299 >    real( kind = dp ) :: pot
1300 >
1301 >    if (FF_uses_EAM .and. SIM_uses_EAM) then
1302 >       call calc_EAM_preforce_Frho(nlocal,pot)
1303 >    endif
1304 >
1305 >
1306 >  end subroutine do_preforce
1307 >
1308 >
1309 >  subroutine get_interatomic_vector(q_i, q_j, d, r_sq)
1310 >
1311 >    real (kind = dp), dimension(3) :: q_i
1312 >    real (kind = dp), dimension(3) :: q_j
1313 >    real ( kind = dp ), intent(out) :: r_sq
1314 >    real( kind = dp ) :: d(3), scaled(3)
1315 >    integer i
1316 >
1317 >    d(1:3) = q_j(1:3) - q_i(1:3)
1318 >
1319 >    ! Wrap back into periodic box if necessary
1320 >    if ( SIM_uses_PBC ) then
1321 >
1322 >       if( .not.boxIsOrthorhombic ) then
1323 >          ! calc the scaled coordinates.
1324 >
1325 >          scaled = matmul(HmatInv, d)
1326 >
1327 >          ! wrap the scaled coordinates
1328 >
1329 >          scaled = scaled  - anint(scaled)
1330 >
1331 >
1332 >          ! calc the wrapped real coordinates from the wrapped scaled
1333 >          ! coordinates
1334 >
1335 >          d = matmul(Hmat,scaled)
1336 >
1337 >       else
1338 >          ! calc the scaled coordinates.
1339 >
1340 >          do i = 1, 3
1341 >             scaled(i) = d(i) * HmatInv(i,i)
1342 >
1343 >             ! wrap the scaled coordinates
1344 >
1345 >             scaled(i) = scaled(i) - anint(scaled(i))
1346 >
1347 >             ! calc the wrapped real coordinates from the wrapped scaled
1348 >             ! coordinates
1349 >
1350 >             d(i) = scaled(i)*Hmat(i,i)
1351 >          enddo
1352 >       endif
1353 >
1354 >    endif
1355 >
1356 >    r_sq = dot_product(d,d)
1357 >
1358 >  end subroutine get_interatomic_vector
1359 >
1360 >  subroutine zero_work_arrays()
1361 >
1362 > #ifdef IS_MPI
1363 >
1364 >    q_Row = 0.0_dp
1365 >    q_Col = 0.0_dp
1366 >
1367 >    q_group_Row = 0.0_dp
1368 >    q_group_Col = 0.0_dp  
1369 >
1370 >    eFrame_Row = 0.0_dp
1371 >    eFrame_Col = 0.0_dp
1372 >
1373 >    A_Row = 0.0_dp
1374 >    A_Col = 0.0_dp
1375 >
1376 >    f_Row = 0.0_dp
1377 >    f_Col = 0.0_dp
1378 >    f_Temp = 0.0_dp
1379 >
1380 >    t_Row = 0.0_dp
1381 >    t_Col = 0.0_dp
1382 >    t_Temp = 0.0_dp
1383 >
1384 >    pot_Row = 0.0_dp
1385 >    pot_Col = 0.0_dp
1386 >    pot_Temp = 0.0_dp
1387 >
1388 >    rf_Row = 0.0_dp
1389 >    rf_Col = 0.0_dp
1390 >    rf_Temp = 0.0_dp
1391 >
1392   #endif
1393 <  
1394 <   !! We were called with only one atom, so just check the global exclude
1395 <   !! list for this atom
1396 <   if (.not. present(atom2)) then
1397 <      do i = 1, nExcludes_global
1398 <         if (excludesGlobal(i) == unique_id_1) then
1399 <            skip_it = .true.
1400 <            return
1401 <         end if
1402 <      end do
1403 <      return
1404 <   end if
1405 <  
1393 >
1394 >    if (FF_uses_EAM .and. SIM_uses_EAM) then
1395 >       call clean_EAM()
1396 >    endif
1397 >
1398 >    rf = 0.0_dp
1399 >    tau_Temp = 0.0_dp
1400 >    virial_Temp = 0.0_dp
1401 >  end subroutine zero_work_arrays
1402 >
1403 >  function skipThisPair(atom1, atom2) result(skip_it)
1404 >    integer, intent(in) :: atom1
1405 >    integer, intent(in), optional :: atom2
1406 >    logical :: skip_it
1407 >    integer :: unique_id_1, unique_id_2
1408 >    integer :: me_i,me_j
1409 >    integer :: i
1410 >
1411 >    skip_it = .false.
1412 >
1413 >    !! there are a number of reasons to skip a pair or a particle
1414 >    !! mostly we do this to exclude atoms who are involved in short
1415 >    !! range interactions (bonds, bends, torsions), but we also need
1416 >    !! to exclude some overcounted interactions that result from
1417 >    !! the parallel decomposition
1418 >
1419   #ifdef IS_MPI
1420 <   unique_id_2 = AtomColToGlobal(atom2)
1420 >    !! in MPI, we have to look up the unique IDs for each atom
1421 >    unique_id_1 = AtomRowToGlobal(atom1)
1422   #else
1423 <   unique_id_2 = atom2
1423 >    !! in the normal loop, the atom numbers are unique
1424 >    unique_id_1 = atom1
1425   #endif
1426 <  
1426 >
1427 >    !! We were called with only one atom, so just check the global exclude
1428 >    !! list for this atom
1429 >    if (.not. present(atom2)) then
1430 >       do i = 1, nExcludes_global
1431 >          if (excludesGlobal(i) == unique_id_1) then
1432 >             skip_it = .true.
1433 >             return
1434 >          end if
1435 >       end do
1436 >       return
1437 >    end if
1438 >
1439   #ifdef IS_MPI
1440 <   !! this situation should only arise in MPI simulations
1441 <   if (unique_id_1 == unique_id_2) then
1442 <      skip_it = .true.
1197 <      return
1198 <   end if
1199 <  
1200 <   !! this prevents us from doing the pair on multiple processors
1201 <   if (unique_id_1 < unique_id_2) then
1202 <      if (mod(unique_id_1 + unique_id_2,2) == 0) then
1203 <         skip_it = .true.
1204 <         return
1205 <      endif
1206 <   else                
1207 <      if (mod(unique_id_1 + unique_id_2,2) == 1) then
1208 <         skip_it = .true.
1209 <         return
1210 <      endif
1211 <   endif
1440 >    unique_id_2 = AtomColToGlobal(atom2)
1441 > #else
1442 >    unique_id_2 = atom2
1443   #endif
1444 <  
1445 <   !! the rest of these situations can happen in all simulations:
1446 <   do i = 1, nExcludes_global      
1447 <      if ((excludesGlobal(i) == unique_id_1) .or. &
1448 <           (excludesGlobal(i) == unique_id_2)) then
1449 <         skip_it = .true.
1450 <         return
1451 <      endif
1452 <   enddo
1453 <  
1454 <   do i = 1, nSkipsForAtom(atom1)
1455 <      if (skipsForAtom(atom1, i) .eq. unique_id_2) then
1456 <         skip_it = .true.
1457 <         return
1458 <      endif
1459 <   end do
1460 <  
1461 <   return
1462 < end function skipThisPair
1463 <
1464 < function FF_UsesDirectionalAtoms() result(doesit)
1465 <   logical :: doesit
1466 <   doesit = FF_uses_DirectionalAtoms .or. FF_uses_Dipoles .or. &
1467 <        FF_uses_Quadrupoles .or. FF_uses_Sticky .or. &
1468 <        FF_uses_GayBerne .or. FF_uses_Shapes
1469 < end function FF_UsesDirectionalAtoms
1470 <
1471 < function FF_RequiresPrepairCalc() result(doesit)
1472 <   logical :: doesit
1473 <   doesit = FF_uses_EAM
1474 < end function FF_RequiresPrepairCalc
1475 <
1476 < function FF_RequiresPostpairCalc() result(doesit)
1477 <   logical :: doesit
1478 <   doesit = FF_uses_RF
1479 < end function FF_RequiresPostpairCalc
1480 <
1444 >
1445 > #ifdef IS_MPI
1446 >    !! this situation should only arise in MPI simulations
1447 >    if (unique_id_1 == unique_id_2) then
1448 >       skip_it = .true.
1449 >       return
1450 >    end if
1451 >
1452 >    !! this prevents us from doing the pair on multiple processors
1453 >    if (unique_id_1 < unique_id_2) then
1454 >       if (mod(unique_id_1 + unique_id_2,2) == 0) then
1455 >          skip_it = .true.
1456 >          return
1457 >       endif
1458 >    else                
1459 >       if (mod(unique_id_1 + unique_id_2,2) == 1) then
1460 >          skip_it = .true.
1461 >          return
1462 >       endif
1463 >    endif
1464 > #endif
1465 >
1466 >    !! the rest of these situations can happen in all simulations:
1467 >    do i = 1, nExcludes_global      
1468 >       if ((excludesGlobal(i) == unique_id_1) .or. &
1469 >            (excludesGlobal(i) == unique_id_2)) then
1470 >          skip_it = .true.
1471 >          return
1472 >       endif
1473 >    enddo
1474 >
1475 >    do i = 1, nSkipsForAtom(atom1)
1476 >       if (skipsForAtom(atom1, i) .eq. unique_id_2) then
1477 >          skip_it = .true.
1478 >          return
1479 >       endif
1480 >    end do
1481 >
1482 >    return
1483 >  end function skipThisPair
1484 >
1485 >  function FF_UsesDirectionalAtoms() result(doesit)
1486 >    logical :: doesit
1487 >    doesit = FF_uses_DirectionalAtoms
1488 >  end function FF_UsesDirectionalAtoms
1489 >
1490 >  function FF_RequiresPrepairCalc() result(doesit)
1491 >    logical :: doesit
1492 >    doesit = FF_uses_EAM
1493 >  end function FF_RequiresPrepairCalc
1494 >
1495 >  function FF_RequiresPostpairCalc() result(doesit)
1496 >    logical :: doesit
1497 >    if (electrostaticSummationMethod == REACTION_FIELD) doesit = .true.
1498 >  end function FF_RequiresPostpairCalc
1499 >
1500   #ifdef PROFILE
1501 < function getforcetime() result(totalforcetime)
1502 <   real(kind=dp) :: totalforcetime
1503 <   totalforcetime = forcetime
1504 < end function getforcetime
1501 >  function getforcetime() result(totalforcetime)
1502 >    real(kind=dp) :: totalforcetime
1503 >    totalforcetime = forcetime
1504 >  end function getforcetime
1505   #endif
1256
1257 !! This cleans componets of force arrays belonging only to fortran
1506  
1507 < subroutine add_stress_tensor(dpair, fpair)
1508 <  
1509 <   real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1510 <  
1511 <   ! because the d vector is the rj - ri vector, and
1512 <   ! because fx, fy, fz are the force on atom i, we need a
1513 <   ! negative sign here:  
1514 <  
1515 <   tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1516 <   tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1517 <   tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1518 <   tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1519 <   tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1520 <   tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1521 <   tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1522 <   tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1523 <   tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1524 <  
1525 <   virial_Temp = virial_Temp + &
1526 <        (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1527 <  
1528 < end subroutine add_stress_tensor
1529 <
1507 >  !! This cleans componets of force arrays belonging only to fortran
1508 >
1509 >  subroutine add_stress_tensor(dpair, fpair)
1510 >
1511 >    real( kind = dp ), dimension(3), intent(in) :: dpair, fpair
1512 >
1513 >    ! because the d vector is the rj - ri vector, and
1514 >    ! because fx, fy, fz are the force on atom i, we need a
1515 >    ! negative sign here:  
1516 >
1517 >    tau_Temp(1) = tau_Temp(1) - dpair(1) * fpair(1)
1518 >    tau_Temp(2) = tau_Temp(2) - dpair(1) * fpair(2)
1519 >    tau_Temp(3) = tau_Temp(3) - dpair(1) * fpair(3)
1520 >    tau_Temp(4) = tau_Temp(4) - dpair(2) * fpair(1)
1521 >    tau_Temp(5) = tau_Temp(5) - dpair(2) * fpair(2)
1522 >    tau_Temp(6) = tau_Temp(6) - dpair(2) * fpair(3)
1523 >    tau_Temp(7) = tau_Temp(7) - dpair(3) * fpair(1)
1524 >    tau_Temp(8) = tau_Temp(8) - dpair(3) * fpair(2)
1525 >    tau_Temp(9) = tau_Temp(9) - dpair(3) * fpair(3)
1526 >
1527 >    virial_Temp = virial_Temp + &
1528 >         (tau_Temp(1) + tau_Temp(5) + tau_Temp(9))
1529 >
1530 >  end subroutine add_stress_tensor
1531 >
1532   end module doForces

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines