示例#1
0
    def prepare_for_submission(self, folder):

        # create code info
        codeinfo = CodeInfo()
        codeinfo.code_uuid = self.inputs.code.uuid
        codeinfo.cmdline_params = [
            self.PARENT_FOLDER_NAME + "/" + self.inputs.chk_name.value, self.DEFAULT_OUTPUT_FILE
        ]
        codeinfo.withmpi = self.inputs.metadata.options.withmpi

        # create calculation info
        calcinfo = CalcInfo()
        calcinfo.uuid = self.uuid
        calcinfo.codes_info = [codeinfo]
        calcinfo.retrieve_list = []

        if self.inputs.retrieve_fchk:
            calcinfo.retrieve_list.append(self.DEFAULT_OUTPUT_FILE)

        # symlink or copy to parent calculation
        calcinfo.remote_symlink_list = []
        calcinfo.remote_copy_list = []
        comp_uuid = self.inputs.parent_calc_folder.computer.uuid
        remote_path = self.inputs.parent_calc_folder.get_remote_path()
        copy_info = (comp_uuid, remote_path, self.PARENT_FOLDER_NAME)
        if self.inputs.code.computer.uuid == comp_uuid:  # if running on the same computer - make a symlink
            # if not - copy the folder
            calcinfo.remote_symlink_list.append(copy_info)
        else:
            calcinfo.remote_copy_list.append(copy_info)

        return calcinfo
示例#2
0
    def prepare_for_submission(self, folder):
        """
        This is the routine to be called when you want to create
        the input files and related stuff with a plugin.

        :param folder: a aiida.common.folders.Folder subclass where
                           the plugin should put all its files.
        """

        if 'structure' in self.inputs:
            pmg_structure = self.inputs.structure.get_pymatgen_molecule()
        else:
            # If structure is not specified, it is read from the chk file
            pmg_structure = None

        # Generate the input file
        input_string = GaussianCalculation._render_input_string_from_params(
            self.inputs.parameters.get_dict(), pmg_structure)

        with open(folder.get_abs_path(self.INPUT_FILE), "w") as out_file:
            out_file.write(input_string)

        settings = self.inputs.settings.get_dict(
        ) if "settings" in self.inputs else {}

        # create code info
        codeinfo = CodeInfo()
        codeinfo.cmdline_params = settings.pop("cmdline", [])
        codeinfo.code_uuid = self.inputs.code.uuid
        codeinfo.stdin_name = self.INPUT_FILE
        codeinfo.stdout_name = self.OUTPUT_FILE
        codeinfo.withmpi = self.inputs.metadata.options.withmpi

        # create calculation info
        calcinfo = CalcInfo()
        calcinfo.remote_copy_list = []
        calcinfo.local_copy_list = []
        calcinfo.uuid = self.uuid
        calcinfo.cmdline_params = codeinfo.cmdline_params
        calcinfo.stdin_name = self.INPUT_FILE
        calcinfo.stdout_name = self.OUTPUT_FILE
        calcinfo.codes_info = [codeinfo]
        calcinfo.retrieve_list = [self.OUTPUT_FILE]

        # symlink or copy to parent calculation
        calcinfo.remote_symlink_list = []
        calcinfo.remote_copy_list = []
        if "parent_calc_folder" in self.inputs:
            comp_uuid = self.inputs.parent_calc_folder.computer.uuid
            remote_path = self.inputs.parent_calc_folder.get_remote_path()
            copy_info = (comp_uuid, remote_path, self.PARENT_FOLDER_NAME)
            if (self.inputs.code.computer.uuid == comp_uuid):
                # if running on the same computer - make a symlink
                # if not - copy the folder
                calcinfo.remote_symlink_list.append(copy_info)
            else:
                calcinfo.remote_copy_list.append(copy_info)

        return calcinfo
