From: <ha...@us...> - 2010-12-17 17:45:49
|
Revision: 14804 http://jmol.svn.sourceforge.net/jmol/?rev=14804&view=rev Author: hansonr Date: 2010-12-17 17:45:39 +0000 (Fri, 17 Dec 2010) Log Message: ----------- version=12.1.26_dev # new feature: write SDF creates V2000 SDfile; see http://www.symyx.com/downloads/public/ctfile/ctfile.pdf Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/readers/molxyz/MolReader.java trunk/Jmol/src/org/jmol/api/JmolAdapter.java trunk/Jmol/src/org/jmol/modelset/ModelCollection.java trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java trunk/Jmol/src/org/jmol/util/Elements.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/PropertyManager.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/adapter/readers/molxyz/MolReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/molxyz/MolReader.java 2010-12-17 15:07:00 UTC (rev 14803) +++ trunk/Jmol/src/org/jmol/adapter/readers/molxyz/MolReader.java 2010-12-17 17:45:39 UTC (rev 14804) @@ -28,6 +28,7 @@ import org.jmol.api.JmolAdapter; +import org.jmol.util.Elements; import org.jmol.util.Logger; /** @@ -172,8 +173,6 @@ applySymmetryAndSetTrajectory(); } - private final static String isotopeMap0 = "H1 H2 "; - private final static String isotopeMap1 = "D T "; void readAtoms(int atomCount) throws Exception { for (int i = 0; i < atomCount; ++i) { readLine(); @@ -196,13 +195,9 @@ charge = 4 - code; code = parseInt(line, 34, 36); if (code != 0 && code >= -3 && code <= 4) { - int ptr = isotopeMap0.indexOf(elementSymbol + code); - if (ptr >= 0) - elementSymbol = isotopeMap1.substring(ptr, ptr + 3).trim(); - else if (elementSymbol=="C") - elementSymbol = (12 + code) + "C"; - else if (elementSymbol=="N") - elementSymbol = (14 + code) + "N"; + int n = JmolAdapter.getNaturalIsotope(JmolAdapter.getElementNumber(elementSymbol)); + if (n > 0) + elementSymbol = (n > 1 ? (n + code) + elementSymbol : code == 1 ? "D" : code == 2 ? "T" : "H"); } } Atom atom = atomSetCollection.addNewAtom(); Modified: trunk/Jmol/src/org/jmol/api/JmolAdapter.java =================================================================== --- trunk/Jmol/src/org/jmol/api/JmolAdapter.java 2010-12-17 15:07:00 UTC (rev 14803) +++ trunk/Jmol/src/org/jmol/api/JmolAdapter.java 2010-12-17 17:45:39 UTC (rev 14804) @@ -89,6 +89,10 @@ return Elements.elementNumberFromSymbol(elementSymbol, false); } + public static int getNaturalIsotope(int elementNumber) { + return Elements.getNaturalIsotope(elementNumber); + } + public static boolean isHetero(String group3) { return JmolConstants.isHetero(group3); } Modified: trunk/Jmol/src/org/jmol/modelset/ModelCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2010-12-17 15:07:00 UTC (rev 14803) +++ trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2010-12-17 17:45:39 UTC (rev 14804) @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.BitSet; +import java.util.Calendar; import java.util.Enumeration; import java.util.Hashtable; import java.util.Iterator; @@ -3002,28 +3003,43 @@ return bsResult; } - public String getModelExtract(BitSet bs, boolean doTransform, boolean isModelKit) { + public String getModelExtract(BitSet bs, boolean doTransform, boolean isModelKit, boolean asSDF) { int nAtoms = 0; int nBonds = 0; int[] atomMap = new int[atomCount]; StringBuffer mol = new StringBuffer(); String name = (isModelKit ? "Jmol Model Kit" : viewer.getFullPathName()); - mol.append(name).append("\nJmol version ").append(Viewer.getJmolVersion()) - .append("\nEXTRACT: ").append(Escape.escape(bs)).append("\n"); - StringBuffer s = new StringBuffer(); + mol.append(name); + String version = Viewer.getJmolVersion(); + if (asSDF) { + Calendar c = Calendar.getInstance(); + mol.append("\nRH Jmol-").append(version.substring(0, 2)); + TextFormat.rFill(mol, " 00", "" + c.get(Calendar.MONTH)); + TextFormat.rFill(mol, "00", "" + c.get(Calendar.DAY_OF_MONTH)); + mol.append(("" + c.get(Calendar.YEAR)).substring(2,4)); + TextFormat.rFill(mol, "00", "" + c.get(Calendar.HOUR_OF_DAY)); + TextFormat.rFill(mol, "00", "" + c.get(Calendar.MINUTE)); + mol.append("3D 1 1.00000 0.00000 0"); + // This line has the format: + // IIPPPPPPPPMMDDYYHHmmddSSssssssssssEEEEEEEEEEEERRRRRR + // (FORTRAN: A2<--A8--><---A10-->A2I2<--F10.5-><---F12.5--><-I6-> ) + } + mol.append("\nJmol version ").append(Viewer.getJmolVersion()).append(asSDF ? " " : "\n") + .append("EXTRACT: ").append(Escape.escape(bs)).append("\n"); + StringBuffer sb = new StringBuffer(); Quaternion q = (doTransform ? viewer.getRotationQuaternion() : null); Point3f pTemp = new Point3f(); for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { if (q != null && atoms[i].isDeleted()) continue; atomMap[i] = ++nAtoms; - getAtomRecordMOL(s, i, q, pTemp); + getAtomRecordMOL(sb, atoms[i], q, pTemp, asSDF); } for (int i = 0; i < bondCount; i++) { Bond bond = bonds[i]; if (bs.get(bond.atom1.index) && bs.get(bond.atom2.index)) { if (!bond.isHydrogen()) { - getBondRecordMOL(s, i, atomMap); + getBondRecordMOL(sb, i, atomMap, asSDF); nBonds++; } } @@ -3035,31 +3051,45 @@ // 21 21 0 0 0 TextFormat.rFill(mol, " ", "" + nAtoms); TextFormat.rFill(mol, " ", "" + nBonds); - mol.append(" 0 0 0\n"); - mol.append(s); + mol.append(asSDF ? " 0 0 0 0 1 V2000" : "").append("\n"); + // lllfffcccsssxxxrrrpppiiimmmvvvvvv + mol.append(sb); + if (asSDF) + mol.append("M END\n$$$$\n"); return mol.toString(); } - private void getAtomRecordMOL(StringBuffer s, int i, Quaternion q, Point3f pTemp){ + private void getAtomRecordMOL(StringBuffer sb, Atom a, Quaternion q, Point3f pTemp, boolean asSDF){ // -0.9920 3.2030 9.1570 Cl 0 0 0 0 0 // 3.4920 4.0920 5.8700 Cl 0 0 0 0 0 //012345678901234567890123456789012 if (q == null) - pTemp.set(atoms[i]); + pTemp.set(a); else - q.transform(atoms[i], pTemp); - TextFormat.rFill(s, " " ,TextFormat.safeTruncate(pTemp.x,9)); - TextFormat.rFill(s, " " ,TextFormat.safeTruncate(pTemp.y,9)); - TextFormat.rFill(s, " " ,TextFormat.safeTruncate(pTemp.z,9)); - s.append(" ").append(((atoms[i].isDeleted() ? "Xx" - : getElementSymbol(i)) + " ").substring(0,2)).append("\n"); + q.transform(a, pTemp); + TextFormat.rFill(sb, " " ,TextFormat.safeTruncate(pTemp.x,9)); + TextFormat.rFill(sb, " " ,TextFormat.safeTruncate(pTemp.y,9)); + TextFormat.rFill(sb, " " ,TextFormat.safeTruncate(pTemp.z,9)); + sb.append(" ").append(a.isDeleted() ? "Xx" + : asSDF ? (Elements.elementSymbolFromNumber(a.getElementNumber()) + " ").substring(0,2) + : getElementSymbol(a.index)); + if (asSDF) { + sb.append(" "); + int iso = a.getIsotopeNumber(); + if (iso > 0) + iso -= Elements.getNaturalIsotope(a.getElementNumber()); + TextFormat.rFill(sb, " " ,"" + iso); + TextFormat.rFill(sb, " ", "" + a.getFormalCharge()); + sb.append(" 0 0 0 0"); + } + sb.append("\n"); } - private void getBondRecordMOL(StringBuffer s, int i,int[] atomMap){ - // 1 2 1 + private void getBondRecordMOL(StringBuffer sb, int i,int[] atomMap, boolean asSDF){ + // 1 2 1 0 Bond b = bonds[i]; - TextFormat.rFill(s, " ","" + atomMap[b.atom1.index]); - TextFormat.rFill(s, " ","" + atomMap[b.atom2.index]); + TextFormat.rFill(sb, " ","" + atomMap[b.atom1.index]); + TextFormat.rFill(sb, " ","" + atomMap[b.atom2.index]); int order = b.getValence(); if (order > 3) order = 1; @@ -3077,7 +3107,10 @@ order = 7; break; } - s.append(" ").append(order).append("\n"); + sb.append(" ").append(order); + if (asSDF) + sb.append(" 0 0 0"); + sb.append("\n"); } @Override @@ -3785,7 +3818,7 @@ tainted[TAINT_ELEMENT].andNot(bs); } models[i].loadScript = new StringBuffer(); - Viewer.getInlineData(commands, getModelExtract(bs, false, true), i > 0); + Viewer.getInlineData(commands, getModelExtract(bs, false, true, false), i > 0); } else { commands.append(models[i].loadScript); } Modified: trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2010-12-17 15:07:00 UTC (rev 14803) +++ trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2010-12-17 17:45:39 UTC (rev 14804) @@ -13233,7 +13233,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;cml")) { + } else if (Parser.isOneOf(val.toLowerCase(), "xyz;mol;sdf;pdb;cml")) { type = val.toUpperCase(); if (pt + 1 == argCount) pt++; @@ -13331,12 +13331,12 @@ && !Parser .isOneOf( type, - "ZIP;ZIPALL;SPT;HIS;MO;ISO;ISOX;MESH;PMESH;VAR;FILE;CML;XYZ;MENU;MOL;PDB;PGRP;QUAT;RAMA;FUNCS;")) + "ZIP;ZIPALL;SPT;HIS;MO;ISO;ISOX;MESH;PMESH;VAR;FILE;FUNCS;CML;XYZ;MENU;MOL;PDB;PGRP;QUAT;RAMA;SDF;")) error( ERROR_writeWhat, "COORDS|FILE|FUNCTIONS|HISTORY|IMAGE|ISOSURFACE|JMOL|MENU|MO|POINTGROUP|QUATERNION [w,x,y,z] [derivative]" + "|RAMACHANDRAN|SPT|STATE|VAR x|ZIP|ZIPALL CLIPBOARD", - "CML|GIF|JPG|JPG64|JVXL|MESH|MOL|PDB|PMESH|PNG|PPM|SPT|XJVXL|XYZ|ZIP" + "CML|GIF|JPG|JPG64|JVXL|MESH|MOL|PDB|PMESH|PNG|PPM|SDF|SPT|XJVXL|XYZ|ZIP" + driverList.toUpperCase().replace(';', '|')); if (isSyntaxCheck) return ""; @@ -13396,9 +13396,9 @@ doDefer = true; if ("?".equals(fileName)) fileName = "?Jmol." + viewer.getParameter("_fileType"); - } else if (data == "MOL" && isCoord) { - data = viewer.getModelExtract("selected", true); - } else if (data == "XYZ" || data == "MOL" || data == "CML") { + } else if ((data == "SDF" || data == "MOL") && isCoord) { + data = viewer.getModelExtract("selected", true, data == "SDF"); + } else if (data == "XYZ" || data == "MOL" || data == "SDF" || data == "CML") { data = viewer.getData("selected", data); } else if (data == "FUNCS") { data = viewer.getFunctionCalls(null); Modified: trunk/Jmol/src/org/jmol/util/Elements.java =================================================================== --- trunk/Jmol/src/org/jmol/util/Elements.java 2010-12-17 15:07:00 UTC (rev 14803) +++ trunk/Jmol/src/org/jmol/util/Elements.java 2010-12-17 17:45:39 UTC (rev 14804) @@ -392,6 +392,21 @@ return 0; } + private static int[] naturalIsotopeMasses = { + 1, 1, // H + 6, 12,// C + 7, 14,// N + 8, 16,// O -- can add any number more if desired + }; + + public static int getNaturalIsotope(int elementNumber) { + for (int i = 0; i < naturalIsotopeMasses.length; i += 2) + if (naturalIsotopeMasses[i] == elementNumber) + return naturalIsotopeMasses[++i]; + return 0; + } + + // add as we go private final static String naturalIsotopes = "1H,12C,14N,"; @@ -443,4 +458,5 @@ "", }; + } Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2010-12-17 15:07:00 UTC (rev 14803) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2010-12-17 17:45:39 UTC (rev 14804) @@ -3,6 +3,7 @@ version=12.1.26_dev +# new feature: write SDF creates V2000 SDfile; see http://www.symyx.com/downloads/public/ctfile/ctfile.pdf # bug fix: Web Export and write xx.jmol fail for load XXX:: forcing file type # code: JUnit test for file reading GenNBO and CIF files lacks viewer object # bug fix: GenNBO reader does not read MOs properly Modified: trunk/Jmol/src/org/jmol/viewer/PropertyManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/PropertyManager.java 2010-12-17 15:07:00 UTC (rev 14803) +++ trunk/Jmol/src/org/jmol/viewer/PropertyManager.java 2010-12-17 17:45:39 UTC (rev 14804) @@ -371,7 +371,7 @@ case PROP_CHAIN_INFO: return viewer.getAllChainInfo(myParam); case PROP_EXTRACT_MODEL: - return viewer.getModelExtract(myParam, true); + return viewer.getModelExtract(myParam, true, false); case PROP_FILENAME: return viewer.getFullPathName(); case PROP_FILEHEADER: Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2010-12-17 15:07:00 UTC (rev 14803) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2010-12-17 17:45:39 UTC (rev 14804) @@ -7520,8 +7520,8 @@ scriptEditor.setVisible(true); } - public String getModelExtract(Object atomExpression, boolean doTransform) { - return modelSet.getModelExtract(getAtomBitSet(atomExpression), doTransform, false); + public String getModelExtract(Object atomExpression, boolean doTransform, boolean asSDF) { + return modelSet.getModelExtract(getAtomBitSet(atomExpression), doTransform, false, asSDF); } // //////////////////////////////////////////////// @@ -7665,8 +7665,8 @@ @Override public String getData(String atomExpression, String type) { String exp = ""; - if (type.equalsIgnoreCase("MOL")) - return getModelExtract(atomExpression, false); + if (type.equalsIgnoreCase("MOL") || type.equalsIgnoreCase("SDF")) + return getModelExtract(atomExpression, false, type.equalsIgnoreCase("SDF")); if (type.toLowerCase().indexOf("property_") == 0) exp = "{selected}.label(\"%{" + type + "}\")"; else if (type.equalsIgnoreCase("CML")) @@ -9313,7 +9313,7 @@ bs = getModelUndeletedAtomsBitSet(modelIndex); sb.append("zap "); sb.append(Escape.escape(bs)).append(";"); - DataManager.getInlineData(sb, modelSet.getModelExtract(bs, false, true), true, null); + DataManager.getInlineData(sb, modelSet.getModelExtract(bs, false, true, false), true, null); sb.append("set refreshing false;") .append(actionManager.getPickingState()).append( transformManager.getMoveToText(0, false)).append( This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |