Source code for ase2sprkkr.asr.test.test_core_results

from typing import Dict
from asr.core import (ASRResult, prepare_result, WebPanelEncoder, command,
                      dct_to_object)
import pytest


[docs] class MyWebPanel(WebPanelEncoder): """WebPanel for testing.""" pass
webpanel = WebPanelEncoder()
[docs] @prepare_result class MyResultVer0(ASRResult): """Generic results.""" a: int b: int version: int = 0 key_descriptions: Dict[str, str] = {'a': 'A description of "a".', 'b': 'A description of "b".'}
[docs] @prepare_result class MyResult(ASRResult): """Generic results.""" a: int prev_version = MyResultVer0 version: int = 1 key_descriptions: Dict[str, str] = {'a': 'A description of "a".'} formats = {'ase_webpanel': webpanel}
@command('test_core_results', returns=MyResult) def recipe() -> MyResult: return MyResult.fromdata(a=2)
[docs] @pytest.mark.ci def test_results_object(capsys): results = MyResult.fromdata(a=1) results.metadata = {'resources': {'time': 'right now'}} assert results.a == 1 assert 'a' in results assert results.__doc__ == '\n'.join(['Generic results.']) formats = results.get_formats() assert formats['ase_webpanel'] == webpanel assert set(formats) == set(['json', 'html', 'dict', 'ase_webpanel', 'str']) print(results) captured = capsys.readouterr() assert captured.out == 'a=1\n' assert isinstance(results.format_as('ase_webpanel', {}, {}), list) html = results.format_as('html') html2 = format(results, 'html') assert html == html2 assert f'{results:html}' == html json = format(results, 'json') newresults = MyResult.from_format(json, format='json') assert newresults == results otherresults = MyResult.fromdata(a=2) assert not otherresults == results
[docs] @pytest.mark.ci def test_reading_result(): result = recipe() jsonresult = result.format_as('json') new_result = recipe.returns.from_format(jsonresult, format='json') assert result == new_result
[docs] @pytest.mark.ci def test_reading_older_version(): result_0 = MyResultVer0.fromdata(a=1, b=2) jsonresult = result_0.format_as('json') result_1 = MyResultVer0.from_format(jsonresult, 'json') assert result_0 == result_1
[docs] @pytest.mark.ci def test_read_old_format(): """Test that reading an old gs results file works.""" from asr.gs import webpanel, Result dct = { "forces": None, "stresses": None, "etot": -22.121104868435815, "gaps_nosoc": { "gap": 1.6479279143592194, "vbm": -1.4188700643247436, "cbm": 0.22905785003447576, "gap_dir": 1.6613864123506252, "vbm_dir": -1.4323285623161495, "cbm_dir": 0.22905785003447576, "k_vbm_c": { "__ndarray__": [ [ 3 ], "float64", [ 3.469446951953614e-18, 3.469446951953614e-18, 0.0 ] ] }, "k_cbm_c": { "__ndarray__": [ [ 3 ], "float64", [ 0.3333333333333333, 0.3333333333333333, 0.0 ] ] }, "k_vbm_dir_c": { "__ndarray__": [ [ 3 ], "float64", [ 0.3333333333333333, 0.3333333333333333, 0.0 ] ] }, "k_cbm_dir_c": { "__ndarray__": [ [ 3 ], "float64", [ 0.3333333333333333, 0.3333333333333333, 0.0 ] ] }, "skn1": [ 0, 0, 12 ], "skn2": [ 0, 36, 13 ], "skn1_dir": [ 0, 36, 12 ], "skn2_dir": [ 0, 36, 13 ], "efermi": -0.5619081841937554 }, "gap_dir_nosoc": 1.6613864123506252, "gap_nosoc": 1.6479279143592194, "gap": 1.580389439677671, "vbm": -1.3569146124166724, "cbm": 0.22347482726099846, "gap_dir": 1.5803894396776728, "vbm_dir": -1.3569146124166742, "cbm_dir": 0.22347482726099846, "k_vbm_c": { "__ndarray__": [ [ 3 ], "float64", [ 0.6666666666666667, -0.3333333333333333, 0.0 ] ] }, "k_cbm_c": { "__ndarray__": [ [ 3 ], "float64", [ 0.3333333333333333, 0.3333333333333333, 0.0 ] ] }, "k_vbm_dir_c": { "__ndarray__": [ [ 3 ], "float64", [ 0.3333333333333333, 0.3333333333333333, 0.0 ] ] }, "k_cbm_dir_c": { "__ndarray__": [ [ 3 ], "float64", [ 0.3333333333333333, 0.3333333333333333, 0.0 ] ] }, "skn1": [ 0, 124, 25 ], "skn2": [ 0, 744, 26 ], "skn1_dir": [ 0, 744, 25 ], "skn2_dir": [ 0, 744, 26 ], "efermi": -0.566719892577837, "vacuumlevels": { "z_z": { "__ndarray__": [ [ 240 ], "float64", [ 0.0, 0.07552963602646466, 0.15105927205292932, 0.22658890807939397, 0.30211854410585864, 0.3776481801323233, 0.45317781615878794, 0.5287074521852526, 0.6042370882117173, 0.679766724238182, 0.7552963602646466, 0.8308259962911113, 0.9063556323175759, 0.9818852683440406, 1.0574149043705052, 1.13294454039697, 1.2084741764234346, 1.2840038124498991, 1.359533448476364, 1.4350630845028285, 1.5105927205292933, 1.5861223565557578, 1.6616519925822226, 1.7371816286086872, 1.8127112646351518, 1.8882409006616165, 1.963770536688081, 2.0393001727145457, 2.1148298087410105, 2.1903594447674752, 2.26588908079394, 2.3414187168204044, 2.416948352846869, 2.492477988873334, 2.5680076248997983, 2.643537260926263, 2.719066896952728, 2.7945965329791926, 2.870126169005657, 2.9456558050321218, 3.0211854410585866, 3.096715077085051, 3.1722447131115157, 3.2477743491379805, 3.3233039851644453, 3.3988336211909096, 3.4743632572173744, 3.549892893243839, 3.6254225292703035, 3.7009521652967683, 3.776481801323233, 3.852011437349698, 3.927541073376162, 4.003070709402627, 4.078600345429091, 4.154129981455556, 4.229659617482021, 4.305189253508486, 4.3807188895349505, 4.456248525561415, 4.53177816158788, 4.607307797614344, 4.682837433640809, 4.7583670696672735, 4.833896705693738, 4.909426341720203, 4.984955977746668, 5.060485613773133, 5.136015249799597, 5.211544885826061, 5.287074521852526, 5.362604157878991, 5.438133793905456, 5.5136634299319205, 5.589193065958385, 5.664722701984849, 5.740252338011314, 5.815781974037779, 5.8913116100642435, 5.966841246090708, 6.042370882117173, 6.117900518143638, 6.193430154170102, 6.268959790196567, 6.344489426223031, 6.420019062249496, 6.495548698275961, 6.571078334302426, 6.6466079703288905, 6.722137606355354, 6.797667242381819, 6.873196878408284, 6.948726514434749, 7.0242561504612135, 7.099785786487678, 7.175315422514143, 7.250845058540607, 7.326374694567072, 7.401904330593537, 7.477433966620001, 7.552963602646466, 7.628493238672931, 7.704022874699396, 7.7795525107258605, 7.855082146752324, 7.930611782778789, 8.006141418805255, 8.081671054831718, 8.157200690858183, 8.232730326884647, 8.308259962911112, 8.383789598937577, 8.459319234964042, 8.534848870990507, 8.610378507016971, 8.685908143043436, 8.761437779069901, 8.836967415096366, 8.91249705112283, 8.988026687149295, 9.06355632317576, 9.139085959202223, 9.214615595228688, 9.290145231255153, 9.365674867281617, 9.441204503308082, 9.516734139334547, 9.592263775361012, 9.667793411387477, 9.743323047413941, 9.818852683440406, 9.894382319466871, 9.969911955493336, 10.0454415915198, 10.120971227546265, 10.19650086357273, 10.272030499599193, 10.347560135625658, 10.423089771652123, 10.498619407678587, 10.574149043705052, 10.649678679731517, 10.725208315757982, 10.800737951784447, 10.876267587810911, 10.951797223837376, 11.027326859863841, 11.102856495890306, 11.17838613191677, 11.253915767943235, 11.329445403969698, 11.404975039996163, 11.480504676022628, 11.556034312049093, 11.631563948075557, 11.707093584102022, 11.782623220128487, 11.858152856154952, 11.933682492181417, 12.009212128207881, 12.084741764234346, 12.160271400260811, 12.235801036287276, 12.31133067231374, 12.386860308340204, 12.462389944366668, 12.537919580393133, 12.613449216419598, 12.688978852446063, 12.764508488472528, 12.840038124498992, 12.915567760525457, 12.991097396551922, 13.066627032578387, 13.142156668604851, 13.217686304631316, 13.293215940657781, 13.368745576684246, 13.444275212710709, 13.519804848737174, 13.595334484763638, 13.670864120790103, 13.746393756816568, 13.821923392843033, 13.897453028869498, 13.972982664895962, 14.048512300922427, 14.124041936948892, 14.199571572975357, 14.275101209001821, 14.350630845028286, 14.426160481054751, 14.501690117081214, 14.577219753107679, 14.652749389134144, 14.728279025160608, 14.803808661187073, 14.879338297213538, 14.954867933240003, 15.030397569266468, 15.105927205292932, 15.181456841319397, 15.256986477345862, 15.332516113372327, 15.408045749398791, 15.483575385425256, 15.559105021451721, 15.634634657478184, 15.710164293504649, 15.785693929531114, 15.861223565557578, 15.936753201584043, 16.01228283761051, 16.087812473636973, 16.163342109663436, 16.238871745689902, 16.314401381716365, 16.389931017742832, 16.465460653769295, 16.54099028979576, 16.616519925822224, 16.69204956184869, 16.767579197875154, 16.84310883390162, 16.918638469928084, 16.99416810595455, 17.069697741981013, 17.14522737800748, 17.220757014033943, 17.296286650060406, 17.371816286086872, 17.447345922113335, 17.522875558139802, 17.598405194166265, 17.67393483019273, 17.749464466219194, 17.82499410224566, 17.900523738272124, 17.97605337429859, 18.051583010325054 ] ] }, "v_z": { "__ndarray__": [ [ 240 ], "float64", [ 4.530735709474784, 4.5307358802267315, 4.5307361183231, 4.5307360342204355, 4.530735724699099, 4.530735624854204, 4.5307358305598875, 4.530735944706786, 4.530735699819084, 4.530735368430079, 4.530735344692873, 4.5307355241194465, 4.530735464732946, 4.530735074573085, 4.530734750924881, 4.530734765365783, 4.5307348283866355, 4.5307345391121885, 4.530734001516101, 4.530733660100281, 4.5307336009335195, 4.530733398586548, 4.530732769809027, 4.5307319950847935, 4.530731471031555, 4.530731062874167, 4.530730279669665, 4.530729003905608, 4.530727627466666, 4.530726392145427, 4.530724930187525, 4.530722750032452, 4.53071989325324, 4.530716739430148, 4.530713247979039, 4.530708797954299, 4.530702901443595, 4.530695643656229, 4.530687161828988, 4.530676924674863, 4.530663927749242, 4.530647494400702, 4.530627379740043, 4.530602975325323, 4.530572753565795, 4.530534785404367, 4.53048743564062, 4.530429039569055, 4.530356910559624, 4.530267014162869, 4.530154632745318, 4.530014676714057, 4.529840819428639, 4.529624333386863, 4.529353885004262, 4.5290159095096465, 4.528594023284084, 4.528067262876483, 4.527408452909879, 4.526583519233766, 4.525550507624682, 4.524256828609622, 4.5226352747849115, 4.520600359706113, 4.518044942761229, 4.514834875927142, 4.510800297906675, 4.505724692332548, 4.499333110959997, 4.491278223740291, 4.4811206396765915, 4.4683015877169865, 4.4521083813300635, 4.431632556546119, 4.40571717045513, 4.37288779133888, 4.331262745295444, 4.278438565989813, 4.211345017019024, 4.12606218254319, 4.017592724822595, 3.879582038080983, 3.7039750988700737, 3.480597807610791, 3.1966615387529527, 2.836212404656853, 2.37956672550332, 1.802788189812487, 1.0772910523194552, 0.16972051049041037, -0.9576420314001248, -2.345568462537219, -4.034862750727566, -6.059372253768478, -8.429731475710401, -11.100404912502217, -13.920140625941517, -16.59144616684862, -18.69328689642614, -19.80669951066067, -19.70122865243803, -18.45825179378976, -16.433230105407358, -14.088098758483273, -11.820268921507086, -9.883770105020353, -8.402139485740058, -7.418453777473216, -6.938555048914434, -6.95473184197257, -7.454305865868995, -8.419377098016524, -9.821040981948446, -11.60978818160518, -13.70423111101949, -15.981731952816489, -18.27575650711197, -20.384657230458668, -22.094136783603503, -23.210878692678424, -23.599395391660693, -23.210878692664778, -22.094136783585775, -20.38465723045397, -18.275756507140777, -15.98173195289673, -13.704231111160958, -11.609788181806705, -9.82104098219933, -8.4193770983017, -7.454305866175578, -6.954731842295565, -6.938555049260225, -7.4184537778602255, -8.40213948619632, -9.88377010557802, -11.82026892219467, -14.088098759318223, -16.433230106392127, -18.45825179491307, -19.701228653679884, -19.806699511997376, -18.69328689783288, -16.59144616830113, -13.920140627418428, -11.100404913987866, -8.429731477195666, -6.059372255248779, -4.034862752199065, -2.345568463993496, -0.9576420328306282, 0.1697205091000158, 1.0772910509856288, 1.8027881885516313, 2.379566724329722, 2.8362124035810656, 3.196661537780759, 3.4805978067427894, 3.7039750981018247, 3.879582037403647, 4.017592724223975, 4.126062182008978, 4.211345016534142, 4.278438565539637, 4.331262744866861, 4.372887790921077, 4.40571717004007, 4.431632556128726, 4.452108380908126, 4.468301587290843, 4.481120639248647, 4.49127822331444, 4.499333110541013, 4.505724691925495, 4.510800297516407, 4.5148348755578915, 4.518044942416332, 4.5206003593878314, 4.522635274494386, 4.524256828346909, 4.52555050738889, 4.52658351902322, 4.527408452722315, 4.528067262709263, 4.528594023134389, 4.529015909374647, 4.52935388488126, 4.529624333273394, 4.529840819322548, 4.530014676613529, 4.530154632648908, 4.530267014069461, 4.530356910468436, 4.530429039479573, 4.5304874355525575, 4.530534785317617, 4.530572753480389, 4.530602975241371, 4.53062737965771, 4.530647494320171, 4.530663927670684, 4.530676924598426, 4.530687161754791, 4.5306956435843535, 4.530702901374068, 4.530708797887119, 4.530713247914168, 4.530716739367523, 4.53071989319279, 4.5307227499741, 4.530724930131185, 4.530726392091025, 4.530727627414133, 4.5307290038548835, 4.530730279620708, 4.530731062826941, 4.53073147098605, 4.530731995041005, 4.530732769766963, 4.530733398546231, 4.53073360089498, 4.530733660063548, 4.5307340014812105, 4.5307345390791705, 4.530734828355519, 4.530734765336592, 4.53073475089764, 4.53073507454781, 4.530735464709645, 4.5307355240981275, 4.530735344673533, 4.530735368412721, 4.530735699803697, 4.530735944693363, 4.530735830548412, 4.53073562484467, 4.530735724691487, 4.530736034214737, 4.530736118319307, 4.530735880224834 ] ] }, "evacdiff": 2.2740295435020684e-10, "dipz": 1.1033907114109559e-11, "evac1": 4.530735699819084, "evac2": 4.530735699803697, "evacmean": 4.530735699811391, "efermi_nosoc": -0.5619081841937554 }, "dipz": 1.1033907114109559e-11, "evac": 4.530735699811391, "evacdiff": 2.2740295435020684e-10, "workfunction": 5.0974555923892275, "__setup_fingerprints__": { "Mo": "296a29d4664fe6c6f68623909fe0870f", "S": "ca434db9faa07220b7a1d8cb6886b7a9" }, "__key_descriptions__": { "forces": "Forces on atoms [eV/Angstrom]", "stresses": "Stress on unit cell [eV/Angstrom^dim]", "etot": "KVP: Total energy (Tot. En.) [eV]", "evac": "KVP: Vacuum level (Vacuum level) [eV]", "evacdiff": "KVP: Vacuum level shift (Vacuum level shift) [eV]", "dipz": "KVP: Out-of-plane dipole [e * Ang]", "efermi": "KVP: Fermi level (Fermi level) [eV]", "gap": "KVP: Band gap (Band gap) [eV]", "vbm": "KVP: Valence band maximum (Val. band max.) [eV]", "cbm": "KVP: Conduction band minimum (Cond. band max.) [eV]", "gap_dir": "KVP: Direct band gap (Dir. band gap) [eV]", "vbm_dir": "KVP: Direct valence band maximum (Dir. val. band max.) [eV]", "cbm_dir": "KVP: Direct conduction band minimum (Dir. cond. band max.) [eV]", "gap_dir_nosoc": "KVP: Direct gap without SOC (Dir. gap wo. soc.) [eV]" }, "__asr_name__": "asr.gs", "__resources__": { "time": 33.32860088348389, "ncores": 1 }, "__creates__": {}, "__requires__": { "gs.gpw": "ec476177fc295c5b8023e32b7ae0e992", "structure.json": "6050f9d2d1b641c56a1057aad824af6a", "results-asr.magnetic_anisotropy.json": "1b701189287782df68b57810614f34b5" }, "__params__": {}, "__versions__": { "asr": "0.3.2-da56322ddd56a8f975c681909e3a98ae1cab23ef", "ase": "3.21.0b1-f60f0eec8e1448feaf94dffe50453fadadbd7208", "gpaw": "20.1.1b1-4fd39e8b1e249bb3984b2a5658a7b7eac4af1248" } } result = dct_to_object(dct) assert result.formats['ase_webpanel'] == webpanel assert isinstance(result, Result) assert result.etot == dct['etot'] assert result.metadata.asr_name == 'asr.gs'