Пример #1
0
    def test_rdata(self):
        " Test data line in INCAR can be read correctly. "
        filename = path + "/INCAR"
        incar = InCar(filename)

        # Test integer parameter.
        ref_line = "ISTART = 0        # 0 = new job, 1 = restart"
        pnames, datas = 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 = incar.rdata(ref_line)
        self.assertListEqual(pnames, ["PREC"])
        self.assertListEqual(datas, ["Normal"])
        
        # Test comment line.
        ref_line = "! Electronic Structure"
        result = incar.rdata(ref_line)
        self.assertIsNone(result)

        # Test multi-parameter line.
        ref_line = "LHFCALC = .TRUE. ; HFSCREEN = 0.2  # HSE"
        pnames, datas = incar.rdata(ref_line)
        self.assertListEqual(pnames, ["LHFCALC", "HFSCREEN"])
        self.assertListEqual(datas, [".TRUE.", "0.2"])
Пример #2
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
Пример #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
    def test_parameter_set(self):
        " Test existed parameter can be set correctly. "
        filename = path + "/INCAR"
        incar = InCar(filename)

        self.assertTrue(incar.ISIF, "2")
        incar.set("ISIF", 3)
        self.assertTrue(incar.ISIF, "3")
Пример #5
0
    def test_parameter_set(self):
        " Test existed parameter can be set correctly. "
        filename = path + "/INCAR"
        incar = InCar(filename)

        self.assertTrue(incar.ISIF, "2")
        incar.set("ISIF", 3)
        self.assertTrue(incar.ISIF, "3")
Пример #6
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")
Пример #7
0
    def test_ne(self):
        " Test __ne__() function."
        # Two equal INCAR.
        filename1 = path + "/INCAR"
        filename2 = path + "/INCAR2"
        incar1 = InCar(filename1)
        incar2 = InCar(filename1)
        self.assertFalse(incar1 != incar2)

        # Different INCAR.
        incar1 = InCar(filename1)
        incar2 = InCar(filename2)
        self.assertTrue(incar1 != incar2)
Пример #8
0
    def test_parameter_del(self):
        " Make sure we can remove parameters correctly. "
        filename = path + "/INCAR"
        incar = InCar(filename)

        # Check before deletion.
        self.assertTrue(hasattr(incar, "ISIF"))
        self.assertTrue("ISIF" in incar.pnames)

        pname, value = incar.pop("ISIF")

        # Check after deletion.
        self.assertEqual(pname, "ISIF")
        self.assertEqual(value, "2")
        self.assertFalse(hasattr(incar, "ISIF"))
        self.assertFalse("ISIF" in incar.pnames)
Пример #9
0
    def test_parameter_del(self):
        " Make sure we can remove parameters correctly. "
        filename = path + "/INCAR"
        incar = InCar(filename)

        # Check before deletion.
        self.assertTrue(hasattr(incar, "ISIF"))
        self.assertTrue("ISIF" in incar.pnames)

        pname, value = incar.pop("ISIF")

        # Check after deletion.
        self.assertEqual(pname, "ISIF")
        self.assertEqual(value, "2")
        self.assertFalse(hasattr(incar, "ISIF"))
        self.assertFalse("ISIF" in incar.pnames)
Пример #10
0
    def test_compare(self):
        " Make sure we can compare two InCar objects correctly. "
        # Two equal INCAR.
        filename1 = path + "/INCAR"
        filename2 = path + "/INCAR2"
        incar1 = InCar(filename1)
        incar2 = InCar(filename1)
        a_dict, b_dict = incar1.compare(incar2)

        self.assertDictEqual(a_dict, {})
        self.assertDictEqual(b_dict, {})

        # Different INCAR.
        incar1 = InCar(filename1)
        incar2 = InCar(filename2)
        a_dict, b_dict = incar1.compare(incar2)

        self.assertDictEqual(a_dict, {'ISMEAR': '1', 'LREAL': 'A'})
        self.assertDictEqual(b_dict, {'ISMEAR': '2', 'LREAL': ''})
