Search in sources :

Example 6 with Comment

use of org.jdom.Comment in project vcell by virtualcell.

the class NFsimXMLWriter method writeNFsimXML.

public static Element writeNFsimXML(SimulationTask origSimTask, long randomSeed, NFsimSimulationOptions nfsimSimulationOptions, boolean bUseLocationMarks) throws SolverException {
    try {
        System.out.println("VCML ORIGINAL .... START\n" + origSimTask.getSimulation().getMathDescription().getVCML_database() + "\nVCML ORIGINAL .... END\n====================\n");
    } catch (MathException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    SimulationTask clonedSimTask = null;
    try {
        clonedSimTask = (SimulationTask) BeanUtils.cloneSerializable(origSimTask);
    } catch (Exception eee) {
        throw new SolverException("failed to clone mathDescription while preparing NFSim input: " + eee.getMessage(), eee);
    }
    MathDescription clonedMathDesc = clonedSimTask.getSimulation().getMathDescription();
    if (bUseLocationMarks) {
        try {
            // 
            // get list of Compartment Names (stored in locations).
            // 
            ArrayList<String> locations = new ArrayList<String>();
            Enumeration<Variable> varEnum = clonedMathDesc.getVariables();
            ArrayList<VolumeParticleSpeciesPattern> volumeParticleSpeciesPatterns = new ArrayList<VolumeParticleSpeciesPattern>();
            while (varEnum.hasMoreElements()) {
                Variable var = varEnum.nextElement();
                if (var instanceof VolumeParticleSpeciesPattern) {
                    VolumeParticleSpeciesPattern speciesPattern = (VolumeParticleSpeciesPattern) var;
                    if (!locations.contains(speciesPattern.getLocationName())) {
                        locations.add(speciesPattern.getLocationName());
                    }
                    volumeParticleSpeciesPatterns.add(speciesPattern);
                }
            }
            // 
            for (ParticleMolecularType particleMolecularType : clonedMathDesc.getParticleMolecularTypes()) {
                String pmcLocationName = RbmUtils.SiteStruct;
                String pmcLocationId = particleMolecularType.getName() + "_" + RbmUtils.SiteStruct;
                ParticleMolecularComponent locationComponent = new ParticleMolecularComponent(pmcLocationId, pmcLocationName);
                for (String location : locations) {
                    locationComponent.addComponentStateDefinition(new ParticleComponentStateDefinition(location));
                }
                particleMolecularType.insertMolecularComponent(0, locationComponent);
                String pmcMarkName = RbmUtils.SiteProduct;
                String pmcMarkId = particleMolecularType.getName() + "_" + RbmUtils.SiteProduct;
                ParticleMolecularComponent markComponent = new ParticleMolecularComponent(pmcMarkId, pmcMarkName);
                markComponent.addComponentStateDefinition(new ParticleComponentStateDefinition("0"));
                markComponent.addComponentStateDefinition(new ParticleComponentStateDefinition("1"));
                particleMolecularType.insertMolecularComponent(1, markComponent);
            }
            // 
            for (VolumeParticleSpeciesPattern speciesPattern : volumeParticleSpeciesPatterns) {
                for (ParticleMolecularTypePattern molTypePattern : speciesPattern.getParticleMolecularTypePatterns()) {
                    // 
                    // add location component to pattern ... state=<location>
                    // 
                    {
                        final ParticleMolecularComponent locationComponentDefinition = molTypePattern.getMolecularType().getComponentList().get(0);
                        ParticleMolecularComponentPattern locationPattern = new ParticleMolecularComponentPattern(locationComponentDefinition);
                        ParticleComponentStateDefinition locationStateDefinition = null;
                        for (ParticleComponentStateDefinition stateDef : locationComponentDefinition.getComponentStateDefinitions()) {
                            if (stateDef.getName().equals(speciesPattern.getLocationName())) {
                                locationStateDefinition = stateDef;
                            }
                        }
                        ParticleComponentStatePattern locationStatePattern = new ParticleComponentStatePattern(locationStateDefinition);
                        locationPattern.setComponentStatePattern(locationStatePattern);
                        locationPattern.setBondType(ParticleBondType.None);
                        locationPattern.setBondId(-1);
                        molTypePattern.insertMolecularComponentPattern(0, locationPattern);
                    }
                    // 
                    // add mark component to pattern ... state="0" (for observables and reactants ... later we will clone and use "1" for products).
                    {
                        final ParticleMolecularComponent markComponentDefinition = molTypePattern.getMolecularType().getComponentList().get(1);
                        ParticleMolecularComponentPattern markPattern = new ParticleMolecularComponentPattern(markComponentDefinition);
                        final int clearStateIndex = 0;
                        final int setStateIndex = 1;
                        ParticleComponentStateDefinition markStateClearedDefinition = markComponentDefinition.getComponentStateDefinitions().get(clearStateIndex);
                        ParticleComponentStatePattern markStatePattern = new ParticleComponentStatePattern(markStateClearedDefinition);
                        markPattern.setComponentStatePattern(markStatePattern);
                        markPattern.setBondType(ParticleBondType.None);
                        markPattern.setBondId(-1);
                        molTypePattern.insertMolecularComponentPattern(1, markPattern);
                    }
                }
            }
            // 
            // when processing ParticleJumpProcesses, we add a new "product" species pattern (by cloning the original speciesPattern)
            // and setting the mark site to "1", change name to name+"_PRODUCT", and add to math model if it doesn't already exist.
            // 
            // cloned the "standard" reactant/observable speciesPattern, set the mark for all molecules, and add to mathDesc.
            // 
            CompartmentSubDomain subDomain = (CompartmentSubDomain) clonedMathDesc.getSubDomains().nextElement();
            for (ParticleJumpProcess particleJumpProcess : subDomain.getParticleJumpProcesses()) {
                for (Action action : particleJumpProcess.getActions()) {
                    if (action.getOperation().equals(Action.ACTION_CREATE)) {
                        VolumeParticleSpeciesPattern volumeParticleSpeciesPattern = (VolumeParticleSpeciesPattern) action.getVar();
                        String newSpeciesPatternName = volumeParticleSpeciesPattern.getName() + "_" + particleJumpProcess.getName();
                        VolumeParticleSpeciesPattern productPattern = new VolumeParticleSpeciesPattern(volumeParticleSpeciesPattern, newSpeciesPatternName);
                        // VolumeParticleSpeciesPattern productPattern = (VolumeParticleSpeciesPattern) BeanUtils.cloneSerializable(volumeParticleSpeciesPattern);
                        for (ParticleMolecularTypePattern productMolTypePattern : productPattern.getParticleMolecularTypePatterns()) {
                            ParticleComponentStateDefinition markSet = productMolTypePattern.getMolecularType().getComponentList().get(1).getComponentStateDefinitions().get(1);
                            productMolTypePattern.getMolecularComponentPatternList().get(1).setComponentStatePattern(new ParticleComponentStatePattern(markSet));
                        }
                        System.out.println(productPattern.getName());
                        if (clonedMathDesc.getVariable(productPattern.getName()) == null) {
                            clonedMathDesc.addVariable(productPattern);
                        }
                        action.setVar(productPattern);
                    }
                }
            }
            try {
                System.out.println("===============================\n ----------- VCML HACKED .... START\n" + clonedMathDesc.getVCML_database() + "\nVCML HACKED .... END\n====================\n");
            } catch (MathException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        } catch (Exception e) {
            throw new SolverException("failed to apply location mark transformation: " + e.getMessage(), e);
        }
    }
    Element sbmlElement = new Element("sbml");
    Element modelElement = new Element("model");
    modelElement.setAttribute("id", "nameless");
    SimulationSymbolTable simulationSymbolTable = new SimulationSymbolTable(clonedSimTask.getSimulation(), clonedSimTask.getSimulationJob().getJobIndex());
    Element listOfParametersElement = getListOfParameters(clonedMathDesc, simulationSymbolTable);
    Element listOfMoleculeTypesElement = getListOfMoleculeTypes(clonedMathDesc);
    Element listOfSpeciesElement = getListOfSpecies(clonedMathDesc, simulationSymbolTable);
    CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) clonedMathDesc.getSubDomains().nextElement();
    Element listOfReactionRules = new Element("ListOfReactionRules");
    for (int reactionRuleIndex = 0; reactionRuleIndex < compartmentSubDomain.getParticleJumpProcesses().size(); reactionRuleIndex++) {
        ParticleJumpProcess particleJumpProcess = compartmentSubDomain.getParticleJumpProcesses().get(reactionRuleIndex);
        MathRuleFactory mathRuleFactory = new MathRuleFactory();
        MathRuleEntry rule = mathRuleFactory.createRuleEntry(particleJumpProcess, reactionRuleIndex);
        RuleAnalysisReport report = RuleAnalysis.analyze(rule, true);
        // remember, we have to add RateLaw
        Element reactionRuleElement = RuleAnalysis.getNFSimXML(rule, report);
        // ArrayList<MolecularTypeOfReactionParticipant> currentReactantElementsOfReaction = new ArrayList<MolecularTypeOfReactionParticipant>();
        // ArrayList<ComponentOfMolecularTypeOfReactionParticipant> currentComponentOfReactantElementsOfReaction = new ArrayList<ComponentOfMolecularTypeOfReactionParticipant>();
        // ArrayList<MolecularTypeOfReactionParticipant> currentProductElementsOfReaction = new ArrayList<MolecularTypeOfReactionParticipant>();
        // ArrayList<ComponentOfMolecularTypeOfReactionParticipant> currentComponentOfProductElementsOfReaction = new ArrayList<ComponentOfMolecularTypeOfReactionParticipant>();
        // currentMappingOfReactionParticipants.clear();
        // reactionProductBondSites.clear();
        // reactionReactantBondSites.clear();
        // 
        // Element reactionRuleElement = new Element("ReactionRule");
        // String reactionRuleID = "RR" + (reactionRuleIndex + 1);
        // reactionRuleElement.setAttribute("id",reactionRuleID);
        // reactionRuleElement.setAttribute("name",particleJumpProcess.getName());
        // reactionRuleElement.setAttribute("symmetry_factor","1");
        // reactionRule.resolveBonds();
        // 
        // ArrayList<VolumeParticleSpeciesPattern> selectedPatterns = new ArrayList<VolumeParticleSpeciesPattern>();
        // for (ParticleVariable particleVariable : particleJumpProcess.getParticleVariables()){
        // if (!(particleVariable instanceof VolumeParticleSpeciesPattern)){
        // throw new SolverException("expecting only "+VolumeParticleSpeciesPattern.class.getSimpleName()+"s for "+ParticleJumpProcess.class.getSimpleName()+" "+particleJumpProcess.getName());
        // }
        // selectedPatterns.add((VolumeParticleSpeciesPattern) particleVariable);
        // }
        // ArrayList<VolumeParticleSpeciesPattern> createdPatterns = new ArrayList<VolumeParticleSpeciesPattern>();
        // HashSet<VolumeParticleSpeciesPattern> destroyedPatterns = new HashSet<VolumeParticleSpeciesPattern>();
        // for (Action action : particleJumpProcess.getActions()){
        // if (!(action.getVar() instanceof VolumeParticleSpeciesPattern)){
        // throw new SolverException("expecting only "+VolumeParticleSpeciesPattern.class.getSimpleName()+"s for "+ParticleJumpProcess.class.getSimpleName()+" "+particleJumpProcess.getName());
        // }
        // if (action.getOperation().equals(Action.ACTION_CREATE)){
        // createdPatterns.add((VolumeParticleSpeciesPattern) action.getVar());
        // }else if (action.getOperation().equals(Action.ACTION_DESTROY)){
        // destroyedPatterns.add((VolumeParticleSpeciesPattern) action.getVar());
        // }else{
        // throw new RuntimeException("unexpected action operation "+action.getOperation()+" for jump process "+particleJumpProcess.getName());
        // }
        // }
        // 
        // Element listOfReactantPatternsElement = new Element("ListOfReactantPatterns");
        // for(int reactantPatternIndex=0; reactantPatternIndex < selectedPatterns.size(); reactantPatternIndex++) {
        // VolumeParticleSpeciesPattern reactantSpeciesPattern = selectedPatterns.get(reactantPatternIndex);
        // String reactantPatternID = "RP" + (reactantPatternIndex + 1);
        // patternReactantBondSites.clear();
        // Element reactantPatternElement = getReactionParticipantPattern1(reactionRuleID, reactantPatternID, reactantSpeciesPattern,
        // currentReactantElementsOfReaction, currentComponentOfReactantElementsOfReaction, "ReactantPattern");
        // listOfReactantPatternsElement.addContent(reactantPatternElement);
        // reactionReactantBondSites.addAll(patternReactantBondSites);
        // }
        // reactionRuleElement.addContent(listOfReactantPatternsElement);
        // 
        // Element listOfProductPatternsElement = new Element("ListOfProductPatterns");
        // ArrayList<VolumeParticleSpeciesPattern> productSpeciesPatterns = new ArrayList<VolumeParticleSpeciesPattern>(selectedPatterns);
        // productSpeciesPatterns.removeAll(destroyedPatterns);
        // productSpeciesPatterns.addAll(createdPatterns);
        // // for products, add all "created" species from Actions and all "particles" that are selected but not destroyed
        // for(int productPatternIndex=0; productPatternIndex < productSpeciesPatterns.size(); productPatternIndex++) {
        // VolumeParticleSpeciesPattern productSpeciesPattern = productSpeciesPatterns.get(productPatternIndex);
        // String productPatternID = "PP" + (productPatternIndex + 1);
        // patternProductBondSites.clear();
        // Element productPatternElement = getReactionParticipantPattern1(reactionRuleID, productPatternID, productSpeciesPattern,
        // currentProductElementsOfReaction, currentComponentOfProductElementsOfReaction, "ProductPattern");
        // listOfProductPatternsElement.addContent(productPatternElement);
        // reactionProductBondSites.addAll(patternProductBondSites);
        // }
        // reactionRuleElement.addContent(listOfProductPatternsElement);
        // <RateLaw id="RR1_RateLaw" type="Ele" totalrate="0">
        // <ListOfRateConstants>
        // <RateConstant value="kon"/>
        // </ListOfRateConstants>
        // </RateLaw>
        Element rateLawElement = new Element("RateLaw");
        rateLawElement.setAttribute("id", RuleAnalysis.getID(rule));
        String rateConstantValue = null;
        JumpProcessRateDefinition particleProbabilityRate = particleJumpProcess.getParticleRateDefinition();
        if (particleProbabilityRate.getExpressions().length > 0) {
            JumpProcessRateDefinition particleRateDefinition = particleJumpProcess.getParticleRateDefinition();
            Expression expression = null;
            if (particleRateDefinition instanceof MacroscopicRateConstant) {
                expression = ((MacroscopicRateConstant) particleProbabilityRate).getExpression();
            } else {
                throw new SolverException("ParticleRateDefinition type " + particleRateDefinition.getClass().getSimpleName() + " not supported");
            }
            rateConstantValue = expression.infixBng();
            // all rates constants are being flattened and given reserved names
            Expression substitutedValExpr = null;
            try {
                substitutedValExpr = simulationSymbolTable.substituteFunctions(expression);
            } catch (MathException | ExpressionException e) {
                e.printStackTrace(System.out);
                throw new SolverException("ParticleJumpProcess " + particleJumpProcess.getName() + " substitution failed : exp = \"" + expression.infix() + "\": " + e.getMessage());
            }
            Double value = null;
            try {
                value = substitutedValExpr.evaluateConstant();
                Element parameterElement = new Element("Parameter");
                String id = "K_reserved_" + reactionRuleIndex;
                parameterElement.setAttribute("id", id);
                if (value != null) {
                    parameterElement.setAttribute("type", "Constant");
                    parameterElement.setAttribute("value", value.toString());
                    parameterElement.addContent(new Comment(rateConstantValue));
                    rateConstantValue = id;
                    listOfParametersElement.addContent(parameterElement);
                }
            } catch (ExpressionException e) {
                System.out.println("ParticleJumpProcess " + particleJumpProcess.getName() + " = " + substitutedValExpr.infix() + " does not have a constant value");
            }
        }
        if (isFunction(rateConstantValue, clonedMathDesc, simulationSymbolTable)) {
            rateLawElement.setAttribute("type", "Function");
            rateLawElement.setAttribute("totalrate", "0");
            rateLawElement.setAttribute("name", rateConstantValue);
        } else {
            rateLawElement.setAttribute("type", "Ele");
            rateLawElement.setAttribute("totalrate", "0");
            Element listOfRateConstantsElement = new Element("ListOfRateConstants");
            Element rateConstantElement = new Element("RateConstant");
            // System.out.println(" --- " + particleJumpProcess.getParticleRateDefinition().getExpressions());
            if (particleProbabilityRate.getExpressions().length > 0) {
                rateConstantElement.setAttribute("value", rateConstantValue);
            }
            listOfRateConstantsElement.addContent(rateConstantElement);
            rateLawElement.addContent(listOfRateConstantsElement);
        }
        reactionRuleElement.addContent(rateLawElement);
        // //  <Map>
        // //    <MapItem sourceID="RR1_RP1_M1" targetID="RR1_PP1_M1"/>
        // //    <MapItem sourceID="RR1_RP1_M1_C1" targetID="RR1_PP1_M1_C1"/>
        // //    <MapItem sourceID="RR1_RP1_M1_C2" targetID="RR1_PP1_M1_C2"/>
        // //    <MapItem sourceID="RR1_RP2_M1" targetID="RR1_PP1_M2"/>
        // //    <MapItem sourceID="RR1_RP2_M1_C1" targetID="RR1_PP1_M2_C1"/>
        // //  </Map>
        // Element mapElement = new Element("Map");
        // System.out.println("----------------------------------------------------------------------");
        // for(MolecularTypeOfReactionParticipant p : currentReactantElementsOfReaction) {
        // System.out.println(p.moleculeName + ", " + p.elementID);
        // }
        // for(ComponentOfMolecularTypeOfReactionParticipant c : currentComponentOfReactantElementsOfReaction) {
        // System.out.println(c.moleculeName + ", " + c.componentName + ", " + c.elementID);
        // }
        // System.out.println("----------------------------------------------------------------------");
        // for(MolecularTypeOfReactionParticipant p : currentProductElementsOfReaction) {
        // System.out.println(p.moleculeName + ", " + p.elementID);
        // }
        // for(ComponentOfMolecularTypeOfReactionParticipant c : currentComponentOfProductElementsOfReaction) {
        // System.out.println(c.moleculeName + ", " + c.componentName + ", " + c.elementID);
        // }
        // System.out.println("----------------------------------------------------------------------");
        // 
        // List<MolecularTypeOfReactionParticipant> cloneOfReactants = new ArrayList<MolecularTypeOfReactionParticipant>(currentReactantElementsOfReaction);
        // List<MolecularTypeOfReactionParticipant> cloneOfProducts = new ArrayList<MolecularTypeOfReactionParticipant>(currentProductElementsOfReaction);
        // for(Iterator<MolecularTypeOfReactionParticipant> itReactant = cloneOfReactants.iterator(); itReactant.hasNext();) {	// participants
        // MolecularTypeOfReactionParticipant reactant = itReactant.next();
        // boolean foundProduct = false;
        // for(Iterator<MolecularTypeOfReactionParticipant> itProduct = cloneOfProducts.iterator(); itProduct.hasNext();) {
        // MolecularTypeOfReactionParticipant product = itProduct.next();
        // if(reactant.find(product)) {
        // MappingOfReactionParticipants m = new MappingOfReactionParticipants(reactant.elementID, product.elementID, "");
        // currentMappingOfReactionParticipants.add(m );
        // itProduct.remove();
        // foundProduct = true;
        // break;		// we exit inner loop if we find a match for current reactant
        // }
        // }
        // if(foundProduct == false) {
        // System.out.println("Did not found a match for reactant " + reactant.moleculeName + ", " + reactant.elementID);
        // }
        // itReactant.remove();		// found or not, we remove the reactant
        // }
        // if(!currentProductElementsOfReaction.isEmpty()) {
        // for(MolecularTypeOfReactionParticipant p : currentProductElementsOfReaction) {
        // System.out.println("Did not found a match for product " + p.moleculeName + ", " + p.elementID);
        // }
        // }
        // for(Iterator<ComponentOfMolecularTypeOfReactionParticipant> itReactant = currentComponentOfReactantElementsOfReaction.iterator(); itReactant.hasNext();) {	// components
        // ComponentOfMolecularTypeOfReactionParticipant reactant = itReactant.next();
        // boolean foundProduct = false;
        // for(Iterator<ComponentOfMolecularTypeOfReactionParticipant> itProduct = currentComponentOfProductElementsOfReaction.iterator(); itProduct.hasNext();) {
        // ComponentOfMolecularTypeOfReactionParticipant product = itProduct.next();
        // String state = "";
        // if(reactant.find(product)) {
        // if(!reactant.state.equals(product.state)) {
        // state = product.state;
        // }
        // MappingOfReactionParticipants m = new MappingOfReactionParticipants(reactant.elementID, product.elementID, state);
        // currentMappingOfReactionParticipants.add(m );
        // itProduct.remove();
        // foundProduct = true;
        // break;		// we exit inner loop if we find a match for current reactant
        // }
        // }
        // if(foundProduct == false) {
        // System.out.println("Did not found a match for reactant " + reactant.moleculeName + ", " + reactant.elementID);
        // }
        // itReactant.remove();		// found or not, we remove the reactant
        // }
        // if(!currentComponentOfProductElementsOfReaction.isEmpty()) {
        // for(ComponentOfMolecularTypeOfReactionParticipant p : currentComponentOfProductElementsOfReaction) {
        // System.out.println("Did not found a match for product " + p.moleculeName + ", " + p.elementID);
        // }
        // }
        // for(Iterator<MappingOfReactionParticipants> it = currentMappingOfReactionParticipants.iterator(); it.hasNext();) {
        // MappingOfReactionParticipants m = it.next();
        // Element mapItemElement = new Element("MapItem");
        // mapItemElement.setAttribute("sourceID", m.reactantElementID);
        // mapItemElement.setAttribute("targetID", m.productElementID);
        // mapElement.addContent(mapItemElement);
        // }
        // reactionRuleElement.addContent(mapElement);
        // 
        // //  <ListOfOperations>
        // //      <AddBond site1="RR1_RP1_M1_C1" site2="RR1_RP2_M1_C1"/>
        // //		<StateChange site="RR0_RP0_M0_C2" finalState="Y"/>
        // //  </ListOfOperations>
        // Element listOfOperationsElement = new Element("ListOfOperations");
        // 
        // // AddBond elements
        // // add any bond in the product which is not present in the reactant
        // Iterator<BondSites> it = patternProductBondSites.iterator();
        // while (it.hasNext()) {
        // BondSites bs = it.next();
        // String reactantS1 = MappingOfReactionParticipants.findMatchingReactant(bs.component1, currentMappingOfReactionParticipants);
        // String reactantS2 = MappingOfReactionParticipants.findMatchingReactant(bs.component2, currentMappingOfReactionParticipants);
        // // we check if the bonds in the product existed already in the reactant, in which case they were not "added" in this reaction
        // BondSites candidate = new BondSites(reactantS1, reactantS2);
        // boolean preExistent = false;
        // for(BondSites bsReactant : reactionReactantBondSites) {
        // if(bsReactant.equals(candidate)) {
        // preExistent = true;
        // break;
        // }
        // }
        // if(preExistent == true) {
        // continue;		// we don't add preexisting bonds
        // }
        // Element addBondElement = new Element("AddBond");
        // addBondElement.setAttribute("site1", reactantS1);
        // addBondElement.setAttribute("site2", reactantS2);
        // listOfOperationsElement.addContent(addBondElement);
        // }
        // // StateChange elements
        // for(Iterator<MappingOfReactionParticipants> it1 = currentMappingOfReactionParticipants.iterator(); it1.hasNext();) {
        // MappingOfReactionParticipants m = it1.next();
        // if(!m.componentFinalState.equals("")) {		// state has changed if it's different from ""
        // Element stateChangeElement = new Element("StateChange");
        // stateChangeElement.setAttribute("site", m.reactantElementID);
        // stateChangeElement.setAttribute("finalState", m.componentFinalState);
        // listOfOperationsElement.addContent(stateChangeElement);
        // }
        // }
        // // eliminate all the common entries (molecule types) in reactants and products
        // // what's left in reactants was deleted, what's left in products was added
        // List<MolecularTypeOfReactionParticipant> commonParticipants = new ArrayList<MolecularTypeOfReactionParticipant>();
        // for(Iterator<MolecularTypeOfReactionParticipant> itReactant = currentReactantElementsOfReaction.iterator(); itReactant.hasNext();) {	// participants
        // MolecularTypeOfReactionParticipant reactant = itReactant.next();
        // for(Iterator<MolecularTypeOfReactionParticipant> itProduct = currentProductElementsOfReaction.iterator(); itProduct.hasNext();) {
        // MolecularTypeOfReactionParticipant product = itProduct.next();
        // if(reactant.find(product)) {
        // // commonParticipants contains the reactant molecules with a equivalent molecule in the product (meaning they are not in the "Deleted" category)
        // commonParticipants.add(reactant);
        // itReactant.remove();
        // itProduct.remove();
        // break;		// we exit inner loop if we find a match for current reactant
        // }
        // }
        // }
        // // DeleteBond element
        // // there is no need to mention deletion of bond if the particleSpeciesPattern
        // // or the MolecularType involved in the bond are deleted as well
        // // We only keep those "Deleted" bonds which belong to the molecules (of the reactant) present in commonParticipants
        // // Both components (sites) of the bond need to have their molecules in commonParticipants
        // boolean foundMoleculeForComponent1 = false;
        // boolean foundMoleculeForComponent2 = false;
        // HashSet<BondSites> cloneOfReactantBondSites = new HashSet<BondSites>(patternReactantBondSites);
        // Iterator<BondSites> itbs = cloneOfReactantBondSites.iterator();
        // while (itbs.hasNext()) {
        // BondSites bs = itbs.next();
        // String bondComponent1MoleculeId = BondSites.extractMoleculeId(bs.component1);
        // String bondComponent2MoleculeId = BondSites.extractMoleculeId(bs.component2);
        // for(MolecularTypeOfReactionParticipant commonReactionMoleculeule : commonParticipants) {
        // String commonReactantPatternId = commonReactionMoleculeule.elementID;
        // if(bondComponent1MoleculeId.equals(commonReactantPatternId)) {
        // foundMoleculeForComponent1 = true;
        // }
        // if(bondComponent2MoleculeId.equals(commonReactantPatternId)) {
        // foundMoleculeForComponent2 = true;
        // }
        // }
        // if(!foundMoleculeForComponent1 || !foundMoleculeForComponent2) {
        // // at least one of bond's molecule is not in common, hence we don't need to report the deletion of this bond
        // itbs.remove();
        // }
        // }
        // // the clone has now all the deleted bonds whose molecules have not been deleted
        // itbs = cloneOfReactantBondSites.iterator();
        // while (itbs.hasNext()) {
        // BondSites bs = itbs.next();
        // Element addBondElement = new Element("DeleteBond");
        // addBondElement.setAttribute("site1", bs.component1);
        // addBondElement.setAttribute("site2", bs.component2);
        // listOfOperationsElement.addContent(addBondElement);
        // }
        // // Add MolecularType element
        // for(MolecularTypeOfReactionParticipant molecule : currentProductElementsOfReaction) {
        // System.out.println("created molecule: " + molecule.elementID + "' " + molecule.moleculeName);
        // Element addMolecularTypePatternElement = new Element("Add");
        // addMolecularTypePatternElement.setAttribute("id", molecule.elementID);
        // listOfOperationsElement.addContent(addMolecularTypePatternElement);
        // }
        // // Delete MolecularType element
        // // if the reactant pattern of the molecule being deleted still exists as part of the common, then we only delete the molecule
        // // if the reactant pattern of the molecule being deleted is not as part of the common, then it's gone completely and we delete the reactant pattern
        // ArrayList<String> patternsToDelete = new ArrayList<String>();
        // for(MolecularTypeOfReactionParticipant molecule : currentReactantElementsOfReaction) {
        // String reactantPatternId = molecule.extractReactantPatternId();
        // boolean found = false;
        // for(MolecularTypeOfReactionParticipant common : commonParticipants) {
        // String commonId = common.extractReactantPatternId();
        // if(reactantPatternId.equals(commonId)) {
        // found = true;
        // break;		// some other molecule of this pattern still there, we don't delete the pattern
        // }
        // }
        // if(found == true) {		// some other molecule of this pattern still there, we don't delete the pattern
        // System.out.println("deleted molecule: " + molecule.elementID + "' " + molecule.moleculeName);
        // Element addMolecularTypePatternElement = new Element("Delete");
        // addMolecularTypePatternElement.setAttribute("id", molecule.elementID);
        // addMolecularTypePatternElement.setAttribute("DeleteMolecules", "0");
        // listOfOperationsElement.addContent(addMolecularTypePatternElement);
        // } else {				// no molecule of this pattern left, we delete the pattern
        // if(patternsToDelete.contains(reactantPatternId)) {
        // // nothing to do, we're already deleting this pattern
        // break;
        // } else {
        // patternsToDelete.add(reactantPatternId);
        // System.out.println("deleted pattern: " + reactantPatternId);
        // Element addParticleSpeciesPatternElement = new Element("Delete");
        // addParticleSpeciesPatternElement.setAttribute("id", reactantPatternId);
        // addParticleSpeciesPatternElement.setAttribute("DeleteMolecules", "0");
        // listOfOperationsElement.addContent(addParticleSpeciesPatternElement);
        // }
        // }
        // }
        // reactionRuleElement.addContent(listOfOperationsElement);
        listOfReactionRules.addContent(reactionRuleElement);
    }
    Element listOfObservablesElement = getListOfObservables(clonedMathDesc);
    Element listOfFunctionsElement = getListOfFunctions(clonedMathDesc, simulationSymbolTable);
    modelElement.addContent(listOfParametersElement);
    modelElement.addContent(listOfMoleculeTypesElement);
    modelElement.addContent(listOfSpeciesElement);
    modelElement.addContent(listOfReactionRules);
    modelElement.addContent(listOfObservablesElement);
    modelElement.addContent(listOfFunctionsElement);
    sbmlElement.addContent(modelElement);
    // //		return e1;
    return sbmlElement;
}
Also used : Action(cbit.vcell.math.Action) SimulationTask(cbit.vcell.messaging.server.SimulationTask) Variable(cbit.vcell.math.Variable) MathDescription(cbit.vcell.math.MathDescription) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ParticleMolecularComponent(cbit.vcell.math.ParticleMolecularComponent) ExpressionException(cbit.vcell.parser.ExpressionException) ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) MacroscopicRateConstant(cbit.vcell.math.MacroscopicRateConstant) MathRuleFactory(cbit.vcell.math.MathRuleFactory) ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) RuleAnalysisReport(org.vcell.model.rbm.RuleAnalysisReport) Comment(org.jdom.Comment) JumpProcessRateDefinition(cbit.vcell.math.JumpProcessRateDefinition) ParticleComponentStatePattern(cbit.vcell.math.ParticleComponentStatePattern) ParticleJumpProcess(cbit.vcell.math.ParticleJumpProcess) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) SolverException(cbit.vcell.solver.SolverException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) ParticleMolecularTypePattern(cbit.vcell.math.ParticleMolecularTypePattern) MathRuleEntry(cbit.vcell.math.MathRuleFactory.MathRuleEntry) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SolverException(cbit.vcell.solver.SolverException)

