コード例 #1
0
    def _submit_pw_calc(self,
                        structure,
                        label,
                        runtype,
                        precision,
                        min_kpoints,
                        wallhours=24,
                        parent_folder=None):
        self.report("Running pw.x for " + label)

        inputs = {}
        inputs['_label'] = label
        inputs['code'] = self.inputs.pw_code
        inputs['structure'] = structure
        inputs['parameters'] = self._get_parameters(structure, runtype)
        inputs['pseudo'] = self._get_pseudos(structure,
                                             family_name="SSSP_modified")
        if parent_folder:
            inputs['parent_folder'] = parent_folder

        # kpoints
        cell_a = inputs['structure'].cell[0][0]
        precision *= self.inputs.precision.value
        nkpoints = max(min_kpoints, int(30 * 2.5 / cell_a * precision))
        use_symmetry = runtype != "bands"
        kpoints = self._get_kpoints(nkpoints, use_symmetry=use_symmetry)
        inputs['kpoints'] = kpoints

        # parallelization settings
        ## TEMPORARY double pools in case of spin
        spinpools = 1
        start_mag = self._get_magnetization(structure)
        if any([m != 0 for m in start_mag.values()]):
            spinpools = 2
        npools = min(spinpools + nkpoints / 5, 5)
        natoms = len(structure.sites)
        nnodes = (1 + natoms / 60) * npools
        inputs['_options'] = {
            "resources": {
                "num_machines": nnodes
            },
            "max_wallclock_seconds": wallhours * 60 * 60,  # hours
        }
        settings = {'cmdline': ["-npools", str(npools)]}

        if runtype == "bands":
            settings['also_bands'] = True  # instruction for output parser

        inputs['settings'] = ParameterData(dict=settings)

        #         self.report("precision %f"%precision)
        #         self.report("nkpoints %d"%nkpoints)
        #         self.report("npools %d"%npools)
        #         self.report("natoms %d"%natoms)
        #         self.report("nnodes %d"%nnodes)

        future = submit(PwCalculation.process(), **inputs)
        return ToContext(**{label: Calc(future)})
コード例 #2
0
def generate_scf_input_params(structure, codename, pseudo, element):
    # The inputs
    inputs = PwCalculation.process().get_inputs_template()

    # The structure
    inputs.structure = structure

    inputs.code = Code.get_from_string(codename)
    # calc.label = "PW test"
    # calc.description = "My first AiiDA calculation of Silicon with Quantum ESPRESSO"
    inputs._options.resources = {"num_machines": 1}
    inputs._options.max_wallclock_seconds = 23*30*60
    queue="compute"
    if queue is not None:
    	inputs._options.queue_name=queue

    # Kpoints
    KpointsData = DataFactory("array.kpoints")
    kpoints = KpointsData()
#    kpoints_mesh = 2
    kp=[0,0,0]

    f=open('/home/bosonie/AIMS/LDARESULTS/NonRelBirchLDAref', 'r')
    for line in f:
        a=line.split()
        if a[0]==element:
            kp[0]=int(a[1])
            kp[1]=int(a[3])
            kp[2]=int(a[5])
            vol=a[7]

    kpoints.set_kpoints_mesh([1,1,1])#[kp[0], kp[1], kp[2]])
    inputs.kpoints = kpoints

    # Calculation parameters
    parameters_dict = {
        "CONTROL": {"calculation": "scf",
                    "tstress": True,  #  Important that this stays to get stress
                    "tprnfor": True,
                    "disk_io": "none"},
        "SYSTEM": {"ecutwfc": 100.,
                   "ecutrho": 200.,
		   "smearing": "gauss",
		   "degauss": 0.000734986},
        "ELECTRONS": {"conv_thr": 1.e-6}
    }
    ParameterData = DataFactory("parameter")
    inputs.parameters = ParameterData(dict=parameters_dict)

    pseudos = {}
    pseudos[element] = pseudo
    inputs.pseudo = pseudos
    
    return inputs
コード例 #3
0
    def run_pw(self):
        print "Workchain node identifiers: {}".format(
            ProcessRegistry().current_calc_node)
        #Instantiate a JobCalc process and create basic structure
        JobCalc = PwCalculation.process()
        self.ctx.s0 = structure_init(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,
                                               str(self.inputs.element))
            print "Running a scf for {} with scale factor {}".format(
                self.inputs.element, factor)
            future = submit(JobCalc, **inputs)
            calcs[label] = Outputs(future)

        # Ask the workflow to continue when the results are ready and store them
        # in the context
        return ToContext(**calcs)  #Here it waits
