17#include "../base/base_uses.f90"
24 REAL(KIND=
dp) :: epot = 0.0
25 REAL(kind=
dp),
DIMENSION(:),
ALLOCATABLE :: goedecker
28 TYPE history_entry_type
31 END TYPE history_entry_type
35 TYPE(history_entry_type),
DIMENSION(:),
POINTER :: entries => null()
38 REAL(kind=
dp) :: e_precision = 0.0
39 REAL(kind=
dp) :: fp_precision = 0.0
48 LOGICAL,
PARAMETER ::
debug = .false.
49 INTEGER,
PARAMETER :: history_grow_unit = 1000
64 ALLOCATE (history%entries(history_grow_unit))
67 r_val=history%E_precision)
69 r_val=history%FP_precision)
72 WRITE (iw,
'(A,T66,E15.3)') &
73 " GLBOPT| History energy precision", history%E_precision
74 WRITE (iw,
'(A,T66,E15.3)') &
75 " GLBOPT| History fingerprint precision", history%FP_precision
87 REAL(kind=
dp),
INTENT(IN) :: epot
88 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: pos
92 REAL(kind=
dp),
DIMENSION(:),
POINTER :: tmp
94 CALL timeset(
"glbopt_history_fingerprint", handle)
98 CALL goedecker_fingerprint(pos, tmp)
101 ALLOCATE (fp%goedecker(
SIZE(tmp)))
102 fp%goedecker(:) = tmp
105 CALL timestop(handle)
115 SUBROUTINE goedecker_fingerprint(pos, res)
116 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: pos
117 REAL(kind=
dp),
DIMENSION(:),
POINTER :: res
119 INTEGER :: i, info, j, n
120 REAL(kind=
dp) :: d2, t
121 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: matrix, work
122 REAL(kind=
dp),
DIMENSION(3) :: d
124 IF (
ASSOCIATED(res)) cpabort(
"goedecker_fingerprint: res already allocated")
127 ALLOCATE (matrix(n, n), work(n, n))
131 d = pos(3*i - 2:3*i) - pos(3*j - 2:3*j)
140 CALL dsyev(
'N',
'U', n, matrix, n, res, work, n**2, info)
141 IF (info /= 0) cpabort(
"goedecker_fingerprint: DSYEV failed")
142 END SUBROUTINE goedecker_fingerprint
157 res = (abs(fp1%Epot - fp2%Epot) < history%E_precision) .AND. &
158 (fingerprint_distance(fp1, fp2) < history%fp_precision)
170 PURE FUNCTION fingerprint_distance(fp1, fp2)
RESULT(res)
174 res = sqrt(sum((fp1%goedecker - fp2%goedecker)**2)/
SIZE(fp1%goedecker))
175 END FUNCTION fingerprint_distance
188 INTEGER,
INTENT(IN),
OPTIONAL :: id
190 INTEGER :: handle, i, k, n
191 TYPE(history_entry_type),
DIMENSION(:),
POINTER :: tmp
193 CALL timeset(
"glbopt_history_add", handle)
195 n =
SIZE(history%entries)
196 IF (n == history%length)
THEN
198 tmp => history%entries
199 ALLOCATE (history%entries(n + history_grow_unit))
200 history%entries(1:n) = tmp(:)
202 n = n + history_grow_unit
205 k = interpolation_search(history, fingerprint%Epot)
211 history%entries(i) = history%entries(i - 1)
214 ALLOCATE (history%entries(k)%p)
215 history%entries(k)%p = fingerprint
217 history%entries(k)%id = id
218 history%length = history%length + 1
222 DO k = 1, history%length
225 IF (history%entries(k - 1)%p%Epot > history%entries(k)%p%Epot) &
226 cpabort(
"history_add: history in wrong order")
231 CALL timestop(handle)
245 LOGICAL,
INTENT(OUT) :: found
246 INTEGER,
INTENT(OUT),
OPTIONAL :: id
248 INTEGER :: found_i, handle, i, k, k_max, k_min
249 REAL(kind=
dp) :: best_match, dist, epot
251 CALL timeset(
"glbopt_history_lookup", handle)
254 IF (
PRESENT(id)) id = -1
255 best_match = huge(1.0_dp)
257 IF (history%length > 0)
THEN
258 epot = fingerprint%Epot
259 k = interpolation_search(history, fingerprint%Epot)
261 DO k_min = k - 1, 1, -1
262 IF (history%entries(k_min)%p%Epot < epot - history%E_precision)
EXIT
265 DO k_max = k, history%length
266 IF (history%entries(k_max)%p%Epot > epot + history%E_precision)
EXIT
269 k_min = max(k_min + 1, 1)
270 k_max = min(k_max - 1, history%length)
272 IF (
debug) found_i = -1
275 dist = fingerprint_distance(fingerprint, history%entries(i)%p)
277 IF (dist < history%fp_precision .AND. dist < best_match)
THEN
280 IF (
PRESENT(id)) id = history%entries(i)%id
281 IF (
debug) found_i = i
285 IF (
debug)
CALL verify_history_lookup(history, fingerprint, found_i)
288 CALL timestop(handle)
299 FUNCTION interpolation_search(history, Efind)
RESULT(res)
301 REAL(kind=
dp),
INTENT(IN) :: efind
304 INTEGER :: high, low, mid
305 REAL(kind=
dp) :: slope
308 high = history%length
310 DO WHILE (low < high)
312 slope = real(high - low, kind=
dp)/(history%entries(high)%p%Epot - history%entries(low)%p%Epot)
313 mid = low + int(slope*(efind - history%entries(low)%p%Epot))
314 mid = min(max(mid, low), high)
316 IF (history%entries(mid)%p%Epot < efind)
THEN
323 IF (0 < low .AND. low <= history%length)
THEN
324 IF (efind > history%entries(low)%p%Epot) low = low + 1
328 END FUNCTION interpolation_search
337 SUBROUTINE verify_history_lookup(history, fingerprint, found_i_ref)
340 INTEGER,
INTENT(IN) :: found_i_ref
342 INTEGER :: found_i, i
343 REAL(kind=
dp) :: best_fp_match, epot_dist, fp_dist
346 best_fp_match = huge(1.0_dp)
348 DO i = 1, history%length
349 epot_dist = abs(fingerprint%Epot - history%entries(i)%p%Epot)
350 IF (epot_dist > history%E_precision) cycle
351 fp_dist = fingerprint_distance(fingerprint, history%entries(i)%p)
353 IF (fp_dist < history%fp_precision .AND. fp_dist < best_fp_match)
THEN
354 best_fp_match = fp_dist
359 IF (found_i /= found_i_ref)
THEN
360 WRITE (*, *) found_i, found_i_ref
361 cpabort(
"verify_history_lookup failed")
364 END SUBROUTINE verify_history_lookup
376 DO i = 1, history%length
377 IF (
ASSOCIATED(history%entries(i)%p)) &
378 DEALLOCATE (history%entries(i)%p)
381 DEALLOCATE (history%entries)
History of minima, calculates, stores and compares fingerprints of minima. Used by Minima Hopping and...
subroutine, public history_init(history, history_section, iw)
Initializes a history.
type(history_fingerprint_type) function, public history_fingerprint(epot, pos)
Calculates a fingerprint for a given configuration.
subroutine, public history_lookup(history, fingerprint, found, id)
Checks if a given fingerprints is contained in the history.
subroutine, public history_finalize(history)
Finalizes a history.
subroutine, public history_add(history, fingerprint, id)
Addes a new fingerprints to the history. Optionally, an abitrary id can be stored alongside the finge...
logical function, public history_fingerprint_match(history, fp1, fp2)
Checks if two given fingerprints match.
Defines the basic variable types.
integer, parameter, public dp