示例#3
0
    def prepare_for_submission(self, folder):
        """Create the input files from the input nodes passed to this instance of the `CalcJob`.
        :param folder: an `aiida.common.folders.Folder` to temporarily write files on disk
        :return: `aiida.common.datastructures.CalcInfo` instance
        """

        settings = self.inputs.settings.get_dict(
        ) if 'settings' in self.inputs else {}

        param_dict = self.inputs.parameters.get_dict()

        # ---------------------------------------------------
        # Write params.ini file
        params_fn = folder.get_abs_path("params.ini")
        with open(params_fn, 'w') as f:
            for key, val in param_dict.items():
                line = str(key) + " "
                if isinstance(val, list):
                    line += " ".join(str(v) for v in val)
                else:
                    line += str(val)
                f.write(line + '\n')
        # ---------------------------------------------------

        # create code info
        codeinfo = CodeInfo()
        codeinfo.code_uuid = self.inputs.code.uuid
        codeinfo.withmpi = False

        # create calc info
        calcinfo = CalcInfo()
        calcinfo.uuid = self.uuid
        calcinfo.codes_info = [codeinfo]

        # file lists
        calcinfo.remote_symlink_list = []
        calcinfo.local_copy_list = [
            (self.inputs.atomtypes.uuid, self.inputs.atomtypes.filename,
             'atomtypes.ini')
        ]
        calcinfo.remote_copy_list = []
        calcinfo.retrieve_list = ["*/*/*.npy"]

        # symlinks
        if 'parent_calc_folder' in self.inputs:
            comp_uuid = self.inputs.parent_calc_folder.computer.uuid
            remote_path = self.inputs.parent_calc_folder.get_remote_path()
            copy_info = (comp_uuid, remote_path, 'parent_calc_folder/')
            if self.inputs.code.computer.uuid == comp_uuid:  # if running on the same computer - make a symlink
                # if not - copy the folder
                calcinfo.remote_symlink_list.append(copy_info)
            else:
                calcinfo.remote_copy_list.append(copy_info)

        return calcinfo


# EOF
示例#4
0
    def prepare_for_submission(self, folder):
        """Create the input files from the input nodes passed to this instance of the `CalcJob`.

        :param folder: an `aiida.common.folders.Folder` to temporarily write files on disk
        :return: `aiida.common.datastructures.CalcInfo` instance
        """

        self.logger.info("prepare_for_submission")

        # These three lists are updated in self._create_additional_files(folder)
        self._internal_retrieve_list = []
        self._additional_cmd_params = []
        self._calculation_cmd = []
        self._create_additional_files(folder)

        # ================= prepare the python input files =================

        # BORN
        if (not self.inputs.fc_only and 'nac_params' in self.inputs
                and 'primitive' in self.inputs
                and 'symmetry_tolerance' in self.inputs.settings.attributes):
            born_txt = get_BORN_txt(self.inputs.nac_params,
                                    self.inputs.primitive,
                                    self.inputs.settings['symmetry_tolerance'])
            with folder.open(self._INPUT_NAC, 'w', encoding='utf8') as handle:
                handle.write(born_txt)
            for params in self._additional_cmd_params:
                params.append('--nac')

        # ============================ calcinfo ===============================

        local_copy_list = []
        remote_copy_list = []

        calcinfo = CalcInfo()
        calcinfo.uuid = self.uuid
        calcinfo.local_copy_list = local_copy_list
        calcinfo.remote_copy_list = remote_copy_list
        calcinfo.retrieve_list = self._internal_retrieve_list

        calcinfo.codes_info = []
        for i, (default_params, additional_params) in enumerate(
                zip(self._calculation_cmd, self._additional_cmd_params)):
            codeinfo = CodeInfo()
            codeinfo.cmdline_params = default_params + additional_params
            codeinfo.code_uuid = self.inputs.code.uuid
            codeinfo.stdout_name = "%s%d" % (self.options.output_filename,
                                             i + 1)
            codeinfo.withmpi = False
            calcinfo.codes_info.append(codeinfo)

        return calcinfo
