Beispiel #1
0
def run_eos_wf(codename, pseudo_family, element):
    print "Workfunction node identifiers: {}".format(Process.current().calc)
    s0 = create_diamond_fcc(Str(element))

    calcs = {}
    for label, factor in zip(labels, scale_facs):
        s = rescale(s0, Float(factor))
        inputs = generate_scf_input_params(s, str(codename),
                                           Str(pseudo_family))
        print "Running a scf for {} with scale factor {}".format(
            element, factor)
        result = run(PwCalculation, **inputs)
        print "RESULT: {}".format(result)
        calcs[label] = get_info(result)

    eos = []
    for label in labels:
        eos.append(calcs[label])

    # Return information to plot the EOS
    ParameterData = DataFactory('parameter')
    retdict = {
        'initial_structure': s0,
        'result': ParameterData(dict={'eos_data': eos})
    }

    return retdict
def run_eos_wf(codename, pseudo_family, element):
	print "Workfunction node pk: {}".format(registry.current_calc_node)
	#Instantiate a JobCalc process and create basic structure
	JobCalc = PwCalculation.process()
	s0 = create_diamond_fcc(Str(element))
	eos=[]
	scale_facs = (0.98, 0.99, 1.0, 1.02, 1.04)
	for factor in  scale_facs:
		s = rescale(s0,Float(factor))
		inputs = generate_scf_input_params(
			s, str(codename), str(pseudo_family))
		print "Running a scf for {} with scale factor {}".format(
			element, factor)
	calc_results = run(JobCalc,**inputs)
	eos.append(get_info(calc_results))
	#Return information to plot the EOS
	ParameterData = DataFactory("parameter")
	return {'initial_structure': s0,'result': ParameterData(dict={'eos_data': eos})}
Beispiel #3
0
    def run_pw(self):
        print "Workchain node identifiers: {}".format(self.calc)
        #Instantiate a JobCalc process and create basic structure
        JobCalc = PwCalculation.process()
        self.ctx.s0 = create_diamond_fcc(Str(self.inputs.element))
        self.ctx.eos_names = []

        calcs = {}
        for label, factor in zip(labels, scale_facs):
            s = rescale(self.ctx.s0, Float(factor))
            inputs = generate_scf_input_params(s, str(self.inputs.code),
                                               self.inputs.pseudo_family)
            print "Running a scf for {} with scale factor {}".format(
                self.inputs.element, factor)
            future = submit(JobCalc, **inputs)
            calcs[label] = future

        # Ask the workflow to continue when the results are ready and store them
        # in the context
        return ToContext(**calcs)
def run_eos_wf(code, pseudo_family, element):
    """Run an equation of state of a bulk crystal structure for the given element."""

    # This will print the pk of the work function
    print('Running run_eos_wf<{}>'.format(Process.current().pid))

    scale_factors = (0.96, 0.98, 1.0, 1.02, 1.04)
    labels = ['c1', 'c2', 'c3', 'c4', 'c5']

    calculations = {}

    # Create an initial bulk crystal structure for the given element, using the calculation function defined earlier
    initial_structure = create_diamond_fcc(element)

    # Loop over the label and scale_factor pairs
    for label, factor in list(zip(labels, scale_factors)):

        # Generated the scaled structure from the initial structure
        structure = rescale(initial_structure, Float(factor))

        # Generate the inputs for the `PwCalculation`
        inputs = generate_scf_input_params(structure, code, pseudo_family)

        # Launch a `PwCalculation` for each scaled structure
        print('Running a scf for {} with scale factor {}'.format(
            element, factor))
        calculations[label] = run(PwCalculation, **inputs)

    # Bundle the individual results from each `PwCalculation` in a single dictionary node.
    # Note: since we are 'creating' new data from existing data, we *have* to go through a `calcfunction`, otherwise
    # the provenance would be lost!
    inputs = {
        label: result['output_parameters']
        for label, result in calculations.items()
    }
    eos = create_eos_dictionary(**inputs)

    # Finally, return the results of this work function
    result = {'initial_structure': initial_structure, 'eos': eos}

    return result
    def run_eos(self):
        """Run calculations for equation of state."""
        # Create basic structure and attach it as an output
        initial_structure = create_diamond_fcc(self.inputs.element)
        self.out('initial_structure', initial_structure)

        calculations = {}

        for label, factor in zip(labels, scale_facs):

            structure = rescale(initial_structure, Float(factor))
            inputs = generate_scf_input_params(structure, self.inputs.code,
                                               self.inputs.pseudo_family)

            self.report(
                'Running an SCF calculation for {} with scale factor {}'.
                format(self.inputs.element, factor))
            future = self.submit(PwCalculation, **inputs)
            calculations[label] = future

        # Ask the workflow to continue when the results are ready and store them in the context
        return ToContext(**calculations)
    def run_pw(self, ctx):
        
        PwProcess = PwCalculation.process()
        ctx.s0 = create_diamond_fcc(Str(self.inputs.element))

        ctx.eos_names = []
        calcs = {}
 
        for label, factor in zip(labels, scale_facs):
            s = rescale(ctx.s0,Float(factor))
            inputs = generate_scf_input_params(
                s, str(self.inputs.code), str(self.inputs.pseudo_family))
            print "Running a scf for {} with scale factor {}".format(
                self.inputs.element, factor)

            # Launch the code
            future = self.submit(PwProcess, inputs)
            # Store the future
            calcs[label] = future
          
        # Ask the workflow to continue when the results are ready and store them
        # in the context
        return ResultToContext(**calcs)
    def report(self, ctx):
        """
        Output final quantities
        """
        from aiida.orm import DataFactory
        self.out("steps", DataFactory('parameter')(dict={
            'steps': ctx.steps,
            'step0': ctx.step0}))
        self.out("structure", ctx.last_structure)
        

if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(description='Energy calculation example.')
    parser.add_argument('--pseudo', type=str, dest='pseudo', required=True,
                        help='The pseudopotential family')
    parser.add_argument('--code', type=str, dest='code', required=True,
                        help='The codename to use')

    structure = create_diamond_fcc(element=Str('Si'))
    
    print "Initial structure:", structure

    args = parser.parse_args()
    wf_results = run(PressureConvergence, structure=structure, code=Str(args.code), pseudo_family=Str(args.pseudo), volume_tolerance=Float(0.1))
    print "Workflow results:"
    print wf_results

        r0_out = self.ctx.r0.get_outputs_dict()
        r1_out = self.ctx.r1.get_outputs_dict()

        return abs(r1_out['output_parameters'].dict.volume -
                   r0_out['output_parameters'].dict.volume
                   ) > self.inputs.volume_tolerance

    def finish(self):
        """
        Output final quantities
        """
        from aiida.orm import DataFactory
        self.out(
            "steps",
            DataFactory('parameter')(dict={
                'steps': self.ctx.steps,
                'step0': self.ctx.step0
            }))
        self.out("structure", self.ctx.last_structure)


if __name__ == "__main__":
    structure = create_diamond_fcc(element=Str('Si'))
    wf_results = run_eos(structure=structure)
    print "Initial structure:", structure
    print "Workflow results:"
    print "Final energies and fit parameters are stored in the ParameterData {}".format(
        wf_results['steps'].pk)
    print "The optimized structure is stored in StructureData with pk {}".format(
        wf_results['structure'].pk)