Example #1
0
def parse_wf_for_latt_constants(wf_id):
    lpad = LaunchPad().from_file(lpad_file_path)

    wf = lpad.get_wf_by_fw_id(wf_id)

    lattdata = {}
    print('{} workflow retrieved with {} fws in it'.format(
        wf.name, len(wf.fws)))
    for fw in wf.fws:
        print('\t{}'.format(fw.name))
        if 'structure optimization' not in fw.name:
            raise ValueError("Not a recognized firework!")
        elif fw.state != 'COMPLETED':
            print('\t\tstatus = {}, so skipping'.format(fw.state))
            continue

        pat = fw.launches[-1].launch_dir
        s = Poscar.from_file(os.path.join(pat, 'CONTCAR.relax2.gz')).structure
        nom = s.composition.reduced_formula
        if nom in lattdata:
            raise ValueError("{} already exists in lattdata??".format(nom))
        elif (max(s.lattice.abc) - min(s.lattice.abc)) > 0.00001 or (
                max(s.lattice.angles) - min(s.lattice.angles)) > 0.00001:
            raise ValueError("Error occured with lattice relaxation??".format(
                s.lattice))
        else:
            lattdata.update({nom: s.lattice.abc[0]})

    print('\nFinalized lattice constant set:\n{}'.format(lattdata))

    return lattdata
Example #2
0
def get_wf_timing(wf_id, returnval=False):

    lp = LaunchPad().from_file(lpad_file_path)
    wf = lp.get_wf_by_fw_id(wf_id)
    out_run_stats = []
    just_non_polar_stats = []
    for fw in wf.fws:
        ld = fw.launches[-1].launch_dir
        out = None
        if 'OUTCAR' in os.listdir(ld):
            out = Outcar(os.path.join(ld, 'OUTCAR'))
        elif 'OUTCAR.gz' in os.listdir(ld):
            out = Outcar(os.path.join(ld, 'OUTCAR.gz'))
        if out:
            out_run_stats.append(out.run_stats.copy())
            if 'nonpolar_polarization' in fw.name:
                just_non_polar_stats.append(out.run_stats.copy())
        ld += '/polarization'
        if os.path.exists(ld):
            out = None
            if 'OUTCAR' in os.listdir(ld):
                out = Outcar(os.path.join(ld, 'OUTCAR'))
            elif 'OUTCAR.gz' in os.listdir(ld):
                out = Outcar(os.path.join(ld, 'OUTCAR.gz'))
            if out:
                out_run_stats.append(out.run_stats.copy())
    cores = out_run_stats[0]['cores']
    print('Workflow {} retrieved {} Outcars all run on {} cores'.format(
        wf.name, len(out_run_stats), cores))
    timestat = {
        k: 0
        for k in [
            'Elapsed time (sec)', 'System time (sec)', 'User time (sec)',
            'Total CPU time used (sec)'
        ]
    }
    print('\nNon-Polar calc (non-polarization) alone took:')
    if len(just_non_polar_stats) != 1:
        raise ValueError("Too many non polar calcs?? = {}".format(
            len(just_non_polar_stats)))
    else:
        for k, v in just_non_polar_stats[0].items():
            if k in timestat.keys():
                print("\t{}: {}".format(k, round(v, 2)))

    for out in out_run_stats:
        if out['cores'] != cores:
            raise ValueError(
                "Inconsisten number of cores for timing! {} vs {}".format(
                    cores, out['cores']))
        for k, v in out.items():
            if k in timestat:
                timestat[k] += v

    print("\nSummary of TOTAL wf timing:")
    for k, v in timestat.items():
        print("\t{}: {}".format(k, round(v, 2)))
    if not returnval:
        return
    else:
        return {'tot': timestat, 'nonpolar': just_non_polar_stats}