def test_doubleatomsymm(): """ Bugs when calling atomsymm twice. """ from tempfile import mkdtemp from shutil import rmtree from os.path import exists from pylada.dftcrystal import Crystal from pylada.misc import Changedir c = Crystal(136, 4.63909875, 2.97938395, ifhr=0, shift=0) \ .add_atom(0, 0, 0, 'Ti') \ .add_atom(0.306153, 0.306153, 0, 'O') \ .append('ATOMSYMM') directory = '/tmp/test' #mkdtemp() if directory == '/tmp/test': if exists(directory): rmtree(directory) with Changedir(directory) as cwd: pass try: c.append('ATOMSYMM') c.eval() finally: if directory != '/tmp/test': rmtree(directory)
def test(): from numpy import all, abs, dot, identity from pylada.dftcrystal import Crystal, External from pylada.crystal import which_site orig = Crystal(227, 5.43).add_atom(0.125, 0.125, 0.125, 'Si') b = External(copy=orig.eval()) assert all(abs(orig.eval().cell - b.initial.cell) < 1e-8) assert len(b.initial) == 2 assert repr(b) == repr( eval(repr(b), {'External': External}) ) assert len(b.print_input().splitlines()) == 2 assert b.print_input().splitlines()[0] == 'EXTERNAL' assert b.print_input().splitlines()[1] == 'END EXTERNAL' # check that symmetries as extracted are ok. for atom in b.initial: for op in orig.symmetry_operators: assert all(abs(identity(3, dtype='float64') - dot(op[:3].T, op[:3])) < 1e-8) assert which_site(dot(op[:3], atom.pos) + op[3], b.initial) != -1 # Check that running structure through crystal works c = b.eval() assert all(abs(c.cell - b.cell) < 1e-8) assert len(c) == 2 assert all(abs(abs(c[0].pos) - [0.67875]*3) < 1e-8) assert all(abs(abs(c[1].pos) - [0.67875]*3) < 1e-8) assert all(abs(c[0].pos + c[1].pos) < 1e-8)
def test(): """ Tests functional prints and reads itself """ from pylada.dftcrystal.functional import Functional from pylada.dftcrystal import Crystal from pylada.dftcrystal.parse import parse parsed = parse(string) structure = Crystal() structure.read_input(parsed['rutile']['CRYSTAL']) a = Functional() a.read_input(parsed) assert a.scfdir assert a.maxcycle == 300 assert a.exchsize == 6937578 # need structure otherwise parse can't find beginning of input. otherstring = a.print_input(structure=structure) otherparsed = parse(otherstring) b = Functional() b.read_input(otherparsed) assert otherstring == b.print_input(structure=structure)
def test_output_map(): from pylada.dftcrystal import Functional, Crystal from pylada.dftcrystal.parse import parse a = Functional() parsed = parse(input)[''] a.basis.read_input(parsed['BASISSET']) structure = Crystal() structure.read_input(parsed['CRYSTAL']) o = a.basis.output_map(structure=structure) assert len(o) == 1 assert o[0] == ('ghosts', '2\n1 2') a.basis.ghosts.breaksym = False o = a.basis.output_map(structure=structure) assert len(o) == 2 assert o[0] == ('keepsymm', True) assert o[1] == ('ghosts', '2\n1 2') b = Functional() b.basis.raw = o.prefix assert set(b.basis) == set(['O', 'Ti']) assert repr(b.basis['O']) == repr(a.basis['O']) assert repr(b.basis['Ti']) == repr(a.basis['Ti'])
def test_breaksym(): from pylada.dftcrystal import Crystal, Functional, Shell, DisplaceAtoms, read functional = Functional() functional.basis['Si'] = [ Shell('s', a0=[16120.0, 0.001959], a1=[2426.0, 0.01493], a2=[553.9, 0.07285], a3=[156.3, 0.2461], a4=[50.07, 0.4859], a5=[17.02, 0.325]), Shell('sp', a0=[292.7, -0.002781, 0.004438], a1=[69.87, -0.03571, 0.03267], a2=[22.34, -0.115, 0.1347], a3=[8.15, 0.09356, 0.3287], a4=[3.135, 0.603, 0.4496]), Shell('sp', 4.0, a0=[1.22, 1.0, 1.0]), Shell('sp', 0.0, a0=[0.55, 1.0, 1.0]), Shell('sp', 0.0, a0=[0.27, 1.0, 1.0]) ] functional.dft.pbe0 = True functional.fmixing = 30 functional.shrink = 8, 16 functional.levshift = 5, True functional.maxcycle = 600 functional.optgeom.keepsymm = True functional.optgeom.enabled = True crystal = Crystal(227, 5.43).add_atom(0.125, 0.125, 0.125, 'Si') crystal.append('breaksym') crystal.append(DisplaceAtoms().add_atom(0.01, 0, 0, 1)) string = functional.print_input(structure=crystal) assert string.splitlines()[10] == 'KEEPSYMM' cry, func = read(string) assert cry.is_breaksym assert func.optgeom.enabled assert func.optgeom.keepsymm functional.optgeom.keepsymm = False string = functional.print_input(structure=crystal) assert string.splitlines()[10] == 'OPTGEOM' cry, func = read(string) assert cry.is_breaksym assert func.optgeom.enabled assert func.optgeom.breaksym crystal[0] = 'keepsymm' string = functional.print_input(structure=crystal) assert string.splitlines()[11] == 'BREAKSYM' cry, func = read(string) assert not cry.is_breaksym assert func.optgeom.enabled assert func.optgeom.breaksym functional.optgeom.keepsymm = True string = functional.print_input(structure=crystal) assert string.splitlines()[11] == 'OPTGEOM' cry, func = read(string) assert not cry.is_breaksym assert func.optgeom.enabled assert func.optgeom.keepsymm string = crystal.print_input() crystal.append('keepsymm') crystal.append('keepsymm') assert crystal.print_input() == string crystal.append('breaksym') assert crystal.print_input() != string assert len(crystal.print_input().splitlines()) == len(string.splitlines()) + 1
def test(): from tempfile import mkdtemp from numpy import array, all, abs from shutil import rmtree from os.path import exists from os import mkdir from pylada.dftcrystal import Crystal, relax, Shell, DisplaceAtoms from pylada import default_comm functional = relax.Relax() functional.basis['Si'] = [ Shell('s', a0=[16120.0, 0.001959], a1=[2426.0, 0.01493], a2=[553.9, 0.07285], a3=[156.3, 0.2461], a4=[50.07, 0.4859], a5=[17.02, 0.325]), Shell('sp', a0=[292.7, -0.002781, 0.004438], a1=[69.87, -0.03571, 0.03267], a2=[22.34, -0.115, 0.1347], a3=[8.15, 0.09356, 0.3287], a4=[3.135, 0.603, 0.4496]), Shell('sp', 4.0, a0=[1.22, 1.0, 1.0]), Shell('sp', 0.0, a0=[0.55, 1.0, 1.0]), Shell('sp', 0.0, a0=[0.27, 1.0, 1.0]) ] functional.dft.pbe0 = True functional.fmixing = 30 functional.optgeom.fulloptg = True functional.shrink = 8, 16 functional.levshift = 5, True functional.maxcycle = 600 functional.guessp = True functional.optgeom.keepsymm = True crystal = Crystal(227, 5.43).add_atom(0.125, 0.125, 0.125, 'Si') crystal.append('fraction') crystal.append('keepsymm') crystal.append(DisplaceAtoms().add_atom(0.01, 0, 0, 1)) directory = mkdtemp() if directory == '/tmp/test/' and exists(directory): rmtree(directory) mkdir(directory) try: results = functional(crystal, outdir=directory, comm=default_comm) assert results.success # check that final crystals are same as final structures. for crystal, structure in zip(results.details.crystal.itervalues(), results.details.structure.itervalues()): estruc = crystal.eval() assert all(abs(estruc.cell - structure.cell) < 1e-8) assert all(abs( array([a.pos for a in estruc]) - array([a.pos for a in structure]) ) < 1e-8) assert all( array([a.type for a in estruc]) == array([a.type for a in structure]) ) instruc = results.details.input_crystal.values()[1:] + [results.crystal] outstruc = results.details.structure.values() for a, b in zip(instruc, outstruc): a = a.eval() assert all(abs(a.cell - b.cell) < 1e-8) assert all(abs( array([v.pos for v in a]) - array([v.pos for v in b]) ) < 1e-8) assert all( array([v.type for v in a]) == array([v.type for v in b]) ) finally: if directory != '/tmp/test/': rmtree(directory) pass