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
216 IF (
PRESENT(id))
THEN
217 history%entries(k)%id = id
219 history%length = history%length + 1
223 DO k = 1, history%length
226 IF (history%entries(k - 1)%p%Epot > history%entries(k)%p%Epot)
THEN
227 cpabort(
"history_add: history in wrong order")
233 CALL timestop(handle)
247 LOGICAL,
INTENT(OUT) :: found
248 INTEGER,
INTENT(OUT),
OPTIONAL :: id
250 INTEGER :: found_i, handle, i, k, k_max, k_min
251 REAL(kind=
dp) :: best_match, dist, epot
253 CALL timeset(
"glbopt_history_lookup", handle)
256 IF (
PRESENT(id)) id = -1
257 best_match = huge(1.0_dp)
259 IF (history%length > 0)
THEN
260 epot = fingerprint%Epot
261 k = interpolation_search(history, fingerprint%Epot)
263 DO k_min = k - 1, 1, -1
264 IF (history%entries(k_min)%p%Epot < epot - history%E_precision)
EXIT
267 DO k_max = k, history%length
268 IF (history%entries(k_max)%p%Epot > epot + history%E_precision)
EXIT
271 k_min = max(k_min + 1, 1)
272 k_max = min(k_max - 1, history%length)
274 IF (
debug) found_i = -1
277 dist = fingerprint_distance(fingerprint, history%entries(i)%p)
279 IF (dist < history%fp_precision .AND. dist < best_match)
THEN
282 IF (
PRESENT(id)) id = history%entries(i)%id
283 IF (
debug) found_i = i
287 IF (
debug)
CALL verify_history_lookup(history, fingerprint, found_i)
290 CALL timestop(handle)
301 FUNCTION interpolation_search(history, Efind)
RESULT(res)
303 REAL(kind=
dp),
INTENT(IN) :: efind
306 INTEGER :: high, low, mid
307 REAL(kind=
dp) :: slope
310 high = history%length
312 DO WHILE (low < high)
314 slope = real(high - low, kind=
dp)/(history%entries(high)%p%Epot - history%entries(low)%p%Epot)
315 mid = low + int(slope*(efind - history%entries(low)%p%Epot))
316 mid = min(max(mid, low), high)
318 IF (history%entries(mid)%p%Epot < efind)
THEN
325 IF (0 < low .AND. low <= history%length)
THEN
326 IF (efind > history%entries(low)%p%Epot) low = low + 1
330 END FUNCTION interpolation_search
339 SUBROUTINE verify_history_lookup(history, fingerprint, found_i_ref)
342 INTEGER,
INTENT(IN) :: found_i_ref
344 INTEGER :: found_i, i
345 REAL(kind=
dp) :: best_fp_match, epot_dist, fp_dist
348 best_fp_match = huge(1.0_dp)
350 DO i = 1, history%length
351 epot_dist = abs(fingerprint%Epot - history%entries(i)%p%Epot)
352 IF (epot_dist > history%E_precision) cycle
353 fp_dist = fingerprint_distance(fingerprint, history%entries(i)%p)
355 IF (fp_dist < history%fp_precision .AND. fp_dist < best_fp_match)
THEN
356 best_fp_match = fp_dist
361 IF (found_i /= found_i_ref)
THEN
362 WRITE (*, *) found_i, found_i_ref
363 cpabort(
"verify_history_lookup failed")
366 END SUBROUTINE verify_history_lookup
378 DO i = 1, history%length
379 IF (
ASSOCIATED(history%entries(i)%p))
THEN
380 DEALLOCATE (history%entries(i)%p)
384 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