Exemplo n.º 1
0
def kinetic_network(traj=None,ranges=None,bins=None,traj_out=False,labels=True,verbose=True):

    prov_net=network(directed=True,kinetic=True,verbose=False)

    ranges=pyn_math.standard_ranges(ranges)
    dimensions=ranges.shape[0]
    traj=pyn_math.standard_traj(traj,dimensions)
    num_frames=traj.shape[0]
    num_parts=traj.shape[1]

    opt_labels=0
    if labels:
        opt_labels=1

    if bins!=None:
        if type(bins) in [int]:
            bins=[bins]
        if len(bins)!=dimensions:
            print '# The length of bins must be equal to the length of ranges'
            return
        bins=numpy.array(bins,dtype=int,order='F')
        traj_net=f_kin_anal.trajbinning2net(opt_labels,traj,ranges,bins,num_frames,num_parts,dimensions)
    else:
        traj_net=f_kin_anal.traj2net(opt_labels,traj,ranges,num_frames,num_parts,dimensions)

    traj_net=pyn_math.standard_traj(traj_net,particles=num_parts,dimensions=1)

    prov_net.Ts=True
    prov_net.T_ind=copy.deepcopy(f_kin_anal.t_ind)
    prov_net.T_wl=copy.deepcopy(f_kin_anal.t_tau)
    prov_net.T_start=copy.deepcopy(f_kin_anal.t_start)
    prov_net.build_from_Ts()
    if opt_labels:
        if bins==None:
            for ii in range(prov_net.num_nodes):
                label=str(f_kin_anal.labels[ii])
                prov_net.node[ii].label=label
                prov_net.labels[label]=ii
        else:
            for ii in range(prov_net.num_nodes):
                label=str(f_kin_anal.labels_daux[ii])
                prov_net.node[ii].label=label
                prov_net.labels[label]=ii


    f_kin_anal.free_memory_ts()
    if verbose:
        prov_net.info(update=False,verbose=True)
        pass
    else:
        pass

    if traj_out:
        return prov_net,traj_net
    else:
        del(traj_net)
        return prov_net
Exemplo n.º 2
0
    def kinetic_network(self, traj=None, ranges=None, bins=None, labels=True, verbose=False):

        if traj in ["CLUSTERS", "Clusters", "clusters"]:
            if type(self.traj_clusters) not in [numpy.ndarray]:
                self.traj_clusters = numpy.array(self.traj_clusters, order="Fortran")

            self.network_clusters = kinetic_network(
                self.traj_clusters, ranges=[self.traj_clusters.min(), self.traj_clusters.max()], verbose=verbose
            )
            return

        elif traj in ["NODES", "Nodes", "nodes"]:
            if type(self.traj_nodes) not in [numpy.ndarray]:
                self.traj_nodes = numpy.array(self.traj_nodes, order="Fortran")
            self.network = kinetic_network(
                self.traj_nodes, ranges=[self.traj_nodes.min(), self.traj_nodes.max()], verbose=verbose
            )
            return

        else:
            self.traj = pyn_math.standard_traj(self.traj, particles=self.particles, dimensions=self.dimensions)
            if ranges == None:
                ranges = pyn_math.build_ranges(self.traj)
            else:
                ranges = pyn_math.standard_ranges(ranges)
            self.network, self.traj_nodes = kinetic_network(
                self.traj, ranges=ranges, bins=bins, traj_out=True, labels=labels, verbose=verbose
            )
            return
Exemplo n.º 3
0
    def flux_cut(self, traj=None, cut=None, verbose=False):

        if cut == None:
            print "# Cut value needed."
            return

        if self.dimensions > 1:
            print "# Not implemented yet"
            return

        if traj == None:

            traj_inp = pyn_math.standard_traj(self.traj, particles=self.particles, dimensions=self.dimensions)
            return f_kin_anal.flux_cut(traj_inp, cut, traj_inp.shape[0], traj_inp.shape[1], traj_inp.shape[2])
Exemplo n.º 4
0
    def life_time(self,traj=None,state=None,segment=None,mean=False,norm=False,verbose=False):

        opt_mean=0
        opt_norm=0
        if (mean):
            opt_mean=1
        if (norm):
            opt_norm=1

        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(state) in [int,float]:
            num_states=1
            state=[state]
        elif type(state) in [list,tuple]:
            num_states=len(state)

        lt_mean=f_trajs.life_time_dist(opt_norm,traj_inp,state,traj_inp.shape[0],traj_inp.shape[1],traj_inp.shape[2],num_states)

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

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

        if mean:
            return lt_mean
        else:
            return lt_x, lt_dist
