Example #1
0
    def define(cls, spec):
        # yapf: disable
        super().define(spec)

        # INPUTS ############################################################################
        spec.input(
            'code', valid_type=orm.Code,
            help='The PWscf code.'
            )
        spec.input(
            'structure', valid_type=orm.StructureData,
            help='The inputs structure.'
            )
        spec.input(
            'parent_folder', valid_type=orm.RemoteData,
            required=False,
            help='The remote data of a previously performed scf calculation.'
            )
        spec.input_namespace(
            'pseudos', valid_type=orm.UpfData,
            dynamic=True,
            help='A mapping of `UpfData` nodes onto the kind name to which they should apply.'
            )
        spec.input(
            'clean_workdir', valid_type=orm.Bool,
            default=orm.Bool(False),
            help='If `True`, work directories of all called calculation will be cleaned at the end of execution.'
            )
        spec.expose_inputs(
            PwRelaxWorkChain, namespace='relax',
            exclude=('clean_workdir', 'structure', 'base.pw.code', 'base.pw.pseudos'),
            namespace_options={
                'required': False, 'populate_defaults': False,
                'help': 'Inputs for the `PwBaseWorkChain` for the RELAX calculation.'
                }
            )
        spec.expose_inputs(
            PwBaseWorkChain, namespace='scf',
            exclude=('clean_workdir', 'pw.structure', 'pw.code', 'pw.pseudos'),
            namespace_options={
                'required': False, 'populate_defaults': False,
                'help': 'Inputs for the `PwBaseWorkChain` for the SCF calculation.'
                }
            )
        spec.expose_inputs(
            PwBaseWorkChain, namespace='bands',
            exclude=('clean_workdir', 'pw.structure', 'pw.code', 'pw.pseudos', 'kpoints'),
            namespace_options={
                'required': False, 'populate_defaults': False,
                'help': 'Inputs for the `PwBaseWorkChain` for the BANDS calculation.'
                }
            )

        spec.input(
            'min_kpoints_distance', valid_type=orm.Float,
            default=orm.Float(5.E-4),
            help='Stop iterations when `kpoints_distance` drop below this value.'
            )
        spec.input(
            'starting_kpoints_distance', valid_type=orm.Float,
            default=orm.Float(0.2),
            help='Strating distance between kpoints.'
            )
        spec.input(
            'scale_kpoints_distance', valid_type=orm.Float,
            default=orm.Float(5.0),
            help='Across iterations divide `kpoints_distance` by this scaling factor.'
            )
        spec.input(
            'starting_kpoints', valid_type=orm.KpointsData,
            required=False,
            help='Starting mesh of kpoints'
            )
        spec.input(
            'gap_threshold', valid_type=orm.Float,
            default=orm.Float(0.0025),
            help='kpoints ith gap < `gap_threshold` are considered possible crossings.'
            )

        # OUTLINE ############################################################################
        spec.outline(
            cls.setup,
            if_(cls.should_do_relax)(
                cls.run_relax,
                cls.inspect_relax,
                ),
            if_(cls.should_do_scf)(
                cls.run_scf,
                cls.inspect_scf,
            ).else_(
                cls.set_remote_scf
                ),
            cls.setup_bands_loop,
            if_(cls.should_do_first_bands)(
                cls.first_bands_step,
                cls.inspect_bands,
            ).else_(
                cls.start_from_scf
                ),
            cls.analyze_bands,
            while_(cls.should_find_zero_gap)(
                cls.setup_grid,
                cls.run_bands,
                cls.inspect_bands,
                cls.analyze_bands,
                cls.stepper
                ),
            cls.results
            )

        # OUTPUTS ############################################################################
        spec.output('crossings', valid_type=orm.ArrayData,
            required=True,
            help='The array containing a list of bands crossing found as rows.'
            )
        spec.output('scf_remote_folder', valid_type=orm.RemoteData,
            required=False,
            help='The remote folder produced by the scf calculation.'
            )
        spec.output('output_structure', valid_type=orm.StructureData,
            required=False,
            help='The structure produced by the relax calculation.'
            )

        # ERRORS ############################################################################
        spec.exit_code(312, 'ERROR_SUB_PROCESS_FAILED_RELAX',
            message='the relax PwRelaxWorkChain sub process failed')
        spec.exit_code(322, 'ERROR_SUB_PROCESS_FAILED_SCF',
            message='the scf PwBaseWorkChain sub process failed')
        spec.exit_code(332, 'ERROR_SUB_PROCESS_FAILED_BANDS',
            message='the bands PwBaseWorkChain sub process failed')
Example #2
0
    def define(cls, spec):
        # yapf: disable
        super().define(spec)

        # INPUTS ############################################################################
        spec.input(
            'pw_code', valid_type=orm.Code,
            help='The code for pw calculations.'
            )
        spec.input(
            'structure', valid_type=orm.StructureData,
            help='The inputs structure.'
            )
        spec.input(
            'crossings', valid_type=orm.ArrayData,
            required=False,
            help='Skip the FindCrossing and use the result of a previously run workchain.'
            )
        spec.input(
            'sphere_radius', valid_type=orm.Float,
            default=orm.Float(0.005),
            help='Radius for the sphere of kpoints.'
            )
        spec.input(
            'scf_parent_folder', valid_type=orm.RemoteData,
            required=False,
            help='The remote_folder of an scf calculation to be used by z2pack.'
            )
        spec.input(
            'clean_workdir', valid_type=orm.Bool,
            default=orm.Bool(False),
            help='If `True`, work directories of all called calculation will be cleaned at the end of execution.'
            )

        spec.expose_inputs(
            FindCrossingsWorkChain, namespace='find',
            exclude=('clean_workdir', 'structure', 'code'),
            namespace_options={
                'required':False, 'populate_defaults':False,
                'help': 'Inputs for the `FindCrossingsWorkChain`.'
                }
            )
        spec.expose_inputs(
            PwBaseWorkChain, namespace='scf',
            exclude=('clean_workdir', 'pw.structure', 'pw.code'),
            namespace_options={
                'required':False, 'populate_defaults':False,
                'help': 'Inputs for the `PwBaseWorkChain` scf calculation.'
                }
            )
        spec.expose_inputs(
            Z2packBaseWorkChain, namespace='z2pack_base',
            exclude=('clean_workdir', 'structure', 'parent_folder', 'pw_code', 'scf'),
            namespace_options={
                'help': 'Inputs for the `Z2packBaseWorkChain`.'
                }
            )

        # OUTLINE ############################################################################
        spec.outline(
            cls.setup,
            cls.validate_crossings,
            if_(cls.should_do_find_crossings)(
                cls.run_find_crossings,
                cls.inspect_find_crossings,
            ).else_(
                cls.set_crossings_from_input
                ),
            if_(cls.should_do_scf)(
                cls.run_scf,
                cls.inspect_scf
                ),
            cls.prepare_z2pack,
            if_(cls.should_do_alltogheter)(
                cls.run_z2pack_all,
                cls.inspect_z2pack_all
            ).else_(
                while_(cls.do_z2pack_one)(
                    cls.run_z2pack_one,
                    cls.inspect_z2pack_one,
                    ),
                ),
            cls.results
            )

        # OUTPUTS ############################################################################
        spec.output(
            'output_parameters', valid_type=orm.Dict,
            help='Dict resulting from a z2pack calculation.'
            )
        spec.expose_outputs(
            FindCrossingsWorkChain, namespace='find',
            exclude=('scf_remote_folder', ),
            namespace_options={
                'required':False, 'populate_defaults': False,
                'help': 'Outputs for the `FindCrossingsWorkChain`.'
                }
            )

        # ERRORS ############################################################################
        spec.exit_code(313, 'ERROR_SUB_PROCESS_FAILED_FINDCROSSING',
            message='the FindCrossingsWorkChain sub process failed')
        spec.exit_code(323, 'ERROR_SUB_PROCESS_FAILED_Z2PACK',
            message='the Z2packBaseWorkChain sub process failed')
        spec.exit_code(333, 'ERROR_INVALID_INPUT_CROSSINGS',
            message='Must provide either `find` namelist or `crossings` ArrayData as input.')
        spec.exit_code(343, 'ERROR_INVALID_INPUT_SCF_Z2PACK',
            message='If `crossings` is given, must also specify `scf_parent_folder` or `z2pack.scf`.')
        spec.exit_code(403, 'ERROR_NO_CROSSINGS_FOUND',
            message='No crossings were found.')