示例#5
0
    def prepare_for_submission(self, folder):
        
         # create calculation info
        calcinfo = CalcInfo()
        calcinfo.uuid = self.uuid
        calcinfo.codes_info = []
        calcinfo.retrieve_list = []

        for key, params in self.inputs.parameters.get_dict().items():
            
            cube_name = key+".cube"
            kind_str = params["kind"]
            npts = params["npts"]

            # create code info 
            codeinfo = CodeInfo()

            codeinfo.cmdline_params = []
            codeinfo.cmdline_params.append(str(self.inputs.metadata.options.resources['tot_num_mpiprocs']))
            codeinfo.cmdline_params.append(kind_str)
            codeinfo.cmdline_params.append(self._PARENT_FOLDER_NAME + "/" + self._DEFAULT_INPUT_FILE)
            codeinfo.cmdline_params.append(cube_name)
            codeinfo.cmdline_params.append(str(npts))

            codeinfo.code_uuid = self.inputs.code.uuid
            codeinfo.withmpi = self.inputs.metadata.options.withmpi

            calcinfo.codes_info.append(codeinfo)

            if self.inputs.retrieve_cubes.value:
                calcinfo.retrieve_list.append(cube_name)

        extra_prepend = "\nexport GAUSS_MEMDEF=%dMB\n" % self.inputs.gauss_memdef
        if not hasattr(calcinfo, 'prepend_text') or not calcinfo.prepend_text:
            calcinfo.prepend_text = extra_prepend
        else:
            calcinfo.prepend_text += extra_prepend

         # symlink or copy to parent calculation
        calcinfo.remote_symlink_list = []
        calcinfo.remote_copy_list = []
        comp_uuid = self.inputs.parent_calc_folder.computer.uuid
        remote_path = self.inputs.parent_calc_folder.get_remote_path()
        copy_info = (comp_uuid, remote_path, self._PARENT_FOLDER_NAME)
        if self.inputs.code.computer.uuid == comp_uuid:  # if running on the same computer - make a symlink
            # if not - copy the folder
            calcinfo.remote_symlink_list.append(copy_info)
        else:
            calcinfo.remote_copy_list.append(copy_info)
        

        return calcinfo
示例#6
0
    def prepare_for_submission(self, folder):
        """
        Create input files.

        :param folder: an `aiida.common.folders.Folder` to temporarily write files on disk
        :return: `aiida.common.datastructures.CalcInfo` instance

        """

        # Prepare CalcInfo to be returned to aiida
        calcinfo = CalcInfo()
        calcinfo.uuid = self.uuid

        # network infers file format from file extension
        structure = self.inputs.structure
        structure_filename = self.inputs.parameters.get_structure_file_name(
            structure)
        calcinfo.local_copy_list = [(structure.uuid, structure.filename,
                                     structure_filename)]

        if 'atomic_radii' in self.inputs:
            atomic_radii = self.inputs.atomic_radii
            radii_file_name = atomic_radii.filename
            calcinfo.local_copy_list.append(
                (atomic_radii.uuid, atomic_radii.filename,
                 atomic_radii.filename))
        else:
            radii_file_name = None

        calcinfo.remote_copy_list = []
        calcinfo.retrieve_list = self.inputs.parameters.output_files

        codeinfo = CodeInfo()
        codeinfo.cmdline_params = self.inputs.parameters.cmdline_params(
            structure_file_name=structure_filename,
            radii_file_name=radii_file_name)
        codeinfo.code_uuid = self.inputs.code.uuid
        codeinfo.withmpi = False
        calcinfo.codes_info = [codeinfo]

        return calcinfo
示例#7
0
    def prepare_for_submission(self, folder):
        """
        Create input files.

            :param folder: aiida.common.folders.Folder subclass where
                the plugin should put all its files.
        """
        # create input files: d3
        structure = self.inputs.get('structure', None)
        try:
            d3_content = D3(self.inputs.parameters.get_dict(), structure)
        except (ValueError, NotImplementedError) as err:
            raise InputValidationError(
                "an input file could not be created from the parameters: {}".
                format(err))
        with folder.open(self._INPUT_FILE_NAME, "w") as f:
            d3_content.write(f)

        # create input files: fort.9
        with self.inputs.wavefunction.open(mode="rb") as f:
            folder.create_file_from_filelike(f,
                                             self._WAVEFUNCTION_FILE_NAME,
                                             mode="wb")

        # Prepare CodeInfo object for aiida
        codeinfo = CodeInfo()
        codeinfo.code_uuid = self.inputs.code.uuid
        codeinfo.stdin_name = self._INPUT_FILE_NAME
        codeinfo.stdout_name = self._OUTPUT_FILE_NAME
        codeinfo.withmpi = False

        # Prepare CalcInfo object for aiida
        calcinfo = CalcInfo()
        calcinfo.uuid = self.uuid
        calcinfo.codes_info = [codeinfo]
        calcinfo.local_copy_list = []
        calcinfo.remote_copy_list = []
        calcinfo.retrieve_list = [self._PROPERTIES_FILE_NAME]
        calcinfo.local_copy_list = []

        return calcinfo
