Search in sources :

Example 1 with ParticleBondType

use of cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType in project vcell by virtualcell.

the class NFsimXMLWriter method getListOfComponents.

private static Element getListOfComponents(String prefix1, ParticleSpeciesPattern speciesPattern, ParticleMolecularTypePattern particleMolecularTypePattern, HashMap<Bond, BondSites> bondSitesMap) throws SolverException {
    if (particleMolecularTypePattern.getMolecularComponentPatternList().isEmpty()) {
        return null;
    }
    Element listOfComponentsElement = new Element("ListOfComponents");
    for (int patternIndex = 0; patternIndex < particleMolecularTypePattern.getMolecularComponentPatternList().size(); patternIndex++) {
        ParticleMolecularComponentPattern particleMolecularComponentPattern = particleMolecularTypePattern.getMolecularComponentPatternList().get(patternIndex);
        Element componentElement = new Element("Component");
        ParticleMolecularComponent particleMolecularComponent = particleMolecularComponentPattern.getMolecularComponent();
        String componentID = prefix1 + "_C" + (patternIndex + 1);
        componentElement.setAttribute("id", componentID);
        componentElement.setAttribute("name", particleMolecularComponent.getName());
        ParticleComponentStatePattern componentStatePattern = particleMolecularComponentPattern.getComponentStatePattern();
        ParticleComponentStateDefinition pcsd = componentStatePattern.getParticleComponentStateDefinition();
        boolean hasState = false;
        if (pcsd != null) {
            componentElement.setAttribute("state", pcsd.getName());
            hasState = true;
        }
        // String state = "";
        // if (componentState!=null){
        // state = componentState.getName();
        // if(!state.equals("*")) {
        // componentElement.setAttribute("state", state);
        // }
        // }
        // number of bonds is 0 or 1 for species (concrete species).  the bonds are listed later in the list of bonds
        ParticleBondType bondType = particleMolecularComponentPattern.getBondType();
        boolean ignoreFlag = false;
        switch(bondType) {
            case Exists:
                {
                    componentElement.setAttribute("numberOfBonds", bondType.symbol);
                    break;
                }
            case None:
                {
                    componentElement.setAttribute("numberOfBonds", "0");
                    break;
                }
            case Possible:
                {
                    componentElement.setAttribute("numberOfBonds", bondType.symbol);
                    ignoreFlag = true;
                    break;
                }
            case Specified:
                {
                    if (particleMolecularComponentPattern.getBondId() >= 0) {
                        componentElement.setAttribute("numberOfBonds", "1");
                        String bondID = prefix1.substring(0, prefix1.lastIndexOf("_"));
                        bondID = bondID + "_B" + particleMolecularComponentPattern.getBondId();
                        Bond bond = new Bond(bondID, speciesPattern);
                        BondSites bondSites = bondSitesMap.get(bond);
                        if (bondSites == null) {
                            BondSites newBondSite = new BondSites();
                            newBondSite.component1 = componentID;
                            bondSitesMap.put(bond, newBondSite);
                        } else {
                            if (bondSites.component1.equals(componentID) || bondSites.component2.equals(componentID)) {
                                throw new SolverException("this molecularComponentPattern already set in bondSites");
                            }
                            if (bondSites.component2.equals("")) {
                                bondSites.component2 = componentID;
                            } else {
                                throw new SolverException("two other molecularComponentPatterns already set in bondSites");
                            }
                        }
                    } else {
                        componentElement.setAttribute("numberOfBonds", "0");
                    }
                    break;
                }
        }
        if (!ignoreFlag || hasState) {
            listOfComponentsElement.addContent(componentElement);
        }
    }
    return listOfComponentsElement;
}
Also used : ParticleComponentStatePattern(cbit.vcell.math.ParticleComponentStatePattern) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) Element(org.jdom.Element) ParticleBondType(cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType) ParticleMolecularComponent(cbit.vcell.math.ParticleMolecularComponent) SolverException(cbit.vcell.solver.SolverException)

Example 2 with ParticleBondType

use of cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType in project vcell by virtualcell.

the class NFsimXMLWriter method getListOfComponents1.

private static Element getListOfComponents1(String reactionRuleID, String patternID, String moleculeID, ParticleSpeciesPattern speciesPattern, ParticleMolecularTypePattern particleMolecularTypePattern, ArrayList<ComponentOfMolecularTypeOfReactionParticipant> currentComponentOfParticipant, HashMap<Bond, BondSites> bondSitesMap) throws SolverException {
    // while traversing Components of a MolecularTypePattern, it populates bondSiteMapping
    Element listOfComponentsElement = new Element("ListOfComponents");
    for (int componentId = 0; componentId < particleMolecularTypePattern.getMolecularComponentPatternList().size(); componentId++) {
        ParticleMolecularComponentPattern particleMolecularComponentPattern = particleMolecularTypePattern.getMolecularComponentPatternList().get(componentId);
        Element componentElement = new Element("Component");
        ParticleMolecularComponent particleMolecularComponent = particleMolecularComponentPattern.getMolecularComponent();
        // componentElement.setAttribute("id", particleMolecularComponent.getId());
        String elementID = "C" + (componentId + 1);
        String componentID = reactionRuleID + "_" + patternID + "_" + moleculeID + "_" + elementID;
        componentElement.setAttribute("id", componentID);
        componentElement.setAttribute("name", particleMolecularComponent.getName());
        ParticleComponentStatePattern componentStatePattern = particleMolecularComponentPattern.getComponentStatePattern();
        ParticleComponentStateDefinition pcsd = componentStatePattern.getParticleComponentStateDefinition();
        String state = "";
        boolean ignoreFlagState = false;
        if (componentStatePattern.isAny()) {
            state = "*";
            ignoreFlagState = true;
        } else if (pcsd != null) {
            state = pcsd.getName();
            componentElement.setAttribute("state", state);
        } else {
            throw new RuntimeException("Invalid state for ParticleComponentStatePattern.");
        }
        // ParticleComponentState componentState = particleMolecularComponentPattern.getComponentState();
        // String state = "";
        // if (componentState!=null){
        // state = componentState.getName();
        // if(!state.equals("*")) {
        // componentElement.setAttribute("state", state);
        // }
        // }
        ComponentOfMolecularTypeOfReactionParticipant cper = new ComponentOfMolecularTypeOfReactionParticipant(particleMolecularTypePattern.getMolecularType().getName(), particleMolecularTypePattern.getMatchLabel(), particleMolecularComponent.getName(), componentID, state);
        // number of bonds is 0 or 1 for species (concrete species).  the bonds are listed later in the list of bonds
        ParticleBondType bondType = particleMolecularComponentPattern.getBondType();
        boolean ignoreFlagBond = false;
        switch(bondType) {
            case Exists:
                {
                    componentElement.setAttribute("numberOfBonds", bondType.symbol);
                    break;
                }
            case None:
                {
                    componentElement.setAttribute("numberOfBonds", "0");
                    break;
                }
            case Possible:
                {
                    componentElement.setAttribute("numberOfBonds", bondType.symbol);
                    ignoreFlagBond = true;
                    break;
                }
            case Specified:
                {
                    if (particleMolecularComponentPattern.getBondId() >= 0) {
                        componentElement.setAttribute("numberOfBonds", "1");
                        String bondID = reactionRuleID + "_" + patternID + "_B" + particleMolecularComponentPattern.getBondId();
                        Bond bond = new Bond(bondID, speciesPattern);
                        BondSites bondSites = bondSitesMap.get(bond);
                        if (bondSites == null) {
                            BondSites newBondSite = new BondSites();
                            newBondSite.component1 = componentID;
                            bondSitesMap.put(bond, newBondSite);
                        } else {
                            if (bondSites.component1.equals(componentID) || bondSites.component2.equals(componentID)) {
                                throw new SolverException("this molecularComponentPattern already set in bondSites");
                            }
                            if (bondSites.component2.equals("")) {
                                bondSites.component2 = componentID;
                            } else {
                                throw new SolverException("two other molecularComponentPatterns already set in bondSites");
                            }
                        }
                    } else {
                        componentElement.setAttribute("numberOfBonds", "0");
                    }
                    break;
                }
        }
        if (ignoreFlagState == false || ignoreFlagBond == false) {
            currentComponentOfParticipant.add(cper);
            listOfComponentsElement.addContent(componentElement);
        }
    }
    return listOfComponentsElement;
}
Also used : ParticleComponentStatePattern(cbit.vcell.math.ParticleComponentStatePattern) Element(org.jdom.Element) ParticleBondType(cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType) ParticleMolecularComponent(cbit.vcell.math.ParticleMolecularComponent) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) SolverException(cbit.vcell.solver.SolverException)

Example 3 with ParticleBondType

use of cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType in project vcell by virtualcell.

the class XmlReader method getParticleMolecularComponentPattern.

private ParticleMolecularComponentPattern getParticleMolecularComponentPattern(Element param, ParticleMolecularType particleMolecularType) throws XmlParseException {
    String molecularComponentName = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    ParticleMolecularComponent particleMolecularComponent = particleMolecularType.getMolecularComponent(molecularComponentName);
    if (particleMolecularComponent != null) {
        ParticleMolecularComponentPattern var = new ParticleMolecularComponentPattern(particleMolecularComponent);
        ParticleComponentStatePattern pcsp = null;
        String componentStateName = unMangle(param.getAttributeValue(XMLTags.StateAttrTag));
        if (componentStateName.equals("*")) {
            pcsp = new ParticleComponentStatePattern();
        } else {
            // ParticleComponentStateDefinition pcsd = new ParticleComponentStateDefinition(componentStateName);		// bad??
            ParticleComponentStateDefinition pcsd = particleMolecularComponent.getComponentStateDefinition(componentStateName);
            if (pcsd == null) {
                throw new XmlParseException("failed to find ParticleComponentStateDefinition named " + molecularComponentName);
            }
            pcsp = new ParticleComponentStatePattern(pcsd);
        }
        var.setComponentStatePattern(pcsp);
        String bondString = unMangle(param.getAttributeValue(XMLTags.BondAttrTag));
        ParticleBondType bondType = ParticleBondType.fromSymbol(bondString);
        if (bondType == ParticleBondType.Specified) {
            int bondId = Integer.parseInt(bondString);
            var.setBondId(bondId);
        }
        var.setBondType(bondType);
        return var;
    } else {
        throw new XmlParseException("failed to find ParticleMolecularComponent named " + molecularComponentName);
    }
}
Also used : ParticleComponentStatePattern(cbit.vcell.math.ParticleComponentStatePattern) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) ParticleBondType(cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType) ParticleMolecularComponent(cbit.vcell.math.ParticleMolecularComponent)

Aggregations

ParticleComponentStateDefinition (cbit.vcell.math.ParticleComponentStateDefinition)3 ParticleComponentStatePattern (cbit.vcell.math.ParticleComponentStatePattern)3 ParticleMolecularComponent (cbit.vcell.math.ParticleMolecularComponent)3 ParticleMolecularComponentPattern (cbit.vcell.math.ParticleMolecularComponentPattern)3 ParticleBondType (cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType)3 SolverException (cbit.vcell.solver.SolverException)2 Element (org.jdom.Element)2