def failWrite(p): try: pwInput.writer(Mol, f, p) except KeyError: return True else: return False
def assertKpoint(): f = StringIO() pwInput.writer(Mol, f, Param) assert f.getvalue() == target
def test_pwi_write_calc(): calcs = ["'scf'", "'relax'", "'vc-relax'"] adnl = ["", "&ions\n ion_dynamics='bfgs'\n/\n\n", "&ions\n ion_dynamics='bfgs'\n/\n\n" "&cell\n cell_dynamics='bfgs'\n/\n\n"] head = "&control\n calculation=" body = "\n/\n\n"\ "&system\n"\ " nat=2\n"\ " ntyp=1\n"\ " celldm(1)=2.0\n"\ " ibrav=0\n"\ " ecutwfc=30.0\n"\ "/\n"\ "\n"\ "&electrons\n"\ " diagonalization='david'\n"\ " conv_thr=1.0e-8\n"\ "/\n"\ "\n" tail = "ATOMIC_SPECIES\n"\ "C 12.0107 C.uspp736.pbe.UPF\n"\ "\n"\ "ATOMIC_POSITIONS crystal\n"\ "C 0.00000 0.00000 0.00000 1 0 1\n"\ "C 0.50000 0.50000 0.50000\n"\ "\n"\ "K_POINTS automatic\n"\ "2 0 0 0 0 0 \n"\ "\n"\ "CELL_PARAMETERS\n"\ " 1.00000 2.00000 0.00000\n"\ " 0.00000 5.00000 6.00000\n"\ " 0.00000 8.00000 9.00000\n" Mol = Molecule() Mol.setFmt('crystal') Mol.setCellDim(2) Mol.setVec(((1, 2, 0), (0, 5, 6), (0, 8, 9))) Mol.newAtom('C', (0, 0, 0), fix=[False, True]) Mol.newAtom('C', [0.5, 0.5, 0.5], fmt='crystal') Mol.setKpoints('active', 'mpg') Mol.setKpoints('mpg', ('2', '0', '0', '0', '0', '0')) def failWrite(p): try: pwInput.writer(Mol, f, p) except KeyError: return True else: return False for c in range(3): for a in range(3): Param = newParam('pwi') Param['&control']['calculation'] = calcs[c] Param['&electrons']['diagonalization'] = "'david'" Param['&electrons']['conv_thr'] = "1.0e-8" if a > 0: Param['&ions'] = {'ion_dynamics': "'bfgs'"} if a > 1: Param['&cell'] = {'cell_dynamics': "'bfgs'"} f = StringIO() if a < c: failWrite(Param) else: pwInput.writer(Mol, f, Param) target = head + calcs[c] + body + adnl[a] + tail assert f.getvalue() == target # default to scf when nothing present: Param = newParam('pwi') Param['&electrons']['diagonalization'] = "'david'" Param['&electrons']['conv_thr'] = "1.0e-8" f = StringIO() pwInput.writer(Mol, f, Param) target = "&control" + body + tail assert f.getvalue() == target