Skip to content

Commit

Permalink
Add @calcfunction to connect data nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Jun 16, 2021
1 parent 6fe5775 commit 4551d11
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 18 deletions.
27 changes: 22 additions & 5 deletions aiida_phonopy/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,30 @@
BandsData = DataFactory('array.bands')


@calcfunction
def select_calculator_settings(calculator_settings, calc_type):
"""Select calculator settings from string."""
return Dict(dict=calculator_settings[calc_type.value])


@calcfunction
def get_remote_fc_calculation_settings(phonon_settings):
"""Create remote force constants phonopy calculation setting."""
ph_settings = _get_setting_info(phonon_settings)
params = _get_phonopy_postprocess_info(phonon_settings)
ph_settings['postprocess_parameters'] = params
return Dict(dict=ph_settings)
"""Create remote force constants phonopy calculation setting.
keys condidered:
supercell_matrix
fc_calculator
"""
key = 'supercell_matrix'
if key in phonon_settings.dict:
fc_settings = {key: phonon_settings[key]}
else:
return None
key = 'fc_calculator'
if key in phonon_settings.dict:
fc_settings['postprocess_parameters'] = {key: phonon_settings[key]}
return Dict(dict=fc_settings)


@calcfunction
Expand Down
26 changes: 13 additions & 13 deletions aiida_phonopy/workflows/phonopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@
from aiida.orm import Code
from aiida_phonopy.common.utils import (
get_force_constants, get_phonon_properties,
setup_phonopy_calculation,
setup_phonopy_calculation, select_calculator_settings,
from_node_id_to_aiida_node_id, get_data_from_node_id,
get_force_sets, collect_forces_and_energies)
from aiida_phonopy.workflows.nac_params import NacParamsWorkChain
from aiida_phonopy.workflows.forces import ForcesWorkChain


# Should be improved by some kind of WorkChainFactory
# For now all workchains should be copied to aiida/workflows

Float = DataFactory('float')
Bool = DataFactory('bool')
Str = DataFactory('str')
Expand Down Expand Up @@ -274,8 +270,9 @@ def _run_force_calculations(self):
builder = ForcesWorkChain.get_builder()
builder.metadata.label = label
builder.structure = supercell
calculator_settings = self.inputs.calculator_settings['forces']
builder.calculator_settings = Dict(dict=calculator_settings)
calculator_settings = select_calculator_settings(
self.inputs.calculator_settings, Str('forces'))
builder.calculator_settings = calculator_settings
future = self.submit(builder)
self.report('{} pk = {}'.format(label, future.pk))
self.to_context(**{label: future})
Expand All @@ -287,8 +284,9 @@ def _run_nac_params_calculation(self):
builder = NacParamsWorkChain.get_builder()
builder.metadata.label = 'nac_params'
builder.structure = self.ctx.primitive
calculator_settings = self.inputs.calculator_settings['nac']
builder.calculator_settings = Dict(dict=calculator_settings)
calculator_settings = select_calculator_settings(
self.inputs.calculator_settings, Str('nac'))
builder.calculator_settings = calculator_settings
future = self.submit(builder)
self.report('nac_params: {}'.format(future.pk))
self.to_context(**{'nac_params_calc': future})
Expand All @@ -314,8 +312,9 @@ def read_force_calculations_from_files(self):
builder = ForcesWorkChain.get_builder()
builder.metadata.label = label
builder.structure = supercell
calculator_settings = self.inputs.calculator_settings['forces']
builder.calculator_settings = Dict(dict=calculator_settings)
calculator_settings = select_calculator_settings(
self.inputs.calculator_settings, Str('forces'))
builder.calculator_settings = calculator_settings
builder.immigrant_calculation_folder = Str(force_folder)
future = self.submit(builder)
self.report('{} pk = {}'.format(label, future.pk))
Expand All @@ -336,8 +335,9 @@ def read_nac_calculations_from_files(self):
builder = NacParamsWorkChain.get_builder()
builder.metadata.label = label
builder.structure = self.ctx.primitive
calculator_settings = self.inputs.calculator_settings['nac']
builder.calculator_settings = Dict(dict=calculator_settings)
calculator_settings = select_calculator_settings(
self.inputs.calculator_settings, Str('nac'))
builder.calculator_settings = calculator_settings
builder.immigrant_calculation_folder = Str(nac_folder)
future = self.submit(builder)
self.report('{} pk = {}'.format(label, future.pk))
Expand Down

0 comments on commit 4551d11

Please sign in to comment.