Assign the membrane properties across the cell.
350051
def defineBiophysics(self):
        """"""
        # Insert active Hodgkin-Huxley current in the soma
        self.soma.insert('hh')
        self.soma.gnabar_hh = 0.12  # Sodium conductance in S/cm2
        self.soma.gkbar_hh = 0.036  # Potassium conductance in S/cm2
        self.soma.gl_hh = 0.003    # Leak conductance in S/cm2
        self.soma.el_hh = -70       # Reversal potential in mV
        
        self.dend.insert('pas')
        self.dend.g_pas = 0.001  # Passive conductance in S/cm2
        self.dend.e_pas = -65    # Leak reversal potential mV
        self.dend.nseg = 1000
353068
private void assumeTableDefaults(Cell aCell) {
        
        if (aCell.getBorder() == Rectangle.UNDEFINED) {
            aCell.setBorder(defaultCell.getBorder());
        }
        if (aCell.getBorderWidth() == Rectangle.UNDEFINED) {
            aCell.setBorderWidth(defaultCell.getBorderWidth());
        }
        if (aCell.getBorderColor() == null) {
            aCell.setBorderColor(defaultCell.getBorderColor());
        }
        if (aCell.getBackgroundColor() == null) {
            aCell.setBackgroundColor(defaultCell.getBackgroundColor());
        }
        if (aCell.getHorizontalAlignment() == Element.ALIGN_UNDEFINED) {
            aCell.setHorizontalAlignment(defaultCell.getHorizontalAlignment());
        }
        if (aCell.getVerticalAlignment() == Element.ALIGN_UNDEFINED) {
            aCell.setVerticalAlignment(defaultCell.getVerticalAlignment());
        }
    }
861124
private void reconcileWith(int i, Cell cell)
    {
        cells[i] = cell.reconcile(cells[i]);
    }
953655
def _sensoryComputeLearningMode(self, anchorInput):
    
    overlaps = self.connections.computeActivity(anchorInput,
                                                self.connectedPermanence)
    activeSegments = np.where(overlaps >= self.activationThreshold)[0]

    potentialOverlaps = self.connections.computeActivity(anchorInput)
    matchingSegments = np.where(potentialOverlaps >=
                                self.learningThreshold)[0]

    # Cells with a active segment: reinforce the segment
    cellsForActiveSegments = self.connections.mapSegmentsToCells(
      activeSegments)
    learningActiveSegments = activeSegments[
      np.in1d(cellsForActiveSegments, self.activeCells)]
    remainingCells = np.setdiff1d(self.activeCells, cellsForActiveSegments)

    # Remaining cells with a matching segment: reinforce the best
    # matching segment.
    candidateSegments = self.connections.filterSegmentsByCell(
      matchingSegments, remainingCells)
    cellsForCandidateSegments = (
      self.connections.mapSegmentsToCells(candidateSegments))
    candidateSegments = candidateSegments[
      np.in1d(cellsForCandidateSegments, remainingCells)]
    onePerCellFilter = np2.argmaxMulti(potentialOverlaps[candidateSegments],
                                       cellsForCandidateSegments)
    learningMatchingSegments = candidateSegments[onePerCellFilter]

    newSegmentCells = np.setdiff1d(remainingCells, cellsForCandidateSegments)

    for learningSegments in (learningActiveSegments,
                             learningMatchingSegments):
      self._learn(self.connections, self.rng, learningSegments,
                  anchorInput, potentialOverlaps,
                  self.initialPermanence, self.sampleSize,
                  self.permanenceIncrement, self.permanenceDecrement,
                  self.maxSynapsesPerSegment)

    # Remaining cells without a matching segment: grow one.
    numNewSynapses = len(anchorInput)

    if self.sampleSize != -1:
      numNewSynapses = min(numNewSynapses, self.sampleSize)

    if self.maxSynapsesPerSegment != -1:
      numNewSynapses = min(numNewSynapses, self.maxSynapsesPerSegment)

    newSegments = self.connections.createSegments(newSegmentCells)

    self.connections.growSynapsesToSample(
      newSegments, anchorInput, numNewSynapses,
      self.initialPermanence, self.rng)
    self.activeSegments = activeSegments
    self.sensoryAssociatedCells = self.activeCells
1202845
def bind(cell1, cell2, moduleDimensions):
  
  cell1Coords = np.unravel_index(cell1, moduleDimensions)
  cell2Coords = np.unravel_index(cell2, moduleDimensions)
  transformCoords = [(c2 - c1) % m
                     for c1, c2, m in itertools.izip(cell1Coords, cell2Coords,
                                                     moduleDimensions)]
  return np.ravel_multi_index(transformCoords, moduleDimensions)
