Skip to content

Commit

Permalink
postprocess_parameters was moved to phonon_setting_info
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Jun 1, 2021
1 parent dd65449 commit ccb6e86
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 57 deletions.
2 changes: 0 additions & 2 deletions aiida_phonopy/calcs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ def define(cls, spec):
help='Phonopy parameters')
spec.input('structure', valid_type=StructureData,
help='Unit cell structure')
spec.input('postprocess_parameters', valid_type=Dict,
help='Parameters to run phonopy')
spec.input('symmetry_tolerance', valid_type=Float,
default=lambda: Float(1e-5))
spec.input('fc_only', valid_type=Bool,
Expand Down
2 changes: 1 addition & 1 deletion aiida_phonopy/calcs/phonopy.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _create_additional_files(self, folder):
self._create_phonopy_yaml(folder)
self._create_FORCE_SETS(folder)
mesh_opts, fc_opts = get_phonopy_options(
self.inputs.postprocess_parameters)
self.inputs.settings['postprocess_parameters'])

self._internal_retrieve_list = [self._INOUT_FORCE_CONSTANTS, ]
self._additional_cmd_params = [['--writefc', ] + fc_opts, ]
Expand Down
4 changes: 2 additions & 2 deletions aiida_phonopy/common/file_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def get_phonopy_yaml_txt(structure,
def get_phonopy_options(postprocess_parameters):
"""Return phonopy command option strings."""
mesh_opts = []
if 'mesh' in postprocess_parameters.keys():
if 'mesh' in postprocess_parameters:
mesh = postprocess_parameters['mesh']
try:
length = float(mesh)
Expand All @@ -80,7 +80,7 @@ def get_phonopy_options(postprocess_parameters):
mesh_opts.append('--nowritemesh')

fc_opts = []
if 'fc_calculator' in postprocess_parameters.keys():
if 'fc_calculator' in postprocess_parameters:
if postprocess_parameters['fc_calculator'].lower().strip() == 'alm':
fc_opts.append('--alm')
return mesh_opts, fc_opts
Expand Down
45 changes: 35 additions & 10 deletions aiida_phonopy/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@


@calcfunction
def generate_phonopy_cells(phonon_settings,
structure,
symmetry_tolerance,
dataset=None):
"""Generate supercells and primitive cell.
def setup_phonopy_calculation(phonon_settings,
structure,
symmetry_tolerance,
run_phonopy,
dataset=None):
"""Set up phonopy calculation.
Valid keys in phonon_settings_info are
('supercell_matrix',
Expand All @@ -33,7 +34,9 @@ def generate_phonopy_cells(phonon_settings,
'random_seed',
'is_plusminus',
'is_diagonal',
'is_trigonal').
'is_trigonal',
'mesh',
'fc_calculator').
Returns
-------
Expand Down Expand Up @@ -77,9 +80,18 @@ def generate_phonopy_cells(phonon_settings,
'is_plusminus' : bool
'is_diagonal' : bool
'is_trigonal' : bool
'postprocess_parameters' : dict
This is given when run_phonopy=True.
'mesh' : float or list
Mesh numbers or distance measure of q-point sampling mesh.
'fc_calculator' : str
External force constants calculator.
"""
ph_settings = _get_setting_info(phonon_settings)
if run_phonopy:
params = _get_phonopy_postprocess_info(phonon_settings)
ph_settings['postprocess_parameters'] = params

ph = _get_phonopy_instance(structure,
ph_settings,
Expand All @@ -102,6 +114,19 @@ def generate_phonopy_cells(phonon_settings,
return return_vals


def _get_phonopy_postprocess_info(phonon_settings):
"""Return phonopy postprocess parameters."""
valid_keys = ('mesh', 'fc_calculator')
params = {}
for key in valid_keys:
if key in phonon_settings.keys():
params[key] = phonon_settings[key]

if 'mesh' not in phonon_settings.keys():
params['mesh'] = 100.0
return params


@calcfunction
def generate_phono3py_cells(phonon_settings,
structure,
Expand All @@ -127,7 +152,6 @@ def generate_phono3py_cells(phonon_settings,
@calcfunction
def get_force_constants(structure,
phonon_settings,
postprocess_parameters,
force_sets,
symmetry_tolerance):
"""Calculate force constants."""
Expand All @@ -136,7 +160,9 @@ def get_force_constants(structure,
symmetry_tolerance=symmetry_tolerance.value)
phonon.dataset = phonon_settings['displacement_dataset']
phonon.forces = force_sets.get_array('force_sets')
if 'fc_calculator' in postprocess_parameters.keys():

if 'fc_calculator' in phonon_settings['postprocess_parameters']:
postprocess_parameters = phonon_settings['postprocess_parameters']
if postprocess_parameters['fc_calculator'].lower().strip() == 'alm':
phonon.produce_force_constants(fc_calculator='alm')
else:
Expand All @@ -153,7 +179,6 @@ def get_force_constants(structure,
def get_phonon_properties(structure,
phonon_settings,
force_constants,
qpoint_mesh,
symmetry_tolerance,
nac_params=None):
"""Calculate phonon properties."""
Expand All @@ -163,7 +188,7 @@ def get_phonon_properties(structure,
symmetry_tolerance=symmetry_tolerance.value,
nac_params=nac_params)
ph.force_constants = force_constants.get_array('force_constants')
mesh = qpoint_mesh['mesh']
mesh = phonon_settings['postprocess_parameters']['mesh']

# Mesh
total_dos, pdos, thermal_properties = get_mesh_property_data(ph, mesh)
Expand Down
61 changes: 19 additions & 42 deletions aiida_phonopy/workflows/phonopy.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""WorkChan to run phonon calculation by phonopy and force calculators."""

from aiida.engine import WorkChain, calcfunction
from aiida.engine import WorkChain
from aiida.plugins import DataFactory, CalculationFactory
from aiida.orm import Code
from aiida.engine import if_, while_
from aiida_phonopy.common.builders import get_immigrant_builder
from aiida_phonopy.common.utils import (
get_force_constants, get_phonon_properties,
generate_phonopy_cells, compare_structures,
compare_structures, setup_phonopy_calculation,
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
Expand All @@ -28,20 +28,6 @@
PhonopyCalculation = CalculationFactory('phonopy.phonopy')


@calcfunction
def get_postprocess_parameters(phonon_settings):
"""Return phonopy postprocess parameters."""
valid_keys = ('mesh', 'fc_calculator')
params = {}
for key in valid_keys:
if key in phonon_settings.keys():
params[key] = phonon_settings[key]

if 'mesh' not in phonon_settings.keys():
params['mesh'] = 100.0
return Dict(dict=params)


class PhonopyWorkChain(WorkChain):
"""Phonopy workchain.
Expand Down Expand Up @@ -124,10 +110,7 @@ def define(cls, spec):
spec.input('code_string', valid_type=Str, required=False)

spec.outline(
cls.initialize_structures,
if_(cls.run_phonopy)(
cls.initialize_postprocess_settings,
),
cls.initialize,
if_(cls.import_calculations)(
if_(cls.import_calculations_from_files)(
while_(cls.continue_import)(
Expand Down Expand Up @@ -172,8 +155,14 @@ def define(cls, spec):
spec.output('band_structure', valid_type=BandsData, required=False)
spec.output('dos', valid_type=XyData, required=False)
spec.output('pdos', valid_type=XyData, required=False)
spec.output('postprocess_parameters', valid_type=Dict, required=False)
spec.output('phonon_setting_info', valid_type=Dict)
spec.exit_code(
1001, 'ERROR_NO_PHONOPY_CODE',
message=("Phonopy Code not found though expected to run phonopy "
"remotely."))
spec.exit_code(
1002, 'ERROR_NO_SUPERCELL_MATRIX',
message=("supercell_matrix was not found."))

def dry_run(self):
"""Return boolen for outline."""
Expand Down Expand Up @@ -217,25 +206,25 @@ def continue_import(self):
"""Return boolen for outline."""
return self.ctx.num_imported < self.ctx.num_supercell_forces

def initialize_structures(self):
def initialize(self):
"""Set default settings and create supercells and primitive cell."""
self.report('initialize_structures')
self.report('initialization')

if self.inputs.run_phonopy and self.inputs.remote_phonopy:
if 'code_string' not in self.inputs:
raise RuntimeError("code_string has to be specified.")
return self.exit_codes.ERROR_NO_PHONOPY_CODE

if 'supercell_matrix' not in self.inputs.phonon_settings.keys():
raise RuntimeError(
"supercell_matrix was not found in phonon_settings.")
return self.exit_codes.ERROR_NO_SUPERCELL_MATRIX

kwargs = {}
if 'displacement_dataset' in self.inputs:
kwargs['dataset'] = self.inputs.displacement_dataset
return_vals = generate_phonopy_cells(self.inputs.phonon_settings,
self.inputs.structure,
self.inputs.symmetry_tolerance,
**kwargs)
return_vals = setup_phonopy_calculation(self.inputs.phonon_settings,
self.inputs.structure,
self.inputs.symmetry_tolerance,
self.inputs.run_phonopy,
**kwargs)

for key in ('phonon_setting_info', 'primitive', 'supercell'):
self.ctx[key] = return_vals[key]
Expand All @@ -249,13 +238,6 @@ def initialize_structures(self):
label = "supercell_%s" % "0".zfill(digits)
self.ctx.supercells[label] = return_vals['supercell']

def initialize_postprocess_settings(self):
"""Set default settings and create supercells and primitive cell."""
self.report('initialize_postprocess_settings')

params = get_postprocess_parameters(self.inputs.phonon_settings)
self.ctx.postprocess_parameters = params

def run_force_and_nac_calculations(self):
"""Run supercell force and NAC params calculations.
Expand Down Expand Up @@ -404,7 +386,6 @@ def run_phonopy_remote(self):
builder.structure = self.inputs.structure
builder.settings = self.ctx.phonon_setting_info
builder.symmetry_tolerance = self.inputs.symmetry_tolerance
builder.postprocess_parameters = self.ctx.postprocess_parameters
builder.metadata.label = self.inputs.metadata.label
builder.metadata.options.update(self.inputs.phonon_settings['options'])
builder.force_sets = self.ctx.force_sets
Expand All @@ -429,7 +410,6 @@ def collect_data(self):
for prop in ph_props:
if prop in self.ctx.phonon_properties.outputs:
self.out(prop, self.ctx.phonon_properties.outputs[prop])
self.out('postprocess_parameters', self.ctx.postprocess_parameters)

self.report('finish phonon')

Expand All @@ -440,7 +420,6 @@ def create_force_constants(self):
self.ctx.force_constants = get_force_constants(
self.inputs.structure,
self.ctx.phonon_setting_info,
self.ctx.postprocess_parameters,
self.ctx.force_sets,
self.inputs.symmetry_tolerance)
self.out('force_constants', self.ctx.force_constants)
Expand All @@ -455,13 +434,11 @@ def run_phonopy_locally(self):
result = get_phonon_properties(self.inputs.structure,
self.ctx.phonon_setting_info,
self.ctx.force_constants,
self.ctx.postprocess_parameters,
self.inputs.symmetry_tolerance,
**params)
self.out('thermal_properties', result['thermal_properties'])
self.out('dos', result['dos'])
self.out('band_structure', result['band_structure'])
self.out('postprocess_parameters', self.ctx.postprocess_parameters)

self.report('finish phonon')

Expand Down

0 comments on commit ccb6e86

Please sign in to comment.