Exemple #1
0
                substrate_slab,
                mat2d_slab,
                max_area=40,
                max_mismatch=0.05,
                max_angle_diff=20,
                r1r2_tol=0.01)
            substrate_slab_aligned.to(fmt='poscar',
                                      filename=address + os.sep +
                                      'POSCAR_substrate_aligned.vasp')
            mat2d_slab_aligned.to(fmt='poscar',
                                  filename=address + os.sep +
                                  'POSCAR_mat2d_aligned.vasp')
            substrate_bulk.to(fmt='poscar',
                              filename=address + os.sep +
                              'POSCAR_substrate_bulk.vasp')
            hetero_interfaces = transformations.generate_all_configs(
                mat2d_slab_aligned, substrate_slab_aligned, nlayers_2d,
                nlayers_substrate, separation)

            for i, iface in enumerate(hetero_interfaces):
                sd_flags = CalibrateSlab.set_sd_flags(interface=iface,
                                                      n_layers=nlayers_2d +
                                                      nlayers_substrate,
                                                      top=True,
                                                      bottom=False)
                poscar = pymatgen.io.vasp.inputs.Poscar(
                    iface, selective_dynamics=sd_flags)
                poscar.write_file(filename=address + os.sep +
                                  'POSCAR_final_{}.vasp'.format(i))
        counter += 1
Exemple #2
0
def upload_file():
    stamp = ""
    if request.method == 'POST':
        #request.environ['REMOTE_ADDR']
        if request.environ.get('HTTP_X_FORWARDED_FOR') is None:
            ip = request.environ['REMOTE_ADDR']
        else:
            ip = request.environ['HTTP_X_FORWARDED_FOR']  # if behind a proxy
        #substrate information#
        f1 = request.files['POSCAR_sub']
        stamp = time.strftime("%Y%m%d-%H%M%S") + '-' + ip
        poscar_sub = stamp + '-' + f1.filename
        f1.save(upload_dir + os.sep + secure_filename(poscar_sub))
        h_sub = int(request.form["h_sub"])
        k_sub = int(request.form["k_sub"])
        l_sub = int(request.form["l_sub"])
        nlayers_substrate = int(request.form["nlayers_substrate"])
        min_thick_sub = float(request.form["min_thick_sub"])
        min_vac_sub = float(request.form["min_vac_sub"])
        #is_primitive      = request.form.get["is_primitive"]
        hkl_sub = [h_sub, k_sub, l_sub]

        #2d information#
        f2 = request.files['POSCAR_2d']
        poscar_2d = stamp + '-' + f2.filename
        f2.save(upload_dir + os.sep + secure_filename(poscar_2d))
        h_2d = int(request.form["h_2d"])
        k_2d = int(request.form["k_2d"])
        l_2d = int(request.form["l_2d"])
        nlayers_2d = int(request.form["nlayers_2d"])
        hkl_2d = [h_2d, k_2d, l_2d]

        #General information#
        separation = float(request.form["separation"])
        max_area = float(request.form["max_area"])
        max_mismatch = float(request.form["max_mismatch"])
        max_angle_diff = float(request.form["max_angle_diff"])

        #Matching#
        try:
            substrate_bulk = pymatgen.Structure.from_file(upload_dir + os.sep +
                                                          poscar_sub)
            sa_sub = pymatgen.symmetry.analyzer.SpacegroupAnalyzer(
                substrate_bulk)
            substrate_bulk = sa_sub.get_conventional_standard_structure()
            substrate_slab = Interface(substrate_bulk,
                                       hkl=hkl_sub,
                                       min_thick=min_thick_sub,
                                       min_vac=min_vac_sub,
                                       primitive=False,
                                       from_ase=True)

            mat2d_slab = utils.slab_from_file(hkl_2d,
                                              upload_dir + os.sep + poscar_2d)
            operation_dir = "static" + os.sep + "operations" + os.sep + stamp
            if not os.path.exists(operation_dir):
                os.makedirs(operation_dir)
            mat2d_slab.to(fmt="poscar",
                          filename=operation_dir + "POSCAR_mat2d_slab.vasp")
            sd_flags = CalibrateSlab.set_sd_flags(interface=substrate_slab,
                                                  n_layers=nlayers_substrate,
                                                  top=True,
                                                  bottom=False)
            poscar = pymatgen.io.vasp.inputs.Poscar(
                substrate_slab, selective_dynamics=sd_flags)
            poscar.write_file(filename=operation_dir + os.sep +
                              "POSCAR_substrate_slab.vasp")
            substrate_slab_aligned, mat2d_slab_aligned, mismatch = transformations.get_aligned_lattices(
                substrate_slab,
                mat2d_slab,
                max_area=max_area,
                max_mismatch=max_mismatch,
                max_angle_diff=max_angle_diff,
                r1r2_tol=0.01)
            substrate_slab_aligned.to(fmt="poscar",
                                      filename=operation_dir + os.sep +
                                      "POSCAR_substrate_aligned.vasp")
            mat2d_slab_aligned.to(fmt="poscar",
                                  filename=operation_dir + os.sep +
                                  "POSCAR_mat2d_aligned.vasp")
            hetero_interfaces = transformations.generate_all_configs(
                mat2d_slab_aligned, substrate_slab_aligned, nlayers_2d,
                nlayers_substrate, separation)
            for i, iface in enumerate(hetero_interfaces):
                sd_flags = CalibrateSlab.set_sd_flags(interface=iface,
                                                      n_layers=nlayers_2d +
                                                      nlayers_substrate,
                                                      top=True,
                                                      bottom=False)
                poscar = pymatgen.io.vasp.inputs.Poscar(
                    iface, selective_dynamics=sd_flags)
                poscar.write_file(filename=operation_dir + os.sep +
                                  'POSCAR_final_{}.vasp'.format(i))

                p = Poscar.from_file(operation_dir + os.sep +
                                     'POSCAR_final_{}.vasp'.format(i))
                w = CifWriter(p.structure)
                w.write_file(operation_dir + os.sep +
                             'POSCAR_final_{}.cif'.format(i))


