def snl_to_wf_elastic(snl, parameters): # parameters["user_vasp_settings"] specifies user defined incar/kpoints parameters fws = [] connections = defaultdict(list) parameters = parameters if parameters else {} snl_priority = parameters.get('priority', 1) priority = snl_priority * 2 # once we start a job, keep going! f = Composition(snl.structure.composition.reduced_formula).alphabetical_formula # add the SNL to the SNL DB and figure out duplicate group tasks = [AddSNLTask()] spec = {'task_type': 'Add to SNL database', 'snl': snl.as_dict(), '_queueadapter': QA_DB, '_priority': snl_priority} if 'snlgroup_id' in parameters and isinstance(snl, MPStructureNL): spec['force_mpsnl'] = snl.as_dict() spec['force_snlgroup_id'] = parameters['snlgroup_id'] del spec['snl'] fws.append(Firework(tasks, spec, name=get_slug(f + '--' + spec['task_type']), fw_id=0)) connections[0] = [1] parameters["exact_structure"] = True # run GGA structure optimization for force convergence spec = snl_to_wf._snl_to_spec(snl, parameters=parameters) user_vasp_settings = parameters.get("user_vasp_settings") spec = update_spec_force_convergence(spec, user_vasp_settings) spec['run_tags'].append("origin") spec['_priority'] = priority spec['_queueadapter'] = QA_VASP del spec['_dupefinder'] spec['task_type'] = "Vasp force convergence optimize structure (2x)" tasks = [VaspWriterTask(), get_custodian_task(spec)] fws.append(Firework(tasks, spec, name=get_slug(f + '--' + spec['task_type']), fw_id=1)) # insert into DB - GGA structure optimization spec = {'task_type': 'VASP db insertion', '_priority': priority, '_allow_fizzled_parents': True, '_queueadapter': QA_DB, 'clean_task_doc':True, 'elastic_constant':"force_convergence"} fws.append(Firework([VaspToDBTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=2)) connections[1] = [2] spec = {'task_type': 'Setup Deformed Struct Task', '_priority': priority, '_queueadapter': QA_CONTROL} fws.append(Firework([SetupDeformedStructTask()], spec, name=get_slug(f + '--' + spec['task_type']),fw_id=3)) connections[2] = [3] wf_meta = get_meta_from_structure(snl.structure) wf_meta['run_version'] = 'May 2013 (1)' if '_materialsproject' in snl.data and 'submission_id' in snl.data['_materialsproject']: wf_meta['submission_id'] = snl.data['_materialsproject']['submission_id'] return Workflow(fws, connections, name=Composition( snl.structure.composition.reduced_formula).alphabetical_formula, metadata=wf_meta)
def run_task(self, fw_spec): # Read structure from previous relaxation relaxed_struct = fw_spec['output']['crystal'] # Generate deformed structures d_struct_set = DeformedStructureSet(relaxed_struct, ns=0.06) wf=[] for i, d_struct in enumerate(d_struct_set.def_structs): fws=[] connections={} f = Composition(d_struct.formula).alphabetical_formula snl = StructureNL(d_struct, 'Joseph Montoya <*****@*****.**>', projects=["Elasticity"]) tasks = [AddSNLTask()] snl_priority = fw_spec.get('priority', 1) spec = {'task_type': 'Add Deformed Struct to SNL database', 'snl': snl.as_dict(), '_queueadapter': QA_DB, '_priority': snl_priority} if 'snlgroup_id' in fw_spec and isinstance(snl, MPStructureNL): spec['force_mpsnl'] = snl.as_dict() spec['force_snlgroup_id'] = fw_spec['snlgroup_id'] del spec['snl'] fws.append(Firework(tasks, spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-1000+i*10)) connections[-1000+i*10] = [-999+i*10] spec = snl_to_wf._snl_to_spec(snl, parameters={'exact_structure':True}) spec = update_spec_force_convergence(spec) spec['deformation_matrix'] = d_struct_set.deformations[i].tolist() spec['original_task_id'] = fw_spec["task_id"] spec['_priority'] = fw_spec['_priority']*2 #Turn off dupefinder for deformed structure del spec['_dupefinder'] spec['task_type'] = "Optimize deformed structure" fws.append(Firework([VaspWriterTask(), SetupElastConstTask(), get_custodian_task(spec)], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-999+i*10)) priority = fw_spec['_priority']*3 spec = {'task_type': 'VASP db insertion', '_priority': priority, '_allow_fizzled_parents': True, '_queueadapter': QA_DB, 'elastic_constant':"deformed_structure", 'clean_task_doc':True, 'deformation_matrix':d_struct_set.deformations[i].tolist(), 'original_task_id':fw_spec["task_id"]} fws.append(Firework([VaspToDBTask(), AddElasticDataToDBTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-998+i*10)) connections[-999+i*10] = [-998+i*10] wf.append(Workflow(fws, connections)) return FWAction(additions=wf)
def run_task(self, fw_spec): print 'sleeping 10s for Mongo' time.sleep(10) print 'done sleeping' print 'the gap is {}, the cutoff is {}'.format( fw_spec['analysis']['bandgap'], self.gap_cutoff) if fw_spec['analysis']['bandgap'] >= self.gap_cutoff: static_dens = 90 uniform_dens = 1000 line_dens = 20 else: static_dens = 450 uniform_dens = 1500 line_dens = 30 if fw_spec['analysis']['bandgap'] <= self.metal_cutoff: user_incar_settings = {"ISMEAR": 1, "SIGMA": 0.2} else: user_incar_settings = {} print 'Adding more runs...' type_name = 'GGA+U' if 'GGA+U' in fw_spec['prev_task_type'] else 'GGA' snl = StructureNL.from_dict(fw_spec['mpsnl']) f = Composition( snl.structure.composition.reduced_formula).alphabetical_formula fws = [] connections = {} priority = fw_spec['_priority'] trackers = [ Tracker('FW_job.out'), Tracker('FW_job.error'), Tracker('vasp.out'), Tracker('OUTCAR'), Tracker('OSZICAR') ] trackers_db = [Tracker('FW_job.out'), Tracker('FW_job.error')] # run GGA static spec = fw_spec # pass all the items from the current spec to the new spec.update({ 'task_type': '{} static v2'.format(type_name), '_queueadapter': QA_VASP_SMALL, '_dupefinder': DupeFinderVasp().to_dict(), '_priority': priority, '_trackers': trackers }) fws.append( Firework([ VaspCopyTask({ 'use_CONTCAR': True, 'skip_CHGCAR': True }), SetupStaticRunTask({ "kpoints_density": static_dens, 'user_incar_settings': user_incar_settings }), get_custodian_task(spec) ], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-10)) # insert into DB - GGA static spec = { 'task_type': 'VASP db insertion', '_queueadapter': QA_DB, '_allow_fizzled_parents': True, '_priority': priority * 2, "_dupefinder": DupeFinderDB().to_dict(), '_trackers': trackers_db } fws.append( Firework([VaspToDBTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-9)) connections[-10] = -9 # run GGA Uniform spec = { 'task_type': '{} Uniform v2'.format(type_name), '_queueadapter': QA_VASP, '_dupefinder': DupeFinderVasp().to_dict(), '_priority': priority, '_trackers': trackers } fws.append( Firework([ VaspCopyTask({'use_CONTCAR': False}), SetupNonSCFTask({ 'mode': 'uniform', "kpoints_density": uniform_dens }), get_custodian_task(spec) ], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-8)) connections[-9] = -8 # insert into DB - GGA Uniform spec = { 'task_type': 'VASP db insertion', '_queueadapter': QA_DB, '_allow_fizzled_parents': True, '_priority': priority * 2, "_dupefinder": DupeFinderDB().to_dict(), '_trackers': trackers_db } fws.append( Firework([VaspToDBTask({'parse_uniform': True})], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-7)) connections[-8] = -7 # run GGA Band structure spec = { 'task_type': '{} band structure v2'.format(type_name), '_queueadapter': QA_VASP, '_dupefinder': DupeFinderVasp().to_dict(), '_priority': priority, '_trackers': trackers } fws.append( Firework([ VaspCopyTask({'use_CONTCAR': False}), SetupNonSCFTask({ 'mode': 'line', "kpoints_line_density": line_dens }), get_custodian_task(spec) ], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-6)) connections[-7] = [-6] # insert into DB - GGA Band structure spec = { 'task_type': 'VASP db insertion', '_queueadapter': QA_DB, '_allow_fizzled_parents': True, '_priority': priority * 2, "_dupefinder": DupeFinderDB().to_dict(), '_trackers': trackers_db } fws.append( Firework([VaspToDBTask({})], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-5)) connections[-6] = -5 if fw_spec.get('parameters') and fw_spec['parameters'].get( 'boltztrap'): # run Boltztrap from mpworks.firetasks.boltztrap_tasks import BoltztrapRunTask spec = { 'task_type': '{} Boltztrap'.format(type_name), '_queueadapter': QA_DB, '_dupefinder': DupeFinderDB().to_dict(), '_priority': priority } fws.append( Firework([BoltztrapRunTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-4)) connections[-7].append(-4) wf = Workflow(fws, connections) print 'Done adding more runs...' return FWAction(additions=wf)
def run_task(self, fw_spec): print 'sleeping 10s for Mongo' time.sleep(10) print 'done sleeping' print 'the gap is {}, the cutoff is {}'.format( fw_spec['analysis']['bandgap'], self.gap_cutoff) if fw_spec['analysis']['bandgap'] >= self.gap_cutoff: print 'Adding more runs...' type_name = 'GGA+U' if 'GGA+U' in fw_spec[ 'prev_task_type'] else 'GGA' snl = StructureNL.from_dict(fw_spec['mpsnl']) f = Composition( snl.structure.composition.reduced_formula).alphabetical_formula fws = [] connections = {} priority = fw_spec['_priority'] # run GGA static spec = fw_spec # pass all the items from the current spec to the new # one spec.update({ 'task_type': '{} static'.format(type_name), '_queueadapter': QA_VASP, '_dupefinder': DupeFinderVasp().to_dict(), '_priority': priority }) fws.append( Firework([ VaspCopyTask({'use_CONTCAR': True}), SetupStaticRunTask(), get_custodian_task(spec) ], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-10)) # insert into DB - GGA static spec = { 'task_type': 'VASP db insertion', '_queueadapter': QA_DB, '_allow_fizzled_parents': True, '_priority': priority, "_dupefinder": DupeFinderDB().to_dict() } fws.append( Firework([VaspToDBTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-9)) connections[-10] = -9 # run GGA Uniform spec = { 'task_type': '{} Uniform'.format(type_name), '_queueadapter': QA_VASP, '_dupefinder': DupeFinderVasp().to_dict(), '_priority': priority } fws.append( Firework([ VaspCopyTask({'use_CONTCAR': False}), SetupNonSCFTask({'mode': 'uniform'}), get_custodian_task(spec) ], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-8)) connections[-9] = -8 # insert into DB - GGA Uniform spec = { 'task_type': 'VASP db insertion', '_queueadapter': QA_DB, '_allow_fizzled_parents': True, '_priority': priority, "_dupefinder": DupeFinderDB().to_dict() } fws.append( Firework([VaspToDBTask({'parse_uniform': True})], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-7)) connections[-8] = -7 # run GGA Band structure spec = { 'task_type': '{} band structure'.format(type_name), '_queueadapter': QA_VASP, '_dupefinder': DupeFinderVasp().to_dict(), '_priority': priority } fws.append( Firework([ VaspCopyTask({'use_CONTCAR': False}), SetupNonSCFTask({'mode': 'line'}), get_custodian_task(spec) ], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-6)) connections[-7] = -6 # insert into DB - GGA Band structure spec = { 'task_type': 'VASP db insertion', '_queueadapter': QA_DB, '_allow_fizzled_parents': True, '_priority': priority, "_dupefinder": DupeFinderDB().to_dict() } fws.append( Firework([VaspToDBTask({})], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=-5)) connections[-6] = -5 wf = Workflow(fws, connections) print 'Done adding more runs...' return FWAction(additions=wf) return FWAction()
def snl_to_wf(snl, parameters=None): fws = [] connections = defaultdict(list) parameters = parameters if parameters else {} snl_priority = parameters.get('priority', 1) priority = snl_priority * 2 # once we start a job, keep going! f = Composition( snl.structure.composition.reduced_formula).alphabetical_formula snl_spec = {} if 'snlgroup_id' in parameters: if 'mpsnl' in parameters: snl_spec['mpsnl'] = parameters['mpsnl'] elif isinstance(snl, MPStructureNL): snl_spec['mpsnl'] = snl.as_dict() else: raise ValueError("improper use of force SNL") snl_spec['snlgroup_id'] = parameters['snlgroup_id'] else: # add the SNL to the SNL DB and figure out duplicate group tasks = [AddSNLTask()] spec = { 'task_type': 'Add to SNL database', 'snl': snl.as_dict(), '_queueadapter': QA_DB, '_priority': snl_priority } fws.append( Firework(tasks, spec, name=get_slug(f + '--' + spec['task_type']), fw_id=0)) connections[0] = [1] trackers = [ Tracker('FW_job.out'), Tracker('FW_job.error'), Tracker('vasp.out'), Tracker('OUTCAR'), Tracker('OSZICAR'), Tracker('OUTCAR.relax1'), Tracker('OUTCAR.relax2') ] trackers_db = [Tracker('FW_job.out'), Tracker('FW_job.error')] # run GGA structure optimization spec = _snl_to_spec(snl, enforce_gga=True, parameters=parameters) spec.update(snl_spec) spec['_priority'] = priority spec['_queueadapter'] = QA_VASP spec['_trackers'] = trackers tasks = [VaspWriterTask(), get_custodian_task(spec)] fws.append( Firework(tasks, spec, name=get_slug(f + '--' + spec['task_type']), fw_id=1)) # insert into DB - GGA structure optimization spec = { 'task_type': 'VASP db insertion', '_priority': priority * 2, '_allow_fizzled_parents': True, '_queueadapter': QA_DB, "_dupefinder": DupeFinderDB().to_dict(), '_trackers': trackers_db } fws.append( Firework([VaspToDBTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=2)) connections[1] = [2] # determine if GGA+U FW is needed incar = MPVaspInputSet().get_incar(snl.structure).as_dict() ggau_compound = ('LDAU' in incar and incar['LDAU']) if not parameters.get('skip_bandstructure', False) and ( not ggau_compound or parameters.get('force_gga_bandstructure', False)): spec = { 'task_type': 'Controller: add Electronic Structure v2', '_priority': priority, '_queueadapter': QA_CONTROL } fws.append( Firework([AddEStructureTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=3)) connections[2] = [3] if ggau_compound: spec = _snl_to_spec(snl, enforce_gga=False, parameters=parameters) del spec[ 'vasp'] # we are stealing all VASP params and such from previous run spec['_priority'] = priority spec['_queueadapter'] = QA_VASP spec['_trackers'] = trackers fws.append( Firework( [VaspCopyTask(), SetupGGAUTask(), get_custodian_task(spec)], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=10)) connections[2].append(10) spec = { 'task_type': 'VASP db insertion', '_queueadapter': QA_DB, '_allow_fizzled_parents': True, '_priority': priority, "_dupefinder": DupeFinderDB().to_dict(), '_trackers': trackers_db } fws.append( Firework([VaspToDBTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=11)) connections[10] = [11] if not parameters.get('skip_bandstructure', False): spec = { 'task_type': 'Controller: add Electronic Structure v2', '_priority': priority, '_queueadapter': QA_CONTROL } fws.append( Firework([AddEStructureTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=12)) connections[11] = [12] wf_meta = get_meta_from_structure(snl.structure) wf_meta['run_version'] = 'May 2013 (1)' if '_materialsproject' in snl.data and 'submission_id' in snl.data[ '_materialsproject']: wf_meta['submission_id'] = snl.data['_materialsproject'][ 'submission_id'] return Workflow( fws, connections, name=Composition( snl.structure.composition.reduced_formula).alphabetical_formula, metadata=wf_meta)
def snl_to_wf(snl, parameters=None): fws = [] connections = {} parameters = parameters if parameters else {} snl_priority = parameters.get('priority', 1) priority = snl_priority * 2 # once we start a job, keep going! f = Composition.from_formula( snl.structure.composition.reduced_formula).alphabetical_formula # add the SNL to the SNL DB and figure out duplicate group tasks = [AddSNLTask()] spec = { 'task_type': 'Add to SNL database', 'snl': snl.to_dict, '_queueadapter': QA_DB, '_priority': snl_priority } if 'snlgroup_id' in parameters and isinstance(snl, MPStructureNL): spec['force_mpsnl'] = snl.to_dict spec['force_snlgroup_id'] = parameters['snlgroup_id'] del spec['snl'] fws.append( FireWork(tasks, spec, name=get_slug(f + '--' + spec['task_type']), fw_id=0)) connections[0] = [1] # run GGA structure optimization spec = _snl_to_spec(snl, enforce_gga=True) spec['_priority'] = priority spec['_queueadapter'] = QA_VASP tasks = [VaspWriterTask(), get_custodian_task(spec)] fws.append( FireWork(tasks, spec, name=get_slug(f + '--' + spec['task_type']), fw_id=1)) # insert into DB - GGA structure optimization spec = { 'task_type': 'VASP db insertion', '_priority': priority, '_allow_fizzled_parents': True, '_queueadapter': QA_DB } fws.append( FireWork([VaspToDBTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=2)) connections[1] = [2] if not parameters.get('skip_bandstructure', False): spec = { 'task_type': 'Controller: add Electronic Structure v2', '_priority': priority, '_queueadapter': QA_CONTROL } fws.append( FireWork([AddEStructureTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=3)) connections[2] = [3] # determine if GGA+U FW is needed incar = MPVaspInputSet().get_incar(snl.structure).to_dict if 'LDAU' in incar and incar['LDAU']: spec = _snl_to_spec(snl, enforce_gga=False) del spec[ 'vasp'] # we are stealing all VASP params and such from previous run spec['_priority'] = priority spec['_queueadapter'] = QA_VASP fws.append( FireWork( [VaspCopyTask(), SetupGGAUTask(), get_custodian_task(spec)], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=10)) connections[2].append(10) spec = { 'task_type': 'VASP db insertion', '_queueadapter': QA_DB, '_allow_fizzled_parents': True, '_priority': priority } fws.append( FireWork([VaspToDBTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=11)) connections[10] = [11] if not parameters.get('skip_bandstructure', False): spec = { 'task_type': 'Controller: add Electronic Structure v2', '_priority': priority, '_queueadapter': QA_CONTROL } fws.append( FireWork([AddEStructureTask()], spec, name=get_slug(f + '--' + spec['task_type']), fw_id=12)) connections[11] = [12] wf_meta = get_meta_from_structure(snl.structure) wf_meta['run_version'] = 'May 2013 (1)' if '_materialsproject' in snl.data and 'submission_id' in snl.data[ '_materialsproject']: wf_meta['submission_id'] = snl.data['_materialsproject'][ 'submission_id'] return Workflow( fws, connections, name=Composition.from_formula( snl.structure.composition.reduced_formula).alphabetical_formula, metadata=wf_meta)
from mpworks.firetasks.vasp_io_tasks import VaspCopyTask, VaspToDBTask from mpworks.workflows.wf_utils import last_relax, get_loc, move_to_garden import os import shutil shutil.copyfile( '/lustre/home/umjzhh-2/pv_me2/config/config_SjtuPi/my_launchpad.yaml', 'my_launchpad.yaml') shutil.copyfile( '/lustre/home/umjzhh-2/pv_me2/config/config_SjtuPi/FW_config.yaml', 'FW_config.yaml') shutil.copyfile( '/lustre/home/umjzhh-2/pv_me2/config/config_SjtuPi/my_fworker.yaml', 'my_fworker.yaml') shutil.copyfile( '/lustre/home/umjzhh-2/pv_me2/config/config_SjtuPi/my_qadapter.yaml', 'my_qadapter.yaml') fw_spec = { "prev_vasp_dir": os.getcwd(), "prev_task_type": "GGA static v2", "run_tags": "GGA static v2", "dir_name": os.getcwd() } #GGA optimize structure (2x)"#"run_tags":"GGA static v2"#GGA static v2 #GGA optimize structure (2x) copy = VaspCopyTask() #copy.run_task(fw_spec) parameters = {"additional_fields": {}} to_db = VaspToDBTask() to_db.run_task(fw_spec)