From: Egon W. <eg...@us...> - 2003-09-03 11:43:01
|
Update of /cvsroot/cdk/cdk/src/org/openscience/cdk/io/cml In directory sc8-pr-cvs1:/tmp/cvs-serv20156/src/org/openscience/cdk/io/cml Modified Files: CMLCoreModule.java ChemFileCDO.java Log Message: More tests src/org/openscience/cdk/test/io/cml/CMLRoundTripTest.java Index: CMLCoreModule.java =================================================================== RCS file: /cvsroot/cdk/cdk/src/org/openscience/cdk/io/cml/CMLCoreModule.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- CMLCoreModule.java 27 Aug 2003 08:19:48 -0000 1.26 +++ CMLCoreModule.java 3 Sep 2003 11:42:57 -0000 1.27 @@ -50,6 +50,7 @@ protected int atomCounter; protected Vector elsym; + protected Vector eltitles; protected Vector elid; protected Vector formalCharges; protected Vector partialCharges; @@ -107,6 +108,7 @@ this.BUILTIN = conv.BUILTIN; this.atomCounter = conv.atomCounter; this.elsym = conv.elsym; + this.eltitles = conv.eltitles; this.elid = conv.elid; this.formalCharges = conv.formalCharges; this.partialCharges = conv.partialCharges; @@ -156,6 +158,7 @@ atomCounter = 0; elsym = new Vector(); elid = new Vector(); + eltitles = new Vector(); formalCharges = new Vector(); partialCharges = new Vector(); isotope = new Vector(); @@ -250,6 +253,9 @@ else if (att.equals("elementType")) { elsym.addElement(value); } // this is supported in CML 2.0 + else if (att.equals("title")) { + eltitles.addElement(value); + } // this is supported in CML 2.0 else if (att.equals("x2")) { x2.addElement(value); } // this is supported in CML 2.0 @@ -423,10 +429,8 @@ if (bondStereo.size() > bondDictRefs.size()) bondDictRefs.addElement(null); } else if ("atom".equals(name)) { - if (atomCounter > formalCharges.size()) { - /* while strictly undefined, assume zero - charge when no number is given */ - formalCharges.addElement("0"); + if (atomCounter > eltitles.size()) { + eltitles.addElement(null); } if (atomCounter > hCounts.size()) { /* while strictly undefined, assume zero @@ -439,6 +443,11 @@ if (atomCounter > isotope.size()) { isotope.addElement(null); } + if (atomCounter > formalCharges.size()) { + /* while strictly undefined, assume zero + implicit hydrogens when no number is given */ + formalCharges.addElement("0"); + } /* It may happen that not all atoms have associated 2D or 3D coordinates. accept that */ if (atomCounter > x2.size() && x2.size() != 0) { @@ -680,6 +689,10 @@ } catch (NumberFormatException exception) { logger.error("Content must a float: " + cData); } + } else if (xpath.toString().endsWith("bond/scalar/")) { + if (DICTREF.equals("mdl:stereo")) { + bondStereo.addElement(cData.trim()); + } } else { logger.warn("Ignoring scaler: " + xpath); } @@ -795,6 +808,7 @@ boolean hasPartialCharge = false; boolean hasHCounts = false; boolean hasSymbols = false; + boolean hasTitles = false; boolean hasIsotopes = false; boolean hasDictRefs = false; @@ -812,6 +826,13 @@ "No atom symbols: " + elsym.size() + " != " + atomCounter); } + if (eltitles.size() == atomCounter) { + hasTitles = true; + } else { + logger.debug( + "No atom titles: " + eltitles.size() + " != " + atomCounter); + } + if ((x3.size() == atomCounter) && (y3.size() == atomCounter) && (z3.size() == atomCounter)) { has3D = true; @@ -884,11 +905,26 @@ if (hasID) { cdo.setObjectProperty("Atom", "id", (String)elid.elementAt(i)); } + if (hasTitles) { + if (hasSymbols) { + String symbol = (String)elsym.elementAt(i); + if (symbol.equals("Du") || symbol.equals("Dummy")) { + cdo.setObjectProperty("PseudoAtom", "label", (String)eltitles.elementAt(i)); + } else { + cdo.setObjectProperty("Atom", "title", (String)eltitles.elementAt(i)); + } + } else { + cdo.setObjectProperty("Atom", "title", (String)eltitles.elementAt(i)); + } + } // store optional atom properties if (hasSymbols) { - cdo.setObjectProperty("Atom", "type", - (String)elsym.elementAt(i)); + String symbol = (String)elsym.elementAt(i); + if (symbol.equals("Du") || symbol.equals("Dummy")) { + symbol = "R"; + } + cdo.setObjectProperty("Atom", "type", symbol); } if (has3D) { Index: ChemFileCDO.java =================================================================== RCS file: /cvsroot/cdk/cdk/src/org/openscience/cdk/io/cml/ChemFileCDO.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ChemFileCDO.java 20 Aug 2003 15:10:35 -0000 1.5 +++ ChemFileCDO.java 3 Sep 2003 11:42:57 -0000 1.6 @@ -144,6 +144,7 @@ numberOfAtoms++; } else if (objectType.equals("Bond")) { bond_id = null; + bond_stereo = -99; } else if (objectType.equals("Animation")) { currentChemSequence = new ChemSequence(); } else if (objectType.equals("Frame")) { @@ -210,6 +211,9 @@ Atom a2 = currentMolecule.getAtomAt(bond_a2); Bond b = new Bond(a1, a2, bond_order); if (bond_id != null) b.setID(bond_id); + if (bond_stereo != -99) { + b.setStereo(bond_stereo); + } currentMolecule.addBond(b); } } else if (objectType.equals("a-axis")) { @@ -283,9 +287,19 @@ if (propertyType.equals("id")) { currentMolecule.setID(propertyValue); } + } else if (objectType.equals("PseudoAtom")) { + if (propertyType.equals("label")) { + if (!(currentAtom instanceof PseudoAtom)) { + currentAtom = new PseudoAtom(currentAtom); + } + ((PseudoAtom)currentAtom).setLabel(propertyValue); + } } else if (objectType.equals("Atom")) { if (propertyType.equals("type")) { - currentAtom.setSymbol(propertyValue); + if (propertyValue.equals("R") && !(currentAtom instanceof PseudoAtom)) { + currentAtom = new PseudoAtom(currentAtom); + } + currentAtom.setSymbol(propertyValue); } else if (propertyType.equals("x2")) { currentAtom.setX2D(new Double(propertyValue).doubleValue()); } else if (propertyType.equals("y2")) { @@ -328,6 +342,12 @@ logger.error("Cannot convert to double: " + propertyValue); bond_order = 1.0; } + } else if (propertyType.equals("stereo")) { + if (propertyValue.equals("H")) { + bond_stereo = CDKConstants.STEREO_BOND_DOWN; + } else if (propertyValue.equals("W")) { + bond_stereo = CDKConstants.STEREO_BOND_UP; + } } } else if (objectType.equals("Reaction")) { if (propertyType.equals("id")) { |