def optimize_cycle(self): if not 'counter' in self.ctx: self.ctx.counter = 0 self.ctx.counter += 1 # self.ctx._get_dict() print ('start optimization') if not 'optimize' in self.ctx: structure = self.inputs.structure else: structure = parse_optimize_calculation(self.ctx.optimize)['output_structure'] if self.inputs.standarize_cell: structure = standardize_cell(structure)['standardized_structure'] JobCalculation, calculation_input = generate_inputs(structure, self.inputs.es_settings, pressure=self.inputs.pressure, type='optimize', ) calculation_input._label = 'optimize' future = submit(JobCalculation, **calculation_input) self.report('optimize calculation pk = {}'.format(future.pid)) return ToContext(optimize=future)
def create_displacement_calculations(self): from aiida_phonopy.workchains.phonon import get_primitive print ('create displacements') self.report('create displacements') if 'optimized' in self.ctx: self.ctx.final_structure = self.ctx.optimized.out.optimized_structure self.out('optimized_data', self.ctx.optimized.out.optimized_structure_data) else: self.ctx.final_structure = self.inputs.structure self.ctx.primitive_structure = get_primitive(self.ctx.final_structure, self.inputs.ph_settings)['primitive_structure'] supercells = create_supercells_with_displacements_using_phono3py(self.ctx.final_structure, self.inputs.ph_settings, self.inputs.cutoff) self.ctx.data_sets = supercells.pop('data_sets') self.ctx.number_of_displacements = len(supercells) if __testing__: f = open('labels', 'r') lines = f.readlines() f.close() from aiida.orm import load_node nodes = [int(line.split()[3]) for line in lines] print (nodes) labels = [line.split()[0] for line in lines] print (labels) for pk, label in zip(nodes, labels): future = load_node(pk) self.ctx._content[label] = future print ('{} pk = {}'.format(label, pk)) return calcs = {} for label, supercell in supercells.iteritems(): JobCalculation, calculation_input = generate_inputs(supercell, # self.inputs.machine, self.inputs.es_settings, # pressure=self.input.pressure, type='forces') calculation_input._label = label future = submit(JobCalculation, **calculation_input) print ('{} pk = {}'.format(label, future.pid)) # self.report('{} pk = {}'.format(label, future.pid)) calcs[label] = future # Born charges (for primitive cell) if bool(self.inputs.use_nac): self.report('calculate born charges') JobCalculation, calculation_input = generate_inputs(self.ctx.primitive_structure, # self.inputs.machine, self.inputs.es_settings, # pressure=self.input.pressure, type='born_charges') future = submit(JobCalculation, **calculation_input) print ('single_point: {}'.format(future.pid)) calcs['single_point'] = future return ToContext(**calcs)
def create_displacement_calculations_chunk(self): from aiida_phonopy.workchains.phonon import get_primitive if 'optimized' in self.ctx: self.ctx.final_structure = self.ctx.optimized.out.optimized_structure self.out('optimized_data', self.ctx.optimized.out.optimized_structure_data) else: self.ctx.final_structure = self.inputs.structure self.ctx.primitive_structure = get_primitive(self.ctx.final_structure, self.inputs.ph_settings)['primitive_structure'] supercells = create_supercells_with_displacements_using_phono3py(self.ctx.final_structure, self.inputs.ph_settings, self.inputs.cutoff) self.ctx.data_sets = supercells.pop('data_sets') self.ctx.number_of_displacements = len(supercells) supercells = cut_supercells(supercells, self.inputs.data_sets) calcs = {} n_disp = len(supercells) if 'i_disp' in self.ctx: list = range(self.ctx.i_disp * int(self.inputs.chunks), (self.ctx.i_disp + 1) * int(self.inputs.chunks)) else: self.ctx.i_disp = n_disp / int(self.inputs.chunks) list = range(self.ctx.i_disp * int(self.inputs.chunks), n_disp) print ('create displacements') self.report('create displacements') print ('total displacements: {}'.format(n_disp)) # Born charges (for primitive cell) if bool(self.inputs.use_nac): self.report('calculate born charges') JobCalculation, calculation_input = generate_inputs(self.ctx.primitive_structure, # self.inputs.machine, self.inputs.es_settings, # pressure=self.input.pressure, type='born_charges') future = submit(JobCalculation, **calculation_input) print ('single_point: {}'.format(future.pid)) calcs['single_point'] = future supercell_list = np.array(supercells.items())[list] for label, supercell in supercell_list: recover_calc = get_recover_calc(self.inputs.recover, label) # Recover calculations (temporal beta patch) if recover_calc is not None: self.ctx._content[label] = recover_calc print ('recovered: {}'.format(label)) continue # Recover calculations end (temporal beta patch) JobCalculation, calculation_input = generate_inputs(supercell, # self.inputs.machine, self.inputs.es_settings, # pressure=self.input.pressure, type='forces') calculation_input['_label'] = label future = submit(JobCalculation, **calculation_input) print ('{} pk = {}'.format(label, future.pid)) calcs[label] = future return ToContext(**calcs)
def create_displacement_calculations(self): self.report('create displacements') if 'optimized' in self.ctx: self.ctx.final_structure = self.ctx.optimized.out.optimized_structure self.out('optimized_data', self.ctx.optimized.out.optimized_structure_data) else: self.ctx.final_structure = self.inputs.structure self.ctx.primitive_structure = get_primitive( self.ctx.final_structure, self.inputs.ph_settings)['primitive_structure'] supercells = create_supercells_with_displacements_using_phonopy( self.ctx.final_structure, self.inputs.ph_settings) self.ctx.data_sets = supercells.pop('data_sets') self.ctx.number_of_displacements = len(supercells) calcs = {} # Load data from nodes if __testing__: from aiida.orm import load_node nodes = [96661, 96664] # VASP labels = ['structure_1', 'structure_0'] for pk, label in zip(nodes, labels): future = load_node(pk) self.ctx._content[label] = future #self.ctx._content['single_point'] = load_node(96667) return # Forces for label, supercell in supercells.iteritems(): JobCalculation, calculation_input = generate_inputs( supercell, # self.inputs.machine, self.inputs.es_settings, # pressure=self.input.pressure, type='forces') calculation_input._label = label future = submit(JobCalculation, **calculation_input) self.report('{} pk = {}'.format(label, future.pid)) calcs[label] = future # Born charges if bool(self.inputs.use_nac): self.report('calculate born charges') JobCalculation, calculation_input = generate_inputs( self.ctx.primitive_structure, self.inputs.es_settings, # pressure=self.input.pressure, type='born_charges') future = submit(JobCalculation, **calculation_input) print('single_point: {}'.format(future.pid)) calcs['single_point'] = future return ToContext(**calcs)