Example 7 with Comment

use of org.jdom.Comment in project OpenOLAT by OpenOLAT.

the class SequencerModel method init.

/**
 * Initilise this JDOM doc - adding comment and setting root node
 */
protected void init() {
    Document _model;
    Element root = new Element(ROOT_NODE_NAME);
    _model = new Document(root);
    for (int i = 0; i < scorm_comments.length; i++) {
        Comment comment = new Comment(scorm_comments[i]);
        _model.getContent().add(0, comment);
    }
    this.setDocument(_model);
}
Also used : Comment(org.jdom.Comment) Element(org.jdom.Element) XMLDocument(uk.ac.reload.jdom.XMLDocument) Document(org.jdom.Document)

Example 8 with Comment

use of org.jdom.Comment in project freemarker by apache.

the class NodeListModel method getType.

private TemplateModel getType() {
    if (nodes.size() == 0)
        return new SimpleScalar("");
    Object firstNode = nodes.get(0);
    char code;
    if (firstNode instanceof Element)
        code = 'e';
    else if (firstNode instanceof Text || firstNode instanceof String)
        code = 'x';
    else if (firstNode instanceof Attribute)
        code = 'a';
    else if (firstNode instanceof EntityRef)
        code = 'n';
    else if (firstNode instanceof Document)
        code = 'd';
    else if (firstNode instanceof DocType)
        code = 't';
    else if (firstNode instanceof Comment)
        code = 'c';
    else if (firstNode instanceof ProcessingInstruction)
        code = 'p';
    else
        code = '?';
    return new SimpleScalar(new String(new char[] { code }));
}
Also used : Comment(org.jdom.Comment) Attribute(org.jdom.Attribute) Element(org.jdom.Element) Text(org.jdom.Text) Document(org.jdom.Document) SimpleScalar(freemarker.template.SimpleScalar) EntityRef(org.jdom.EntityRef) DocType(org.jdom.DocType) ProcessingInstruction(org.jdom.ProcessingInstruction)

