338LOGICAL FUNCTION distmtx(NAN, LAN, LOOKNGB, UPNGB)
352INTEGER,
INTENT(IN) :: nan
353INTEGER,
DIMENSION(NAN),
INTENT(IN) :: lan
354LOGICAL,
INTENT(IN) :: lookngb, upngb
356INTEGER :: ra, rb, rc, rd, rf, rg, rh, ri, rj, rk, rl, rm
357INTEGER :: rn, ro, rp, rq, rs, rt, ru, rv, rw, rx, ry, rz
358INTEGER :: a_start, a_end
360DOUBLE PRECISION :: dik
361DOUBLE PRECISION :: maxbd, minbd
362INTEGER,
DIMENSION(:),
ALLOCATABLE :: ba, bb
363INTEGER,
DIMENSION(:),
ALLOCATABLE :: ca, cb
364DOUBLE PRECISION,
DIMENSION(:),
ALLOCATABLE :: xc, yc, zc
365LOGICAL :: calcmat=.false.
367LOGICAL :: toom=.false.
369LOGICAL :: pixr=.false.
372LOGICAL :: is_clone, boundary, keep_it
373INTEGER,
DIMENSION(3) :: pixpos
374DOUBLE PRECISION,
DIMENSION(3) :: xyz, uvw
375INTEGER :: pid, cid, did, eid, fid, ai, bi, ci
376INTEGER :: init_a, end_a
377INTEGER :: init_b, end_b
378INTEGER :: init_c, end_c
379INTEGER,
DIMENSION(3) :: dim = (/-1, 0, 1/)
380INTEGER,
DIMENSION(3,3,3) :: shift
384INTEGER :: atom_start, atom_end
385INTEGER,
DIMENSION(:),
ALLOCATABLE :: atpix
390 INTEGER FUNCTION getnbx (NP, NPS)
391 INTEGER,
INTENT(IN) :: np, nps
393 LOGICAL FUNCTION dvtbox (ST, NAS, NAT, NPOS)
394 INTEGER,
INTENT(IN) :: st, nas, nat
395 DOUBLE PRECISION,
DIMENSION(NAT,3),
INTENT(INOUT) :: npos
399 INTEGER,
INTENT(IN) :: nobj, nthreads, thread_id
402 INTEGER,
INTENT(IN) :: nobj, nthreads, thread_id
405 DOUBLE PRECISION FUNCTION calcdij (R12, AT1, AT2, STEP_1, STEP_2, SID)
407 DOUBLE PRECISION,
DIMENSION(3),
INTENT(INOUT) :: r12
408 INTEGER,
INTENT(IN) :: at1, at2, step_1, step_2, sid
410 DOUBLE PRECISION FUNCTION spheres_caps_volumes (DAB, RAP, RBP)
411 DOUBLE PRECISION,
INTENT(IN) :: dab, rap, rbp
416 write (6,
'("In DMTX:: LOOKNGB= ",L1, ", NOHOM= ",L1," PBC= ",L1,", CUBIC= ",L1)') lookngb, nohp, pbc, overall_cubic
419if (
allocated(gr_tmp))
deallocate(gr_tmp)
420allocate(gr_tmp(nsp,nsp), stat=err)
430 if (gr_cut(i,j) .gt. gr_cutoff)
then
431 gr_tmp(i,j)=gr_cutoff
433 gr_tmp(i,j)=gr_cut(i,j)
435 if (.not.lookngb) gr_tmp(i,j) = gr_tmp(i,j) + 50.0
448 if (
allocated(voisj))
deallocate(voisj)
449 allocate(voisj(maxn,nna,ns), stat=err)
456 if (
allocated(contj))
deallocate(contj)
457 allocate(contj(nna,ns), stat=err)
477 a_start = nan *(nbx**3 - 1)/2 + 1
478 a_end = a_start + nan - 1
481ab = isize(1)*isize(2)
485numth = omp_get_max_threads()
488 if (numth .ge. 2*(ns-1))
then
495if (all_atoms) doatoms=.true.
500 call print_pixel_grid ()
505 if (nan.lt.numth) numth=nan
508 allocate(poa(nna,3), stat=err)
520 if (.not.
dvtbox(sat, na, nna, poa))
then
526 if (
allocated(thepix))
deallocate(thepix)
527 allocate(thepix(abc), stat=err)
535 if (
allocated(atpix))
deallocate(atpix)
536 allocate(atpix(nna), stat=err)
550 if (.not.lookngb) ra = maxn*10
551 if (.not.lookngb .or. abc .le. 5) ra =
min(ra*5, nna)
554 thepix(rb)%TOCHECK=.false.
555 thepix(rb)%CHECKED=.false.
556 allocate(thepix(rb)%ATOM_ID(ra), stat=err)
558 alc_tab=
"THEPIX%ATOM_ID"
563 thepix(rb)%IDNEIGH(:) = 0
564 thepix(rb)%ATOM_ID(:) = 0
570 pixpos(rb) = int((fullpos(ra,rb,sat) - pmin(rb))*cutf)
571 if (pixpos(rb) .eq. isize(rb)) pixpos(rb) = pixpos(rb)-1
575 if (ncells.gt.1)
then
576 xyz = matmul(poa(ra,:), the_box(sat)%carttofrac/nbx)
578 xyz = matmul(poa(ra,:), the_box(1)%carttofrac/nbx)
581 if (ncells.gt.1)
then
582 xyz = matmul(fullpos(ra,:,sat), the_box(sat)%carttofrac)
584 xyz = matmul(fullpos(ra,:,sat), the_box(1)%carttofrac)
588 uvw(rb) = xyz(rb) - floor(xyz(rb))
589 pixpos(rb) = int(uvw(rb)*isize(rb))
593 pix = pixpos(1) + pixpos(2)*isize(1) + pixpos(3)*ab + 1
594 if (pix.gt.abc .or. pix.le.0)
then
595 write (6,
'("Thread(id)= ",i4,", MD step= ",i8)') thread_num, sat
597 write (6,
'("at= ",i7,", pos(x)= ",f15.10,", pos(y)= ",f15.10,", pos(z)= ",f15.10)') ra, poa(ra,:)
599 write (6,
'("at= ",i7,", pos(x)= ",f15.10,", pos(y)= ",f15.10,", pos(z)= ",f15.10)') ra, fullpos(ra,:,sat)
602 write (6,
'("at= ",i7,", fra(x)= ",f15.10,", fra(y)= ",f15.10,", fra(z)= ",f15.10)') ra, xyz
603 write (6,
'("at= ",i7,", cor(x)= ",f15.10,", cor(y)= ",f15.10,", cor(z)= ",f15.10)') ra, uvw
605 write (6,
'("at= ",i7,", pixpos(x)= ",i4,", pixpos(y)= ",i4,", pixpos(z)= ",i4)') ra, pixpos
606 write (6,
'("at= ",i7,", pixpos= ",i10)') ra, pix
612 if ((pbc .and. ra.ge.a_start .and. ra.le.a_end) .or. .not.pbc)
then
613 if (.not.thepix(pix)%TOCHECK)
then
620 if (pbc .and. .not.calc_prings)
then
621 call set_shift (shift, ai, bi, ci, isize(1), isize(2), isize(3), ab, abc)
623 if (ai.eq.1 .or. ai.eq.isize(1)) boundary=.true.
624 if (bi.eq.1 .or. bi.eq.isize(2)) boundary=.true.
625 if (ci.eq.1 .or. ci.eq.isize(3)) boundary=.true.
629 if (isize(1) .eq. 1)
then
636 if (isize(2) .eq. 1)
then
643 if (isize(3) .eq. 1)
then
653 if (ai.eq.1 .and. cid.eq.1)
then
655 else if (ai.eq.isize(1) .and. cid.eq.3)
then
657 else if (bi.eq.1 .and. did.eq.1)
then
659 else if (bi.eq.isize(2) .and. did.eq.3)
then
661 else if (ci.eq.1 .and. eid.eq.1)
then
663 else if (ci.eq.isize(3) .and. eid.eq.3)
then
669 thepix(pix)%IDNEIGH(pid) = pix + dim(cid) + dim(did) * isize(1) + dim(eid) * ab + shift(cid,did,eid)
674 thepix(pix)%NEIGHBOR = pid
676 thepix(pix)%TOCHECK=.true.
678 thepix(pix)%ATOMS = thepix(pix)%ATOMS + 1
679 thepix(pix)%ATOM_ID(thepix(pix)%ATOMS) = ra
696 thread_num = omp_get_thread_num()
700 do rc=atom_start, atom_end
702 rf = rc - (rc/nan)*nan
703 if (rf .eq. 0) rf=nan
705 do rh=1, thepix(rd)%NEIGHBOR
706 ri = thepix(rd)%IDNEIGH(rh)
707 rj = thepix(ri)%ATOMS
709 rl = thepix(ri)%ATOM_ID(rk)
711 if ((rc.ge.a_start .and. rc.le.a_end) .or. (rl.ge.a_start .and. rl.le.a_end))
then
712 rm = rl - (rl/nan)*nan
713 if (rm .eq. 0) rm=nan
716 if (.not.pbc .or. nbx.gt.1)
then
717 if (((rc.ge.a_start .and. rc.le.a_end) .and. (rl.ge.a_start .and. rl.le.a_end)) .or. .not.pbc)
then
725 if (rg.ne.rn .or. .not.nohp)
then
734 rij(rp) = poa(rc,rp) - poa(rl,rp)
740 rij(rp) = fullpos(rf,rp,sat) - fullpos(rm,rp,sat)
743 if (ncells .gt. 1)
then
744 dij =
calcdij(rij,rf,rm,sat,sat,sat)
746 dij =
calcdij(rij,rf,rm,sat,sat,1)
748 if (dik-dij .gt.0.01d0)
then
752 if (dij .le. gr_tmp(rg,rn))
then
757 if (calc_prings)
then
764 contj(rp,sat)=contj(rp,sat)+1
765 if (contj(rp,sat) .gt. maxn)
then
771 voisj(contj(rp,sat),rp,sat)=rq
772 if (.not.calc_prings .and. upngb)
then
774 voisj(contj(rp,sat),rp,sat)=-rq
787 if (la_count(rf,ro,sat).eq.4 .and. contj(rf,sat).eq.4)
then
788 if (la_count(rm,ro,sat).eq.4 .and. contj(rm,sat).eq.4)
then
791 rs = voisj(rq,rf,sat)
792 do rt=1, contj(rs,sat)
793 if (voisj(rt,rs,sat) .eq. rm) rp=rp+1
798 corta(rg,ro)=corta(rg,ro)+1
801 cornera(rg,ro,sat)=cornera(rg,ro,sat)+1
803 elseif (rp.eq.2)
then
805 edgeta(rg,ro)=edgeta(rg,ro)+1
808 edgea(rg,ro,sat)=edgea(rg,ro,sat)+1
810 elseif (rp.ge.3)
then
812 corta(rg,ro)=corta(rg,ro)+1
814 edgeta(rg,ro)=edgeta(rg,ro)+1
816 defta(rg,ro)=defta(rg,ro)+1
819 cornera(rg,ro,sat)=cornera(rg,ro,sat)+1
821 edgea(rg,ro,sat)=edgea(rg,ro,sat)+1
823 defa(rg,ro,sat)=defa(rg,ro,sat)+1
840 if (
allocated(thepix))
deallocate(thepix)
841 if (
allocated(atpix))
deallocate(atpix)
845 if (.not.lookngb)
then
848 corta(rc,rd)=corta(rc,rd)/2
849 edgeta(rc,rd)=edgeta(rc,rd)/2
850 defta(rc,rd)=defta(rc,rd)/2
852 cornera(rc,rd,sat)=cornera(rc,rd,sat)/2
853 edgea(rc,rd,sat)=edgea(rc,rd,sat)/2
854 defa(rc,rd,sat)=defa(rc,rd,sat)/2
859 if (.not.calc_prings .and.upngb)
then
861 if (
allocated(ba))
deallocate(ba)
862 allocate(ba(ra), stat=err)
869 if (
allocated(bb))
deallocate(bb)
870 allocate(bb(ra), stat=err)
879 if (
allocated(ca))
deallocate(ca)
880 allocate(ca(rb), stat=err)
887 if (
allocated(cb))
deallocate(cb)
888 allocate(cb(rb), stat=err)
895 if (
allocated(xc))
deallocate(xc)
896 allocate(xc(rb), stat=err)
903 if (
allocated(yc))
deallocate(yc)
904 allocate(yc(rb), stat=err)
911 if (
allocated(zc))
deallocate(zc)
912 allocate(zc(rb), stat=err)
920 if (ra.gt.0 .or. rb.gt.0)
then
924 do rd=1, contj(rc,sat)
925 rf = voisj(rd,rc,sat)
933 voisj(rd,rc,sat) = -rf
939 if (ncells .gt. 1)
then
940 call calcrij (rc,rf,sat,sat,sat)
952 call update_bonds (0, sat-1, ra, ba, bb, xc, yc, zc)
953 call update_bonds (1, sat-1, rb, ca, cb, xc, yc, zc)
955 call update_atom_neighbors (sat-1, rc-1, contj(rc,sat))
956 do rd=1, contj(rc,sat)
957 call update_this_neighbor (sat-1, rc-1, rd-1, voisj(rd,rc,sat))
981 if (
allocated(thepix))
deallocate(thepix)
982 allocate(thepix(abc), stat=err)
1000 if (.not.lookngb) ra = maxn*10
1001 if (.not.lookngb .or. abc .le. 5) ra =
min(ra*5, nna)
1004 thepix(rb)%TOCHECK=.false.
1005 thepix(rb)%CHECKED=.false.
1006 allocate(thepix(rb)%ATOM_ID(ra), stat=err)
1007 if (err .ne. 0)
then
1008 alc_tab=
"THEPIX%ATOM_ID"
1017 thepix(rb)%IDNEIGH(:) = 0
1018 thepix(rb)%ATOM_ID(:) = 0
1026 if (
allocated(poa))
deallocate (poa)
1027 allocate(poa(nna,3), stat=err)
1028 if (err .ne. 0)
then
1038 if (
allocated(poa))
deallocate (poa)
1039 allocate(poa(nna,3), stat=err)
1040 if (err .ne. 0)
then
1047 if (.not.
dvtbox(sat, na, nna, poa))
then
1060 thepix(ra)%TOCHECK=.false.
1061 thepix(ra)%CHECKED=.false.
1062 thepix(ra)%IDNEIGH(:) = 0
1063 thepix(ra)%ATOM_ID(:) = 0
1068 pixpos(rb) = int((fullpos(ra,rb,sat) - pmin(rb))*cutf)
1069 if (pixpos(rb) .eq. isize(rb)) pixpos(rb) = pixpos(rb)-1
1072 if (nbx .gt. 1)
then
1073 if (ncells.gt.1)
then
1074 xyz = matmul(poa(ra,:), the_box(sat)%carttofrac/nbx)
1076 xyz = matmul(poa(ra,:), the_box(1)%carttofrac/nbx)
1079 if (ncells.gt.1)
then
1080 xyz = matmul(fullpos(ra,:,sat), the_box(sat)%carttofrac)
1082 xyz = matmul(fullpos(ra,:,sat), the_box(1)%carttofrac)
1086 uvw(rb) = xyz(rb) - floor(xyz(rb))
1087 pixpos(rb) = int(uvw(rb)*isize(rb))
1091 pix = pixpos(1) + pixpos(2)*isize(1) + pixpos(3)*ab + 1
1092 if (pix.gt.abc .or. pix.le.0)
then
1094 write (6,
'("Thread(id)= ",i4,", MD step= ",i8)') omp_get_thread_num(), sat
1096 write (6,
'("MD step= ",i8)') sat
1099 write (6,
'("at= ",i7,", pos(x)= ",f15.10,", pos(y)= ",f15.10,", pos(z)= ",f15.10)') ra, poa(ra,:)
1101 write (6,
'("at= ",i7,", pos(x)= ",f15.10,", pos(y)= ",f15.10,", pos(z)= ",f15.10)') ra, fullpos(ra,:,sat)
1104 write (6,
'("at= ",i7,", fra(x)= ",f15.10,", fra(y)= ",f15.10,", fra(z)= ",f15.10)') ra, xyz
1105 write (6,
'("at= ",i7,", cor(x)= ",f15.10,", cor(y)= ",f15.10,", cor(z)= ",f15.10)') ra, uvw
1107 write (6,
'("at= ",i7,", pixpos(x)= ",i4,", pixpos(y)= ",i4,", pixpos(z)= ",i4)') ra, pixpos
1108 write (6,
'("at= ",i7,", pixpos= ",i10)') ra, pix
1118 if ((pbc .and. ra.ge.a_start .and. ra.le.a_end) .or. .not.pbc)
then
1119 if (.not.thepix(pix)%TOCHECK)
then
1129 if (pbc .and. .not.calc_prings)
then
1130 call set_shift (shift, ai, bi, ci, isize(1), isize(2), isize(3), ab, abc)
1132 if (ai.eq.1 .or. ai.eq.isize(1)) boundary=.true.
1133 if (bi.eq.1 .or. bi.eq.isize(2)) boundary=.true.
1134 if (ci.eq.1 .or. ci.eq.isize(3)) boundary=.true.
1138 if (isize(1) .eq. 1)
then
1145 if (isize(2) .eq. 1)
then
1152 if (isize(3) .eq. 1)
then
1157 do cid=init_a, end_a
1158 do did=init_b, end_b
1159 do eid=init_c, end_c
1162 if (ai.eq.1 .and. cid.eq.1)
then
1164 else if (ai.eq.isize(1) .and. cid.eq.3)
then
1166 else if (bi.eq.1 .and. did.eq.1)
then
1168 else if (bi.eq.isize(2) .and. did.eq.3)
then
1170 else if (ci.eq.1 .and. eid.eq.1)
then
1172 else if (ci.eq.isize(3) .and. eid.eq.3)
then
1178 thepix(pix)%IDNEIGH(pid) = pix + dim(cid) + dim(did) * isize(1) + dim(eid) * ab + shift(cid,did,eid)
1183 thepix(pix)%NEIGHBOR = pid
1185 thepix(pix)%TOCHECK=.true.
1187 thepix(pix)%ATOMS = thepix(pix)%ATOMS + 1
1188 thepix(pix)%ATOM_ID(thepix(pix)%ATOMS) = ra
1195 if (thepix(rc)%TOCHECK)
then
1196 rd = thepix(rc)%ATOMS
1198 do rf=1, thepix(rc)%NEIGHBOR
1199 rg = thepix(rc)%IDNEIGH(rf)
1200 if (.not.thepix(rg)%CHECKED)
then
1201 rh = thepix(rg)%ATOMS
1203 if (rc .eq. rg)
then
1209 rk = thepix(rc)%ATOM_ID(rj)
1211 rn = thepix(rg)%ATOM_ID(rm)
1212 if ((rk.ge.a_start .and. rk.le.a_end) .or. (rn.ge.a_start .and. rn.le.a_end))
then
1213 rp=rk - (rk/nan)*nan
1214 rq=rn - (rn/nan)*nan
1215 if (rp .eq. 0) rp=nan
1216 if (rq .eq. 0) rq=nan
1217 if (rp .ne. rq)
then
1221 if (.not.pbc .or. nbx.gt.1)
then
1222 if (((rk.ge.a_start .and. rk.le.a_end) .and. (rn.ge.a_start .and. rn.le.a_end)) .or. .not.pbc)
then
1230 if (rl.ne.ro .or. .not.nohp)
then
1239 rij(rs) = poa(rk,rs) - poa(rn,rs)
1245 rij(rs) = fullpos(rp,rs,sat) - fullpos(rq,rs,sat)
1248 if (ncells .gt. 1)
then
1249 dij =
calcdij(rij,rp,rq,sat,sat,sat)
1251 dij =
calcdij(rij,rp,rq,sat,sat,1)
1253 if (dik-dij .gt.0.01d0)
then
1257 if (dij .le. gr_tmp(rl,ro))
then
1261 maxbd=
max(dij,maxbd)
1265 minbd=
min(dij,minbd)
1266 if (calc_prings)
then
1274 contj(rt,sat)=contj(rt,sat)+1
1275 if (contj(rt,sat) .gt. maxn)
then
1285 voisj(contj(rt,sat),rt,sat)=ru
1286 contj(ru,sat)=contj(ru,sat)+1
1287 if (contj(ru,sat) .gt. maxn)
then
1297 voisj(contj(ru,sat),ru,sat)=rt
1298 if (.not.calc_prings .and. upngb)
then
1301 voisj(contj(rt,sat),rt,sat)=-ru
1302 voisj(contj(ru,sat),ru,sat)=-rt
1310 if (rl .eq. ro)
then
1312 if (la_count(rp,rv,sat).eq.4 .and. contj(rp,sat).eq.4)
then
1313 if (la_count(rq,rv,sat).eq.4 .and. contj(rq,sat).eq.4)
then
1316 ry = voisj(rx,rp,sat)
1317 do rz=1, contj(ry,sat)
1318 if (voisj(rz,ry,sat) .eq. rq) rw=rw+1
1325 corta(rl,rv)=corta(rl,rv)+1
1326 if (ns .gt. 1) cornera(rl,rv,sat)=cornera(rl,rv,sat)+1
1327 elseif (rw.eq.2)
then
1331 edgeta(rl,rv)=edgeta(rl,rv)+1
1332 if (ns .gt. 1) edgea(rl,rv,sat)=edgea(rl,rv,sat)+1
1333 elseif (rw.ge.3)
then
1337 corta(rl,rv)=corta(rl,rv)+1
1341 edgeta(rl,rv)=edgeta(rl,rv)+1
1345 defta(rl,rv)=defta(rl,rv)+1
1347 cornera(rl,rv,sat)=cornera(rl,rv,sat)+1
1348 edgea(rl,rv,sat)=edgea(rl,rv,sat)+1
1349 defa(rl,rv,sat)=defa(rl,rv,sat)+1
1364 thepix(rc)%CHECKED=.true.
1368 if (.not.calc_prings .and.upngb)
then
1370 if (
allocated(ba))
deallocate(ba)
1371 allocate(ba(ra), stat=err)
1372 if (err .ne. 0)
then
1382 if (
allocated(bb))
deallocate(bb)
1383 allocate(bb(ra), stat=err)
1384 if (err .ne. 0)
then
1396 if (
allocated(ca))
deallocate(ca)
1397 allocate(ca(rb), stat=err)
1398 if (err .ne. 0)
then
1408 if (
allocated(cb))
deallocate(cb)
1409 allocate(cb(rb), stat=err)
1410 if (err .ne. 0)
then
1420 if (
allocated(xc))
deallocate(xc)
1421 allocate(xc(rb), stat=err)
1422 if (err .ne. 0)
then
1432 if (
allocated(yc))
deallocate(yc)
1433 allocate(yc(rb), stat=err)
1434 if (err .ne. 0)
then
1444 if (
allocated(zc))
deallocate(zc)
1445 allocate(zc(rb), stat=err)
1446 if (err .ne. 0)
then
1457 if (ra.gt.0 .or. rb.gt.0)
then
1461 do rd=1, contj(rc,sat)
1462 rf = voisj(rd,rc,sat)
1470 voisj(rd,rc,sat) = -rf
1476 if (ncells .gt. 1)
then
1477 dij =
calcdij(rij,rc,rf,sat,sat,sat)
1479 dij =
calcdij(rij,rc,rf,sat,sat,1)
1489 call update_bonds (0, sat-1, ra, ba, bb, xc, yc, zc)
1490 call update_bonds (1, sat-1, rb, ca, cb, xc, yc, zc)
1492 call update_atom_neighbors (sat-1, rc-1, contj(rc,sat))
1493 do rd=1, contj(rc,sat)
1494 call update_this_neighbor (sat-1, rc-1, rd-1, voisj(rd,rc,sat))
1508 if (
allocated(thepix))
deallocate(thepix)
1521 if (maxbd-minbd .lt. 0.1)
then
1522 minbd = minbd - 0.5;
1523 maxbd = maxbd + 0.5;
1525 call recup_dmin_dmax (minbd, maxbd)
1533 call show_error (
"Impossible to allocate memory !"//char(0), &
1534 "Function: DMTX"//char(0), char(9)//
"Table: "//alc_tab(1:len_trim(alc_tab))//char(0))
1536if (pixr)
call pixout (pout)
1538if (
allocated(thepix))
deallocate(thepix)
1539if (
allocated(poa))
deallocate(poa)
1540if (
allocated(ba))
deallocate(ba)
1541if (
allocated(bb))
deallocate(bb)
1542if (
allocated(ca))
deallocate(ca)
1543if (
allocated(cb))
deallocate(cb)
1544if (
allocated(xc))
deallocate(xc)
1545if (
allocated(yc))
deallocate(yc)
1546if (
allocated(zc))
deallocate(zc)