コード例 #1
0
def online_get_phase_graph():
    mpr = check_apikey()
    compat = MaterialsProjectCompatibility()
    print("input the elements list")
    wait_sep()
    in_str = ""
    while in_str == "":
        in_str = input().strip()
    elements = in_str.split()
    web = "materials.org"
    proc_str = "Reading Data From " + web + " ..."
    step_count = 1
    procs(proc_str, step_count, sp='-->>')
    unprocessed_entries = mpr.get_entries_in_chemsys(elements)
    processed_entries = compat.process_entries(unprocessed_entries)
    pd = PhaseDiagram(processed_entries)
    pdp = PDPlotter(pd, show_unstable=True)
    try:
        pdp.show()
    except:
        pass
    finally:
        step_count += 1
        filename = 'phase.png'
        proc_str = "Writing Data to " + filename + " File..."
        procs(proc_str, step_count, sp='-->>')
        pdp.write_image(filename)
コード例 #2
0
ファイル: vaspout.py プロジェクト: wangvei/maptool
def charge_density_diff():
    print("input the name of charge density file like this")
    print("file_A file_B, or")
    print("it means rho(A)-rho(B))")
    print("file_A file_B file_C")
    print("it means rho(A)-rho(B)-rho(C)")
    wait_sep()
    in_str = ""
    while in_str == "":
        in_str = input().strip()
    filenames = in_str.split()
    len_file = len(filenames)
    chg = [None] * len_file
    if len_file >= 2:
        for i in range(len_file):
            fchg = filenames[i]
            proc_str = "Reading Charge Density From " + fchg + " File ..."
            procs(proc_str, i + 1, sp='-->>')
            chg[i] = CHGCAR.from_file(fchg)
        diff_chg = copy(chg[0])
        for j in range(len_file - 1):
            diff_chg -= chg[j + 1]
        proc_str = "Writing Charge Density Difference to Diff.vasp  File ..."
        procs(proc_str, i + 2, sp='-->>')
        diff_chg.write_file('Diff.vasp', 'total')
    else:
        print("you must input at least 2 files")
コード例 #3
0
def is_pbc():
    print('your choice ?')
    print('{} >>> {}'.format('1', 'crystal'))
    print('{} >>> {}'.format('2', 'molecule/cluster'))
    wait_sep()
    in_str = ""
    while in_str == "":
        in_str = input().strip()
    choice = int(in_str)
    assert choice in [1, 2]
    if choice == 1:
        return True
    else:
        return False
コード例 #4
0
def online_get_properties():
    mpr = check_apikey()
    print("input the mp-ID")
    wait_sep()
    in_str = ""
    while in_str == "":
        in_str = input().strip()
    mp_id = in_str
    proc_str = "Reading Data From " + web + " ..."
    step_count = 1
    procs(proc_str, step_count, sp='-->>')
    data = mpr.get_data(mp_id)
    filename = mp_id + '.json'
    proc_str = "Writing Data To " + filename + " File ..."
    step_count += 1
    procs(proc_str, step_count, sp='-->>')
    json_store(data, filename)
コード例 #5
0
def online_get_banddos():
    check_matplotlib()
    mpr = check_apikey()
    print("input the mp-ID")
    wait_sep()
    in_str = ""
    while in_str == "":
        in_str = input().strip()
    mp_id = in_str
    step_count = 1
    proc_str = "Reading Data From " + web + " ..."
    procs(proc_str, step_count, sp='-->>')
    data = mpr.get_entry_by_material_id(mp_id)
    sepline()
    print(data)
    sepline()
    step_count += 1
    proc_str = "Reading Band Data From " + web + " ..."
    procs(proc_str, step_count, sp='-->>')
    band = mpr.get_bandstructure_by_material_id(mp_id)

    step_count += 1
    filename = mp_id + '_band.png'
    proc_str = "Writing Data to " + filename + " File..."
    bsp = BSPlotter(band)
    procs(proc_str, step_count, sp='-->>')
    bsp.save_plot(filename=filename, img_format="png")

    step_count += 1
    proc_str = "Reading DOS Data From " + web + " ..."
    procs(proc_str, step_count, sp='-->>')
    dos = mpr.get_dos_by_material_id(mp_id)

    step_count += 1
    filename = mp_id + '_dos.png'
    proc_str = "Writing Data to " + filename + " File..."
    dsp = DosPlotter()
    dsp.add_dos('Total', dos)
    procs(proc_str, step_count, sp='-->>')
    dsp.save_plot(filename=filename, img_format="png")
