Search in sources :

Example 1 with ParticleProperties

use of cbit.vcell.math.ParticleProperties in project vcell by virtualcell.

the class NFsimXMLWriter method getListOfSpecies.

private static Element getListOfSpecies(MathDescription mathDesc, SimulationSymbolTable simulationSymbolTable) throws SolverException {
    CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) mathDesc.getSubDomains().nextElement();
    // 
    // NFsim expects a list of seed species.  These are concrete species patterns that have a "ParticleProperties" element defined (for initial conditions).
    // 
    Element listOfSpeciesElement = new Element("ListOfSpecies");
    for (int speciesIndex = 0; speciesIndex < compartmentSubDomain.getParticleProperties().size(); speciesIndex++) {
        // seedSpecies.getSpeciesPattern().resolveBonds();
        ParticleProperties particleProperties = compartmentSubDomain.getParticleProperties().get(speciesIndex);
        Element speciesElement = new Element("Species");
        String speciesID = "S" + (speciesIndex + 1);
        ParticleSpeciesPattern seedSpecies = (ParticleSpeciesPattern) particleProperties.getVariable();
        speciesElement.setAttribute("id", speciesID);
        speciesElement.setAttribute("name", seedSpecies.getName());
        List<ParticleInitialCondition> particleInitialConditions = particleProperties.getParticleInitialConditions();
        if (particleInitialConditions.size() != 1) {
            throw new SolverException("multiple particle initial conditions not expected for " + ParticleSpeciesPattern.class.getSimpleName() + " " + seedSpecies.getName());
        }
        // the initial conditions must be a count in math (ParticleInitialConditionCount)
        if (!(particleInitialConditions.get(0) instanceof ParticleInitialConditionCount)) {
            throw new SolverException("expecting initial count for " + ParticleSpeciesPattern.class.getSimpleName() + " " + seedSpecies.getName());
        }
        ParticleInitialConditionCount initialCount = (ParticleInitialConditionCount) particleInitialConditions.get(0);
        try {
            double value = evaluateConstant(initialCount.getCount(), simulationSymbolTable);
            Integer maxMoleculesPerType = simulationSymbolTable.getSimulation().getSolverTaskDescription().getNFSimSimulationOptions().getMaxMoleculesPerType();
            if (maxMoleculesPerType == null) {
                maxMoleculesPerType = NFsimSimulationOptions.DefaultMaxMoleculesPerSpecies;
            }
            if (maxMoleculesPerType.doubleValue() < value) {
                String eMessage = "The Initial count for Species '" + seedSpecies.getName() + "' is " + BigDecimal.valueOf(value).toBigInteger();
                eMessage += ", which is higher than the limit of " + maxMoleculesPerType + ".\n";
                eMessage += "Please do one of the following: \n- reduce the Initial Condition value for this Species or reduce the compartment size\n";
                eMessage += "- increase the maximal number of Molecules per Molecular Type in the Advanced Solver Options panel.";
                throw new RuntimeException(eMessage);
            }
            speciesElement.setAttribute("concentration", Double.toString(value));
        } catch (ExpressionException | MathException e) {
            e.printStackTrace();
            throw new SolverException("error processing initial count of " + ParticleSpeciesPattern.class.getSimpleName() + " " + seedSpecies.getName() + ": " + e.getMessage());
        }
        HashMap<Bond, BondSites> bondSiteMapping = new HashMap<Bond, BondSites>();
        Element listOfMoleculesElement = getListOfMolecules(speciesID, seedSpecies, bondSiteMapping);
        speciesElement.addContent(listOfMoleculesElement);
        if (bondSiteMapping.size() > 0) {
            Element listOfBondsElement = getListOfBonds(bondSiteMapping);
            speciesElement.addContent(listOfBondsElement);
        }
        listOfSpeciesElement.addContent(speciesElement);
    }
    return listOfSpeciesElement;
}
Also used : HashMap(java.util.HashMap) Element(org.jdom.Element) ExpressionException(cbit.vcell.parser.ExpressionException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) ParticleInitialCondition(cbit.vcell.math.ParticleProperties.ParticleInitialCondition) MathException(cbit.vcell.math.MathException) ParticleProperties(cbit.vcell.math.ParticleProperties) ParticleSpeciesPattern(cbit.vcell.math.ParticleSpeciesPattern) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) SolverException(cbit.vcell.solver.SolverException) ParticleInitialConditionCount(cbit.vcell.math.ParticleProperties.ParticleInitialConditionCount)

Example 2 with ParticleProperties

use of cbit.vcell.math.ParticleProperties in project vcell by virtualcell.

the class SmoldynFileWriter method writeMolecules.

private void writeMolecules() throws ExpressionException, MathException {
    // write molecules
    StringBuilder sb = new StringBuilder();
    int max_mol = 0;
    Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
    while (subDomainEnumeration.hasMoreElements()) {
        SubDomain subDomain = subDomainEnumeration.nextElement();
        for (ParticleProperties particleProperties : subDomain.getParticleProperties()) {
            ArrayList<ParticleInitialCondition> particleInitialConditions = particleProperties.getParticleInitialConditions();
            String variableName = getVariableName(particleProperties.getVariable(), subDomain);
            for (ParticleInitialCondition pic : particleInitialConditions) {
                if (pic instanceof ParticleInitialConditionCount) {
                    max_mol += writeInitialCount((ParticleInitialConditionCount) pic, subDomain, variableName, sb);
                } else if (pic instanceof ParticleInitialConditionConcentration) {
                    max_mol += writeInitialConcentration((ParticleInitialConditionConcentration) pic, subDomain, particleProperties.getVariable(), variableName, sb);
                }
            }
            if (lg.isDebugEnabled()) {
                lg.debug("subdomain " + subDomain.getName() + ' ' + variableName + " processed, maximum mol estimate now " + max_mol);
            }
        }
    }
    if (max_mol > MAX_MOLECULE_LIMIT) {
        throw new MathException(VCellErrorMessages.getSmoldynMaxMolReachedErrorMessage((long) max_mol, MAX_MOLECULE_LIMIT));
    }
    int max_adjusted = max_mol * MOLECULE_MAX_COEFFICIENT;
    if (max_adjusted < MIN_MOLECULE_LIMIT) {
        if (lg.isInfoEnabled()) {
            lg.info("adjusting computed max " + max_adjusted + " to minimum " + MIN_MOLECULE_LIMIT);
        }
        max_adjusted = MIN_MOLECULE_LIMIT;
    }
    if (max_adjusted > MAX_MOLECULE_LIMIT) {
        if (lg.isInfoEnabled()) {
            lg.info("adjusting computed max " + max_adjusted + " to maximum " + MAX_MOLECULE_LIMIT);
        }
        max_adjusted = MAX_MOLECULE_LIMIT;
    }
    printWriter.println("# molecules");
    printWriter.println(SmoldynVCellMapper.SmoldynKeyword.max_mol + " " + max_adjusted);
    printWriter.println(sb);
}
Also used : CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) ParticleInitialConditionConcentration(cbit.vcell.math.ParticleProperties.ParticleInitialConditionConcentration) ParticleInitialCondition(cbit.vcell.math.ParticleProperties.ParticleInitialCondition) MathException(cbit.vcell.math.MathException) ParticleProperties(cbit.vcell.math.ParticleProperties) ParticleInitialConditionCount(cbit.vcell.math.ParticleProperties.ParticleInitialConditionCount)

Example 3 with ParticleProperties

use of cbit.vcell.math.ParticleProperties in project vcell by virtualcell.

the class SmoldynFileWriter method writeDrifts.

private void writeDrifts() throws ExpressionBindingException, ExpressionException, MathException {
    // writer diffusion properties
    printWriter.println("# drift properties");
    Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
    while (subDomainEnumeration.hasMoreElements()) {
        SubDomain subDomain = subDomainEnumeration.nextElement();
        List<ParticleProperties> particlePropertiesList = subDomain.getParticleProperties();
        for (ParticleProperties pp : particlePropertiesList) {
            String variableName = null;
            if (subDomain instanceof MembraneSubDomain) {
                variableName = getVariableName(pp.getVariable(), subDomain);
            } else {
                variableName = getVariableName(pp.getVariable(), null);
            }
            try {
                double driftX = 0.0;
                if (pp.getDriftX() != null) {
                    driftX = subsituteFlattenToConstant(pp.getDriftX());
                }
                double driftY = 0.0;
                if (pp.getDriftY() != null) {
                    driftY = subsituteFlattenToConstant(pp.getDriftY());
                }
                double driftZ = 0.0;
                if (pp.getDriftZ() != null) {
                    driftZ = subsituteFlattenToConstant(pp.getDriftZ());
                }
                printWriter.println(SmoldynVCellMapper.SmoldynKeyword.drift + " " + variableName + " " + driftX + " " + driftY + " " + driftZ);
            } catch (NotAConstantException ex) {
                throw new ExpressionException("diffusion coefficient for variable " + variableName + " is not a constant. Constants are required for all diffusion coefficients");
            }
        }
    }
    printWriter.println();
}
Also used : CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) ParticleProperties(cbit.vcell.math.ParticleProperties) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 4 with ParticleProperties

