(git:27c966b)
Loading...
Searching...
No Matches
topology_snapshot.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Reader and physical moving-basis links for version-1 topology snapshots.
10! **************************************************************************************************
12 USE ai_moments, ONLY: expikr
13 USE cp_files, ONLY: close_file,&
15 USE ieee_arithmetic, ONLY: ieee_is_finite
16 USE kinds, ONLY: dp
17 USE orbital_pointers, ONLY: indco,&
19#include "./base/base_uses.f90"
20
21 IMPLICIT NONE
22 PRIVATE
23 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'topology_snapshot'
24 REAL(KIND=dp), PARAMETER :: pi = 3.1415926535897932384626433832795_dp, cell_tol = 1.e-10_dp
25 TYPE :: snapshot_shell_type
26 INTEGER :: first = 0, count = 0, lmin = 0, lmax = 0
27 REAL(KIND=dp) :: center(3) = 0.0_dp, radius = 0.0_dp
28 REAL(KIND=dp), ALLOCATABLE :: exponent(:), radii(:), contraction(:, :)
29 END TYPE snapshot_shell_type
30 TYPE :: snapshot_atom_type
31 INTEGER :: kind = 0, count = 0
32 REAL(KIND=dp) :: center(3) = 0.0_dp
33 TYPE(snapshot_shell_type), ALLOCATABLE :: shells(:)
34 END TYPE snapshot_atom_type
36 INTEGER :: nao = 0, rank = 0, nspin = 0, channel = 0
37 INTEGER :: periodic(3) = 0
38 REAL(kind=dp) :: cell(3, 3) = 0.0_dp, inverse(3, 3) = 0.0_dp, k(3) = 0.0_dp
39 TYPE(snapshot_atom_type), ALLOCATABLE :: atoms(:)
40 INTEGER, ALLOCATABLE :: bands(:)
41 REAL(kind=dp), ALLOCATABLE :: energies(:)
42 COMPLEX(KIND=dp), ALLOCATABLE :: coefficients(:, :)
43 END TYPE snapshot_type
45CONTAINS
46
47! **************************************************************************************************
48!> \brief Read a single point, retaining only its states; reject malformed/truncated exports.
49!> \param filename Version-1 STATE_EXPORT file
50!> \param point One-based point index
51!> \param state Selected frame
52! **************************************************************************************************
53 SUBROUTINE read_snapshot(filename, point, state)
54 CHARACTER(LEN=*), INTENT(IN) :: filename
55 INTEGER, INTENT(IN) :: point
56 TYPE(snapshot_type), INTENT(OUT) :: state
57
58 CHARACTER(LEN=256) :: header
59 INTEGER :: first, i, ia, ic, ios, ip, iset, ix, j, &
60 nat, nc, nk, np, ns, nt, offset, p, &
61 powers(3), refpowers(3), unit
62 LOGICAL, ALLOCATABLE :: covered(:)
63 REAL(kind=dp) :: det, k(3), pair(2)
64 REAL(kind=dp), ALLOCATABLE :: energies(:), row(:)
65
66 CALL open_file(filename, unit_number=unit, file_status='OLD', file_action='READ')
67 READ (unit, '(A)', iostat=ios) header
68 cpassert(ios == 0)
69 IF (trim(header) /= 'CP2K_TOPOLOGY_STATE 1') THEN
70 cpabort('Unsupported topology snapshot version')
71 END IF
72 READ (unit, *, iostat=ios) nat, state%nao, state%rank, nk, state%nspin, nt, state%channel
73 cpassert(ios == 0)
74 IF (min(nat, state%nao, state%rank, nk, nt, state%channel) < 1) THEN
75 cpabort('Invalid snapshot dimensions')
76 END IF
77 IF (state%rank > nt .OR. point < 1 .OR. point > nk) THEN
78 cpabort('Invalid snapshot point or rank')
79 END IF
80 IF (state%nspin /= 1 .AND. state%nspin /= 2) THEN
81 cpabort('Invalid snapshot spin components')
82 END IF
83 ALLOCATE (state%bands(state%rank), state%energies(nt), energies(nt), &
84 state%coefficients(state%nao*state%nspin, state%rank), state%atoms(nat))
85 READ (unit, *, iostat=ios) state%bands
86 cpassert(ios == 0)
87 IF (any(state%bands < 1) .OR. any(state%bands > nt)) THEN
88 cpabort('Invalid snapshot band indices')
89 END IF
90 DO i = 2, state%rank
91 IF (state%bands(i) <= state%bands(i - 1)) THEN
92 cpabort('Snapshot bands must be strictly ordered')
93 END IF
94 END DO
95 DO j = 1, 3
96 READ (unit, *, iostat=ios) state%cell(:, j)
97 cpassert(ios == 0)
98 END DO
99 IF (.NOT. all(ieee_is_finite(state%cell))) THEN
100 cpabort('Nonfinite snapshot cell')
101 END IF
102 associate(a => state%cell, b => state%inverse)
103 b(1, :) = [a(2, 2)*a(3, 3) - a(2, 3)*a(3, 2), a(1, 3)*a(3, 2) - a(1, 2)*a(3, 3), a(1, 2)*a(2, 3) - a(1, 3)*a(2, 2)]
104 b(2, :) = [a(2, 3)*a(3, 1) - a(2, 1)*a(3, 3), a(1, 1)*a(3, 3) - a(1, 3)*a(3, 1), a(1, 3)*a(2, 1) - a(1, 1)*a(2, 3)]
105 b(3, :) = [a(2, 1)*a(3, 2) - a(2, 2)*a(3, 1), a(1, 2)*a(3, 1) - a(1, 1)*a(3, 2), a(1, 1)*a(2, 2) - a(1, 2)*a(2, 1)]
106 det = dot_product(a(:, 1), b(1, :))
107 IF (abs(det) < cell_tol) THEN
108 cpabort('Singular snapshot cell')
109 END IF
110 b(:, :) = b/det
111 END associate
112 READ (unit, *, iostat=ios) state%periodic
113 cpassert(ios == 0)
114 IF (any(state%periodic < 0) .OR. any(state%periodic > 1)) THEN
115 cpabort('Invalid snapshot periodicity')
116 END IF
117 offset = 0
118 DO ia = 1, nat
119 associate(atom => state%atoms(ia))
120 READ (unit, *, iostat=ios) ix, atom%kind, ns, atom%count
121 cpassert(ios == 0)
122 IF (ix /= ia .OR. min(atom%kind, ns, atom%count) < 1) THEN
123 cpabort('Invalid snapshot atom')
124 END IF
125 READ (unit, *, iostat=ios) atom%center
126 cpassert(ios == 0)
127 IF (.NOT. all(ieee_is_finite(atom%center))) THEN
128 cpabort('Nonfinite atom center')
129 END IF
130 ALLOCATE (atom%shells(ns), covered(atom%count))
131 covered(:) = .false.
132 DO iset = 1, ns
133 associate(s => atom%shells(iset))
134 READ (unit, *, iostat=ios) first, s%count, np, nc, s%lmin, s%radius
135 cpassert(ios == 0)
136 IF (min(first, s%count, np, nc) < 1 .OR. s%lmin < 0) THEN
137 cpabort('Invalid Gaussian shell')
138 END IF
139 IF (.NOT. ieee_is_finite(s%radius) .OR. s%radius <= 0) THEN
140 cpabort('Invalid shell screening radius')
141 END IF
142 IF (first + s%count - 1 > atom%count) THEN
143 cpabort('Shell AO range exceeds atom')
144 END IF
145 IF (any(covered(first:first + s%count - 1))) THEN
146 cpabort('Overlapping shell AO ranges')
147 END IF
148 covered(first:first + s%count - 1) = .true.
149 s%lmax = 0
150 DO WHILE ((s%lmax + 1)*(s%lmax + 2)*(s%lmax + 3)/6 < nc)
151 s%lmax = s%lmax + 1
152 END DO
153 IF ((s%lmax + 1)*(s%lmax + 2)*(s%lmax + 3)/6 /= nc .OR. s%lmin > s%lmax) THEN
154 cpabort('Invalid Cartesian Gaussian count')
155 END IF
156 CALL init_orbital_pointers(s%lmax + 1)
157 s%first = offset + first
158 s%center(:) = atom%center
159 ALLOCATE (s%exponent(np), s%radii(np), s%contraction(nc*np, s%count), row(s%count))
160 DO ip = 1, np
161 READ (unit, *, iostat=ios) s%exponent(ip), s%radii(ip)
162 cpassert(ios == 0)
163 IF (.NOT. ieee_is_finite(s%exponent(ip)) .OR. .NOT. ieee_is_finite(s%radii(ip))) THEN
164 cpabort('Nonfinite primitive Gaussian')
165 END IF
166 IF (s%exponent(ip) <= 0 .OR. s%radii(ip) <= 0) THEN
167 cpabort('Invalid primitive Gaussian')
168 END IF
169 DO ic = 1, nc
170 READ (unit, *, iostat=ios) powers, row
171 cpassert(ios == 0)
172 refpowers(:) = indco(:, ic)
173 IF (any(powers /= refpowers)) THEN
174 cpabort('Unexpected Cartesian Gaussian ordering')
175 END IF
176 IF (.NOT. all(ieee_is_finite(row))) THEN
177 cpabort('Nonfinite contraction')
178 END IF
179 s%contraction((ip - 1)*nc + ic, :) = row
180 END DO
181 END DO
182 DEALLOCATE (row)
183 END associate
184 END DO
185 IF (.NOT. all(covered)) THEN
186 cpabort('Incomplete atom AO coverage')
187 END IF
188 DEALLOCATE (covered)
189 offset = offset + atom%count
190 END associate
191 END DO
192 IF (offset /= state%nao) THEN
193 cpabort('Snapshot AO count mismatch')
194 END IF
195 DO p = 1, nk
196 READ (unit, *, iostat=ios) ix, k
197 cpassert(ios == 0)
198 IF (ix /= p .OR. .NOT. all(ieee_is_finite(k))) THEN
199 cpabort('Invalid snapshot k-point')
200 END IF
201 READ (unit, *, iostat=ios) energies
202 cpassert(ios == 0)
203 IF (.NOT. all(ieee_is_finite(energies))) THEN
204 cpabort('Nonfinite snapshot spectrum')
205 END IF
206 IF (any(energies(2:) < energies(:nt - 1))) THEN
207 cpabort('Unordered snapshot spectrum')
208 END IF
209 IF (p == point) THEN
210 state%k(:) = k
211 state%energies(:) = energies
212 END IF
213 DO j = 1, state%rank
214 DO i = 1, state%nao*state%nspin
215 READ (unit, *, iostat=ios) pair
216 cpassert(ios == 0)
217 IF (.NOT. all(ieee_is_finite(pair))) THEN
218 cpabort('Nonfinite state coefficient')
219 END IF
220 IF (p == point) state%coefficients(i, j) = cmplx(pair(1), pair(2), dp)
221 END DO
222 END DO
223 END DO
224 DO
225 READ (unit, '(A)', iostat=ios) header
226 IF (ios < 0) EXIT
227 IF (ios /= 0 .OR. len_trim(header) /= 0) THEN
228 cpabort('Unexpected trailing snapshot content')
229 END IF
230 END DO
231 CALL close_file(unit)
232 END SUBROUTINE read_snapshot
233
234! **************************************************************************************************
235!> \brief Apply screened Gaussian cross-geometry operator by atom blocks, without a dense AO matrix.
236!> \param a Left physical state
237!> \param b Right physical state
238!> \param ka Unwrapped left fractional k-point
239!> \param kb Unwrapped right fractional k-point
240!> \param overlap Selected-state overlap including all spinor components
241! **************************************************************************************************
242 SUBROUTINE snapshot_overlap(a, b, ka, kb, overlap)
243 TYPE(snapshot_type), INTENT(IN) :: a, b
244 REAL(kind=dp), INTENT(IN) :: ka(3), kb(3)
245 COMPLEX(KIND=dp), INTENT(OUT) :: overlap(:, :)
246
247 COMPLEX(KIND=dp) :: part(size(overlap, 1), size(overlap, 2))
248 INTEGER :: ia
249
250 IF (any(shape(overlap) /= [a%rank, b%rank])) THEN
251 cpabort('Incorrect overlap output dimensions')
252 END IF
253 IF (a%nspin /= b%nspin .OR. a%channel /= b%channel .OR. a%rank /= b%rank) THEN
254 cpabort('Changed spin or rank')
255 END IF
256 IF (any(a%bands /= b%bands)) THEN
257 cpabort('Changed selected band indices')
258 END IF
259 IF (SIZE(a%atoms) /= SIZE(b%atoms) .OR. a%nao /= b%nao) THEN
260 cpabort('Changed atom or AO count')
261 END IF
262 IF (maxval(abs(a%cell - b%cell)) > cell_tol .OR. any(a%periodic /= b%periodic)) THEN
263 cpabort('Changed cell')
264 END IF
265 IF (.NOT. all(ieee_is_finite(ka)) .OR. .NOT. all(ieee_is_finite(kb))) THEN
266 cpabort('Nonfinite k-point')
267 END IF
268 IF (maxval(abs(ka - a%k - anint(ka - a%k))) > cell_tol .OR. &
269 maxval(abs(kb - b%k - anint(kb - b%k))) > cell_tol) THEN
270 cpabort('Frame k-point does not match request')
271 END IF
272 overlap(:, :) = 0.0_dp
273!$OMP PARALLEL DO DEFAULT(NONE) SHARED(A,b,ka,kb) PRIVATE(ia,part) REDUCTION(+:overlap) SCHEDULE(DYNAMIC)
274 DO ia = 1, SIZE(a%atoms)
275 CALL atom_overlap(a, b, ia, ka, kb, part)
276 overlap(:, :) = overlap + part
277 END DO
278!$OMP END PARALLEL DO
279 END SUBROUTINE snapshot_overlap
280
281! **************************************************************************************************
282!> \brief Screened atom-row contribution using CP2K's complex plane-wave primitive integrals.
283!> \param a Left physical state
284!> \param b Right physical state
285!> \param ia Left atom whose AO rows are contracted
286!> \param ka Unwrapped left fractional k-point
287!> \param kb Unwrapped right fractional k-point
288!> \param atom_link This atom's contribution to the selected-state overlap
289! **************************************************************************************************
290 SUBROUTINE atom_overlap(a, b, ia, ka, kb, atom_link)
291 TYPE(snapshot_type), INTENT(IN) :: a, b
292 INTEGER, INTENT(IN) :: ia
293 REAL(kind=dp), INTENT(IN) :: ka(3), kb(3)
294 COMPLEX(KIND=dp), INTENT(OUT) :: atom_link(:, :)
295
296 COMPLEX(KIND=dp) :: phase
297 COMPLEX(KIND=dp), ALLOCATABLE :: block(:, :), expab(:, :), oc(:, :, :)
298 INTEGER :: af, bf, hi(3), i, ib, image(3), j, k, &
299 lo(3), nc_a, nc_b, s, sa, sb
300 REAL(kind=dp) :: bounds(3), cutoff, disp(3), q(3), rb(3)
301
302 q(:) = 2.0_dp*pi*matmul(transpose(a%inverse), kb - ka)
303 atom_link(:, :) = 0.0_dp
304 DO sa = 1, SIZE(a%atoms(ia)%shells)
305 associate(left => a%atoms(ia)%shells(sa))
306 ALLOCATE (oc(left%count, b%rank, a%nspin))
307 oc(:, :, :) = 0.0_dp
308 nc_a = SIZE(left%contraction, 1)
309 DO ib = 1, SIZE(b%atoms)
310 DO sb = 1, SIZE(b%atoms(ib)%shells)
311 associate(right => b%atoms(ib)%shells(sb))
312 cutoff = left%radius + right%radius
313 disp(:) = matmul(a%inverse, right%center - left%center)
314 DO i = 1, 3
315 bounds(i) = cutoff*norm2(a%inverse(i, :))
316 END DO
317 lo(:) = ceiling(-disp - bounds)
318 hi(:) = floor(-disp + bounds)
319 WHERE (a%periodic == 0)
320 lo = 0
321 hi = 0
322 END WHERE
323 nc_b = SIZE(right%contraction, 1)
324 ALLOCATE (expab(nc_a, nc_b), block(left%count, right%count))
325 block(:, :) = 0.0_dp
326 DO k = lo(3), hi(3)
327 DO j = lo(2), hi(2)
328 DO i = lo(1), hi(1)
329 image(:) = [i, j, k]
330 rb(:) = right%center + matmul(a%cell, real(image, dp))
331 IF (norm2(rb - left%center) > cutoff) cycle
332 CALL expikr(left%lmax, SIZE(left%exponent), left%exponent, left%radii, left%lmin, &
333 right%lmax, SIZE(right%exponent), right%exponent, right%radii, right%lmin, &
334 left%center, rb, -q, expab)
335 phase = exp(cmplx(0.0_dp, 2.0_dp*pi*dot_product(kb, real(image, dp)), dp))
336 block(:, :) = block + phase*matmul(transpose(left%contraction), &
337 matmul(expab, right%contraction))
338 END DO
339 END DO
340 END DO
341 DO s = 1, a%nspin
342 bf = right%first + (s - 1)*b%nao
343 oc(:, :, s) = oc(:, :, s) + matmul(block, b%coefficients(bf:bf + right%count - 1, :))
344 END DO
345 DEALLOCATE (expab, block)
346 END associate
347 END DO
348 END DO
349 DO s = 1, a%nspin
350 af = left%first + (s - 1)*a%nao
351 atom_link(:, :) = atom_link + matmul(conjg(transpose(a%coefficients(af:af + left%count - 1, :))), oc(:, :, s))
352 END DO
353 DEALLOCATE (oc)
354 END associate
355 END DO
356 END SUBROUTINE atom_overlap
357
358! **************************************************************************************************
359!> \brief Check AO-metric normalization and separation at every selected/excluded boundary.
360!> \param a Physical frame to validate
361!> \param metric_tol Maximum entrywise error in C^dagger S C minus identity
362!> \param gap_tol Minimum sampled selected/excluded-band separation in hartree
363!> \param metric_error Observed normalization error
364!> \param gap Smallest sampled selected/excluded-band separation in hartree
365! **************************************************************************************************
366 SUBROUTINE check_snapshot(a, metric_tol, gap_tol, metric_error, gap)
367 TYPE(snapshot_type), INTENT(IN) :: a
368 REAL(kind=dp), INTENT(IN) :: metric_tol, gap_tol
369 REAL(kind=dp), INTENT(OUT) :: metric_error, gap
370
371 INTEGER :: i
372 LOGICAL :: selected(size(a%energies))
373 COMPLEX(KIND=dp) :: metric(a%rank, a%rank)
374
375 CALL snapshot_overlap(a, a, a%k, a%k, metric)
376 DO i = 1, a%rank
377 metric(i, i) = metric(i, i) - 1.0_dp
378 END DO
379 metric_error = maxval(abs(metric))
380 IF (.NOT. ieee_is_finite(metric_error) .OR. metric_error > metric_tol) THEN
381 cpabort('Frame is not AO-metric normalized')
382 END IF
383 selected(:) = .false.
384 selected(a%bands) = .true.
385 gap = huge(1.0_dp)
386 DO i = 1, SIZE(a%energies) - 1
387 IF (selected(i) .NEQV. selected(i + 1)) gap = min(gap, a%energies(i + 1) - a%energies(i))
388 END DO
389 IF (gap == huge(1.0_dp) .OR. gap <= gap_tol) THEN
390 cpabort('No verified sampled subspace isolation')
391 END IF
392 END SUBROUTINE check_snapshot
393
394! **************************************************************************************************
395!> \brief Check explicitly prescribed atom permutation, periodic translations and basis at a seam.
396!> \param a Start frame
397!> \param b Endpoint frame
398!> \param permutation One-based endpoint-atom to start-atom map
399!> \param tolerance Absolute tolerance for geometry and basis agreement
400! **************************************************************************************************
401 SUBROUTINE check_snapshot_seam(a, b, permutation, tolerance)
402 TYPE(snapshot_type), INTENT(IN) :: a, b
403 INTEGER, INTENT(IN) :: permutation(:)
404 REAL(kind=dp), INTENT(IN) :: tolerance
405
406 INTEGER :: i, j, n, s
407 REAL(kind=dp) :: delta(3), shift(3)
408
409 n = SIZE(a%atoms)
410 IF (SIZE(b%atoms) /= n .OR. SIZE(permutation) /= n) THEN
411 cpabort('Seam atom count mismatch')
412 END IF
413 IF (any(permutation < 1) .OR. any(permutation > n)) THEN
414 cpabort('Invalid seam permutation')
415 END IF
416 DO i = 1, n
417 IF (count(permutation == i) /= 1) THEN
418 cpabort('Seam atom map is not a permutation')
419 END IF
420 END DO
421 IF (maxval(abs(a%cell - b%cell)) > tolerance .OR. any(a%periodic /= b%periodic)) THEN
422 cpabort('Seam cell mismatch')
423 END IF
424 DO i = 1, n
425 j = permutation(i)
426 associate(left => a%atoms(j), right => b%atoms(i))
427 IF (left%kind /= right%kind .OR. left%count /= right%count) THEN
428 cpabort('Seam changes atom kind or AO count')
429 END IF
430 IF (SIZE(left%shells) /= SIZE(right%shells)) THEN
431 cpabort('Seam changes basis')
432 END IF
433 delta(:) = right%center - left%center
434 shift(:) = anint(matmul(a%inverse, delta))
435 WHERE (a%periodic == 0) shift = 0.0_dp
436 IF (maxval(abs(delta - matmul(a%cell, shift))) > tolerance) THEN
437 cpabort('Geometry does not close at seam')
438 END IF
439 DO s = 1, SIZE(left%shells)
440 associate(x => left%shells(s), y => right%shells(s))
441 IF (x%count /= y%count .OR. x%lmin /= y%lmin .OR. x%lmax /= y%lmax) THEN
442 cpabort('Seam changes shell')
443 END IF
444 IF (any(shape(x%contraction) /= shape(y%contraction))) THEN
445 cpabort('Seam changes contractions')
446 END IF
447 IF (SIZE(x%exponent) /= SIZE(y%exponent)) THEN
448 cpabort('Seam changes primitives')
449 END IF
450 IF (maxval(abs(x%radii - y%radii)) > tolerance .OR. abs(x%radius - y%radius) > tolerance) THEN
451 cpabort('Seam changes Gaussian screening radii')
452 END IF
453 IF (maxval(abs(x%exponent - y%exponent)) > tolerance .OR. &
454 maxval(abs(x%contraction - y%contraction)) > tolerance) THEN
455 cpabort('Seam changes physical basis')
456 END IF
457 END associate
458 END DO
459 END associate
460 END DO
461 END SUBROUTINE check_snapshot_seam
462END MODULE topology_snapshot
Calculation of the moment integrals over Cartesian Gaussian-type functions.
Definition ai_moments.F:17
subroutine, public expikr(la_max_set, npgfa, zeta, rpgfa, la_min_set, lb_max, npgfb, zetb, rpgfb, lb_min, rac, rbc, kvec, expab, dexpab, dexpba, momentab)
Evaluate primitive exp(i k.r) integrals through the complex overlap recurrence.
Definition ai_moments.F:163
Definition atom.F:9
Utility routines to open and close files.
Definition cp_files.F:22
subroutine, public open_file(file_name, unit_number, file_status, file_form, file_action, file_position, file_pad, file_access, debug)
Opens a file and returns its logical unit number.
Definition cp_files.F:197
subroutine, public close_file(unit_number, file_status)
Closes an open file given by its logical unit number.
Definition cp_files.F:64
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Provides Cartesian and spherical orbital pointers and indices.
subroutine, public init_orbital_pointers(maxl)
Initialize or update the orbital pointers.
integer, dimension(:, :), allocatable, public indco
Reader and physical moving-basis links for version-1 topology snapshots.
subroutine, public check_snapshot_seam(a, b, permutation, tolerance)
Check explicitly prescribed atom permutation, periodic translations and basis at a seam.
subroutine, public snapshot_overlap(a, b, ka, kb, overlap)
Apply screened Gaussian cross-geometry operator by atom blocks, without a dense AO matrix.
subroutine, public check_snapshot(a, metric_tol, gap_tol, metric_error, gap)
Check AO-metric normalization and separation at every selected/excluded boundary.
subroutine, public read_snapshot(filename, point, state)
Read a single point, retaining only its states; reject malformed/truncated exports.