150843
def create_metabolic_model(self):
        """"""

        def _translate_compartments(reaction, compartment):
            """Translate compound with missing compartments.

            These compounds will have the specified compartment in the output.
            """
            left = (((c.in_compartment(compartment), v)
                     if c.compartment is None else (c, v))
                    for c, v in reaction.left)
            right = (((c.in_compartment(compartment), v)
                      if c.compartment is None else (c, v))
                     for c, v in reaction.right)
            return Reaction(reaction.direction, left, right)

        # Create metabolic model
        database = DictDatabase()
        for reaction in self.reactions:
            if reaction.equation is not None:
                equation = _translate_compartments(
                    reaction.equation, self.default_compartment)
                database.set_reaction(reaction.id, equation)

        undefined_compartments = set()
        undefined_compounds = set()
        extracellular_compounds = set()
        extracellular = self.extracellular_compartment
        for reaction in database.reactions:
            for compound, _ in database.get_reaction_values(reaction):
                if compound.name not in self.compounds:
                    undefined_compounds.add(compound.name)
                if compound.compartment == extracellular:
                    extracellular_compounds.add(compound.name)
                if compound.compartment not in self.compartments:
                    undefined_compartments.add(compound.compartment)

        for compartment in sorted(undefined_compartments):
            logger.warning(
                'The compartment {} was not defined in the list'
                ' of compartments'.format(compartment))

        for compound in sorted(undefined_compounds):
            logger.warning(
                'The compound {} was not defined in the list'
                ' of compounds'.format(compound))

        exchange_compounds = set()
        for exchange_compound in self.exchange:
            if exchange_compound.compartment == extracellular:
                exchange_compounds.add(exchange_compound.name)

        for compound in sorted(extracellular_compounds - exchange_compounds):
            logger.warning(
                'The compound {} was in the extracellular compartment'
                ' but not defined in the exchange compounds'.format(compound))
        for compound in sorted(exchange_compounds - extracellular_compounds):
            logger.warning(
                'The compound {} was defined in the exchange compounds but'
                ' is not in the extracellular compartment'.format(compound))

        model_definition = None
        if len(self.model) > 0:
            model_definition = self.model

        return MetabolicModel.load_model(
            database, model_definition, itervalues(self.exchange),
            itervalues(self.limits), v_max=self.default_flux_limit)
57972
def advect(f, vx, vy):
    """"""
    rows, cols = f.shape
    cell_xs, cell_ys = np.meshgrid(np.arange(cols), np.arange(rows))
    center_xs = (cell_xs - vx).ravel()
    center_ys = (cell_ys - vy).ravel()

    # Compute indices of source cells.
    left_ix = np.floor(center_ys).astype(int)
    top_ix  = np.floor(center_xs).astype(int)
    rw = center_ys - left_ix              # Relative weight of right-hand cells.
    bw = center_xs - top_ix               # Relative weight of bottom cells.
    left_ix  = np.mod(left_ix,     rows)  # Wrap around edges of simulation.
    right_ix = np.mod(left_ix + 1, rows)
    top_ix   = np.mod(top_ix,      cols)
    bot_ix   = np.mod(top_ix  + 1, cols)

    # A linearly-weighted sum of the 4 surrounding cells.
    flat_f = (1 - rw) * ((1 - bw)*f[left_ix,  top_ix] + bw*f[left_ix,  bot_ix]) \
                 + rw * ((1 - bw)*f[right_ix, top_ix] + bw*f[right_ix, bot_ix])
    return np.reshape(flat_f, (rows, cols))
581633
function setCell(map, key, columnCount, columnIndex, value) {
  if (!map.has(key)) map.set(key, new Array(columnCount));
  map.get(key)[columnIndex] = value;
}
195203
def setCol(self, x, l):
        """"""
        for i in xrange(0, self.__size):
            self.setCell(x, i, l[i])
331551
protected void initMaxCellWidth() {

        m_maxCellWidth = m_opener.getOffsetWidth() - 2 /*border*/;
        for (Widget widget : m_selector) {
            if (widget instanceof A_CmsSelectCell) {
                int cellWidth = ((A_CmsSelectCell)widget).getRequiredWidth();
                if (cellWidth > m_maxCellWidth) {
                    m_maxCellWidth = cellWidth;
                }
            }
        }
    }
1373851
def assign(self, experiment):
        """"""

        self.experiments.append(experiment)
        self.farms.append(empty_farm)
113325
@Override
	public void process() {
		locations.reset();
		descriptions.reset();

		int stepBlockPixelsX = pixelsPerCell *stepBlock;
		int stepBlockPixelsY = pixelsPerCell *stepBlock;

		int maxY = derivX.height - pixelsPerCell * cellsPerBlockY + 1;
		int maxX = derivX.width - pixelsPerCell * cellsPerBlockX + 1;

		for (int y = 0; y < maxY; y += stepBlockPixelsY ) {
			for (int x = 0; x < maxX; x += stepBlockPixelsX ) {
				TupleDesc_F64 d = descriptions.grow();
				Arrays.fill(d.value,0);
				histogram = d.value;

				for (int cellRow = 0; cellRow < cellsPerBlockY; cellRow++) {
					int blockPixelRow = cellRow* pixelsPerCell;
					for (int cellCol = 0; cellCol < cellsPerBlockX; cellCol++) {
						int blockPixelCol = cellCol* pixelsPerCell;

						computeCellHistogram(x+blockPixelCol, y+blockPixelRow, cellCol, cellRow);
					}
				}

				DescribeSiftCommon.normalizeDescriptor(d,0.2);
				locations.grow().set(x,y);
			}
		}
	}