示例#8
0
 def prepare_for_submission(self, folder):
     """
     The baseclass will only setup the basic calcinfo arguments but will
     not write **any** files which has to be implemented in the subclassed
     prepare_for_submission() method
     """
     # if no custodian code is defined directly run the VASP calculation,
     # i.e. initialize the CodeInfo for the passed VASP code
     if not self.inputs.custodian.get('code', False):
         codeinfo = CodeInfo()
         codeinfo.code_uuid = self.inputs.code.uuid
         codeinfo.stdout_name = self._default_output_file
         codeinfo.stderr_name = self._default_error_file
     # otherwise wrap in Custodian calculation and initialize CodeInfo for
     # the passed Custodian code (This is sufficient as AiiDA will scan all
     # Code-inputs to generate the required prepend / append lines)
     else:
         codeinfo = CodeInfo()
         codeinfo.code_uuid = self.inputs.custodian.code.uuid
         # define custodian-exe command line arguments
         codeinfo.cmdline_params = ['run', PluginDefaults.CSTDN_SPEC_FNAME]
         # never add the MPI command to custodian since it will call
         # VASP using MPI itself
         codeinfo.withmpi = False
     calcinfo = CalcInfo()
     calcinfo.uuid = self.uuid
     calcinfo.codes_info = [codeinfo]
     # those list are set defined in the inherited classes
     calcinfo.local_copy_list = []
     calcinfo.remote_copy_list = []
     calcinfo.remote_symlink_list = []
     # retrieve lists are defined on the base class
     calcinfo.retrieve_temporary_list = self.retrieve_temporary_list()
     calcinfo.retrieve_list = self.retrieve_permanent_list()
     # need to set run mode since presubmit() takes all code inputs into
     # account and would complain if both vasp and custodian codes are set
     calcinfo.codes_run_mode = CodeRunMode.SERIAL
     # finally write the neccessary calculation inputs to the calculation's
     # input folder
     calcinfo = self.create_calculation_inputs(folder, calcinfo)
     return calcinfo
示例#9
0
    def prepare_for_submission(self, tempfolder):
        """Create the input files from the input nodes passed to this instance of the `CalcJob`.

        :param tempfolder: an `aiida.common.folders.Folder` to temporarily write files on disk
        :return: `aiida.common.CalcInfo` instance
        """
        # assert that the potential and structure have the same kind elements
        if self.inputs.potential.allowed_element_names is not None and not set(
            k.symbol for k in self.inputs.structure.kinds
        ).issubset(self.inputs.potential.allowed_element_names):
            raise ValidationError(
                "the structure and potential are not compatible (different kind elements)"
            )

        # Setup structure
        structure_txt, struct_transform = generate_lammps_structure(
            self.inputs.structure, self.inputs.potential.atom_style
        )

        with open(
            tempfolder.get_abs_path(self.options.cell_transform_filename), "w+b"
        ) as handle:
            np.save(handle, struct_transform)

        if "parameters" in self.inputs:
            parameters = self.inputs.parameters
        else:
            parameters = Dict()

        # Setup input parameters
        input_txt = self.create_main_input_content(
            parameter_data=parameters,
            potential_data=self.inputs.potential,
            kind_symbols=[kind.symbol for kind in self.inputs.structure.kinds],
            structure_filename=self._INPUT_STRUCTURE,
            trajectory_filename=self.options.trajectory_suffix,
            system_filename=self.options.system_suffix,
            restart_filename=self.options.restart_filename,
        )

        input_filename = tempfolder.get_abs_path(self._INPUT_FILE_NAME)

        with open(input_filename, "w") as infile:
            infile.write(input_txt)

        self.validate_parameters(parameters, self.inputs.potential)
        retrieve_list, retrieve_temporary_list = self.get_retrieve_lists()
        retrieve_list.extend(
            [self.options.output_filename, self.options.cell_transform_filename]
        )

        # prepare extra files if needed
        self.prepare_extra_files(tempfolder, self.inputs.potential)

        # =========================== dump to file =============================

        structure_filename = tempfolder.get_abs_path(self._INPUT_STRUCTURE)
        with open(structure_filename, "w") as infile:
            infile.write(structure_txt)

        for name, content in self.inputs.potential.get_external_files().items():
            fpath = tempfolder.get_abs_path(name)
            with open(fpath, "w") as infile:
                infile.write(content)

        # ============================ calcinfo ================================

        codeinfo = CodeInfo()
        codeinfo.cmdline_params = list(self._cmdline_params)
        codeinfo.code_uuid = self.inputs.code.uuid
        codeinfo.withmpi = self.metadata.options.withmpi
        codeinfo.stdout_name = self._stdout_name

        calcinfo = CalcInfo()
        calcinfo.uuid = self.uuid
        calcinfo.retrieve_list = retrieve_list
        calcinfo.retrieve_temporary_list = retrieve_temporary_list
        calcinfo.codes_info = [codeinfo]

        return calcinfo