コード例 #4
0
ファイル: neb.py プロジェクト: zooks97/aiida-quantumespresso
    def prepare_for_submission(self, folder):
        """Prepare the calculation job for submission by transforming input nodes into input files.

        In addition to the input files being written to the sandbox folder, a `CalcInfo` instance will be returned that
        contains lists of files that need to be copied to the remote machine before job submission, as well as file
        lists that are to be retrieved after job completion.

        :param folder: a sandbox folder to temporarily write files on disk.
        :return: :py:`~aiida.common.datastructures.CalcInfo` instance.
        """
        # pylint: disable=too-many-branches,too-many-statements
        import numpy as np

        local_copy_list = []
        remote_copy_list = []
        remote_symlink_list = []

        # Convert settings dictionary to have uppercase keys, or create an empty one if none was given.
        if 'settings' in self.inputs:
            settings_dict = _uppercase_dict(self.inputs.settings.get_dict(), dict_name='settings')
        else:
            settings_dict = {}

        first_structure = self.inputs.first_structure
        last_structure = self.inputs.last_structure

        # Check that the first and last image have the same cell
        if abs(np.array(first_structure.cell) - np.array(last_structure.cell)).max() > 1.e-4:
            raise InputValidationError('Different cell in the fist and last image')

        # Check that the first and last image have the same number of sites
        if len(first_structure.sites) != len(last_structure.sites):
            raise InputValidationError('Different number of sites in the fist and last image')

        # Check that sites in the initial and final structure have the same kinds
        if first_structure.get_site_kindnames() != last_structure.get_site_kindnames():
            raise InputValidationError(
                'Mismatch between the kind names and/or order between '
                'the first and final image'
            )

        # Check that a pseudo potential was specified for each kind present in the `StructureData`
        # self.inputs.pw.pseudos is a plumpy.utils.AttributesFrozendict
        kindnames = [kind.name for kind in first_structure.kinds]
        if set(kindnames) != set(self.inputs.pw.pseudos.keys()):
            raise InputValidationError(
                'Mismatch between the defined pseudos and the list of kinds of the structure.\nPseudos: {};\n'
                'Kinds: {}'.format(', '.join(list(self.inputs.pw.pseudos.keys())), ', '.join(list(kindnames)))
            )

        ##############################
        # END OF INITIAL INPUT CHECK #
        ##############################

        # Create the subfolder that will contain the pseudopotentials
        folder.get_subfolder(self._PSEUDO_SUBFOLDER, create=True)
        # Create the subfolder for the output data (sometimes Quantum ESPRESSO codes crash if the folder does not exist)
        folder.get_subfolder(self._OUTPUT_SUBFOLDER, create=True)

        # We first prepare the NEB-specific input file.
        neb_input_filecontent = self._generate_input_files(self.inputs.parameters, settings_dict)
        with folder.open(self.inputs.metadata.options.input_filename, 'w') as handle:
            handle.write(neb_input_filecontent)

        # We now generate the PW input files for each input structure
        local_copy_pseudo_list = []
        for i, structure in enumerate([first_structure, last_structure]):
            # We need to a pass a copy of the settings_dict for each structure
            this_settings_dict = copy.deepcopy(settings_dict)
            pw_input_filecontent, this_local_copy_pseudo_list = PwCalculation._generate_PWCPinputdata(  # pylint: disable=protected-access
                self.inputs.pw.parameters, this_settings_dict, self.inputs.pw.pseudos, structure, self.inputs.pw.kpoints
            )
            local_copy_pseudo_list += this_local_copy_pseudo_list
            with folder.open(f'pw_{i + 1}.in', 'w') as handle:
                handle.write(pw_input_filecontent)

        # We need to pop the settings that were used in the PW calculations
        for key in list(settings_dict.keys()):
            if key not in list(this_settings_dict.keys()):
                settings_dict.pop(key)

        # We avoid to copy twice the same pseudopotential to the same filename
        local_copy_pseudo_list = set(local_copy_pseudo_list)
        # We check that two different pseudopotentials are not copied
        # with the same name (otherwise the first is overwritten)
        if len({filename for (uuid, filename, local_path) in local_copy_pseudo_list}) < len(local_copy_pseudo_list):
            raise InputValidationError('Same filename for two different pseudopotentials')

        local_copy_list += local_copy_pseudo_list

        # If present, add also the Van der Waals table to the pseudo dir. Note that the name of the table is not checked
        # but should be the one expected by Quantum ESPRESSO.
        vdw_table = self.inputs.get('pw.vdw_table', None)
        if vdw_table:
            local_copy_list.append(
                (vdw_table.uuid, vdw_table.filename, os.path.join(self._PSEUDO_SUBFOLDER, vdw_table.filename))
            )

        # operations for restart
        parent_calc_folder = self.inputs.get('parent_folder', None)
        symlink = settings_dict.pop('PARENT_FOLDER_SYMLINK', self._default_symlink_usage)  # a boolean
        if symlink:
            if parent_calc_folder is not None:
                # I put the symlink to the old parent ./out folder
                remote_symlink_list.append((
                    parent_calc_folder.computer.uuid,
                    os.path.join(parent_calc_folder.get_remote_path(), self._OUTPUT_SUBFOLDER,
                                 '*'),  # asterisk: make individual symlinks for each file
                    self._OUTPUT_SUBFOLDER
                ))
                # and to the old parent prefix.path
                remote_symlink_list.append((
                    parent_calc_folder.computer.uuid,
                    os.path.join(parent_calc_folder.get_remote_path(), f'{self._PREFIX}.path'), f'{self._PREFIX}.path'
                ))
        else:
            # copy remote output dir and .path file, if specified
            if parent_calc_folder is not None:
                remote_copy_list.append((
                    parent_calc_folder.computer.uuid,
                    os.path.join(parent_calc_folder.get_remote_path(), self._OUTPUT_SUBFOLDER,
                                 '*'), self._OUTPUT_SUBFOLDER
                ))
                # and copy the old parent prefix.path
                remote_copy_list.append((
                    parent_calc_folder.computer.uuid,
                    os.path.join(parent_calc_folder.get_remote_path(), f'{self._PREFIX}.path'), f'{self._PREFIX}.path'
                ))

        # here we may create an aiida.EXIT file
        create_exit_file = settings_dict.pop('ONLY_INITIALIZATION', False)
        if create_exit_file:
            exit_filename = f'{self._PREFIX}.EXIT'
            with folder.open(exit_filename, 'w') as handle:
                handle.write('\n')

        calcinfo = CalcInfo()
        codeinfo = CodeInfo()

        calcinfo.uuid = self.uuid
        cmdline_params = settings_dict.pop('CMDLINE', [])
        calcinfo.local_copy_list = local_copy_list
        calcinfo.remote_copy_list = remote_copy_list
        calcinfo.remote_symlink_list = remote_symlink_list
        # In neb calculations there is no input read from standard input!!
        codeinfo.cmdline_params = (['-input_images', '2'] + list(cmdline_params))
        codeinfo.stdout_name = self.inputs.metadata.options.output_filename
        codeinfo.code_uuid = self.inputs.code.uuid
        calcinfo.codes_info = [codeinfo]

        # Retrieve the output files and the xml files
        calcinfo.retrieve_list = []
        calcinfo.retrieve_list.append(self.inputs.metadata.options.output_filename)
        calcinfo.retrieve_list.append((
            os.path.join(self._OUTPUT_SUBFOLDER, self._PREFIX + '_*[0-9]', 'PW.out'),  # source relative path (globbing)
            '.',  # destination relative path
            2  # depth to preserve
        ))

        for xml_filepath in self.xml_filepaths:  # pylint: disable=not-an-iterable
            calcinfo.retrieve_list.append([xml_filepath, '.', 3])

        calcinfo.retrieve_list += settings_dict.pop('ADDITIONAL_RETRIEVE_LIST', [])
        calcinfo.retrieve_list += self._internal_retrieve_list

        # We might still have parser options in the settings dictionary: pop them.
        _pop_parser_options(self, settings_dict)

        if settings_dict:
            unknown_keys = ', '.join(list(settings_dict.keys()))
            raise InputValidationError(f'`settings` contained unexpected keys: {unknown_keys}')

        return calcinfo
