How to use the pymatgen.Lattice function in pymatgen

To help you get started, we’ve selected a few pymatgen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github materialsproject / crystaltoolkit / crystal_toolkit / renderables / lattice.py View on Github external
name = (
        f"a={self.a}, b={self.b}, c={self.c}, "
        f"alpha={self.alpha}, beta={self.beta}, gamma={self.gamma}"
    )

    contents = [Lines(line_pairs, **kwargs)]

    if show_axes:
        contents.append(self._axes_from_lattice())

    return Scene(name, contents, origin=origin)


# TODO: re-think origin, shift globally at end (scene.origin)
Lattice._axes_from_lattice = _axes_from_lattice
Lattice.get_scene = get_lattice_scene
github materialsproject / pymatgen / pymatgen / analysis / interface.py View on Github external
slab_substrate (Slab): substrate structure supercell
            slab_film (Slab): film structure supercell
            offset ([int]): separation vector of film and substrate
        """

        # Check if lattices are equal. If not, strain them to match
        # NOTE: CHANGED THIS TO MAKE COPY OF SUBSTRATE/FILM, self.modified_film_structures NO LONGER STRAINED
        unstrained_slab_substrate = slab_substrate.copy()
        slab_substrate = slab_substrate.copy()
        unstrained_slab_film= slab_film.copy()
        slab_film = slab_film.copy()
        latt_1 = slab_substrate.lattice.matrix.copy()
        latt_1[2, :] = [0, 0, 1]
        latt_2 = slab_film.lattice.matrix.copy()
        latt_2[2, :] = [0, 0, 1]
        if not Lattice(latt_1) == Lattice(latt_2):
            # Calculate lattice strained to match:
            matched_slab_substrate, matched_slab_film = strain_slabs(slab_substrate, slab_film)
        else:
            matched_slab_substrate = slab_substrate
            matched_slab_film = slab_film

        # Ensure substrate has positive c-direction:
        if matched_slab_substrate.lattice.matrix[2, 2] < 0:
            latt = matched_slab_substrate.lattice.matrix.copy()
            latt[2, 2] *= -1
            new_struct = matched_slab_substrate.copy()
            new_struct.lattice = Lattice(latt)
            matched_slab_substrate = new_struct

        # Ensure film has positive c-direction:
        if matched_slab_film.lattice.matrix[2, 2] < 0:
github henniggroup / MPInterfaces / examples / workflows / single_workflow.py View on Github external
from pymatgen.core.structure import Structure
from pymatgen.io.vaspio.vasp_input import Incar, Poscar, Potcar, Kpoints

from fireworks.fw_config import LAUNCHPAD_LOC
from fireworks import Firework, Workflow, LaunchPad
from fireworks.core.rocket_launcher import launch_rocket

from mpinterfaces.firetasks import MPINTCalibrateTask, MPINTMeasurementTask

#---------------------------------------------------------------------
# INITIAL INPUTSET
#---------------------------------------------------------------------
#structure
a0 = 3.965
lattice_matrix = np.array([ [0.5, 0.0, 0.5], [0.5, 0.5, 0.0], [0.0, 0.5, 0.5] ]) * a0
lattice = Lattice(lattice_matrix)
structure = Structure( lattice, ['Pt'], [ [0.0, 0.0, 0.0] ],
                       coords_are_cartesian=False)
incarparams = {'System':'test',
                   'ENCUT': 400,
                   'ISMEAR': 1,
                   'SIGMA': 0.1,
                   'EDIFF':1E-6}
incar = Incar(params=incarparams)
poscar = Poscar(structure, comment='test', selective_dynamics=None)
potcar = Potcar(symbols = poscar.site_symbols, functional='PBE',
                sym_potcar_map=None)
kpoints = Kpoints(kpts=((8, 8, 8),))

#---------------------------------------------------------------------
# FIRETASK
#
github bjmorgan / vasppy / vasppy / poscar.py View on Github external
def to_pymatgen_structure( self ):
        lattice = pmg_Lattice( self.cell.matrix * self.scaling )
        structure = pmg_Structure( lattice, self.labels(), self.coordinates )
        return structure
github materialsproject / pymatgen / pymatgen / analysis / gb / grain.py View on Github external
all_species = []
        all_species.extend([site.specie for site in bottom_grain])
        all_species.extend([site.specie for site in top_grain])

        half_lattice = top_grain.lattice
        # calculate translation vector, perpendicular to the plane
        normal_v_plane = np.cross(half_lattice.matrix[0], half_lattice.matrix[1])
        unit_normal_v = normal_v_plane / np.linalg.norm(normal_v_plane)
        translation_v = unit_normal_v * vacuum_thickness

        # construct the final lattice
        whole_matrix_no_vac = np.array(half_lattice.matrix)
        whole_matrix_no_vac[2] = half_lattice.matrix[2] * 2
        whole_matrix_with_vac = whole_matrix_no_vac.copy()
        whole_matrix_with_vac[2] = whole_matrix_no_vac[2] + translation_v * 2
        whole_lat = Lattice(whole_matrix_with_vac)

        # construct the coords, move top grain with translation_v
        all_coords = []
        grain_labels = bottom_grain.site_properties['grain_label'] + top_grain.site_properties['grain_label']
        for site in bottom_grain:
            all_coords.append(site.coords)
        for site in top_grain:
            all_coords.append(site.coords + half_lattice.matrix[2] * (1 + c_adjust) +
                              unit_ab_adjust * np.linalg.norm(half_lattice.matrix[2] * (1 + c_adjust)) +
                              translation_v + ab_shift[0] * whole_matrix_with_vac[0] +
                              ab_shift[1] * whole_matrix_with_vac[1])

        gb_with_vac = Structure(whole_lat, all_species, all_coords,
                                coords_are_cartesian=True,
                                site_properties={'grain_label': grain_labels})
        # merge closer atoms. extract near gb atoms.
github materialsproject / pymatgen / pymatgen / analysis / interface.py View on Github external
film_struct = align_x(film_slab, get_ortho_axes(sub_struct)).copy()
    latt_2 = film_struct.lattice.matrix.copy()

    # Rotate film so its diagonal matches with the sub's diagonal
    diag_vec = np.add(latt_1[0, :], latt_1[1, :])
    sub_norm_diag_vec = diag_vec / np.linalg.norm(diag_vec)
    sub_b = np.cross(sub_norm_diag_vec, [0, 0, 1])
    sub_matrix = np.vstack([sub_norm_diag_vec, sub_b, [0, 0, 1]])

    diag_vec = np.add(latt_2[0, :], latt_2[1, :])
    film_norm_diag_vec = diag_vec / np.linalg.norm(diag_vec)
    film_b = np.cross(film_norm_diag_vec, [0, 0, 1])
    film_matrix = np.vstack([film_norm_diag_vec, film_b, [0, 0, 1]])

    rotation = np.dot(np.linalg.inv(film_matrix), sub_matrix)
    new_latt = Lattice(np.dot(film_struct.lattice.matrix, rotation))
    film_struct.lattice = new_latt

    # Average the two lattices (Should get equal strain?)
    mean_a = np.mean([film_struct.lattice.matrix[0, :], sub_struct.lattice.matrix[0, :]], axis=0)
    mean_b = np.mean([film_struct.lattice.matrix[1, :], sub_struct.lattice.matrix[1, :]], axis=0)
    new_latt = np.vstack([mean_a, mean_b, sub_struct.lattice.matrix[2, :]])
    sub_struct.lattice = Lattice(new_latt)
    new_latt = np.vstack([mean_a, mean_b, film_struct.lattice.matrix[2, :]])
    film_struct.lattice = Lattice(new_latt)

    return sub_struct, film_struct
github materialsproject / pymatgen / pymatgen / analysis / interface.py View on Github external
def align_x(slab, orthogonal_basis=[[1, 0, 0], [0, 1, 0], [0, 0, 1]]):
    """
    Align the a lattice vector of slab with the x axis. Optionally specify
    an orthogonal_basis to align according to a different set of axes

    Args:
        slab (Slab): input structure
        orthogonal basis (3x3 numpy matrix): If specified, align with
            orthogonal_basis[0] rather than [1,0,0]

    Returns:
        The slab, which has been aligned with the specified axis in place.
    """
    sub_ortho_axes = get_ortho_axes(slab)
    rotation = transf_mat(sub_ortho_axes, orthogonal_basis)
    new_sub_lattice = Lattice(np.dot(slab.lattice.matrix[0:3], rotation))
    slab.lattice = new_sub_lattice
    return slab
github lmhale99 / atomman / atomman / dump / pymatgen_Structure / dump.py View on Github external
A atomman representation of a system.
    symbols : tuple, optional
        List of the element symbols that correspond to the atom types.  If not
        given, will use system.symbols if set, otherwise no element content
        will be included.
    
    Returns
    -------
    structure : pymatgen.Structure
        A pymatgen representation of a structure.
    """
    
    assert has_pmg, 'pymatgen not imported'
    
    # Get box/lattice information
    lattice = pmg.Lattice(system.box.vects)
    
    # Get symbols information
    if symbols is None:
        symbols = system.symbols
    symbols = np.asarray(symbols)
    if None in symbols:
        raise ValueError('Symbols needed for all atypes')
    
    # Convert short symbols list to full species list
    atype = system.atoms.atype
    species = symbols[atype-1]
    
    # Get atomic information
    sites = system.atoms_prop(key='pos', scale=True)
    prop = {}
    for p in system.atoms_prop():