示例#10
0
    def prepare_for_submission(self, folder):
        """
        This is the routine to be called when you want to create
        the input files and related stuff with a plugin.

        :param folder: a aiida.common.folders.Folder subclass where
                           the plugin should put all its files.
        """
        # create calc info
        calcinfo = CalcInfo()
        calcinfo.remote_copy_list = []
        calcinfo.local_copy_list = []

        # The main input
        try:
            input_string = GaussianCalculation._render_input_string_from_params(
                self.inputs.parameters.get_dict(), self.inputs.structure
            )
        # If structure is not specified the user might want to restart from a chk
        except AttributeError:
            input_string = GaussianCalculation._render_input_string_from_params(
                self.inputs.parameters.get_dict(), None
            )

        # Parse additional link1 sections
        if "extra_link1_sections" in self.inputs:
            for l1_name, l1_params in self.inputs.extra_link1_sections.items():
                input_string += "--Link1--\n"
                # The link1 secions don't support their own geometries.
                input_string += GaussianCalculation._render_input_string_from_params(
                    l1_params.get_dict(), None
                )

        with open(folder.get_abs_path(self.INPUT_FILE), "w") as out_file:
            out_file.write(input_string)

        settings = self.inputs.settings.get_dict() if "settings" in self.inputs else {}

        # create code info
        codeinfo = CodeInfo()
        codeinfo.cmdline_params = settings.pop("cmdline", [])
        codeinfo.code_uuid = self.inputs.code.uuid
        codeinfo.stdin_name = self.INPUT_FILE
        codeinfo.stdout_name = self.OUTPUT_FILE
        codeinfo.withmpi = self.inputs.metadata.options.withmpi

        # create calculation info
        calcinfo.uuid = self.uuid
        calcinfo.cmdline_params = codeinfo.cmdline_params
        calcinfo.stdin_name = self.INPUT_FILE
        calcinfo.stdout_name = self.OUTPUT_FILE
        calcinfo.codes_info = [codeinfo]
        calcinfo.retrieve_list = [self.OUTPUT_FILE]

        # symlink or copy to parent calculation
        calcinfo.remote_symlink_list = []
        calcinfo.remote_copy_list = []
        if "parent_calc_folder" in self.inputs:
            comp_uuid = self.inputs.parent_calc_folder.computer.uuid
            remote_path = self.inputs.parent_calc_folder.get_remote_path()
            copy_info = (comp_uuid, remote_path, "parent_calc")
            if (
                self.inputs.code.computer.uuid == comp_uuid
            ):  # if running on the same computer - make a symlink
                # if not - copy the folder
                calcinfo.remote_symlink_list.append(copy_info)
            else:
                calcinfo.remote_copy_list.append(copy_info)

        return calcinfo
