def test_occmap(): from numpy import cos, sin, pi, abs, all from pylada.crystal import binary from pylada.ce import Cluster lattice = binary.zinc_blende() for atom in lattice: atom.type = ['Si', 'Ge'] a = Cluster(lattice) mapping = a.occupation_mapping() assert len(mapping) == len(lattice) assert len(mapping[0]) == 2 assert len(mapping[1]) == 2 assert abs(mapping[0]['Si'] - cos(2e0*pi*0e0/2.0)) < 1e-8 assert abs(mapping[0]['Ge'] - cos(2e0*pi*1e0/2.0)) < 1e-8 assert abs(mapping[1]['Si'] - cos(2e0*pi*0e0/2.0)) < 1e-8 assert abs(mapping[1]['Ge'] - cos(2e0*pi*1e0/2.0)) < 1e-8 lattice = binary.zinc_blende() lattice[1].type = ['Si', 'Ge', 'C'] a = Cluster(lattice) mapping = a.occupation_mapping() assert len(mapping) == len(lattice) assert mapping[0] is None assert len(mapping[1]) == len(lattice[1].type) assert all(abs(mapping[1]['C'] - [cos(2e0*pi*0e0/3.0), sin(2e0*pi*2e0/3.0)])) assert all(abs(mapping[1]['Si'] - [cos(2e0*pi*1e0/3.0), sin(2e0*pi*1e0/3.0)])) assert all(abs(mapping[1]['Ge'] - [cos(2e0*pi*2e0/3.0), sin(2e0*pi*2e0/3.0)]))
def test_onsite(): """ Tests J0 PI calculation. This uses the same algorithmic pathway as more complex figures, but can be easily computed as the sum of particular specie-dependent terms on each site. """ from numpy import dot, abs, all from random import choice from pylada.crystal import binary, supercell from pylada.ce import Cluster lattice = binary.zinc_blende() for atom in lattice: atom.type = ['Si', 'Ge', 'C'] structure = binary.zinc_blende() for atom in structure: atom.type = 'Si' a = Cluster(lattice) # Empty cluster first assert abs(a(structure) - len(structure)) < 1e-8 for i in xrange(10): superstructure = supercell(lattice, dot(lattice.cell, get_cell())) for atom in superstructure: atom.type = choice(atom.type) assert abs(a(superstructure) - len(superstructure)) < 1e-8 # Try on-site cluster. # loop over random supercells. # PI should be number of proportional to number of each atomic type on each # site, or thereabouts mapping = a.occupation_mapping() for i in xrange(10): # create random superstructure superstructure = supercell(lattice, dot(lattice.cell, get_cell())) for atom in superstructure: atom.type = choice(atom.type) # now first and second site clusters for i, site in enumerate(lattice): # loop over flavors. types = [u.type for u in superstructure] a.spins = None a.add_spin(site.pos) s = mapping[i].itervalues().next().copy() s[:] = 0e0 for t in site.type: s += float(types.count(t)) * mapping[i][t] assert all(abs(a(superstructure) - s) < 1e-8)