def calcClusterNumber(self, min_clst=5, max_clst=30, rmsLimit=1.0, weight=1.13, converged=1e-11, aMask=None, force=0): """ Calculate the approximate number of clusters needed to pass the average intra-cluster rmsd limit. @param min_clst: lower limit for clusters (default: 5) @type min_clst: int @param max_clst: upper limit for clusters (default: 30 ) @type max_clst: int @param rmsLimit: rmsd criteria that the average of all clusters must meet in Angstrom (default: 1.0) @type rmsLimit: float @param weight: fuzziness weigth (default: 1.13) @type weight: float @param converged: stop iteration if min dist changes less than converged (default: 1e-11) @type converged: float @param force: re-calculate even if parameters haven't changed (default: 0) @type force: 1|0 @return: number of clusters @rtype: int @raise ClusterError: if can't determining number of clusters """ pos = [min_clst, max_clst] while 1: clst = int(N0.average(pos)) self.cluster(clst, weight, converged, aMask, force=force) rmsLst = [self.avgRmsd(i, aMask)[0] for i in range(clst)] if N0.average(rmsLst) > rmsLimit: pos[0] = clst else: pos[1] = clst if pos[1] - pos[0] == 1: if self.verbose: T.flushPrint( 'Converged at %i clusters, current average cluster rmsd %.2f\n' % (clst, N0.average(rmsLst))) return pos[1] if pos[1] - pos[0] != 1: if self.verbose: T.flushPrint( 'Current cluster setting %i, current average cluster rmsd %.2f\n' % (clst, N0.average(rmsLst))) if pos[1] - pos[0] <= 0 or pos[0] < min_clst or pos[1] > max_clst: raise ClusterError("Error determining number of clusters")
def calcClusterNumber( self, min_clst=5, max_clst=30, rmsLimit=1.0, weight=1.13, converged=1e-11, aMask=None, force=0 ): """ Calculate the approximate number of clusters needed to pass the average intra-cluster rmsd limit. @param min_clst: lower limit for clusters (default: 5) @type min_clst: int @param max_clst: upper limit for clusters (default: 30 ) @type max_clst: int @param rmsLimit: rmsd criteria that the average of all clusters must meet in Angstrom (default: 1.0) @type rmsLimit: float @param weight: fuzziness weigth (default: 1.13) @type weight: float @param converged: stop iteration if min dist changes less than converged (default: 1e-11) @type converged: float @param force: re-calculate even if parameters haven't changed (default: 0) @type force: 1|0 @return: number of clusters @rtype: int @raise ClusterError: if can't determining number of clusters """ pos = [ min_clst, max_clst ] while 1: clst = int( N0.average(pos) ) self.cluster( clst, weight, converged, aMask, force=force ) rmsLst = [ self.avgRmsd(i, aMask)[0] for i in range(clst)] if N0.average( rmsLst ) > rmsLimit: pos[0] = clst else: pos[1] = clst if pos[1]-pos[0] == 1: if self.verbose: T.flushPrint('Converged at %i clusters, current average cluster rmsd %.2f\n'%( clst, N0.average( rmsLst ) )) return pos[1] if pos[1]-pos[0] != 1: if self.verbose: T.flushPrint('Current cluster setting %i, current average cluster rmsd %.2f\n'%( clst, N0.average( rmsLst ) )) if pos[1]-pos[0]<= 0 or pos[0]<min_clst or pos[1]>max_clst: raise ClusterError("Error determining number of clusters")
def blockFit2ref( self, refModel=None, mask=None, conv=1e-6 ): """ Fit trajectory until convergence onto it's own average and then transform the average of all frames onto the reference. To be used with parallell trajectories. :param refModel: Reference model (default: None) :type refModel: PDBModel :param mask: atom mask to apply before fitting (default: None, all atoms) :type mask: [1|0] :param conv: convergence cutoff creterion (default: 1e-6) :type conv: float """ self.fit( ref=self.ref ) m_avg = self.avgModel() ## fit on average until it's not getting better d = 1. dd= 1. while dd >= conv: self.fit( ref=m_avg, mask=mask ) m_new_avg = self.avgModel() oldD, d = d, m_avg.rms( m_new_avg, mask=mask ) T.flushPrint( "rms difference: %f" % d ) dd = oldD - d m_avg = m_new_avg ## transform trajectory en block onto reference if refModel: T.flushPrint('fitting trajectory en-block onto reference...') if refModel.atomNames() != self.ref.atomNames(): ref_i, i = refModel.compareAtoms( m_avg ) refModel = refModel.take( ref_i ) m_avg = m_avg.take( i ) r, t = m_avg.transformation( refModel, mask ) self.transform( r, t )
out = T.absfile(o['o']) inLst = T.toList(o['i']) start = int(o.get('s', '0')) end = o.get('e', None) if end: end = int(end) step = int(o.get('step', 1)) prot = 'prot' in o ref = o.get('ref', None) if ref: ref = PDBModel(T.absfile(ref)) if 'prot' in o: ref = ref.compress(ref.maskProtein()) T.flushPrint("Loading and appending trajectories...") r = loadTraj(inLst[0], 0, start, end, step, prot=prot) for i in range(1, len(inLst)): t = loadTraj(inLst[i], i, start, end, step) if t.ref.equals(r.ref) != [1, 1]: raise Exception('Incompatible reference structure.') r = r.concat(t) T.flushPrint('#') print(" Done")
pdb - PDB code to be stored in trajectory """) sys.exit(0) ########## ## MAIN ## use() o = T.cmdDict( {'n':10} ) f_in = T.absfile( o['i'] ) f_out = T.absfile( o.get('o', f_in) ) n = int( o['n'] ) T.flushPrint("Loading...") t = T.load( f_in ) T.flushPrint("Converting %i frames..." % len(t) ) if isinstance(t, EnsembleTraj ): T.flushPrint( "Nothing to be done!\n") sys.exit(0) t = traj2ensemble( t, n ) if 'pdb' in o: t.ref.pdbCode = o['pdb'] if f_in == f_out: os.rename( f_in, f_in + '_backup')
######## ## MAIN ######## syntax() ## get and clean up options o = options() o['step'] = int( o['step'] ) o['i'] = T.absfile( o['i'] ) o['o'] = o.get('o', '%s/%s_rms.eps' % (osp.dirname(o['i']), T.stripFilename(o['i']))) o['show'] = 'show' in o T.flushPrint( "Loading..." ) t = T.load( o['i'] ) T.flushPrint( "done loading trajectory with %i frames." % len(t) ) if o['step'] != 1: t = t.thin( o['step'] ) T.flushPrint( "Fitting ...") calcRmsd( t ) T.flushPrint( "done." ) p = plot( t, o.get( 'title', T.stripFilename(o['i']) ) ) if o['show']: p.show()
######## ## MAIN ######## syntax() ## get and clean up options o = options() o['z'] = float(o['z']) o['step'] = int(o['step']) o['i'] = T.absfile(o['i']) o['o'] = o.get( 'o', '%s/%s_rms.eps' % (osp.dirname(o['i']), T.stripFilename(o['i']))) o['show'] = 'show' in o T.flushPrint("Loading...") t0 = T.load(o['i']) T.flushPrint("done loading %i member trajectory." % t0.n_members) t = t0 if o['step'] != 1: t = t0.thin(o['step']) T.flushPrint("Fitting %i members..." % t.n_members) calcRmsd(t) T.flushPrint("done.") p = plot(t, o.get('title', T.stripFilename(o['i']))) if o['z'] > 0.0: T.flushPrint("Getting outliers ...")