use of cbit.vcell.math.ParticleProperties in project vcell by virtualcell.

the class Xmlproducer method getXML.

/**
 * This method returns a XML representation of a CompartmentSubDomain object.
 * Creation date: (3/2/2001 1:18:55 PM)
 * @return Element
 * @param param cbit.vcell.math.CompartmentSubDomain
 */
private Element getXML(CompartmentSubDomain param) throws XmlParseException {
    Element compartment = new Element(XMLTags.CompartmentSubDomainTag);
    compartment.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
    // Add boundaryType subelements
    Element boundary;
    // Xm
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXm);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXm().boundaryTypeStringValue());
    compartment.addContent(boundary);
    // Xp
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXp);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXp().boundaryTypeStringValue());
    compartment.addContent(boundary);
    // Ym
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYm);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYm().boundaryTypeStringValue());
    compartment.addContent(boundary);
    // Yp
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYp);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYp().boundaryTypeStringValue());
    compartment.addContent(boundary);
    // Zm
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZm);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZm().boundaryTypeStringValue());
    compartment.addContent(boundary);
    // Zp
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZp);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZp().boundaryTypeStringValue());
    compartment.addContent(boundary);
    // add BoundaryConditionSpecs
    for (BoundaryConditionSpec bcs : param.getBoundaryconditionSpecs()) {
        compartment.addContent(getXML(bcs));
    }
    // Add Equations
    Enumeration<Equation> enum1 = param.getEquations();
    while (enum1.hasMoreElements()) {
        Equation equ = enum1.nextElement();
        compartment.addContent(getXML(equ));
    }
    // Add FastSystem
    if (param.getFastSystem() != null) {
        compartment.addContent(getXML(param.getFastSystem()));
    }
    // Add Variable Initial Condition
    for (VarIniCondition varIni : param.getVarIniConditions()) {
        compartment.addContent(getXML(varIni));
    }
    // Add JumpProcesses
    for (JumpProcess jp : param.getJumpProcesses()) {
        compartment.addContent(getXML(jp));
    }
    for (ParticleJumpProcess pjp : param.getParticleJumpProcesses()) {
        compartment.addContent(getXML(pjp));
    }
    for (ParticleProperties pp : param.getParticleProperties()) {
        compartment.addContent(getXML(pp));
    }
    return compartment;
}
Also used : VarIniCondition(cbit.vcell.math.VarIniCondition) Element(org.jdom.Element) ParticleJumpProcess(cbit.vcell.math.ParticleJumpProcess) ComputeNormalComponentEquation(cbit.vcell.math.ComputeNormalComponentEquation) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) PdeEquation(cbit.vcell.math.PdeEquation) ComputeMembraneMetricEquation(cbit.vcell.math.ComputeMembraneMetricEquation) OdeEquation(cbit.vcell.math.OdeEquation) ComputeCentroidComponentEquation(cbit.vcell.math.ComputeCentroidComponentEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation) Equation(cbit.vcell.math.Equation) JumpProcess(cbit.vcell.math.JumpProcess) ParticleJumpProcess(cbit.vcell.math.ParticleJumpProcess) ParticleProperties(cbit.vcell.math.ParticleProperties) BoundaryConditionSpec(cbit.vcell.math.SubDomain.BoundaryConditionSpec)

Example 5 with ParticleProperties

use of cbit.vcell.math.ParticleProperties in project vcell by virtualcell.

the class Xmlproducer method getXML.