Example #3
0
    def define(cls, spec):
        super(RelaxWorkChain, cls).define(spec)
        spec.expose_inputs(cls._next_workchain,
                           exclude=('parameters', 'structure', 'settings'))
        spec.input('structure',
                   valid_type=(get_data_class('structure'),
                               get_data_class('cif')))
        spec.input('parameters', valid_type=get_data_class('dict'))
        spec.input('settings',
                   valid_type=get_data_class('dict'),
                   required=False)
        spec.input('relax.perform',
                   valid_type=get_data_class('bool'),
                   required=False,
                   default=lambda: get_data_node('bool', False),
                   help="""
            If True, perform relaxation.
            """)
        spec.input('relax.algo',
                   valid_type=get_data_class('str'),
                   default=lambda: get_data_node('str', 'cg'),
                   help="""
            The algorithm to use during relaxation.
            """)
        spec.input('relax.energy_cutoff',
                   valid_type=get_data_class('float'),
                   required=False,
                   help="""
            The cutoff that determines when the relaxation procedure is stopped. In this
            case it stops when the total energy between two ionic steps is less than the
            supplied value.
            """)
        spec.input('relax.force_cutoff',
                   valid_type=get_data_class('float'),
                   required=False,
                   help="""
            The cutoff that determines when the relaxation procedure is stopped. In this
            case it stops when all forces are smaller than than the
            supplied value.
            """)
        spec.input('relax.steps',
                   valid_type=get_data_class('int'),
                   required=False,
                   default=lambda: get_data_node('int', 60),
                   help="""
                   The number of relaxation steps to perform (updates to the atomic positions,
            unit cell size or shape).
                   """)
        spec.input('relax.positions',
                   valid_type=get_data_class('bool'),
                   required=False,
                   default=lambda: get_data_node('bool', True),
                   help="""
                   If True, perform relaxation of the atomic positions.
                   """)
        spec.input('relax.shape',
                   valid_type=get_data_class('bool'),
                   required=False,
                   default=lambda: get_data_node('bool', False),
                   help="""
                   If True, perform relaxation of the unit cell shape.
                   """)
        spec.input('relax.volume',
                   valid_type=get_data_class('bool'),
                   required=False,
                   default=lambda: get_data_node('bool', False),
                   help="""
                   If True, perform relaxation of the unit cell volume..
                   """)
        spec.input('relax.convergence_on',
                   valid_type=get_data_class('bool'),
                   required=False,
                   default=lambda: get_data_node('bool', False),
                   help="""
                   If True, test convergence based on selected criterias set.
                   """)
        spec.input('relax.convergence_absolute',
                   valid_type=get_data_class('bool'),
                   required=False,
                   default=lambda: get_data_node('bool', False),
                   help="""
                   If True, test convergence based on absolute differences.
                   """)
        spec.input('relax.convergence_max_iterations',
                   valid_type=get_data_class('int'),
                   required=False,
                   default=lambda: get_data_node('int', 5),
                   help="""
                   The number of iterations to perform if the convergence criteria is not met.
                   """)
        spec.input('relax.convergence_volume',
                   valid_type=get_data_class('float'),
                   required=False,
                   default=lambda: get_data_node('float', 0.01),
                   help="""
                   The cutoff value for the convergence check on volume. If ``convergence_absolute``
                   is True in AA, otherwise in relative.
                   """)
        spec.input('relax.convergence_positions',
                   valid_type=get_data_class('float'),
                   required=False,
                   default=lambda: get_data_node('float', 0.01),
                   help="""
                   The cutoff value for the convergence check on positions. If ``convergence_absolute``
                   is True in AA, otherwise in relative difference.
                   """)
        spec.input('relax.convergence_shape_lengths',
                   valid_type=get_data_class('float'),
                   required=False,
                   default=lambda: get_data_node('float', 0.1),
                   help="""
                   The cutoff value for the convergence check on the lengths of the unit cell
                   vecotrs. If ``convergence_absolute``
                   is True in AA, otherwise in relative difference.
                   """)
        spec.input('relax.convergence_shape_angles',
                   valid_type=get_data_class('float'),
                   required=False,
                   default=lambda: get_data_node('float', 0.1),
                   help="""
                   The cutoff value for the convergence check on the angles of the unit cell.
                   If ``convergence_absolute`` is True in degrees, otherwise in relative difference.
                   """)
        spec.exit_code(0, 'NO_ERROR', message='the sun is shining')
        spec.exit_code(
            300,
            'ERROR_MISSING_REQUIRED_OUTPUT',
            message=
            'the called workchain does not contain the necessary relaxed output structure'
        )
        spec.exit_code(420,
                       'ERROR_NO_CALLED_WORKCHAIN',
                       message='no called workchain detected')
        spec.exit_code(500,
                       'ERROR_UNKNOWN',
                       message='unknown error detected in the relax workchain')
        spec.exit_code(502,
                       'ERROR_OVERRIDE_PARAMETERS',
                       message='there was an error overriding the parameters')
        spec.outline(
            cls.initialize,
            if_(cls.perform_relaxation)(
                while_(cls.run_next_workchains)(
                    cls.init_next_workchain,
                    cls.run_next_workchain,
                    cls.verify_next_workchain,
                    cls.analyze_convergence,
                ),
                cls.store_relaxed,
            ),
            cls.init_relaxed,
            cls.init_next_workchain,
            cls.run_next_workchain,
            cls.verify_next_workchain,
            cls.results,
            cls.finalize
        )  # yapf: disable

        spec.expose_outputs(cls._next_workchain)
        spec.output('relax.structure',
                    valid_type=get_data_class('structure'),
                    required=False)
Example #4
0
    def define(cls, spec):
        super().define(spec)
        spec.expose_inputs(FleurScfWorkChain, namespace='scf')
        spec.expose_inputs(FleurScfWorkChain,
                           namespace='final_scf',
                           exclude=('structure', 'fleur', 'fleurinp',
                                    'remote_data'),
                           namespace_options={
                               'required': False,
                           })
        spec.input('wf_parameters', valid_type=Dict, required=False)

        spec.outline(
            cls.start,
            if_(cls.should_relax)(cls.converge_scf, cls.check_failure,
                                  while_(cls.condition)(
                                      cls.generate_new_fleurinp,
                                      cls.converge_scf,
                                      cls.check_failure,
                                  )),
            cls.get_results_relax,
            if_(cls.should_run_final_scf)(cls.run_final_scf,
                                          cls.get_results_final_scf),
            cls.return_results,
        )

        spec.output('output_relax_wc_para', valid_type=Dict)
        spec.output('optimized_structure', valid_type=StructureData)

        # exit codes
        spec.exit_code(230,
                       'ERROR_INVALID_INPUT_PARAM',
                       message='Invalid workchain parameters.')
        spec.exit_code(
            231,
            'ERROR_INPGEN_MISSING',
            message='If you want to run a final scf inpgen has to be there.')
        spec.exit_code(
            350,
            'ERROR_DID_NOT_RELAX',
            message='Optimization cycle did not lead to convergence of forces.'
        )
        spec.exit_code(351,
                       'ERROR_SCF_FAILED',
                       message='SCF Workchains failed for some reason.')
        spec.exit_code(
            352,
            'ERROR_NO_RELAX_OUTPUT',
            message='Found no relaxed structure info in the output of SCF')
        spec.exit_code(353,
                       'ERROR_NO_SCF_OUTPUT',
                       message='Found no SCF output')
        spec.exit_code(354,
                       'ERROR_SWITCH_BFGS',
                       message='Force is small, switch to BFGS')
        spec.exit_code(
            311,
            'ERROR_VACUUM_SPILL_RELAX',
            message='FLEUR calculation failed because an atom spilled to the'
            'vacuum during relaxation')
        spec.exit_code(313,
                       'ERROR_MT_RADII_RELAX',
                       message='Overlapping MT-spheres during relaxation.')
    def define(cls, spec):
        super(SiestaBaseWorkChain, cls).define(spec)
        spec.input('code', valid_type=orm.Code)
        spec.input('structure', valid_type=orm.StructureData)
        spec.input_namespace('pseudos', required=False, dynamic=True)
        spec.input('pseudo_family', valid_type=orm.Str, required=False)
        spec.input('parent_folder', valid_type=orm.RemoteData, required=False)
        spec.input('kpoints', valid_type=orm.KpointsData, required=False)
        spec.input('bandskpoints', valid_type=orm.KpointsData, required=False)
        #Required by the plugin
        spec.input('parameters', valid_type=orm.Dict)
        spec.input('basis', valid_type=orm.Dict, required=False)
        spec.input('settings', valid_type=orm.Dict, required=False)
        #Required by any CalcJob
        spec.input('options', valid_type=orm.Dict)

        spec.input(
            'max_iterations',
            valid_type=orm.Int,
            default=orm.Int(5),
            help=
            'maximum number of iterations the workchain will restart the calculation to finish successfully'
        )
        spec.input(
            'clean_workdir',
            valid_type=orm.Bool,
            default=orm.Bool(False),
            help=
            'if True, work directories of all called calculation will be cleaned at the end of execution'
        )

        spec.outline(
            cls.setup,
            cls.validate_pseudo_potentials,
            while_(cls.should_run_siesta)(
                cls.run_siesta,
                cls.inspect_siesta,
            ),
            cls.run_results,
        )

        # commented out, since it's more clear to provide list of outputs explicitly:
        # spec.dynamic_output()

        spec.output('forces_and_stress',
                    valid_type=orm.ArrayData,
                    required=False)
        spec.output('bands', valid_type=orm.BandsData, required=False)
        spec.output('output_structure',
                    valid_type=orm.StructureData,
                    required=False)
        spec.output('output_parameters', valid_type=orm.Dict)
        spec.output('remote_folder', valid_type=orm.RemoteData)

        spec.exit_code(
            100,
            'ERROR_ITERATION_RETURNED_NO_CALCULATION',
            message=
            'the run_calculation step did not successfully add a calculation node to the context'
        )
        spec.exit_code(101,
                       'ERROR_MAXIMUM_ITERATIONS_EXCEEDED',
                       message='the maximum number of iterations was exceeded')
        spec.exit_code(
            102,
            'ERROR_UNEXPECTED_CALCULATION_STATE',
            message=
            'the calculation finished with an unexpected calculation state')
        spec.exit_code(
            103,
            'ERROR_SECOND_CONSECUTIVE_SUBMISSION_FAILURE',
            message='the calculation failed to submit, twice in a row')
        spec.exit_code(
            104,
            'ERROR_SECOND_CONSECUTIVE_UNHANDLED_FAILURE',
            message=
            'the calculation failed for an unknown reason, twice in a row')

        spec.exit_code(
            301,
            'ERROR_INVALID_INPUT_PSEUDO_POTENTIALS',
            message=
            "the explicitly passed 'pseudos' or 'pseudo_family' could not be used to get the necessary potentials"
        )

        spec.exit_code(501,
                       'ERROR_WORKFLOW_FAILED',
                       message="Workflow did not succeed")