#                st = pychemia.code.vasp.read_poscar(operation_dir+os.sep+'POSCAR_final_{}.vasp'.format(i))
#rf = open("testing")
#rf.write("reading succesful")
#rf.close()
#                pychemia.io.cif.save(structure=st,filename=operation_dir+os.sep+'POSCAR_final_{}.xyz'.format(i))
        except:
            #redirect(url_for("error",_id="matching",stamp=stamp))
            return ("Error")

        return redirect(url_for('result', stamp=stamp))
    return render_template("matching.html",
                           _id="matching",
                           test_var="test",
                           stamp=stamp)
def create_heterostructure(
    bulk_structure=None,
    slab_structure=None,

    strain_sys="overlayer",  # 'support' or 'overlayer'

    surface_cut=[0, 0, 1],
    separation=3,
    nlayers_2d=1,
    nlayers_substrate=4,

    # Lattice matching algorithm parameters
    max_area=40,
    max_mismatch=1,
    max_angle_diff=0.1,
    r1r2_tol=0.01,
    ):
    """

    bulk_structure:
        ase atoms object for the support material
    slab_structure:
        overlayer material

    strain_sys:
    surface_cut:
    separation:
    nlayers_2d:
    nlayers_substrate:
    max_area:
    max_mismatch:
    max_angle_diff:
    r1r2_tol:

    """
    #| - create_heterostructure

    #| - Generate Heterostructures
    # substrate_bulk = Structure.from_file(bulk_filename)

    substrate_slab = Interface(
        bulk_structure,
        # substrate_bulk,
        hkl=surface_cut,
        min_thick=20,
        min_vac=30,
        primitive=False,
        from_ase=True,
        )

    # mat2d_slab = slab_from_file([0, 0, 1], graphene_filename)
    mat2d_slab = slab_structure

    if strain_sys == "support":
        lower_mat = mat2d_slab
        upper_mat = substrate_slab
    elif strain_sys == "overlayer":
        lower_mat = substrate_slab
        upper_mat = mat2d_slab

    # mat2d_slab_aligned, substrate_slab_aligned = get_aligned_lattices(
    lower_mat_aligned, upper_mat_aligned = get_aligned_lattices(
        lower_mat,
        upper_mat,
        max_area=max_area,
        max_mismatch=max_mismatch,
        max_angle_diff=max_angle_diff,
        r1r2_tol=r1r2_tol,
        )

    if strain_sys == "support":
        mat2d_slab_aligned = lower_mat_aligned
        substrate_slab_aligned = upper_mat_aligned
    elif strain_sys == "overlayer":
        mat2d_slab_aligned = upper_mat_aligned
        substrate_slab_aligned = lower_mat_aligned


    # Writing hetero_interfaces to pickle file
    with open('aligned_latt_materials.pickle', 'wb') as fle:
        pickle.dump((substrate_slab_aligned, mat2d_slab_aligned), fle)

    substrate_slab_aligned.to(filename='00_substrate_opt.POSCAR')
    mat2d_slab_aligned.to(filename='00_graphene_opt.POSCAR')

    # merge substrate and mat2d in all possible ways
    hetero_interfaces = generate_all_configs(
        mat2d_slab_aligned,
        substrate_slab_aligned,
        nlayers_2d,
        nlayers_substrate,
        separation,
        )

    # Writing hetero_interfaces to pickle file
    with open('hetero_interfaces.pickle', 'wb') as fle:
        pickle.dump(hetero_interfaces, fle)
    #__|

    return(hetero_interfaces)
    # mat2d_slab_aligned, substrate_slab_aligned = get_aligned_lattices(
    lower_mat_aligned, upper_mat_aligned = get_aligned_lattices(
        lower_mat,
        upper_mat,
        max_area=max_area,
        max_mismatch=max_mismatch,
        max_angle_diff=max_angle_diff,
        r1r2_tol=r1r2_tol,
    )

    # merge substrate and mat2d in all possible ways
    hetero_interfaces = generate_all_configs(
        lower_mat_aligned,
        upper_mat_aligned,
        nlayers_2d,
        nlayers_substrate,
        separation,
    )

    out_dir = os.path.join(
        '01_heterostructures',
        str(surface_cut[0]) + str(surface_cut[1]) + str(surface_cut[2]))

    if not os.path.exists(out_dir):
        os.makedirs(out_dir)

    for i, iface in enumerate(hetero_interfaces):
        atoms = AseAtomsAdaptor.get_atoms(iface)
        io.write(
            os.path.join(