github uw-cmg / MAST / MAST / utility / finite_size_scaling / fss.py View on Github external
for m1 in numpy.arange(0,fsize[1],psize[1]):
            for m2 in numpy.arange(0,fsize[2],psize[2]):
                vect.append([ssize[0]+m0*psize[0],m1,m2])
    
    for m1 in range(padding[1]):
        for m0 in numpy.arange(0,ssize[0],psize[0]):
            for m2 in numpy.arange(0,fsize[2],psize[2]):
                vect.append([m0,ssize[1]+m1*psize[1],m2])
    
    for m2 in range(padding[2]):
        for m0 in numpy.arange(0,ssize[0],psize[0]):
            for m1 in numpy.arange(0,ssize[1],psize[1]):
                vect.append([m0,m1,ssize[2]+m2*psize[2]])
    
    #Construct a new structure with desired size
    new_lat = Lattice(numpy.array([fsize[c] * lv[c] for c in range(3)]))
    final = Structure(new_lat, defst.species_and_occu,defst.cart_coords,
            coords_are_cartesian=True)
    for m0,m1,m2 in vect:
        npos = positions + numpy.dot((m0, m1, m2), lv)
        for i in range(len(npos)):
            final.append(syms[i],npos[i],coords_are_cartesian=True)
    
    #Check for periodic issues in final structure
    final = check_periodic(final,defst)
    
    # Write output as POSCAR
    write_structure(final, 'POSCAR_Final')
    
    return final
github materialsproject / pymatgen / pymatgen / analysis / gb / grain.py View on Github external
structure (pymatgen structure object):
            input structure
        matrix (lattice matrix, 3 by 3 array/matrix)
            new structure's lattice matrix, if none, use
            input structure's matrix

    Return:
        new structure with fixed frac_coords and lattice matrix
    """

    spec = []
    coords = []
    if matrix is None:
        latte = Lattice(structure.lattice.matrix)
    else:
        latte = Lattice(matrix)

    for site in structure:
        spec.append(site.specie)
        coord = np.array(site.frac_coords)
        for i in range(3):
            coord[i] -= floor(coord[i])
            if np.allclose(coord[i], 1):
                coord[i] = 0
            elif np.allclose(coord[i], 0):
                coord[i] = 0
            else:
                coord[i] = round(coord[i], 7)
        coords.append(coord)

    return Structure(latte, spec, coords, site_properties=structure.site_properties)