Example #1
0
def get_rectangular_structure(atoms, order_adjust=True, iax=2, eps=1e-7):

    #print(atoms.cell)
    P = [[1, 1, 0], [-1, 1, 0], [0, 0, 1]]
    atoms_rec = make_supercell(atoms, P)

    ## check cell shape
    for i1 in range(3):
        for i2 in range(3):
            if i1 == i2:
                continue
            if abs(atoms_rec.cell[i1, i2]) > eps:
                print("Error", atoms_rec.cell[i1, i2])
                exit()
            else:
                atoms_rec.cell[i1, i2] = 0.
    ##
    atoms_rec.wrap()

    ##
    if order_adjust:
        atoms_new = get_ordered_structure(atoms_rec, iax=iax)
        return atoms_new
    else:
        return atoms_rec
Example #2
0
def hcp_supercell(pgpa, natom, tmat=None, force=False):
  from ase.build.supercells import make_supercell
  a, c = hcp_ac(pgpa, force=force)
  atoms0 = hcp_prim_cell(a, c/a)
  if tmat is None:
    tmat = get_tilematrix(natom)
  atoms1 = make_supercell(atoms0, tmat)
  return atoms1
Example #3
0
def build_supercell(unitcell, R_c):
    """
    build supercell from a given unitcell

    Parameters
    ----------
    unitcell: ASE atoms object for the unitcell
    R_c: cutoff distance (in Angstroms)

    Returns
    -------
    supercell: ASE atoms object for the supercell
    number of atoms in the unitcell

    """

    [n1, n2, n3] = [
        np.ceil(R_c / length)
        for length in unitcell.get_cell_lengths_and_angles()[:3]
    ]

    supercell = make_supercell(
        unitcell, [[2 * n1 + 1, 0, 0], [0, 2 * n2 + 1, 0], [0, 0, 2 * n3 + 1]])

    # wrap supercell so that original unitcell is in the center
    supercell.wrap(center=(0.5 / (2 * n1 + 1), 0.5 / (2 * n2 + 1),
                           0.5 / (2 * n3 + 1)))

    coords1, elements1 = [
        supercell.get_positions(),
        supercell.get_chemical_symbols()
    ]

    # sort atoms so that atoms in the original unitcell are listed first in
    # the supercell
    # and trim away atoms that are not within cutiff distance of any atoms
    # in the unitcell
    coords, elements = [
        unitcell.get_positions().tolist(),
        unitcell.get_chemical_symbols()
    ]
    R = cdist(unitcell.get_positions(), np.asarray(coords1))
    for j in range(len(coords1)):
        if np.any(np.less(R[:, j], 1E-08)):
            # if atom in unitcell, do not add to the list
            continue
        elif np.any(np.less_equal(R[:, j], R_c)):
            # if atom is within cutoff distance of an atom in the unitcell,
            # add to the list
            coords.append(coords1[j])
            elements.append(elements1[j])

    return coords, elements, len(unitcell.positions)
Example #4
0
def find_cell(tsize):
    #atoms = bulk("Al", crystalstructure="sc", a=5.0)
    a = 10.0
    atoms = Atoms(["Al", "Mg"],
                  positions=[[0.0, 0.0, 0.0], [a / 2.0, a / 2.0, a / 2.0]],
                  cell=[a, a, a])
    view(atoms)
    trans = sc.find_optimal_cell_shape_pure_python(atoms.cell, tsize, "sc")
    atoms = sc.make_supercell(atoms, trans)
    print(len(atoms))

    #atoms.set_cell(cell)
    view(atoms)
def test_conventional_map(lat):
    if not hasattr(lat, 'conventional_cellmap'):
        pytest.skip()

    conv_lat = lat.conventional()
    prim_atoms = Atoms('Au', cell=lat.tocell(), pbc=1)
    conv_atoms = make_supercell(prim_atoms, lat.conventional_cellmap)

    e1 = emt_energy_per_atom(prim_atoms)
    e2 = emt_energy_per_atom(conv_atoms)

    assert e1 == pytest.approx(e2)
    assert conv_lat.cellpar() == pytest.approx(conv_atoms.cell.cellpar())

    # Rule out also that cells could differ by a rotation:
    assert conv_lat.tocell()[:] == pytest.approx(conv_atoms.cell[:])
Example #6
0
def make_super(base_dir="./", super_cell=[2, 2, 1]):
    traj_fin_filename = os.path.join(base_dir,
                                     "relaxed.traj")
    assert os.path.exists(traj_fin_filename)  # Should exists
    atoms = ase.io.read(traj_fin_filename)      # final image
    super_atoms = make_supercell(atoms,
                                 numpy.diag(super_cell))
    # Add fixation for All VO
    scaled_pos = super_atoms.get_scaled_positions()
    lim = 0.3
    cond = list(numpy.where((scaled_pos[:, -1] < lim) \
                       | (scaled_pos[:, -1] > 1 - lim)))[0]
    parprint(cond)
    constraints = FixAtoms(list(cond))
    super_atoms.set_constraint(constraints)
    return super_atoms