Example #6
0
 def define(cls, spec):
     super().define(spec)
     spec.input('iterations', required=True)
     spec.input('code', required=False)
     spec.outline(cls.init_loop, while_(cls.terminate_loop)(cls.run_task))
Example #7
0
    def define(cls, spec):
        # yapf: disable
        super().define(spec)

        # SCF INPUTS ###########################################################
        spec.expose_inputs(
            PwBaseWorkChain, namespace='scf',
            exclude=('clean_workdir', 'pw.structure', 'pw.code'),
            namespace_options={
                'required':False, 'populate_defaults':False,
                'help': 'Inputs for the `PwBaseWorkChain` for the SCF calculation.'
                }
            )
        spec.input(
            'structure', valid_type=orm.StructureData,
            help='The inputs structure.'
            )
        spec.input(
            'pw_code', valid_type=orm.Code,
            help='The code for pw calculations.'
            )
        spec.input(
            'clean_workdir', valid_type=orm.Bool,
            default=lambda: orm.Bool(False),
            help='If `True`, work directories of all called calculation will be cleaned at the end of execution.'
            )
        spec.input(
            'parent_folder', valid_type=orm.RemoteData,
            required=False,
            help=(
                'Output of a previous scf calculation to start a new z2pack calclulation from. '
                'If specified, will not run the scf calculation and start straight from z2pack.'
                )
            )

        #Z2pack inputs ###########################################################
        spec.input(
            'min_neighbour_distance_scale_factor', valid_type=orm.Float,
            default=lambda: orm.Float(10.0),
            help='Scale factor for min_neighbour_distance to be used between restarts when convergence is not achieved.'
            )
        spec.input(
            'min_neighbour_distance_threshold_minimum', valid_type=orm.Float,
            default=lambda: orm.Float(1E-4),
            help='Stop the restart iterations when `min_neighbour_distance` becomes smaller than this threshold.'
            )
        spec.expose_inputs(
            Z2packCalculation, namespace='z2pack',
            exclude=('parent_folder', 'pw_code'),
            namespace_options={
                'help': 'Inputs for the `Z2packCalculation` for the SCF calculation.'
                }
            )

        spec.outline(
            cls.setup,
            if_(cls.should_do_scf)(
                cls.run_scf,
                cls.inspect_scf,
                ),
            cls.setup_z2pack,
            while_(cls.should_run_process)(
                cls.prepare_process,
                cls.run_process,
                cls.inspect_process
                ),
            cls.results
            )

        spec.expose_outputs(Z2packCalculation)
        spec.expose_outputs(PwBaseWorkChain, namespace='scf',
            namespace_options={
                'required':False,
                })
        spec.output(
            'last_z2pack_remote_folder', valid_type=orm.RemoteData,
            required=False, help=''
            )
        spec.output(
            'wannier90_parameters', valid_type=orm.Dict,
            required=False,
            help='Auto-setted w90parameters.'
            )
        spec.exit_code(101, 'ERROR_UNRECOVERABLE_FAILURE', message='Can\'t recover. Aborting!')
        spec.exit_code(111, 'ERROR_SUB_PROCESS_FAILED_STARTING_SCF',
            message='the starting scf PwBaseWorkChain sub process failed')
        spec.exit_code(201, 'ERROR_NOT_CONVERGED',
            message='Calculation finished, but convergence not achieved.')
        spec.exit_code(211, 'ERROR_POS_TOL_CONVERGENCE_FAILED',
            message='WCCs position is not stable when increasing k-points on a line.')
        spec.exit_code(221, 'ERROR_MOVE_TOL_CONVERGENCE_FAILED',
            message='Position of largest gap between WCCs varies too much between neighboring lines.')
        spec.exit_code(222, 'ERROR_GAP_TOL_CONVERGENCE_FAILED',
            message='The WCC gap between neighboring lines are too close.')
        spec.exit_code(223, 'ERROR_MOVE_GAP_TOL_CONVERGENCE_FAILED',
            message='Both gap_tol and move_tol convergence failed.')
        spec.exit_code(231, 'ERROR_FAILED_SAVEFILE_TWICE',
            message='The calculation failed to produce the savefile for a restart twice.')
Example #8
0
    def define(cls, spec):
        """Define the process specification."""
        # yapf: disable
        super().define(spec)
        spec.expose_inputs(PwCalculation, namespace='pw', exclude=('kpoints',))
        spec.input('pw.metadata.options.resources', valid_type=dict, required=False)
        spec.input('kpoints', valid_type=orm.KpointsData, required=False,
            help='An explicit k-points list or mesh. Either this or `kpoints_distance` has to be provided.')
        spec.input('kpoints_distance', valid_type=orm.Float, required=False,
            help='The minimum desired distance in 1/Å between k-points in reciprocal space. The explicit k-points will '
                 'be generated automatically by a calculation function based on the input structure.')
        spec.input('kpoints_force_parity', valid_type=orm.Bool, required=False,
            help='Optional input when constructing the k-points based on a desired `kpoints_distance`. Setting this to '
                 '`True` will force the k-point mesh to have an even number of points along each lattice vector except '
                 'for any non-periodic directions.')
        spec.input('pseudo_family', valid_type=orm.Str, required=False,
            help='An alternative to specifying the pseudo potentials manually in `pseudos`: one can specify the name '
                 'of an existing pseudo potential family and the work chain will generate the pseudos automatically '
                 'based on the input structure.')
        spec.input('automatic_parallelization', valid_type=orm.Dict, required=False,
            help='When defined, the work chain will first launch an initialization calculation to determine the '
                 'dimensions of the problem, and based on this it will try to set optimal parallelization flags.')

        spec.outline(
            cls.setup,
            cls.validate_parameters,
            cls.validate_kpoints,
            cls.validate_pseudos,
            cls.validate_resources,
            if_(cls.should_run_init)(
                cls.validate_init_inputs,
                cls.run_init,
                cls.inspect_init,
            ),
            while_(cls.should_run_process)(
                cls.prepare_process,
                cls.run_process,
                cls.inspect_process,
            ),
            cls.results,
        )

        spec.expose_outputs(PwCalculation)
        spec.output('automatic_parallelization', valid_type=orm.Dict, required=False,
            help='The results of the automatic parallelization analysis if performed.')

        spec.exit_code(201, 'ERROR_INVALID_INPUT_PSEUDO_POTENTIALS',
            message='The explicit `pseudos` or `pseudo_family` could not be used to get the necessary pseudos.')
        spec.exit_code(202, 'ERROR_INVALID_INPUT_KPOINTS',
            message='Neither the `kpoints` nor the `kpoints_distance` input was specified.')
        spec.exit_code(203, 'ERROR_INVALID_INPUT_RESOURCES',
            message='Neither the `options` nor `automatic_parallelization` input was specified.')
        spec.exit_code(204, 'ERROR_INVALID_INPUT_RESOURCES_UNDERSPECIFIED',
            message='The `metadata.options` did not specify both `resources.num_machines` and `max_wallclock_seconds`.')
        spec.exit_code(210, 'ERROR_INVALID_INPUT_AUTOMATIC_PARALLELIZATION_MISSING_KEY',
            message='Required key for `automatic_parallelization` was not specified.')
        spec.exit_code(211, 'ERROR_INVALID_INPUT_AUTOMATIC_PARALLELIZATION_UNRECOGNIZED_KEY',
            message='Unrecognized keys were specified for `automatic_parallelization`.')
        spec.exit_code(300, 'ERROR_UNRECOVERABLE_FAILURE',
            message='The calculation failed with an unidentified unrecoverable error.')
        spec.exit_code(310, 'ERROR_KNOWN_UNRECOVERABLE_FAILURE',
            message='The calculation failed with a known unrecoverable error.')
        spec.exit_code(320, 'ERROR_INITIALIZATION_CALCULATION_FAILED',
            message='The initialization calculation failed.')
        spec.exit_code(501, 'ERROR_IONIC_CONVERGENCE_REACHED_EXCEPT_IN_FINAL_SCF',
            message='Then ionic minimization cycle converged but the thresholds are exceeded in the final SCF.')
Example #9
0
    def define(cls, spec):
        super(VaspWorkChain, cls).define(spec)
        spec.input('code', valid_type=Code)
        spec.input('structure', valid_type=(get_data_class('structure'), get_data_class('cif')), required=True)
        spec.input('kpoints', valid_type=get_data_class('array.kpoints'), required=True)
        spec.input('potential_family', valid_type=get_data_class('str'), required=True)
        spec.input('potential_mapping', valid_type=get_data_class('dict'), required=True)
        spec.input('parameters', valid_type=get_data_class('dict'), required=True)
        spec.input('options', valid_type=get_data_class('dict'), required=True)
        spec.input('settings', valid_type=get_data_class('dict'), required=False)
        spec.input('wavecar', valid_type=get_data_class('vasp.wavefun'), required=False)
        spec.input('chgcar', valid_type=get_data_class('vasp.chargedensity'), required=False)
        spec.input('restart_folder',
                   valid_type=get_data_class('remote'),
                   required=False,
                   help="""
            The restart folder from a previous workchain run that is going to be used.
            """)
        spec.input('max_iterations',
                   valid_type=get_data_class('int'),
                   required=False,
                   default=lambda: get_data_node('int', 5),
                   help="""
            The maximum number of iterations to perform.
            """)
        spec.input('clean_workdir',
                   valid_type=get_data_class('bool'),
                   required=False,
                   default=lambda: get_data_node('bool', True),
                   help="""
            If True, clean the work dir upon the completion of a successfull calculation.
            """)
        spec.input('verbose',
                   valid_type=get_data_class('bool'),
                   required=False,
                   default=lambda: get_data_node('bool', False),
                   help="""
            If True, enable more detailed output during workchain execution.
            """)
        spec.input('dynamics.positions_dof',
                   valid_type=get_data_class('list'),
                   required=False,
                   help="""
            Site dependent flag for selective dynamics when performing relaxation
            """)

        spec.outline(
            cls.init_context,
            cls.init_inputs,
            while_(cls.run_calculations)(
                cls.init_calculation,
                cls.run_calculation,
                cls.verify_calculation
            ),
            cls.results,
            cls.finalize
        )  # yapf: disable

        spec.output('misc', valid_type=get_data_class('dict'))
        spec.output('remote_folder', valid_type=get_data_class('remote'))
        spec.output('retrieved', valid_type=get_data_class('folder'))
        spec.output('structure', valid_type=get_data_class('structure'), required=False)
        spec.output('kpoints', valid_type=get_data_class('array.kpoints'), required=False)
        spec.output('trajectory', valid_type=get_data_class('array.trajectory'), required=False)
        spec.output('chgcar', valid_type=get_data_class('vasp.chargedensity'), required=False)
        spec.output('wavecar', valid_type=get_data_class('vasp.wavefun'), required=False)
        spec.output('bands', valid_type=get_data_class('array.bands'), required=False)
        spec.output('forces', valid_type=get_data_class('array'), required=False)
        spec.output('stress', valid_type=get_data_class('array'), required=False)
        spec.output('dos', valid_type=get_data_class('array'), required=False)
        spec.output('occupancies', valid_type=get_data_class('array'), required=False)
        spec.output('energies', valid_type=get_data_class('array'), required=False)
        spec.output('projectors', valid_type=get_data_class('array'), required=False)
        spec.output('dielectrics', valid_type=get_data_class('array'), required=False)
        spec.output('born_charges', valid_type=get_data_class('array'), required=False)
        spec.output('hessian', valid_type=get_data_class('array'), required=False)
        spec.output('dynmat', valid_type=get_data_class('array'), required=False)
        spec.output('site_magnetization', valid_type=get_data_class('dict'), required=False)
        spec.exit_code(0, 'NO_ERROR', message='the sun is shining')
        spec.exit_code(700, 'ERROR_NO_POTENTIAL_FAMILY_NAME', message='the user did not supply a potential family name')
        spec.exit_code(701, 'ERROR_POTENTIAL_VALUE_ERROR', message='ValueError was returned from get_potcars_from_structure')
        spec.exit_code(702, 'ERROR_POTENTIAL_DO_NOT_EXIST', message='the potential does not exist')
        spec.exit_code(703, 'ERROR_IN_PARAMETER_MASSAGER', message='the exception: {exception} was thrown while massaging the parameters')
Example #10
0
    def define(cls, spec):
        super().define(spec)

        spec.expose_inputs(Cp2kBaseWorkChain,
                           namespace='cp2k_base',
                           exclude=[
                               'cp2k.structure', 'cp2k.parameters',
                               'cp2k.metadata.options.parser_name'
                           ])
        spec.input('structure',
                   valid_type=StructureData,
                   help='Input structure that contains the molecule.')
        spec.input('molecule',
                   valid_type=StructureData,
                   help='Input molecule in the unit cell of the structure.')
        spec.input(
            'protocol_tag',
            valid_type=Str,
            default=lambda: Str('standard'),
            required=False,
            help=
            'The tag of the protocol tag.yaml. NOTE: only the settings are read, stage is set to GEO_OPT.'
        )
        spec.input(
            'protocol_yaml',
            valid_type=SinglefileData,
            required=False,
            help=
            'Specify a custom yaml file. NOTE: only the settings are read, stage is set to GEO_OPT.'
        )
        spec.input(
            'protocol_modify',
            valid_type=Dict,
            default=lambda: Dict(dict={}),
            required=False,
            help='Specify custom settings that overvrite the yaml settings')
        spec.input(
            'starting_settings_idx',
            valid_type=Int,
            default=lambda: Int(0),
            required=False,
            help=
            'If idx>0 is chosen, jumps directly to overwrite settings_0 with settings_{idx}'
        )
        spec.input(
            'cp2k_base.cp2k.parameters',
            valid_type=Dict,
            required=False,
            help=
            'Specify custom CP2K settings to overwrite the input dictionary just before submitting the CalcJob'
        )

        # Workchain outline
        spec.outline(
            cls.setup,
            while_(cls.should_run_geo_opt)(
                cls.run_geo_opt,
                cls.inspect_and_update_settings_geo_opt,
            ),
            cls.run_bsse,
            cls.results,
        )

        # Exit codes
        spec.exit_code(
            901, 'ERROR_MISSING_INITIAL_SETTINGS',
            'Specified starting_settings_idx that is not existing, or any in between 0 and idx is missing'
        )
        spec.exit_code(
            902, 'ERROR_NO_MORE_SETTINGS',
            'Settings for Stage0 are not ok but there are no more robust settings to try'
        )
        spec.exit_code(
            903, 'ERROR_PARSING_OUTPUT',
            'Something important was not printed correctly and the parsing of the first calculation failed'
        )

        # Outputs
        spec.expose_outputs(Cp2kBaseWorkChain, include=['remote_folder'])
        spec.output('loaded_molecule',
                    valid_type=StructureData,
                    help='Molecule geometry in the unit cell.')
        spec.output('loaded_structure',
                    valid_type=StructureData,
                    help='Geometry of the system with both fragments.')
        spec.output('output_parameters',
                    valid_type=Dict,
                    help='Info regarding the binding energy of the system.')
Example #11
0
    def define(cls, spec):
        super().define(spec)
        spec.input('code', valid_type=orm.Code, help='The FLEUR code.')
        spec.input(
            'parent_folder',
            valid_type=orm.RemoteData,
            required=False,
            help=
            'An optional working directory of a previously completed calculation to '
            'restart from.')
        spec.input(
            'settings',
            valid_type=orm.Dict,
            required=False,
            help=
            'Optional parameters to affect the way the calculation job and the parsing'
            ' are performed.')
        spec.input('options',
                   valid_type=orm.Dict,
                   help='Optional parameters to set up computational details.')
        spec.input('fleurinpdata',
                   valid_type=FleurinpData,
                   help='Optional parameter set up a ready-to-use fleurinp.')
        spec.input('description',
                   valid_type=six.string_types,
                   required=False,
                   non_db=True,
                   help='Calculation description.')
        spec.input('label',
                   valid_type=six.string_types,
                   required=False,
                   non_db=True,
                   help='Calculation label.')
        spec.input(
            'only_even_MPI',
            valid_type=orm.Bool,
            default=lambda: orm.Bool(False),
            help=
            'Set to true if you want to suppress odd number of MPI processes in parallelisation.'
            'This might speedup a calculation for machines having even number of sockets per node.'
        )

        spec.outline(
            cls.setup,
            cls.validate_inputs,
            while_(cls.should_run_calculation)(
                cls.run_calculation,
                cls.inspect_calculation,
            ),
            cls.results,
        )

        spec.output('output_parameters', valid_type=orm.Dict, required=False)
        spec.output('output_params_complex',
                    valid_type=orm.Dict,
                    required=False)
        spec.output('relax_parameters', valid_type=orm.Dict, required=False)
        spec.output('retrieved', valid_type=orm.FolderData, required=False)
        spec.output('remote_folder', valid_type=orm.RemoteData, required=False)
        spec.output('final_calc_uuid', valid_type=orm.Str, required=False)

        spec.exit_code(
            311,
            'ERROR_VACUUM_SPILL_RELAX',
            message='FLEUR calculation failed because an atom spilled to the'
            'vacuum during relaxation')
        spec.exit_code(313,
                       'ERROR_MT_RADII_RELAX',
                       message='Overlapping MT-spheres during relaxation.')
        spec.exit_code(
            315,
            'ERROR_INVALID_ELEMENTS_MMPMAT',
            message='The LDA+U density matrix contains invalid elements.'
            ' Consider a less aggresive mixing scheme')
        spec.exit_code(389,
                       'ERROR_MEMORY_ISSUE_NO_SOLUTION',
                       message='Computational resources are not optimal.')
        spec.exit_code(390,
                       'ERROR_NOT_OPTIMAL_RESOURCES',
                       message='Computational resources are not optimal.')
        spec.exit_code(
            399,
            'ERROR_SOMETHING_WENT_WRONG',
            message=
            'FleurCalculation failed and FleurBaseWorkChain has no strategy '
            'to resolve this')
Example #12
0
    def define(cls, spec):
        super().define(spec)

        cls._iteration_inputs = {}

        # Define the outline of the workflow, i.e. the order in which methods are executed.
        # See this class' documentation for an extended version of it
        spec.outline(cls.initialize,
                     while_(cls.next_step)(
                         cls.run_batch,
                         cls.analyze_batch,
                     ), cls.return_results, cls.report_end)

        # Inputs that are general to all iterator workchains. They manage the iterator and batching.
        # More inputs can be defined in subclasses.
        if cls._iterate_over_port:
            spec.input(
                "iterate_over",
                valid_type=DataFactory('dict'),
                serializer=cls._iterate_input_serializer,
                help=
                '''A dictionary where each key is the name of a parameter we want to iterate
                over (str) and each value is a list with all the values to iterate over for
                that parameter. Each value in the list can be either a node (unstored or stored)
                or a simple python object (str, float, int, bool).
                Note that each subclass might parse this keys and values differently, so you should
                know how they do it.
                ''')

        spec.input("iterate_mode",
                   valid_type=Str,
                   default=lambda: Str('zip'),
                   help='''Indicates the way the parameters should be iterated.
            Currently allowed values are:
            - 'zip': zips all the parameters together (all parameters should
              have the same number of values!)
            - 'product': performs a cartesian product of the parameters. That is,
              all possible combinations of parameters and values are explored.
            ''')
        spec.input(
            "batch_size",
            valid_type=Int,
            default=lambda: Int(1),
            help=
            '''The maximum number of simulations that should run at the same time.
            You can set this to a very large number to make sure that all simulations run in
            one single batch if you want.''')

        # We expose the inputs of the _process_class, in addition some more args
        # can be passed to the expose_inputs method (for instance inputs to exclude)
        spec.expose_inputs(cls._process_class, **cls._expose_inputs_kwargs)

        # Make the inputs that we have exposed not required (since if you iterate over,
        # them you might not pass them directly) and save them in a variable.
        if "namespace" in cls._expose_inputs_kwargs:
            cls._exposed_input_keys = spec._exposed_inputs[
                cls._expose_inputs_kwargs["namespace"]][cls._process_class]
            if cls._iterate_over_port:
                for input_key in cls._exposed_input_keys:
                    spec.inputs._ports[cls._expose_inputs_kwargs["namespace"]][
                        input_key].required = False
        else:
            cls._exposed_input_keys = spec._exposed_inputs[None][
                cls._process_class]
            if cls._iterate_over_port:
                for input_key in cls._exposed_input_keys:
                    spec.inputs._ports[input_key].required = False
Example #13
0
    def define(cls, spec):
        super(IsothermWorkChain, cls).define(spec)

        spec.expose_inputs(ZeoppCalculation,
                           namespace='zeopp',
                           include=['code', 'metadata'])

        spec.expose_inputs(RaspaBaseWorkChain,
                           namespace='raspa_base',
                           exclude=['raspa.structure', 'raspa.parameters'])

        spec.input('structure',
                   valid_type=CifData,
                   help='Adsorbent framework CIF.')

        spec.input(
            "molecule",
            valid_type=(Str, Dict),
            help='Adsorbate molecule: settings to be read from the yaml.' +
            'Advanced: input a Dict for non-standard settings.')

        spec.input(
            "parameters",
            valid_type=Dict,
            help=
            'Parameters for the Isotherm workchain: will be merged with IsothermParameters_defaults.'
        )

        spec.input(
            "geometric",
            valid_type=Dict,
            required=False,
            help=
            '[Only used by IsothermMultiTempWorkChain] Already computed geometric properties'
        )

        spec.outline(
            cls.setup,
            cls.run_zeopp,  # computes volpo and blocks
            if_(cls.should_run_widom)(  # run Widom only if porous
                cls.run_raspa_widom,  # run raspa widom calculation
                if_(cls.should_run_gcmc)(  # Kh is high enough
                    cls.init_raspa_gcmc,  # initializate setting for GCMC
                    while_(cls.should_run_another_gcmc)(  # new pressure
                        cls.run_raspa_gcmc,  # run raspa GCMC calculation
                    ),
                ),
            ),
            cls.return_output_parameters,
        )

        spec.expose_outputs(ZeoppCalculation,
                            include=['block'])  #only if porous

        spec.output(
            'output_parameters',
            valid_type=Dict,
            required=True,
            help=
            'Results of the single temperature wc: keys can vay depending on is_porous and is_kh_enough booleans.'
        )
