Ejemplo n.º 1
0
 def mdstep(self,t,step,gamma=0.1,silent=False):
     t0 = time.time()
     xyzr = self.chain.get_particles()
     o    = IMP.atom.MolecularDynamics(self.model)
     o.set_scoring_function(self.scoringFunction)
     md   = IMP.atom.VelocityScalingOptimizerState(self.model,xyzr,t)
     #md   = IMP.atom.LangevinThermostatOptimizerState(self.model,xyzr,t,gamma)
     o.add_optimizer_state(md)
     
     if self._record_step > 0:
         self.cache_coordinates()
         self.record.append(np.copy(self.xyz))  
         while step > self._record_step:
             s = o.optimize(self._record_step)
             self.cache_coordinates()
             self.record.append(np.copy(self.xyz))
             step -= self._record_step
         s = o.optimize(step)
     else:
         s = o.optimize(step)
         
     o.remove_optimizer_state(md)
     if not silent:
         self.logger.info('MD %d steps done @ %.1fs score = %f'%(step,utils.timespend(t0),s))
         print 'MD %d steps done @ %.1fs score = %f'%(step,utils.timespend(t0),s)
     return s
Ejemplo n.º 2
0
 def SimulatedAnnealing_Scored(self,
                               hot,
                               cold,
                               nc=10,
                               nstep=500,
                               lowscore=10):
     """perform a cycle of simulated annealing but stop if reach low score"""
     t0 = time.time()
     dt = (hot - cold) / nc
     for i in range(nc):
         t = hot - dt * i
         self.mdstep(t, nstep, silent=True)
         score = self.cgstep(100, silent=True)
         self.logger.info(u"      Temp=%s Step=%s Time=%.1fs Score=%.8f" %
                          (t, nstep, alabutils.timespend(t0), score))
         print "      Temp=%s Step=%s Time=%.1fs Score=%.8f" % (
             t, nstep, alabutils.timespend(t0), score)
         if score < lowscore:
             return t, score
             break
     self.mdstep(cold, 300, silent=True)
     score = self.cgstep(100, silent=True)
     self.logger.info(u"      Temp=%s Step=%s Time=%.1fs Score=%.8f" %
                      (cold, nstep, alabutils.timespend(t0), score))
     print "      Temp=%s Step=%s Time=%.1fs Score=%.8f" % (
         cold, nstep, alabutils.timespend(t0), score)
     return t, score
Ejemplo n.º 3
0
    def mdstep_withChromosomeTerritory(self, t, step):
        """
        perform an mdstep with chromosome terriory restraint
        
        Parameters
        -----------
        t : int
            temperature
        step : int
            optimization steps
        """
        t0 = time.time()
        chrContainers = []
        for chrom in self.genome.info['chrom']:
            chromContainer1 = IMP.container.ListSingletonContainer(
                self.model, 'Container %s s1' % chrom)
            chromContainer2 = IMP.container.ListSingletonContainer(
                self.model, 'Container %s s2' % chrom)
            for j in np.flatnonzero(self.probmat.idx['chrom'] == chrom):
                p = self.chain.get_particle(j)
                chromContainer1.add(p)
                p = self.chain.get_particle(j + self.nbead)
                chromContainer2.add(p)
            chrContainers.append(chromContainer1)
            chrContainers.append(chromContainer2)
        # set each chromosome to different containers
        for st in range(step / 10):
            ctRestraintSet = IMP.RestraintSet(self.model)
            for i in range(len(self.genome.info['chrom'])):
                comxyz = centerOfMass(chrContainers[2 * i])
                comc = IMP.algebra.Vector3D(comxyz[0], comxyz[1], comxyz[2])
                ub = IMP.core.HarmonicUpperBound(self.chromRadius[i], 0.2)
                ss = IMP.core.DistanceToSingletonScore(ub, comc)
                ct_rs = IMP.container.SingletonsRestraint(
                    ss, chrContainers[2 * i])

                ctRestraintSet.add_restraint(ct_rs)
                #another one
                comxyz = centerOfMass(chrContainers[2 * i + 1])
                comc = IMP.algebra.Vector3D(comxyz[0], comxyz[1], comxyz[2])
                ub = IMP.core.HarmonicUpperBound(self.chromRadius[i], 0.2)
                ss = IMP.core.DistanceToSingletonScore(ub, comc)
                ct_rs = IMP.container.SingletonsRestraint(
                    ss, chrContainers[2 * i + 1])

                ctRestraintSet.add_restraint(ct_rs)
            self.updateScoringFunction([self.restraints, ctRestraintSet])
            s = self.mdstep(t, 10, silent=True)
        #---
        #s = mdstep(model,chain,sf,t,1000)
        self.updateScoringFunction()
        self.logger.info(u'CT-MD %d steps done @ %.1fs score = %f' %
                         (step, alabutils.timespend(t0), s))
        print 'CT-MD %d steps done @ %.1fs score = %f' % (
            step, alabutils.timespend(t0), s)
        return s
