Exemple #1
0
 def toString(self, string=None):
     if string != None:
         qeConf = QEInput(config=string)
         qeConf.parse()
     else:
         if self.qeConf != None:
             qeConf = self.qeConf
         else:
             qeConf = QEInput(config='')
     self.updatePWInput(qeConf)
     return qeConf.toString()
Exemple #2
0
    def test_filter_apply(self):
        input = QEInput(config=fixtures.textMain)
        # Filter that adds parameters to input
        fp = Filter("fPlus")
        fp.setParam("control", "prefix", "'ni'")
        fp.setParam("control", "pseudo_dir", "''")
        fp.setParam("control", "outdir", "''")
        fp.setCard({
            "name": "occupations",
            "lines": ("New line", )
        })  # Add new card
        fp.setNamelist({
            "name": "cell",
            "params": {
                "hello": "world"
            }
        })  # Add new namelist
        fp.setNamelist({"name": "phonon"})
        fp.apply(input, "plus")

        self.assertEqual(input.toString(), fixtures.assertPlus)

        # Filter that removes parameters from input
        fm = Filter("fMinus")
        fm.setCard({"name": "atomic_species"})
        fm.setNamelist({"name": "phonon"})  # Remove namelist
        fm.setParam("cell",
                    "hello")  # Remove parameter that makes namelist empty
        fm.setParam("control", "prefix")  # Remove parameter
        fm.apply(input, "minus")
        self.assertEqual(input.toString(), fixtures.assertMinus)
Exemple #3
0
    def test_qeinput_card_exists(self):
        input = QEInput(config=fixtures.textMain)
        # If non-standard card is requested, it will not add it!
        card = input.card("SOME_CARD")
        self.assertFalse(input.cardExists("some_card"))

        card = input.card("occupations")
        self.assertTrue(input.cardExists("occupations"))
Exemple #4
0
    def test_qeinput_namelist_exists(self):
        input = QEInput(config=fixtures.textMain)
        # If non-standard card is requested, it will not add it!
        nl = input.namelist("SOME_NAMELIST")
        self.assertFalse(input.namelistExists("some_namelist"))

        nl = input.namelist("cell")
        self.assertTrue(input.namelistExists("cell"))
Exemple #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)
Exemple #6
0
    def test_qeinput_save(self):
        fname = "temp.in"
        input = QEInput(config=fixtures.textMain)
        input.save(fname)
        self.assertTrue(filecmp.cmp(fname, "ref.in"))

        try:
            os.remove(fname)
        except OSError:
            pass  # Doesn't exist
Exemple #7
0
    def test_qeinput_card(self):
        input = QEInput()
        c = Card("atomic_species")
        c.setArg("temp")
        c.addLine("Ni  26.98  Ni.pbe-nd-rrkjus.UPF")
        input.addCard(c)
        c2 = input.card("atomic_positions")
        self.assertEqual(input.toString(), fixtures.assertNewCard)

        input.removeCard("atomic_species")
        self.assertEqual(input.toString(), fixtures.assertNewCard2)
    def save(self, fname=None):
        """Writes/updates structure into PW config file,
           if the file does not exist, new one will be created"""
        if fname != None:
            filename = fname
            self.lattice.save(filename)
            qeConf = QEInput(fname)
            qeConf.parse()
        else:
            filename = self.filename
            self.lattice.save(filename)
            qeConf = self.qeConf
        self.updatePWInput(qeConf)

        qeConf.save(filename)
Exemple #9
0
 def save(self, fname=None):
     """Will save the lattice either into its own file or into supplied with fname.
        It will also create all relevant sections/cards"""
     from os.path import exists
     if fname != None:
         filename = fname
         if not exists(filename):
             f = open(filename, 'w')
         qeConf = QEInput(fname)
         qeConf.parse()
     else:
         qeConf = self.qeConf
         filename = qeConf.filename
     self.updatePWInput(qeConf)
     qeConf.save(filename)
Exemple #10
0
    def test_qeinput_filter(self):
        input = QEInput(config=fixtures.textMain)

        f = Filter("fPlus")
        f.setParam("control", "calculation", "'md'")
        f.setCard({"name": "occupations", "lines": ("New line", )})

        input.applyFilter(f, "plus")
        self.assertEqual(input.toString(), fixtures.assertInputFilterPlus)

        f = Filter("fMinus")
        f.setNamelist({"name": "control"})
        f.setCard({"name": "k_points"})

        input.applyFilter(f, "minus")
        self.assertEqual(input.toString(), fixtures.assertInputFilterMinus)
 def write(self, filename=None, format="pwinput"):
     """Save structure to file in the specified format
     format   -- structure formats
                 'pwinput' ( pw.x input, default), 'pwoutput' (pw.x output),
                 'bratoms', 'cif', 'discus', 'pdb', 'pdffit', 'rawxyz', 
                 'xcfg', 'xyz'        
     No return value.
     """
     if format == "pwinput":
         self._qeInput.update(forceUpdate=True)
         if filename == None:
             filename = self._qeInput.filename
         input = QEInput(config=self._qeInput.toString(), type='pw')
         input.save(filename=filename)
     else:
         self.matter().write(filename=filename, format=format)
     return
Exemple #12
0
    def test_qeinput_read(self):
        input = QEInput()
        input.readString(fixtures.textMain)  # Load input from string

        self.assertEqual(input.config, fixtures.textMain)  # config is set

        nl = input.namelist("control")
        c = input.card("atomic_positions")
        self.assertEqual(nl.get("calculation"), "'scf'")
        self.assertEqual(c.line(0), "Ni 0.00 0.00 0.00")

        input.readFile("matdyn.in")
        self.assertEqual(input.filename, "matdyn.in")  # filename is set

        input.readFile("ni.scf.in")  # Load input from file

        nl = input.namelist("control")
        c = input.card("atomic_positions")
        self.assertEqual(nl.get("calculation"), "'scf'")
        self.assertEqual(c.line(0), "Ni 0.00 0.00 0.00")
Exemple #13
0
 def getLatticeParamsFromPWSCF(self, ibrav, fname):
     qeConf = QEInput(fname)
     qeConf.parse()
     return self.parsePWInput(ibrav, qeConf)
Exemple #14
0
 def test_qeinput_remove(self):
     input = QEInput(config=fixtures.textMain)
     input.removeCard("atomic_species")  # Remove non-existing card
     input.removeNamelist("control")  # Remove non-existing namelist
Exemple #15
0
 def setLatticeFromPWSCF(self, fname):
     self.qeConf = QEInput(fname)
     self.qeConf.parse()
     setLatticeFromPWInput(self, qeConf)
Exemple #16
0
            base = self._base / self._a
            self.setLattice(ibrav=self._ibrav, a=self._a, base=base)
        else:
            if self._ibrav == 0:
                pass
            else:
                self._type = value

    type = property(_get_type,
                    _set_type,
                    doc="""QE lattice type: 'celldm',
    'traditional' or 'generic cubic', 'generic hexagonal'(implies ibrav = 0""")

if __name__ == '__main__':

    pwInput = QEInput('scf.in', type='pw')
    pwInput.parse()
    qeLattice = QELattice(qeConf=pwInput)
    print qeLattice.latticeParams()
    #    qeLattice = QELattice(fname = 'qwe.in')
    #   qeLattice.setLatticeFromPrimitiveVectors(12,qeLattice.lattice().base)
    #   print qeLattice.latticeParams()
    #    qeLattice.latticeType = 'generic hexagonal'
    #    qeLattice.bb = 12
    qeLattice.a = 13.0
    qeLattice.b = 24.0
    qeLattice.c = 3.
    qeLattice.ibrav = 4
    print qeLattice.b, qeLattice.c,
    print qeLattice.latticeParams()
    qeLattice.saveLatticeToPWSCF('./scf_2.in')
Exemple #17
0
    def test_qeinput_attach(self):
        "This unit test is useful for matdyn simulation type"
        input = QEInput()
        input.addAttach("176\n\
0.000000    0.000000    0.456392    0.000000")
        self.assertEqual(input.toString(), fixtures.assertAttach)
Exemple #18
0
    def test_qeinput_parse(self):
        input = QEInput(config=fixtures.textMain, parse=False)
        self.assertEqual(input.toString(), "")

        input = QEInput(config=fixtures.textMain, parse=True)
        self.assertEqual(input.namelistExists("control"), True)
Exemple #19
0
 def test_qeinput_type(self):
     input = QEInput(type="ph")
     self.assertEqual(input.type(), "ph")