コード例 #6
0
def select_function(choice):

    # structure operation
    if choice == "a1":
        random_operation()
    elif choice == "a2":
        covert_operation()
    elif choice == "a3":
        build_operation()
    elif choice == "a4":
        cleave_operation()
    elif choice == "a5":
        strain_operation()
    elif choice == 'a6':
        twoD_operation()

# structure analysis
    elif choice == "b1":
        structure_symmetry()
    elif choice == "b2":
        structure_finger_print()
    elif choice == "b3":
        structures_difference()
    elif choice == "b4":
        get_primitive_cell()
    elif choice == "b5":
        get_conventional_cell()
    elif choice == "b6":
        get_xrd()

# vasp in/out tools
    elif choice == "c1":
        struct = readstructure(crystal=True,
                               molecule=False,
                               filename='POSCAR',
                               cano=False)
        sepline(ch=' prepare intput files ', sp='-')
        print('your choce ?')
        print('{} >>> {}'.format('1', 'prepare all files automatically'))
        print('{} >>> {}'.format('2', 'prepare INCAR file'))
        print('{} >>> {}'.format('3', 'prepare KPOINTS file'))
        print('{} >>> {}'.format('4', 'prepare POTCAR file'))
        wait_sep()
        in_str = ""
        while in_str == "":
            in_str = input().strip()
        choice = int(in_str)
        if choice == 1:
            generate_all_input(struct)
        elif choice == 2:
            generate_incar(struct)
        elif choice == 3:
            generate_kpoint(struct)
        elif choice == 4:
            generate_potcar(struct)
        else:
            print("unknown choice")

    elif choice == "cxx":
        sepline(ch=' summary output files ', sp='=')
        print('{} >>> {}'.format('1', 'describe OUCAR file'))
        print('{} >>> {}'.format('2', 'describe OSICAR file'))
        print('{} >>> {}'.format('3', 'describe vasprun.xml file'))
        wait_sep()
        in_str = ""
        while in_str == "":
            in_str = input().strip()
        choice = int(in_str)
        if choice == 1:
            describe_outcar()
        elif choice == 2:
            describe_OSICAR()
        elif choice == 3:
            describe_vasprun()
        else:
            print("unknow choice")

    elif choice == "c2":
        sepline(ch=' vasp output analysis ', sp='-')
        print('{} >>> {}'.format('1 ', 'total density of states'))
        print('{} >>> {}'.format('2 ', 'projected density of states'))
        print('{} >>> {}'.format('3 ', 'band structure'))
        print('{} >>> {}'.format('4 ', 'projected band structure'))
        print('{} >>> {}'.format('5 ', 'select one band structure'))
        print('{} >>> {}'.format('6 ', 'charge density'))
        print('{} >>> {}'.format('7 ', 'spin density'))
        print('{} >>> {}'.format('8 ', 'charge density difference'))
        print('{} >>> {}'.format('9 ', 'spin density component: up/down'))
        print('{} >>> {}'.format('10', 'average charge density/potential'))
        print('{} >>> {}'.format('11', 'optics analysis'))
        print('{} >>> {}'.format('12', 'mechanical analysis'))
        print('{} >>> {}'.format('13',
                                 'ab initio molecular dynamics analysis'))
        wait_sep()
        in_str = ""
        while in_str == "":
            in_str = input().strip()
        choice = int(in_str)
        if choice == 1:
            total_dos()
        elif choice == 2:
            projected_dos()
        elif choice == 3:
            band_structure()
        elif choice == 4:
            projected_band_structure()
        elif choice == 5:
            select_one_band_structure()
        elif choice == 6:
            charge_density()
        elif choice == 7:
            spin_density()
        elif choice == 8:
            charge_density_diff()
        elif choice == 9:
            spin_density_component()
        elif choice == 10:
            chg_locp_average()
        elif choice == 11:
            optics_analysis()
        elif choice == 12:
            elastic_analysis()
        elif choice == 13:
            aimd_analysis()
        else:
            print("unknow choice")

