def rungen(rundir,args,chspfname,globs): try: from Classes.mWidgets import qBoxFolder from Classes.mWidgets import mQDialogInf from Classes.mWidgets import mQDialogErr except ImportError: args.gui = False emsg = False globs.nosmiles = 0 # reset smiles ligands for each run # check for specified ligands/functionalization ligocc = [] # check for files specified for multiple ligands mligs,catoms = [False],[False] if args.lig is not None: if '.smi' in args.lig[0]: ligfilename = args.lig[0].split('.')[0] if args.lig: mligs,catoms,multidx = checkmultilig(args.lig) if args.debug: print('after checking for mulitple ligs, we found ' + str(multidx) + ' ligands' ) # save initial smicat0 = [ss for ss in args.smicat] if args.smicat else False # loop over ligands for mcount, mlig in enumerate(mligs): args.smicat = [ss for ss in smicat0] if smicat0 else False args.checkdir, skip = False, False # initialize flags if len(mligs) > 0 and mligs[0]: args.lig = mlig # get combination if multidx!=-1: if catoms[multidx][mcount]: ssatoms = catoms[multidx][mcount].split(',') lloc = [int(scat)-1 for scat in ssatoms] # append connection atoms if specified in smiles if args.smicat and len(args.smicat) > 0: for i in range(len(args.smicat),multidx): args.smicat.append([]) else: args.smicat = [lloc] args.smicat[multidx] = lloc if (args.lig): ligands = args.lig if (args.ligocc): ligocc = args.ligocc else: ligocc = ['1'] for i in range(len(ligocc),len(ligands)): ligocc.append('1') lig = '' for i,l in enumerate(ligands): ligentry,emsg = lig_load(l) # update ligand if ligentry: ligands[i] = ligentry.name args.lig[i] = ligentry.name if emsg: skip = True break if ligentry.ident == 'smi': ligentry.ident += str(globs.nosmiles) globs.nosmiles += 1 if args.sminame: if len(args.sminame) > int(ligentry.ident[-1]): ligentry.ident = args.sminame[globs.nosmiles-1][0:3] lig += ''.join("%s%s" % (ligentry.ident,ligocc[i])) else: ligands =[] lig = '' ligocc = '' ##### fetch smart name fname = name_complex(rundir,args.core,args.geometry,ligands,ligocc,mcount,args,nconf=False,sanity=False,bind=args.bind,bsmi=args.nambsmi) if args.tsgen: substrate = args.substrate subcatoms = ['multiple'] if args.subcatoms: subcatoms = args.subcatoms mlig = args.mlig mligcatoms = args.mligcatoms fname = name_ts_complex(rundir,args.core,args.geometry,ligands,ligocc,substrate,subcatoms,mlig,mligcatoms,mcount,args,nconf=False,sanity=False,bind=args.bind,bsmi=args.nambsmi) if globs.debug: print('fname is ' + str(fname)) rootdir = fname # check for charges/spin rootcheck = False if (chspfname): rootcheck = rootdir rootdir = rootdir + '/'+chspfname if (args.suff): rootdir += args.suff # check for mannual overwrite of # directory name if args.jobdir: rootdir = rundir + args.jobdir # check for top directory if rootcheck and os.path.isdir(rootcheck) and not args.checkdirt and not skip: args.checkdirt = True if not args.rprompt: flagdir=raw_input('\nDirectory '+rootcheck +' already exists. Keep both (k), replace (r) or skip (s) k/r/s: ') if 'k' in flagdir.lower(): flagdir = 'keep' elif 's' in flagdir.lower(): flagdir = 'skip' else: flagdir = 'replace' else: #qqb = qBoxFolder(args.gui.wmain,'Folder exists','Directory '+rootcheck+' already exists. What do you want to do?') #flagdir = qqb.getaction() flagdir = 'replace' # replace existing directory if (flagdir=='replace'): shutil.rmtree(rootcheck) os.mkdir(rootcheck) # skip existing directory elif flagdir=='skip': skip = True # keep both (default) else: ifold = 1 while glob.glob(rootdir+'_'+str(ifold)): ifold += 1 rootcheck += '_'+str(ifold) os.mkdir(rootcheck) elif rootcheck and (not os.path.isdir(rootcheck) or not args.checkdirt) and not skip: if globs.debug: print('rootcheck is ' + str(rootcheck)) args.checkdirt = True try: os.mkdir(rootcheck) except: print 'Directory '+rootcheck+' can not be created. Exiting..\n' return # check for actual directory if os.path.isdir(rootdir) and not args.checkdirb and not skip and not args.jobdir: args.checkdirb = True if not args.rprompt: flagdir=raw_input('\nDirectory '+rootdir +' already exists. Keep both (k), replace (r) or skip (s) k/r/s: ') if 'k' in flagdir.lower(): flagdir = 'keep' elif 's' in flagdir.lower(): flagdir = 'skip' else: flagdir = 'replace' else: #qqb = qBoxFolder(args.gui.wmain,'Folder exists','Directory '+rootdir+' already exists. What do you want to do?') #flagdir = qqb.getaction() flagdir = 'replace' # replace existing directory if (flagdir=='replace'): shutil.rmtree(rootdir) os.mkdir(rootdir) # skip existing directory elif flagdir=='skip': skip = True # keep both (default) else: ifold = 1 while glob.glob(rootdir+'_'+str(ifold)): ifold += 1 rootdir += '_'+str(ifold) os.mkdir(rootdir) elif not os.path.isdir(rootdir) or not args.checkdirb and not skip: if not os.path.isdir(rootdir): args.checkdirb = True os.mkdir(rootdir) #################################### ############ GENERATION ############ #################################### if not skip: # check for generate all if args.genall: tstrfiles = [] # generate xyz with FF and trained ML args.ff = 'mmff94' args.ffoption = 'ba' args.MLbonds = False strfiles,emsg,this_diag = structgen(args,rootdir,ligands,ligocc,globs,mcount) for strf in strfiles: tstrfiles.append(strf+'FFML') os.rename(strf+'.xyz',strf+'FFML.xyz') # generate xyz with FF and covalent args.MLbonds = ['c' for i in range(0,len(args.lig))] strfiles,emsg,this_diag = structgen(args,rootdir,ligands,ligocc,globs,mcount) for strf in strfiles: tstrfiles.append(strf+'FFc') os.rename(strf+'.xyz',strf+'FFc.xyz') args.ff = False args.ffoption = False args.MLbonds = False # generate xyz without FF and trained ML strfiles,emsg,this_diag = structgen(args,rootdir,ligands,ligocc,globs,mcount) for strf in strfiles: tstrfiles.append(strf+'ML') os.rename(strf+'.xyz',strf+'ML.xyz') args.MLbonds = ['c' for i in range(0,len(args.lig))] # generate xyz without FF and covalent ML strfiles,emsg,this_diag = structgen(args,rootdir,ligands,ligocc,globs,mcount) for strf in strfiles: tstrfiles.append(strf+'c') os.rename(strf+'.xyz',strf+'c.xyz') strfiles = tstrfiles else: # generate xyz files strfiles,emsg,this_diag = structgen(args,rootdir,ligands,ligocc,globs,mcount) # generate QC input files if args.qccode and not emsg: if args.charge and (isinstance(args.charge, list)): args.charge = args.charge[0] if args.spin and (isinstance(args.spin, list)): args.spin = args.spin[0] if args.qccode.lower() in 'terachem tc Terachem TeraChem TERACHEM TC': jobdirs = multitcgen(args,strfiles) print 'TeraChem input files generated!' elif 'gam' in args.qccode.lower(): jobdirs = multigamgen(args,strfiles) print 'GAMESS input files generated!' elif 'qch' in args.qccode.lower(): jobdirs = multiqgen(args,strfiles) print 'QChem input files generated!' elif 'orc' in args.qccode.lower(): jobdirs = multiogen(args,strfiles) print 'ORCA input files generated!' elif 'molc' in args.qccode.lower(): jobdirs = multimolcgen(args,strfiles) print 'MOLCAS input files generated!' else: print 'Only TeraChem, GAMESS, QChem, ORCA, MOLCAS are supported right now.\n' # check molpac if args.mopac and not emsg: print('Generating MOPAC input') if globs.debug: print(strfiles) jobdirs = mlpgen(args,strfiles,rootdir) # generate jobscripts if args.jsched and not emsg: if args.jsched in 'SBATCH SLURM slurm sbatch': slurmjobgen(args,jobdirs) print 'SLURM jobscripts generated!' elif args.jsched in 'SGE Sungrid sge': sgejobgen(args,jobdirs) print 'SGE jobscripts generated!' elif multidx != -1: # if ligand input was a list of smiles strings, write good smiles strings to separate list try: f = open(ligfilename+'-good.smi','a') f.write(args.lig[0]) f.close() except: 0 elif not emsg: if args.gui: qq = mQDialogInf('Folder skipped','Folder '+rootdir+' was skipped.') qq.setParent(args.gui.wmain) else: print 'Folder '+rootdir+' was skipped..\n' return emsg # ## Transition state generation # # @param rundir Run directory # # @param args Namespace of arguments # # @param chspfname Folder name for charges and spins # # @param globs Global variables # # @return Error messages # def tsgen_supervisor(rundir,args,chspfname,globs): # emsg = False # # load specified core into a mol3D object # cc, emsg = core_load(args.core) # if emsg: # return emsg # cc.convert2mol3D() # subcores = getsubcores() # # load substrate molecule into a mol3D object # if len(args.substrate) > 1: # print('Currently only one substrate molecule is supported. Exiting...') # return # else: # substr, emsg = substr_load(args.substrate[0],subcores) # if emsg: # return emsg # substr.convert2mol3D() # ##### fetch smart name # fname = name_TS(rundir,args.core,substr,args,bind=args.bind,bsmi=args.nambsmi) # if globs.debug: # print('fname is ' + str(fname)) # rootdir = fname # # check for charges/spin # rootcheck = False # if (chspfname): # rootcheck = rootdir # rootdir = rootdir + '/'+chspfname # if (args.suff): # rootdir += args.suff # # check for mannual overwrite of # # directory name # if args.jobdir: # rootdir = rundir + args.jobdir # # check for top directory # skip = False # if rootcheck and os.path.isdir(rootcheck) and not args.checkdirt and not skip: # args.checkdirt = True # if not args.rprompt: # flagdir=raw_input('\nDirectory '+rootcheck +' already exists. Keep both (k), replace (r) or skip (s) k/r/s: ') # if 'k' in flagdir.lower(): # flagdir = 'keep' # elif 's' in flagdir.lower(): # flagdir = 'skip' # else: # flagdir = 'replace' # else: # flagdir = 'replace' # # replace existing directory # if (flagdir=='replace'): # shutil.rmtree(rootcheck) # os.mkdir(rootcheck) # # skip existing directory # elif flagdir=='skip': # skip = True # # keep both (default) # else: # ifold = 1 # while glob.glob(rootdir+'_'+str(ifold)): # ifold += 1 # rootcheck += '_'+str(ifold) # os.mkdir(rootcheck) # elif rootcheck and (not os.path.isdir(rootcheck) or not args.checkdirt) and not skip: # if globs.debug: # print('rootcheck is ' + str(rootcheck)) # args.checkdirt = True # try: # os.mkdir(rootcheck) # except: # print 'Directory '+rootcheck+' can not be created. Exiting..\n' # return # # check for actual directory # if os.path.isdir(rootdir) and not args.checkdirb and not skip and not args.jobdir: # args.checkdirb = True # if not args.rprompt: # flagdir=raw_input('\nDirectory '+rootdir +' already exists. Keep both (k), replace (r) or skip (s) k/r/s: ') # if 'k' in flagdir.lower(): # flagdir = 'keep' # elif 's' in flagdir.lower(): # flagdir = 'skip' # else: # flagdir = 'replace' # else: # #qqb = qBoxFolder(args.gui.wmain,'Folder exists','Directory '+rootdir+' already exists. What do you want to do?') # #flagdir = qqb.getaction() # flagdir = 'replace' # # replace existing directory # if (flagdir=='replace'): # shutil.rmtree(rootdir) # os.mkdir(rootdir) # # skip existing directory # elif flagdir=='skip': # skip = True # # keep both (default) # else: # ifold = 1 # while glob.glob(rootdir+'_'+str(ifold)): # ifold += 1 # rootdir += '_'+str(ifold) # os.mkdir(rootdir) # elif not os.path.isdir(rootdir) or not args.checkdirb and not skip: # if not os.path.isdir(rootdir): # args.checkdirb = True # os.mkdir(rootdir) # #################################### # ############ GENERATION ############ # #################################### # # determine TS generation mode/reaction type # # 1: oxidative addition of a single group to an unsaturated complex (e.g., Fe(II) + O2 -> Fe(III)-O-O) # # 2: oxidative addition of two groups to an unsaturated complex (e.g., Pd + CH4 -> Pd(H)(CH3)) # # 3: abstraction (ligand only reaction) (e.g., Fe(IV)=O + CH4 -> Fe(III)-OH + CH3) # # 1: compreact is the metal center, substreact is one atom # # 2: compreact is the metal center, substreact is two bonded atoms # # 3: compreact is not the metal center and bonded to only one atom, substreact is one atom # if len(args.compreact) == 1: # compreact = int(args.compreact[0]) - 1 # one-indexed in input # else: # print('Error: Currently only one complex reacting atom is supported. Exiting...') # return # if cc.getAtom(compreact).ismetal(): # if len(args.substreact) == 1: # substreact = int(args.substreact[0]) - 1 # one-indexed in input # if len(substr.getBondedAtoms(substreact)) == 1: # if len(cc.getBondedAtomsOct(compreact)) < 6: # mode = 1 # print('Mode 1: oxidative addition of a single group') # else: # print('Error: You have specified oxidative addition of a single group, but the metal atom is not unsaturated. Please check your input. Exiting...') # return # else: # print('Error: You have specified oxidative addition of a single group, but the substrate atom is not terminal. Please check your input. Exiting...') # return # elif len(args.substreact) == 2: # if int(args.substreact[1]) in substr.getBondedAtoms(int(args.substreact[0])): # if len(cc.getBondedAtomsOct(compreact)) < 5: # substreact = [int(i) - 1 for i in args.substreact] # one-indexed in input # mode = 2 # print('Mode 2: oxidative addition of two groups') # else: # print('Error: You have specified oxidative addition of two groups, but the metal atom does not have two available empty sites. Please check your input. Exiting...') # return # else: # print('Error: You have specified oxidative addition of two groups, but the two substrate groups are not bonded. Please check your input. Exiting...') # return # elif len(cc.getBondedAtoms(compreact)) == 1: # if len(args.substreact) == 1: # substreact = int(args.substreact[0]) - 1 # one-indexed in input # else: # print('Error: You have specified abstraction, but specified more than one substrate atom. Please check your input. Exiting...') # return # if len(substr.getBondedAtoms(substreact)) == 1: # mode = 3 # print('Mode 3: Abstraction') # else: # print('Error: You have specified abstraction, but the substrate atom is not terminal. Please check your input. Exiting...') # return # else: # print('Error: You have specified abstraction, but the abstracting atom is not terminal. Please check your input. Exiting...') # return # if not skip: # # generate xyz files # strfiles,emsg,this_diag = tsgen(mode,args,rootdir,cc,substr,compreact,substreact,globs) # # generate QC input files # if args.qccode and not emsg: # args.runtyp = 'ts' # if args.charge and (isinstance(args.charge, list)): # args.charge = args.charge[0] # if args.spin and (isinstance(args.spin, list)): # args.spin = args.spin[0] # if args.qccode.lower() in 'terachem tc Terachem TeraChem TERACHEM TC': # jobdirs = multitcgen(args,strfiles) # print 'TeraChem input files generated!' # elif 'gam' in args.qccode.lower(): # jobdirs = multigamgen(args,strfiles) # print 'GAMESS input files generated!' # elif 'qch' in args.qccode.lower(): # jobdirs = multiqgen(args,strfiles) # print 'QChem input files generated!' # else: # print 'Only TeraChem, GAMESS and QChem are supported right now.\n' # # generate jobscripts # if args.jsched and not emsg: # if args.jsched in 'SBATCH SLURM slurm sbatch': # slurmjobgen(args,jobdirs) # print 'SLURM jobscripts generated!' # elif args.jsched in 'SGE Sungrid sge': # sgejobgen(args,jobdirs) # print 'SGE jobscripts generated!' # if this_diag.sanity: # move to separate subdirectory if generated structure was bad # fname = rootdir.rsplit('/',1)[-1] # shutil.move(rootdir,rundir+'/badjobs/'+fname) # elif not emsg: # print 'Folder '+rootdir+' was skipped..\n' # return emsg
def rungen(rundir,args,chspfname,globs): try: from Classes.mWidgets import qBoxFolder from Classes.mWidgets import mQDialogInf from Classes.mWidgets import mQDialogErr except ImportError: args.gui = False emsg = False globs.nosmiles = 0 # reset smiles ligands for each run # check for specified ligands/functionalization ligocc = [] # check for files specified for multiple ligands mligs,catoms = [False],[False] if args.lig is not None: if '.smi' in args.lig[0]: ligfilename = args.lig[0].split('.')[0] if args.lig: mligs,catoms,multidx = checkmultilig(args.lig) if args.debug: print('after checking for mulitple ligs, we found ' + str(multidx) + ' ligands' ) # save initial smicat0 = [ss for ss in args.smicat] if args.smicat else False # loop over ligands for mcount, mlig in enumerate(mligs): args.smicat = [ss for ss in smicat0] if smicat0 else False args.checkdir, skip = False, False # initialize flags if len(mligs) > 0 and mligs[0]: args.lig = mlig # get combination if multidx!=-1: if catoms[multidx][mcount]: ssatoms = catoms[multidx][mcount].split(',') lloc = [int(scat)-1 for scat in ssatoms] # append connection atoms if specified in smiles if args.smicat and len(args.smicat) > 0: for i in range(len(args.smicat),multidx): args.smicat.append([]) else: args.smicat = [lloc] args.smicat[multidx] = lloc if (args.lig): ligands = args.lig if (args.ligocc): ligocc = args.ligocc else: ligocc = ['1'] for i in range(len(ligocc),len(ligands)): ligocc.append('1') lig = '' for i,l in enumerate(ligands): ligentry,emsg = lig_load(l) # update ligand if ligentry: ligands[i] = ligentry.name args.lig[i] = ligentry.name if emsg: skip = True break if ligentry.ident == 'smi': ligentry.ident += str(globs.nosmiles) globs.nosmiles += 1 if args.sminame: if len(args.sminame) > int(ligentry.ident[-1]): ligentry.ident = args.sminame[globs.nosmiles-1][0:3] lig += ''.join("%s%s" % (ligentry.ident,ligocc[i])) else: ligands =[] lig = '' ligocc = '' ##### fetch smart name fname = name_complex(rundir,args.core,args.geometry,ligands,ligocc,mcount,args,nconf=False,sanity=False,bind=args.bind,bsmi=args.nambsmi) if args.tsgen: substrate = args.substrate subcatoms = ['multiple'] if args.subcatoms: subcatoms = args.subcatoms mlig = args.mlig mligcatoms = args.mligcatoms fname = name_ts_complex(rundir,args.core,args.geometry,ligands,ligocc,substrate,subcatoms,mlig,mligcatoms,mcount,args,nconf=False,sanity=False,bind=args.bind,bsmi=args.nambsmi) if globs.debug: print('fname is ' + str(fname)) rootdir = fname # check for charges/spin rootcheck = False if (chspfname): rootcheck = rootdir rootdir = rootdir + '/'+chspfname if (args.suff): rootdir += args.suff # check for mannual overwrite of # directory name if args.jobdir: rootdir = rundir + args.jobdir # check for top directory if rootcheck and os.path.isdir(rootcheck) and not args.checkdirt and not skip: args.checkdirt = True if not args.rprompt: flagdir=raw_input('\nDirectory '+rootcheck +' already exists. Keep both (k), replace (r) or skip (s) k/r/s: ') if 'k' in flagdir.lower(): flagdir = 'keep' elif 's' in flagdir.lower(): flagdir = 'skip' else: flagdir = 'replace' else: #qqb = qBoxFolder(args.gui.wmain,'Folder exists','Directory '+rootcheck+' already exists. What do you want to do?') #flagdir = qqb.getaction() flagdir = 'replace' # replace existing directory if (flagdir=='replace'): shutil.rmtree(rootcheck) os.mkdir(rootcheck) # skip existing directory elif flagdir=='skip': skip = True # keep both (default) else: ifold = 1 while glob.glob(rootdir+'_'+str(ifold)): ifold += 1 rootcheck += '_'+str(ifold) os.mkdir(rootcheck) elif rootcheck and (not os.path.isdir(rootcheck) or not args.checkdirt) and not skip: if globs.debug: print('rootcheck is ' + str(rootcheck)) args.checkdirt = True try: os.mkdir(rootcheck) except: print 'Directory '+rootcheck+' can not be created. Exiting..\n' return # check for actual directory if os.path.isdir(rootdir) and not args.checkdirb and not skip and not args.jobdir: args.checkdirb = True if not args.rprompt: flagdir=raw_input('\nDirectory '+rootdir +' already exists. Keep both (k), replace (r) or skip (s) k/r/s: ') if 'k' in flagdir.lower(): flagdir = 'keep' elif 's' in flagdir.lower(): flagdir = 'skip' else: flagdir = 'replace' else: #qqb = qBoxFolder(args.gui.wmain,'Folder exists','Directory '+rootdir+' already exists. What do you want to do?') #flagdir = qqb.getaction() flagdir = 'replace' # replace existing directory if (flagdir=='replace'): shutil.rmtree(rootdir) os.mkdir(rootdir) # skip existing directory elif flagdir=='skip': skip = True # keep both (default) else: ifold = 1 while glob.glob(rootdir+'_'+str(ifold)): ifold += 1 rootdir += '_'+str(ifold) os.mkdir(rootdir) elif not os.path.isdir(rootdir) or not args.checkdirb and not skip: if not os.path.isdir(rootdir): args.checkdirb = True os.mkdir(rootdir) #################################### ############ GENERATION ############ #################################### if not skip: # check for generate all if args.genall: tstrfiles = [] # generate xyz with FF and trained ML args.ff = 'mmff94' args.ffoption = 'ba' args.MLbonds = False strfiles,emsg,this_diag = structgen(args,rootdir,ligands,ligocc,globs,mcount) for strf in strfiles: tstrfiles.append(strf+'FFML') os.rename(strf+'.xyz',strf+'FFML.xyz') # generate xyz with FF and covalent args.MLbonds = ['c' for i in range(0,len(args.lig))] strfiles,emsg,this_diag = structgen(args,rootdir,ligands,ligocc,globs,mcount) for strf in strfiles: tstrfiles.append(strf+'FFc') os.rename(strf+'.xyz',strf+'FFc.xyz') args.ff = False args.ffoption = False args.MLbonds = False # generate xyz without FF and trained ML strfiles,emsg,this_diag = structgen(args,rootdir,ligands,ligocc,globs,mcount) for strf in strfiles: tstrfiles.append(strf+'ML') os.rename(strf+'.xyz',strf+'ML.xyz') args.MLbonds = ['c' for i in range(0,len(args.lig))] # generate xyz without FF and covalent ML strfiles,emsg,this_diag = structgen(args,rootdir,ligands,ligocc,globs,mcount) for strf in strfiles: tstrfiles.append(strf+'c') os.rename(strf+'.xyz',strf+'c.xyz') strfiles = tstrfiles else: # generate xyz files strfiles,emsg,this_diag = structgen(args,rootdir,ligands,ligocc,globs,mcount) # generate QC input files if args.qccode and not emsg: if args.charge and (isinstance(args.charge, list)): args.charge = args.charge[0] if args.spin and (isinstance(args.spin, list)): args.spin = args.spin[0] if args.qccode.lower() in 'terachem tc Terachem TeraChem TERACHEM TC': jobdirs = multitcgen(args,strfiles) print 'TeraChem input files generated!' elif 'gam' in args.qccode.lower(): jobdirs = multigamgen(args,strfiles) print 'GAMESS input files generated!' elif 'qch' in args.qccode.lower(): jobdirs = multiqgen(args,strfiles) print 'QChem input files generated!' elif 'orc' in args.qccode.lower(): jobdirs = multiogen(args,strfiles) print 'ORCA input files generated!' elif 'molc' in args.qccode.lower(): jobdirs = multimolcgen(args,strfiles) print 'MOLCAS input files generated!' else: print 'Only TeraChem, GAMESS, QChem, ORCA, MOLCAS are supported right now.\n' # check molpac if args.mopac and not emsg: print('Generating MOPAC input') if globs.debug: print(strfiles) jobdirs = mlpgen(args,strfiles,rootdir) # generate jobscripts if args.jsched and not emsg: if args.jsched in 'SBATCH SLURM slurm sbatch': slurmjobgen(args,jobdirs) print 'SLURM jobscripts generated!' elif args.jsched in 'SGE Sungrid sge': sgejobgen(args,jobdirs) print 'SGE jobscripts generated!' elif multidx != -1: # if ligand input was a list of smiles strings, write good smiles strings to separate list try: f = open(ligfilename+'-good.smi','a') f.write(args.lig[0]) f.close() except: 0 elif not emsg: if args.gui: qq = mQDialogInf('Folder skipped','Folder '+rootdir+' was skipped.') qq.setParent(args.gui.wmain) else: print 'Folder '+rootdir+' was skipped..\n' return emsg
def rungen(rundir, args, chspfname, globs): try: from Classes.mWidgets import qBoxFolder from Classes.mWidgets import mQDialogInf from Classes.mWidgets import mQDialogErr except ImportError: args.gui = False emsg = False globs.nosmiles = 0 # reset smiles ligands for each run # check for specified ligands/functionalization ligocc = [] # check for files specified for multiple ligands mligs, catoms = [False], [False] if '.smi' in args.lig[0]: ligfilename = args.lig[0].split('.')[0] if args.lig: mligs, catoms, multidx = checkmultilig(args.lig) if args.debug: print('after checking for mulitple ligs, we found ' + str(multidx) + ' ligands') # save initial smicat0 = [ss for ss in args.smicat] if args.smicat else False # loop over ligands for mcount, mlig in enumerate(mligs): args.smicat = [ss for ss in smicat0] if smicat0 else False args.checkdir, skip = False, False # initialize flags if len(mligs) > 0 and mligs[0]: args.lig = mlig # get combination if multidx != -1: if catoms[multidx][mcount]: ssatoms = catoms[multidx][mcount].split(',') lloc = [int(scat) - 1 for scat in ssatoms] # append connection atoms if specified in smiles if args.smicat and len(args.smicat) > 0: for i in range(len(args.smicat), multidx): args.smicat.append([]) else: args.smicat = [lloc] args.smicat[multidx] = lloc if (args.lig): ligands = args.lig if (args.ligocc): ligocc = args.ligocc else: ligocc = ['1'] for i in range(len(ligocc), len(ligands)): ligocc.append('1') lig = '' for i, l in enumerate(ligands): ligentry, emsg = lig_load(l) # update ligand if ligentry: ligands[i] = ligentry.name args.lig[i] = ligentry.name if emsg: skip = True break if ligentry.ident == 'smi': ligentry.ident += str(globs.nosmiles) globs.nosmiles += 1 if args.sminame: if len(args.sminame) > int(ligentry.ident[-1]): ligentry.ident = args.sminame[globs.nosmiles - 1][0:3] lig += ''.join("%s%s" % (ligentry.ident, ligocc[i])) else: ligands = [] lig = '' ligocc = '' ##### fetch smart name fname = name_complex(rundir, args.core, ligands, ligocc, mcount, args, nconf=False, sanity=False, bind=args.bind, bsmi=args.nambsmi) if globs.debug: print('fname is ' + str(fname)) rootdir = fname # check for charges/spin rootcheck = False if (chspfname): rootcheck = rootdir rootdir = rootdir + '/' + chspfname if (args.suff): rootdir += args.suff # check for mannual overwrite of # directory name if args.jobdir: rootdir = rundir + args.jobdir # check for top directory if rootcheck and os.path.isdir( rootcheck) and not args.checkdirt and not skip: args.checkdirt = True if not args.rprompt: flagdir = raw_input( '\nDirectory ' + rootcheck + ' already exists. Keep both (k), replace (r) or skip (s) k/r/s: ' ) if 'k' in flagdir.lower(): flagdir = 'keep' elif 's' in flagdir.lower(): flagdir = 'skip' else: flagdir = 'replace' else: #qqb = qBoxFolder(args.gui.wmain,'Folder exists','Directory '+rootcheck+' already exists. What do you want to do?') #flagdir = qqb.getaction() flagdir = 'replace' # replace existing directory if (flagdir == 'replace'): shutil.rmtree(rootcheck) os.mkdir(rootcheck) # skip existing directory elif flagdir == 'skip': skip = True # keep both (default) else: ifold = 1 while glob.glob(rootdir + '_' + str(ifold)): ifold += 1 rootcheck += '_' + str(ifold) os.mkdir(rootcheck) elif rootcheck and (not os.path.isdir(rootcheck) or not args.checkdirt) and not skip: if globs.debug: print('rootcheck is ' + str(rootcheck)) args.checkdirt = True try: os.mkdir(rootcheck) except: print 'Directory ' + rootcheck + ' can not be created. Exiting..\n' return # check for actual directory if os.path.isdir( rootdir ) and not args.checkdirb and not skip and not args.jobdir: args.checkdirb = True if not args.rprompt: flagdir = raw_input( '\nDirectory ' + rootdir + ' already exists. Keep both (k), replace (r) or skip (s) k/r/s: ' ) if 'k' in flagdir.lower(): flagdir = 'keep' elif 's' in flagdir.lower(): flagdir = 'skip' else: flagdir = 'replace' else: #qqb = qBoxFolder(args.gui.wmain,'Folder exists','Directory '+rootdir+' already exists. What do you want to do?') #flagdir = qqb.getaction() flagdir = 'replace' # replace existing directory if (flagdir == 'replace'): shutil.rmtree(rootdir) os.mkdir(rootdir) # skip existing directory elif flagdir == 'skip': skip = True # keep both (default) else: ifold = 1 while glob.glob(rootdir + '_' + str(ifold)): ifold += 1 rootdir += '_' + str(ifold) os.mkdir(rootdir) elif not os.path.isdir(rootdir) or not args.checkdirb and not skip: if not os.path.isdir(rootdir): args.checkdirb = True os.mkdir(rootdir) #################################### ############ GENERATION ############ #################################### if not skip: # check for generate all if args.genall: tstrfiles = [] # generate xyz with FF and trained ML args.ff = 'mmff94' args.ffoption = 'ba' args.MLbonds = False strfiles, emsg, this_diag = structgen(args, rootdir, ligands, ligocc, globs, mcount) for strf in strfiles: tstrfiles.append(strf + 'FFML') os.rename(strf + '.xyz', strf + 'FFML.xyz') # generate xyz with FF and covalent args.MLbonds = ['c' for i in range(0, len(args.lig))] strfiles, emsg, this_diag = structgen(args, rootdir, ligands, ligocc, globs, mcount) for strf in strfiles: tstrfiles.append(strf + 'FFc') os.rename(strf + '.xyz', strf + 'FFc.xyz') args.ff = False args.ffoption = False args.MLbonds = False # generate xyz without FF and trained ML strfiles, emsg, this_diag = structgen(args, rootdir, ligands, ligocc, globs, mcount) for strf in strfiles: tstrfiles.append(strf + 'ML') os.rename(strf + '.xyz', strf + 'ML.xyz') args.MLbonds = ['c' for i in range(0, len(args.lig))] # generate xyz without FF and covalent ML strfiles, emsg, this_diag = structgen(args, rootdir, ligands, ligocc, globs, mcount) for strf in strfiles: tstrfiles.append(strf + 'c') os.rename(strf + '.xyz', strf + 'c.xyz') strfiles = tstrfiles else: # generate xyz files strfiles, emsg, this_diag = structgen(args, rootdir, ligands, ligocc, globs, mcount) # generate QC input files if args.qccode and not emsg: if args.charge and (isinstance(args.charge, list)): args.charge = args.charge[0] if args.spin and (isinstance(args.spin, list)): args.spin = args.spin[0] if args.qccode.lower( ) in 'terachem tc Terachem TeraChem TERACHEM TC': jobdirs = multitcgen(args, strfiles) print 'TeraChem input files generated!' elif 'gam' in args.qccode.lower(): jobdirs = multigamgen(args, strfiles) print 'GAMESS input files generated!' elif 'qch' in args.qccode.lower(): jobdirs = multiqgen(args, strfiles) print 'QChem input files generated!' else: print 'Only TeraChem, GAMESS and QChem are supported right now.\n' # check molpac if args.mopac and not emsg: print('Generating MOPAC input') if globs.debug: print(strfiles) jobdirs = mlpgen(args, strfiles, rootdir) # generate jobscripts if args.jsched and not emsg: if args.jsched in 'SBATCH SLURM slurm sbatch': slurmjobgen(args, jobdirs) print 'SLURM jobscripts generated!' elif args.jsched in 'SGE Sungrid sge': sgejobgen(args, jobdirs) print 'SGE jobscripts generated!' elif multidx != -1: # if ligand input was a list of smiles strings, write good smiles strings to separate list try: f = open(ligfilename + '-good.smi', 'a') f.write(args.lig[0]) f.close() except: 0 elif not emsg: if args.gui: qq = mQDialogInf('Folder skipped', 'Folder ' + rootdir + ' was skipped.') qq.setParent(args.gui.wmain) else: print 'Folder ' + rootdir + ' was skipped..\n' return emsg
def postproc(rundir, args, globs): globs = globalvars() if args.gui: from Classes.mWidgets import mQDialogErr from Classes.mWidgets import mQDialogInf choice = mQDialogInf( 'Post processing', 'Parsing the results will take a while..Please be patient. Start?') choice.setParent(args.gui.pWindow) # locate output files pdir = args.postdir if args.postdir else globs.rundir cmd = "find '" + pdir + "' -name *out" t = mybash(cmd) resf = t.splitlines() logfile = pdir + "/post.log" if not os.path.isdir(pdir): print '\nSpecified directory ' + pdir + ' does not exist..\n\n' if args.gui: args.gui.iWtxt.setText('\nSpecified directory ' + pdir + ' does not exist.\n\n' + args.gui.iWtxt.toPlainText()) return flog = open(logfile, 'a') flog.write('\n\n\n##### Date: ' + time.strftime('%m/%d/%Y %H:%M') + '#####\n\n') # run summary report if args.pres: print '\nGetting runs summary..\n\n' flog.write('\nGetting runs summary..\n\n') if args.gui: args.gui.iWtxt.setText('\nGetting runs summary..\n\n' + args.gui.iWtxt.toPlainText()) terapost(resf, pdir, args.gui, flog) gampost(resf, pdir, args.gui, flog) # run nbo analysis if args.pnbo: print '\nGetting NBO summary..\n\n' flog.write('\nGetting NBO summary..\n\n') if args.gui: args.gui.iWtxt.setText('\nGetting NBO summary..\n\n' + args.gui.iWtxt.toPlainText()) nbopost(resf, pdir, args.gui, flog) # locate molden files cmd = "find " + "'" + pdir + "'" + " -name *molden" t = mybash(cmd) molf = t.splitlines() # parse molecular orbitals if args.porbinfo: print '\nGetting MO information..\n\n' flog.write('\nGetting MO information..\n\n') if args.gui: args.gui.iWtxt.setText('\nGetting MO information..\n\n' + args.gui.iWtxt.toPlainText()) if not os.path.isdir(pdir + '/MO_files'): os.mkdir(pdir + '/MO_files') moldpost(molf, pdir, args.gui, flog) # calculate delocalization indices if args.pdeloc: print '\nCalculating delocalization indices..\n\n' flog.write('\nCalculating delocalization indices..\n\n') if args.gui: args.gui.iWtxt.setText( '\nCalculating delocalization indices..\n\n' + args.gui.iWtxt.toPlainText()) if not os.path.isdir(pdir + '/Deloc_files'): os.mkdir(pdir + '/Deloc_files') deloc(molf, pdir, args.gui, flog) # calculate charges if args.pcharge: print '\nCalculating charges..\n\n' flog.write('\nCalculating charges..\n\n') if args.gui: args.gui.iWtxt.setText('\nCalculating charges..\n\n' + args.gui.iWtxt.toPlainText()) if not os.path.isdir(pdir + '/Charge_files'): os.mkdir(pdir + '/Charge_files') getcharges(molf, pdir, args.gui, flog) # parse wavefunction if args.pwfninfo: print '\nCalculating wavefunction properties..\n\n' flog.write('\nCalculating wavefunction properties..\n\n') if args.gui: args.gui.iWtxt.setText( '\nCalculating wavefunction properties..\n\n' + args.gui.iWtxt.toPlainText()) if not os.path.isdir(pdir + '/Wfn_files'): os.mkdir(pdir + '/Wfn_files') if not os.path.isdir(pdir + '/Cube_files'): os.mkdir(pdir + '/Cube_files') getcubes(molf, pdir, args.gui, flog) getwfnprops(molf, pdir, args.gui, flog) if not args.pgencubes and os.path.isdir(pdir + '/Cube_files'): shutil.rmtree(pdir + '/Cube_files') # generate cube files if args.pgencubes: print '\nGenerating cube files..\n\n' flog.write('\nGenerating cube files..\n\n') if args.gui: args.gui.iWtxt.setText('\nGenerating cube files..\n\n' + args.gui.iWtxt.toPlainText()) if not os.path.isdir(pdir + '/Cube_files'): os.mkdir(pdir + '/Cube_files') getcubes(molf, pdir, args.gui, flog) flog.close()
def postproc(rundir,args,globs): globs = globalvars() if args.gui: from Classes.mWidgets import mQDialogErr from Classes.mWidgets import mQDialogInf choice = mQDialogInf('Post processing','Parsing the results will take a while..Please be patient. Start?') choice.setParent(args.gui.pWindow) # locate output files pdir = args.postdir if args.postdir else globs.rundir cmd = "find '"+pdir+"' -name *out" t = mybash(cmd) resf = t.splitlines() logfile = pdir+"/post.log" if not os.path.isdir(pdir): print '\nSpecified directory '+pdir+' does not exist..\n\n' if args.gui: args.gui.iWtxt.setText('\nSpecified directory '+pdir+' does not exist.\n\n'+args.gui.iWtxt.toPlainText()) return flog = open(logfile,'a') flog.write('\n\n\n##### Date: '+time.strftime('%m/%d/%Y %H:%M')+'#####\n\n') # run summary report if args.pres: print '\nGetting runs summary..\n\n' flog.write('\nGetting runs summary..\n\n') if args.gui: args.gui.iWtxt.setText('\nGetting runs summary..\n\n'+args.gui.iWtxt.toPlainText()) terapost(resf,pdir,args.gui,flog) gampost(resf,pdir,args.gui,flog) # run nbo analysis if args.pnbo: print '\nGetting NBO summary..\n\n' flog.write('\nGetting NBO summary..\n\n') if args.gui: args.gui.iWtxt.setText('\nGetting NBO summary..\n\n'+args.gui.iWtxt.toPlainText()) nbopost(resf,pdir,args.gui,flog) # locate molden files cmd = "find "+"'"+pdir+"'"+" -name *molden" t = mybash(cmd) molf = t.splitlines() # parse molecular orbitals if args.porbinfo: print '\nGetting MO information..\n\n' flog.write('\nGetting MO information..\n\n') if args.gui: args.gui.iWtxt.setText('\nGetting MO information..\n\n'+args.gui.iWtxt.toPlainText()) if not os.path.isdir(pdir+'/MO_files'): os.mkdir(pdir+'/MO_files') moldpost(molf,pdir,args.gui,flog) # calculate delocalization indices if args.pdeloc: print '\nCalculating delocalization indices..\n\n' flog.write('\nCalculating delocalization indices..\n\n') if args.gui: args.gui.iWtxt.setText('\nCalculating delocalization indices..\n\n'+args.gui.iWtxt.toPlainText()) if not os.path.isdir(pdir+'/Deloc_files'): os.mkdir(pdir+'/Deloc_files') deloc(molf,pdir,args.gui,flog) # calculate charges if args.pcharge: print '\nCalculating charges..\n\n' flog.write('\nCalculating charges..\n\n') if args.gui: args.gui.iWtxt.setText('\nCalculating charges..\n\n'+args.gui.iWtxt.toPlainText()) if not os.path.isdir(pdir+'/Charge_files'): os.mkdir(pdir+'/Charge_files') getcharges(molf,pdir,args.gui,flog) # parse wavefunction if args.pwfninfo: print '\nCalculating wavefunction properties..\n\n' flog.write('\nCalculating wavefunction properties..\n\n') if args.gui: args.gui.iWtxt.setText('\nCalculating wavefunction properties..\n\n'+args.gui.iWtxt.toPlainText()) if not os.path.isdir(pdir+'/Wfn_files'): os.mkdir(pdir+'/Wfn_files') if not os.path.isdir(pdir+'/Cube_files'): os.mkdir(pdir+'/Cube_files') getcubes(molf,pdir,args.gui,flog) getwfnprops(molf,pdir,args.gui,flog) if not args.pgencubes and os.path.isdir(pdir+'/Cube_files'): shutil.rmtree(pdir+'/Cube_files') # generate cube files if args.pgencubes: print '\nGenerating cube files..\n\n' flog.write('\nGenerating cube files..\n\n') if args.gui: args.gui.iWtxt.setText('\nGenerating cube files..\n\n'+args.gui.iWtxt.toPlainText()) if not os.path.isdir(pdir+'/Cube_files'): os.mkdir(pdir+'/Cube_files') getcubes(molf,pdir,args.gui,flog) flog.close()