Example 9 with Comment

use of org.jdom.Comment in project dna by leifeld.

the class Exporter method exportGraphml.

/**
 * Export filter for graphML files.
 *
 * @param matrix                 Input {@link Matrix}.
 * @param twoMode                Indicates whether the network is a two-mode network.
 * @param statementType          The statement type on which the network is based.
 * @param outfile                Name of the output file.
 * @param var1                   Name of the first variable (the rows of the matrix).
 * @param var2                   Name of the second variable (the columns of the matrix).
 * @param frequencies1           The number of statements in which the row node is involved (after filtering).
 * @param frequencies2           The number of statements in which the column node is involved (after filtering).
 * @param attributes             An ArrayList of {@link AttributeVector}s containing all attribute vectors in the database.
 * @param qualifierAggregation   A String denoting the qualifier aggregation. Valid values are "ignore", "combine", "subtract", "congruence", and "conflict".
 * @param qualifierBinary        Indicates whether the qualifier is a binary variable.
 */
private void exportGraphml(Matrix mt, boolean twoMode, StatementType statementType, String outfile, String var1, String var2, int[] frequencies1, int[] frequencies2, ArrayList<AttributeVector> attributes, String qualifierAggregation, boolean qualifierBinary) {
    // extract attributes
    String[] rn = mt.getRownames();
    String[] cn = mt.getColnames();
    String[] names;
    String[] variables;
    int[] frequencies;
    if (twoMode == true) {
        names = new String[rn.length + cn.length];
        variables = new String[names.length];
        frequencies = new int[names.length];
    } else {
        names = new String[rn.length];
        variables = new String[rn.length];
        frequencies = new int[rn.length];
    }
    for (int i = 0; i < rn.length; i++) {
        names[i] = rn[i];
        variables[i] = var1;
        frequencies[i] = frequencies1[i];
    }
    if (twoMode == true) {
        for (int i = 0; i < cn.length; i++) {
            names[i + rn.length] = cn[i];
            variables[i + rn.length] = var2;
            frequencies[i + rn.length] = frequencies2[i];
        }
    }
    int[] id = new int[names.length];
    String[] color = new String[names.length];
    String[] type = new String[names.length];
    String[] alias = new String[names.length];
    String[] notes = new String[names.length];
    for (int i = 0; i < attributes.size(); i++) {
        if (attributes.get(i).getStatementTypeId() == statementType.getId() && attributes.get(i).getVariable().equals(var1)) {
            for (int j = 0; j < rn.length; j++) {
                if (rn[j].equals(attributes.get(i).getValue())) {
                    id[j] = attributes.get(i).getId();
                    color[j] = String.format("#%02X%02X%02X", attributes.get(i).getColor().getRed(), attributes.get(i).getColor().getGreen(), attributes.get(i).getColor().getBlue());
                    type[j] = attributes.get(i).getType();
                    alias[j] = attributes.get(i).getAlias();
                    notes[j] = attributes.get(i).getNotes();
                }
            }
        } else if (attributes.get(i).getStatementTypeId() == statementType.getId() && attributes.get(i).getVariable().equals(var2) && twoMode == true) {
            for (int j = 0; j < cn.length; j++) {
                if (cn[j].equals(attributes.get(i).getValue())) {
                    id[j + rn.length] = attributes.get(i).getId();
                    color[j + rn.length] = String.format("#%02X%02X%02X", attributes.get(i).getColor().getRed(), attributes.get(i).getColor().getGreen(), attributes.get(i).getColor().getBlue());
                    type[j + rn.length] = attributes.get(i).getType();
                    alias[j + rn.length] = attributes.get(i).getAlias();
                    notes[j + rn.length] = attributes.get(i).getNotes();
                }
            }
        }
    }
    // set up graph structure
    Namespace xmlns = Namespace.getNamespace("http://graphml.graphdrawing.org/xmlns");
    Element graphml = new Element("graphml", xmlns);
    Namespace visone = Namespace.getNamespace("visone", "http://visone.info/xmlns");
    graphml.addNamespaceDeclaration(visone);
    Namespace xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
    graphml.addNamespaceDeclaration(xsi);
    Namespace yNs = Namespace.getNamespace("y", "http://www.yworks.com/xml/graphml");
    graphml.addNamespaceDeclaration(yNs);
    Attribute attSchema = new Attribute("schemaLocation", "http://graphml.graphdrawing.org/xmlns/graphml http://www.yworks.com/xml/schema/graphml/1.0/ygraphml.xsd ", xsi);
    graphml.setAttribute(attSchema);
    org.jdom.Document document = new org.jdom.Document(graphml);
    Comment dataSchema = new Comment(" data schema ");
    graphml.addContent(dataSchema);
    Element keyVisoneNode = new Element("key", xmlns);
    keyVisoneNode.setAttribute(new Attribute("for", "node"));
    keyVisoneNode.setAttribute(new Attribute("id", "d0"));
    keyVisoneNode.setAttribute(new Attribute("yfiles.type", "nodegraphics"));
    graphml.addContent(keyVisoneNode);
    Element keyVisoneEdge = new Element("key", xmlns);
    keyVisoneEdge.setAttribute(new Attribute("for", "edge"));
    keyVisoneEdge.setAttribute(new Attribute("id", "e0"));
    keyVisoneEdge.setAttribute(new Attribute("yfiles.type", "edgegraphics"));
    graphml.addContent(keyVisoneEdge);
    Element keyVisoneGraph = new Element("key", xmlns);
    keyVisoneGraph.setAttribute(new Attribute("for", "graph"));
    keyVisoneGraph.setAttribute(new Attribute("id", "prop"));
    keyVisoneGraph.setAttribute(new Attribute("visone.type", "properties"));
    graphml.addContent(keyVisoneGraph);
    Element keyId = new Element("key", xmlns);
    keyId.setAttribute(new Attribute("id", "id"));
    keyId.setAttribute(new Attribute("for", "node"));
    keyId.setAttribute(new Attribute("attr.name", "id"));
    keyId.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyId);
    Element keyName = new Element("key", xmlns);
    keyName.setAttribute(new Attribute("id", "name"));
    keyName.setAttribute(new Attribute("for", "node"));
    keyName.setAttribute(new Attribute("attr.name", "name"));
    keyName.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyName);
    Element keyType = new Element("key", xmlns);
    keyType.setAttribute(new Attribute("id", "type"));
    keyType.setAttribute(new Attribute("for", "node"));
    keyType.setAttribute(new Attribute("attr.name", "type"));
    keyType.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyType);
    Element keyAlias = new Element("key", xmlns);
    keyAlias.setAttribute(new Attribute("id", "alias"));
    keyAlias.setAttribute(new Attribute("for", "node"));
    keyAlias.setAttribute(new Attribute("attr.name", "alias"));
    keyAlias.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyAlias);
    Element keyNote = new Element("key", xmlns);
    keyNote.setAttribute(new Attribute("id", "note"));
    keyNote.setAttribute(new Attribute("for", "node"));
    keyNote.setAttribute(new Attribute("attr.name", "note"));
    keyNote.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyNote);
    Element keyVariable = new Element("key", xmlns);
    keyVariable.setAttribute(new Attribute("id", "variable"));
    keyVariable.setAttribute(new Attribute("for", "node"));
    keyVariable.setAttribute(new Attribute("attr.name", "variable"));
    keyVariable.setAttribute(new Attribute("attr.type", "string"));
    graphml.addContent(keyVariable);
    Element keyFrequency = new Element("key", xmlns);
    keyFrequency.setAttribute(new Attribute("id", "frequency"));
    keyFrequency.setAttribute(new Attribute("for", "node"));
    keyFrequency.setAttribute(new Attribute("attr.name", "frequency"));
    keyFrequency.setAttribute(new Attribute("attr.type", "int"));
    graphml.addContent(keyFrequency);
    Element keyWeight = new Element("key", xmlns);
    keyWeight.setAttribute(new Attribute("id", "weight"));
    keyWeight.setAttribute(new Attribute("for", "edge"));
    keyWeight.setAttribute(new Attribute("attr.name", "weight"));
    keyWeight.setAttribute(new Attribute("attr.type", "double"));
    graphml.addContent(keyWeight);
    Element graphElement = new Element("graph", xmlns);
    graphElement.setAttribute(new Attribute("edgedefault", "undirected"));
    graphElement.setAttribute(new Attribute("id", "DNA"));
    int numEdges = rn.length * cn.length;
    if (twoMode == false) {
        numEdges = (numEdges / 2) - rn.length;
    }
    int numNodes = rn.length;
    if (twoMode == true) {
        numNodes = numNodes + cn.length;
    }
    graphElement.setAttribute(new Attribute("parse.edges", String.valueOf(numEdges)));
    graphElement.setAttribute(new Attribute("parse.nodes", String.valueOf(numNodes)));
    graphElement.setAttribute(new Attribute("parse.order", "free"));
    Element properties = new Element("data", xmlns);
    properties.setAttribute(new Attribute("key", "prop"));
    Element labelAttribute = new Element("labelAttribute", visone);
    labelAttribute.setAttribute("edgeLabel", "weight");
    labelAttribute.setAttribute("nodeLabel", "name");
    properties.addContent(labelAttribute);
    graphElement.addContent(properties);
    // add nodes
    Comment nodes = new Comment(" nodes ");
    graphElement.addContent(nodes);
    for (int i = 0; i < names.length; i++) {
        Element node = new Element("node", xmlns);
        node.setAttribute(new Attribute("id", "n" + id[i]));
        Element idElement = new Element("data", xmlns);
        idElement.setAttribute(new Attribute("key", "id"));
        idElement.setText(String.valueOf(id[i]));
        node.addContent(idElement);
        Element nameElement = new Element("data", xmlns);
        nameElement.setAttribute(new Attribute("key", "name"));
        nameElement.setText(names[i]);
        node.addContent(nameElement);
        Element typeElement = new Element("data", xmlns);
        typeElement.setAttribute(new Attribute("key", "type"));
        typeElement.setText(type[i]);
        node.addContent(typeElement);
        Element aliasElement = new Element("data", xmlns);
        aliasElement.setAttribute(new Attribute("key", "alias"));
        aliasElement.setText(alias[i]);
        node.addContent(aliasElement);
        Element notesElement = new Element("data", xmlns);
        notesElement.setAttribute(new Attribute("key", "notes"));
        notesElement.setText(notes[i]);
        node.addContent(notesElement);
        Element variableElement = new Element("data", xmlns);
        variableElement.setAttribute(new Attribute("key", "variable"));
        variableElement.setText(variables[i]);
        node.addContent(variableElement);
        Element frequency = new Element("data", xmlns);
        frequency.setAttribute(new Attribute("key", "frequency"));
        frequency.setText(String.valueOf(frequencies[i]));
        node.addContent(frequency);
        Element vis = new Element("data", xmlns);
        vis.setAttribute(new Attribute("key", "d0"));
        Element visoneShapeNode = new Element("shapeNode", visone);
        Element yShapeNode = new Element("ShapeNode", yNs);
        Element geometry = new Element("Geometry", yNs);
        geometry.setAttribute(new Attribute("height", "20.0"));
        geometry.setAttribute(new Attribute("width", "20.0"));
        geometry.setAttribute(new Attribute("x", String.valueOf(Math.random() * 800)));
        geometry.setAttribute(new Attribute("y", String.valueOf(Math.random() * 600)));
        yShapeNode.addContent(geometry);
        Element fill = new Element("Fill", yNs);
        fill.setAttribute(new Attribute("color", color[i]));
        fill.setAttribute(new Attribute("transparent", "false"));
        yShapeNode.addContent(fill);
        Element borderStyle = new Element("BorderStyle", yNs);
        borderStyle.setAttribute(new Attribute("color", "#000000"));
        borderStyle.setAttribute(new Attribute("type", "line"));
        borderStyle.setAttribute(new Attribute("width", "1.0"));
        yShapeNode.addContent(borderStyle);
        Element nodeLabel = new Element("NodeLabel", yNs);
        nodeLabel.setAttribute(new Attribute("alignment", "center"));
        nodeLabel.setAttribute(new Attribute("autoSizePolicy", "content"));
        nodeLabel.setAttribute(new Attribute("backgroundColor", "#FFFFFF"));
        nodeLabel.setAttribute(new Attribute("fontFamily", "Dialog"));
        nodeLabel.setAttribute(new Attribute("fontSize", "12"));
        nodeLabel.setAttribute(new Attribute("fontStyle", "plain"));
        nodeLabel.setAttribute(new Attribute("hasLineColor", "false"));
        nodeLabel.setAttribute(new Attribute("height", "19.0"));
        nodeLabel.setAttribute(new Attribute("modelName", "eight_pos"));
        nodeLabel.setAttribute(new Attribute("modelPosition", "n"));
        nodeLabel.setAttribute(new Attribute("textColor", "#000000"));
        nodeLabel.setAttribute(new Attribute("visible", "true"));
        nodeLabel.setText(names[i]);
        yShapeNode.addContent(nodeLabel);
        Element shape = new Element("Shape", yNs);
        if (i < rn.length) {
            shape.setAttribute(new Attribute("type", "ellipse"));
        } else {
            shape.setAttribute(new Attribute("type", "roundrectangle"));
        }
        yShapeNode.addContent(shape);
        visoneShapeNode.addContent(yShapeNode);
        vis.addContent(visoneShapeNode);
        node.addContent(vis);
        graphElement.addContent(node);
    }
    // add edges
    double[][] m = mt.getMatrix();
    Comment edges = new Comment(" edges ");
    graphElement.addContent(edges);
    for (int i = 0; i < rn.length; i++) {
        for (int j = 0; j < cn.length; j++) {
            if (m[i][j] != 0.0 && (twoMode == true || (twoMode == false && i < j))) {
                // only lower triangle is used for one-mode networks
                Element edge = new Element("edge", xmlns);
                int currentId = id[i];
                edge.setAttribute(new Attribute("source", "n" + String.valueOf(currentId)));
                if (twoMode == true) {
                    currentId = id[j + rn.length];
                } else {
                    currentId = id[j];
                }
                edge.setAttribute(new Attribute("target", "n" + String.valueOf(currentId)));
                Element weight = new Element("data", xmlns);
                weight.setAttribute(new Attribute("key", "weight"));
                weight.setText(String.valueOf(m[i][j]));
                edge.addContent(weight);
                Element visEdge = new Element("data", xmlns);
                visEdge.setAttribute("key", "e0");
                Element visPolyLineEdge = new Element("polyLineEdge", visone);
                Element yPolyLineEdge = new Element("PolyLineEdge", yNs);
                Element yLineStyle = new Element("LineStyle", yNs);
                if (qualifierAggregation.equals("combine") && qualifierBinary == true) {
                    if (m[i][j] == 1.0) {
                        yLineStyle.setAttribute("color", "#00ff00");
                    } else if (m[i][j] == 2.0) {
                        yLineStyle.setAttribute("color", "#ff0000");
                    } else if (m[i][j] == 3.0) {
                        yLineStyle.setAttribute("color", "#0000ff");
                    }
                } else if (qualifierAggregation.equals("subtract")) {
                    if (m[i][j] < 0) {
                        yLineStyle.setAttribute("color", "#ff0000");
                    } else if (m[i][j] > 0) {
                        yLineStyle.setAttribute("color", "#00ff00");
                    }
                } else if (qualifierAggregation.equals("conflict")) {
                    yLineStyle.setAttribute("color", "#ff0000");
                } else if (qualifierAggregation.equals("congruence")) {
                    yLineStyle.setAttribute("color", "#00ff00");
                } else {
                    yLineStyle.setAttribute("color", "#000000");
                }
                yLineStyle.setAttribute(new Attribute("type", "line"));
                yLineStyle.setAttribute(new Attribute("width", "2.0"));
                yPolyLineEdge.addContent(yLineStyle);
                visPolyLineEdge.addContent(yPolyLineEdge);
                visEdge.addContent(visPolyLineEdge);
                edge.addContent(visEdge);
                graphElement.addContent(edge);
            }
        }
    }
    graphml.addContent(graphElement);
    // write to file
    File dnaFile = new File(outfile);
    try {
        FileOutputStream outStream = new FileOutputStream(dnaFile);
        XMLOutputter outToFile = new XMLOutputter();
        Format format = Format.getPrettyFormat();
        format.setEncoding("utf-8");
        outToFile.setFormat(format);
        outToFile.output(document, outStream);
        outStream.flush();
        outStream.close();
    } catch (IOException e) {
        System.err.println("Cannot save \"" + dnaFile + "\":" + e.getMessage());
    }
}
Also used : Comment(org.jdom.Comment) XMLOutputter(org.jdom.output.XMLOutputter) Attribute(org.jdom.Attribute) Element(org.jdom.Element) IOException(java.io.IOException) Document(dna.dataStructures.Document) Namespace(org.jdom.Namespace) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) Format(org.jdom.output.Format) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 10 with Comment

