From: Peter Murray-R. <pe...@us...> - 2005-11-30 15:51:26
|
Update of /cvsroot/cml/jumbo50/src/org/xmlcml/cml/element In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20453/src/org/xmlcml/cml/element Modified Files: CMLReaction.java Added Files: CMLAtom.java-1 CMLAttributeList.java CMLNodeFactory.java CMLTypeList.java Removed Files: ProductReactant.java ProductReactantList.java Log Message: refactored reactions and forward references from elements to tools --- NEW FILE: CMLAttributeList.java --- package org.xmlcml.cml.element; import java.util.Map; import java.util.HashMap; import java.util.logging.Logger; import org.xmlcml.cml.base.CMLException; import org.xmlcml.cml.base.CMLAttribute; import org.xmlcml.cml.base.StringAttribute; import org.xmlcml.cml.base.StringArrayAttribute; import org.xmlcml.cml.base.IntAttribute; import org.xmlcml.cml.base.IntArrayAttribute; import org.xmlcml.cml.base.DoubleAttribute; import org.xmlcml.cml.base.DoubleArrayAttribute; import nu.xom.Attribute; /** user-modifiable class supporting CMLAttributeList. * * autogenerated from schema * use as a shell which can be edited [...1747 lines suppressed...] * @return Attribute */ public static Attribute makeAttributeFromGroupName(String attributeGroupName, String value, String URI) throws CMLException { CMLAttribute attribute = CMLAttribute.createSubclassedAttribute(CMLAttributeList.getAttribute(attributeGroupName), value); if (attribute != null) { attribute.setCMLValue(value); } return attribute; } /** get summary. * * @return String */ public String getSummary() { return ""; } } --- NEW FILE: CMLAtom.java-1 --- package org.xmlcml.cml.element; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; import jumbo.euclid.Angle; import jumbo.euclid.EuclidException; import jumbo.euclid.Point3; import jumbo.euclid.Real2; import jumbo.euclid.Transform2; import jumbo.euclid.Transform3; import jumbo.euclid.Vector2; import jumbo.euclid.Vector3; import nu.xom.Element; import nu.xom.Node; [...1810 lines suppressed...] newLigands[count++] = heaviestAtom; newLigandVector.remove(heaviest); } return newLigands; } private int getHeaviestAtom(List<CMLAtom> newAtomVector) { int heaviestAtNum = -1; int heaviest = -1; for (int i = 0; i < newAtomVector.size(); i++) { CMLAtom atom = newAtomVector.get(i); int atnum = atom.getAtomicNumber(); if (atnum > heaviestAtNum) { heaviest = i; heaviestAtNum = atnum; } } return heaviest; } } --- ProductReactant.java DELETED --- --- ProductReactantList.java DELETED --- --- NEW FILE: CMLTypeList.java --- package org.xmlcml.cml.element; import java.util.Map; import java.util.HashMap; import java.util.logging.Logger; import org.xmlcml.cml.base.CMLException; import org.xmlcml.cml.base.CMLType; /** NON-modifiable class supporting CMLTypeList. * * autogenerated from schema * DO NOT EDIT!! */ public class CMLTypeList { // fields; // map of types by type name public static Map<String, CMLType> typeMap = new HashMap<String, CMLType>(); [...1002 lines suppressed...] st.setBase("xsd:string"); st.setId("st.elementTypeArrayType"); st.setSummary("An array of elementTypes."); st.setDescription("Instances of this type will be used in array-style representation of atoms."); st.setIsList(true); typeMap.put("elementTypeArrayType", st); //----type-------maxType---------- st = new CMLType(); namex = "maxType"; st.setName(namex); st.setBase("xsd:string"); st.setId("st.maxType"); st.setSummary("The maximum INCLUSIVE value of a quantity."); st.setDescription("\n The maximum INCLUSIVE value of a sortable quantity such as\n numeric, date or string. It should be ignored for dataTypes such as URL. \nThe use of min and\n max attributes can be used to give a range for the quantity.\n The statistical basis of this range is not defined. The value of max \nis usually an observed \nquantity (or calculated from observations). To restrict a value, the \nmaxExclusive type in a dictionary should be used.\n The type of the maximum is the same as the quantity to which it refers - numeric,\n date and string are currently allowed"); typeMap.put("maxType", st); } catch (CMLException e) { logger.severe("bug"+e); } }; } Index: CMLReaction.java =================================================================== RCS file: /cvsroot/cml/jumbo50/src/org/xmlcml/cml/element/CMLReaction.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** CMLReaction.java 29 Nov 2005 08:41:04 -0000 1.15 --- CMLReaction.java 30 Nov 2005 15:51:14 -0000 1.16 *************** *** 1,7 **** package org.xmlcml.cml.element; - import java.io.IOException; - import java.io.StringWriter; - import java.io.Writer; import java.util.ArrayList; import java.util.List; --- 1,4 ---- *************** *** 117,203 **** /** - * output and analyse aggregate formula for products and reactants. - * - * - * @param w - * the output writer - * @throws CMLException - * @throws IOException - */ - public void outputBalance(Writer w) throws CMLException, IOException { - CMLReactantList reactantList = (CMLReactantList) this - .getFirstCMLChild(CMLReactantList.TAG); - CMLFormula reactantFormula = null; - if (reactantList != null) { - reactantFormula = ProductReactantList.getAggregateFormula(reactantList); - w.write(reactantFormula.getFormattedString()); - } else { - w.write("Null reactantList"); - } - w.write(" = "); - - CMLProductList productList = (CMLProductList) this - .getFirstCMLChild(CMLProductList.TAG); - if (productList != null) { - CMLFormula productFormula = ProductReactantList.getAggregateFormula(productList); - w.write(productFormula.getFormattedString()); - - w.write(" ; difference: "); - - String differenceFormula = reactantFormula - .getDifference(productFormula); - w.write(differenceFormula); - } else { - w.write("Null productList"); - } - } - - /** - * output simple inline version of reaction. - * - * of form "C2H4 + H2O = C2H6O" without newline - * - * @param w - * the output writer - * @throws CMLException - * @throws IOException - */ - public void outputReaction(Writer w) throws CMLException, IOException { - CMLReactantList reactantList = (CMLReactantList) this.getFirstCMLChild(CMLReactantList.TAG); - if (reactantList != null) { - int reactantCount = reactantList.getCMLChildCount(CMLReactant.TAG); - for (int i = 0; i < reactantCount; i++) { - CMLReactant reactant = (CMLReactant) reactantList.getChildCMLElement(CMLReactant.TAG, i); - if (reactant == null) { - w.write("Null reactant"); - } else { - CMLFormula reactantFormula = ProductReactant.getFormula(reactant); - w.write(((i > 0) ? " + " : S_EMPTY) - + reactantFormula.getFormattedString()); - } - } - } else { - w.write("Null reactantList"); - } - w.write(" = "); - CMLProductList productList = (CMLProductList) this.getFirstCMLChild(CMLProductList.TAG); - if (productList != null) { - int productCount = productList.getCMLChildCount(CMLProduct.TAG); - for (int i = 0; i < productCount; i++) { - CMLProduct product = (CMLProduct) productList.getChildCMLElement(CMLProduct.TAG, i); - if (product == null) { - w.write("Null product"); - } else { - CMLFormula productFormula = ProductReactant.getFormula(product); - w.write(((i > 0) ? " + " : S_EMPTY) - + productFormula.getFormattedString()); - } - } - } else { - w.write("Null productList"); - } - } - - /** * merge productLists into single productList. * --- 114,117 ---- *************** *** 339,372 **** } - /** - * get all molecules on reactant or product side. includes cmlSpectator - * - * @param reactantProduct - * CMLSpectator.REACTANT or CMLSpectator.PRODUCT - * @return all molecules - */ - public List<CMLMolecule> getMoleculesIncludingSpectators(String reactantProduct) { - List<CMLMolecule> moleculeList = new ArrayList<CMLMolecule>(); - if (reactantProduct.equals(CMLReactant.TAG)) { - CMLReactantList reactantList = (CMLReactantList) this.getFirstCMLChild(CMLReactantList.TAG); - if (reactantList != null) { - moleculeList = ProductReactantList.getMolecules(reactantList); - } - } else if (reactantProduct.equals(CMLProduct.TAG)) { - CMLProductList productList = (CMLProductList) this.getFirstCMLChild(CMLProductList.TAG); - if (productList != null) { - moleculeList = ProductReactantList.getMolecules(productList); - } - } - CMLSpectatorList spectatorList = (CMLSpectatorList) this.getFirstCMLChild(CMLSpectatorList.TAG); - if (spectatorList != null) { - List<CMLMolecule> moleculex = spectatorList.getSpectatorMolecules(reactantProduct); - for (int i = 0; i < moleculex.size(); i++) { - moleculeList.add(moleculex.get(i)); - } - } - return moleculeList; - } - public List<CMLMolecule> concat(Elements moleculeNodes1, List<CMLMolecule> m2) { List<CMLMolecule> m = new ArrayList <CMLMolecule>(); --- 253,256 ---- *************** *** 486,509 **** } } - - /** - * output the reaction analysis to a string. - * - * @return the string - * @throws CMLException - */ - public String analyzeReaction() throws CMLException { - StringWriter w = new StringWriter(); - try { - this.outputReaction(w); - w.write(S_NL); - this.outputBalance(w); - w.write(S_NL); - w.close(); - } catch (IOException ioe) { - logger.severe("BUG " + ioe); - } - return w.toString(); - } - } --- 370,372 ---- --- NEW FILE: CMLNodeFactory.java --- package org.xmlcml.cml.element; import java.util.Stack; import nu.xom.Attribute; import nu.xom.Element; import nu.xom.NodeFactory; import nu.xom.Nodes; import nu.xom.Text; import org.xmlcml.cml.base.CMLElement; import org.xmlcml.cml.base.CMLException; import org.xmlcml.cml.base.CMLRuntime; /** user-modifiable class supporting CMLNodeFactory. * * autogenerated from schema * use as a shell which can be edited */ public class CMLNodeFactory extends NodeFactory { // fields; // current of current node public Element current; // current element stack public Stack<Element> stack = new Stack<Element>(); /** must give simple documentation. * */ public CMLNodeFactory() { } /** callback from element start tag. * * @param name element name * @param namespace namespace of element * @return Element */ public Element startMakingElement(String name, String namespace) { // fields; // new element Element newElement; if (false) { } else if(name.equals("symmetry")) { newElement = CMLSymmetry.makeElementInContext(current); } else if(name.equals("peakList")) { newElement = CMLPeakList.makeElementInContext(current); } else if(name.equals("product")) { newElement = CMLProduct.makeElementInContext(current); } else if(name.equals("region")) { newElement = CMLRegion.makeElementInContext(current); } else if(name.equals("point3")) { newElement = CMLPoint3.makeElementInContext(current); } else if(name.equals("expression")) { newElement = CMLExpression.makeElementInContext(current); } else if(name.equals("reactantList")) { newElement = CMLReactantList.makeElementInContext(current); } else if(name.equals("actionList")) { newElement = CMLActionList.makeElementInContext(current); } else if(name.equals("alternative")) { newElement = CMLAlternative.makeElementInContext(current); } else if(name.equals("object")) { newElement = CMLObject.makeElementInContext(current); } else if(name.equals("string")) { newElement = CMLString.makeElementInContext(current); } else if(name.equals("parameter")) { newElement = CMLParameter.makeElementInContext(current); } else if(name.equals("reactionStep")) { newElement = CMLReactionStep.makeElementInContext(current); } else if(name.equals("spectrumList")) { newElement = CMLSpectrumList.makeElementInContext(current); } else if(name.equals("bondStereo")) { newElement = CMLBondStereo.makeElementInContext(current); } else if(name.equals("peakStructure")) { newElement = CMLPeakStructure.makeElementInContext(current); } else if(name.equals("atomParity")) { newElement = CMLAtomParity.makeElementInContext(current); } else if(name.equals("mechanismComponent")) { newElement = CMLMechanismComponent.makeElementInContext(current); } else if(name.equals("operator")) { newElement = CMLOperator.makeElementInContext(current); } else if(name.equals("array")) { newElement = CMLArray.makeElementInContext(current); } else if(name.equals("scalar")) { newElement = CMLScalar.makeElementInContext(current); } else if(name.equals("stringArray")) { newElement = CMLStringArray.makeElementInContext(current); } else if(name.equals("peakGroup")) { newElement = CMLPeakGroup.makeElementInContext(current); } else if(name.equals("unitList")) { newElement = CMLUnitList.makeElementInContext(current); } else if(name.equals("angle")) { newElement = CMLAngle.makeElementInContext(current); } else if(name.equals("torsion")) { newElement = CMLTorsion.makeElementInContext(current); } else if(name.equals("spectatorList")) { newElement = CMLSpectatorList.makeElementInContext(current); } else if(name.equals("latticeVector")) { newElement = CMLLatticeVector.makeElementInContext(current); } else if(name.equals("module")) { newElement = CMLModule.makeElementInContext(current); } else if(name.equals("line3")) { newElement = CMLLine3.makeElementInContext(current); } else if(name.equals("integerArray")) { newElement = CMLIntegerArray.makeElementInContext(current); } else if(name.equals("zMatrix")) { newElement = CMLZMatrix.makeElementInContext(current); } else if(name.equals("observation")) { newElement = CMLObservation.makeElementInContext(current); } else if(name.equals("enumeration")) { newElement = CMLEnumeration.makeElementInContext(current); } else if(name.equals("potentialForm")) { newElement = CMLPotentialForm.makeElementInContext(current); } else if(name.equals("system")) { newElement = CMLSystem.makeElementInContext(current); } else if(name.equals("name")) { newElement = CMLName.makeElementInContext(current); } else if(name.equals("bondTypeList")) { newElement = CMLBondTypeList.makeElementInContext(current); } else if(name.equals("action")) { newElement = CMLAction.makeElementInContext(current); } else if(name.equals("vector3")) { newElement = CMLVector3.makeElementInContext(current); } else if(name.equals("atomicBasisFunction")) { newElement = CMLAtomicBasisFunction.makeElementInContext(current); } else if(name.equals("metadataList")) { newElement = CMLMetadataList.makeElementInContext(current); } else if(name.equals("unit")) { newElement = CMLUnit.makeElementInContext(current); } else if(name.equals("length")) { newElement = CMLLength.makeElementInContext(current); } else if(name.equals("definition")) { newElement = CMLDefinition.makeElementInContext(current); } else if(name.equals("link")) { newElement = CMLLink.makeElementInContext(current); } else if(name.equals("reactiveCentre")) { newElement = CMLReactiveCentre.makeElementInContext(current); } else if(name.equals("relatedEntry")) { newElement = CMLRelatedEntry.makeElementInContext(current); } else if(name.equals("isotopeList")) { newElement = CMLIsotopeList.makeElementInContext(current); } else if(name.equals("transitionState")) { newElement = CMLTransitionState.makeElementInContext(current); } else if(name.equals("documentation")) { newElement = CMLDocumentation.makeElementInContext(current); } else if(name.equals("plane3")) { newElement = CMLPlane3.makeElementInContext(current); } else if(name.equals("atomSet")) { newElement = CMLAtomSet.makeElementInContext(current); } else if(name.equals("spectator")) { newElement = CMLSpectator.makeElementInContext(current); } else if(name.equals("identifier")) { newElement = CMLIdentifier.makeElementInContext(current); } else if(name.equals("bondArray")) { newElement = CMLBondArray.makeElementInContext(current); } else if(name.equals("floatArray")) { newElement = CMLFloatArray.makeElementInContext(current); } else if(name.equals("lattice")) { newElement = CMLLattice.makeElementInContext(current); } else if(name.equals("table")) { newElement = CMLTable.makeElementInContext(current); } else if(name.equals("arg")) { newElement = CMLArg.makeElementInContext(current); } else if(name.equals("potential")) { newElement = CMLPotential.makeElementInContext(current); } else if(name.equals("reactionStepList")) { newElement = CMLReactionStepList.makeElementInContext(current); } else if(name.equals("xaxis")) { newElement = CMLXaxis.makeElementInContext(current); } else if(name.equals("mechanism")) { newElement = CMLMechanism.makeElementInContext(current); } else if(name.equals("atom")) { newElement = CMLAtom.makeElementInContext(current); } else if(name.equals("spectrumData")) { newElement = CMLSpectrumData.makeElementInContext(current); } else if(name.equals("potentialList")) { newElement = CMLPotentialList.makeElementInContext(current); } else if(name.equals("electron")) { newElement = CMLElectron.makeElementInContext(current); } else if(name.equals("eigen")) { newElement = CMLEigen.makeElementInContext(current); } else if(name.equals("parameterList")) { newElement = CMLParameterList.makeElementInContext(current); } else if(name.equals("reactionScheme")) { newElement = CMLReactionScheme.makeElementInContext(current); } else if(name.equals("float")) { newElement = CMLFloat.makeElementInContext(current); } else if(name.equals("reactant")) { newElement = CMLReactant.makeElementInContext(current); } else if(name.equals("yaxis")) { newElement = CMLYaxis.makeElementInContext(current); } else if(name.equals("integer")) { newElement = CMLInteger.makeElementInContext(current); } else if(name.equals("stmml")) { newElement = CMLStmml.makeElementInContext(current); } else if(name.equals("property")) { newElement = CMLProperty.makeElementInContext(current); } else if(name.equals("appinfo")) { newElement = CMLAppinfo.makeElementInContext(current); } else if(name.equals("bond")) { newElement = CMLBond.makeElementInContext(current); } else if(name.equals("formula")) { newElement = CMLFormula.makeElementInContext(current); } else if(name.equals("particle")) { newElement = CMLParticle.makeElementInContext(current); } else if(name.equals("substanceList")) { newElement = CMLSubstanceList.makeElementInContext(current); } else if(name.equals("unitType")) { newElement = CMLUnitType.makeElementInContext(current); } else if(name.equals("bondType")) { newElement = CMLBondType.makeElementInContext(current); } else if(name.equals("reaction")) { newElement = CMLReaction.makeElementInContext(current); } else if(name.equals("bondSet")) { newElement = CMLBondSet.makeElementInContext(current); } else if(name.equals("map")) { newElement = CMLMap.makeElementInContext(current); } else if(name.equals("productList")) { newElement = CMLProductList.makeElementInContext(current); } else if(name.equals("substance")) { newElement = CMLSubstance.makeElementInContext(current); } else if(name.equals("dimension")) { newElement = CMLDimension.makeElementInContext(current); } else if(name.equals("metadata")) { newElement = CMLMetadata.makeElementInContext(current); } else if(name.equals("sample")) { newElement = CMLSample.makeElementInContext(current); } else if(name.equals("propertyList")) { newElement = CMLPropertyList.makeElementInContext(current); } else if(name.equals("atomArray")) { newElement = CMLAtomArray.makeElementInContext(current); } else if(name.equals("molecule")) { newElement = CMLMolecule.makeElementInContext(current); } else if(name.equals("reactionList")) { newElement = CMLReactionList.makeElementInContext(current); } else if(name.equals("peak")) { newElement = CMLPeak.makeElementInContext(current); } else if(name.equals("annotation")) { newElement = CMLAnnotation.makeElementInContext(current); } else if(name.equals("atomType")) { newElement = CMLAtomType.makeElementInContext(current); } else if(name.equals("entry")) { newElement = CMLEntry.makeElementInContext(current); } else if(name.equals("atomTypeList")) { newElement = CMLAtomTypeList.makeElementInContext(current); } else if(name.equals("band")) { newElement = CMLBand.makeElementInContext(current); } else if(name.equals("cml")) { newElement = CMLCml.makeElementInContext(current); } else if(name.equals("gradient")) { newElement = CMLGradient.makeElementInContext(current); } else if(name.equals("list")) { newElement = CMLList.makeElementInContext(current); } else if(name.equals("sphere3")) { newElement = CMLSphere3.makeElementInContext(current); } else if(name.equals("transform3")) { newElement = CMLTransform3.makeElementInContext(current); } else if(name.equals("basisSet")) { newElement = CMLBasisSet.makeElementInContext(current); } else if(name.equals("spectrum")) { newElement = CMLSpectrum.makeElementInContext(current); } else if(name.equals("crystal")) { newElement = CMLCrystal.makeElementInContext(current); } else if(name.equals("amount")) { newElement = CMLAmount.makeElementInContext(current); } else if(name.equals("isotope")) { newElement = CMLIsotope.makeElementInContext(current); } else if(name.equals("conditionList")) { newElement = CMLConditionList.makeElementInContext(current); } else if(name.equals("abundance")) { newElement = CMLAbundance.makeElementInContext(current); } else if(name.equals("matrix")) { newElement = CMLMatrix.makeElementInContext(current); } else if(name.equals("label")) { newElement = CMLLabel.makeElementInContext(current); } else if(name.equals("dictionary")) { newElement = CMLDictionary.makeElementInContext(current); } else if(name.equals("description")) { newElement = CMLDescription.makeElementInContext(current); } else if(name.equals("bandList")) { newElement = CMLBandList.makeElementInContext(current); } else if (namespace != null && namespace.trim().length() != 0) { newElement = new Element(name, namespace); } else { newElement = new Element(name); } stack.push(current); current = newElement; return newElement; } /** callback from element end tag. * * @param element the context element * @return Nodes */ public Nodes finishMakingElement(Element element) { Element parent = stack.pop(); if (current instanceof CMLElement) { ((CMLElement) current).finishMakingElement(parent); } current = parent; Nodes nodes = new Nodes(); nodes.append(element); return nodes; } /** callback from each attribute. * * @param name attribute name * @param URI attribute namespace * @param value attribute value * @param type attribute type (ignored) * @return Nodes */ public Nodes makeAttribute(String name, String URI, String value, Attribute.Type type) { Nodes nodes = new Nodes(); Attribute attribute = null; try { int prefixLoc = name.indexOf(":"); if (URI != null && URI.trim().length() != 0 && prefixLoc != -1) { // namespaced non-cml attribute is allowed attribute = new Attribute(name, value, URI); } else if (current instanceof CMLElement) { CMLElement currentCML = (CMLElement) current; String attributeGroupName = currentCML.getAttributeGroupName(name); if (attributeGroupName == null) { throw new CMLRuntime("+unknown attribute: "+name); } attribute = CMLAttributeList.makeAttributeFromGroupName(attributeGroupName, value, URI); } else if (prefixLoc == -1) { // non-prefixed non-cml element attribute = new Attribute(name, value); } else if (prefixLoc != -1) { // prefixed non-cml element attribute = new Attribute(name, value, URI); } } catch (CMLException e) { throw new CMLRuntime(""+e); } nodes.append(attribute); return nodes; } /** FIXME text - needs to trap/check values. * * @param text String content * @return Nodes */ public Nodes makeText(String text) { Nodes nodes = new Nodes(); nodes.append(new Text(text)); return nodes; } /** no-op. * * @param text String content */ public static void main(String text) { } } |