def test_cpmd_write_format(): Mol = Molecule() Mol.setCellDim(1, fmt='angstrom') Mol.setVec(((5, 0, 0), (0, 5, 0), (0, 0, 5))) Mol.newAtom('Na', (0, 0, 0), fmt='crystal') Mol.newAtom('Cl', (0.5, 0.5, 0.5), fmt='crystal') p = newParam('cpmd') p["&INFO"] = "comment\n" p["&CPMD"] = " MOLECULAR DYNAMICS CP\n RESTART "\ "WAVEFUNCTION COORDINATES LATEST\n" fmts = ['bohr', 'angstrom', 'crystal', 'alat'] head = "&INFO\n"\ "comment\n"\ "&END\n"\ "&CPMD\n"\ " MOLECULAR DYNAMICS CP\n RESTART "\ "WAVEFUNCTION COORDINATES LATEST\n"\ "&END\n"\ "&SYSTEM\n" body = [" CELL VECTORS\n" " 9.4486 0.0000 0.0000\n" " 0.0000 9.4486 0.0000\n" " 0.0000 0.0000 9.4486\n" "&END\n" "&ATOMS\n" "*Na.uspp736.pbe BINARY\n" " LMAX=F\n" " 1\n" " 0.0000 0.0000 0.0000\n" "*Cl.uspp736.pbe BINARY\n" " LMAX=F\n" " 1\n" " 4.7243 4.7243 4.7243\n", " ANGSTROM\n" " CELL VECTORS\n" " 5.0000 0.0000 0.0000\n" " 0.0000 5.0000 0.0000\n" " 0.0000 0.0000 5.0000\n" "&END\n" "&ATOMS\n" "*Na.uspp736.pbe BINARY\n" " LMAX=F\n" " 1\n" " 0.0000 0.0000 0.0000\n" "*Cl.uspp736.pbe BINARY\n" " LMAX=F\n" " 1\n" " 2.5000 2.5000 2.5000\n", " SCALE\n" " CELL VECTORS\n" " 9.4486 0.0000 0.0000\n" " 0.0000 9.4486 0.0000\n" " 0.0000 0.0000 9.4486\n" "&END\n" "&ATOMS\n" "*Na.uspp736.pbe BINARY\n" " LMAX=F\n" " 1\n" " 0.0000 0.0000 0.0000\n" "*Cl.uspp736.pbe BINARY\n" " LMAX=F\n" " 1\n" " 0.5000 0.5000 0.5000\n", " SCALE\n" " CELL VECTORS\n" " 9.4486 0.0000 0.0000\n" " 0.0000 9.4486 0.0000\n" " 0.0000 0.0000 9.4486\n" "&END\n" "&ATOMS\n" "*Na.uspp736.pbe BINARY\n" " LMAX=F\n" " 1\n" " 0.0000 0.0000 0.0000\n" "*Cl.uspp736.pbe BINARY\n" " LMAX=F\n" " 1\n" " 0.5000 0.5000 0.5000\n"] tail = "ISOTOPE\n"\ "22.99\n"\ "35.453\n"\ "&END\n" for i in range(len(body)): target = head + body[i] + tail Mol.setFmt(fmts[i]) f = StringIO() cpmd.writer(Mol, f, p) assert f.getvalue() == target
def assertKpoint(): f = StringIO() cpmd.writer(Mol, f, p) f = f.getvalue() assert f == target
def test_cpmd_write_kpoints_constraints(): Mol = Molecule() Mol.newAtom('Na', (0, 0, 0), fix=[True]) Mol.newAtom('Na', (1, 1, 1), fix=[True, True, True]) p = newParam('cpmd') p["&ATOMS"] = "CONSTRAINTS\n"\ "FIX COM\n"\ "END CONSTRAINTS\n" head = "&CPMD\n"\ "&END\n"\ "&SYSTEM\n"\ " CELL VECTORS\n"\ " 1.0000 0.0000 0.0000\n"\ " 0.0000 1.0000 0.0000\n"\ " 0.0000 0.0000 1.0000\n" tail = "&END\n"\ "&ATOMS\n"\ "*Na.uspp736.pbe BINARY\n"\ " LMAX=F\n"\ " 2\n"\ " 0.0000 0.0000 0.0000\n"\ " 1.0000 1.0000 1.0000\n"\ "CONSTRAINTS\n"\ "FIX ATOMS\n"\ "1\n"\ " 2\n"\ "FIX COORDINATES\n"\ "1\n"\ "1 0 1 1\n"\ "\n"\ "FIX COM\n"\ "END CONSTRAINTS\n"\ "ISOTOPE\n"\ "22.99\n"\ "&END\n" def assertKpoint(): f = StringIO() cpmd.writer(Mol, f, p) f = f.getvalue() assert f == target Mol.setKpoints('active', 'gamma') target = head + tail assertKpoint() Mol.setKpoints('active', 'mpg') Mol.setKpoints('mpg', ('2', '0', '0', '0', '0', '0')) target = head +\ " KPOINTS MONKHORST-PACK\n 2 0 0 \n" +\ tail assertKpoint() Mol.setKpoints('mpg', ('2', '0', '0', '0', '0', '0.5')) target = head +\ " KPOINTS MONKHORST-PACK SHIFT=0 0 0.5 \n" +\ " 2 0 0 \n" +\ tail assertKpoint() Mol.setKpoints('active', 'discrete') Mol.setKpoints('discrete', [['0.0', '0.0', '0.0', '0.75'], ['0.5', '0.5', '0.5', '0.25']]) Mol.setKpoints('options', {'crystal': False, 'bands': False}) target = head +\ " KPOINTS\n 2\n 0.0 0.0 0.0 0.75\n 0.5 0.5 0.5 0.25\n" +\ tail assertKpoint() Mol.setKpoints('options', {'crystal': True, 'bands': False}) target = head +\ " KPOINTS SCALED\n 2\n 0.0 0.0 0.0 0.75\n"\ " 0.5 0.5 0.5 0.25\n" +\ tail assertKpoint() Mol.setKpoints('discrete', [['0.0', '0.0', '0.0', '2'], ['0.5', '0.5', '0.5', '0']]) Mol.setKpoints('options', {'crystal': False, 'bands': True}) target = head +\ " KPOINTS BANDS\n 2 0.0 0.0 0.0 0.5 0.5 0.5 \n"\ " 0 0. 0. 0. 0. 0. 0.\n" +\ tail assertKpoint() Mol.setKpoints('options', {'crystal': True, 'bands': True}) target = head +\ " KPOINTS SCALED BANDS\n 2 0.0 0.0 0.0 0.5 0.5 0.5 \n"\ " 0 0. 0. 0. 0. 0. 0.\n" +\ tail assertKpoint() Mol.newAtom('Na', (2, 1, 1), fix=[True, True, True]) Mol.newAtom('Na', (3, 1, 1), fix=[True, True, True]) Mol.newAtom('Na', (4, 1, 1), fix=[True, True, True]) Mol.newAtom('Na', (5, 1, 1), fix=[True, True, True]) Mol.newAtom('Na', (6, 1, 1), fix=[True, True, True]) Mol.newAtom('Na', (7, 1, 1), fix=[True, True, True]) Mol.newAtom('Na', (8, 1, 1), fix=[True, True, True]) Mol.newAtom('Na', (9, 1, 1), fix=[True, True, True]) Mol.newAtom('Na', (1, 2, 1), fix=[True, True, True]) Mol.newAtom('Na', (1, 3, 1), fix=[True, True, True]) Mol.setKpoints('active', 'gamma') tail2 = "&END\n"\ "&ATOMS\n"\ "*Na.uspp736.pbe BINARY\n"\ " LMAX=F\n"\ " 12\n"\ " 0.0000 0.0000 0.0000\n"\ " 1.0000 1.0000 1.0000\n"\ " 2.0000 1.0000 1.0000\n"\ " 3.0000 1.0000 1.0000\n"\ " 4.0000 1.0000 1.0000\n"\ " 5.0000 1.0000 1.0000\n"\ " 6.0000 1.0000 1.0000\n"\ " 7.0000 1.0000 1.0000\n"\ " 8.0000 1.0000 1.0000\n"\ " 9.0000 1.0000 1.0000\n"\ " 1.0000 2.0000 1.0000\n"\ " 1.0000 3.0000 1.0000\n"\ "CONSTRAINTS\n"\ "FIX ATOMS\n"\ "11\n"\ " 2 3 4 5 6 7 8 9 10 11\n"\ " 12\n"\ "FIX COORDINATES\n"\ "1\n"\ "1 0 1 1\n"\ "END CONSTRAINTS\n"\ "ISOTOPE\n"\ "22.99\n"\ "&END\n" target = head + tail2 f = StringIO() cpmd.writer(Mol, f, newParam('cpmd')) for i in range(len(target.split('\n'))): print(f.getvalue().split('\n')[i], target.split('\n')[i]) assert f.getvalue().split('\n')[i] == target.split('\n')[i] assert f.getvalue() == target