Ejemplo n.º 4
0
 def SimulatedAnnealing(self,hot,cold,nc=10,nstep=500):
     """
         perform a cycle of simulated annealing from hot to cold
     """
     t0 = time.time()
     dt = (hot-cold)/nc
     for i in range(nc):
         t = hot-dt*i
         s = self.mdstep(t,nstep,silent=True)
         self.logger.info("      Temp=%d Step=%d Time=%.1fs Score = %.8f"%(t,nstep,utils.timespend(t0),s))
         print "      Temp=%d Step=%d Time=%.1fs Score = %.8f"%(t,nstep,utils.timespend(t0),s)
     s= self.mdstep(cold,nstep,silent=True)
     self.logger.info("      Temp=%d Step=%d Time=%.1fs Score = %.8f"%(cold,nstep,utils.timespend(t0),s))
     print "      Temp=%d Step=%d Time=%.1fs Score = %.8f"%(cold,nstep,utils.timespend(t0),s)
     self.cgstep(100,silent=True)
Ejemplo n.º 5
0
 def mdstep_withChromosomeTerritory(self,t,step):
     """
         perform an mdstep with chromosome terriory restraint
         parameters:
         -----------
         t:         temperature
         step:      optimization steps
     """
     t0 = time.time()
     chrContainers=[]
     for chrom in self.genome.info['chrom']:
         chromContainer1=IMP.container.ListSingletonContainer(self.model,'Container %s s1'%chrom)
         chromContainer2=IMP.container.ListSingletonContainer(self.model,'Container %s s2'%chrom)
         for j in np.flatnonzero(self.probmat.idx['chrom'] == chrom):
             p=self.chain.get_particle(j)
             chromContainer1.add(p)
             p=self.chain.get_particle(j+self.nbead)
             chromContainer2.add(p)
         chrContainers.append(chromContainer1)
         chrContainers.append(chromContainer2)
     # set each chromosome to different containers
     for st in range(step/10):
         ctRestraintSet = IMP.RestraintSet(self.model)
         for i in range(len(self.genome.info['chrom'])):
             comxyz = centerOfMass(chrContainers[2*i])
             comc   = IMP.algebra.Vector3D(comxyz[0],comxyz[1],comxyz[2])
             ub     = IMP.core.HarmonicUpperBound(self.chromRadius[i],0.2)
             ss     = IMP.core.DistanceToSingletonScore(ub,comc)
             ct_rs  = IMP.container.SingletonsRestraint(ss,chrContainers[2*i])
             
             ctRestraintSet.add_restraint(ct_rs)
             #another one
             comxyz = centerOfMass(chrContainers[2*i+1])
             comc   = IMP.algebra.Vector3D(comxyz[0],comxyz[1],comxyz[2])
             ub     = IMP.core.HarmonicUpperBound(self.chromRadius[i],0.2)
             ss     = IMP.core.DistanceToSingletonScore(ub,comc)
             ct_rs  = IMP.container.SingletonsRestraint(ss,chrContainers[2*i+1])
             
             ctRestraintSet.add_restraint(ct_rs)
         self.updateScoringFunction([self.restraints,ctRestraintSet])
         s = self.mdstep(t,10,silent=True)
     #---
     #s = mdstep(model,chain,sf,t,1000)
     self.updateScoringFunction()
     self.logger.info('CT-MD %d steps done @ %.1fs score = %f'%(step,utils.timespend(t0),s))
     print 'CT-MD %d steps done @ %.1fs score = %f'%(step,utils.timespend(t0),s)
     return s
Ejemplo n.º 6
0
 def mdstep(self, t, step, gamma=0.1, silent=False):
     t0 = time.time()
     #self.cache_coordinates()
     xyzr = self.chain.get_particles()
     o = IMP.atom.MolecularDynamics(self.model)
     o.set_scoring_function(self.scoringFunction)
     md = IMP.atom.VelocityScalingOptimizerState(self.model, xyzr, t)
     #md   = IMP.atom.LangevinThermostatOptimizerState(self.model,xyzr,t,gamma)
     o.add_optimizer_state(md)
     s = o.optimize(step)
     o.remove_optimizer_state(md)
     if not silent:
         self.logger.info(u'MD %d steps done @ %.1fs score = %f' %
                          (step, alabutils.timespend(t0), s))
         print 'MD %d steps done @ %.1fs score = %f' % (
             step, alabutils.timespend(t0), s)
     return s
