Beispiel #1
0
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
	)
Beispiel #2
0
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
Beispiel #3
0
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 findGmec(epart):

	print("\n\nFinding GMEC with energy partition: %s\n" % epart)

	# configure conformation energies with the desired energy partition
	confEcalc = osprey.ConfEnergyCalculator(confSpace, ecalc, energyPartition=epart)

	# find the GMEC
	emat = osprey.EnergyMatrix(confEcalc)
	astar = osprey.AStarTraditional(emat, confSpace)
	gmec = osprey.GMECFinder(astar, confEcalc).find()
Beispiel #5
0
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)
Beispiel #6
0
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)

# run PAStE
Beispiel #7
0
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()

# how should we compute energies of molecules?
ecalc = osprey.EnergyCalculator(confSpace, ffparams)

# how should we define energies of conformations?
confEcalc = osprey.ConfEnergyCalculator(confSpace, ecalc)

# compute the energy matrix
emat = osprey.EnergyMatrix(confEcalc)

# run DEE with just steric pruning
pmat = osprey.DEE(confSpace, emat, showProgress=True)

# or run DEE with Goldstein pruning
#i0 = 10.0 # kcal/mol
#pmat = osprey.DEE(confSpace, emat, showProgress=True, singlesGoldsteinDiffThreshold=i0, pairsGoldsteinDiffThreshold=i0)

# find the best sequence and rotamers
astar = osprey.AStarMPLP(emat, pmat)
gmec = osprey.GMECFinder(astar, confEcalc).find()
Beispiel #8
0
def confEcalcFactory(confSpace, ecalc):
    eref = osprey.ReferenceEnergies(confSpace, ecalc)
    return osprey.ConfEnergyCalculator(confSpace,
                                       ecalc,
                                       referenceEnergies=eref)
Beispiel #9
0
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)

    # BBK* needs rigid energies too
    confEcalcRigid = osprey.ConfEnergyCalculatorCopy(info.confEcalcMinimized,
Beispiel #10
0
    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.
    pruningInterval = 20.0  # kcal/mol
    pmat = osprey.DEE(
Beispiel #11
0
# 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
#want to change maxMutable for various designs
maxMutable = 1
numFilteredSeqs = 10000
Beispiel #12
0
# 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()