All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.unibo.alchemist.model.biochemistry.actions.ChangeBiomolConcentrationInCell Maven / Gradle / Ivy

There is a newer version: 35.0.2
Show newest version
/*
 * Copyright (C) 2010-2023, Danilo Pianini and contributors
 * listed, for each module, in the respective subproject's build.gradle.kts file.
 *
 * This file is part of Alchemist, and is distributed under the terms of the
 * GNU General Public License, with a linking exception,
 * as described in the file LICENSE in the Alchemist distribution's top directory.
 */

package it.unibo.alchemist.model.biochemistry.actions;

import it.unibo.alchemist.model.actions.AbstractActionOnSingleMolecule;
import it.unibo.alchemist.model.biochemistry.molecules.Biomolecule;
import it.unibo.alchemist.model.Context;
import it.unibo.alchemist.model.Node;
import it.unibo.alchemist.model.Reaction;

/**
 *
 */
public final class ChangeBiomolConcentrationInCell extends AbstractActionOnSingleMolecule {

    private static final long serialVersionUID = 5569613886926615012L;
    private final double deltaC;

    /**
     * 
     * @param biomolecule the molecule
     * @param deltaConcentration the change in concentration
     * @param node the node
     */
    public ChangeBiomolConcentrationInCell(
            final Node node,
            final Biomolecule biomolecule,
            final double deltaConcentration
    ) {
        super(node, biomolecule);
        if (deltaConcentration == 0) {
            throw new IllegalArgumentException(
                "Changing the concentration of '" + biomolecule + "' of 0 in node " + node.getId() + "makes no sense"
            );
        }
        this.deltaC = deltaConcentration;
    }

    @Override
    public ChangeBiomolConcentrationInCell cloneAction(final Node node, final Reaction reaction) {
        throw new UnsupportedOperationException("cloneOnNewNode(Node, Reaction) has to be implemented in: " + getClass());
    }

    @Override
    public void execute() {
        super.getNode().setConcentration(getMolecule(), super.getNode().getConcentration(getMolecule()) + deltaC);
    }

    @Override
    public Context getContext() {
        return Context.LOCAL; 
    }

    @Override
    public String toString() {
         if (deltaC >= 0) {
             return getMolecule().getName() + "+" + deltaC;
         }  else {
             return getMolecule().getName() + deltaC;
         }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy