92RECURSIVE SUBROUTINE setmol (this_mol, toglin, stmb, molcount, the_step, the_atom, the_id)
98TYPE (
mol),
POINTER,
INTENT(INOUT) :: this_mol
99INTEGER,
INTENT(INOUT) :: molcount, stmb
100INTEGER,
INTENT(IN) :: the_step, the_atom, the_id
101INTEGER,
DIMENSION(NA),
INTENT(INOUT) :: toglin
104 LOGICAL FUNCTION add_ato(this_mol, ATOM_ID)
106 TYPE (
mol),
POINTER,
INTENT(INOUT) :: this_mol
107 INTEGER,
INTENT(IN) :: atom_id
112toglin(the_atom) = the_id
113this_mol%ATOMES = this_mol%ATOMES + 1
114this_mol%BSP(lot(the_atom)) = this_mol%BSP(lot(the_atom)) + 1
116if (this_mol%ATOMES > 1)
then
117 if (.not.
add_ato(this_mol, the_atom))
then
122 allocate(this_mol%FIRST_AT, stat=err)
130 this_mol%FIRST_AT%IND = the_atom
131 this_mol%ATOM => this_mol%FIRST_AT
133if (stmb .eq. na)
goto 002
134if (molcount.eq.10000)
goto 001
135if (molcount.eq.-1)
goto 001
136do mc=1, contj(the_atom, the_step)
137 md = voisj(mc,the_atom,the_step)
138 if (toglin(md).eq.0 .and. molcount.lt.10000)
then
139 call setmol (this_mol, toglin, stmb, molcount, the_step, voisj(mc,the_atom,the_step), the_id)
141 if (stmb .eq. na)
goto 002
142 if (molcount.eq.10000)
goto 001
143 if (molcount.eq.-1)
goto 001
154INTEGER (KIND=c_int) FUNCTION molecules (frag_and_mol, allbonds) bind (C,NAME='molecules_')
163INTEGER (KIND=c_int),
INTENT(IN) :: frag_and_mol, allbonds
164INTEGER :: totmol, molps, maxmol
165INTEGER,
DIMENSION(:),
ALLOCATABLE :: atmol
166INTEGER,
DIMENSION(:),
ALLOCATABLE :: atvs, mtmbs
171 LOGICAL FUNCTION add_mol(this_mol, MOL_ID, STEP_ID)
173 TYPE (
mol),
POINTER,
INTENT(INOUT) :: this_mol
174 INTEGER,
INTENT(IN) :: mol_id, step_id
176 RECURSIVE SUBROUTINE setmol (this_mol, toglin, stmb, molcount, the_step, the_atom, the_id)
178 TYPE (
mol),
POINTER,
INTENT(INOUT) :: this_mol
179 INTEGER,
INTENT(INOUT) :: molcount, stmb
180 INTEGER,
INTENT(IN) :: the_step, the_atom, the_id
181 INTEGER,
DIMENSION(NA),
INTENT(INOUT) :: toglin
185TYPE (at),
POINTER :: tmpat
186TYPE (mol),
ALLOCATABLE,
TARGET :: themol
187TYPE (mol),
POINTER :: tmpmol
189if (
allocated(fullpos))
deallocate(fullpos)
194 if (contj(j,i) .eq. 0) k = k + 1
197maxmol = k + allbonds/2;
199if (
allocated(themol))
deallocate(themol)
200allocate(themol, stat=err)
207if (
allocated(mtmbs))
deallocate(mtmbs)
208allocate(mtmbs(ns), stat=err)
216if (frag_and_mol .eq. 1)
then
217 call allocate_mol_data ()
222numth = omp_get_max_threads()
223if (ns.lt.numth) numth=ns
229if (
allocated(togl))
deallocate(togl)
230allocate(togl(na), stat=err)
250 allocate(tmpmol, stat=err)
266 nullify(themol%FIRST_AT)
267 allocate(themol%BSP(nsp), stat=err)
292 if (molcounter.eq.0 .and. togl(j).eq.0)
then
295 if (.not.
add_mol(tmpmol, mtmbs(i)+1, i))
then
306 mtmbs(i) = mtmbs(i) + 1
307 call setmol (tmpmol, togl, tmbs, molcounter, i, j, totmol)
308 if (molcounter .lt. 0)
then
317 if (tmbs.eq.na)
goto 003
319 if (molcounter.eq.10000)
goto 002
323 else if (molcounter.gt.0 .and.togl(j).eq.totmol)
then
326 if (togl(m).eq.0)
then
328 call setmol (tmpmol, togl, tmbs, molcounter, i, voisj(l,j,i), totmol)
329 if (molcounter .lt. 0)
then
338 if (tmbs.eq.na)
goto 003
339 if (molcounter.eq.10000)
goto 002
346 if (tmbs .lt. na)
then
353 if (frag_and_mol .eq. 1)
then
356 call allocate_mol_for_step (i, mtmbs(i))
358 allocate(atmol(tmpmol%ATOMES), stat=err)
370 if (tmpmol%ATOMES .gt. 1)
then
371 allocate(tmpat, stat=err)
382 tmpat = tmpmol%FIRST_AT
383 do k=1, tmpmol%ATOMES
385 if (k < tmpmol%ATOMES)
then
387 deallocate (tmpat%PREV)
392 atmol(1) = tmpmol%FIRST_AT%IND
393 deallocate (tmpmol%FIRST_AT)
395 call send_mol_details (tmpmol%STEP, tmpmol%MID, tmpmol%ATOMES, nsp, tmpmol%BSP, atmol)
396 if (tmpmol%ATOMES .gt. 1)
then
397 do l=1, tmpmol%ATOMES
399 n = contj(m,tmpmol%STEP)
400 allocate(atvs(n), stat=err)
412 atvs(o)= voisj(o,m,tmpmol%STEP)
414 call send_mol_neighbors (tmpmol%STEP, tmpmol%MID, m, n, atvs)
420 if (j .lt. mtmbs(i)) tmpmol => tmpmol%NEXT
426 do while (tmpmol%MID .gt. 1)
427 tmpmol => tmpmol%PREV
428 deallocate (tmpmol%NEXT%BSP)
429 deallocate (tmpmol%NEXT)
431 deallocate (tmpmol%BSP)
433 call setup_fragments (i, togl)
443if (
allocated(togl))
deallocate (togl)
444if (
allocated(themol))
deallocate(themol)
445if (
allocated(atmol))
deallocate(atmol)
446if (
allocated(atvs))
deallocate(atvs)
449if (
allocated(togl))
deallocate (togl)
450if (
allocated(themol))
deallocate(themol)
451if (
allocated(atvs))
deallocate(atvs)
452if (
allocated(atmol))
deallocate(atmol)
458 molps = molps + mtmbs(i)
461call send_coord_opengl (2, 1, 0, 0, j, 1)
462call init_menu_fragmol (2)
464if (frag_and_mol .eq. 1)
then
465 call setup_menu_molecules ()
473 call show_error (
"Impossible to allocate memory !"//char(0), &
474 "Function: molecules"//char(0), char(9)//
"Table: "//alc_tab(1:len_trim(alc_tab))//char(0))
477if (
allocated(mtmbs))
deallocate(mtmbs)
recursive subroutine setmol(this_mol, toglin, stmb, molcount, the_step, the_atom, the_id)