示例#11
0
    def prepare_for_submission(self, folder):
        """Create the input files from the input nodes passed to this instance of the `CalcJob`.

        :param folder: an `aiida.common.folders.Folder` to temporarily write files on disk
        :return: `aiida.common.datastructures.CalcInfo` instance
        """

        self.logger.info("prepare_for_submission")

        self._internal_retrieve_list = []
        self._additional_cmd_params = []
        self._calculation_cmd = []

        settings = self.inputs.settings
        structure = self.inputs.structure
        code = self.inputs.code

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

        # ================= prepare the python input files =================

        self._create_additional_files(folder)

        cell_txt = get_poscar_txt(structure)
        input_txt = get_phonopy_conf_file_txt(settings)

        input_filename = folder.get_abs_path(
            self.inputs.metadata.options.input_filename)
        with open(input_filename, 'w') as infile:
            infile.write(input_txt)

        cell_filename = folder.get_abs_path(self._INPUT_CELL)
        with open(cell_filename, 'w') as infile:
            infile.write(cell_txt)

        if ('nac_params' in self.inputs and 'primitive' in self.inputs):
            born_txt = get_BORN_txt(self.inputs.nac_params,
                                    self.inputs.primitive,
                                    settings['symmetry_tolerance'])

            nac_filename = folder.get_abs_path(self._INPUT_NAC)
            with open(nac_filename, 'w') as infile:
                infile.write(born_txt)
            for params in self._additional_cmd_params:
                params.append('--nac')

        # ============================ calcinfo ===============================

        local_copy_list = []
        remote_copy_list = []

        calcinfo = CalcInfo()

        calcinfo.uuid = self.uuid

        # Empty command line by default
        calcinfo.local_copy_list = local_copy_list
        calcinfo.remote_copy_list = remote_copy_list

        # Retrieve files
        calcinfo.retrieve_list = self._internal_retrieve_list

        calcinfo.codes_info = []
        for default_params, additional_params in zip(
                self._calculation_cmd, self._additional_cmd_params):
            codeinfo = CodeInfo()
            codeinfo.cmdline_params = ([
                self.inputs.metadata.options.input_filename,
            ] + default_params + additional_params)
            codeinfo.code_uuid = code.uuid
            codeinfo.stdout_name = self.inputs.metadata.options.output_filename
            codeinfo.withmpi = False
            calcinfo.codes_info.append(codeinfo)

        return calcinfo
示例#12
0
    def prepare_for_submission(self, folder):

        # create calculation info
        calcinfo = CalcInfo()
        calcinfo.uuid = self.uuid
        calcinfo.codes_info = []
        calcinfo.retrieve_list = []
        calcinfo.retrieve_temporary_list = []
        calcinfo.prepend_text = "export GAUSS_MEMDEF=%dMB\n" % self.inputs.gauss_memdef

        calcinfo.local_copy_list = []

        if "stencil" in self.inputs:
            calcinfo.local_copy_list.append(
                (self.inputs.stencil.uuid, self.inputs.stencil.filename,
                 'stencil.txt'))

        for key, params in self.inputs.parameters.get_dict().items():

            cube_name = key + ".cube"
            kind_str = params["kind"]
            npts = params["npts"]

            # create code info
            codeinfo = CodeInfo()

            codeinfo.cmdline_params = []
            codeinfo.cmdline_params.append(
                str(self.inputs.metadata.options.resources['tot_num_mpiprocs'])
            )
            codeinfo.cmdline_params.append(kind_str)
            codeinfo.cmdline_params.append(self.PARENT_FOLDER_NAME + "/" +
                                           self.DEFAULT_INPUT_FILE)
            codeinfo.cmdline_params.append(cube_name)

            if npts == -1:
                if 'stencil' not in self.inputs:
                    self.report(
                        "Warning: npts: -1 set but no stencil provided, using -2"
                    )
                    codeinfo.cmdline_params.append("-2")
                else:
                    codeinfo.cmdline_params.append(str(npts))
                    codeinfo.stdin_name = "stencil.txt"
            else:
                codeinfo.cmdline_params.append(str(npts))

            codeinfo.code_uuid = self.inputs.code.uuid
            codeinfo.withmpi = self.inputs.metadata.options.withmpi

            calcinfo.codes_info.append(codeinfo)

            if self.inputs.retrieve_cubes.value:
                calcinfo.retrieve_list.append(cube_name)
            else:
                calcinfo.retrieve_temporary_list.append(cube_name)

        # symlink or copy to parent calculation
        calcinfo.remote_symlink_list = []
        calcinfo.remote_copy_list = []
        comp_uuid = self.inputs.parent_calc_folder.computer.uuid
        remote_path = self.inputs.parent_calc_folder.get_remote_path()
        copy_info = (comp_uuid, remote_path, self.PARENT_FOLDER_NAME)
        if self.inputs.code.computer.uuid == comp_uuid:
            # if running on the same computer - make a symlink
            # if not - copy the folder
            calcinfo.remote_symlink_list.append(copy_info)
        else:
            calcinfo.remote_copy_list.append(copy_info)

        return calcinfo
