-
Notifications
You must be signed in to change notification settings - Fork 44
/
vasprun.py
805 lines (667 loc) · 26.7 KB
/
vasprun.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
"""
vasprun parser.
---------------
The file parser that handles the parsing of vasprun.xml files.
"""
# pylint: disable=too-many-public-methods, protected-access
import sys
import numpy as np
from parsevasp.vasprun import Xml
from parsevasp.kpoints import Kpoint
from parsevasp import constants as parsevaspct
from aiida_vasp.parsers.file_parsers.parser import BaseFileParser, SingleFile
from aiida_vasp.utils.compare_bands import get_band_properties
DEFAULT_OPTIONS = {
'quantities_to_parse': [
'structure',
'eigenvalues',
'dos',
'bands',
'kpoints',
'occupancies',
'trajectory',
'energies',
'projectors',
'dielectrics',
'born_charges',
'hessian',
'dynmat',
'forces',
'stress',
'total_energies',
'maximum_force',
'maximum_stress',
'band_properties',
#'run_status',
'version',
],
'energy_type': ['energy_extrapolated'],
'electronic_step_energies': False
}
# Mapping of the energy names to those returned by parsevasp.vasprunl.Xml
ENERGY_MAPPING = {
'energy_extrapolated': 'energy_extrapolated_final',
'energy_free': 'energy_free_final',
'energy_no_entropy': 'energy_no_entropy_final',
'energy_extrapolated_electronic': 'energy_extrapolated',
'energy_free_electronic': 'energy_free',
'energy_no_entropy_electronic': 'energy_no_entropy',
}
ENERGY_MAPPING_VASP5 = {
'energy_extrapolated': 'energy_no_entropy_final',
'energy_free': 'energy_free_final',
# Not that energy_extrapolated_final parsed is the entropy term
'energy_no_entropy': 'energy_extrapolated_final',
'energy_extrapolated_electronic': 'energy_extrapolated',
'energy_free_electronic': 'energy_free',
'energy_no_entropy_electronic': 'energy_no_entropy',
}
class VasprunParser(BaseFileParser):
"""Interface to parsevasp's xml parser."""
PARSABLE_ITEMS = {
'structure': {
'inputs': [],
'name': 'structure',
'prerequisites': [],
'alternatives': ['poscar-structure']
},
'eigenvalues': {
'inputs': [],
'name': 'eigenvalues',
'prerequisites': [],
'alternatives': ['eigenval-eigenvalues']
},
'dos': {
'inputs': [],
'name': 'dos',
'prerequisites': [],
'alternatives': ['doscar-dos']
},
'kpoints': {
'inputs': [],
'name': 'kpoints',
'prerequisites': [],
'alternatives': ['kpoints-kpoints']
},
'occupancies': {
'inputs': [],
'name': 'occupancies',
'prerequisites': [],
},
'trajectory': {
'inputs': [],
'name': 'trajectory',
'prerequisites': [],
},
'energies': {
'inputs': [],
'name': 'energies',
'prerequisites': [],
},
'total_energies': {
'inputs': [],
'name': 'total_energies',
'prerequisites': [],
},
'projectors': {
'inputs': [],
'name': 'projectors',
'prerequisites': [],
},
'dielectrics': {
'inputs': [],
'name': 'dielectrics',
'prerequisites': [],
},
'stress': {
'inputs': [],
'name': 'stress',
'prerequisites': [],
},
'forces': {
'inputs': [],
'name': 'forces',
'prerequisites': [],
},
'born_charges': {
'inputs': [],
'name': 'born_charges',
'prerequisites': [],
},
'hessian': {
'inputs': [],
'name': 'hessian',
'prerequisites': [],
},
'dynmat': {
'inputs': [],
'name': 'dynmat',
'prerequisites': [],
},
'fermi_level': {
'inputs': [],
'name': 'fermi_level',
'prerequisites': [],
},
'maximum_force': {
'inputs': [],
'name': 'maximum_force',
'prerequisites': []
},
'maximum_stress': {
'inputs': [],
'name': 'maximum_stress',
'prerequisites': []
},
'band_properties': {
'inputs': [],
'name': 'band_properties',
'prerequisites': [],
},
# 'run_status': {
# 'inputs': [],
# 'name': 'run_status',
# 'prerequisites': [],
# },
'version': {
'inputs': [],
'name': 'version',
'prerequisites': [],
}
}
def __init__(self, *args, **kwargs):
"""
Initialize vasprun.xml parser
file_path : str
File path.
data : SingleFileData
AiiDA Data class install to store a single file.
settings : ParserSettings
exit_codes : CalcJobNode.process_class.exit_codes
"""
super(VasprunParser, self).__init__(*args, **kwargs)
self._xml = None
self._xml_truncated = False
self._settings = kwargs.get('settings', None)
self._exit_codes = kwargs.get('exit_codes', None)
if 'file_path' in kwargs:
self._init_xml(kwargs['file_path'])
if 'data' in kwargs:
self._init_xml(kwargs['data'].get_file_abs_path())
def _init_xml(self, path):
"""Create parsevasp Xml instance"""
self._data_obj = SingleFile(path=path)
# Since vasprun.xml can be fairly large, we will parse it only
# once and store the parsevasp Xml object.
try:
self._xml = Xml(file_path=path, k_before_band=True, logger=self._logger)
# Let us also check if the xml was truncated as the parser uses lxml and its
# recovery mode in case we can use some of the results.
self._xml_truncated = self._xml.truncated
except SystemExit:
self._logger.warning('Parsevasp exited abruptly. Returning None.')
self._xml = None
def _parse_file(self, inputs):
"""Parse the quantities related to this file parser."""
# Since all quantities will be returned by properties, we can't pass
# inputs as a parameter, so we store them in self._parsed_data
for key, value in inputs.items():
self._parsed_data[key] = value
quantities_to_parse = DEFAULT_OPTIONS.get('quantities_to_parse')
if self._settings is not None and self._settings.quantity_names_to_parse:
quantities_to_parse = self._settings.quantity_names_to_parse
result = {}
if self._xml is None:
# parsevasp threw an exception, which means vasprun.xml could not be parsed.
for quantity in quantities_to_parse:
if quantity in self._parsable_items:
result[quantity] = None
return result
for quantity in quantities_to_parse:
if quantity in self._parsable_items:
result[quantity] = getattr(self, quantity)
# Now we make sure that if some of the requested quantities sets an error during parsing and
# the xml file is in recover mode, the calculation is simply garbage. Also, exit_code is not always set, or
# its status can be zero.
if self._exit_code is None:
self._exit_code = self._exit_codes.NO_ERROR
if self._exit_code.status:
if (self._xml_truncated and self._exit_code.status == self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.status):
self._exit_code = self._exit_codes.ERROR_RECOVERY_PARSING_OF_XML_FAILED.format(quantities=list(result.keys()))
return result
@property
def version(self):
"""Fetch the VASP version from parsevasp and return it as a string object."""
# fetch version
version = self._xml.get_version()
if version is None:
# version not present
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
return version
@property
def eigenvalues(self):
"""Fetch eigenvalues from parsevasp."""
# fetch eigenvalues
eigenvalues = self._xml.get_eigenvalues()
if eigenvalues is None:
# eigenvalues not present
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
eigen = []
eigen.append(eigenvalues.get('total'))
if eigen[0] is None:
# spin decomposed?
eigen[0] = eigenvalues.get('up')
eigen.append(eigenvalues.get('down'))
if eigen[0] is None:
# safety, should not really happen?
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
return eigen
@property
def occupancies(self):
"""Fetch occupancies from parsevasp."""
# fetch occupancies
occupancies = self._xml.get_occupancies()
if occupancies is None:
# occupancies not present, should not really happen?
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
occ = []
occ.append(occupancies.get('total'))
if occ[0] is None:
# spin decomposed
occ[0] = occupancies.get('up')
occ.append(occupancies.get('down'))
if occ[0] is None:
# should not really happen
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
return occ
@property
def kpoints(self):
"""Fetch the kpoints from parsevasp an store in KpointsData."""
kpts = self._xml.get_kpoints()
kptsw = self._xml.get_kpointsw()
kpoints_data = None
if (kpts is not None) and (kptsw is not None):
# create a KpointsData object and store k-points
kpoints_data = {}
kpoints_data['mode'] = 'explicit'
kpoints_data['points'] = []
for kpt, kptw in zip(kpts, kptsw):
kpoints_data['points'].append(Kpoint(kpt, weight=kptw))
return kpoints_data
@property
def structure(self):
"""
Fetch a given structure.
Which structure to fetch is controlled by inputs.
eFL: Need to clean this so that we can set different
structures to pull from the outside. Could be usefull not
pulling the whole trajectory.
Currently defaults to the last structure.
"""
return self.last_structure
@property
def last_structure(self):
"""
Fetch the structure.
After or at the last recorded ionic step from parsevasp.
"""
last_lattice = self._xml.get_lattice('last')
if last_lattice is None:
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
return _build_structure(last_lattice)
@property
def final_structure(self):
"""
Fetch the structure.
After or at the last recorded ionic step from parsevasp. Should in
principle be the same as the method above.
"""
return self.last_structure
@property
def last_forces(self):
"""
Fetch forces.
After or at the last recorded ionic step from parsevasp.
"""
force = self._xml.get_forces('last')
return force
@property
def final_forces(self):
"""
Fetch forces.
After or at the last recorded ionic step from parsevasp.
"""
return self.last_forces
@property
def forces(self):
"""
Fetch forces.
This container should contain all relevant forces.
Currently, it only contains the final forces, which can be obtain
by the id `final_forces`.
"""
final_forces = self.final_forces
forces = {'final': final_forces}
return forces
@property
def maximum_force(self):
"""Fetch the maximum force of at the last ionic run."""
forces = self.final_forces
if forces is None:
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
norm = np.linalg.norm(forces, axis=1)
return np.amax(np.abs(norm))
@property
def last_stress(self):
"""
Fetch stess.
After or at the last recorded ionic step from parsevasp.
"""
stress = self._xml.get_stress('last')
return stress
@property
def final_stress(self):
"""
Fetch stress.
After or at the last recorded ionic step from parsevasp.
"""
return self.last_stress
@property
def stress(self):
"""
Fetch stress.
This container should contain all relevant stress.
Currently, it only contains the final stress, which can be obtain
by the id `final_stress`.
"""
final_stress = self.final_stress
stress = {'final': final_stress}
return stress
@property
def maximum_stress(self):
"""Fetch the maximum stress of at the last ionic run."""
stress = self.final_stress
if stress is None:
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
norm = np.linalg.norm(stress, axis=1)
return np.amax(np.abs(norm))
@property
def trajectory(self):
"""
Fetch unitcells, positions, species, forces and stress.
For all calculation steps from parsevasp.
"""
unitcell = self._xml.get_unitcell('all')
positions = self._xml.get_positions('all')
species = self._xml.get_species()
forces = self._xml.get_forces('all')
stress = self._xml.get_stress('all')
# make sure all are sorted, first to last calculation
# (species is constant)
unitcell = sorted(unitcell.items())
positions = sorted(positions.items())
forces = sorted(forces.items())
stress = sorted(stress.items())
# convert to numpy
unitcell = np.asarray([item[1] for item in unitcell])
positions = np.asarray([item[1] for item in positions])
forces = np.asarray([item[1] for item in forces])
stress = np.asarray([item[1] for item in stress])
# Aiida wants the species as symbols, so invert
elements = _invert_dict(parsevaspct.elements)
symbols = np.asarray([elements[item].title() for item in species.tolist()])
if (unitcell is not None) and (positions is not None) and \
(species is not None) and (forces is not None) and \
(stress is not None):
trajectory_data = {}
keys = ('cells', 'positions', 'symbols', 'forces', 'stress', 'steps')
stepids = np.arange(unitcell.shape[0])
for key, data in zip(keys, (unitcell, positions, symbols, forces, stress, stepids)):
trajectory_data[key] = data
return trajectory_data
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
@property
def total_energies(self):
"""Fetch the total energies after the last ionic run."""
energies = self.energies
if energies is None:
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
energies_dict = {}
for etype in self._settings.get('energy_type', DEFAULT_OPTIONS['energy_type']):
energies_dict[etype] = energies[etype][-1]
# Also return the raw electronic steps energy
energies_dict[etype + '_electronic'] = energies[etype + '_electronic'][-1]
return energies_dict
@property
def energies(self):
"""Fetch the total energies."""
# Check if we want total energy entries for each electronic step.
electronic_step_energies = self._settings.get('electronic_step_energies', DEFAULT_OPTIONS['electronic_step_energies'])
return self._energies(nosc=not electronic_step_energies)
def _energies(self, nosc):
"""
Fetch the total energies for all energy types, calculations (ionic steps) and electronic steps.
The returned dict from the parser contains the total energy types as a key (plus the _final, which is
the final total energy ejected by VASP after the closure of the electronic steps). The energies can then
be found in the flattened ndarray where the key `electronic_steps` indicate how many electronic steps
there is per ionic step. Using the combination, one can rebuild the electronic step energy per ionic step etc.
Because the VASPrun parser returns both the electronic step energies (at the end of each cycles) and the ionic step
energies (_final), we apply a mapping to recovery the naming such that the ionic step energies do not have the suffix,
but the electronic step energies do.
"""
etype = self._settings.get('energy_type', DEFAULT_OPTIONS['energy_type'])
# Create a copy
etype = list(etype)
etype_orig = list(etype)
# Apply mapping and request the correct energies from the parsing results
# VASP 5 has a bug where the energy_no_entropy is not included in the XML output - we have to calculate it here
if self.version.startswith('5'):
# For energy_no_entropy needs to be calculated here
if 'energy_no_entropy' in etype_orig:
etype.append('energy_free')
etype.append('energy_extrapolated')
# energy extrapolated is stored as energy_no_entropy for the ionic steps
if 'energy_extrapolated' in etype_orig:
etype.append('energy_no_entropy')
# Remove duplicates
etype = list(set(etype))
energies = self._xml.get_energies(status='all', etype=etype, nosc=nosc)
# Here we must calculate the true `energy_no_entropy`
if 'energy_no_entropy' in etype_orig:
# The energy_extrapolated_final is the entropy term itself in VASP 5
# Store the calculated energy_no_entropy under 'energy_extrapolated_final',
# which is then recovered as `energy_no_entropy` later
energies['energy_extrapolated_final'] = energies['energy_free_final'] - energies['energy_extrapolated_final']
else:
energies = self._xml.get_energies(status='all', etype=etype, nosc=nosc)
if energies is None:
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=str(sys._getframe().f_code.co_name))
return None
# Apply mapping - those with `_final` has the suffix removed and those without has `_electronic` added
mapped_energies = {}
mapping = ENERGY_MAPPING_VASP5 if self.version.startswith('5') else ENERGY_MAPPING
# Reverse the mapping - now key is the name of the original energies output
revmapping = {value: key for key, value in mapping.items()}
for key, value in energies.items():
# Apply mapping if needed
if key in revmapping:
if revmapping[key].replace('_electronic', '') in etype_orig:
mapped_energies[revmapping[key]] = value
else:
mapped_energies[key] = value
return mapped_energies
@property
def projectors(self):
"""Fetch the projectors."""
proj = self._xml.get_projectors()
if proj is None:
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
projectors = {}
prj = []
try:
prj.append(proj['total']) # pylint: disable=unsubscriptable-object
except KeyError:
try:
prj.append(proj['up']) # pylint: disable=unsubscriptable-object
prj.append(proj['down']) # pylint: disable=unsubscriptable-object
except KeyError:
self._logger.error('Did not detect any projectors. Returning.')
if len(prj) == 1:
projectors['projectors'] = prj[0]
else:
projectors['projectors'] = np.asarray(prj)
return projectors
@property
def dielectrics(self):
"""Fetch the dielectric function."""
diel = self._xml.get_dielectrics()
if diel is None:
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
dielectrics = {}
energy = diel.get('energy')
idiel = diel.get('imag')
rdiel = diel.get('real')
epsilon = diel.get('epsilon')
epsilon_ion = diel.get('epsilon_ion')
if energy is not None:
dielectrics['ediel'] = energy
if idiel is not None:
dielectrics['rdiel'] = rdiel
if rdiel is not None:
dielectrics['idiel'] = idiel
if epsilon is not None:
dielectrics['epsilon'] = epsilon
if epsilon_ion is not None:
dielectrics['epsilon_ion'] = epsilon_ion
return dielectrics
@property
def born_charges(self):
"""Fetch the Born effective charges."""
brn = self._xml.get_born()
if brn is None:
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
born = {'born_charges': brn}
return born
@property
def hessian(self):
"""Fetch the Hessian matrix."""
hessian = self._xml.get_hessian()
if hessian is None:
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
hess = {'hessian': hessian}
return hess
@property
def dynmat(self):
"""Fetch the dynamical eigenvectors and eigenvalues."""
dynmat = self._xml.get_dynmat()
if dynmat is None:
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
dyn = {}
dyn['dynvec'] = dynmat['eigenvectors'] # pylint: disable=unsubscriptable-object
dyn['dyneig'] = dynmat['eigenvalues'] # pylint: disable=unsubscriptable-object
return dyn
@property
def dos(self):
"""Fetch the total density of states."""
dos = self._xml.get_dos()
if dos is None:
self._exit_code = self._exit_codes.ERROR_NOT_ABLE_TO_PARSE_QUANTITY.format(quantity=sys._getframe().f_code.co_name)
return None
densta = {}
# energy is always there, regardless of
# total, spin or partial
energy = dos['total']['energy'] # pylint: disable=unsubscriptable-object
densta['energy'] = energy
tdos = None
pdos = None
upspin = dos.get('up')
downspin = dos.get('down')
total = dos.get('total')
if (upspin is not None) and (downspin is not None):
tdos = np.stack((upspin['total'], downspin['total']))
if (upspin['partial'] is not None) and \
(downspin['partial'] is not None):
pdos = np.stack((upspin['partial'], downspin['partial']))
else:
tdos = total['total']
pdos = total['partial']
densta['tdos'] = tdos
if pdos is not None:
densta['pdos'] = pdos
return densta
@property
def fermi_level(self):
"""Fetch Fermi level."""
return self._xml.get_fermi_level()
@property
def band_properties(self):
"""Fetch miscellaneous electronic structure data"""
eigenvalues = self.eigenvalues
occupations = self.occupancies
if eigenvalues is None:
return None
# Convert to np.ndarray
eigenvalues = np.stack(eigenvalues, axis=0)
occupations = np.stack(occupations, axis=0)
return get_band_properties(eigenvalues, occupations)
@property
def run_status(self):
"""Fetch run_status information"""
info = {}
# First check electronic convergence by comparing executed steps to the
# maximum allowed number of steps (NELM).
energies = self._xml.get_energies('last', nosc=False)
parameters = self._xml.get_parameters()
info['finished'] = not self._xml_truncated
# Only set to true for untruncated run to avoid false positives
if energies is None:
info['electronic_converged'] = False
elif energies.get('electronic_steps')[0] < parameters['nelm'] and not self._xml_truncated:
info['electronic_converged'] = True
else:
info['electronic_converged'] = False
# Then check the ionic convergence by comparing executed steps to the
# maximum allowed number of steps (NSW).
energies = self._xml.get_energies('all', nosc=True)
if energies is None:
info['ionic_converged'] = False
else:
if len(energies.get('electronic_steps')) < parameters['nsw'] and not self._xml_truncated:
info['ionic_converged'] = True
else:
info['ionic_converged'] = False
# Override if nsw is 0 - no ionic steps are performed
if parameters['nsw'] < 1:
info['ionic_converged'] = None
return info
def _build_structure(lattice):
"""Builds a structure according to AiiDA spec."""
structure_dict = {}
structure_dict['unitcell'] = lattice['unitcell']
structure_dict['sites'] = []
# AiiDA wants the species as symbols, so invert
elements = _invert_dict(parsevaspct.elements)
for pos, specie in zip(lattice['positions'], lattice['species']):
site = {}
site['position'] = np.dot(pos, lattice['unitcell'])
site['symbol'] = elements[specie].title()
site['kind_name'] = elements[specie].title()
structure_dict['sites'].append(site)
return structure_dict
def _invert_dict(dct):
return dct.__class__(map(reversed, dct.items()))