Skip to content

Commit

Permalink
fc_calculation and qpoints_mesh info were moved to postprocess_parame…
Browse files Browse the repository at this point in the history
…ters.
  • Loading branch information
atztogo committed May 31, 2021
1 parent dd066db commit dd65449
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 30 deletions.
4 changes: 2 additions & 2 deletions aiida_phonopy/calcs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def define(cls, spec):
help='Phonopy parameters')
spec.input('structure', valid_type=StructureData,
help='Unit cell structure')
spec.input('qpoint_mesh', valid_type=Dict,
help='Q-point sampling mesh information')
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
8 changes: 4 additions & 4 deletions 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.settings.get_dict(), self.inputs.qpoint_mesh.get_dict())
self.inputs.postprocess_parameters)

self._internal_retrieve_list = [self._INOUT_FORCE_CONSTANTS, ]
self._additional_cmd_params = [['--writefc', ] + fc_opts, ]
Expand All @@ -90,7 +90,7 @@ def _create_additional_files(self, folder):
def _create_phonopy_yaml(self, folder):
phpy_yaml_txt = get_phonopy_yaml_txt(
self.inputs.structure,
self.inputs.settings.get_dict())
supercell_matrix=self.inputs.settings['supercell_matrix'])
with folder.open(self._INPUT_CELL, 'w', encoding='utf8') as handle:
handle.write(phpy_yaml_txt)

Expand All @@ -99,9 +99,9 @@ def _create_FORCE_SETS(self, folder):
force_sets = self.inputs.force_sets
else:
force_sets = None
if 'displacement_dataset' in self.inputs.settings.attributes:
if 'displacement_dataset' in self.inputs.settings.keys():
dataset = self.inputs.settings['displacement_dataset']
elif 'dataset' in self.inputs.settings.attributes:
elif 'dataset' in self.inputs.settings.keys():
dataset = self.inputs.settings['dataset']
elif ('dataset' in self.inputs and
'displacements' in self.inputs.dataset.get_arraynames()):
Expand Down
13 changes: 6 additions & 7 deletions aiida_phonopy/common/file_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ def get_FORCE_CONSTANTS_txt(force_constants_object):


