Exemplo n.º 1
0
    def __init__(self,  paramtree=None, measuretree=None,
                 paramfile=PARAMFILE, measurefile=MEASUREFILE,
                 initial_plug='random', reduce_p=True,
                 verbose=False):

        """
        Metaphase instanciation method


        :param duration: The duration of the mitosis in seconds (defaults to 900)
        :type duration: float

        :param paramtree: The paramtree contains the parameters for the simulation
            if paramtree is None, the parameters are read
            from the file paramfile. Defaults to None.
        :type paramtree: ParamTree instance or None

        :param measuretree: The measuretree contains the observed characteristics
            of the mitosis e.g. metaphase spindle elongation rate, etc.
            if measuretree is None, the measures are read from the file
            indicated by the measurefile argument. Defaults to None.
        :type measuretree: ParamTree instance or None

        :param paramfile: Path to a xml file to read the parameters from. Defaults to the
            file params.xml in the module's default directory. Other parameter
            files can be produced by editing and changing the default one.
            If the paramtree argument is not None,  paramfile is ignored
        :type paramfile: string

        :param measurefile: Path to a xml file to read the measures from. Defaults to the
            file measures.xml in the module's default directory.
            Other measure files can be produced by editing and changing
            the default one. If the measuretree argument is not None, measurefile
            is ignored
        :type measurefile: string

        :param initial_plug: Defines globally the initial attachment states.
            This argument can have the following values:
                * 'null': all kinetochores are detached
                * 'amphitelic': all chromosmes are amphitelic
                * 'random': all attachement site can be bound to
                        either pole or deteched with equal prob.
                * 'monotelic': right kinetochores are attached to the same pole,
                           left ones are detached
                * 'syntelic' : all kinetochores are attached to the same pole
        :type initial_plug: string or None

        :param reduce_p: If True, changes the parameters according to the measures
            so that the simulation average behaviour complies with
            the data in the measures dictionary
        :type reduce_p: bool

        """

        # Enable or disable log console
        self.verbose = verbose
        logger = logging.getLogger(__name__)
        if not self.verbose:
            logger.disabled = True
        else:
            logger.disabled = False

        if paramtree is None:
            self.paramtree = ParamTree(paramfile)
        else:
            self.paramtree = paramtree
        if measuretree is None:
            self.measuretree = ParamTree(measurefile, adimentionalized=False)
        else:
            self.measuretree = measuretree

        if reduce_p:
            parameters.reduce_params(self.paramtree, self.measuretree)

        logger.info('Parameters loaded')

        params = self.paramtree.relative_dic
        # Reset explicitely the unit parameters to their
        # dimentionalized value
        params['Vk'] = self.paramtree.absolute_dic['Vk']
        params['Fk'] = self.paramtree.absolute_dic['Fk']
        params['dt'] = self.paramtree.absolute_dic['dt']

        self.KD = KinetoDynamics(params, initial_plug=initial_plug)
        dt = self.paramtree.absolute_dic['dt']
        duration = self.paramtree.absolute_dic['span']
        self.num_steps = int(duration / dt)
        self.KD.anaphase = False
        self.timelapse = np.arange(0, duration, dt)
        self.report = []
        self.delay = -1
        self.observations = {}

        logger.info('Simulation initialized')
        logger.disabled = False
