def setNamelist(self, namelist): """ Sets namelist as dictionaty: namelist: (dict) -- Dictionary of namelist Format: {"name": <namelist name>, "params": {param1: value1, param2: value2, ...}} Example: {"name": "control", "params": {calculation: 'scf', restart_mode: 'from_scratch', tprnfor: .true.}} """ if not namelist: # Ignore empty card return self._checkDictFormat(namelist, NAMELIST_KEYS, NAMELIST_REQ) nl = Namelist(namelist["name"]) if namelist.has_key("params"): for p in namelist["params"].keys(): value = namelist["params"][p] nl.set(p, value) self._fnamelists.append(nl)
def setNamelist(self, namelist): """ Sets namelist as dictionaty: namelist: (dict) -- Dictionary of namelist Format: {"name": <namelist name>, "params": {param1: value1, param2: value2, ...}} Example: {"name": "control", "params": {calculation: 'scf', restart_mode: 'from_scratch', tprnfor: .true.}} """ if not namelist: # Ignore empty card return self._checkDictFormat(namelist, NAMELIST_KEYS, NAMELIST_REQ) nl = Namelist(namelist["name"]) if namelist.has_key("params"): for p in namelist["params"].keys(): value = namelist["params"][p] nl.set(p, value) self._fnamelists.append(nl)
def test_namelist_remove_exists(self): nl = Namelist("control") nl.set("title", "hello") self.assertTrue(nl.exists("title")) self.assertTrue(nl.exists("Title")) nl.remove("title") self.assertFalse(nl.exists("title"))
def test_namelist_remove_exists(self): nl = Namelist("control") nl.set("title", "hello") self.assertTrue(nl.exists("title")) self.assertTrue(nl.exists("Title")) nl.remove("title") self.assertFalse(nl.exists("title"))
def test_qeinput_namelist(self): input = QEInput() nl = Namelist("control") nl.set("title", "'Ni'") input.addNamelist(nl) nl2 = input.namelist("phonon") self.assertEqual(input.toString(), fixtures.assertNewNamelist) input.removeNamelist("control") self.assertEqual(input.toString(), fixtures.assertNewNamelist2)
def test_qeinput_namelist(self): input = QEInput() nl = Namelist("control") nl.set("title", "'Ni'") input.addNamelist(nl) nl2 = input.namelist("phonon") self.assertEqual(input.toString(), fixtures.assertNewNamelist) input.removeNamelist("control") self.assertEqual(input.toString(), fixtures.assertNewNamelist2)
def test_namelist_set_get(self): nl = Namelist("control") self.assertEqual(nl.get("title"), None) nl.set("title", "hello") self.assertEqual(nl.get("title"), "hello") self.assertEqual(nl.get("title", quotes=True), "hello") # should not add quotes nl.set("Title", "'hello'") self.assertEqual(nl.get("titlE", quotes=False), "hello") self.assertEqual(nl.get("title"), "'hello'")
def test_namelist_set_get(self): nl = Namelist("control") self.assertEqual(nl.get("title"), None) nl.set("title", "hello") self.assertEqual(nl.get("title"), "hello") self.assertEqual(nl.get("title", quotes=True), "hello") # should not add quotes nl.set("Title", "'hello'") self.assertEqual(nl.get("titlE", quotes=False), "hello") self.assertEqual(nl.get("title"), "'hello'")
def testCreateConfig(): print "Testing creation of config file" qe = QEInput() nl = Namelist('control') nl.add('title', "'Ni'") nl.add('restart_mode', "'from_scratch'") print "Adding parameters to namelist:\n%s" % nl.toString() nl.set('title', "'Fe'") qe.addNamelist(nl) print "Adding namelist to QEInput:\n%s" % qe.toString() c = Card('atomic_species') c.addLine('Ni 26.98 Ni.pbe-nd-rrkjus.UPF') print "Adding line to card:\n%s" % c.toString() qe.addCard(c) print "Adding card to QEInput:\n%s" % qe.toString()
def testCreateConfig(): print "Testing creation of config file" qe = QEInput() nl = Namelist('control') nl.add('title', "'Ni'") nl.add('restart_mode', "'from_scratch'") print "Adding parameters to namelist:\n%s" % nl.toString() nl.set('title', "'Fe'") qe.addNamelist(nl) print "Adding namelist to QEInput:\n%s" % qe.toString() c = Card('atomic_species') c.addLine('Ni 26.98 Ni.pbe-nd-rrkjus.UPF') print "Adding line to card:\n%s" % c.toString() qe.addCard(c) print "Adding card to QEInput:\n%s" % qe.toString()
def setParam(self, namelist, param, value=""): """ Set parameter of the namelist. If the parameter or namelist do not exist, it creates them. namelist: (str) -- Name of the namelist param: (str) -- Name of the parameter value: (str) -- Valur of the parameter """ for nl in self._fnamelists: if nl.name() == namelist: nl.set(param, value) return # namelist doesn't exists nl = Namelist(namelist) nl.set(param, value) self._fnamelists.append(nl)
def setParam(self, namelist, param, value=""): """ Set parameter of the namelist. If the parameter or namelist do not exist, it creates them. namelist: (str) -- Name of the namelist param: (str) -- Name of the parameter value: (str) -- Valur of the parameter """ for nl in self._fnamelists: if nl.name() == namelist: nl.set(param, value) return # namelist doesn't exists nl = Namelist(namelist) nl.set(param, value) self._fnamelists.append(nl)
def test_namelist_tostring(self): nl = Namelist("control") nl.set("title", "hello") self.assertEqual(nl.toString(), fixtures.assertNL) self.assertEqual(nl.toString(indent=3), fixtures.assertNL_space_3)
def test_namelist_tostring(self): nl = Namelist("control") nl.set("title", "hello") self.assertEqual(nl.toString(), fixtures.assertNL) self.assertEqual(nl.toString(indent=3), fixtures.assertNL_space_3)