예제 #1
0
def make_firework(atoms, fw_name, vasp_settings):
    '''
    This function makes a FireWorks rocket to perform a VASP relaxation

    Args:
        atoms           `ase.Atoms` object to relax
        fw_name         Dictionary of tags/etc to use as the FireWorks name
        vasp_settings   Dictionary of VASP settings to pass to Vasp()
    Returns:
        firework    An instance of a `fireworks.Firework` object that is set up
                    to perform a VASP relaxation
    '''
    # Warn the user if they're submitting a big one
    if len(atoms) > 80:
        warnings.warn(
            'You are making a firework with %i atoms in it. This may '
            'take awhile.' % len(atoms), RuntimeWarning)

    # Take the `vasp_functions` submodule in GASpy and then pass it out to each
    # FireWork rocket to use.
    vasp_filename = vasp_functions.__file__
    if vasp_filename.split(
            '.')[-1] == 'pyc':  # Make sure we use the source file
        vasp_filename = vasp_filename[:-3] + 'py'
    with open(vasp_filename) as file_handle:
        vasp_functions_contents = file_handle.read()
    pass_vasp_functions = FileWriteTask(
        files_to_write=[{
            'filename': 'vasp_functions.py',
            'contents': vasp_functions_contents
        }])

    # Convert the atoms object to a string so that we can pass it through
    # FireWorks, and then tell the FireWork rocket to use our `vasp_functions`
    # submodule to unpack the string
    atom_trajhex = encode_atoms_to_trajhex(atoms)
    read_atoms_file = PyTask(func='vasp_functions.hex_to_file',
                             args=['slab_in.traj', atom_trajhex])

    # Tell the FireWork rocket to perform the relaxation
    relax = PyTask(func='vasp_functions.runVasp',
                   args=['slab_in.traj', 'slab_relaxed.traj', vasp_settings],
                   stored_data_varname='opt_results')

    fw_name['user'] = getpass.getuser()
    firework = Firework([pass_vasp_functions, read_atoms_file, relax],
                        name=fw_name)
    return firework
예제 #2
0
def add_namefile(original_wf, use_slug=True):
    """
    Every FireWork begins by writing an empty file with the name
    "FW--<fw.name>". This makes it easy to figure out what jobs are in what
    launcher directories, e.g. "ls -l launch*/FW--*" from within a "block" dir.

    Args:
        original_wf (Workflow)
        use_slug (bool): whether to replace whitespace-type chars with a slug

    Returns:
       Workflow
    """
    for idx, fw in enumerate(original_wf.fws):
        fname = "FW--{}".format(fw.name)
        if use_slug:
            fname = get_slug(fname)
        original_wf.fws[idx].tasks.insert(0, FileWriteTask(
            files_to_write=[{"filename": fname, "contents": ""}]))
    return original_wf
