本文整理汇总了Python中pymatgen.matproj.snl.StructureNL.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python StructureNL.from_dict方法的具体用法?Python StructureNL.from_dict怎么用?Python StructureNL.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pymatgen.matproj.snl.StructureNL
的用法示例。
在下文中一共展示了StructureNL.from_dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_from_dict
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def test_to_from_dict(self):
# no complicated objects in the 'data' or 'nodes' field
a = StructureNL(self.s, self.hulk, ['test_project'], self.pmg,
['remark1'], {"_my_data": "string"},
[self.valid_node, self.valid_node2])
b = StructureNL.from_dict(a.as_dict())
self.assertEqual(a, b)
# complicated objects in the 'data' and 'nodes' field
complicated_node = {
"name": "complicated node",
"url": "www.complicatednodegoeshere.com",
"description": {
"structure": self.s2
}
}
a = StructureNL(self.s, self.hulk, ['test_project'], self.pmg,
['remark1'], {"_my_data": {
"structure": self.s2
}}, [complicated_node, self.valid_node])
b = StructureNL.from_dict(a.as_dict())
self.assertEqual(
a, b, 'to/from dict is broken when object embedding is '
'used! Apparently MontyEncoding is broken...')
#Test molecule
molnl = StructureNL(self.mol, self.hulk, references=self.pmg)
b = StructureNL.from_dict(molnl.as_dict())
self.assertEqual(molnl, b)
示例2: run_task
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def run_task(self, fw_spec):
sma = SNLMongoAdapter.auto_load()
snl = StructureNL.from_dict(fw_spec['snl'])
mpsnl, snlgroup_id, spec_group = sma.add_snl(snl)
mod_spec = [{"_push": {"run_tags": "species_group={}".format(spec_group)}}] if spec_group else None
return FWAction(update_spec={'mpsnl': mpsnl.to_dict, 'snlgroup_id': snlgroup_id}, mod_spec=mod_spec)
示例3: run_task
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def run_task(self, fw_spec):
# get the SNL mongo adapter
sma = SNLMongoAdapter.auto_load()
# get the SNL
snl = StructureNL.from_dict(fw_spec['snl'])
# add snl
mpsnl, snlgroup_id = sma.add_snl(snl)
return FWAction(update_spec={'mpsnl': mpsnl.to_dict, 'snlgroup_id': snlgroup_id})
示例4: run_task
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def run_task(self, fw_spec):
# pass-through option for when we start with an mpsnl and don't actually want to add
if 'force_mpsnl' in fw_spec and 'force_snlgroup_id' in fw_spec:
print 'USING FORCED MPSNL'
return FWAction(update_spec={'mpsnl': fw_spec['force_mpsnl'], 'snlgroup_id': fw_spec['force_snlgroup_id']})
sma = SNLMongoAdapter.auto_load()
snl = StructureNL.from_dict(fw_spec['snl'])
mpsnl, snlgroup_id = sma.add_snl(snl)
return FWAction(update_spec={'mpsnl': mpsnl.to_dict, 'snlgroup_id': snlgroup_id})
示例5: from_snl
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def from_snl(snl, snl_id, sg_num, sg_symbol, hall, xtal_system, lattice_type):
# make a copy of SNL
snl2 = StructureNL.from_dict(snl.to_dict)
if '_materialsproject' not in snl2.data:
snl2.data['_materialsproject'] = {}
snl2.data['_materialsproject']['snl_id'] = snl_id
snl2.data['_materialsproject']['sg_num'] = sg_num
snl2.data['_materialsproject']['sg_symbol'] = sg_symbol
snl2.data['_materialsproject']['hall'] = hall
snl2.data['_materialsproject']['xtal_system'] = xtal_system
snl2.data['_materialsproject']['lattice_type'] = lattice_type
return MPStructureNL.from_dict(snl2.to_dict)
示例6: submit_new_workflow
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def submit_new_workflow(self):
# finds a submitted job, creates a workflow, and submits it to FireWorks
job = self.jobs.find_and_modify({'state': 'SUBMITTED'}, {'$set': {'state': 'WAITING'}})
if job:
submission_id = job['submission_id']
try:
if 'snl_id' in job:
snl = MPStructureNL.from_dict(job)
else:
snl = StructureNL.from_dict(job)
if len(snl.structure.sites) > SubmissionProcessor.MAX_SITES:
self.sma.update_state(submission_id, 'REJECTED', 'too many sites', {})
print 'REJECTED WORKFLOW FOR {} - too many sites ({})'.format(
snl.structure.formula, len(snl.structure.sites))
elif not job['is_valid']:
self.sma.update_state(submission_id, 'REJECTED',
'invalid structure (atoms too close)', {})
print 'REJECTED WORKFLOW FOR {} - invalid structure'.format(
snl.structure.formula)
elif len(set(NO_POTCARS) & set(job['elements'])) > 0:
self.sma.update_state(submission_id, 'REJECTED',
'invalid structure (no POTCAR)', {})
print 'REJECTED WORKFLOW FOR {} - invalid element (No POTCAR)'.format(
snl.structure.formula)
elif not job['is_ordered']:
self.sma.update_state(submission_id, 'REJECTED',
'invalid structure (disordered)', {})
print 'REJECTED WORKFLOW FOR {} - invalid structure'.format(
snl.structure.formula)
else:
snl.data['_materialsproject'] = snl.data.get('_materialsproject', {})
snl.data['_materialsproject']['submission_id'] = submission_id
# create a workflow
if "Elasticity" in snl.projects:
from mpworks.workflows.snl_to_wf_phonon import snl_to_wf_phonon
wf=snl_to_wf_phonon(snl, job['parameters'])
else:
wf = snl_to_wf(snl, job['parameters'])
self.launchpad.add_wf(wf)
print 'ADDED WORKFLOW FOR {}'.format(snl.structure.formula)
except:
self.jobs.find_and_modify({'submission_id': submission_id},
{'$set': {'state': 'ERROR'}})
traceback.print_exc()
return submission_id
示例7: from_snl
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def from_snl(snl, snl_id, sg_num, sg_symbol, hall, xtal_system, lattice_type, pointgroup):
# make a copy of SNL
snl2 = StructureNL.from_dict(snl.to_dict)
if '_materialsproject' not in snl2.data:
snl2.data['_materialsproject'] = {}
snl2.data['_materialsproject']['snl_id'] = snl_id
snl2.data['_materialsproject']['spacegroup'] = {}
sg = snl2.data['_materialsproject']['spacegroup']
sg['symbol'] = sg_symbol
sg['number'] = sg_num
sg['point_group'] = pointgroup
sg['crystal_system'] = xtal_system
sg['hall'] = hall
sg['lattice_type'] = lattice_type
return MPStructureNL.from_dict(snl2.to_dict)
示例8: from_snl
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def from_snl(snl, snl_id, sg_num, sg_symbol, hall, xtal_system, lattice_type, pointgroup):
# make a copy of SNL
snl2 = StructureNL.from_dict(snl.as_dict())
if "_materialsproject" not in snl2.data:
snl2.data["_materialsproject"] = {}
snl2.data["_materialsproject"]["snl_id"] = snl_id
snl2.data["_materialsproject"]["spacegroup"] = {}
sg = snl2.data["_materialsproject"]["spacegroup"]
sg["symbol"] = sg_symbol
sg["number"] = sg_num
sg["point_group"] = pointgroup
sg["crystal_system"] = xtal_system
sg["hall"] = hall
sg["lattice_type"] = lattice_type
return MPStructureNL.from_dict(snl2.as_dict())
示例9: submit_new_workflow
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def submit_new_workflow(self):
# finds a submitted job, creates a workflow, and submits it to FireWorks
job = self.jobs.find_and_modify({'state': 'submitted'}, {'$set': {'state': 'waiting'}})
if job:
submission_id = job['submission_id']
try:
snl = StructureNL.from_dict(job)
snl.data['_materialsproject'] = snl.data.get('_materialsproject', {})
snl.data['_materialsproject']['submission_id'] = submission_id
# create a workflow
wf = snl_to_wf(snl)
self.launchpad.add_wf(wf)
print 'ADDED WORKFLOW FOR {}'.format(snl.structure.formula)
except:
self.jobs.find_and_modify({'submission_id': submission_id}, {'$set': {'state': 'error'}})
traceback.print_exc()
return submission_id
示例10: job_is_submittable
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def job_is_submittable(job):
snl = StructureNL.from_dict(job)
# mpworks.processors.process_submissions.SubmissionProcessor#submit_new_workflow
max_sites = 200 # SubmissionProcessor.MAX_SITES above
# from mpworks.workflows.wf_utils import NO_POTCARS
no_potcars = ['Po', 'At', 'Rn', 'Fr', 'Ra', 'Am', 'Cm', 'Bk', 'Cf', 'Es', 'Fm', 'Md', 'No', 'Lr']
if len(snl.structure.sites) > max_sites:
print 'REJECTED WORKFLOW FOR {} - too many sites ({})'.format(
snl.structure.formula, len(snl.structure.sites))
elif not job['is_valid']:
print 'REJECTED WORKFLOW FOR {} - invalid structure (atoms too close)'.format(
snl.structure.formula)
elif len(set(no_potcars) & set(job['elements'])) > 0:
print 'REJECTED WORKFLOW FOR {} - invalid element (No POTCAR)'.format(
snl.structure.formula)
elif not job['is_ordered']:
print 'REJECTED WORKFLOW FOR {} - invalid structure (disordered)'.format(
snl.structure.formula)
else:
return True
return False
示例11: run_task
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
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",
#.........这里部分代码省略.........
示例12: process_fw
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def process_fw(self, dir_name, d):
d["task_id_deprecated"] = int(d["task_id"].split('-')[-1]) # useful for WC and AJ
# update the run fields to give species group in root, if exists
for r in d['run_tags']:
if "species_group=" in r:
d["species_group"] = int(r.split("=")[-1])
break
# custom Materials Project post-processing for FireWorks
with zopen(zpath(os.path.join(dir_name, 'FW.json'))) as f:
fw_dict = json.load(f)
d['fw_id'] = fw_dict['fw_id']
d['snl'] = fw_dict['spec']['mpsnl']
d['snlgroup_id'] = fw_dict['spec']['snlgroup_id']
d['vaspinputset_name'] = fw_dict['spec'].get('vaspinputset_name')
d['task_type'] = fw_dict['spec']['task_type']
# Process data for deformed structures
if 'deformed' in d['task_type']:
d['deformation_matrix'] = fw_dict['spec']['deformation_matrix']
d['original_task_id'] = fw_dict['spec']['original_task_id']
if not self.update_duplicates:
if 'optimize structure' in d['task_type'] and 'output' in d:
# create a new SNL based on optimized structure
new_s = Structure.from_dict(d['output']['crystal'])
old_snl = StructureNL.from_dict(d['snl'])
history = old_snl.history
history.append(
{'name': 'Materials Project structure optimization',
'url': 'http://www.materialsproject.org',
'description': {'task_type': d['task_type'],
'fw_id': d['fw_id'],
'task_id': d['task_id']}})
new_snl = StructureNL(new_s, old_snl.authors, old_snl.projects,
old_snl.references, old_snl.remarks,
old_snl.data, history)
# enter new SNL into SNL db
# get the SNL mongo adapter
sma = SNLMongoAdapter.auto_load()
# add snl
mpsnl, snlgroup_id, spec_group = sma.add_snl(new_snl, snlgroup_guess=d['snlgroup_id'])
d['snl_final'] = mpsnl.as_dict()
d['snlgroup_id_final'] = snlgroup_id
d['snlgroup_changed'] = (d['snlgroup_id'] !=
d['snlgroup_id_final'])
else:
d['snl_final'] = d['snl']
d['snlgroup_id_final'] = d['snlgroup_id']
d['snlgroup_changed'] = False
# custom processing for detecting errors
new_style = os.path.exists(zpath(os.path.join(dir_name, 'FW.json')))
vasp_signals = {}
critical_errors = ["INPUTS_DONT_EXIST",
"OUTPUTS_DONT_EXIST", "INCOHERENT_POTCARS",
"VASP_HASNT_STARTED", "VASP_HASNT_COMPLETED",
"CHARGE_UNCONVERGED", "NETWORK_QUIESCED",
"HARD_KILLED", "WALLTIME_EXCEEDED",
"ATOMS_TOO_CLOSE", "DISK_SPACE_EXCEEDED", "NO_RELAX2", "POSITIVE_ENERGY"]
last_relax_dir = dir_name
if not new_style:
# get the last relaxation dir
# the order is relax2, current dir, then relax1. This is because
# after completing relax1, the job happens in the current dir.
# Finally, it gets moved to relax2.
# There are some weird cases where both the current dir and relax2
# contain data. The relax2 is good, but the current dir is bad.
if is_valid_vasp_dir(os.path.join(dir_name, "relax2")):
last_relax_dir = os.path.join(dir_name, "relax2")
elif is_valid_vasp_dir(dir_name):
pass
elif is_valid_vasp_dir(os.path.join(dir_name, "relax1")):
last_relax_dir = os.path.join(dir_name, "relax1")
vasp_signals['last_relax_dir'] = last_relax_dir
## see what error signals are present
print "getting signals for dir :{}".format(last_relax_dir)
sl = SignalDetectorList()
sl.append(VASPInputsExistSignal())
sl.append(VASPOutputsExistSignal())
sl.append(VASPOutSignal())
sl.append(HitAMemberSignal())
sl.append(SegFaultSignal())
sl.append(VASPStartedCompletedSignal())
if d['state'] == 'successful' and 'optimize structure' in d['task_type']:
sl.append(Relax2ExistsSignal())
signals = sl.detect_all(last_relax_dir)
signals = signals.union(WallTimeSignal().detect(dir_name))
if not new_style:
root_dir = os.path.dirname(dir_name) # one level above dir_name
signals = signals.union(WallTimeSignal().detect(root_dir))
#.........这里部分代码省略.........
示例13: run_task
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
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
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)
示例14: run_task
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def run_task(self, fw_spec):
if '_fizzled_parents' in fw_spec and not 'prev_vasp_dir' in fw_spec:
prev_dir = get_loc(fw_spec['_fizzled_parents'][0]['launches'][0]['launch_dir'])
update_spec = {} # add this later when creating new FW
fizzled_parent = True
parse_dos = False
else:
prev_dir = get_loc(fw_spec['prev_vasp_dir'])
update_spec = {'prev_vasp_dir': prev_dir,
'prev_task_type': fw_spec['prev_task_type'],
'run_tags': fw_spec['run_tags'], 'parameters': fw_spec.get('parameters')}
fizzled_parent = False
parse_dos = 'Uniform' in fw_spec['prev_task_type']
if 'run_tags' in fw_spec:
self.additional_fields['run_tags'] = fw_spec['run_tags']
else:
self.additional_fields['run_tags'] = fw_spec['_fizzled_parents'][0]['spec']['run_tags']
if MOVE_TO_GARDEN_DEV:
prev_dir = move_to_garden(prev_dir, prod=False)
elif MOVE_TO_GARDEN_PROD:
prev_dir = move_to_garden(prev_dir, prod=True)
# get the directory containing the db file
db_dir = os.environ['DB_LOC']
db_path = os.path.join(db_dir, 'tasks_db.json')
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger('MPVaspDrone')
logger.setLevel(logging.INFO)
sh = logging.StreamHandler(stream=sys.stdout)
sh.setLevel(getattr(logging, 'INFO'))
logger.addHandler(sh)
with open(db_path) as f:
db_creds = json.load(f)
drone = MPVaspDrone(
host=db_creds['host'], port=db_creds['port'],
database=db_creds['database'], user=db_creds['admin_user'],
password=db_creds['admin_password'],
collection=db_creds['collection'], parse_dos=parse_dos,
additional_fields=self.additional_fields,
update_duplicates=self.update_duplicates)
t_id, d = drone.assimilate(prev_dir, launches_coll=LaunchPad.auto_load().launches)
mpsnl = d['snl_final'] if 'snl_final' in d else d['snl']
snlgroup_id = d['snlgroup_id_final'] if 'snlgroup_id_final' in d else d['snlgroup_id']
update_spec.update({'mpsnl': mpsnl, 'snlgroup_id': snlgroup_id})
print 'ENTERED task id:', t_id
stored_data = {'task_id': t_id}
if d['state'] == 'successful':
update_spec['analysis'] = d['analysis']
update_spec['output'] = d['output']
return FWAction(stored_data=stored_data, update_spec=update_spec)
# not successful - first test to see if UnconvergedHandler is needed
if not fizzled_parent:
unconverged_tag = 'unconverged_handler--{}'.format(fw_spec['prev_task_type'])
output_dir = last_relax(os.path.join(prev_dir, 'vasprun.xml'))
ueh = UnconvergedErrorHandler(output_filename=output_dir)
if ueh.check() and unconverged_tag not in fw_spec['run_tags']:
print 'Unconverged run! Creating dynamic FW...'
spec = {'prev_vasp_dir': prev_dir,
'prev_task_type': fw_spec['task_type'],
'mpsnl': mpsnl, 'snlgroup_id': snlgroup_id,
'task_type': fw_spec['prev_task_type'],
'run_tags': list(fw_spec['run_tags']),
'parameters': fw_spec.get('parameters'),
'_dupefinder': DupeFinderVasp().to_dict(),
'_priority': fw_spec['_priority']}
snl = StructureNL.from_dict(spec['mpsnl'])
spec['run_tags'].append(unconverged_tag)
spec['_queueadapter'] = QA_VASP
fws = []
connections = {}
f = Composition.from_formula(
snl.structure.composition.reduced_formula).alphabetical_formula
fws.append(FireWork(
[VaspCopyTask({'files': ['INCAR', 'KPOINTS', 'POSCAR', 'POTCAR', 'CONTCAR'],
'use_CONTCAR': False}), SetupUnconvergedHandlerTask(),
get_custodian_task(spec)], spec, name=get_slug(f + '--' + spec['task_type']),
fw_id=-2))
spec = {'task_type': 'VASP db insertion', '_allow_fizzled_parents': True,
'_priority': fw_spec['_priority'], '_queueadapter': QA_DB,
'run_tags': list(fw_spec['run_tags'])}
spec['run_tags'].append(unconverged_tag)
fws.append(
FireWork([VaspToDBTask()], spec, name=get_slug(f + '--' + spec['task_type']),
fw_id=-1))
connections[-2] = -1
wf = Workflow(fws, connections)
#.........这里部分代码省略.........
示例15: run_task
# 需要导入模块: from pymatgen.matproj.snl import StructureNL [as 别名]
# 或者: from pymatgen.matproj.snl.StructureNL import from_dict [as 别名]
def run_task(self, fw_spec):
from mpworks.workflows.snl_to_wf import _get_metadata, \
_get_custodian_task
# TODO: only add the workflow if the gap is > 1.0 eV
# TODO: add stored data?
if fw_spec['analysis']['bandgap'] >= self.gap_cutoff:
type_name = 'GGA+U' if 'GGA+U' in fw_spec['prev_task_type'] else 'GGA'
snl = StructureNL.from_dict(fw_spec['mpsnl'])
fws = []
connections = {}
# 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),
'_dupefinder': DupeFinderVasp().to_dict()})
spec.update(_get_metadata(snl))
fws.append(
FireWork(
[VaspCopyTask({'extension': '.relax2'}), SetupStaticRunTask(),
_get_custodian_task(spec)], spec, name=spec['task_type'], fw_id=-10))
# insert into DB - GGA static
spec = {'task_type': 'VASP db insertion',
'_allow_fizzled_parents': True}
spec.update(_get_metadata(snl))
fws.append(
FireWork([VaspToDBTask()], spec, name=spec['task_type'], fw_id=-9))
connections[-10] = -9
# run GGA Uniform
spec = {'task_type': '{} Uniform'.format(type_name),
'_dupefinder': DupeFinderVasp().to_dict()}
spec.update(_get_metadata(snl))
fws.append(FireWork(
[VaspCopyTask(), SetupNonSCFTask({'mode': 'uniform'}),
_get_custodian_task(spec)], spec, name=spec['task_type'], fw_id=-8))
connections[-9] = -8
# insert into DB - GGA Uniform
spec = {'task_type': 'VASP db insertion',
'_allow_fizzled_parents': True}
spec.update(_get_metadata(snl))
fws.append(
FireWork([VaspToDBTask({'parse_uniform': True})], spec, name=spec['task_type'],
fw_id=-7))
connections[-8] = -7
# run GGA Band structure
spec = {'task_type': '{} band structure'.format(type_name),
'_dupefinder': DupeFinderVasp().to_dict()}
spec.update(_get_metadata(snl))
fws.append(FireWork([VaspCopyTask(), SetupNonSCFTask({'mode': 'line'}),
_get_custodian_task(spec)], spec, name=spec['task_type'],
fw_id=-6))
connections[-7] = -6
# insert into DB - GGA Band structure
spec = {'task_type': 'VASP db insertion',
'_allow_fizzled_parents': True}
spec.update(_get_metadata(snl))
fws.append(FireWork([VaspToDBTask({})], spec, name=spec['task_type'], fw_id=-5))
connections[-6] = -5
wf = Workflow(fws, connections)
return FWAction(additions=wf)
return FWAction()