Example #7
0
def get_supercell(slab):
    '''
        This function returns a 3 by 3 supercell of the original cell
    '''
    P = [[3, 0, 0], [0, 3, 0], [0, 0, 1]]
    supercell = make_supercell(slab, P)
    slab_cell = slab.cell
    x = np.array(supercell.positions[:,0]
                 - (slab_cell[0][0] + slab_cell[1][0]),
                 dtype = 'double', order = 'C')
    y = np.array(supercell.positions[:,1]
                 - (slab_cell[1][1]),
                 dtype = 'double', order = 'C')
    z = np.array(supercell.positions[:,2],
                 dtype = 'double', order = 'C')
    symbol = np.array(supercell.get_chemical_symbols(),
                      dtype = 'str', order = 'C')
    atomic_number = np.array(supercell.get_atomic_numbers(),
                             dtype = 'str', order = 'C')
    return [symbol, atomic_number, x, y, z]
Example #8
0
def get_FeCl3mols_intercalated_graphite(nprim=[2, 2, 1],
                                        ncells=[1, 1, 1],
                                        rectangular=True,
                                        iaxial=2,
                                        layer_distance=3.35,
                                        mol_distance=3.0):
    """
    Parameters
    --------------
    nprim : array, shape=(3)
        number of primitive unit cells of graphene along its translational
        vectors
    ncells : array, shape=(3)
        number of unit cells
    rectangular : bool
        False returns the primitive unit cell of the intercalated structure,
        while True returns the rectangular cell.
    layer_distance : float
        distance between graphene layers
    mol_distance : float
        distance between FeCl3-layer and graphene layer
    """
    fecl3 = get_pubchem_structure(cid=24380)
    intercalated = get_gic_structure(nprim=nprim,
                                     molecule=fecl3,
                                     layer_distance=layer_distance,
                                     distance=mol_distance)
    if rectangular:
        intercalated = get_rectangular_structure(intercalated)

    ## make a supercell
    if ncells:
        intercalated = make_supercell(
            intercalated,
            [[ncells[0], 0, 0], [0, ncells[1], 0], [0, 0, ncells[2]]])
    atoms_new = get_ordered_structure(intercalated, iax=iaxial)

    return atoms_new
Example #9
0
if prm.visualize == True:
    view(initial_pos)

# get atomic species
fin = [initial_pos.get_chemical_symbols()[0]]
for i in range(len(initial_pos.get_chemical_symbols())):
    if i == len(initial_pos.get_chemical_symbols()) - 1: break
    if initial_pos.get_chemical_symbols(
    )[i] != initial_pos.get_chemical_symbols()[i + 1]:
        fin.append(initial_pos.get_chemical_symbols()[i + 1])

# make supercell
#----------------------------
if prm.get_super == True:
    del initial_pos.constraints
    super_cell = make_supercell(initial_pos, Tmat)

    # some post processing...
    #----------------------------
    indices = []
    symbls = []
    for symbol in fin:
        ii = 0
        for atom in super_cell.get_chemical_symbols():
            if atom == symbol:
                indices.append(ii)  # get sorted atomic index
                symbls.append(symbol)  # get sorted atomic symbols
            ii += 1

    pos_new = [super_cell.get_positions()[i] for i in indices]
    super_cell.set_positions(pos_new)
def ciftoxyzfunc(name, size=[1,1,1]):
    a = read(name)
    b = sc.make_supercell(a,[[size[0],0,0],[0,size[1],0],[0,0,size[2]]])
    b.write(name+'.xyz',format='xyz')
Example #11
0
                    help="Output file name (including extension - "
                    "if not given a default name will be created from the "
                    "input one)")

args = parser.parse_args()

# Input structure
struct = io.read(args.input_file)

# Build the supercell matrix
scell_arg = np.array(args.supercell)
if scell_arg.shape not in ((1, ), (3, ), (9, )):
    sys.exit('Invalid supercell argument shape '
             '(use either 1, 3 or 9 numbers)')

if scell_arg.shape == (1, ):
    scell_mat = np.eye(3) * scell_arg[0]
elif scell_arg.shape == (3, ):
    scell_mat = np.diag(scell_arg)
else:
    scell_mat = scell_arg.reshape((3, 3))

struct_scell = make_supercell(struct, scell_mat)

# Create output file name if needed
if args.output == None:
    ofile = '-scell'.join(os.path.splitext(args.input_file))
else:
    ofile = args.output

io.write(ofile, struct_scell)
Example #12
0
def make_supercell_li():
    crys = bulk('Li', 'bcc', a=3.51, orthorhombic=True)
    P = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) * 10
    return make_supercell(crys, P)
Example #13
0
def make_supercell_cu():
    crys = bulk('Cu', 'fcc', a=3.6, orthorhombic=True)
    P = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]) * 5
    return make_supercell(crys, P)
Example #14
0
from ase.io import read, write
from ase import Atoms
from ase import geometry
from ase.build.supercells import make_supercell
import numpy as np

#Read structure from POSCAR, this is ase.atom object
struc = read('gra.vasp',format='vasp')

#make supercell here
P = np.array([[1,-1,0],[1,1,0],[0,0,1]])*2
gra1 = make_supercell(struc, P)

#After the lattice transformation
#the supercell might have unpleasant shape
#let's apply another transformation here
cell_par = gra1.get_cell_lengths_and_angles()
pos1 = gra1.get_scaled_positions()
cell1 = geometry.cell.cellpar_to_cell(cell_par)
gra1.set_cell(cell1)
gra1.set_scaled_positions(pos1)

#output in any format whichever you want
write('POSCAR',gra1, format='vasp')