Example #14
0
    def define(cls, spec):
        super(PwContactFieldWorkChain, cls).define(spec)

        spec.expose_inputs(PpCalculation,
                           namespace='pp',
                           exclude=('parent_folder', 'parameters'))
        spec.expose_inputs(PjwfcCalculation,
                           namespace='projwfc',
                           exclude=('parent_folder', 'parameters'))

        #         spec.expose_inputs(PwBaseWorkChain, namespace='scf', exclude=('clean_workdir', 'pw.structure'))
        #         spec.input('equiv_sites', valid_type=orm.List, required=False, validator=validate_scale_factors, help='the list of muon equiv site.')
        #         spec.input('equiv_sites', valid_type=orm.List, help='the list of muon equiv site.')
        #         spec.input('structures', valid_type=orm.Dict, help='a dictionary of structures to use')
        #         spec.input('structure', valid_type=orm.StructureData, help='The pristine supercell pymatgen structure')
        #         spec.input('equiv_sites', valid_type=orm.ArrayData, help='the list of muon equiv site.')

        spec.input('equiv_sites',
                   valid_type=orm.Dict,
                   help='a dictionary of structures to use')
        """
        # equiv_sites contains a collection of nth dictionary  (of equivalent muon sites) 
        # each contains a lattice parameters (3x3 matrix), a list of species and nd.arrayx3 
        # of ion positions. Why do that?
        # parsing a dict of pymatgen structure is not JSON serializable
        # better if we create the structures using 'create_amatch_structure' along the way
        # by parsing the lattice, species and positions of ions (including the muon in) in 
        # `create_amatch_structure(lattice, species, positions)` function
        """
        spec.input('equiv_count',
                   valid_type=orm.Int,
                   default=lambda: orm.Int(1),
                   help='number of structures to use')
        spec.input('parent_folder', valid_type=orm.RemoteData)

        spec.input('meta_convergence',
                   valid_type=orm.Bool,
                   default=lambda: orm.Bool(True))
        #spec.input('meta_convergence', valid_type=orm.Bool, default=lambda: orm.Bool(False))
        spec.input('max_meta_convergence_iterations',
                   valid_type=orm.Int,
                   default=lambda: orm.Int(5))
        spec.input('contact_field_convergence',
                   valid_type=orm.Float,
                   default=lambda: orm.Float(0.1))
        spec.input('clean_workdir',
                   valid_type=orm.Bool,
                   default=lambda: orm.Bool(False))

        spec.outline(
            cls.setup_init,
            while_(cls.should_refine_contact_field)(
                cls.run_init_scf,
                cls.inspect_init_scf,
                cls.run_pp_up,
                cls.run_pp_dn,
                cls.inspect_pp,
            ),
            cls.run_projwfc,
            cls.results,
            if_(cls.equiv_site_is_greater_than_one)(
                cls.next_workchain,
                while_(cls.run_next_workchain)(
                    cls.setup_next_workchain,
                    while_(cls.should_refine_contact_field)(
                        cls.scf_next_workchain,
                        cls.inspect_scf_next_workchain,
                        cls.run_pp_up,
                        cls.run_pp_dn,
                        cls.inspect_pp,
                    ),
                    cls.extract_contact_field_and_structure,
                    #check if all struct done!
                    cls.final_calc,
                ),
                cls.finalize,
            ),
        )

        spec.exit_code(0,
                       'NO_ERROR',
                       message='done with calculations, everything works!')
        spec.exit_code(
            400,
            'ERROR_SUB_PROCESS_FAILED_SCF',
            message=
            'the scf PwBasexWorkChain sub processes did not finish successfully.'
        )
        spec.exit_code(401,
                       'ERROR_SUB_PROCESS_FAILED_RELAX',
                       message='the relax PwBaseWorkChain sub process failed')
        spec.exit_code(
            402,
            'ERROR_SUB_PROCESS_FAILED_FINAL_SCF',
            message='the final scf PwBaseWorkChain sub process failed')
        #spec.expose_outputs(PwBaseWorkChain)

        spec.output('contact_field',
                    valid_type=orm.Float,
                    help='The contact field in Tesla at each calculations.')

        #         spec.output('structure_contact_field_dict', valid_type=DataFactory('array'),
        #                     help='The list containing all the contact field and structures')
        #         spec.output('structure_contact_field_dict', valid_type=orm.Dict,
        #                     help='A dictionary containing all the contact field and structures')

        spec.output(
            'contact_field_dict',
            valid_type=orm.Dict,
            help=
            'A dictionary containing all the contact field for each structure')
        spec.output(
            'structure_positions',
            valid_type=DataFactory('array'),
            help=
            'a list containing the nuclei positions (with mu) for each structures'
        )

        spec.expose_outputs(PjwfcCalculation, namespace='projwfc')
        spec.expose_outputs(PwCalculation, namespace='pw')
Example #15
0
    def define(cls, spec):
        """Workfunction definition

        """
        super(YamboConvergence, cls).define(spec)

        spec.expose_inputs(YamboWorkflow, namespace='ywfl', namespace_options={'required': True}, \
                            exclude = ('scf.kpoints', 'nscf.kpoints','parent_folder'))

        spec.expose_inputs(YamboWorkflow, namespace='p2y', namespace_options={'required': True}, \
                            exclude = ('scf.kpoints', 'nscf.kpoints','parent_folder'))

        spec.expose_inputs(YamboWorkflow, namespace='precalc', namespace_options={'required': False}, \
                    exclude = ('scf.kpoints', 'nscf.kpoints','parent_folder'))

        spec.input('kpoints', valid_type=KpointsData, required=True)
        spec.input('parent_folder', valid_type=RemoteData, required=False)

        spec.input("parameters_space", valid_type=List, required=True, \
                    help = 'variables to converge, range, steps, and max iterations')
        spec.input("workflow_settings", valid_type=Dict, required=True, \
                    help = 'settings for the workflow: type, quantity to be examinated...')

        ##################################### OUTLINE ####################################

        spec.outline(
            cls.start_workflow,
            if_(cls.p2y_needed)(
                cls.do_p2y,
                cls.prepare_calculations,
            ),
            if_(cls.precalc_needed)(
                cls.do_precalc,
                cls.post_processing,
            ),
            while_(cls.has_to_continue)(cls.next_step, cls.data_analysis),
            cls.report_wf,
        )

        ##################################################################################

        spec.output('history', valid_type=Dict, help='all calculations')
        spec.output('last_calculation',
                    valid_type=Dict,
                    help='final useful calculation')
        spec.output('last_calculation_remote_folder', valid_type = RemoteData, required = False, \
                                                      help='final remote folder')

        spec.exit_code(300,
                       'UNDEFINED_STATE',
                       message='The workchain is in an undefined state.')
        spec.exit_code(301,
                       'P2Y_FAILED',
                       message='The workchain failed the p2y step.')
        spec.exit_code(302,
                       'PRECALC_FAILED',
                       message='The workchain failed the precalc step.')
        spec.exit_code(303,
                       'CALCs_FAILED',
                       message='The workchain failed some calculations.')
        spec.exit_code(400,
                       'CONVERGENCE_NOT_REACHED',
                       message='The workchain failed to reach convergence.')
Example #16
0
    def define(cls, spec):
        """Define this workchain"""
        super(CastepBaseWorkChain, cls).define(spec)

        # The inputs
        spec.input('max_iterations',
                   valid_type=orm.Int,
                   default=lambda: orm.Int(10),
                   serializer=to_aiida_type,
                   help='Maximum number of restarts')
        spec.input(
            'reuse_folder',
            valid_type=orm.RemoteData,
            help=
            'Use a remote folder as the parent folder. Useful for restarts.',
            required=False)
        spec.input(
            'continuation_folder',
            valid_type=orm.RemoteData,
            help=
            'Use a remote folder as the parent folder. Useful for restarts.',
            required=False)
        spec.input('pseudos_family',
                   valid_type=orm.Str,
                   serializer=to_aiida_type,
                   required=False,
                   help='Pseudopotential family to be used')
        spec.input('kpoints_spacing',
                   valid_type=orm.Float,
                   required=False,
                   serializer=to_aiida_type,
                   help="Kpoint spacing")
        spec.input('ensure_gamma_centering',
                   valid_type=orm.Bool,
                   serializer=to_aiida_type,
                   required=False,
                   help='Ensure the kpoint grid is gamma centred.')
        spec.input(
            'options',
            valid_type=orm.Dict,
            serializer=to_aiida_type,
            required=False,
            help=('Options specific to the workchain.'
                  'Avaliable options: queue_wallclock_limit, use_castep_bin'))
        spec.input(
            'calc_options',
            valid_type=orm.Dict,
            serializer=to_aiida_type,
            required=False,
            help="Options to be passed to calculations's metadata.options")
        spec.input(
            'clean_workdir',
            valid_type=orm.Bool,
            serializer=to_aiida_type,
            required=False,
            help=
            'Wether to clean the workdir of the calculations or not, the default is not clean.'
        )
        spec.expose_inputs(cls._calculation_class, namespace='calc')
        # Ensure this port is not required
        spec.input(
            'calc.metadata.options.resources',
            valid_type=dict,
            required=False,
            help=
            'Set the dictionary of resources to be used by the scheduler plugin, like the number of nodes, '
            'cpus etc. This dictionary is scheduler-plugin dependent. Look at the documentation of the '
            'scheduler for more details.')
        spec.input('calc.parameters',
                   valid_type=orm.Dict,
                   serializer=to_aiida_type,
                   help='Input parameters, flat format is allowed.',
                   validator=flat_input_param_validator)

        spec.output('output_array', valid_type=orm.ArrayData, required=False)
        spec.output('output_trajectory',
                    valid_type=orm.ArrayData,
                    required=False)
        spec.output('output_bands', valid_type=orm.BandsData, required=True)
        spec.output('output_structure',
                    valid_type=orm.StructureData,
                    required=False)
        spec.output('output_parameters', valid_type=orm.Dict, required=True)
        spec.output('remote_folder', valid_type=orm.RemoteData)

        # Define the exit codes
        spec.exit_code(900, 'ERROR_INVALID_INPUTS', 'Input validate is failed')
        spec.exit_code(
            201, 'ERROR_TOTAL_WALLCLOCK_EXCEEDED',
            'The maximum length of the wallclocks has been exceeded')
        spec.exit_code(200, 'ERROR_MAXIMUM_ITERATIONS_EXCEEDED',
                       'The maximum number of iterations has been exceeded')
        spec.exit_code(301, 'ERROR_CASTEP_FAILURE',
                       'CASTEP generated error files and is not recoverable')
        spec.exit_code(302, 'ERROR_SCF_FAILURE',
                       'Cannot reach SCF convergence despite restart efforts')
        spec.exit_code(
            400, 'USER_REQUESTED_STOP',
            'The stop flag has been put in the .param file to request termination of the calculation.'
        )
        spec.exit_code(1000, 'UNKOWN_ERROR', 'Error is not known')
        spec.exit_code(
            901, 'ERROR_ITERATION_RETURNED_NO_CALCULATION',
            'Completed one iteration but found not calculation returned')

        # Outline of the calculation
        spec.outline(
            cls.setup,
            cls.validate_inputs,
            if_(cls.should_dry_run)(
                cls.validate_dryrun_inputs,
                cls.run_dry_run,
                cls.inspect_dryrun,
            ),
            while_(cls.should_run_calculation)(
                cls.prepare_calculation,
                cls.run_calculation,
                cls.inspect_calculation,
            ),
            cls.results,
        )
