예제 #1
0
def create_incar(xsdname, args):
    """"""
    if os.path.exists('INCAR'):
        return 'INCAR already exists, not changed.\n'

    incar = InCar()
    if args.task:
        task = args.task
        incar.quickgen(args.task)
    else:
        task = 'SC'
    content = 'INCAR -->\n'
    content += '     Task is %s\n' %task

    if PY2:
        pname_value_pairs = args.__dict__.iteritems()
    else:
        pname_value_pairs = args.__dict__.items()

    for pname, value in pname_value_pairs :
        if (value is not None):
            if pname in incar.pnames:
                incar.set(pname, value)
            else:
                if (pname in INCAR_PARAMETERS.keys()):
                    incar.add(pname, value)
            content += "     {} -> {}\n".format(pname, value)
    #incar.set('SYSTEM', xsdname)

    incar.tofile(verbos=False)

    content += '\n'

    return content
예제 #2
0
파일: incar_test.py 프로젝트: PytLab/VASPy
    def test_parameter_add(self):
        " Test new parameter can be added correctly. "
        filename = path + "/INCAR"
        incar = InCar(filename)

        self.assertFalse(hasattr(incar, "TEST_zjshao"))
        incar.add("TEST_zjshao", "True")
        self.assertTrue(incar.TEST_zjshao, "True")
예제 #3
0
    def test_parameter_add(self):
        " Test new parameter can be added correctly. "
        filename = path + "/INCAR"
        incar = InCar(filename)

        self.assertFalse(hasattr(incar, "TEST_zjshao"))
        incar.add("TEST_zjshao", "True")
        self.assertTrue(incar.TEST_zjshao, "True")
예제 #4
0
class InCarTest(unittest.TestCase):

    def setUp(self):
        # Create an InCar object.
        self.incar = InCar("./testdata/INCAR")

    def test_rdata(self):
        " Test data line in INCAR can be read correctly. "

        # Test integer parameter.
        ref_line = "ISTART = 0        # 0 = new job, 1 = restart"
        pnames, datas = self.incar.rdata(ref_line)
        self.assertListEqual(pnames, ["ISTART"])
        self.assertListEqual(datas, ["0"])

        # Test string parameter.
        ref_line = "PREC   = Normal  # [Low/Medium/High/Accurate/Normal]"
        pnames, datas = self.incar.rdata(ref_line)
        self.assertListEqual(pnames, ["PREC"])
        self.assertListEqual(datas, ["Normal"])
        
        # Test comment line.
        ref_line = "! Electronic Structure"
        result = self.incar.rdata(ref_line)
        self.assertIsNone(result)

        # Test multi-parameter line.
        ref_line = "LHFCALC = .TRUE. ; HFSCREEN = 0.2  # HSE"
        pnames, datas = self.incar.rdata(ref_line)
        self.assertListEqual(pnames, ["LHFCALC", "HFSCREEN"])
        self.assertListEqual(datas, [".TRUE.", "0.2"])

    def test_load(self):
        " Test all data in INCAR can be loaded. "
        ref_pnames = ['SYSTEM', 'ISTART', 'ISPIN', 'PREC', 'ENCUT',
                      'NELM', 'NELMIN', 'ISMEAR', 'SIGMA', 'LREAL',
                      'EDIFFG', 'ALGO', 'ISIF', 'NSW', 'IBRION', 'POTIM',
                      'ISYM', 'NWRITE', 'LCHARG', 'LWAVE', 'NCORE']

        ref_datas = ['per', '0', '2', 'Normal', '450', '400', '3',
                     '1', '0.1', 'A', '-0.05', 'Fast', '2', '900',
                     '1', '0.2', '0', '1', '.False.', '.False.', '4']

        for pname, data in zip(ref_pnames, ref_datas):
            self.assertEqual(getattr(self.incar, pname), data)

    def test_parameter_set(self):
        " Test existed parameter can be set correctly. "
        self.assertTrue(self.incar.ISIF, "2")
        self.incar.set("ISIF", 3)
        self.assertTrue(self.incar.ISIF, "3")

    def test_parameter_add(self):
        " Test new parameter can be added correctly. "
        self.assertFalse(hasattr(self.incar, "TEST_zjshao"))
        self.incar.add("TEST_zjshao", "True")
        self.assertTrue(self.incar.TEST_zjshao, "True")

    def test_tofile(self):
        " Test INCAR content can be write to file. "
        # NEED IMPLEMENTATIN
        pass
