def makeo_emat(confspace, ffparams, parallelism, fo, continuous=False): """Save energy matrix based on OSPREY objects""" ecalc = osprey.EnergyCalculator(confspace, ffparams, parallelism, isMinimizing=continuous) eref = osprey.ReferenceEnergies(confspace, ecalc) conf_ecalc = osprey.ConfEnergyCalculator(confspace, ecalc, referenceEnergies=eref) emat = osprey.EnergyMatrix(conf_ecalc, cacheFile=fo)
def make_pfunc_factory(conf_space, ffparams, numcores, eps, algo_index, emat_cache_pattern, data): """make_pfunc_factory Return a PartitionFunctionFactory object for the input confspace, which we can use to make partition functions for various sequences. """ parallelism = osprey.Parallelism(cpuCores=numcores) data['numCpus'] = numcores # how should we compute energies of molecules? minimizingEcalc = osprey.EnergyCalculator(conf_space, ffparams, parallelism=parallelism, isMinimizing=True) # Compute reference energies eref = osprey.ReferenceEnergies(conf_space, minimizingEcalc) #Create a minimizing energy calculator confEcalcMinimized = osprey.ConfEnergyCalculator(conf_space, minimizingEcalc, referenceEnergies=eref) # we need rigid energies too for many algorithms rigidEcalc = osprey.SharedEnergyCalculator(minimizingEcalc, isMinimizing=False) rigidConfEcalc = osprey.ConfEnergyCalculatorCopy(confEcalcMinimized, rigidEcalc) confEcalcRigid = rigidConfEcalc # Specify the type of partitionFunction if ALGO_LIST[algo_index] == 'SHARK': # using SHARK* impt_ecalc = rigidConfEcalc choose_markstar = False elif ALGO_LIST[algo_index] == 'MARK': # using MARK* impt_ecalc = rigidConfEcalc choose_markstar = True else: # using Gradient descent pfunc impt_ecalc = None choose_markstar = False pfuncFactory = osprey.PartitionFunctionFactory( conf_space, confEcalcMinimized, emat_cache_pattern, confUpperBoundcalc=impt_ecalc, useMARK=choose_markstar) # Set cache pattern pfuncFactory.setCachePattern( '%s/emat.%s.%s' % (XTMP_DIR, emat_cache_pattern, data["design name"])) print('Cache pattern: %s/emat.%s.%s' % (XTMP_DIR, emat_cache_pattern, data["design name"])) return pfuncFactory
def config(state): # how should we define energies of conformations? confEcalc = osprey.ConfEnergyCalculator( state.confSpace, ecalc, referenceEnergies = osprey.ReferenceEnergies(state.confSpace, ecalc), # use the "AllOnPairs" setting to get tighter energy bounds # tighter energy bounds make SOFEA run much faster! energyPartition = osprey.EnergyPartition.AllOnPairs ) # train forcefield approximations to make energy calculations go much faster amat = osprey.ApproximatorMatrix( confEcalc, # save the approximator matrix to disk so we don't have to calculate it again later cacheFile = 'sofea.%s.amat' % state.name, ) # update the conformation energy calculator with the forcefield approximations confEcalc = osprey.ConfEnergyCalculator( state.confSpace, ecalc, # copy settings from the previous confEcalc referenceEnergies = confEcalc.eref, energyPartition = confEcalc.epart, # give the new confEcalc the approximator matrix amat = amat, # how much error can we tolerate per conformation? approximationErrorBudget = 0.1 # kcal/mol ) # make the SOFEA config return osprey.SOFEA_StateConfig( # calculate the energy matrix emat = osprey.EnergyMatrix( confEcalc, # save the emat to disk so we don't have to calculate it again later cacheFile = 'sofea.%s.emat' % state.name, # correct overly optimistic energy bounds with triples to get even tighter energy bounds! tripleCorrectionThreshold = 0.0 ), confEcalc = confEcalc )
def configure_bbk(instance, minimizingEcalc, type_string, id_obj, algo_index): """Configure the energy calculators and info for BBK* instance""" for info in instance.confSpaceInfos(): # Compute reference energies eref = osprey.ReferenceEnergies(info.confSpace, minimizingEcalc) #Create a minimizing energy calculator info.confEcalcMinimized = osprey.ConfEnergyCalculator( info.confSpace, minimizingEcalc, referenceEnergies=eref) # BBK* needs rigid energies too rigidEcalc = osprey.SharedEnergyCalculator(minimizingEcalc, isMinimizing=False) rigidConfEcalc = osprey.ConfEnergyCalculatorCopy( info.confEcalcMinimized, rigidEcalc) info.confEcalcRigid = rigidConfEcalc # Specify the input for the partition functions. Providing the confUpperBoundcalc turns on SHARK* if ALGO_LIST[algo_index] == 'SHARK': impt_ecalc = rigidConfEcalc choose_markstar = False elif ALGO_LIST[algo_index] == 'MARK': impt_ecalc = rigidConfEcalc choose_markstar = True else: impt_ecalc = None choose_markstar = False info.pfuncFactory = osprey.PartitionFunctionFactory( info.confSpace, info.confEcalcMinimized, info.id, confUpperBoundcalc=impt_ecalc, useMARK=choose_markstar) # Set cache pattern info.pfuncFactory.setCachePattern('%s/emat.%s.%s' % (XTMP_DIR, info.id, id_obj)) print('Cache pattern: %s/emat.%s.%s' % (XTMP_DIR, info.id, id_obj)) # compute the energy matrices info.ematMinimized = info.pfuncFactory.getOrMakeEmat( info.confEcalcMinimized, 'minimized') info.ematRigid = info.pfuncFactory.getOrMakeEmat( info.confEcalcRigid, 'rigid') # Updating energy matrix? #info.ematCorrected =\ #osprey.c.ematrix.UpdatingEnergyMatrix( #info.confSpace, #info.ematMinimized, #info.confEcalcMinimized #) # how should confs be ordered and searched? (don't forget to capture emat by using a defaulted argument) def makeAStar_min(rcs, emat=info.ematMinimized): return osprey.AStarTraditional(emat, rcs, showProgress=True) info.confSearchFactoryMinimized =\ osprey.KStar.ConfSearchFactory(makeAStar_min) def makeRigidAStar(rcs, emat=info.ematRigid): return osprey.AStarTraditional(emat, rcs, showProgress=True) info.confSearchFactoryRigid =\ osprey.KStar.ConfSearchFactory(makeRigidAStar)
# configure PAStE paste = osprey.Paste( complexConfSpace, numPDBs=15, epsilon= 0.68, # you proabably want something more precise in your real designs useWindowCriterion=True, writeSequencesToConsole=True, writeSequencesToFile='paste.results.tsv', mutFile='mut.txt') # configure PAStE inputs for the conf space # how should we define energies of conformations? eref = osprey.ReferenceEnergies(paste.protein.confSpace, ecalc) paste.protein.confEcalc = osprey.ConfEnergyCalculator(paste.protein.confSpace, ecalc, referenceEnergies=eref) # compute the energy matrix emat = osprey.EnergyMatrix(paste.protein.confEcalc, cacheFile='emat.%s.dat' % paste.protein.id) # how should confs be ordered and searched? (don't forget to capture emat by using a defaulted argument) def makeAStar(rcs, emat=emat): return osprey.AStarTraditional(emat, rcs, showProgress=False) paste.protein.confSearchFactory = osprey.Paste.ConfSearchFactory(makeAStar)
def confEcalcFactory(confSpace, ecalc): eref = osprey.ReferenceEnergies(confSpace, ecalc) return osprey.ConfEnergyCalculator(confSpace, ecalc, referenceEnergies=eref)
# configure BBK* bbkstar = osprey.BBKStar( proteinConfSpace, ligandConfSpace, complexConfSpace, numBestSequences=2, epsilon= 0.99, # you proabably want something more precise in your real designs writeSequencesToConsole=True, writeSequencesToFile='bbkstar.results.tsv') # configure BBK* inputs for each conf space for info in bbkstar.confSpaceInfos(): # how should we define energies of conformations? eref = osprey.ReferenceEnergies(info.confSpace, minimizingEcalc) info.confEcalcMinimized = osprey.ConfEnergyCalculator( info.confSpace, minimizingEcalc, referenceEnergies=eref) # compute the energy matrix ematMinimized = osprey.EnergyMatrix(info.confEcalcMinimized, cacheFile='emat.%s.dat' % info.id) # how should confs be ordered and searched? # (since we're in a loop, need capture variables above by using defaulted arguments) def makeAStarMinimized(rcs, emat=ematMinimized): return osprey.AStarTraditional(emat, rcs, showProgress=False) info.confSearchFactoryMinimized = osprey.BBKStar.ConfSearchFactory( makeAStarMinimized)
confSpace = osprey.MultiStateConfSpace([ osprey.StateMutable('design', osprey.ConfSpace(design)), osprey.StateUnmutable('ligand', osprey.ConfSpace(ligand)), osprey.StateMutable('complex', osprey.ConfSpace([design, ligand])) ]) # train a LUTE model for each state for state in confSpace.states: # how should we compute energies of molecules? ecalc = osprey.EnergyCalculator(state.confSpace, ffparams, parallelism=parallelism) # how should we define energies of conformations? eref = osprey.ReferenceEnergies(state.confSpace, ecalc) confEcalc = osprey.ConfEnergyCalculator(state.confSpace, ecalc, referenceEnergies=eref) # calculate the energy matrix so we can do DEE emat = osprey.EnergyMatrix( confEcalc, # save it to disk so we don't have to calculate it again later cacheFile='sofea.%s.emat' % state.name) # Good LUTE fits rely heavily on DEE pruning, so use the best available DEE options here. # With interval pruning, we prune only conformations whose energies are more than X higher # than the lower bound of the conformation with the minimum lower bound. # If we sort the whole conformation space by lower bounds, interval pruning is like keeping # only conformations in the bottom X kcal/mol slice of the sorted list.
# configure K* kstar = osprey.KStar( proteinConfSpace, ligandConfSpace, complexConfSpace, epsilon= 0.95, # you proabably want something more precise in your real designs writeSequencesToConsole=True, writeSequencesToFile='kstar.results.tsv') # configure K* inputs for each conf space for info in kstar.confSpaceInfos(): # how should we define energies of conformations? eref = osprey.ReferenceEnergies(info.confSpace, ecalc) info.confEcalc = osprey.ConfEnergyCalculator(info.confSpace, ecalc, referenceEnergies=eref) # compute the minimized energy matrix ematMinimized = osprey.EnergyMatrix(info.confEcalc, cacheFile='emat.%s.dat' % info.id) # if you want to use MARK*, pass in a rigid energy calculator and energy matrix as well confEcalcRigid = osprey.ConfEnergyCalculatorCopy(info.confEcalc, ecalcRigid) ematRigid = osprey.EnergyMatrix(confEcalcRigid, cacheFile='emat.%s.rigid.dat' % info.id) # how should we score each sequence?
# make the conf space for the protein+ligand complex confSpace = osprey.ConfSpace([protein, ligand]) # how should we compute energies of molecules? # (give the complex conf space to the ecalc since it knows about all the templates and degrees of freedom) numCPUs = 40 parallelism = osprey.Parallelism(cpuCores=numCPUs) ecalc = osprey.EnergyCalculator(confSpace, ffparams, parallelism=parallelism) rigidEcalc = osprey.EnergyCalculator(confSpace, ffparams, parallelism=parallelism, isMinimizing=False) # how should we define energies of conformations? eref = osprey.ReferenceEnergies(confSpace, ecalc) erefRigid = osprey.ReferenceEnergies(confSpace, rigidEcalc) confECalc = osprey.ConfEnergyCalculator(confSpace, ecalc, referenceEnergies=eref) confRigidECalc = osprey.ConfEnergyCalculator(confSpace, rigidEcalc, referenceEnergies=eref) # variables for EWAKStar epsilon = 0.68 numTopSeqs = 5 maxPFConfs = 500 seqFilterOnly = False wtBenchmark = False useMaxMutable = True
# define a strand strand = osprey.Strand('1CC8.ss.pdb') strand.flexibility['A2'].setLibraryRotamers('ALA', 'GLY') strand.flexibility['A3'].setLibraryRotamers(osprey.WILD_TYPE, 'VAL') strand.flexibility['A4'].setLibraryRotamers(osprey.WILD_TYPE) # make the conf space confSpace = osprey.ConfSpace(strand) # choose a forcefield ffparams = osprey.ForcefieldParams() # compute the reference energies (with res entropy) ecalc = osprey.EnergyCalculator(confSpace, ffparams) eref = osprey.ReferenceEnergies(confSpace, ecalc, addResEntropy=True) # define conf energy, with res entropy confEcalc = osprey.ConfEnergyCalculator(confSpace, ecalc, referenceEnergies=eref, addResEntropy=True) # use the reference energies for energy matrix computation emat = osprey.EnergyMatrix(confEcalc) # Optional: using edge MPLP when using reference energies can make A* faster astar = osprey.AStarMPLP(emat, confSpace, updater=osprey.EdgeUpdater()) # find the best sequence and rotamers gmec = osprey.GMECFinder(astar, confEcalc).find()