Exemplo n.º 2
0
    def __init__(self, results_path,
                 nsimu,
                 name="",
                 ncore=None,
                 paramtree=None,
                 measuretree=None,
                 paramfile=PARAMFILE,
                 measurefile=MEASUREFILE,
                 verbose=True,
                 name_without_date=False):
        """

        :results_path: The path where simulation results are stored
        :type results_path: string

        :nsimu: Number of simulation to run
        :type nsimu: int

        :ncore: Number of process to launch at the same time
        :type ncore: int

        :param paramtree: The paramtree contains the parameters for the simulation
            if paramtree is None, the parameters are read
            from the file paramfile. Defaults to None.
        :type paramtree: ParamTree instance or None

        :param measuretree: The measuretree contains the observed characteristics
            of the mitosis e.g. metaphase spindle elongation rate, etc.
            if measuretree is None, the measures are read from the file
            indicated by the measurefile argument. Defaults to None.
        :type measuretree: ParamTree instance or None

        :param paramfile: Path to a xml file to read the parameters from. Defaults to the
            file params.xml in the module's default directory. Other parameter
            files can be produced by editing and changing the default one.
            If the paramtree argument is not None,  paramfile is ignored
        :type paramfile: string

        :param measurefile: Path to a xml file to read the measures from. Defaults to the
            file measures.xml in the module's default directory.
            Other measure files can be produced by editing and changing
            the default one. If the measuretree argument is not None, measurefile
            is ignored
        :type measurefile: string


        """

        # Enable or disable log console
        self.verbose = verbose
        logger = logging.getLogger(__name__)
        if not self.verbose:
            logger.disabled = True
        else:
            logger.disabled = False

        if paramtree is None:
            self.paramtree = ParamTree(paramfile)
        else:
            self.paramtree = paramtree
        if measuretree is None:
            self.measuretree = ParamTree(measurefile, adimentionalized=False)
        else:
            self.measuretree = measuretree

        # Reduce parameters
        parameters.reduce_params(self.paramtree, self.measuretree)

        self.results_path = results_path
        self.nsimu = nsimu
        if not ncore:
            self.ncore = multiprocessing.cpu_count()
        else:
            self.ncore = ncore

        self.last_progress = 0

        self.name = name

        # Make result directory
        if not os.path.exists(self.results_path):
            os.makedirs(self.results_path)

        # Results directory according to date and time
        if name_without_date and name:
            dirname = name
        else:
            now = datetime.datetime.now()
            if name:
                dirname = now.strftime("%Y.%m.%d") + "_" + name
            else:
                dirname = now.strftime("%Y.%m.%d")

        self.results_path = os.path.join(self.results_path, dirname)

        # TODO: Ugly fix
        if os.path.isdir(self.results_path):
            self.results_path += "_2"

        # Remove existing directory of it exist
        if os.path.exists(self.results_path):
            shutil.rmtree(self.results_path)
        os.makedirs(self.results_path)

        # Save params.xml and measures.xml in results dir
        self.paramtree.save(os.path.join(self.results_path, "params.xml"))
        self.measuretree.save(os.path.join(self.results_path, "measures.xml"))

        self.raw_results_path = os.path.join(self.results_path, "raw")
        os.makedirs(self.raw_results_path)

        # Redirect log to run.log
        logfile = os.path.join(self.results_path, "run.log")
        handler = logging.FileHandler(logfile)
        logging.getLogger(__name__).addHandler(handler)
Exemplo n.º 3
0
    def __init__(self, results_path,
                 nsimu,
                 name="",
                 ncore=None,
                 paramtree=None,
                 measuretree=None,
                 paramfile=PARAMFILE,
                 measurefile=MEASUREFILE,
                 verbose=True,
                 parameter_to_explore={},
                 pool_eval=False,
                 name_without_date=False):
        """
        """

        if not parameter_to_explore:
            raise Exception("No parameter to explore found !")

        # Enable or disable log console
        self.verbose = verbose
        logger = logging.getLogger(__name__)
        if not self.verbose:
            logger.disabled = True
        else:
            logger.disabled = False

        if paramtree is None:
            self.paramtree = ParamTree(paramfile)
        else:
            self.paramtree = paramtree
        if measuretree is None:
            self.measuretree = ParamTree(measurefile, adimentionalized=False)
        else:
            self.measuretree = measuretree

        # Reduce parameters
        parameters.reduce_params(self.paramtree, self.measuretree)

        self.parameter_to_explore = parameter_to_explore

        self.results_path = results_path
        self.nsimu = nsimu
        self.nparam = len(self.parameter_to_explore['vector'])
        self.total_simu = self.nsimu * self.nparam

        self.last_progress = 0

        self.name = name
        self.ncore = ncore
        self.pool_eval = pool_eval

        # Make result directory
        if not os.path.exists(self.results_path):
            os.makedirs(self.results_path)

        # Results directory according to date and time
        if name_without_date and name:
            dirname = name
        else:
            now = datetime.datetime.now()
            if name:
                dirname = now.strftime("%Y.%m.%d") + "_" + name
            else:
                dirname = now.strftime("%Y.%m.%d")

        self.results_path = os.path.join(self.results_path, dirname)

        # Remove existing directory of it exist
        if os.path.exists(self.results_path):
            shutil.rmtree(self.results_path)
        os.makedirs(self.results_path)

        # Redirect log to run.log
        logfile = os.path.join(self.results_path, "run.log")
        handler = logging.FileHandler(logfile)
        logging.getLogger(__name__).addHandler(handler)