Hi AJ,
I am new to the FireWorks. I try to write a customized FireTask – InsLogTask and pass an object (options) through fw_spec. The FireTask class is:
from fireworks.core.firework import FireTaskBase, FWAction
from fireworks.utilities.fw_utilities import explicit_serialize
import re
@explicit_serialize
class InsLogTask(FireTaskBase):
_fw_name = "InsLogTask"
def run_task(self, fw_spec):
options=fw_spec['opts']
scrDir = options.scrDir
logFile = scrDir + '/' + options.insaneLog
memRe=re.compile("NDX Membrane")
solRe=re.compile("NDX Solvent")
with open(logFile, 'r') as f:
for line in f:
if(re.search(memRe, line)):
strs=line.split()
options.NDX_Mem_Beg=int(strs[3])
options.NDX_Mem_End=int(strs[4])
if (re.search(solRe, line)):
strs = line.split()
options.NDX_Sol_Beg = int(strs[3])
options.NDX_Sol_End = int(strs[4])
print options.NDX_Mem_Beg, options.NDX_Mem_End, options.NDX_Sol_Beg, options.NDX_Sol_End
return FWAction()
The Options class is:
class Options(yaml.YAMLObject):
yaml_tag = u'!Options'
def __init__(self, cDir, log, gfile, sfile):
self.curDir=None
self.scrDir=None
self.appDir=None
self.NDX_Mem_Beg=None
self.NDX_Mem_End=None
self.NDX_Sol_Beg=None
self.NDX_Sol_End=None
…
And it is called in the main function as:
fh=open(args.iFile)
options=yaml.load(fh)
…
fw = Firework(InsLogTask(), spec={'opts': options})
The error message:
···
=====================
2016-05-27 10:48:49,607 INFO RUNNING fw_id: 1 in directory: /Users/zhang30/workspace/PycharmProjects/fireworks/ras_wf/launcher_2016-05-27-17-48-49-513553
2016-05-27 10:48:49,610 INFO Task started: {{fireworks.user_objects.ras_objects.insLogExTask.InsLogTask}}.
Traceback (most recent call last):
File “/Users/zhang30/workspace/PycharmProjects/fireworks/fireworks/core/rocket.py”, line 213, in run
m_action = t.run_task(my_spec)
File “/Users/zhang30/workspace/PycharmProjects/fireworks/fireworks/user_objects/ras_objects/insLogExTask.py”, line 11, in run_task
scrDir = options.scrDir
AttributeError: ‘unicode’ object has no attribute ‘scrDir’
2016-05-27 10:48:49,699 INFO Rocket finished
Process finished with exit code 0
=====================
Do you how I can fix it? I try to pass the options into Fire task, update the options, and eventually return the updated options. Can you tell me how to do it?
Thank you!
Xiaohua Zhang