From: <ha...@us...> - 2010-01-24 13:40:46
|
Revision: 12204 http://jmol.svn.sourceforge.net/jmol/?rev=12204&view=rev Author: hansonr Date: 2010-01-24 13:40:35 +0000 (Sun, 24 Jan 2010) Log Message: ----------- version=11.9.22_dev # new feature: JVXL files readable as CML, including atom positions for MO only # bug fix: JVXL writing way too much information # bug fix: JVXL write invalid XML # bug fix: CML reader not accounting for possibility of nonunique atom names Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/readers/xml/XmlCmlReader.java trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java trunk/Jmol/src/org/jmol/jvxl/data/JvxlCoder.java trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java trunk/Jmol/src/org/jmol/jvxl/data/VolumeData.java trunk/Jmol/src/org/jmol/modelset/ModelSet.java trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java trunk/Jmol/src/org/jmol/shape/Mesh.java trunk/Jmol/src/org/jmol/shapesurface/MolecularOrbital.java trunk/Jmol/src/org/jmol/util/XmlUtil.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/JmolConstants.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/adapter/readers/xml/XmlCmlReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/xml/XmlCmlReader.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/adapter/readers/xml/XmlCmlReader.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -38,6 +38,7 @@ import org.xml.sax.XMLReader; import org.jmol.adapter.readers.cifpdb.CifReader; import org.jmol.util.Logger; +import org.jmol.util.Parser; /** * A CML2 Reader - @@ -182,6 +183,8 @@ private String scalarDictValue; private String scalarTitle; private String cellParameterType; + private boolean checkedSerial; + private boolean isSerial; // counter that is incremented each time a molecule element is started and // decremented when finished. Needed so that only 1 atomSet created for each @@ -348,6 +351,7 @@ if (!coords3D) atom.z = 0; parent.setAtomCoord(atom); + addAtom(atom); } } if (name.equals("formula")) { @@ -364,7 +368,7 @@ if (atts.containsKey("order")) order = parseBondToken((String) atts.get("order")); if (tokenCount == 2 && order > 0) { - atomSetCollection.addNewBond(tokens[0], tokens[1], order); + addNewBond(tokens[0], tokens[1], order); } } break; @@ -373,10 +377,17 @@ state = MOLECULE_ATOM; atom = new Atom(); parent.setFractionalCoordinates(false); + String id = (String) atts.get("id"); if (atts.containsKey("label")) atom.atomName = (String) atts.get("label"); else - atom.atomName = (String) atts.get("id"); + atom.atomName = id; + if (!checkedSerial) { + isSerial = (id != null && Parser.parseInt(id) != Integer.MIN_VALUE); + checkedSerial = true; + } + if (isSerial) + atom.atomSerial = Parser.parseInt(id); if (atts.containsKey("xFract") && (parent.iHaveUnitCell || !atts.containsKey("x3"))) { parent.setFractionalCoordinates(true); @@ -433,6 +444,14 @@ } } + private void addNewBond(String a1, String a2, int order) { + if (isSerial) + atomSetCollection.addNewBondWithMappedSerialNumbers(Parser.parseInt(a1), + Parser.parseInt(a2), order); + else + atomSetCollection.addNewBond(a1, a2, order); + } + private void getDictRefValue(HashMap atts) { scalarDictRef = (String) atts.get("dictRef"); if (scalarDictRef != null) { @@ -558,12 +577,8 @@ case MOLECULE_ATOM_ARRAY: if (name.equals("atomArray")) { state = MOLECULE; - for (int i = 0; i < atomCount; ++i) { - Atom atom = atomArray[i]; - if ((atom.elementSymbol != null || atom.elementNumber >= 0) - && !Float.isNaN(atom.z)) - atomSetCollection.addAtomWithMappedName(atom); - } + for (int i = 0; i < atomCount; ++i) + addAtom(atomArray[i]); } break; case MOLECULE_BOND: @@ -574,10 +589,7 @@ case MOLECULE_ATOM: if (name.equals("atom")) { state = MOLECULE_ATOM_ARRAY; - if ((atom.elementSymbol != null || atom.elementNumber >= 0) - && !Float.isNaN(atom.z)) { - atomSetCollection.addAtomWithMappedName(atom); - } + addAtom(atom); atom = null; } break; @@ -619,7 +631,7 @@ } else if (scalarDictValue.equals("order")) { int order = parseBondToken(chars); if (order > 0 && tokenCount == 2) - atomSetCollection.addNewBond(tokens[0], tokens[1], order); + addNewBond(tokens[0], tokens[1], order); } setKeepChars(false); break; @@ -629,6 +641,16 @@ } } + private void addAtom(Atom atom) { + if ((atom.elementSymbol == null && atom.elementNumber < 0) + || Float.isNaN(atom.z)) + return; + if (isSerial) + atomSetCollection.addAtomWithMappedSerialNumber(atom); + else + atomSetCollection.addAtomWithMappedName(atom); + } + int parseBondToken(String str) { float floatOrder = parseFloat(str); if (Float.isNaN(floatOrder) && str.length() >= 1) { @@ -658,7 +680,7 @@ } //this routine breaks out all the tokens in a string - // results are placed into the tokens array + // results ar e placed into the tokens array void breakOutTokens(String str) { StringTokenizer st = new StringTokenizer(str); tokenCount = st.countTokens(); Modified: trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/adapter/smarter/Resolver.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -508,6 +508,9 @@ if (header.indexOf("arguslab") >= 0) { return specialTags[SPECIAL_ARGUS_XML][0]; } + if (header.indexOf("jvxl") >= 0) { + return specialTags[SPECIAL_CML_XML][0]; + } if (header.indexOf(CML_NAMESPACE_URI) >= 0 || header.indexOf("cml:") >= 0) { return specialTags[SPECIAL_CML_XML][0]; Modified: trunk/Jmol/src/org/jmol/jvxl/data/JvxlCoder.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/data/JvxlCoder.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/jvxl/data/JvxlCoder.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -91,6 +91,8 @@ "jmolVersion", jvxlData.version }); if (jvxlData.jvxlFileTitle != null) XmlUtil.appendCdata(data, "jvxlFileTitle", "\n" + jvxlData.jvxlFileTitle); + if (jvxlData.moleculeXml != null) + data.append(jvxlData.moleculeXml); if (jvxlData.jvxlVolumeDataXml == null) jvxlData.jvxlVolumeDataXml = (new VolumeData()).setVolumetricXml(); data.append(jvxlData.jvxlVolumeDataXml); Modified: trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -142,6 +142,7 @@ public int excludedTriangleCount; public int excludedVertexCount; public boolean colorDensity; + public String moleculeXml; public void setSurfaceInfo(Point4f thePlane, int nSurfaceInts, String surfaceData) { jvxlSurfaceData = surfaceData; Modified: trunk/Jmol/src/org/jmol/jvxl/data/VolumeData.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/data/VolumeData.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/jvxl/data/VolumeData.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -387,7 +387,7 @@ XmlUtil.appendTag(sb, "jvxlVolumeData", null); } else { XmlUtil.openTag(sb, "jvxlVolumeData", new String[] { - "origin=", Escape.escape(volumetricOrigin) }); + "origin", Escape.escape(volumetricOrigin) }); for (int i = 0; i < 3; i++) XmlUtil.appendTag(sb, "jvxlVolumeVector", new String[] { "type", "" + i, Modified: trunk/Jmol/src/org/jmol/modelset/ModelSet.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/ModelSet.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/modelset/ModelSet.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -29,6 +29,8 @@ import org.jmol.util.Escape; import org.jmol.util.Logger; import org.jmol.util.Point3fi; +import org.jmol.util.TextFormat; +import org.jmol.util.XmlUtil; import org.jmol.viewer.JmolConstants; import org.jmol.script.Token; import org.jmol.api.Interface; @@ -948,5 +950,68 @@ return super.calculateStruts(bs1, bs2); } + /* + * <molecule title="acetic_acid.mol" + * xmlns="http://www.xml-cml.org/schema/cml2/core" + * xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + * xsi:schemaLocation="http://www.xml-cml.org/schema/cml2/core cmlAll.xsd"> + * <atomArray> <atom id="a1" elementType="C" x3="0.1853" y3="0.0096" + * z3="0.4587"/> <atom id="a2" elementType="O" x3="0.6324" y3="1.0432" + * z3="0.8951"/> <atom id="a3" elementType="C" x3="-1.0665" y3="-0.1512" + * z3="-0.3758"/> <atom id="a4" elementType="O" x3="0.7893" y3="-1.1734" + * z3="0.6766" formalCharge="-1"/> <atom id="a5" elementType="H" x3="-1.7704" + * y3="-0.8676" z3="0.1055"/> <atom id="a6" elementType="H" x3="-0.8068" + * y3="-0.5215" z3="-1.3935"/> <atom id="a7" elementType="H" x3="-1.5889" + * y3="0.8259" z3="-0.4854"/> </atomArray> <bondArray> <bond atomRefs2="a1 a2" + * order="partial12"/> <bond atomRefs2="a1 a3" order="S"/> <bond + * atomRefs2="a1 a4" order="partial12"/> <bond atomRefs2="a3 a5" order="S"/> + * <bond atomRefs2="a3 a6" order="S"/> <bond atomRefs2="a3 a7" order="S"/> + * </bondArray> </molecule> + */ + public String getModelCml(BitSet bs, int atomsMax, boolean addBonds) { + StringBuffer sb = new StringBuffer(""); + int nAtoms = BitSetUtil.cardinalityOf(bs); + if (nAtoms == 0) + return ""; + XmlUtil.openTag(sb, "molecule"); + XmlUtil.openTag(sb, "atomArray"); + BitSet bsAtoms = new BitSet(); + for (int i = 0; i < atomCount; i++) { + if (!bs.get(i) || --atomsMax == 0) + continue; + String name = atoms[i].getAtomName(); + TextFormat.simpleReplace(name, "\"", "''"); + bsAtoms.set(atoms[i].index); + XmlUtil + .appendTag(sb, "atom", new String[] { + "id", "" + (atoms[i].index + 1), + "label", atoms[i].getAtomName(), + "elementType", atoms[i].getElementSymbol(), + "x3", "" + atoms[i].x, + "y3", "" + atoms[i].y, + "z3", "" + atoms[i].z }); + } + XmlUtil.closeTag(sb, "atomArray"); + if (addBonds) { + XmlUtil.openTag(sb, "bondArray"); + for (int i = 0; i < bondCount; i++) { + Bond bond = bonds[i]; + Atom a1 = bond.atom1; + Atom a2 = bond.atom2; + if (!bsAtoms.get(a1.index) || !bsAtoms.get(a2.index)) + continue; + String order = JmolConstants.getCmlOrder(bond.order); + if (order == null) + continue; + XmlUtil.appendTag(sb, "bond", new String[] { + "atomRefs2", (bond.atom1.index + 1) + " " + (bond.atom2.index + 1), + "order", order, }); + } + XmlUtil.closeTag(sb, "bondArray"); + } + XmlUtil.closeTag(sb, "molecule"); + return sb.toString(); + } + } Modified: trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -11007,7 +11007,7 @@ case Token.identifier: case Token.string: case Token.frame: - type = ScriptVariable.sValue(tokenAt(pt, args)).toLowerCase(); + type= ScriptVariable.sValue(tokenAt(pt, args)).toLowerCase(); if (tok == Token.image) { pt++; } else if (tok == Token.frame) { @@ -11054,7 +11054,7 @@ } else if (Parser.isOneOf(val.toLowerCase(), "png;jpg;jpeg;jpg64;jpeg64") && tokAt(pt + 1, args) == Token.integer) { quality = ScriptVariable.iValue(tokenAt(++pt, args)); - } else if (Parser.isOneOf(val.toLowerCase(), "xyz;mol;pdb")) { + } else if (Parser.isOneOf(val.toLowerCase(), "xyz;mol;pdb;cml")) { type = val.toUpperCase(); if (pt + 1 == argCount) pt++; @@ -11146,12 +11146,12 @@ if (!isImage && !isExport && !Parser.isOneOf(type, - "ZIP;ZIPALL;SPT;HIS;MO;ISO;ISOX;PMESH;VAR;FILE;XYZ;MENU;MOL;PDB;PGRP;QUAT;RAMA;FUNCS;")) + "ZIP;ZIPALL;SPT;HIS;MO;ISO;ISOX;PMESH;VAR;FILE;CML;XYZ;MENU;MOL;PDB;PGRP;QUAT;RAMA;FUNCS;")) error( ERROR_writeWhat, "ALL|COORDS|FILE|FUNCTIONS|HISTORY|IMAGE|ISOSURFACE|MENU|MO|POINTGROUP|QUATERNION [w,x,y,z] [derivative]" + "|RAMACHANDRAN|STATE|VAR x CLIPBOARD", - "JPG|JPG64|PNG|GIF|PPM|SPT|JVXL|XJVXL|XYZ|MOL|PDB|" + "JPG|JPG64|PNG|GIF|PPM|SPT|JVXL|XJVXL|CML|XYZ|MOL|PDB|" + driverList.toUpperCase().replace(';', '|')); if (isSyntaxCheck) return ""; @@ -11185,7 +11185,7 @@ data = viewer.getPointGroupAsString(type2.equals("draw"), null, 0, 1.0f); } else if (data == "PDB") { data = viewer.getPdbData(null); - } else if (data == "XYZ" || data == "MOL") { + } else if (data == "XYZ" || data == "MOL" || data == "CML") { data = viewer.getData("selected", data); } else if (data == "QUAT" || data == "RAMA") { int modelIndex = viewer.getCurrentModelIndex(); Modified: trunk/Jmol/src/org/jmol/shape/Mesh.java =================================================================== --- trunk/Jmol/src/org/jmol/shape/Mesh.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/shape/Mesh.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -217,7 +217,7 @@ } public String getState(String type) { - String sxml = Shape.getXmlPropertyString(xmlProperties, type); + String sxml = null; // problem here is that it can be WAY to large. Shape.getXmlPropertyString(xmlProperties, type); StringBuffer s = new StringBuffer(); if (sxml != null) s.append("/** XML ** ").append(sxml).append(" ** XML **/\n"); Modified: trunk/Jmol/src/org/jmol/shapesurface/MolecularOrbital.java =================================================================== --- trunk/Jmol/src/org/jmol/shapesurface/MolecularOrbital.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/shapesurface/MolecularOrbital.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -269,6 +269,7 @@ super.setProperty("init", params, null); setOrbital(i); } + jvxlData.moleculeXml = viewer.getModelCml(viewer.getModelAtomBitSet(thisMesh.modelIndex, true), 100, true); if (!haveHeader) { str.append(JvxlCoder.jvxlGetFile(jvxlData, null, null, "HEADERONLY", true, nTotal, null, null)); Modified: trunk/Jmol/src/org/jmol/util/XmlUtil.java =================================================================== --- trunk/Jmol/src/org/jmol/util/XmlUtil.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/util/XmlUtil.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -84,7 +84,7 @@ */ public static String wrapCdata(Object data) { String s = "" + data; - return (s.indexOf("&") < 0 && s.indexOf("<") < 0 ? s + return (s.indexOf("&") < 0 && s.indexOf("<") < 0 ? (s.startsWith("\n") ? "" : "\n") + s : "<![CDATA[" + TextFormat.simpleReplace(s, "]]>", "]]]]><![CDATA[>") + "]]>"); } Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2010-01-24 13:40:35 UTC (rev 12204) @@ -3,6 +3,10 @@ version=11.9.22_dev +# new feature: JVXL files for molecular orbitals readable as CML, including atom positions +# bug fix: JVXL writing way too much information +# bug fix: JVXL write invalid XML +# bug fix: CML reader not accounting for possibility of nonunique atom names # new feature: set picking STRUTS # bug fix: APBS reader could hang on empty line # bug fix: isosurface "..." AS "..." capability expanded to all readers Modified: trunk/Jmol/src/org/jmol/viewer/JmolConstants.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/JmolConstants.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/viewer/JmolConstants.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -518,6 +518,27 @@ return "?"; } + public static String getCmlOrder(int order) { + String sname = getBondOrderNameFromOrder(order); + switch (sname.charAt(0)) { + case 's': + case 'd': + case 't': + return "" + sname.toUpperCase().charAt(0); + case 'a': + if (sname.indexOf("Double") >= 0) + return "D"; + else if (sname.indexOf("Single") >= 0) + return "S"; + return "aromatic"; + case 'p': + if (sname.indexOf(" ") >= 0) + return sname.substring(sname.indexOf(" ") + 1); + return "partial12"; + } + return null; + } + /** * used for formatting labels and in the connect PARTIAL command * Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2010-01-24 10:56:35 UTC (rev 12203) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2010-01-24 13:40:35 UTC (rev 12204) @@ -7222,6 +7222,8 @@ String exp = ""; if (type.toLowerCase().indexOf("property_") == 0) exp = "{selected}.label(\"%{" + type + "}\")"; + else if (type.equalsIgnoreCase("CML")) + return getModelCml(getAtomBitSet(atomExpression), 0, true); else if (type.equalsIgnoreCase("PDB")) // old crude exp = "{selected and not hetero}.label(\"ATOM %5i %-4a%1A%3.3n %1c%4R%1E %8.3x%8.3y%8.3z%6.2Q%6.2b %2e \").lines" @@ -7240,6 +7242,10 @@ return (String) evaluateExpression(exp); } + public String getModelCml(BitSet bs, int nAtomsMax, boolean addBonds) { + return modelSet.getModelCml(bs, nAtomsMax, addBonds); + } + // synchronized here trapped the eventQueue public Object evaluateExpression(Object stringOrTokens) { return ScriptEvaluator.evaluateExpression(this, stringOrTokens); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |