<commit_before>#!/usr/bin/env python

"""
TODO: Change the module doc.
"""

from __future__ import division

__author__ = "shyuepingong"
__version__ = "0.1"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Beta"
__date__ = "2/4/13"

import logging

from custodian.custodian import Custodian
from custodian.vasp.handlers import VaspErrorHandler, \
    UnconvergedErrorHandler, PoscarErrorHandler
from custodian.vasp.jobs import VaspJob


def relax(args):
    FORMAT = '%(asctime)s %(message)s'
    logging.basicConfig(format=FORMAT, level=logging.INFO, filename="run.log")
    handlers = [VaspErrorHandler(), UnconvergedErrorHandler(),
                PoscarErrorHandler()]
    vasp_command = args.command.split()
    jobs = []
    if args.repeat == 1:
        jobs.append(VaspJob(vasp_command, final=True, suffix="", gzipped=True))
    elif args.repeat > 1:
        jobs.append(VaspJob(vasp_command, final=False, suffix=".relax1"))
        for i in xrange(1, args.repeat):
            if i != args.repeat - 1:
                jobs.append(
                    VaspJob(
                        vasp_command, final=False,
                        suffix=".relax{}".format(i + 1),
                        settings_override=[
                            {"dict": "INCAR",
                             "action": {"_set": {"ISTART": 1}}},
                            {"filename": "CONTCAR",
                             "action": {"_file_copy": {"dest": "POSCAR"}}}]))
            else:
                jobs.append(
                    VaspJob(
                        vasp_command, final=True, backup=False,
                        suffix=".relax{}".format(i + 1), gzipped=True,
                        settings_override=[
                            {"dict": "INCAR",
                             "action": {"_set": {"ISTART": 1}}},
                            {"filename": "CONTCAR",
                             "action": {"_file_copy": {"dest": "POSCAR"}}}]))

    c = Custodian(handlers, jobs, max_errors=10)
    c.run()



if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(description="""
    run_vasp.py is a master script to perform various kinds of VASP runs.
    """,
    epilog="""
    Author: <NAME>
    Version: {}
    Last updated: {}""".format(__version__, __date__))

    subparsers = parser.add_subparsers()

    prelax = subparsers.add_parser("relax", help="Do relaxation run.")

    prelax.add_argument(
        "-c", "--command", dest="command", nargs="?",
        default="pvasp", type=str,
        help="VASP command. Defaults to pvasp. If you are using mpirun, "
             "set this to something like \"mpirun pvasp\".")

    prelax.add_argument(
        "-r", "--repeat", dest="repeat", default=2, type=int,
        help="Number of repeats for the vasprun. Defaults to 2 for a double "
             "relaxation.")

    prelax.set_defaults(func=relax)<commit_msg>Fix bug in run_vasp script.<commit_after>#!/usr/bin/env python

"""
TODO: Change the module doc.
"""

from __future__ import division

__author__ = "shyuepingong"
__version__ = "0.1"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Beta"
__date__ = "2/4/13"

import logging

from custodian.custodian import Custodian
from custodian.vasp.handlers import VaspErrorHandler, \
    UnconvergedErrorHandler, PoscarErrorHandler
from custodian.vasp.jobs import VaspJob


def relaxation_run(args):
    FORMAT = '%(asctime)s %(message)s'
    logging.basicConfig(format=FORMAT, level=logging.INFO, filename="run.log")
    handlers = [VaspErrorHandler(), UnconvergedErrorHandler(),
                PoscarErrorHandler()]
    vasp_command = args.command.split()
    jobs = []
    if args.repeat == 1:
        jobs.append(VaspJob(vasp_command, final=True, suffix="", gzipped=True))
    elif args.repeat > 1:
        jobs.append(VaspJob(vasp_command, final=False, suffix=".relax1"))
        for i in xrange(1, args.repeat):
            if i != args.repeat - 1:
                jobs.append(
                    VaspJob(
                        vasp_command, final=False,
                        suffix=".relax{}".format(i + 1),
                        settings_override=[
                            {"dict": "INCAR",
                             "action": {"_set": {"ISTART": 1}}},
                            {"filename": "CONTCAR",
                             "action": {"_file_copy": {"dest": "POSCAR"}}}]))
            else:
                jobs.append(
                    VaspJob(
                        vasp_command, final=True, backup=False,
                        suffix=".relax{}".format(i + 1), gzipped=True,
                        settings_override=[
                            {"dict": "INCAR",
                             "action": {"_set": {"ISTART": 1}}},
                            {"filename": "CONTCAR",
                             "action": {"_file_copy": {"dest": "POSCAR"}}}]))

    c = Custodian(handlers, jobs, max_errors=10)
    c.run()


def static_run(args):
    FORMAT = '%(asctime)s %(message)s'
    logging.basicConfig(format=FORMAT, level=logging.INFO, filename="run.log")
    handlers = [VaspErrorHandler()]
    vasp_command = args.command.split()
    jobs = [VaspJob(
        vasp_command, final=True,
        suffix=".static",
        settings_override=[
            {"dict": "INCAR",
             "action": {"_set": {"ISTART": 1, "NSW": 0}}},
            {"filename": "CONTCAR",
             "action": {"_file_copy": {"dest": "POSCAR"}}}])]
    c = Custodian(handlers, jobs, max_errors=10)
    c.run()


if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(description="""
    run_vasp.py is a master script to perform various kinds of VASP runs.
    """,
    epilog="""
    Author: <NAME>
    Version: {}
    Last updated: {}""".format(__version__, __date__))

    subparsers = parser.add_subparsers()

    prelax = subparsers.add_parser("relax", help="Do relaxation run.")

    prelax.add_argument(
        "-c", "--command", dest="command", nargs="?",
        default="pvasp", type=str,
        help="VASP command. Defaults to pvasp. If you are using mpirun, "
             "set this to something like \"mpirun pvasp\".")

    prelax.add_argument(
        "-r", "--repeat", dest="repeat", default=2, type=int,
        help="Number of repeats for the vasprun. Defaults to 2 for a double "
             "relaxation.")

    prelax.set_defaults(func=relaxation_run)

    pstatic = subparsers.add_parser("static", help="Do a static run.")

    pstatic.add_argument(
        "-c", "--command", dest="command", nargs="?",
        default="pvasp", type=str,
        help="VASP command. Defaults to pvasp. If you are using mpirun, "
             "set this to something like \"mpirun pvasp\".")

    pstatic.set_defaults(func=static_run)

    parser.parse_args()
{'fraction_non_alphanumeric': 0.14310722100656456, 'fraction_numerical': 0.00612691466083151, 'mean_word_length': 2.1248860528714677, 'pattern_counts': {'":': 43, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5789399', 'n_tokens_mistral': 2182, 'n_tokens_neox': 2044, 'n_words': 472}