def get_phonopy_yaml_txt(structure,
settings,
supercell_matrix=None,
primitive_matrix=None,
calculator=None):
unitcell = phonopy_atoms_from_structure(structure)
ph = Phonopy(unitcell,
supercell_matrix=settings['supercell_matrix'],
supercell_matrix=supercell_matrix,
primitive_matrix='auto',
calculator=calculator)
phpy_yaml = PhonopyYaml()
Expand All @@ -68,11 +67,11 @@ def get_phonopy_yaml_txt(structure,
return str(phpy_yaml)


def get_phonopy_options(settings, qpoint_mesh):
def get_phonopy_options(postprocess_parameters):
"""Return phonopy command option strings."""
mesh_opts = []
if 'mesh' in qpoint_mesh:
mesh = qpoint_mesh['mesh']
if 'mesh' in postprocess_parameters.keys():
mesh = postprocess_parameters['mesh']
try:
length = float(mesh)
mesh_opts.append('--mesh=%f' % length)
Expand All @@ -81,8 +80,8 @@ def get_phonopy_options(settings, qpoint_mesh):
mesh_opts.append('--nowritemesh')

fc_opts = []
if 'fc_calculator' in settings:
if settings['fc_calculator'].lower().strip() == 'alm':
if 'fc_calculator' in postprocess_parameters.keys():
if postprocess_parameters['fc_calculator'].lower().strip() == 'alm':
fc_opts.append('--alm')
return mesh_opts, fc_opts

Expand Down
10 changes: 6 additions & 4 deletions aiida_phonopy/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def generate_phonopy_cells(phonon_settings,
'phonon_supercell_matrix',
'distance',
'symmetry_tolerance',
'fc_calculator',
'number_of_snapshots',
'random_seed',
'is_plusminus',
Expand Down Expand Up @@ -73,7 +72,6 @@ def generate_phonopy_cells(phonon_settings,
'international' : Space group type.
'phonon_displacement_dataset' : dict
Phono3py.phonon_dataset.
'fc_calculator' : str
'number_of_snapshots' : int
'random_seed' : int
'is_plusminus' : bool
Expand Down Expand Up @@ -129,6 +127,7 @@ 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 @@ -137,7 +136,11 @@ def get_force_constants(structure,
symmetry_tolerance=symmetry_tolerance.value)
phonon.dataset = phonon_settings['displacement_dataset']
phonon.forces = force_sets.get_array('force_sets')
phonon.produce_force_constants()
if 'fc_calculator' in postprocess_parameters.keys():
if postprocess_parameters['fc_calculator'].lower().strip() == 'alm':
phonon.produce_force_constants(fc_calculator='alm')
else:
phonon.produce_force_constants()
force_constants = ArrayData()
force_constants.set_array('force_constants', phonon.force_constants)
force_constants.set_array('p2s_map', phonon.primitive.p2s_map)
Expand Down Expand Up @@ -645,7 +648,6 @@ def _get_setting_info(phonon_settings, code_name='phonopy'):
'phonon_supercell_matrix',
'distance',
'symmetry_tolerance',
'fc_calculator',
'number_of_snapshots',
'random_seed',
'is_plusminus',
Expand Down
43 changes: 30 additions & 13 deletions aiida_phonopy/workflows/phonopy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""WorkChan to run phonon calculation by phonopy and force calculators."""

from aiida.engine import WorkChain
from aiida.engine import WorkChain, calcfunction
from aiida.plugins import DataFactory, CalculationFactory
from aiida.orm import Float, Bool, Str, Code
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 (
Expand All @@ -17,6 +17,9 @@
# 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')
Dict = DataFactory('dict')
ArrayData = DataFactory('array')
XyData = DataFactory('array.xy')
Expand All @@ -25,6 +28,20 @@
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 @@ -108,7 +125,9 @@ def define(cls, spec):

spec.outline(
cls.initialize_structures,
cls.initialize_postprocess_settings,
if_(cls.run_phonopy)(
cls.initialize_postprocess_settings,
),
if_(cls.import_calculations)(
if_(cls.import_calculations_from_files)(
while_(cls.continue_import)(
Expand Down Expand Up @@ -153,7 +172,7 @@ 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('qpoint_mesh', valid_type=Dict, required=False)
spec.output('postprocess_parameters', valid_type=Dict, required=False)
spec.output('phonon_setting_info', valid_type=Dict)

def dry_run(self):
Expand Down Expand Up @@ -234,11 +253,8 @@ def initialize_postprocess_settings(self):
"""Set default settings and create supercells and primitive cell."""
self.report('initialize_postprocess_settings')

if 'mesh' in self.inputs.phonon_settings.keys():
mesh = self.inputs.phonon_settings['mesh']
else:
mesh = 100.0
self.ctx.qpoint_mesh = Dict(dict={'mesh': mesh})
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 @@ -388,7 +404,7 @@ 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.qpoint_mesh = self.ctx.qpoint_mesh
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 @@ -413,7 +429,7 @@ 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('qpoint_mesh', self.ctx.qpoint_mesh)
self.out('postprocess_parameters', self.ctx.postprocess_parameters)

self.report('finish phonon')

Expand All @@ -424,6 +440,7 @@ 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 @@ -438,13 +455,13 @@ def run_phonopy_locally(self):
result = get_phonon_properties(self.inputs.structure,
self.ctx.phonon_setting_info,
self.ctx.force_constants,
self.ctx.qpoint_mesh,
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('qpoint_mesh', self.ctx.qpoint_mesh)
self.out('postprocess_parameters', self.ctx.postprocess_parameters)

self.report('finish phonon')

Expand Down

0 comments on commit dd65449

Please sign in to comment.