Example #17
0
    def define(cls, spec: CalcJobProcessSpec):

        super(CryMainBaseWorkChain, cls).define(spec)
        spec.expose_inputs(CryCalculation, namespace=cls._calc_namespace, exclude=())
        spec.input(
            "{}.metadata.options.resources".format(cls._calc_namespace),
            valid_type=dict,
            required=False,
        )
        spec.input(
            "basis_family",
            valid_type=orm.Str,
            required=False,
            serializer=to_aiida_type,
            help=(
                "An alternative to specifying the basis sets manually: "
                "one can specify the name of an existing basis set family "
                "and the work chain will generate the basis sets automatically "
                "based on the input structure."
            ),
        )
        spec.input(
            "kpoints_distance",
            valid_type=orm.Float,
            required=False,
            serializer=to_aiida_type,
            validator=_validate_kpoint_distance,
            help=(
                "The minimum desired distance in 1/Å between k-points "
                "in reciprocal space. "
                "The explicit k-points will be generated automatically "
                "by the input structure, and "
                "will replace the SHRINK IS value in the input parameters."
                "Note: This methods assumes "
                "the PRIMITIVE unit cell is provided"
            ),
        )
        spec.input(
            "kpoints_force_parity",
            valid_type=orm.Bool,
            required=False,
            serializer=to_aiida_type,
            help=(
                "Optional input when constructing the k-points based "
                "on a desired `kpoints_distance`. "
                "Setting this to `True` will force the k-point mesh "
                "to have an even number of points along each lattice vector "
                "except for any non-periodic directions."
            ),
        )

        # TODO include option for symmetry calculation
        spec.outline(
            cls.setup,
            cls.validate_parameters,
            cls.validate_basis_sets,
            cls.validate_resources,
            while_(cls.should_run_process)(
                cls.prepare_calculation,
                cls.run_process,
                cls.inspect_process,
            ),
            cls.results,
        )

        spec.expose_outputs(CryCalculation, exclude=("retrieved", "optimisation"))

        spec.exit_code(
            201,
            "ERROR_INVALID_INPUT_PARAMETERS",
            message=(
                "The parameters could not be validated " "against the jsonschema."
            ),
        )
        spec.exit_code(
            202,
            "ERROR_INVALID_INPUT_BASIS_SETS",
            message=(
                "The explicit `basis_sets` or `basis_family` "
                "could not be used to get the necessary basis sets."
            ),
        )
        spec.exit_code(
            204,
            "ERROR_INVALID_INPUT_RESOURCES_UNDERSPECIFIED",
            message=(
                "The `metadata.options` did not specify both "
                "`resources.num_machines` and `max_wallclock_seconds`."
            ),
        )
        spec.exit_code(
            300,
            "ERROR_UNRECOVERABLE_FAILURE",
            message="The calculation failed with an unrecoverable error.",
        )
        spec.exit_code(
            320,
            "ERROR_INITIALIZATION_CALCULATION_FAILED",
            message="The initialization calculation failed.",
        )
Example #18
0
    def define(cls, spec):
        # yapf: disable
        super().define(spec)

        # INPUTS ############################################################################
        spec.input('code', valid_type=orm.Code, help='The PWscf code.')

        spec.input(
            'structure', valid_type=orm.StructureData,
            help='The inputs structure.'
            )
        spec.input(
            'parent_folder', valid_type=orm.RemoteData,
            required=False,
            help='The remote data of a previously performed scf calculation.'
            )
        spec.input_namespace(
            'pseudos', valid_type=orm.UpfData,
            dynamic=True,
            help='A mapping of `UpfData` nodes onto the kind name to which they should apply.'
            )
        spec.input(
            'clean_workdir', valid_type=orm.Bool,
            default=orm.Bool(False),
            help='If `True`, work directories of all called calculation will be cleaned at the end of execution.'
            )

        spec.expose_inputs(
            PwBaseWorkChain, namespace='scf',
            exclude=('clean_workdir', 'pw.structure', 'pw.code', 'pw.pseudos'),
            namespace_options={
                'required': False, 'populate_defaults': False,
                'help': 'Inputs for the `PwBaseWorkChain` for the BANDS calculation.'
            })

        spec.expose_inputs(
            PwBaseWorkChain, namespace='bands',
            exclude=('clean_workdir', 'pw.structure', 'pw.code', 'pw.pseudos', 'pw.parent_folder'),
            namespace_options={
                'required': True, 'populate_defaults': False,
                'help': 'Inputs for the `PwBaseWorkChain` for the BANDS calculation.'
            })

        spec.input('crossings',
                   valid_type=orm.ArrayData,
                   help='Starting crossings to refine.')
        spec.input(
            'step_size',
            valid_type=orm.Float,
            default=orm.Float(1.E-4),
            help='Distance between center point and edges of the cross.')
        spec.input(
            'gap_threshold',
            valid_type=orm.Float,
            default=orm.Float(0.0005),
            help=
            'kpoints with gap < `gap_threshold` are considered possible crossings.'
        )

        # OUTLINE ############################################################################
        spec.outline(
            cls.setup,
            if_(cls.do_scf)(
                cls.setup_scf,
                cls.run_scf,
                cls.inspect_scf
            ).else_(
                cls.setup_remote
                ),
            while_(cls.do_loop)(
                cls.setup_kpt,
                cls.setup_bands,
                cls.run_bands,
                cls.inspect_bands,
                cls.analyze_bands
                ),
            cls.results)

        # OUTPUTS ############################################################################
        spec.output(
            'scf_remote_folder',
            valid_type=orm.RemoteData,
            required=False,
            help='The remote data produced by the `scf` calculation.'
        )
        spec.output(
            'crossings',
            valid_type=orm.ArrayData,
            required=True,
            help='The array containing a list of bands crossing found as rows.'
        )

        # ERRORS ############################################################################
        spec.exit_code(322,
                       'ERROR_SUB_PROCESS_FAILED_SCF',
                       message='the bands PwBaseWorkChain sub process failed')
        spec.exit_code(332,
                       'ERROR_SUB_PROCESS_FAILED_BANDS',
                       message='the bands PwBaseWorkChain sub process failed')
