def _set_shear(self): """ Set ShearWorkChain data. """ qb = QueryBuilder() qb.append(Node, filters={'id': {'==': self._pk}}, tag='wf') qb.append(CalcFunctionNode, filters={'label': { '==': 'get_shear_structures' }}, with_incoming='wf', project=['id']) create_shears_pk = qb.all()[0][0] qb = QueryBuilder() qb.append(Node, filters={'id': {'==': create_shears_pk}}, tag='cs') qb.append(StructureData, with_incoming='cs', project=['id', 'label']) structs = qb.all() orig_cell_pks = [ struct[0] for struct in structs if 'shear_orig' in struct[1] ] orig_cell_pks.sort(key=lambda x: x) self._create_shears_pk = create_shears_pk self._structure_pks = {} self._structure_pks['shear_original_pks'] = orig_cell_pks self._structure_pks['hexagonal_pk'] = self._node.inputs.structure self._cells = {} self._cells['hexagonal'] = \ get_cell_from_aiida(self._node.inputs.structure) self._cells['shear_original'] = \ [ get_cell_from_aiida(load_node(pk)) for pk in orig_cell_pks ]
def _set_final_structure(self, ignore_warning): """ Set final structure. """ try: relax_structure = self._node.outputs.relax__structure self._final_structure_pk = relax_structure.pk self._final_cell = get_cell_from_aiida(relax_structure) self._current_final_structure_pk = self._final_structure_pk self._current_final_cell = self._final_cell except NotExistentAttributeError: if not ignore_warning: warnings.warn("Final structure could not find.\n" "process state:{} (pk={})".format( self.process_state, self._node.pk)) relax_pks, static_pk = self.get_vasp_calculation_pks() if relax_pks is None: self._current_final_structure_pk = self._initial_structure_pk self._current_final_cell = self._initial_cell else: if static_pk is not None: self._current_final_structure_pk = \ load_node(static_pk).inputs.structure.pk self._current_final_cell = get_cell_from_aiida( load_node(static_pk).inputs.structure) else: aiida_vasp = AiidaVaspWorkChain(load_node(relax_pks[-1])) self._current_final_structure_pk = \ aiida_vasp.get_pks()['initial_structure_pk'] self._current_final_cell = aiida_vasp.initial_cell
def _set_structures(self): """ Set structures. """ self._unitcell = get_cell_from_aiida(self._node.inputs.structure) self._primitive = get_cell_from_aiida(self._node.outputs.primitive) self._supercell = get_cell_from_aiida(self._node.outputs.supercell) self._structure_pks = { 'unitcell_pk': self._node.inputs.structure.pk, 'primitive_pk': self._node.outputs.primitive.pk, 'supercell_pk': self._node.outputs.supercell.pk, }
def _set_initial_structure(self): """ Set initial structure. """ self._initial_structure_pk = self._node.inputs.structure.pk self._initial_cell = get_cell_from_aiida( load_node(self._initial_structure_pk))
def _set_twinboundary_structure(self): """ Set twinpy structure object and standardize object. """ params = self._twinboundary_parameters cell = get_cell_from_aiida( load_node(self._structure_pks['hexagonal_pk'])) lattice, _, symbols = cell wyckoff = get_wyckoff_from_hcp(cell=cell) twinboundary = get_twinboundary( lattice=lattice, symbol=symbols[0], twinmode=params['twinmode'], layers=params['layers'], wyckoff=wyckoff, delta=params['delta'], twintype=params['twintype'], xshift=params['xshift'], yshift=params['yshift'], shear_strain_ratio=params['shear_strain_ratio']) tb_cell = twinboundary.get_cell_for_export( get_lattice=False, move_atoms_into_unitcell=True, ) self._twinboundary_structure = twinboundary self._standardize = StandardizeCell(cell=tb_cell)
def __init__( self, node: Node, is_nac: bool = True, external_nac_node: int = None, ): """ Args: node: Aiida Node. external_nac_node: If is_nac=True and external_nac_node is specified, nac params are gotten from external_nac_node. """ process_class = 'PhonopyWorkChain' check_process_class(node, process_class) super().__init__(node=node) self._unitcell = get_cell_from_aiida( load_node(node.inputs.structure.pk)) self._phonon_settings = node.inputs.phonon_settings.get_dict() self._phonon_setting_info = node.outputs.phonon_setting_info.get_dict() self._unitcell = None self._primitive = None self._supercell = None self._structure_pks = None self._set_structures() self._force_sets = None self._set_force_sets() self._nac_params = None if external_nac_node: self._set_nac_params_from_external(external_nac_node) elif 'nac_params' in self._node.outputs and is_nac: self._set_nac_params()
def _set_final_structure(self, ignore_warning): """ Set final structure. """ try: self._final_structure_pk = self._node.outputs.structure.pk self._final_cell = get_cell_from_aiida( load_node(self._final_structure_pk)) except NotExistentAttributeError: if not ignore_warning: warnings.warn("Final structure could not find.\n" "process state:{} (pk={})".format( self.process_state, self._node.pk))
def _set_twinboundary(self): """ Set twinboundary from vasp. """ sub_prc = self._sub_processes tb_parameters = self._node.outputs.twinboundary_parameters.get_dict() aiida_hex_structure = self._node.inputs.structure aiida_tb_structure = \ sub_prc['get_twinboundary_structure'].outputs.twinboundary aiida_tb_orig_structure = \ sub_prc['get_twinboundary_structure'].outputs.twinboundary_orig aiida_tb_rlx_structure = \ sub_prc['RelaxWorkChain'].outputs.relax__structure round_cells = [] for aiida_structure in [ aiida_tb_structure, aiida_tb_orig_structure, aiida_tb_rlx_structure ]: cell = get_cell_from_aiida(aiida_structure) round_lattice = np.round(cell[0], decimals=8) round_lattice = cell[0] round_atoms = np.round(cell[1], decimals=8) % 1 round_cell = (round_lattice, round_atoms, cell[2]) round_cells.append(round_cell) self._twinboundary_parameters = tb_parameters self._cells = { 'hexagonal': get_cell_from_aiida(aiida_hex_structure), 'twinboundary': round_cells[0], 'twinboundary_original': round_cells[1], 'twinboundary_relax': round_cells[2], } self._structure_pks = { 'hexagonal_pk': aiida_hex_structure.pk, 'twinboundary_pk': aiida_tb_structure.pk, 'twinboundary_original_pk': aiida_tb_orig_structure.pk, 'twinboundary_relax_pk': aiida_tb_rlx_structure.pk, }
def _set_structures(self): """ Check previous output structure and next input structure are the same. """ relax_pk = None structure_pk = None for i, aiida_relax in enumerate(self._aiida_relaxes): if i > 0: if aiida_relax.get_pks()['initial_structure_pk'] \ != structure_pk: raise RuntimeError( "Relax pk {} output structure pk {} " "and relax pk {} input structure pk {} " "does not match.".format( relax_pk, structure_pk, aiida_relax.pk, aiida_relax.get_pks()['initial_structure_pk'], )) relax_pk = aiida_relax.pk structure_pk = aiida_relax.get_pks()['current_final_structure_pk'] self._current_final_structure_pk = structure_pk self._current_final_cell = \ get_cell_from_aiida(load_node(structure_pk)) if self._aiida_relaxes[-1].process_state == 'finished': self._final_structure_pk = \ self._current_final_structure_pk self._final_cell = self._current_final_cell self._initial_structure_pk = \ self._aiida_relaxes[0].get_pks()['initial_structure_pk'] self._initial_cell = \ get_cell_from_aiida(load_node(self._initial_structure_pk))