def __init__(self, docking, filename=None, parser=None):
     self.docking = docking
     self.filename = filename
     if filename:
         if not parser:
             parser = DlgParser()
         self.parser = parser
         parser.parse(filename)
         #for now, keep info about ad3 vs ad4
         self.version = parser.version
         self.dlgFile = filename
         self.dpo = self._buildDpo(parser.dpfLines)
         #if the autodock job did not finish, all models do not exist
         #so shorten the expected list of conformations to actual value
         if len(parser.modelList)<self.dpo['ga_run']['value']:
             self.dpo['ga_run']['value']= len(parser.modelList)
         self.output = parser.histogramlines
         ##???
         self.macroStem = self.dpo.receptor_stem
         self.macroFile = self.macroStem + '.pdbqs'
         if self.parser.version>=4.0:
             self.macroFile = self.macroStem + '.pdbqt'
         ##???
         filename = self.dpo['move']['value']
         if self.docking and not hasattr(self.docking, 'ligMol'):
             ligMol = self._buildInputLig(parser.ligLines, filename=filename)
             if ligMol is not None:
                 ligMol.filename = self.dpo['move']['value']
                 ligMol.name = os.path.splitext(ligMol.filename)[0]
                 self.docking.ligMol = ligMol
                 ligMol.trueLigAtoms = ligMol.allAtoms
                 if hasattr(self, 'flex_res') and self.flex_res:
                     self.docking.flex_res = self.flex_res
                     trueLigAtoms = ligMol.trueLigAtoms
                     for r in self.flex_res:
                         if r.name in ligMol.chains.residues.name:
                             for a in r.atoms:
                                 thisAt = ligMol.allAtoms.get(a.name)
                                 trueLigAtoms = trueLigAtoms - thisAt
                     ligMol.trueLigAtoms = trueLigAtoms 
                 ligMol.lenNonHAtoms = len(ligMol.trueLigAtoms.get(lambda x: x.element!='H'))
            directory = a
            if verbose: print 'set directory to ', a
        if o in ('-o', '--o'):
            outputfilename = a
            if verbose: print 'set outputfilename to ', a
        if o in ('-v', '--v'):
            verbose = True
            if verbose: print 'set verbose to ', True
        if o in ('-h', '--'):
            usage()
            sys.exit()

    if not  directory:
        print 'summarize_time: directory must be specified.'
        usage()
        sys.exit()

    p = DlgParser()
    dlg_list = glob.glob(directory + '/*.dlg')
    for dlg in dlg_list:
        p.parse(dlg)
    stem = dlg_list[0].split('.')[0]
    ostr = '%s: % 12.4f m \n' %(directory, p.total_time) 
    fptr = open(outputfilename, 'a')
    fptr.write(ostr)
    fptr.close()

# To execute this command type:
# summarize_time.py -d directory -o outputfilename -v

        if o in ('-d', '--d'):
            directory = a
            if verbose: print 'set directory to ', a
        if o in ('-o', '--o'):
            outputfilename = a
            if verbose: print 'set outputfilename to ', a
        if o in ('-v', '--v'):
            verbose = True
            if verbose: print 'set verbose to ', True
        if o in ('-h', '--'):
            usage()
            sys.exit()

    if not directory:
        print 'summarize_time: directory must be specified.'
        usage()
        sys.exit()

    p = DlgParser()
    dlg_list = glob.glob(directory + '/*.dlg')
    for dlg in dlg_list:
        p.parse(dlg)
    stem = dlg_list[0].split('.')[0]
    ostr = '%s: % 12.4f m \n' % (directory, p.total_time)
    fptr = open(outputfilename, 'a')
    fptr.write(ostr)
    fptr.close()

# To execute this command type:
# summarize_time.py -d directory -o outputfilename -v