Esempio n. 1
0
    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)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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"))
Esempio n. 4
0
    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"))
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)
Esempio n. 7
0
 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'")
Esempio n. 8
0
    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'")
Esempio n. 9
0
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()
Esempio n. 10
0
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()
Esempio n. 11
0
    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)
Esempio n. 12
0
    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)
Esempio n. 13
0
 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)
Esempio n. 14
0
 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)