/**
 * This method returns a XML representation of a MembraneSubDomain object.
 * Creation date: (3/2/2001 5:40:17 PM)
 * @return Element
 * @param param cbit.vcell.math.MembraneSubDomain
 */
private Element getXML(MembraneSubDomain param) throws XmlParseException {
    Element membrane = new Element(XMLTags.MembraneSubDomainTag);
    // Add attributes
    membrane.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
    membrane.setAttribute(XMLTags.InsideCompartmentTag, mangle(param.getInsideCompartment().getName()));
    membrane.setAttribute(XMLTags.OutsideCompartmentTag, mangle(param.getOutsideCompartment().getName()));
    // Add boundaryType subelements
    Element boundary;
    // Xm
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXm);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXm().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Xp
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXp);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXp().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Ym
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYm);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYm().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Yp
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYp);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYp().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Zm
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZm);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZm().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Zp
    boundary = new Element(XMLTags.BoundaryTypeTag);
    boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZp);
    boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZp().boundaryTypeStringValue());
    membrane.addContent(boundary);
    // Add Equation subelements
    Enumeration<Equation> enum1 = param.getEquations();
    while (enum1.hasMoreElements()) {
        Equation equ = enum1.nextElement();
        membrane.addContent(getXML(equ));
    }
    // Add JumConditions
    Enumeration<JumpCondition> enum2 = param.getJumpConditions();
    while (enum2.hasMoreElements()) {
        JumpCondition jc = (JumpCondition) enum2.nextElement();
        membrane.addContent(getXML(jc));
    }
    // Add FastSystem (if there is)
    if (param.getFastSystem() != null) {
        membrane.addContent(getXML(param.getFastSystem()));
    }
    for (ParticleProperties pp : param.getParticleProperties()) {
        membrane.addContent(getXML(pp));
    }
    for (ParticleJumpProcess pjp : param.getParticleJumpProcesses()) {
        membrane.addContent(getXML(pjp));
    }
    Mutable<Element> velocity = new MutableObject<>();
    addVelocityMaybe(velocity, XMLTags.XAttrTag, param.getVelocityX());
    addVelocityMaybe(velocity, XMLTags.YAttrTag, param.getVelocityY());
    if (velocity.getValue() != null) {
        membrane.addContent(velocity.getValue());
    }
    return membrane;
}
Also used : JumpCondition(cbit.vcell.math.JumpCondition) Element(org.jdom.Element) ParticleJumpProcess(cbit.vcell.math.ParticleJumpProcess) ComputeNormalComponentEquation(cbit.vcell.math.ComputeNormalComponentEquation) VolumeRegionEquation(cbit.vcell.math.VolumeRegionEquation) PdeEquation(cbit.vcell.math.PdeEquation) ComputeMembraneMetricEquation(cbit.vcell.math.ComputeMembraneMetricEquation) OdeEquation(cbit.vcell.math.OdeEquation) ComputeCentroidComponentEquation(cbit.vcell.math.ComputeCentroidComponentEquation) MembraneRegionEquation(cbit.vcell.math.MembraneRegionEquation) Equation(cbit.vcell.math.Equation) ParticleProperties(cbit.vcell.math.ParticleProperties) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Aggregations

ParticleProperties (cbit.vcell.math.ParticleProperties)13 SubDomain (cbit.vcell.math.SubDomain)9 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)7 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)7 Expression (cbit.vcell.parser.Expression)7 ExpressionException (cbit.vcell.parser.ExpressionException)6 MathDescription (cbit.vcell.math.MathDescription)5 ParticleInitialCondition (cbit.vcell.math.ParticleProperties.ParticleInitialCondition)5 ArrayList (java.util.ArrayList)5 ParticleJumpProcess (cbit.vcell.math.ParticleJumpProcess)4 ParticleInitialConditionCount (cbit.vcell.math.ParticleProperties.ParticleInitialConditionCount)4 ParticleVariable (cbit.vcell.math.ParticleVariable)4 Variable (cbit.vcell.math.Variable)4 VolumeParticleVariable (cbit.vcell.math.VolumeParticleVariable)4 Element (org.jdom.Element)4 GeometryClass (cbit.vcell.geometry.GeometryClass)3 Constant (cbit.vcell.math.Constant)3 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)3 MathException (cbit.vcell.math.MathException)3 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)3