Specifying result objects and webpanelsΒΆ
The asr.core.ASRResult
object is a way for you to document
the what might be contained in the results that you recipe-step returns.
A typical realistic example of a Result object declaration can be seen below
import typing
from asr.core import ASRResult, prepare_result
from asr.database.browser import WebPanel, describe_entry
def webpanel(result, context):
parameter_description = context.parameter_description(
'asr.c2db.gs@calculate')
energy = describe_entry(result.energy, parameter_description)
prop_table = {'type': 'table',
'header': ['Property', 'value'],
'rows': [['energy', energy]]}
return [
WebPanel(title='Title of my webpanel',
columns=[[prop_table], []])
]
@prepare_result
class Result(ASRResult):
"""My ground state results object.
These results are generated using...
"""
energy: float
forces: typing.List[typing.Tuple[float, float, float]]
key_descriptions = dict(
energy='The energy of the material.',
forces='The forces on the atoms of the material.',
)
formats = {'webpanel2': webpanel}
# # Call like this
# myresult = Result.fromdata(energy=1.0, forces=[[1.0, 1.0, 1.0]])
# webpanels = myresult.format_as('ase_webpanel', row=..., key_descriptions=...)
# webpanel = webpanels[0]
There are several points to be made here
The Result class takes some type hints like
energy: float
to indicate the type of the data contained in the object.The class also takes
key_descriptions
which eventually are used in the docstring for the class.The
formats
attribute can be set to include additional formatting functions and in this case we want to include anase_webpanel
. The name is arbitrary but we are using this name in the ASR web application so it is important that you get it correct.The
@prepare_result
decorator sets up the result class by automatically settings the docstring and more.
The webpanel
formatter takes a result
object an
ase.db.AtomsRow
object and a key_descriptions
dictionary.