# online exctraction
    elif choice == "e1":
        online_get_banddos()
    elif choice == "e2":
        online_get_structure()
    elif choice == "e3":
        online_get_properties()
    elif choice == "e4":
        online_get_phase_graph()
    elif choice == "88":
        return
    else:
        print("unknow choice")
        return
コード例 #7
0
ファイル: read_structure.py プロジェクト: wangvei/maptool
def readstructure(crystal=True,
                  molecule=False,
                  filename=None,
                  multi_files=False,
                  cano=False):

    if multi_files:
        if crystal:
            print('input the full file names seperated by space')
            print('supported format 1: a.vasp')
            print('supported format 2: a.cif')
            print('supported format 3: a.vasp b.vasp')
            print('supported format 4: *.vasp')
            print('supported format 5: *.cif')
            structs = []
            wait_sep()
            in_str = ""
            while in_str == "":
                in_str = input().strip()
            if '*' in in_str:
                fnames = glob.glob(in_str)
            else:
                fnames = in_str.split()
                #print(fnames)

            for fname in fnames:
                if 'vasp' in fname:
                    try:
                        struct = MStructure.from_file(fname)
                    except:
                        nfname = str(uuid.uuid4()) + '_POSCAR'
                        os.symlink(fname, nfname)
                        mpt_log.debug("linke file for %s is %s" %
                                      (fname, nfname))
                        fname = nfname
                        struct = MStructure.from_file(fname)
                        os.unlink(fname)
                else:
                    try:
                        #print(fname)
                        struct = MStructure.from_file(fname)

                    except:
                        raise Exception("Unknown format")
                #print(struct)
                #print(type(struct))
                if cano:
                    struct.canonical_form()
                structs.append(struct)
            return structs, fnames

        if molecule:
            print(
                'input the full file names seperated by space (only for .xyz format)'
            )
            print('supported format 1: a.xyz b.xyz')
            print('supported format 2: *.xyz')
            structs = []
            wait_sep()
            in_str = ""
            while in_str == "":
                in_str = input().strip()
            if '*' in in_str:
                fnames = glob.glob(in_str)
            else:
                fnames = in_str.split()

            for fname in fnames:
                struct = MMolecule.from_file(fname)
                if cano:
                    struct.canonical_form()
                structs.append(struct)
            return structs, fnames

    if filename is not None:
        try:
            struct = MStructure.from_file(filename)
            if cano:
                struct.canonical_form()
        except:
            struct = MMolecule.from_file(filename)
            if cano:
                struct.canonical_form()
        return struct


#    sepline(ch='Read Structure',sp='=')
    print('your choice ?')
    print('{} >>> {}'.format('0', 'specific the file name!'))
    if crystal:
        print('{} >>> {}'.format('1', 'POSCAR'))
        print('{} >>> {}'.format('2', 'CONTCAR'))
        print('{} >>> {}'.format('3', 'CHGCAR'))
        print('{} >>> {}'.format('4', 'LOCPOT'))
        print('{} >>> {}'.format('5', NAME + '.cif'))
        print('{} >>> {}'.format('6', NAME + '.xsf'))
        print('{} >>> {}'.format('7', NAME + '.nc'))
        print('{} >>> {}'.format('8', NAME + '.yaml'))
        print('{} >>> {}'.format('9', NAME + '.json'))
    if molecule:
        print('{} >>> {}'.format('1', NAME + '.xyz'))
        print('{} >>> {}'.format('2', NAME + '.mol'))
        print('{} >>> {}'.format('3', NAME + '.nc'))
        print('{} >>> {}'.format('4', NAME + '.yaml'))
        print('{} >>> {}'.format('5', NAME + '.json'))

    wait_sep()
    in_str = ""
    while in_str == "":
        in_str = input().strip()
    fstin = int(in_str)
    if crystal:
        if fstin == 0:
            print('input the full file name')
            wait_sep()
            in_str = ""
            while in_str == "":
                in_str = input().strip()
            fname = in_str
            if fname.endswith('.vasp'):
                nfname = str(uuid.uuid4()) + '_POSCAR'
                os.symlink(fname, nfname)
                fname = nfname
        else:
            fname = infile_list_c[fstin - 1]
        struct = MStructure.from_file(fname)
        if cano:
            struct.canonical_form()

    if molecule:
        if fstin == 0:
            print('input the full file name')
            wait_sep()
            in_str = ""
            while in_str == "":
                in_str = input().strip()
            fname = in_str
        else:
            fname = infile_list_m[fstin - 1]
        struct = MMolecule.from_file(fname)
        if cano:
            struct.canonical_form()
    return struct
コード例 #8
0
def online_get_structure():
    mpr = check_apikey()
    print('your choice ?')
    print('{} >>> {}'.format('1', 'get a structure by mp-ID'))
    print('{} >>> {}'.format('2', 'get a structure by fomular'))
    print('{} >>> {}'.format('3', 'get a structure by elements'))
    wait_sep()
    in_str = ""
    while in_str == "":
        in_str = input().strip()
    choice = int(in_str)
    if choice == 1:
        print("input the mp-ID")
        wait_sep()
        in_str = ""
        while in_str == "":
            in_str = input().strip()
        mp_id = in_str
        struct = mpr.get_structure_by_material_id(mp_id)
        web = "materials.org"
        step_count = 1
        proc_str = "Reading Data From " + web + " ..."
        procs(proc_str, step_count, sp='-->>')
        filename = mp_id + '.vasp'
        step_count += 1
        proc_str = "Writing Data to " + filename + " File..."
        procs(proc_str, step_count, sp='-->>')
        struct.to(filename=filename, fmt='POSCAR')
    elif choice == 2:
        print("input the formula of structure")
        wait_sep()
        in_str = ""
        while in_str == "":
            in_str = input().strip()
        formula = in_str
        mpid = mpr.query(criteria={'pretty_formula': formula},
                         properties=['material_id'])
        web = "materials.org"
        proc_str = "Reading Data From " + web + " ..."
        step_count = 1
        procs(proc_str, step_count, sp='-->>')
        for i in range(len(mpid)):
            sid = mpid[i]['material_id']
            struct = mpr.get_structure_by_material_id(sid)
            filename = sid + '.cif'
            step_count += 1
            proc_str = "Writing Data to " + filename + " File..."
            procs(proc_str, step_count, sp='-->>')
            struct.to(fmt='cif', filename=filename)
    elif choice == 3:
        print("input the elements list")
        wait_sep()
        in_str = ""
        while in_str == "":
            in_str = input().strip()
        elements = in_str.split()
        data = mpr.get_entries_in_chemsys(elements=elements)
        web = "materials.org"
        proc_str = "Reading Data From " + web + " ..."
        step_count = 1
        procs(proc_str, step_count, sp='-->>')
        for i in range(len(data)):
            if len(data[i].composition) == len(elements):
                sid = data[i].entry_id
                struct = mpr.get_structure_by_material_id(sid)
                filename = sid + '.cif'
                step_count += 1
                proc_str = "Writing Data to " + filename + " File..."
                procs(proc_str, step_count, sp='-->>')
                struct.to(fmt='cif', filename=filename)
    else:
        print('unknow choice')
