def get_charge_and_multiplicity(unknw_res_names, verbose=False): results = {} for residue_name in unknw_res_names: print(residue_name) if residue_name in results: continue mol = builder.run(chemical_component=residue_name, no_output=True, silent=True ) mol.WritePDB('4antechamber_%s.pdb' %residue_name) mol.Multiplicitise() print(mol.DisplayBrief()) results[residue_name] = [mol.charge, mol.multiplicity] return results
def calculate_amber_files( code, pH=8, ): import tempfile cwd = os.getcwd() td = tempfile.mkdtemp() os.chdir(td) mol = builder.run( chemical_component=code, final_geometry=code, no_output=True, quiet=True, pH=pH, ) mol.OptimiseHydrogens() mol.WritePDB('4antechamber_%s.pdb' % code) mol.Multiplicitise() print mol.DisplayVeryBrief() try: os.remove('sqm.pdb') except OSError: pass cmd='antechamber -i 4antechamber_%s.pdb -fi pdb -o tmp.mol2 -fo mol2 \ -nc %d -m %d -s 2 -pf y -c bcc -at gaff' \ %(code, mol.charge, mol.multiplicity) print cmd ero = easy_run.fully_buffered(cmd) f = open('antelog_%s.txt' % code, 'wb') ero.show_stdout(out=f) ero.show_stderr(out=f) f.write('\nSECOND RUN OF %s\N' % code) cmd='antechamber -i sqm.pdb -fi pdb -o %s.mol2 -fo mol2 \ -nc %s -m %d -s 2 -pf y -c bcc -at gaff' \ %(code, mol.charge, mol.multiplicity) print cmd ero = easy_run.fully_buffered(cmd) ero.show_stdout(out=f) ero.show_stderr(out=f) cmd = 'parmchk2 -i %s.mol2 -f mol2 -o %s.frcmod' % (code, code) ero = easy_run.fully_buffered(cmd) ero.show_stdout(out=f) ero.show_stderr(out=f) f.close() print '\nMoving files from', os.getcwd() cmd = "mv %s %s " % ("antelog_%s.txt" % (code), os.path.join(cwd, "..", "output", "antelog_%s.txt" % (code))) print cmd easy_run.call(cmd) cmd = "mv %s %s " % ("sqm.out", os.path.join(cwd, "..", "output", "sqm_%s.out" % (code))) print cmd easy_run.call(cmd) cmd = "mv %s %s " % ("4antechamber_%s.pdb" % (code), os.path.join(cwd, "%s.final.pdb" % (code))) print cmd easy_run.call(cmd) for ext in ["frcmod", "mol2"]: if not os.path.exists("%s.%s" % (code, ext)): return None cmd = "mv %s %s" % ("%s.%s" % (code, ext), os.path.join(cwd, "%s.%s" % (code, ext))) print cmd easy_run.call(cmd) os.chdir(cwd) import shutil print "Deleting temporary directory : %s" % td shutil.rmtree(td) return True
def get_elbow_molecule_cif_filename(code, kwds={}, return_molecule=False): def _get_qm_package_kwds(kwds, qm_package): if qm_package is not None: if qm_package.lower() == "gamess": kwds["gamess"] = True elif qm_package.lower() == "gaussian": kwds["gaussian"] = True #else: # assert 0 del kwds["qm_package"] return kwds code = code.upper() filename = "%s" % code default_kwds = { "qm_package": None, "qm_method": None, "qm_basis": None, "qm_solvent_model": None, "opt_nprocs": 1, "opt": False, "mogul": False, "geostd": False, "qsub": "", "automatic": False, "qm_check": False, "dry_run": False, "quiet": True, #"validate" : True, "pH": "neutral", #"xml" : True, "write_redundant_dihedrals_boolean": False, # special case!!! #"initial_geometry" : code, #"smiles" : get_smiles(code), #"file" : sdf_filename, #"no_output" : True, #"output": "ANP_neutral", "overwrite": True, } kwds["chemical_component"] = code for dk in default_kwds: if dk not in kwds: kwds[dk] = default_kwds[dk] count = 0 for kwd in [ "opt", #"qm_method", "mogul", "automatic", ]: if kwds[kwd]: count += 1 assert count <= 1 if 0: for key in sorted(kwds): print " %-20s : %s" % (key, kwds[key]) kwds = _get_qm_package_kwds(kwds, kwds["qm_package"]) if "smiles" in kwds and not kwds["smiles"]: return None if not kwds["overwrite"] and os.path.exists("%s.cif" % filename): print "CIF found", os.path.abspath("%s.cif" % filename) if return_molecule: assert 0 return filename if not kwds["overwrite"] and os.path.exists("%s.pickle" % filename): print "pickle found", os.path.abspath("%s.pickle" % filename) if return_molecule: assert 0 f = file(os.path.abspath("%s.pickle" % filename), "rb") mol = pickle.load(f) del f mol.WriteCIF(filename) return filename else: display_kwds(kwds) if qm_job_not_run(kwds): print '\n\n\tNo previous job\n\n' # WHY WAS THIS INDENTED # if kwds["qm_method"]: # if qm_job_not_run(kwds): # print '\n\n\tNo previous job\n\n' # mol = builder.run(**kwds) # elif qm_job_run_and_failed(kwds): # print last_qm_lines(kwds, 100) # print '\n\n\tPrevious job is failed\n\n' # mol = builder.run(**kwds) # elif not qm_job_run_and_finished(kwds): # print '\n\n\tJob is still running\n\n' # mol = None # elif qm_job_run_and_finished(kwds): # print '\n\n\tJob is finished running\n\n' # assert 0 # else: # print 'else' # mol = None # else: mol = builder.run(**kwds) elif qm_job_run_and_finished(kwds): print '\n\n\tJob is still running\n\n' mol = None elif qm_job_run_and_failed(kwds): print last_qm_lines(kwds, 100) print '\n\n\tPrevious job is failed\n\n' mol = builder.run(**kwds) else: print 'else' mol = None if mol: if not os.path.exists(os.path.dirname(filename)): try: os.mkdir(os.path.dirname(filename)) except: pass mol.WriteCIF(filename) if return_molecule: return mol else: return filename
def calculate_amber_files(code, pH=8, use_temp_file=True, ): import tempfile cwd = os.getcwd() if use_temp_file: td = tempfile.mkdtemp() os.chdir(td) mol = builder.run(chemical_component=code, final_geometry=code, no_output=True, quiet=True, pH=pH, ) # a very dull problem if hasattr(mol, "restraint_class"): del mol.restraint_class mol.OptimiseHydrogens() mol.WritePDB('4antechamber_%s.pdb' % code, pymol_pdb_bond_order=False) mol.WriteTriposMol2('4antechamber_%s.mol2' % code) mol.Multiplicitise() try: os.remove('sqm.pdb') except OSError: pass cmd='antechamber -i 4antechamber_%s.mol2 -fi mol2 -o %s.mol2 -fo mol2 \ -nc %d -s 2 -pf y -c bcc -at gaff2 \ -ek "qm_theory=\'AM1\', scfconv=1.d-10, ndiis_attempts=700,maxcyc=0"' \ %(code, code, mol.charge) print cmd ero=easy_run.fully_buffered(cmd) f=open('antelog_%s.txt' % code,'wb') ero.show_stdout(out=f) ero.show_stderr(out=f) cmd='parmchk2 -i %s.mol2 -f mol2 -o %s.frcmod -s 2' %(code,code) print cmd ero=easy_run.fully_buffered(cmd) ero.show_stdout(out=f) ero.show_stderr(out=f) f.close() print '\nMoving files from',os.getcwd() cmd = "mv %s %s " % ("antelog_%s.txt" % (code), os.path.join(cwd,"..","output", "antelog_%s.txt" % (code)) ) print cmd easy_run.call(cmd) cmd = "mv %s %s " % ("sqm.out", os.path.join(cwd,"..","output", "sqm_%s.out" % (code)) ) print cmd easy_run.call(cmd) # copy the geometry used to create the inputs cmd = "mv %s %s " % ("4antechamber_%s.pdb" % (code), os.path.join(cwd, "%s.final.pdb" % (code)) ) print cmd easy_run.call(cmd) for ext in ["frcmod", "mol2"]: if not os.path.exists("%s.%s" % (code, ext)): return None cmd = "mv %s %s" % ("%s.%s" % (code, ext), os.path.join(cwd, "%s.%s" % (code,ext)) ) print cmd easy_run.call(cmd) os.chdir(cwd) import shutil if use_temp_file: print "Deleting temporary directory : %s" % td shutil.rmtree(td) return True
def get_elbow_molecule_cif_filename(code, kwds={}, return_molecule=False): def _get_qm_package_kwds(kwds, qm_package): if qm_package is not None: if qm_package.lower()=="gamess": kwds["gamess"]=True elif qm_package.lower()=="gaussian": kwds["gaussian"]=True #else: # assert 0 del kwds["qm_package"] return kwds if code in skip_codes: print 'code %s in skip list' % code return None code=code.upper() filename = "%s" % code default_kwds = { "qm_package" : None, "qm_method" : None, "qm_basis" : None, "qm_solvent_model" : None, "opt_nprocs" : 1, "opt" : False, "mogul" : False, "geostd" : False, "qsub" : "", "automatic" : False, "qm_check" : False, "dry_run" : False, "quiet" : True, #"validate" : True, "pH" : "neutral", #"xml" : True, "write_redundant_dihedrals_boolean" : False, # special case!!! #"initial_geometry" : code, #"smiles" : get_smiles(code), #"file" : sdf_filename, #"no_output" : True, #"output": "ANP_neutral", "overwrite" : True, } kwds["chemical_component"] = code for dk in default_kwds: if dk not in kwds: kwds[dk]=default_kwds[dk] count = 0 for kwd in [ "opt", #"qm_method", "mogul", "automatic", ]: if kwds[kwd]: count+=1 assert count<=1 if 0: for key in sorted(kwds): print " %-20s : %s" % (key, kwds[key]) kwds = _get_qm_package_kwds(kwds, kwds["qm_package"]) if "smiles" in kwds and not kwds["smiles"]: return None if not kwds["overwrite"] and os.path.exists("%s.cif" % filename): print "CIF found",os.path.abspath("%s.cif" % filename) if return_molecule: assert 0 return filename if not kwds["overwrite"] and os.path.exists("%s.pickle" % filename): print "pickle found",os.path.abspath("%s.pickle" % filename) if return_molecule: assert 0 f=file(os.path.abspath("%s.pickle" % filename), "rb") mol = pickle.load(f) del f mol.WriteCIF(filename) return filename else: display_kwds(kwds) if qm_job_not_run(kwds): print '\n\n\tNo previous job\n\n' # WHY WAS THIS INDENTED # if kwds["qm_method"]: # if qm_job_not_run(kwds): # print '\n\n\tNo previous job\n\n' # mol = builder.run(**kwds) # elif qm_job_run_and_failed(kwds): # print last_qm_lines(kwds, 100) # print '\n\n\tPrevious job is failed\n\n' # mol = builder.run(**kwds) # elif not qm_job_run_and_finished(kwds): # print '\n\n\tJob is still running\n\n' # mol = None # elif qm_job_run_and_finished(kwds): # print '\n\n\tJob is finished running\n\n' # assert 0 # else: # print 'else' # mol = None # else: mol = builder.run(**kwds) elif not qm_job_run_and_finished(kwds): print '\n\n\tJob is still running\n\n' mol = None elif qm_job_run_and_failed(kwds): print last_qm_lines(kwds, 100) print '\n\n\tPrevious job is failed\n\n' mol = builder.run(**kwds) else: print 'else' mol = None if mol: if not os.path.exists(os.path.dirname(filename)): try: os.mkdir(os.path.dirname(filename)) except: pass mol.WriteCIF(filename) if return_molecule: return mol else: return filename