コード例 #5
0
ファイル: nscf_gw.py プロジェクト: yakutovicha/yambo-aiida
inputs['settings'] = ParameterData(dict={'cmdline': ['-nk', str(num_pools)]})

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(description='NSCF calculation.')
    parser.add_argument('--code',
                        type=str,
                        dest='codename',
                        required=True,
                        help='The pw codename to use')
    parser.add_argument('--pseudo',
                        type=str,
                        dest='pseudo',
                        required=True,
                        help='The pseudo family to use')
    parser.add_argument('--parent',
                        type=int,
                        dest='parent',
                        required=True,
                        help='The parent  to use')
    args = parser.parse_args()
    code = Code.get_from_string(args.codename)
    structure = load_node(args.parent).inp.structure
    inputs['structure'] = structure
    inputs['pseudo'] = get_pseudos_from_structure(structure, args.pseudo)
    inputs['code'] = code
    inputs['parent_folder'] = load_node(args.parent).out.remote_folder
    process = PwCalculation.process()
    running = submit(process, **inputs)
    print "Created calculation; with pid={}".format(running.pid)
コード例 #6
0
ファイル: old_wc.py プロジェクト: FermiQ/yambo-aiida
    def setUp(self):
        """
        """
        from aiida import work
        from aiida.orm.code import Code
        from aiida.orm.nodes.parameter import Dict
        from aiida.orm.nodes.structure import StructureData
        from aiida.orm.nodes.remote import RemoteData
        from ase.spacegroup import crystal
        from aiida_quantumespresso.calculations.pw import PwCalculation
        from aiida_yambo.calculations.gw import YamboCalculation
        from aiida.common.links import LinkType
        from aiida.orm.computer import Computer as AiidaOrmComputer
        from aiida.common.datastructures import calc_states
        from aiida.plugins.utils import DataFactory
        runner = work.Runner(poll_interval=0.,
                             rmq_config=None,
                             enable_persistence=None)
        work.set_runner(runner)
        self.computer = AiidaOrmComputer(name="testcase")
        # conf_attrs hostname, description, enabled_state, transport_type, scheduler_type,  workdir
        # mpirun_command , default_mpiprocs_per_machine,
        self.computer._set_hostname_string("localhost")
        self.computer._set_enabled_state_string('True')
        self.computer._set_transport_type_string("local")
        self.computer._set_scheduler_type_string("direct")
        self.computer._set_workdir_string("/tmp/testcase/{username}/base")
        self.computer.store()
        create_authinfo(computer=self.computer).store()
        self.code_yambo = Code()
        self.code_yambo.label = "yambo"
        os_env = os.environ.copy()
        yambo_path = subprocess.check_output(['which', 'mock_yambo'],
                                             env=os_env).strip()
        self.code_yambo.set_remote_computer_exec((self.computer, yambo_path))
        self.code_yambo.set_input_plugin_name('yambo.yambo')

        self.code_p2y = Code()
        self.code_p2y.label = "p2y"
        p2y_path = subprocess.check_output(['which', 'mock_p2y'],
                                           env=os_env).strip()
        self.code_p2y.set_remote_computer_exec((self.computer, p2y_path))
        self.code_p2y.set_input_plugin_name('yambo.yambo')
        self.code_yambo.store()
        self.code_p2y.store()

        self.calc_pw = PwCalculation()
        self.calc_pw.set_computer(self.computer)
        self.calc_pw.set_resources({
            "num_machines": 1,
            "num_mpiprocs_per_machine": 16,
            'default_mpiprocs_per_machine': 16
        })
        StructureData = DataFactory('structure')
        cell = [[15.8753100000, 0.0000000000, 0.0000000000],
                [0.0000000000, 15.8753100000, 0.0000000000],
                [0.0000000000, 0.0000000000, 2.4696584760]]
        s = StructureData(cell=cell)
        self.calc_pw.use_structure(s)
        print((self.calc_pw.store_all(), " pw calc"))
        pw_remote_folder = RemoteData(computer=self.computer,
                                      remote_path="/tmp/testcase/work/calcPW")
        print((pw_remote_folder.store(), "pw remote data"))
        self.calc_pw._set_state(calc_states.PARSING)
        pw_remote_folder.add_link_from(self.calc_pw,
                                       label='remote_folder',
                                       link_type=LinkType.CREATE)

        outputs = Dict(
            dict={
                "lsda": False,
                "number_of_bands": 80,
                "number_of_electrons": 8.0,
                "number_of_k_points": 147,
                "non_colinear_calculation": False
            })
        outputs.store()
        outputs.add_link_from(self.calc_pw,
                              label='output_parameters',
                              link_type=LinkType.CREATE)

        self.calc = YamboCalculation()
        self.calc.set_computer(self.computer)
        self.calc.use_code(self.code_p2y)
        p2y_settings = {
            u'ADDITIONAL_RETRIEVE_LIST':
            [u'r-*', u'o-*', u'l-*', u'l_*', u'LOG/l-*_CPU_1'],
            u'INITIALISE':
            True
        }
        yambo_settings = {
            u'ADDITIONAL_RETRIEVE_LIST':
            [u'r-*', u'o-*', u'l-*', u'l_*', u'LOG/l-*_CPU_1']
        }
        self.calc.use_settings(Dict(dict=p2y_settings))
        self.calc.set_resources({
            "num_machines": 1,
            "num_mpiprocs_per_machine": 16,
            'default_mpiprocs_per_machine': 16
        })
        self.calc.use_parent_calculation(self.calc_pw)
        print((self.calc.store_all(), " yambo calc"))
        self.calc._set_state(calc_states.PARSING)
        a = 5.388
        cell = crystal('Si', [(0, 0, 0)],
                       spacegroup=227,
                       cellpar=[a, a, a, 90, 90, 90],
                       primitive_cell=True)
        self.struc = StructureData(ase=cell)
        self.struc.store()
        self.parameters = Dict(
            dict={
                "BndsRnXp": [1.0, 48.0],
                "Chimod": "Hartree",
                "DysSolver": "n",
                "FFTGvecs": 25,
                "FFTGvecs_units": "Ry",
                "GbndRnge": [1.0, 48.0],
                "HF_and_locXC": True,
                "LongDrXp": [1.0, 0.0, 0.0],
                "NGsBlkXp": 2,
                "NGsBlkXp_units": "Ry",
                "QPkrange": [[1, 145, 3, 5]],
                "SE_CPU": "1 2 4",
                "SE_ROLEs": "q qp b",
                "X_all_q_CPU": "1 1 4 2",
                "X_all_q_ROLEs": "q k c v",
                "em1d": True,
                "gw0": True,
                "ppa": True,
                "rim_cut": True
            })
        self.yambo_settings = Dict(
            dict={
                "ADDITIONAL_RETRIEVE_LIST": [
                    "r-*", "o-*", "l-*", "l_*", "LOG/l-*_CPU_1",
                    "aiida/ndb.QP", "aiida/ndb.HF_and_locXC"
                ]
            })
        self.p2y_settings = Dict(
            dict={
                "ADDITIONAL_RETRIEVE_LIST": [
                    'r-*', 'o-*', 'l-*', 'l_*', 'LOG/l-*_CPU_1',
                    'aiida/ndb.QP', 'aiida/ndb.HF_and_locXC'
                ],
                'INITIALISE':
                True
            })
        self.yambo_calc_set = Dict(
            dict={
                'resources': {
                    "num_machines": 1,
                    "num_mpiprocs_per_machine": 16
                },
                'max_wallclock_seconds': 60 * 29,
                'max_memory_kb': 1 * 88 * 1000000,
                "queue_name":
                "s3parvc3",  #'custom_scheduler_commands': u"#PBS -A  Pra14_3622" ,
                'environment_variables': {
                    "OMP_NUM_THREADS": "1"
                }
            })
        self.p2y_calc_set = Dict(
            dict={
                'resources': {
                    "num_machines": 1,
                    "num_mpiprocs_per_machine": 2
                },
                'max_wallclock_seconds': 60 * 2,
                'max_memory_kb': 1 * 10 * 1000000,
                "queue_name":
                "s3parvc3",  # 'custom_scheduler_commands': u"#PBS -A  Pra14_3622" ,
                'environment_variables': {
                    "OMP_NUM_THREADS": "2"
                }
            })
        self.remote_folder = RemoteData(computer=self.computer,
                                        remote_path="/tmp/testcase/work/calcX")
        self.remote_folder.store()
        self.remote_folder.add_link_from(self.calc,
                                         label='remote_folder',
                                         link_type=LinkType.CREATE)
        self.calc._set_state(calc_states.FINISHED)