예제 #5
0
    kpt_str = " ".join(kpoints)
    kpt_content = "mesh auto\n0\nG\n" + kpt_str + "\n0 0 0\n"
    with open("KPOINTS", "w") as f:
        f.write(kpt_content)

    # Modify INCAR parameters.
    incar = InCar()
    incar.set("IBRION", 3)
    incar.set("POTIM", 0)
    neb_parameters = [("IOPT", 1),
                      ("ICHAIN", 0),
                      ("LCLIMB", ".TRUE."),
                      ("SPRING", -5),
                      ("IMAGES", n_images)]
    for pname, value in neb_parameters:
        incar.add(pname, value)
        _logger.info("{} -> {}".format(pname, value))
    incar.tofile()

    # Modify qsub script.
    jobname = xtdname.split('.')[0]
    with open('vasp.script', 'r') as f:
        content_list = f.readlines()

    # Change job name.
    content_list[1] = '#PBS -N ' + jobname + '\n'
    _logger.info("job name -> {}".format(jobname))

    # Change node number and cpu number.
    if args.nnode or args.ncpu:
        regex = re.compile(r'nodes=(\d):ppn=(\d)')
예제 #6
0
    else:
        kpoints = [i.strip() for i in args.kpoints.split(",")]
        _logger.info("Set k-point -> {} {} {}".format(*kpoints))
    kpt_str = " ".join(kpoints)
    kpt_content = "mesh auto\n0\nG\n" + kpt_str + "\n0 0 0\n"
    with open("KPOINTS", "w") as f:
        f.write(kpt_content)

    # Modify INCAR parameters.
    incar = InCar()
    incar.set("IBRION", 3)
    incar.set("POTIM", 0)
    neb_parameters = [("IOPT", 1), ("ICHAIN", 0), ("LCLIMB", ".TRUE."),
                      ("SPRING", -5), ("IMAGES", n_images)]
    for pname, value in neb_parameters:
        incar.add(pname, value)
        _logger.info("{} -> {}".format(pname, value))
    incar.tofile()

    # Modify qsub script.
    jobname = xtdname.split('.')[0]
    with open('vasp.script', 'r') as f:
        content_list = f.readlines()

    # Change job name.
    content_list[1] = '#PBS -N ' + jobname + '\n'
    _logger.info("job name -> {}".format(jobname))

    # Change node number and cpu number.
    if args.nnode or args.ncpu:
        regex = re.compile(r'nodes=(\d):ppn=(\d)')
예제 #7
0
class InCarTest(unittest.TestCase):
    def setUp(self):
        # Create an InCar object.
        self.incar = InCar("./testdata/INCAR")

    def test_rdata(self):
        " Test data line in INCAR can be read correctly. "

        # Test integer parameter.
        ref_line = "ISTART = 0        # 0 = new job, 1 = restart"
        pnames, datas = self.incar.rdata(ref_line)
        self.assertListEqual(pnames, ["ISTART"])
        self.assertListEqual(datas, ["0"])

        # Test string parameter.
        ref_line = "PREC   = Normal  # [Low/Medium/High/Accurate/Normal]"
        pnames, datas = self.incar.rdata(ref_line)
        self.assertListEqual(pnames, ["PREC"])
        self.assertListEqual(datas, ["Normal"])

        # Test comment line.
        ref_line = "! Electronic Structure"
        result = self.incar.rdata(ref_line)
        self.assertIsNone(result)

        # Test multi-parameter line.
        ref_line = "LHFCALC = .TRUE. ; HFSCREEN = 0.2  # HSE"
        pnames, datas = self.incar.rdata(ref_line)
        self.assertListEqual(pnames, ["LHFCALC", "HFSCREEN"])
        self.assertListEqual(datas, [".TRUE.", "0.2"])

    def test_load(self):
        " Test all data in INCAR can be loaded. "
        ref_pnames = [
            'SYSTEM', 'ISTART', 'ISPIN', 'PREC', 'ENCUT', 'NELM', 'NELMIN',
            'ISMEAR', 'SIGMA', 'LREAL', 'EDIFFG', 'ALGO', 'ISIF', 'NSW',
            'IBRION', 'POTIM', 'ISYM', 'NWRITE', 'LCHARG', 'LWAVE', 'NCORE'
        ]

        ref_datas = [
            'per', '0', '2', 'Normal', '450', '400', '3', '1', '0.1', 'A',
            '-0.05', 'Fast', '2', '900', '1', '0.2', '0', '1', '.False.',
            '.False.', '4'
        ]

        for pname, data in zip(ref_pnames, ref_datas):
            self.assertEqual(getattr(self.incar, pname), data)

    def test_parameter_set(self):
        " Test existed parameter can be set correctly. "
        self.assertTrue(self.incar.ISIF, "2")
        self.incar.set("ISIF", 3)
        self.assertTrue(self.incar.ISIF, "3")

    def test_parameter_add(self):
        " Test new parameter can be added correctly. "
        self.assertFalse(hasattr(self.incar, "TEST_zjshao"))
        self.incar.add("TEST_zjshao", "True")
        self.assertTrue(self.incar.TEST_zjshao, "True")

    def test_tofile(self):
        " Test INCAR content can be write to file. "
        # NEED IMPLEMENTATIN
        pass