def rotatedCrystal(V,size=(2,2,1),a=1.3968418):
"""
Generates a triangular crystal lattice of the given size and rotates it so that the new unit vectors
align with the columns of V. The positions are set so that the center atom is at the
origin. Size is expected to be even in all directions.
'a' is the atomic distance between the atoms of the hexagonal lattice daul to this crystal.
In other words, a*sqrt(3) is the lattice constant of the triangular lattice.
The returned object is of ase.Atoms type
"""
numbers = [6.0]
cell = numpy.array([[a*(3.0**0.5),0,0],[0.5*a*(3.0**0.5),1.5*a,0],[0,0,10*a]])
positions = numpy.array([[0,0,0]])
cr = ase.Atoms(numbers=numbers,positions=positions,cell=cell,pbc=[True,True,True])
# Repeating
ix = numpy.indices(size, dtype=int).reshape(3,-1)
tvecs = numpy.einsum('ki,kj',ix,cr.cell)
rPos = numpy.ndarray((len(cr)*len(tvecs),3))
for i in range(len(cr)):
rPos[i*len(tvecs):(i+1)*len(tvecs)] = tvecs + cr.positions[i]
# New cell size
for i in range(3):
cr.cell[i]*=size[i]
cr = Atoms(symbols=['C']*len(rPos), positions=rPos, cell = cr.cell, pbc=[True,True,True])
center = numpy.sum(cr.cell,axis=0)*0.5
cr.positions = cr.positions - center
cr.cell = numpy.einsum('ik,jk',cr.cell,V)
cr.positions = numpy.einsum('ik,jk',cr.positions,V)
return cr
评论列表
文章目录