示例#13
0
文件: dp.py 项目: eimrek/aiida-deepmd
    def prepare_for_submission(self, folder):
        """Create the input files from the input nodes passed to this instance of the `CalcJob`.

        :param folder: an `aiida.common.folders.Folder` to temporarily write files on disk
        :return: `aiida.common.datastructures.CalcInfo` instance
        """

        # create json input file
        input = dict()
        input['model'] = self.inputs.model.get_dict()
        input['learning_rate'] = self.inputs.learning_rate.get_dict()
        input['loss'] = self.inputs.loss.get_dict()
        input['training'] = self.inputs.training.get_dict()
        # replace all the random seed
        input['model']['descriptor']['seed'] = np.random.randint(100000000)
        input['model']['fitting_net']['seed'] = np.random.randint(100000000)
        input['training']['seed'] = np.random.randint(100000000)
        warn("All seeds in user input will be automatically replaced by numpy.")
        json_str = json.dumps(input, indent=4, sort_keys=False)

        with io.open(folder.get_abs_path(self._DEFAULT_INPUT_FILE), mode="w", encoding="utf-8") as fobj:
            try:
                fobj.write(json_str)
            except ValueError as exc:
                raise InputValidationError("invalid keys or values in input parameters found")

        # Create the subfolder that will contain the train data
        local_copy_list = []
        for datadir in self.inputs.datadirs:
            # change to absolute path
            if not os.path.exists(datadir):
                raise FileExistsError("This datadir dose not exist")
            absdatadir = os.path.abspath(datadir)
            # create subfolder
            datadir_basename = os.path.basename(absdatadir)
            datadir_in_workdir = os.path.join("./", datadir_basename)
            folder.get_subfolder(datadir_in_workdir, create=True)
            # this loop use to copy the training data under the datadir
            for root, directories, files in os.walk(top=absdatadir, topdown=True):
                relroot = os.path.relpath(root, absdatadir)
                # create subtree folders
                for name in directories:
                    folder.get_subfolder(
                        os.path.join(
                            datadir_basename,
                            relroot,
                            name),
                        create=True)

                # give the singlefiledata to file
                for name in files:
                    fobj = SinglefileData(
                        file=os.path.join(root, name)
                    )
                    # must save fobj otherwise the node is empty and can't be copied
                    fobj.store()
                    dst_path = os.path.join(
                        datadir_basename,
                        relroot,
                        name)
                    local_copy_list.append((fobj.uuid, fobj.filename, dst_path))



        # settings = self.inputs.settings.get_dict() if 'settings' in self.inputs else {}

        # set two code info here, once the training finished, the model will freeze then.
        # create code info for training
        codeinfotrain = CodeInfo()
        codeinfotrain.cmdline_params = ["train", self._DEFAULT_INPUT_FILE]
        #codeinfotrain.stdin_name = self._DEFAULT_INPUT_FILE
        codeinfotrain.stdout_name = self._DEFAULT_TRAIN_OUTPUT_FILE
        codeinfotrain.join_files = True
        codeinfotrain.code_uuid = self.inputs.code.uuid
        codeinfotrain.withmpi = self.inputs.metadata.options.withmpi

        # create code info for freeze
        codeinfofreeze = CodeInfo()
        codeinfofreeze.cmdline_params = ["freeze", '-o', self._DEFAULT_FREEZE_OUTPUT_FILE]
        #codeinfofreeze.stdout_name = self._DEFAULT_FREEZE_OUTPUT_FILE
        codeinfofreeze.code_uuid = self.inputs.code.uuid
        codeinfofreeze.withmpi = self.inputs.metadata.options.withmpi


        # create calc info
        calcinfo = CalcInfo()
        calcinfo.uuid = self.uuid
        calcinfo.local_copy_list = local_copy_list
        calcinfo.codes_info = [codeinfotrain, codeinfofreeze]

        calcinfo.retrieve_list = [
            self._DEFAULT_TRAIN_OUTPUT_FILE,
            self._DEFAULT_FREEZE_OUTPUT_FILE,
            self._DEFAULT_OUTPUT_INFO_FILE,
            self._DEFAULT_CHECK_META_FILE,
            self._DEFAULT_CHECK_INDEX_FILE
        ]

        return calcinfo