Exemplo n.º 5
0
    def kinetic_network(self,traj=None,ranges=None,verbose=False):

        if traj in ['CLUSTERS','Clusters','clusters']:
            if type(self.traj_clusters) not in [numpy.ndarray]:
                self.traj_clusters=numpy.array(self.traj_clusters,order="Fortran")

            self.network_clusters=kinetic_network(self.traj_clusters,ranges=[self.traj_clusters.min(),self.traj_clusters.max()],verbose=verbose)
            return

        elif traj in ['NODES','Nodes','nodes']:
            if type(self.traj_nodes) not in [numpy.ndarray]:
                self.traj_nodes=numpy.array(self.traj_nodes,order="Fortran")
            self.network_nodes=kinetic_network(self.traj_nodes,ranges=[self.traj_nodes.min(),self.traj_nodes.max()],verbose=verbose)
            return

        else:
            self.traj=pyn_math.standard_traj(self.traj,particles=self.particles,dimensions=self.dimensions)
            if ranges==None:
                ranges=pyn_math.build_ranges(self.traj)
            else:
                ranges=pyn_math.standard_ranges(ranges)
            self.network_nodes,self.traj_nodes=kinetic_network(self.traj,ranges=ranges,traj_out=True,verbose=verbose)                
            return
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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
        if mean:
            opt_mean = 1
        if norm:
            opt_norm = 1
        if segment:
            opt_segm = 1

        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)

        segments = numpy.zeros((self.dimensions, 2), dtype=float, order="F")
        if opt_segm:
            segment = numpy.array(segment)
            if len(segment.shape) == 1:
                segment.resize(1, segment.shape[0])
            for ii in range(num_sel_dim):
                segments[sel_dim[ii], 0] = segment[ii, 0]
                segments[sel_dim[ii], 1] = segment[ii, 1]
            num_states = 1
            state = [0]
        else:
            if type(state) in [int, float]:
                num_states = 1
                state = [state]
            elif type(state) in [list, tuple]:
                num_states = len(state)

        if traj == None:
            if self.__tr_mode_in_file__:
                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,
                    segments,
                    sel_dim,
                    self.particles,
                    self.dimensions,
                    num_states,
                    num_sel_dim,
                )
                pyn_math.pyn_f90units.remove(infile.unit)
                infile.unit = None

            else:
                traj_inp = pyn_math.standard_traj(self.traj, particles=self.particles, dimensions=self.dimensions)
                lt_mean = f_kin_anal.life_time_dist(
                    opt_norm,
                    opt_segm,
                    traj_inp,
                    state,
                    segments,
                    traj_inp.shape[0],
                    traj_inp.shape[1],
                    traj_inp.shape[2],
                    num_states,
                )

        elif traj in ["CLUSTERS", "Clusters", "clusters"]:
            traj_inp = pyn_math.standard_traj(self.traj_clusters, particles=self.particles, dimensions=1)
            lt_mean = f_kin_anal.life_time_dist(
                opt_norm, traj_inp, state, traj_inp.shape[0], traj_inp.shape[1], traj_inp.shape[2], num_states
            )
        elif traj in ["NODES", "Nodes", "nodes"]:
            traj_inp = pyn_math.standard_traj(self.traj_nodes, particles=self.particles, dimensions=1)
            lt_mean = f_kin_anal.life_time_dist(
                opt_norm, traj_inp, state, traj_inp.shape[0], traj_inp.shape[1], traj_inp.shape[2], num_states
            )
        else:
            print "# A readable traj is needed"
            return

        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