예제 #3
0
    def addRunSteps(self, inpSim, userID, cores):
        #builds the following workflow for running simulations
        #creates directory for simulation using the sim name and uuid
        #writes gkyl input file to the directory
        #runs file in the directory
        #if run is successful, prints 'Done', if not, prints 'Failed
        #plots task

        #userid --> for folder location
        self.fws = []
        print(inpSim)
        self.last = len(self.launchpad.get_fw_ids())
        #        for fwork in self.launchpad.get_fw_ids():
        #            self.launchpad.delete_fws([fwork])
        sim = Sim(inpSim)

        #        path = '/home/adaniel99/gkylsoft/sims/'+str(userID)+'/'+inpSim+'/'
        path = '/home/dalex_99/gkylsoft/sims/' + str(
            userID) + '/' + inpSim + '/'
        n = 0
        #        for f in os.listdir('/home/adaniel99/gkylsoft/sims/'):
        for f in os.listdir('/home/dalex_99/gkylsoft/sims/'):
            if f == str(userID):
                #                for f in os.listdir('/home/adaniel99/gkylsoft/sims/'+str(userID)+'/'):
                for f in os.listdir('/home/dalex_99/gkylsoft/sims/' +
                                    str(userID) + '/'):
                    if f == inpSim:
                        n = n + 1
                        self.rerun = True

        if n == 0:
            desttask = ScriptTask.from_str('mkdir ' + path)
            writetask = FileWriteTask({
                'files_to_write': ([{
                    'filename': sim.name(),
                    'contents': sim.inpFile()
                }]),
                'dest':
                path
            })
            runtask = ScriptTask.from_str(
                'redis-cli PUBLISH ' + User(userID).name() +
                '2 "Running Simulation"; mpiexec -n ' + cores + 'gkyl ' +
                path + sim.name())
            runFlag = ScriptTask.from_str('redis-cli PUBLISH ' +
                                          User(userID).name() + '2' + ' Done')
            deleteFail = ScriptTask.from_str('lpad defuse_fws -i ' +
                                             str(6 + self.last))
            flagFail = ScriptTask.from_str('redis-cli PUBLISH ' +
                                           User(userID).name() + '2' +
                                           ' Failed')
            self.ids.clear()
            dest = Firework(desttask, name='Make Folder', fw_id=1 + self.last)
            self.ids.append(1 + self.last)
            write = Firework(writetask, name='Write', fw_id=2 + self.last)
            self.ids.append(2 + self.last)
            run = Firework(runtask, name='Run', fw_id=3 + self.last)
            self.ids.append(3 + self.last)
            flag1 = Firework(runFlag, name='done?', fw_id=4 + self.last)
            self.ids.append(4 + self.last)
            delfail = Firework(deleteFail,
                               name='remove fail flag',
                               fw_id=5 + self.last)
            self.ids.append(5 + self.last)
            failflag = Firework(flagFail,
                                name='fail flag',
                                fw_id=6 + self.last)
            self.ids.append(6 + self.last)

            self.fws.append(dest)
            self.fws.append(write)
            self.fws.append(run)
            self.fws.append(flag1)
            self.fws.append(delfail)
            self.fws.append(failflag)
            wf = Workflow(self.fws, {
                dest: [write],
                write: [run],
                run: [flag1],
                flag1: [delfail]
            },
                          name='Running ' + sim.name())
            self.launchpad.add_wf(wf)

        if n == 1:
            writetask = FileWriteTask({
                'files_to_write': ([{
                    'filename': sim.name(),
                    'contents': sim.inpFile()
                }]),
                'dest':
                path
            })
            runtask = ScriptTask.from_str(
                'redis-cli PUBLISH ' + User(userID).name() +
                '2 "Running Simulation"; mpiexec -n ' + cores + 'gkyl ' +
                path + sim.name())
            runFlag = ScriptTask.from_str('redis-cli PUBLISH ' +
                                          User(userID).name() + '2' + ' Done')
            deleteFail = ScriptTask.from_str('lpad defuse_fws -i ' +
                                             str(5 + self.last))
            flagFail = ScriptTask.from_str('redis-cli PUBLISH ' +
                                           User(userID).name() + '2' +
                                           ' Failed')
            self.ids.clear()
            write = Firework(writetask, name='Write', fw_id=1 + self.last)
            self.ids.append(1 + self.last)
            run = Firework(runtask, name='Run', fw_id=2 + self.last)
            self.ids.append(2 + self.last)
            flag1 = Firework(runFlag, name='done?', fw_id=3 + self.last)
            self.ids.append(3 + self.last)
            delfail = Firework(deleteFail,
                               name='remove fail flag',
                               fw_id=4 + self.last)
            self.ids.append(4 + self.last)
            failflag = Firework(flagFail,
                                name='fail flag',
                                fw_id=5 + self.last)
            self.ids.append(5 + self.last)
            wf = Workflow([write, run, flag1, delfail, failflag], {
                write: [run],
                run: [flag1],
                flag1: [delfail]
            },
                          name='Running ' + sim.name())
            self.launchpad.add_wf(wf)