コード例 #9
0
def print_menu():
    sepline(ch=" structural operation ", sp='=')
    print('{} >>> {}'.format('a1', 'random operation'))
    print('{} >>> {}'.format('a2', 'covert operation'))
    print('{} >>> {}'.format('a3', 'build operation'))
    print('{} >>> {}'.format('a4', 'cleave operation'))
    print('{} >>> {}'.format('a5', 'strain operation'))
    print('{} >>> {}'.format('a6', '2D structure operation'))

    sepline(ch=" structural analysis ", sp='=')
    print('{} >>> {}'.format('b1', 'structure symmetry'))
    print('{} >>> {}'.format('b2', 'structure finger print'))
    print('{} >>> {}'.format('b3', 'structure difference'))
    print('{} >>> {}'.format('b4', 'get primitive cell'))
    print('{} >>> {}'.format('b5', 'get conventional cell'))
    print('{} >>> {}'.format('b6', 'get XRD pattern'))

    sepline(ch=" vasp in/out tools ", sp='=')
    print('{} >>> {}'.format('c1', 'prepare input files'))
    print('{} >>> {}'.format('c2', 'analysis output files'))
    #    print('{} >>> {}'.format('c3','summary output files'))

    #sepline(ch=" vasp auto calculation ",sp='=')
    #print('{} >>> {}'.format('d1','optimize structure'))
    #print('{} >>> {}'.format('d2','calculate band structure'))
    #print('{} >>> {}'.format('d3','calculate band structure HSE06'))
    #print('{} >>> {}'.format('d4','calculate dos'))
    #print('{} >>> {}'.format('d5','calculate dos by HSE06'))
    #print('{} >>> {}'.format('d6','calculate elastic properties'))
    #print('{} >>> {}'.format('d7','calculate phonon'))
    #print('{} >>> {}'.format('d8','execute MD simulation'))

    sepline(ch=" online retrieve ", sp='=')
    print('{} >>> {}'.format('e1', 'get band/dos by mp-ID'))
    print('{} >>> {}'.format('e2',
                             'get structure from materialsproject database'))
    print('{} >>> {}'.format('e3', 'get properties by mp-ID'))
    print('{} >>> {}'.format('e4', 'get phase graph'))
    sepline(ch="=", sp='=')

    #TODO
    #    sepline(ch=" siesta tools ",sp='=')
    #    print('{} >>> {}'.format('si1','prepare input files'))
    #    sepline(ch=" gaussian tools ",sp='=')
    #    print('{} >>> {}'.format('gi1','prepare input files'))
    #    sepline(ch=" nwchem tools ",sp='=')
    #    print('{} >>> {}'.format('ni1','prepare input files'))
    #    sepline(ch=" quantum espresso tools ",sp='=')
    #    print('{} >>> {}'.format('qi1','prepare input files'))
    #    sepline(ch=" lammps tools ",sp='=')
    #    print('{} >>> {}'.format('li1','prepare input files'))

    print("")
    print("")
    print("88 >>> exit")
    print("your choice ?")
    wait_sep()
    in_str = ""
    while in_str == "":
        in_str = input().strip()
    select_function(in_str)
コード例 #10
0
ファイル: vaspout.py プロジェクト: wangvei/maptool
def chg_locp_average():
    chg = False
    print("which file would like to average: CHG or LOCPOT ?")
    wait_sep()
    in_str = ""
    while in_str == "":
        in_str = input().strip()
    if in_str.lower() == 'chg':
        filename = 'CHG'
        check_file(filename)
        grid_data = CHGCAR.from_file(filename)
        head_line = "#%(key1)+s %(key2)+s" % {
            'key1': 'Distance/Ang',
            'key2': 'Average Charge/(e/Ang**3)'
        }
        chg = True
    elif in_str.lower() == 'locpot':
        filename = 'LOCPOT'
        check_file(filename)
        grid_data = Locpot.from_file(filename)
        head_line = "#%(key1)+s %(key2)+s" % {
            'key1': 'Distance/Ang',
            'key2': 'Average Potential/(eV)'
        }
    else:
        print('unknown file file: ' + in_str)
        os._exit()

    step_count = 1
    check_file(filename)
    proc_str = "Reading Data From " + filename + " File ..."
    procs(proc_str, step_count, sp='-->>')
    volume = grid_data.structure.volume
    print("which direction would like to average: x y or z ?")
    wait_sep()
    in_str = ""
    while in_str == "":
        in_str = input().strip().lower()
    if in_str == "x":
        selected_dir = 0
    elif in_str == 'y':
        selected_dir = 1
    elif in_str == 'z':
        selected_dir = 2
    else:
        print("Unknow Direction!")
        return

    axis_grid = grid_data.get_axis_grid(selected_dir)
    if chg:
        aver_grid = grid_data.get_average_along_axis(selected_dir) / volume
    else:
        aver_grid = grid_data.get_average_along_axis(selected_dir)

    data = np.vstack((axis_grid, aver_grid)).T

    step_count += 1
    if chg:
        filename = "average_CHG_" + in_str + '.dat'
    else:
        filename = "average_LOCPOT_" + in_str + '.dat'

    proc_str = "Writting Average Data to " + filename + " File ..."
    procs(proc_str, step_count, sp='-->>')
    write_col_data(filename, data, head_line)
コード例 #11
0
ファイル: vaspout.py プロジェクト: wangvei/maptool
def select_one_band_structure():
    check_matplotlib()
    step_count = 1
    filename = 'vasprun.xml'
    check_file(filename)
    proc_str = "Reading Data From " + filename + " File ..."
    procs(proc_str, step_count, sp='-->>')
    vsr = Vasprun(filename)

    step_count += 1
    filename = 'KPOINTS'
    check_file(filename)
    proc_str = "Reading Data From " + filename + " File ..."
    procs(proc_str, step_count, sp='-->>')
    bands = vsr.get_band_structure(filename, line_mode=True, efermi=vsr.efermi)
    nelect = vsr.parameters['NELECT']
    nbands = bands.nb_bands
    if vsr.is_spin:
        proc_str = "This Is a Spin-polarized Calculation."
        procs(proc_str, 0, sp='-->>')
        ISPIN = 2
    else:
        if vsr.parameters['LNONCOLLINEAR']:
            proc_str = "This Is a Non-Collinear Calculation."
            procs(proc_str, 0, sp='-->>')
            ISPIN = 3
        else:
            proc_str = "This Is a Non-Spin Calculation."
            procs(proc_str, 0, sp='-->>')
            ISPIN = 1
    proc_str = "Total band number is " + str(nbands)
    procs(proc_str, 0, sp='-->>')
    proc_str = "Total electron number is " + str(nelect)
    procs(proc_str, 0, sp='-->>')

    print("which band would like to select ?")
    wait_sep()
    in_str = ""
    while in_str == "":
        in_str = input().strip()
    selected_band = int(in_str)

    step_count += 1
    filename = "BAND_" + str(selected_band) + '.dat'
    proc_str = "Writting Selected Band Structure Data to " + filename + " File ..."
    procs(proc_str, step_count, sp='-->>')
    if ISPIN == 1 or ISPIN == 3:
        band_data = bands.bands[Spin.up][selected_band - 1] - vsr.efermi
        data = np.vstack((bands.distance, band_data)).T
        head_line = "#%(key1)+12s%(key2)+13s" % {
            'key1': 'K-Distance',
            'key2': 'Energy(ev)'
        }
        write_col_data(filename, data, head_line, len(band_data))
    else:
        band_data_up = bands.bands[Spin.up][selected_band - 1] - vsr.efermi
        band_data_down = bands.bands[Spin.down][selected_band - 1] - vsr.efermi
        data = np.vstack((bands.distance, band_data_up, band_data_down)).T
        head_line = "#%(key1)+12s%(key2)+13s%(key3)+15s" % {
            'key1': 'K-Distance',
            'key2': 'UpEnergy(ev)',
            'key3': 'DownEnergy(ev)'
        }
        write_col_data(filename, data, head_line, len(band_data_up))
    return