747770
def initialize(self):
    
    if self._pooler is None:
      params = {
        "inputWidth": self.inputWidth,
        "lateralInputWidths": [self.cellCount] * self.numOtherCorticalColumns,
        "cellCount": self.cellCount,
        "sdrSize": self.sdrSize,
        "onlineLearning": self.onlineLearning,
        "maxSdrSize": self.maxSdrSize,
        "minSdrSize": self.minSdrSize,
        "synPermProximalInc": self.synPermProximalInc,
        "synPermProximalDec": self.synPermProximalDec,
        "initialProximalPermanence": self.initialProximalPermanence,
        "minThresholdProximal": self.minThresholdProximal,
        "sampleSizeProximal": self.sampleSizeProximal,
        "connectedPermanenceProximal": self.connectedPermanenceProximal,
        "predictedInhibitionThreshold": self.predictedInhibitionThreshold,
        "synPermDistalInc": self.synPermDistalInc,
        "synPermDistalDec": self.synPermDistalDec,
        "initialDistalPermanence": self.initialDistalPermanence,
        "activationThresholdDistal": self.activationThresholdDistal,
        "sampleSizeDistal": self.sampleSizeDistal,
        "connectedPermanenceDistal": self.connectedPermanenceDistal,
        "inertiaFactor": self.inertiaFactor,
        "seed": self.seed,
      }
      self._pooler = ColumnPooler(**params)
573975
function Cell(north, east, south, west) {
    this._north = north;
    this._east = east;
    this._south = south;
    this._west = west;
}
901275
def plot_cells(cell_1, cell_2, cell_3):
    """"""
    fig, ((ax1, ax2, ax3)) = plt.subplots(1, 3, figsize=(12, 5))
    for ax in [ax1, ax2, ax3]:
        ax.grid(False)
        ax.set_xticks([])
        ax.set_yticks([])
    ax1.set_title("Type 1")
    ax1.imshow(cell_1)
    ax2.set_title("Type 2")
    ax2.imshow(cell_2)
    ax3.set_title("Type 3")
    ax3.imshow(cell_3)
    return ax1, ax2, ax3
236733
def set_CCLE_context(self, cell_types):
        """"""
        self.get_gene_names()

        # Get expression and mutations from context client
        exp_values = \
            context_client.get_protein_expression(self._gene_names, cell_types)
        mut_values = \
            context_client.get_mutations(self._gene_names, cell_types)

        # Make a dict of presence/absence of mutations
        muts = {cell_line: {} for cell_line in cell_types}
        for cell_line, entries in mut_values.items():
            if entries is not None:
                for gene, mutations in entries.items():
                    if mutations:
                        muts[cell_line][gene] = 1
                    else:
                        muts[cell_line][gene] = 0

        # Create bins for the exp values
        # because colorbrewer only does 3-9 bins and I don't feel like
        # reinventing color scheme theory, this will only bin 3-9 bins
        def bin_exp(expression_dict):
            d = expression_dict
            exp_values = []
            for line in d:
                for gene in d[line]:
                    val = d[line][gene]
                    if val is not None:
                        exp_values.append(val)
            thr_dict = {}
            for n_bins in range(3, 10):
                bin_thr = np.histogram(np.log10(exp_values), n_bins)[1][1:]
                thr_dict[n_bins] = bin_thr
            # this dict isn't yet binned, that happens in the loop
            binned_dict = {x: deepcopy(expression_dict) for x in range(3, 10)}
            for n_bins in binned_dict:
                for line in binned_dict[n_bins]:
                    for gene in binned_dict[n_bins][line]:
                        # last bin is reserved for None
                        if binned_dict[n_bins][line][gene] is None:
                            binned_dict[n_bins][line][gene] = n_bins
                        else:
                            val = np.log10(binned_dict[n_bins][line][gene])
                            for thr_idx, thr in enumerate(thr_dict[n_bins]):
                                if val <= thr:
                                    binned_dict[n_bins][line][gene] = thr_idx
                                    break
            return binned_dict
        binned_exp = bin_exp(exp_values)

        context = {'bin_expression': binned_exp,
                   'mutation': muts}
        self._context['CCLE'] = context
575273
def to_abivars(self):
        """"""
        # These variables are always present.
        out_vars = {
            "ionmov" : self.abivars.ionmov,
            "optcell": self.abivars.optcell,
            "ntime"  : self.abivars.ntime,
        }

        # Atom relaxation.
        if self.move_atoms:
            out_vars.update({
                "tolmxf": self.abivars.tolmxf,
            })

        if self.abivars.atoms_constraints:
            # Add input variables for constrained relaxation.
            raise NotImplementedError("")
            out_vars.update(self.abivars.atoms_constraints.to_abivars())

        # Cell relaxation.
        if self.move_cell:
            out_vars.update({
                "dilatmx"  : self.abivars.dilatmx,
                "ecutsm"   : self.abivars.ecutsm,
                "strfact"  : self.abivars.strfact,
                "strtarget": self.abivars.strtarget,
            })

        return out_vars