Ejemplo n.º 7
0
 def SimulatedAnnealing_Scored(self,hot,cold,nc=10,nstep=500,lowscore=10):
     """perform a cycle of simulated annealing but stop if reach low score"""
     t0 = time.time()
     dt = (hot-cold)/nc
     for i in range(nc):
         t = hot-dt*i
         self.mdstep(t,nstep,silent=True)
         score = self.cgstep(100,silent=True)
         self.logger.info("      Temp=%s Step=%s Time=%.1fs Score=%.8f"%(t,nstep,utils.timespend(t0),score))
         print "      Temp=%s Step=%s Time=%.1fs Score=%.8f"%(t,nstep,utils.timespend(t0),score)
         if score < lowscore:
             return t,score
             break
     self.mdstep(cold,300,silent=True)
     score = self.cgstep(100,silent=True)
     self.logger.info("      Temp=%s Step=%s Time=%.1fs Score=%.8f"%(cold,nstep,utils.timespend(t0),score))
     print "      Temp=%s Step=%s Time=%.1fs Score=%.8f"%(cold,nstep,utils.timespend(t0),score)
     return t,score
Ejemplo n.º 8
0
 def SimulatedAnnealing(self, hot, cold, nc=10, nstep=500):
     """
         perform a cycle of simulated annealing from hot to cold
     """
     t0 = time.time()
     dt = (hot - cold) / nc
     for i in range(nc):
         t = hot - dt * i
         s = self.mdstep(t, nstep, silent=True)
         self.logger.info(u"      Temp=%d Step=%d Time=%.1fs Score = %.8f" %
                          (t, nstep, alabutils.timespend(t0), s))
         print "      Temp=%d Step=%d Time=%.1fs Score = %.8f" % (
             t, nstep, alabutils.timespend(t0), s)
     s = self.mdstep(cold, nstep, silent=True)
     self.logger.info(u"      Temp=%d Step=%d Time=%.1fs Score = %.8f" %
                      (cold, nstep, alabutils.timespend(t0), s))
     print "      Temp=%d Step=%d Time=%.1fs Score = %.8f" % (
         cold, nstep, alabutils.timespend(t0), s)
     self.cgstep(100, silent=True)
Ejemplo n.º 9
0
 def cgstep(self,step,silent=False):
     """
         perform conjugate gradient on model using scoring function sf
     """
     t0 = time.time()
     
     o = IMP.core.ConjugateGradients(self.model)
     o.set_check_level(IMP.USAGE)
     o.set_scoring_function(self.scoringFunction)
     # For conjugate gradient we just record one snap shot
     if self._record_step > 0:
         self.cache_coordinates()
         self.record.append(np.copy(self.xyz))                
     # start optimizing    
     try:
         s = o.optimize(step)
     except:
         s = o.optimize(step)
     if not silent:
         self.logger.info('CG %d steps done @ %.1fs score = %f'%(step,utils.timespend(t0),s))
         print 'CG %d steps done @ %.1fs score = %f'%(step,utils.timespend(t0),s)
     return s
Ejemplo n.º 10
0
 def cgstep(self,step,silent=False):
     """
         perform conjugate gradient on model using scoring function sf
     """
     t0 = time.time()
     self.cache_coordinates()
     o = IMP.core.ConjugateGradients(self.model)
     o.set_check_level(IMP.USAGE)
     o.set_scoring_function(self.scoringFunction)
     try:
         s = o.optimize(step)
     except:
         #tt = str(np.random.random_integers(1000))+'.txt'
         #np.savetxt(tt,self.xyz,fmt='%.4f')
         #print tt
         #self.cache_coordinates()
         #np.savetxt(tt+'.af',self.xyz,fmt='%.4f')
         s = o.optimize(step)
     if not silent:
         self.logger.info(u'CG %d steps done @ %.1fs score = %f'%(step,alabutils.timespend(t0),s))
         print 'CG %d steps done @ %.1fs score = %f'%(step,alabutils.timespend(t0),s)
     return s
Ejemplo n.º 11
0
 def cgstep(self, step, silent=False):
     """
         perform conjugate gradient on model using scoring function sf
     """
     t0 = time.time()
     self.cache_coordinates()
     o = IMP.core.ConjugateGradients(self.model)
     o.set_check_level(IMP.USAGE)
     o.set_scoring_function(self.scoringFunction)
     try:
         s = o.optimize(step)
     except:
         #tt = str(np.random.random_integers(1000))+'.txt'
         #np.savetxt(tt,self.xyz,fmt='%.4f')
         #print tt
         #self.cache_coordinates()
         #np.savetxt(tt+'.af',self.xyz,fmt='%.4f')
         s = o.optimize(step)
     if not silent:
         self.logger.info(u'CG %d steps done @ %.1fs score = %f' %
                          (step, alabutils.timespend(t0), s))
         print 'CG %d steps done @ %.1fs score = %f' % (
             step, alabutils.timespend(t0), s)
     return s