Пример #11
0
    def test_rdata(self):
        " Test data line in INCAR can be read correctly. "
        filename = path + "/INCAR"
        incar = InCar(filename)

        # Test integer parameter.
        ref_line = "ISTART = 0        # 0 = new job, 1 = restart"
        pnames, datas = 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 = incar.rdata(ref_line)
        self.assertListEqual(pnames, ["PREC"])
        self.assertListEqual(datas, ["Normal"])

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

        # Test multi-parameter line.
        ref_line = "LHFCALC = .TRUE. ; HFSCREEN = 0.2  # HSE"
        pnames, datas = incar.rdata(ref_line)
        self.assertListEqual(pnames, ["LHFCALC", "HFSCREEN"])
        self.assertListEqual(datas, [".TRUE.", "0.2"])
Пример #12
0
    def test_compare(self):
        " Make sure we can compare two InCar objects correctly. "
        # Two equal INCAR.
        filename1 = path + "/INCAR"
        filename2 = path + "/INCAR2"
        incar1 = InCar(filename1)
        incar2 = InCar(filename1)
        a_dict, b_dict = incar1.compare(incar2)

        self.assertDictEqual(a_dict, {})
        self.assertDictEqual(b_dict, {})

        # Different INCAR.
        incar1 = InCar(filename1)
        incar2 = InCar(filename2)
        a_dict, b_dict = incar1.compare(incar2)

        self.assertDictEqual(a_dict, {'ISMEAR': '1', 'LREAL': 'A'})
        self.assertDictEqual(b_dict, {'ISMEAR': '2', 'LREAL': ''})
Пример #13
0
    def test_load(self):
        " Test all data in INCAR can be loaded. "
        filename = path + "/INCAR"
        incar = InCar(filename)

        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(incar, pname), data)
Пример #14
0
_logger = logging.getLogger("vaspy.script")

# Set arguments parser.
parser = argparse.ArgumentParser()
parser.add_argument("--xsd",
                    help="create MaterStudio .xsd file",
                    action="store_true")
args = parser.parse_args()

outcar = OutCar()
poses, forces = outcar.forces(-1)

poscar = PosCar()
tfs = poscar.tf

incar = InCar()
#print(incar.paras)
EDIFFG = incar.get_pvalue('EDIFFG')
#EDIFFG = 0.05

bad_ids = []
max_idx = [-1, -1, -1]
max_force = [0., 0., 0.]
for i, (pos, force, tf) in enumerate(zip(poses, forces, tfs)):
    for j, (c, f) in enumerate(zip(tf, force)):
        if c == 'T':
            if np.fabs(f) >= max_force[j]:
                max_idx[j] = i
                max_force[j] = np.fabs(f)
            if np.fabs(f) > np.fabs(float(EDIFFG)):
                if i not in bad_ids:
Пример #15
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
Пример #16
0
 def setUp(self):
     # Create an InCar object.
     self.incar = InCar("./testdata/INCAR")
Пример #17
0
 def setUp(self):
     # Create an InCar object.
     self.incar = InCar("./testdata/INCAR")
Пример #18
0
    # Copy INCAR vasp.script
    subprocess.getstatusoutput('cp $HOME/example/INCAR $HOME/example/vasp.script ./')

    # Set argument parser.
    parser = argparse.ArgumentParser()

    # Add optional argument.
    parser.add_argument("-k", "--kpoints", help="set k-points")
    parser.add_argument("--nnode", help="node number used for the job")
    parser.add_argument("--ncpu", help="cpu number on each node")
    parser.add_argument("-q", "--queue", help="pbs queue type")

    # Add all possible arguments in INCAR file.
    if os.path.exists("INCAR"):
        incar = InCar()
        parameters = incar.pnames
        for parameter in parameters:
            help_info = "Set '{}' in INCAR".format(parameter)
            parser.add_argument("--{}".format(parameter), help=help_info)

    args = parser.parse_args()

    # Create POSCAR
    status, output = subprocess.getstatusoutput('ls *.xsd | head -1')
    xsd = XsdFile(filename=output)
    poscar_content = xsd.get_poscar_content(bases_const=1.0)
    with open('POSCAR', 'w') as f:
        f.write(poscar_content)

    # Create POTCAR
Пример #19
0
        atom_idxs.append(idx)
        atom_names.append(atom_name)
# if constrained get distance and create fort.188
if atom_idxs:
    if len(atom_idxs) > 2:
        raise ValueError("More than two atoms end with '_c'")
    pt1, pt2 = [xsd.data[idx, :] for idx in atom_idxs]
    # use Ax=b convert to cartisan coordinate
    diff = pt1 - pt2
    A = np.matrix(xsd.bases.T)
    x = np.matrix(diff).T
    b = A*x
    distance = np.linalg.norm(b)
    # create fort.188
    content = '1\n3\n6\n4\n0.04\n%-5d%-5d%f\n0\n' % \
        (atom_idxs[0]+1, atom_idxs[1]+1, distance)
    with open('fort.188', 'w') as f:
        f.write(content)
    print "fort.188 has been created."
    print '-'*20
    print "atom number: %-5d%-5d" % (atom_idxs[0]+1, atom_idxs[1]+1)
    print "atom name: %s %s" % tuple(atom_names)
    print "distance: %f" % distance
    print '-'*20

    # set IBRION = 1
    incar = InCar()
    incar.set('IBRION', 1)
    incar.tofile()
    print "IBRION is set to 1."
Пример #20
0
import logging

from vaspy.incar import InCar

SHELL_COMMAND = "find ./ -name 'INCAR'"

if "__main__" == __name__:

    # Check command validity.
    status, output = commands.getstatusoutput(SHELL_COMMAND)
    if status:
        raise SystemExit("Invalid shell commands - '{}'".format(SHELL_COMMAND))

    # Get InCar objects.
    incar_paths = (incar_path.strip() for incar_path in output.split('\n'))
    incars = [InCar(incar_path) for incar_path in incar_paths]

    # Get all possible arguments.
    set_list = [set(incar.pnames()) for incar in incars]
    possible_args = set.intersection(*set_list)

    # Set arguments for this script.
    parser = argparse.ArgumentParser()
    for arg in possible_args:
        arg_str = "--{}".format(arg)
        parser.add_argument(arg_str, help="set {} INCAR parameter".format(arg))
    args_space = parser.parse_args()

    # Change parameters for all incars.
    for pname, value in args_space.__dict__.iteritems():
        if value is None:
Пример #21
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
Пример #22
0
            atom_names.append(atom_name)
    # If constrained get distance and create fort.188
    if atom_idxs:
        if len(atom_idxs) > 2:
            raise ValueError("More than two atoms end with '_c'")
        pt1, pt2 = [xsd.data[idx, :] for idx in atom_idxs]
        # Use Ax=b convert to cartisan coordinate
        diff = pt1 - pt2
        A = np.matrix(xsd.bases.T)
        x = np.matrix(diff).T
        b = A * x
        distance = np.linalg.norm(b)
        # Create fort.188
        content = '1\n3\n6\n4\n0.04\n%-5d%-5d%f\n0\n' % \
            (atom_idxs[0]+1, atom_idxs[1]+1, distance)
        with open('fort.188', 'w') as f:
            f.write(content)
        logging.info("fort.188 has been created.")
        logging.info('-' * 20)
        logging.info("atom number: {:<5d}{:<5d}".format(
            atom_idxs[0] + 1, atom_idxs[1] + 1))
        logging.info("atom name: {} {}".format(*atom_names))
        logging.info("distance: {:f}".format(distance))
        logging.info('-' * 20)

        # Set IBRION = 1
        incar = InCar()
        incar.set('IBRION', 1)
        incar.tofile()
        logging.info("IBRION is set to 1.")
Пример #23
0
    return output


