Search in sources :

Example 1 with ParticleSpeciesPattern

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

the class NFsimXMLWriter method getParticleSpeciesPatternList.

private static Element getParticleSpeciesPatternList(String prefix0, ParticleObservable particleObservable) {
    Element listOfPatternsElement = new Element("ListOfPatterns");
    for (int molecularPatternIndex = 0; molecularPatternIndex < particleObservable.getParticleSpeciesPatterns().size(); molecularPatternIndex++) {
        ParticleSpeciesPattern pattern = particleObservable.getParticleSpeciesPatterns().get(molecularPatternIndex);
        if (pattern instanceof VolumeParticleSpeciesPattern) {
            Element patternElement;
            try {
                String molecularPatternID = "P" + (molecularPatternIndex + 1);
                patternElement = getObservableParticipantPattern(prefix0, molecularPatternID, (VolumeParticleSpeciesPattern) pattern, "Pattern", particleObservable.getSequence(), particleObservable.getQuantity());
                listOfPatternsElement.addContent(patternElement);
            } catch (SolverException e) {
                e.printStackTrace();
            }
        }
    }
    return listOfPatternsElement;
}
Also used : Element(org.jdom.Element) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) ParticleSpeciesPattern(cbit.vcell.math.ParticleSpeciesPattern) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) SolverException(cbit.vcell.solver.SolverException)

Example 2 with ParticleSpeciesPattern

use of cbit.vcell.math.ParticleSpeciesPattern 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 3 with ParticleSpeciesPattern

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

the class XmlReader method getVolumeParticleObservable.

private VolumeParticleObservable getVolumeParticleObservable(Element param, VariableHash varHash) throws XmlParseException {
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
    Domain domain = null;
    if (domainStr != null) {
        domain = new Domain(domainStr);
    }
    String molecularTypeString = unMangle(param.getAttributeValue(XMLTags.ParticleMolecularTypePatternTag));
    ObservableType observableType = ObservableType.fromString(molecularTypeString);
    VolumeParticleObservable var = new VolumeParticleObservable(name, domain, observableType);
    String sequenceAttr = param.getAttributeValue(XMLTags.ParticleObservableSequenceTypeAttrTag);
    if (sequenceAttr != null) {
        Sequence sequence = Sequence.fromString(sequenceAttr);
        String sequenceLength = param.getAttributeValue(XMLTags.ParticleObservableSequenceLengthAttrTag);
        var.setSequence(sequence);
        if (sequence != Sequence.Multimolecular) {
            var.setQuantity(Integer.parseInt(sequenceLength));
        }
    } else {
        var.setSequence(Sequence.Multimolecular);
    }
    Element volumeParticleSpeciesPatternsElement = param.getChild(XMLTags.VolumeParticleSpeciesPatternsTag, vcNamespace);
    List<Element> volumeParticleSpeciesPatternList = volumeParticleSpeciesPatternsElement.getChildren(XMLTags.VolumeParticleSpeciesPatternTag, vcNamespace);
    for (Element volumeParticleSpeciesPattern : volumeParticleSpeciesPatternList) {
        String volumeParticleSpeciesPatternName = unMangle(volumeParticleSpeciesPattern.getAttributeValue(XMLTags.NameAttrTag));
        Variable v = varHash.getVariable(volumeParticleSpeciesPatternName);
        if (v == null) {
            throw new XmlParseException("failed to find VolumeParticleSpeciesPattern named " + volumeParticleSpeciesPatternName);
        }
        if (v instanceof ParticleSpeciesPattern) {
            var.addParticleSpeciesPattern((ParticleSpeciesPattern) v);
        } else {
            throw new XmlParseException("Variable " + volumeParticleSpeciesPatternName + " is not a ParticleSpeciesPattern");
        }
    }
    return var;
}
Also used : FilamentVariable(cbit.vcell.math.FilamentVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) StochVolVariable(cbit.vcell.math.StochVolVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) VolVariable(cbit.vcell.math.VolVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) PointVariable(cbit.vcell.math.PointVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) MemVariable(cbit.vcell.math.MemVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) ObservableType(cbit.vcell.math.ParticleObservable.ObservableType) Element(org.jdom.Element) ParticleSpeciesPattern(cbit.vcell.math.ParticleSpeciesPattern) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) Sequence(cbit.vcell.math.ParticleObservable.Sequence) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) Domain(cbit.vcell.math.Variable.Domain) VolumeParticleObservable(cbit.vcell.math.VolumeParticleObservable)

