Beispiel #1
0
    def trip_time (self,traj=None,from_state=None,from_segment=None,to_state=None,to_segment=None,no_return=False,mean=False,norm=False,verbose=False):

        opt_mean=0
        opt_norm=0
        opt_no_return=0
        opt_to_segment=0
        opt_from_segment=0
        opt_to_state=0
        opt_from_state=0

        if (mean):
            opt_mean=1
        if (norm):
            opt_norm=1
        if (no_return):
            opt_no_return=1

        if from_state!=None:   
            opt_from_state=1
        else:
            from_state=0

        if from_segment!=None: 
            opt_from_segment=1
        else:
            from_segment=[0.0,0.0]

        if to_state!=None:     
            opt_to_state=1
        else:
            to_state=0

        if to_segment!=None:   
            opt_to_segment=1
        else:
            to_segment=[0.0,0.0]
        
        if opt_to_segment==0 and opt_to_state==0:
            print '# the input variable to_state or to_segment is needed'
            return

        if traj == None:
            traj_inp=self.traj
            aux_dims=self.dimensions
        elif traj in ['CLUSTERS','Clusters','clusters']:
            traj_inp=self.traj_clusters
            aux_dims=1
        elif traj in ['NODES','Nodes','nodes']:
            traj_inp=self.traj_nodes
            aux_dims=1
        else:
            print '# A readable traj is needed'
            return

        traj_inp=pyn_math.standard_traj(traj_inp,particles=self.particles,dimensions=aux_dims)

        if type(from_state) in [int,float]:
            from_num_states=1
            from_state=[from_state]
        elif type(state) in [list,tuple]:
            from_num_states=len(from_state)

        if type(to_state) in [int,float]:
            to_num_states=1
            to_state=[to_state]
        elif type(to_state) in [list,tuple]:
            to_num_states=len(to_state)

        tt_mean=f_kin_anal.tt_dist(opt_norm,opt_no_return,opt_from_state,opt_from_segment,opt_to_state,opt_to_segment, \
                                                        from_state,from_segment,to_state,to_segment, \
                                                        traj_inp,traj_inp.shape[0],traj_inp.shape[1],traj_inp.shape[2],\
                                                        from_num_states,to_num_states)

        tt_dist=copy.deepcopy(f_kin_anal.distrib)
        tt_x=copy.deepcopy(f_kin_anal.distrib_x)
        f_kin_anal.free_distrib()

        if verbose:
            print '# Mean first passage time:', tt_mean,'frames.'

        if mean:
            return tt_mean
        else:
            return tt_x, tt_dist
Beispiel #2
0
    def committed_trip_time (self,traj=None,states=None,segments=None,commitment=None,no_return=False,mean=False,norm=False,verbose=False):

        opt_mean=0
        opt_norm=0
        opt_segments=0
        opt_states=0
        opt_noreturn=0

        if (mean):
            opt_mean=1
        if (norm):
            opt_norm=1
        if (no_return):
            opt_noreturn=1

        if states!=None:   
            opt_states=1
            segments=[[0,0]]
            num_segments=1
        else:
            opt_segments=0
            states=[0]
            num_states=1

        if opt_segments==0 and opt_states==0:
            print '# the input variable states or segments is needed'
            return

        if traj == None:
            traj_inp=self.traj
            aux_dims=self.dimensions
        elif traj in ['CLUSTERS','Clusters','clusters']:
            traj_inp=self.traj_clusters
            aux_dims=1
        elif traj in ['NODES','Nodes','nodes']:
            traj_inp=self.traj_nodes
            aux_dims=1
        else:
            print '# A readable traj is needed'
            return

        traj_inp=pyn_math.standard_traj(traj_inp,particles=self.particles,dimensions=aux_dims)

        if type(states) in [int,float]:
            num_states=1
            states=[states]
        elif type(states) in [list,tuple]:
            num_states=len(states)

        if opt_segments:
            num_segments=len(segments)

        if commitment==None:
            if opt_segments:
                num_commits=num_segments
            else:
                num_commits=num_states
            commitment=[True for ii in range(num_commits)]
        else:
            num_commits=len(commitment)

        commitment_in=[int(ii) for ii in commitment]
        ctt_mean=f_kin_anal.ctt_dist(opt_norm,opt_noreturn,opt_states,opt_segments, states,segments,commitment_in,\
                                                        traj_inp,traj_inp.shape[0],traj_inp.shape[1],traj_inp.shape[2],\
                                                        num_states,num_segments,num_commits)

        ctt_dist=copy.deepcopy(f_kin_anal.distrib)
        ctt_x=copy.deepcopy(f_kin_anal.distrib_x)
        f_kin_anal.free_distrib()

        if verbose:
            print '# Mean first passage time:', ctt_mean,'frames.'

        if mean:
            return ctt_mean
        else:
            return ctt_x, ctt_dist
Beispiel #3
0
    def life_time(self,traj=None,state=None,segment=None,sel_dim=0,mean=False,norm=False,verbose=False):

        opt_mean =0
        opt_norm =0
        opt_segm =0
        opt_state=0
        num_states=0

        if type(sel_dim) in [int,float]:
            sel_dim=[sel_dim]
            num_sel_dim=1
        elif type(sel_dim) in [list,tuple]:
            num_sel_dim=len(sel_dim)

        if traj == None and not self.__tr_mode_in_file__:
            traj_inp=self.traj
            aux_dims=self.dimensions
        elif traj in ['CLUSTERS','Clusters','clusters']:
            traj_inp=self.traj_clusters
            aux_dims=1
        elif traj in ['NODES','Nodes','nodes']:
            traj_inp=self.traj_nodes
            aux_dims=1
        else:
            print '# A readable traj is needed'
            return

        if (mean):
            opt_mean=1
        if (norm):
            opt_norm=1
        if segment!=None:
            opt_segm=1
            segment=numpy.array(segment)
            if len(segment.shape)==1:
                segment.resize(1,segment.shape[0])
            for ii in range(num_sel_dim):
                segment[sel_dim[ii],0]=segment[ii,0]
                segment[sel_dim[ii],1]=segment[ii,1]
            num_states=1
            state=[0]
        else:
            segment=numpy.zeros((aux_dims,2),dtype=float,order='F')
        if state!=None:
            opt_state=1
            if type(state) in [int,float]:
                num_states=1
                state=[state]
            elif type(state) in [list,tuple]:
                num_states=len(state)
        else:
            num_states=1
            state=[0]


        if not self.__tr_mode_in_file__:
            traj_inp=pyn_math.standard_traj(traj_inp,particles=self.particles,dimensions=aux_dims)
            lt_mean=f_kin_anal.life_time_dist(opt_norm,opt_segm,traj_inp,state,segment,traj_inp.shape[0],traj_inp.shape[1],traj_inp.shape[2],num_states)
        else:
            infile=self.file_traj
            infile.unit=len(pyn_math.pyn_f90units)+1
            pyn_math.pyn_f90units.append(infile.unit)
            lt_mean=f_kin_anal.life_time_dist_infile(infile.name,infile.binary,infile.unit,opt_norm,opt_segm,state,segment,\
                                                     sel_dim,self.particles,self.dimensions,num_states,num_sel_dim)
            pyn_math.pyn_f90units.remove(infile.unit)
            infile.unit=None


        lt_dist=copy.deepcopy(f_kin_anal.distrib)
        lt_x=copy.deepcopy(f_kin_anal.distrib_x)
        f_kin_anal.free_distrib()

        if verbose:
            print '# Mean life time:', lt_mean,'frames.'

        if mean:
            return lt_mean
        else:
            return lt_x, lt_dist