Exemplo n.º 9
0
    def __init__(
        self,
        traject=None,
        columns=None,
        frames=None,
        particles=None,
        dimensions=None,
        traject_type="Traj",
        in_ram=True,
        in_file=False,
        by_frame=False,
        verbose=True,
    ):

        self.dimensions = dimensions
        self.particles = particles
        self.frames = frames

        self.file_traj = None
        self.file_nodes = None
        self.file_clusters = None

        self.traj = None
        self.traj_nodes = None
        self.traj_clusters = None

        self.network = None
        self.network_clusters = None

        self.__tr_mode_in_ram__ = False
        self.__tr_mode_in_file__ = False
        self.__tr_mode_by_frame__ = False

        self.__no_mode_in_ram__ = False
        self.__no_mode_in_file__ = False
        self.__no_mode_by_frame__ = False

        self.__cl_mode_in_ram__ = False
        self.__cl_mode_in_file__ = False
        self.__cl_mode_by_frame__ = False

        self.__type_nodes__ = None
        self.__type_clusters__ = None
        self.__offset__ = 0

        if in_file:
            in_ram = False

        if traject_type in ["TRAJ", "Traj", "traj"]:
            self.__tr_mode_in_ram__ = in_ram
            self.__tr_mode_in_file__ = in_file
            self.__tr_mode_by_frame__ = by_frame
        elif traject_type in ["NODES", "Nodes", "nodes"]:
            self.__no_mode_in_ram__ = in_ram
            self.__no_mode_in_file__ = in_file
            self.__no_mode_by_frame__ = by_frame
        elif traject_type in ["CLUSTERS", "Clusters", "clusters"]:
            self.__cl_mode_in_ram__ = in_ram
            self.__cl_mode_in_file__ = in_file
            self.__cl_mode_by_frame__ = by_frame

        if traject == None:
            if self.frames != None:
                if self.dimensions == None:
                    self.dimensions = 1
                if self.particles == None:
                    self.particles = 1

                if traject_type in ["TRAJ", "Traj", "traj"]:
                    self.traj = numpy.zeros((self.frames, self.particles, self.dimensions), dtype=float, order="F")
                elif traject_type in ["NODES", "Nodes", "nodes"]:
                    self.traj_nodes = numpy.zeros(
                        (self.frames, self.particles, self.dimensions), dtype=float, order="F"
                    )
                elif traject_type in ["CLUSTERS", "Clusters", "clusters"]:
                    self.traj_clusters = numpy.zeros(
                        (self.frames, self.particles, self.dimensions), dtype=float, order="F"
                    )

        if type(traject) in [str]:

            if type(columns) in [int]:
                self.particles = 1
                self.dimensions = 1
                columns = [columns]
            elif type(columns) in [tuple, list]:
                if (len(columns)) == 1:
                    self.particles = 1
                    self.dimensions = 1
                else:
                    if particles == None and dimensions == None:
                        print '# Please, make use of the variables "particles" or/and "dimensions":'
                        print '#   traj:=[100 frames, 3 dimensions] --> "particles=1" or/and "dimensions=3"'
                        print '#   traj:=[100 frames, 8  particles] --> "particles=8" or/and "dimensions=1"'
                        return
                    elif particles == 1 or dimensions >= 1:
                        self.particles = 1
                        self.dimensions = len(columns)
                    elif particles > 1 or dimensions == 1:
                        self.dimensions = 1
                        self.particles = len(columns)
            elif columns in ["ALL", "All", "all"]:
                fff = open(traject, "r")
                line = fff.readline().split()
                nn = len(line)
                fff.close()
                columns = [ii for ii in range(nn)]
                if nn > 1:
                    if particles == None and dimensions == None:
                        print '# Please, make use of the variables "particles" or/and "dimensions":'
                        print '#   traj:=[100 frames, 3 dimensions] --> "particles=1" or/and "dimensions=3"'
                        print '#   traj:=[100 frames, 8  particles] --> "particles=8" or/and "dimensions=1"'
                        return
                    elif particles == 1 or dimensions >= 1:
                        self.particles = 1
                        self.dimensions = nn
                    elif particles > 1 or dimensions == 1:
                        self.dimensions = 1
                        self.particles = nn
                else:
                    self.dimensions = 1
                    self.particles = 1

            if self.__tr_mode_in_ram__ and not self.__tr_mode_by_frame__:

                if traject.endswith(".bin"):
                    self.file_traj = pyn_file(
                        name=traject, frames=frames, particles=particles, dimensions=dimensions, opt="r"
                    )
                    self.file_traj.open()
                    self.traj = self.file_traj.extract()

                else:

                    self.file_traj = pyn_file(name=traject, opt="r")
                    self.frames = 0

                    self.file_traj.open()
                    for line in self.file_traj.file:
                        self.frames += 1
                    self.file_traj.close()

                    self.traj = numpy.empty((self.frames, self.particles, self.dimensions), dtype=float, order="F")

                    self.file_traj.open()

                    gg = -1
                    for line in self.file_traj.file:
                        line = line.split()
                        gg += 1
                        for kk in range(len(columns)):
                            self.traj[gg, 0, kk] = float(line[columns[kk]])

                self.file_traj.close()

                self.traj = pyn_math.standard_traj(self.traj, self.particles, self.dimensions)

            if self.__tr_mode_in_file__:

                self.file_traj = pyn_file(name=traject, frames=frames, particles=particles, dimensions=dimensions)

                if self.dimensions == None or self.particles == None:
                    print '# Error: Input variables "dimensions" and "particles" needed.'
                    return

        if type(traject) in [list, tuple, numpy.ndarray]:

            self.traj = pyn_math.standard_traj(traject, particles=self.particles, dimensions=self.dimensions)

            self.frames = self.traj.shape[0]
            self.particles = self.traj.shape[1]
            self.dimensions = self.traj.shape[2]

        if verbose:
            self.info()
