예제 #1
0
    def process_item(self, task):
        """
        Process the tasks into a list of materials

        Args:
            task [dict] : a task doc

        Returns:
            list of C
        """

        t_type = task_type(get(task, 'orig_inputs'))
        entries = []

        if not any([t in t_type for t in self.task_types]):
            return []

        is_hubbard = get(task, "input.is_hubbard", False)
        hubbards = get(task, "input.hubbards", [])
        i = 0

        for calc in task.get("calcs_reversed", []):

            parameters = {
                "is_hubbard": is_hubbard,
                "hubbards": hubbards,
                "potcar_spec": get(calc, "input.potcar_spec", []),
                "run_type": calc.get("run_type", "GGA")
            }

            for step_num, step in enumerate(get(calc, "output.ionic_steps")):
                struc = Structure.from_dict(step.get("structure"))
                forces = calc.get("forces", [])
                if forces:
                    struc.add_site_property("forces", forces)
                stress = calc.get("stress", None)
                data = {"stress": stress} if stress else {}
                data["step"] = step_num
                c = ComputedStructureEntry(structure=struc,
                                           correction=0,
                                           energy=step.get("e_wo_entrp"),
                                           parameters=parameters,
                                           entry_id="{}-{}".format(
                                               task[self.tasks.key], i),
                                           data=data)
                i += 1

                d = c.as_dict()
                d["chemsys"] = '-'.join(
                    sorted(set([e.symbol
                                for e in struc.composition.elements])))
                d["task_type"] = task_type(get(calc, 'input'))
                d["calc_name"] = get(calc, "task.name")
                d["task_id"] = task[self.tasks.key]

                entries.append(d)

        return entries
예제 #2
0
    def task_to_prop_list(self, task):
        """
        Converts a task into an list of properties with associated metadata
        """
        t_type = task_type(task['orig_inputs'])
        t_id = task["task_id"]

        # Convert the task doc into a serious of properties in the materials
        # doc with the right document structure
        props = []
        for prop in self.__settings:
            if t_type in prop["quality_score"].keys():
                if has(task, prop["tasks_key"]):
                    props.append({
                        "value": get(task, prop["tasks_key"]),
                        "task_type": t_type,
                        "task_id": t_id,
                        "quality_score": prop["quality_score"][t_type],
                        "track": prop.get("track", False),
                        "aggregate": prop.get("aggregate", False),
                        "last_updated": task[self.tasks.lu_field],
                        "energy": get(task, "output.energy", 0.0),
                        "materials_key": prop["materials_key"]
                    })
                elif not prop.get("optional", False):
                    self.logger.error("Failed getting {} for task: {}".format(prop["tasks_key"], t_id))
        return props
예제 #3
0
파일: materials.py 프로젝트: FilipchukB/P1
    def filter_and_group_tasks(self, tasks):
        """
        Groups tasks by structure matching
        """

        filtered_tasks = [
            t for t in tasks
            if task_type(t['orig_inputs']) in self.allowed_tasks
        ]

        structures = []

        for idx, t in enumerate(filtered_tasks):
            s = Structure.from_dict(t["output"]['structure'])
            s.index = idx
            structures.append(s)

        grouped_structures = group_structures(
            structures,
            ltol=self.ltol,
            stol=self.stol,
            angle_tol=self.angle_tol,
            separate_mag_orderings=self.separate_mag_orderings)

        for group in grouped_structures:
            yield [filtered_tasks[struc.index] for struc in group]
예제 #4
0
    def filter_and_group_tasks(self, tasks):
        """
        Groups tasks by structure matching
        """

        filtered_tasks = [
            t for t in tasks
            if task_type(t['orig_inputs']) in self.allowed_tasks
        ]

        structures = []

        for idx, t in enumerate(filtered_tasks):
            s = Structure.from_dict(t["output"]['structure'])
            s.index = idx
            structures.append(s)

        if self.separate_mag_orderings:
            for structure in structures:
                if has(structure.site_properties, "magmom"):
                    structure.add_spin_by_site(
                        structure.site_properties['magmom'])
                    structure.remove_site_property('magmom')

        sm = StructureMatcher(ltol=self.ltol,
                              stol=self.stol,
                              angle_tol=self.angle_tol,
                              primitive_cell=True,
                              scale=True,
                              attempt_supercell=False,
                              allow_subset=False,
                              comparator=ElementComparator())

        grouped_structures = sm.group_structures(structures)

        grouped_tasks = [[filtered_tasks[struc.index] for struc in group]
                         for group in grouped_structures]

        return grouped_tasks
예제 #5
0
    def filter_and_group_tasks(self, tasks):
        """
        Groups tasks by structure matching
        """

        filtered_tasks = [
            t for t in tasks
            if task_type(t["orig_inputs"]) in self.allowed_tasks
        ]

        structures = []

        for idx, t in enumerate(filtered_tasks):
            s = Structure.from_dict(t["output"]["structure"])
            s.index = idx
            total_mag = get(
                t, "calcs_reversed.0.output.outcar.total_magnetization", 0)
            s.total_magnetization = total_mag if total_mag else 0
            # a fix for very old tasks that did not report site-projected magnetic moments
            # so that we can group them appropriately
            if (("magmom" not in s.site_properties)
                    and (get(t, "input.parameters.ISPIN", 1) == 2)
                    and has(t, "input.parameters.MAGMOM")):
                # TODO: map input structure sites to output structure sites
                s.add_site_property("magmom",
                                    t["input"]["parameters"]["MAGMOM"])
            structures.append(s)

        grouped_structures = group_structures(
            structures,
            ltol=self.ltol,
            stol=self.stol,
            angle_tol=self.angle_tol,
            separate_mag_orderings=self.separate_mag_orderings,
        )

        for group in grouped_structures:
            yield [filtered_tasks[struc.index] for struc in group]