use of org.jdom.Comment in project vcell by virtualcell.

the class XmlHelper method geometryToXML.

static String geometryToXML(Geometry geometry, boolean printkeys) throws XmlParseException {
    String geometryString = null;
    if (geometry == null) {
        throw new XmlParseException("Invalid input for Geometry: " + geometry);
    }
    // NEW WAY, with XML declaration, vcml element, namespace, version #, etc.
    // create the root vcml element
    Element vcmlElement = new Element(XMLTags.VcmlRootNodeTag);
    vcmlElement.setAttribute(XMLTags.VersionTag, getEscapedSoftwareVersion());
    // get the geometry element from xmlProducer
    Xmlproducer xmlProducer = new Xmlproducer(printkeys);
    Element geometryElement = xmlProducer.getXML(geometry);
    // add it to root vcml element
    vcmlElement.addContent(geometryElement);
    // set default namespace for vcmlElemebt
    vcmlElement = XmlUtil.setDefaultNamespace(vcmlElement, Namespace.getNamespace(XMLTags.VCML_NS));
    // create xml doc using vcml root element and convert to string
    Document geoDoc = new Document();
    Comment docComment = new Comment("This geometry was generated in VCML Version " + getEscapedSoftwareVersion());
    geoDoc.addContent(docComment);
    geoDoc.setRootElement(vcmlElement);
    geometryString = XmlUtil.xmlToString(geoDoc, false);
    return geometryString;
}
Also used : Comment(org.jdom.Comment) Element(org.jdom.Element) Document(org.jdom.Document) VCDocument(org.vcell.util.document.VCDocument)

Aggregations

Comment (org.jdom.Comment)13 Element (org.jdom.Element)13 Document (org.jdom.Document)10 XMLDocument (uk.ac.reload.jdom.XMLDocument)4 Attribute (org.jdom.Attribute)3 VCDocument (org.vcell.util.document.VCDocument)3 ExpressionException (cbit.vcell.parser.ExpressionException)2 IOException (java.io.IOException)2 EntityRef (org.jdom.EntityRef)2 Namespace (org.jdom.Namespace)2 Text (org.jdom.Text)2 Action (cbit.vcell.math.Action)1 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)1 JumpProcessRateDefinition (cbit.vcell.math.JumpProcessRateDefinition)1 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)1 MathDescription (cbit.vcell.math.MathDescription)1 MathException (cbit.vcell.math.MathException)1 MathRuleFactory (cbit.vcell.math.MathRuleFactory)1 MathRuleEntry (cbit.vcell.math.MathRuleFactory.MathRuleEntry)1 ParticleComponentStateDefinition (cbit.vcell.math.ParticleComponentStateDefinition)1