Example #19
0
    def define(cls, spec):
        super().define(spec)
        spec.input('structure', valid_type=StructureData)
        spec.input('phonon_settings', valid_type=Dict)
        spec.input('symmetry_tolerance',
                   valid_type=Float,
                   default=lambda: Float(1e-5))
        spec.input('dry_run', valid_type=Bool, default=lambda: Bool(False))
        spec.input('subtract_residual_forces',
                   valid_type=Bool,
                   default=lambda: Bool(False))
        spec.input('run_phonopy', valid_type=Bool, default=lambda: Bool(False))
        spec.input('remote_phonopy',
                   valid_type=Bool,
                   default=lambda: Bool(False))
        spec.input('displacement_dataset', valid_type=Dict, required=False)
        spec.input('immigrant_calculation_folders',
                   valid_type=Dict,
                   required=False)
        spec.input('calculation_nodes', valid_type=Dict, required=False)
        spec.input('calculator_settings', valid_type=Dict, required=False)
        spec.input('code_string', valid_type=Str, required=False)
        spec.input('options', valid_type=Dict, required=False)

        spec.outline(
            cls.initialize,
            if_(cls.import_calculations)(
                if_(cls.import_calculations_from_files)(
                    while_(cls.continue_import)(
                        cls.read_force_calculations_from_files, ),
                    cls.read_nac_calculations_from_files,
                ),
                if_(cls.import_calculations_from_nodes)(
                    cls.read_calculation_data_from_nodes, ),
                cls.check_imported_structures,
            ).else_(cls.run_force_and_nac_calculations, ),
            if_(cls.dry_run)(cls.postprocess_of_dry_run, ).else_(
                cls.create_force_sets,
                if_(cls.is_nac)(cls.create_nac_params),
                if_(cls.run_phonopy)(if_(cls.remote_phonopy)(
                    cls.run_phonopy_remote,
                    cls.collect_data,
                ).else_(
                    cls.create_force_constants,
                    cls.run_phonopy_in_workchain,
                ), ),
            ),
            cls.finalize,
        )
        spec.output('force_constants', valid_type=ArrayData, required=False)
        spec.output('primitive', valid_type=StructureData, required=False)
        spec.output('supercell', valid_type=StructureData, required=False)
        spec.output('force_sets', valid_type=ArrayData, required=False)
        spec.output('supercell_forces', valid_type=ArrayData, required=False)
        spec.output('supercell_energy', valid_type=Float, required=False)
        spec.output('nac_params', valid_type=ArrayData, required=False)
        spec.output('thermal_properties', valid_type=XyData, required=False)
        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('phonon_setting_info', valid_type=Dict)
Example #20
0
    def define(cls, spec):
        super().define(spec)

        # Inputs
        spec.expose_inputs(Cp2kBaseWorkChain,
                           namespace='cp2k_base',
                           exclude=[
                               'cp2k.structure', 'cp2k.parameters',
                               'cp2k.metadata.options.parser_name'
                           ])
        spec.input('structure',
                   valid_type=StructureData,
                   required=False,
                   help='Input structure')
        spec.input(
            'protocol_tag',
            valid_type=Str,
            default=lambda: Str('standard'),
            required=False,
            help=
            'The tag of the protocol to be read from {tag}.yaml unless protocol_yaml input is specified'
        )
        spec.input(
            'protocol_yaml',
            valid_type=SinglefileData,
            required=False,
            help=
            'Specify a custom yaml file with the multistage settings (and ignore protocol_tag)'
        )
        spec.input(
            'protocol_modify',
            valid_type=Dict,
            default=lambda: Dict(dict={}),
            required=False,
            help='Specify custom settings that overvrite the yaml settings')
        spec.input(
            'starting_settings_idx',
            valid_type=Int,
            default=lambda: Int(0),
            required=False,
            help=
            'If idx>0 is chosen, jumps directly to overwrite settings_0 with settings_{idx}'
        )
        spec.input(
            'min_cell_size',
            valid_type=Float,
            default=lambda: Float(0.0),
            required=False,
            help=
            'To avoid using k-points, extend the cell so that min(perp_width)>min_cell_size'
        )
        spec.input(
            'parent_calc_folder',
            valid_type=RemoteData,
            required=False,
            help=
            'Provide an initial parent folder that contains the wavefunction for restart'
        )
        spec.input(
            'cp2k_base.cp2k.parameters',
            valid_type=Dict,
            required=False,
            help=
            'Specify custom CP2K settings to overwrite the input dictionary just before submitting the CalcJob'
        )
        spec.input(
            'cp2k_base.cp2k.metadata.options.parser_name',
            valid_type=str,
            default='lsmo.cp2k_advanced_parser',
            non_db=True,
            help=
            'Parser of the calculation: the default is cp2k_advanced_parser to get the necessary info'
        )

        # Workchain outline
        spec.outline(
            cls.setup_multistage,
            while_(cls.should_run_stage0)(
                cls.run_stage,
                cls.inspect_and_update_settings_stage0,
            ),
            cls.inspect_and_update_stage,
            while_(cls.should_run_stage)(
                cls.run_stage,
                cls.inspect_and_update_stage,
            ),
            cls.results,
        )

        # Exit codes
        spec.exit_code(
            901, 'ERROR_MISSING_INITIAL_SETTINGS',
            'Specified starting_settings_idx that is not existing, or any in between 0 and idx is missing'
        )
        spec.exit_code(
            902, 'ERROR_NO_MORE_SETTINGS',
            'Settings for Stage0 are not ok but there are no more robust settings to try'
        )
        spec.exit_code(
            903, 'ERROR_PARSING_OUTPUT',
            'Something important was not printed correctly and the parsing of the first calculation failed'
        )

        # Outputs
        spec.expose_outputs(Cp2kBaseWorkChain, include=['remote_folder'])
        spec.output(
            'output_structure',
            valid_type=StructureData,
            required=False,
            help=
            'Processed structure (missing if only ENERGY calculation is performed)'
        )
        spec.output(
            'last_input_parameters',
            valid_type=Dict,
            required=False,
            help=
            'CP2K input parameters used (and possibly working) used in the last stage'
        )
        spec.output(
            'output_parameters',
            valid_type=Dict,
            required=False,
            help='Output CP2K parameters of all the stages, merged together')
Example #21
0
    def define(cls, spec):
        super().define(spec)
        spec.input('code', valid_type=orm.Code, help='The FLEUR code.')
        spec.input(
            'parent_folder',
            valid_type=orm.RemoteData,
            required=False,
            help=
            'An optional working directory of a previously completed calculation to '
            'restart from.')
        spec.input(
            'settings',
            valid_type=orm.Dict,
            required=False,
            help=
            'Optional parameters to affect the way the calculation job and the parsing'
            ' are performed.')
        spec.input('options',
                   valid_type=orm.Dict,
                   help='Optional parameters to set up computational details.')
        spec.input('fleurinpdata',
                   valid_type=FleurinpData,
                   help='Optional parameter set up a ready-to-use fleurinp.')
        spec.input('description',
                   valid_type=six.string_types,
                   required=False,
                   non_db=True,
                   help='Calculation description.')
        spec.input('label',
                   valid_type=six.string_types,
                   required=False,
                   non_db=True,
                   help='Calculation label.')
        spec.input(
            'add_comp_para',
            valid_type=orm.Dict,
            default=lambda: orm.Dict(
                dict={
                    'only_even_MPI': False,
                    'max_queue_nodes': 20,
                    'max_queue_wallclock_sec': 86400
                }),
            help='Gives additional control over computational parameters'
            'only_even_MPI: set to true if you want to suppress odd number of MPI processes in parallelisation.'
            'This might speedup a calculation for machines having even number of sockets per node.'
            'max_queue_nodes: maximal number of nodes allowed on the remote machine. Used only to automatically solve some FLEUR failures.'
            'max_queue_wallclock_sec: maximal wallclock time allowed on the remote machine. Used only to automatically solve some FLEUR failures.'
        )

        spec.outline(
            cls.setup,
            cls.validate_inputs,
            while_(cls.should_run_calculation)(
                cls.run_calculation,
                cls.inspect_calculation,
            ),
            cls.results,
        )

        spec.output('output_parameters', valid_type=orm.Dict, required=False)
        spec.output('output_params_complex',
                    valid_type=orm.Dict,
                    required=False)
        spec.output('relax_parameters', valid_type=orm.Dict, required=False)
        spec.output('retrieved', valid_type=orm.FolderData, required=False)
        spec.output('remote_folder', valid_type=orm.RemoteData, required=False)
        spec.output('final_calc_uuid', valid_type=orm.Str, required=False)

        spec.exit_code(
            311,
            'ERROR_VACUUM_SPILL_RELAX',
            message='FLEUR calculation failed because an atom spilled to the'
            'vacuum during relaxation')
        spec.exit_code(313,
                       'ERROR_MT_RADII_RELAX',
                       message='Overlapping MT-spheres during relaxation.')
        spec.exit_code(389,
                       'ERROR_MEMORY_ISSUE_NO_SOLUTION',
                       message='Computational resources are not optimal.')
        spec.exit_code(390,
                       'ERROR_NOT_OPTIMAL_RESOURCES',
                       message='Computational resources are not optimal.')
        spec.exit_code(
            399,
            'ERROR_SOMETHING_WENT_WRONG',
            message=
            'FleurCalculation failed and FleurBaseWorkChain has no strategy '
            'to resolve this')