Exemplo n.º 10
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_trajs.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_trajs.distrib)
        tt_x=copy.deepcopy(f_trajs.distrib_x)
        f_trajs.free_distrib()

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

        if mean:
            return tt_mean
        else:
            return tt_x, tt_dist
Exemplo n.º 11
0
    def first_committed_passage_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]
        fcpt_mean=f_trajs.fcpt_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)

        fcpt_dist=copy.deepcopy(f_trajs.distrib)
        fcpt_x=copy.deepcopy(f_trajs.distrib_x)
        f_trajs.free_distrib()

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

        if mean:
            return fcpt_mean
        else:
            return fcpt_x, fcpt_dist
Exemplo n.º 12
0
    def __init__ (self,traject=None,columns=None,particles=None,dimensions=None,verbose=True):

        self.file_traj=''
        self.file_nodes=''
        self.file_clusters=''
        self.file_traj_columns=None
        self.traj=None
        self.dimensions=dimensions
        self.particles=particles
        self.frames=0
        self.traj_nodes=None
        self.traj_clusters=None
        self.network_nodes=None
        self.network_clusters=None
        self.__mode_in_ram__=True
        self.__mode_in_file__=False
        self.__mode_by_frame__=False
        self.__type_nodes__=None
        self.__type_clusters__=None
        self.__offset__=0

        if traject==None:
            print 'Trajectory needed (name of file or array)'
            return
        
        if type(columns) in [int]:
            self.particles=1
            self.dimensions=1
            columns=[columns]
        elif type(columns) in [tuple,list]:
            if (len(columns))==1:
                self.particles=1
                self.dimensions=1
            else:
                if particles==None and dimensions==None:
                    print '# Please, make use of the variables "particles" or/and "dimensions":'
                    print '#   traj:=[100 frames, 3 dimensions] --> "particles=1" or/and "dimensions=3"'
                    print '#   traj:=[100 frames, 8  particles] --> "particles=8" or/and "dimensions=1"'
                    return
                elif particles==1 or dimensions>=1:
                    self.particles=1
                    self.dimensions=len(columns)
                elif particles>1 or dimensions==1:
                    self.dimensions=1
                    self.particles=len(columns)

        elif columns in ['ALL','All','all']:
            fff=open(traject,'r')
            line=fff.readline().split()
            nn=len(line)
            fff.close()
            columns=[ii for ii in range(nn)]
            if nn>1:
                if particles==None and dimensions==None:
                    print '# Please, make use of the variables "particles" or/and "dimensions":'
                    print '#   traj:=[100 frames, 3 dimensions] --> "particles=1" or/and "dimensions=3"'
                    print '#   traj:=[100 frames, 8  particles] --> "particles=8" or/and "dimensions=1"'
                    return
                elif particles==1 or dimensions>=1:
                    self.particles=1
                    self.dimensions=nn
                elif particles>1 or dimensions==1:
                    self.dimensions=1
                    self.particles=nn
            else:
                self.dimensions=1
                self.particles=1

        if type(traject) in [str]:

            self.file_traj=traject
            self.file_column=columns

            self.frames = 0
            for line in open(traject): self.frames += 1

            self.traj=numpy.empty((self.frames,self.particles,self.dimensions),dtype=float,order='F')

            fff=open(traject,'r')

            gg=-1
            for line in fff:
                line=line.split()
                gg+=1
                for kk in range(len(columns)):
                    self.traj[gg,0,kk]=float(line[columns[kk]])
 
            fff.close()

            self.traj=pyn_math.standard_traj(self.traj,self.particles,self.dimensions)

        if type(traject) in [list,tuple,numpy.ndarray]:
            
            self.traj=pyn_math.standard_traj(traject,particles=self.particles,dimensions=self.dimensions)

        self.frames=self.traj.shape[0]
        self.particles=self.traj.shape[1]
        self.dimensions=self.traj.shape[2]

        if verbose:
            print '# Loaded:'
            self.info()