示例#14
0
    def prepare_for_submission(self, tempfolder):
        """Create the input files from the input nodes passed to this instance of the `CalcJob`.

        :param tempfolder: an `aiida.common.folders.Folder` to temporarily write files on disk
        :return: `aiida.common.CalcInfo` instance
        """
        # assert that the potential and structure have the same kind elements
        if [k.symbol for k in self.inputs.structure.kinds] != self.inputs.potential.kind_elements:
            raise ValidationError("the structure and potential are not compatible (different kind elements)")

        # Setup potential
        potential_txt = self.inputs.potential.get_potential_file()

        # Setup structure
        structure_txt, struct_transform = generate_lammps_structure(
            self.inputs.structure, self.inputs.potential.atom_style)

        with open(tempfolder.get_abs_path(self.options.cell_transform_filename), 'w+b') as handle:
            np.save(handle, struct_transform)

        if "parameters" in self.inputs:
            parameters = self.inputs.parameters
        else:
            parameters = Dict()
        pdict = parameters.get_dict()

        # Check lammps version date in parameters
        lammps_date = convert_date_string(
            pdict.get("lammps_version", '11 Aug 2017'))

        # Setup input parameters
        input_txt = self._generate_input_function(
            parameters=parameters,
            potential_obj=self.inputs.potential,
            structure_filename=self._INPUT_STRUCTURE,
            trajectory_filename=self.options.trajectory_name,
            info_filename=self.options.info_filename,
            restart_filename=self.options.restart_filename,
            add_thermo_keywords=pdict.get("thermo_keywords", []),
            version_date=lammps_date)

        input_filename = tempfolder.get_abs_path(self._INPUT_FILE_NAME)

        with open(input_filename, 'w') as infile:
            infile.write(input_txt)

        self.validate_parameters(parameters, self.inputs.potential)

        # prepare extra files if needed
        self.prepare_extra_files(tempfolder, self.inputs.potential)

        # =========================== dump to file =============================

        structure_filename = tempfolder.get_abs_path(self._INPUT_STRUCTURE)
        with open(structure_filename, 'w') as infile:
            infile.write(structure_txt)

        if potential_txt is not None:
            potential_filename = tempfolder.get_abs_path(
                self.inputs.potential.potential_filename)
            with open(potential_filename, 'w') as infile:
                infile.write(potential_txt)

        # ============================ calcinfo ================================

        codeinfo = CodeInfo()
        codeinfo.cmdline_params = self._cmdline_params
        codeinfo.code_uuid = self.inputs.code.uuid
        codeinfo.withmpi = False  # Set lammps openmpi environment properly
        codeinfo.stdout_name = self._stdout_name

        calcinfo = CalcInfo()
        calcinfo.uuid = self.uuid
        calcinfo.retrieve_list = self._retrieve_list + [
            self.options.output_filename,
            self.options.cell_transform_filename]
        calcinfo.retrieve_temporary_list = self._retrieve_temporary_list
        calcinfo.codes_info = [codeinfo]

        return calcinfo