Example 4 with ParticleSpeciesPattern

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

the class RbmUtils method toBnglStringShort.

public static String toBnglStringShort(ParticleJumpProcess particleJumpProcess, List<ParticleSpeciesPattern> reactantSpeciesPatterns, List<ParticleSpeciesPattern> productSpeciesPatterns) {
    StringBuilder buffer = new StringBuilder();
    for (int i = 0; i < reactantSpeciesPatterns.size(); i++) {
        ParticleSpeciesPattern reactantSpeciesPattern = reactantSpeciesPatterns.get(i);
        if (i > 0) {
            buffer.append(" + ");
        }
        buffer.append(toBnglString(reactantSpeciesPattern));
    }
    // particleJumpProcesses are not reversible
    boolean bReversible = false;
    buffer.append(bReversible ? " <-> " : " -> ");
    for (int i = 0; i < productSpeciesPatterns.size(); i++) {
        ParticleSpeciesPattern productSpeciesPattern = productSpeciesPatterns.get(i);
        if (i > 0) {
            buffer.append(" + ");
        }
        buffer.append(toBnglString(productSpeciesPattern));
    }
    return buffer.toString();
}
Also used : ParticleSpeciesPattern(cbit.vcell.math.ParticleSpeciesPattern)

Example 5 with ParticleSpeciesPattern

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

the class Xmlproducer method getVolumeParticleSpeciesPatternList.

private Element getVolumeParticleSpeciesPatternList(ParticleObservable param) {
    org.jdom.Element e = null;
    e = new org.jdom.Element(XMLTags.VolumeParticleSpeciesPatternsTag);
    for (ParticleSpeciesPattern pp : param.getParticleSpeciesPatterns()) {
        org.jdom.Element e1 = new org.jdom.Element(XMLTags.VolumeParticleSpeciesPatternTag);
        e1.setAttribute(XMLTags.NameAttrTag, mangle(pp.getName()));
        e.addContent(e1);
    }
    return e;
}
Also used : Element(org.jdom.Element) ParticleSpeciesPattern(cbit.vcell.math.ParticleSpeciesPattern) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) Element(org.jdom.Element)

Aggregations

ParticleSpeciesPattern (cbit.vcell.math.ParticleSpeciesPattern)5 VolumeParticleSpeciesPattern (cbit.vcell.math.VolumeParticleSpeciesPattern)4 Element (org.jdom.Element)4 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)2 SolverException (cbit.vcell.solver.SolverException)2 FilamentRegionVariable (cbit.vcell.math.FilamentRegionVariable)1 FilamentSubDomain (cbit.vcell.math.FilamentSubDomain)1 FilamentVariable (cbit.vcell.math.FilamentVariable)1 InsideVariable (cbit.vcell.math.InsideVariable)1 MathException (cbit.vcell.math.MathException)1 MemVariable (cbit.vcell.math.MemVariable)1 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)1 MembraneRandomVariable (cbit.vcell.math.MembraneRandomVariable)1 MembraneRegionVariable (cbit.vcell.math.MembraneRegionVariable)1 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)1 OutsideVariable (cbit.vcell.math.OutsideVariable)1 ObservableType (cbit.vcell.math.ParticleObservable.ObservableType)1 Sequence (cbit.vcell.math.ParticleObservable.Sequence)1 ParticleProperties (cbit.vcell.math.ParticleProperties)1 ParticleInitialCondition (cbit.vcell.math.ParticleProperties.ParticleInitialCondition)1