Example #1
0
def _parsing_vasp(paths, id_prefix, iters=True):
    entries = []
    icount = 0
    for path in paths:
        f_outcar = os.path.join(path, 'OUTCAR')
        f_job = os.path.join(path, 'job.json')

        try:
            vi = VaspInput.from_directory(path)
            if os.path.isfile(f_job):
                attrib = loadfn(f_job)
            else:
                attrib = {}

            if iters and attrib:
                tmp_ = path.split('/')[-1]
                iter_info = tmp_.split('.')[1]
                task_info = tmp_.split('.')[-1]
                attrib['iter_info'] = iter_info
                attrib['task_info'] = task_info
            else:
                pass
            comp = vi['POSCAR'].structure.composition
            ls = LabeledSystem(f_outcar)
            lss = ls.to_list()
            for ls in lss:
                if id_prefix:
                    eid = id_prefix + "_" + str(icount)
                else:
                    eid = str(uuid4())
                entry = Entry(comp,
                              'vasp',
                              vi.as_dict(),
                              ls.as_dict(),
                              attribute=attrib,
                              entry_id=eid)
                entries.append(entry)
                icount += 1
        except:
            dlog.info("failed here : %s" % path)
    return entries
Example #2
0
def _parsing_vasp(paths, config_info_dict, id_prefix, iters=True):
    entries = []
    icount = 0
    if iters:
        iter_record = []
        iter_record_new = []
        try:
            with open("record.database", "r") as f_record:
                iter_record = [i.split()[0] for i in f_record.readlines()]
            iter_record.sort()
            dlog.info("iter_record")
            dlog.info(iter_record)
        except:
            pass
    for path in paths:
        try:
            f_outcar = os.path.join(path, 'OUTCAR')
            f_job = os.path.join(path, 'job.json')
            tmp_iter = path.split('/')[-3]
            if (tmp_iter in iter_record) and (tmp_iter != iter_record[-1]):
                continue
            if tmp_iter not in iter_record_new:
                iter_record_new.append(tmp_iter)
            vi = VaspInput.from_directory(path)
            if os.path.isfile(f_job):
                attrib = loadfn(f_job)
            else:
                attrib = {}

            if iters and attrib:
                # generator/Cu/iter.000031/02.fp/task.007.000000
                tmp_ = path.split('/')[-1]
                #config_info=tmp_.split('.')[1]
                task_info = tmp_.split('.')[-1]
                tmp_iter = path.split('/')[-3]
                iter_info = tmp_iter.split('.')[-1]
                sys_info = path.split('/')[-4]
                config_info_int = int(tmp_.split('.')[1])
                for (key, value) in config_info_dict.items():
                    if config_info_int in value:
                        config_info = key
                attrib['config_info'] = config_info
                attrib['task_info'] = task_info
                attrib['iter_info'] = iter_info
                attrib['sys_info'] = sys_info
                with open(f_outcar, "r") as fin_outcar:
                    infile_outcar = fin_outcar.readlines()
                for line in infile_outcar:
                    if "running on" in line:
                        attrib["core"] = int(line.split()[2])
                    if "Elapse" in line:
                        attrib["wall_time"] = float(line.split()[-1])
                    if "executed on" in line:
                        attrib["date"] = line.split()[-2]
                        attrib["clocktime"] = line.split()[-1]
                dlog.info("Attrib")
                dlog.info(attrib)
            comp = vi['POSCAR'].structure.composition
            ls = LabeledSystem(f_outcar)
            lss = ls.to_list()
            for ls in lss:
                if id_prefix:
                    eid = id_prefix + "_" + str(icount)
                else:
                    eid = str(uuid4())
            entry = Entry(comp,
                          'vasp',
                          vi.as_dict(),
                          ls.as_dict(),
                          attribute=attrib,
                          entry_id=eid)
            entries.append(entry)
            icount += 1
        except Exception:
            #dlog.info(str(Exception))
            dlog.info("failed for %s" % (path))
            #pass
    if iters:
        iter_record.sort()
        iter_record_new.sort()
        with open("record.database", "w") as fw:
            for line in iter_record:
                fw.write(line + "\n")
            for line in iter_record_new:
                fw.write(line + "\n")
    return entries