if "__main__" == __name__:
    # Set argument parser.
    parser = argparse.ArgumentParser()

    # Add optional arguments.
    parser.add_argument("-k", "--kpoints", help="set k-points")
    parser.add_argument("--nnode", help="node number used for the job")
    parser.add_argument("--ncpu", help="cpu number on each node")
    parser.add_argument("-q", "--queue", help="pbs queue type")

    # Add all possible arguments in INCAR file.
    if os.path.exists("INCAR"):
        incar = InCar()
        parameters = incar.pnames
        for parameter in parameters:
            help_info = "Set '{}' in INCAR".format(parameter)
            parser.add_argument("--{}".format(parameter), help=help_info)

    args = parser.parse_args()

    # Create XtdFile & ArcFile objects.
    arcname = _exec_command("ls *.arc | head -1")
    xtdname = _exec_command("ls *.xtd | head -1")
    xtd = XtdFile(filename=xtdname, arcname=arcname)

    # Create images.
    for idx, dir_coords in enumerate(xtd.coords_iterator):
        # Create images dir.
Пример #24
0


if "__main__" == __name__:
    # Set argument parser.
    parser = argparse.ArgumentParser()

    # Add optional arguments.
    parser.add_argument("-k", "--kpoints", help="set k-points")
    parser.add_argument("--nnode", help="node number used for the job")
    parser.add_argument("--ncpu", help="cpu number on each node")
    parser.add_argument("-q", "--queue", help="pbs queue type")

    # Add all possible arguments in INCAR file.
    if os.path.exists("INCAR"):
        incar = InCar()
        parameters = incar.pnames
        for parameter in parameters:
            help_info = "Set '{}' in INCAR".format(parameter)
            parser.add_argument("--{}".format(parameter), help=help_info)

    args = parser.parse_args()

    # Create XtdFile & ArcFile objects.
    arcname = _exec_command("ls *.arc | head -1")
    xtdname = _exec_command("ls *.xtd | head -1")
    xtd = XtdFile(filename=xtdname, arcname=arcname)

    # Create images.
    for idx, dir_coords in enumerate(xtd.coords_iterator):
        # Create images dir.
Пример #25
0
    # Copy INCAR vasp.script
    subprocess.getstatusoutput(
        'cp $HOME/example/INCAR $HOME/example/vasp.script ./')

    # Set argument parser.
    parser = argparse.ArgumentParser()

    # Add optional argument.
    parser.add_argument("-k", "--kpoints", help="set k-points")
    parser.add_argument("--nnode", help="node number used for the job")
    parser.add_argument("--ncpu", help="cpu number on each node")
    parser.add_argument("-q", "--queue", help="pbs queue type")

    # Add all possible arguments in INCAR file.
    if os.path.exists("INCAR"):
        incar = InCar()
        parameters = incar.pnames
        for parameter in parameters:
            help_info = "Set '{}' in INCAR".format(parameter)
            parser.add_argument("--{}".format(parameter), help=help_info)

    args = parser.parse_args()

    # Create POSCAR
    status, output = subprocess.getstatusoutput('ls *.xsd | head -1')
    xsd = XsdFile(filename=output)
    poscar_content = xsd.get_poscar_content(bases_const=1.0)
    with open('POSCAR', 'w') as f:
        f.write(poscar_content)

    # Create POTCAR
Пример #26
0
import logging
import os

from vaspy import PY2
from vaspy.incar import InCar

if PY2:
    import commands as subprocess
else:
    import subprocess

_logger = logging.getLogger("vaspy.script")

if "__main__" == __name__:
    incar = InCar()

    # Move files.
    cmd = "cp ../KPOINTS ./"
    status, output = subprocess.getstatusoutput(cmd)
    if status:
        raise ValueError(output)
    _logger.info(cmd)

    # Change INCAR parameters.
    parameters = [("IBRION", 5), ("POTIM", 0.05), ("ISIF", 0), ("NFREE", 2)]

    for pname, value in parameters:
        if hasattr(incar, pname):
            incar.set(pname, value)
        else: