From: <ha...@us...> - 2010-05-17 20:08:40
|
Revision: 13118 http://jmol.svn.sourceforge.net/jmol/?rev=13118&view=rev Author: hansonr Date: 2010-05-17 20:08:33 +0000 (Mon, 17 May 2010) Log Message: ----------- version=12.0.RC12_dev # new feature: m = compare({2.1},{1.1},"smilesString..." [,"stddev"]) # does a MATCH of atoms, then a compare # bug fix: SMILES business not working outside of first frame Modified Paths: -------------- trunk/Jmol/src/org/jmol/api/SmilesMatcherInterface.java trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java trunk/Jmol/src/org/jmol/script/Token.java trunk/Jmol/src/org/jmol/smiles/SmilesAtom.java trunk/Jmol/src/org/jmol/smiles/SmilesMatcher.java trunk/Jmol/src/org/jmol/smiles/SmilesSearch.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Modified: trunk/Jmol/src/org/jmol/api/SmilesMatcherInterface.java =================================================================== --- trunk/Jmol/src/org/jmol/api/SmilesMatcherInterface.java 2010-05-17 19:40:30 UTC (rev 13117) +++ trunk/Jmol/src/org/jmol/api/SmilesMatcherInterface.java 2010-05-17 20:08:33 UTC (rev 13118) @@ -2,18 +2,21 @@ import java.util.BitSet; - - - public interface SmilesMatcherInterface { - public abstract BitSet getSubstructureSet(String smiles, JmolNode[] atoms, int atomCount, BitSet bsSelected, boolean isSearch, boolean isAll) + public abstract BitSet getSubstructureSet(String smiles, JmolNode[] atoms, + int atomCount, BitSet bsSelected, + boolean isSearch, boolean isAll) throws Exception; + public abstract int[][] getCorrelationMaps(String smiles, JmolNode[] atoms, + int atomCount, BitSet bsSelected, + boolean isSearch, boolean isAll) throws Exception; + public abstract BitSet[] getSubstructureSetArray(String smiles, JmolNode[] atoms, int atomCount, BitSet bsSelected, BitSet bsRequired, BitSet bsNot, BitSet bsAromatic, boolean isSearch, boolean isAll) throws Exception; public abstract int find(String pattern,/* ...in... */ String smiles, boolean isSearch, boolean isAll); + - } Modified: trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2010-05-17 19:40:30 UTC (rev 13117) +++ trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2010-05-17 20:08:33 UTC (rev 13118) @@ -40,6 +40,7 @@ import org.jmol.api.JmolEdge; import org.jmol.g3d.Graphics3D; +import org.jmol.modelset.Atom; import org.jmol.modelset.BoxInfo; import org.jmol.modelset.MeasurementData; import org.jmol.modelset.Bond.BondSet; @@ -715,23 +716,85 @@ return false; } - private boolean evaluateCompare(ScriptVariable[] args, int tok) throws ScriptException { - // compare({bitset} or [{positions}],{bitset} or [{positions}]) - // returns matrix4f for rotation/translation - Vector ptsA, ptsB; - if (args.length < 2) + private boolean evaluateCompare(ScriptVariable[] args, int tok) + throws ScriptException { + // compare({bitset} or [{positions}],{bitset} or [{positions}] [,"stddev"]) + // compare({bitset},{bitset},smilesString [,"stddev"]) + // returns matrix4f for rotation/translation or stddev + if (args.length < 2 || args.length > 4) return false; - ptsA = eval.getPointVector(args[0].value, 0); - ptsB = eval.getPointVector(args[1].value, 0); - if (ptsA == null || ptsB == null) + float stddev; + String sOpt = ScriptVariable.sValue(args[args.length - 1]); + boolean isStdDev = sOpt.equalsIgnoreCase("stddev"); + boolean isSmiles = (args.length == (isStdDev ? 4 : 3)); + if (isSmiles + && (args[0].tok != Token.bitset || args[1].tok != Token.bitset)) return false; Matrix4f m = new Matrix4f(); - float stddev = Measure.getTransformMatrix4(ptsA, ptsB, m, null); - if (args.length == 3 && ScriptVariable.sValue(args[2]).equalsIgnoreCase("stddev")) - return addX(stddev); - return addX(m); + if (isSyntaxCheck) { + m.setIdentity(); + stddev = 0; + } else { + Vector ptsA, ptsB; + if (isSmiles) { + ptsA = new Vector(); + ptsB = new Vector(); + if (args.length == 4) + sOpt = ScriptVariable.sValue(args[2]); + stddev = getSmilesCorrelation((BitSet) args[0].value, + (BitSet) args[1].value, sOpt, ptsA, ptsB, m); + if (Float.isNaN(stddev)) + return false; + } else { + ptsA = eval.getPointVector(args[0].value, 0); + ptsB = eval.getPointVector(args[1].value, 0); + if (ptsA == null || ptsB == null) + return false; + stddev = Measure.getTransformMatrix4(ptsA, ptsB, m, null); + } + } + return (isStdDev ? addX(stddev) : addX(m)); } + private float getSmilesCorrelation(BitSet bsA, BitSet bsB, String smiles, + Vector ptsA, Vector ptsB, Matrix4f m) + throws ScriptException { + try { + Atom[] atoms = viewer.getModelSet().atoms; + int atomCount = viewer.getAtomCount(); + int[][] maps = viewer.getSmilesMatcher().getCorrelationMaps(smiles, + atoms, atomCount, bsA, false, false); + if (maps.length == 0) + return Float.NaN; + for (int i = 0; i < maps[0].length; i++) + ptsA.add(atoms[maps[0][i]]); + maps = viewer.getSmilesMatcher().getCorrelationMaps(smiles, atoms, + atomCount, bsB, false, true); + if (maps.length == 0) + return Float.NaN; + float lowestStdDev = Float.MAX_VALUE; + int[] mapB = null; + for (int i = 0; i < maps.length; i++) { + ptsB.clear(); + for (int j = 0; j < maps[i].length; j++) + ptsB.add(atoms[maps[i][j]]); + float stddev = Measure.getTransformMatrix4(ptsA, ptsB, m, null); + if (stddev < lowestStdDev) { + mapB = maps[i]; + lowestStdDev = stddev; + } + } + for (int i = 0; i < mapB.length; i++) + ptsB.add(atoms[mapB[i]]); + return lowestStdDev; + } catch (Exception e) { + // e.printStackTrace(); + eval.evalError(e.getMessage(), null); + return 0; // unattainable + } + } + + private boolean evaluateVolume(ScriptVariable[] args) throws ScriptException { ScriptVariable x1 = getX(); if (isSyntaxCheck) Modified: trunk/Jmol/src/org/jmol/script/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/script/Token.java 2010-05-17 19:40:30 UTC (rev 13117) +++ trunk/Jmol/src/org/jmol/script/Token.java 2010-05-17 20:08:33 UTC (rev 13118) @@ -634,14 +634,17 @@ public final static int point = 10 | 0 << 9 | mathfunc; final static int quaternion = 11 | 0 << 9 | mathfunc | scriptCommand; final static int axisangle = 12 | 0 << 9 | mathfunc; + final static int compare = 13 | 0 << 9 | mathfunc | scriptCommand; // xxx(a,b,c,d,e) - final static int within = 13 | 0 << 9 | mathfunc; - public final static int connected = 14 | 0 << 9 | mathfunc; - public final static int helix = 15 | 0 << 9 | mathfunc | predefinedset; + final static int within = 14 | 0 << 9 | mathfunc; + public final static int connected = 15 | 0 << 9 | mathfunc; + public final static int helix = 16 | 0 << 9 | mathfunc | predefinedset; - final static int now = 16 | 0 << 9 | mathfunc; + // xxx() + + final static int now = 17 | 0 << 9 | mathfunc; // xxx(a) @@ -694,7 +697,6 @@ // xxx(a,b,c) - final static int compare = 1 | 3 << 9 | mathfunc | scriptCommand; final static int find = 2 | 3 << 9 | mathfunc | mathproperty; final static int hkl = 3 | 3 << 9 | mathfunc; final static int select = 4 | 3 << 9 | mathfunc | atomExpressionCommand; Modified: trunk/Jmol/src/org/jmol/smiles/SmilesAtom.java =================================================================== --- trunk/Jmol/src/org/jmol/smiles/SmilesAtom.java 2010-05-17 19:40:30 UTC (rev 13117) +++ trunk/Jmol/src/org/jmol/smiles/SmilesAtom.java 2010-05-17 20:08:33 UTC (rev 13118) @@ -116,7 +116,10 @@ public String toString() { - return "[" + Elements.elementSymbolFromNumber(elementNumber) + String s = (elementNumber == -1 ? "A" : elementNumber == -2 ? "*" : Elements.elementSymbolFromNumber(elementNumber)); + if (isAromatic) + s = s.toLowerCase(); + return "[" + s + '.' + index + (matchingAtom >= 0 ? "(" + matchingAtom + ")" : "") // + " ch:" + charge // + " ar:" + isAromatic Modified: trunk/Jmol/src/org/jmol/smiles/SmilesMatcher.java =================================================================== --- trunk/Jmol/src/org/jmol/smiles/SmilesMatcher.java 2010-05-17 19:40:30 UTC (rev 13117) +++ trunk/Jmol/src/org/jmol/smiles/SmilesMatcher.java 2010-05-17 20:08:33 UTC (rev 13118) @@ -269,4 +269,40 @@ bitsets[i] = (BitSet) vSubstructures.get(i); return bitsets; } + + /** + * Rather than returning bitsets, this method returns the + * sets of matching atoms so that a direct atom-atom correlation can be done. + * + * @param smiles + * @param atoms + * @param atomCount + * @param bsSelected + * @param isSearch + * @param isAll + * @return a set of atom correlations + * @throws Exception + * + */ + public int[][] getCorrelationMaps(String smiles, JmolNode[] atoms, + int atomCount, BitSet bsSelected, + boolean isSearch, boolean isAll) throws Exception { + SmilesSearch search = SmilesParser.getMolecule(isSearch, smiles); + search.jmolAtoms = atoms; + search.jmolAtomCount = Math.abs(atomCount); + if (atomCount < 0) + search.isSmilesFind = true; + search.bsSelected = bsSelected; + search.bsRequired = null; + search.bsNot = null; + search.setRingData(null); + search.isAll = isAll; + search.asVector = true; + search.getMaps = true; + Vector vSubstructures = (Vector) search.search(false); + int[][] maps = new int[vSubstructures.size()][]; + for (int i = 0; i < maps.length; i++) + maps[i] = (int[]) vSubstructures.get(i); + return maps; + } } Modified: trunk/Jmol/src/org/jmol/smiles/SmilesSearch.java =================================================================== --- trunk/Jmol/src/org/jmol/smiles/SmilesSearch.java 2010-05-17 19:40:30 UTC (rev 13117) +++ trunk/Jmol/src/org/jmol/smiles/SmilesSearch.java 2010-05-17 20:08:33 UTC (rev 13118) @@ -68,6 +68,8 @@ String pattern; int patternAtomCount; boolean asVector; + boolean getMaps; + boolean haveSelected; boolean haveBondStereochemistry; boolean haveAtomStereochemistry; @@ -157,7 +159,9 @@ * */ if (asVector) - vReturn = new Vector(); + vReturn = new Vector(); +// else + // System.out.println("smilesseearch search" + pattern); for (int i = 0; i < jmolAtomCount; i++) if (!checkMatch(atoms[0], 0, i, firstAtomOnly)) break; @@ -199,9 +203,10 @@ for (int i = 0; i < atomNum; i++) { int iPrev = atoms[i].getMatchingAtom(); - if (iPrev == iAtom || atom != null - && jmolAtoms[0].getModelIndex() != atom.getModelIndex()) { + if (iPrev == iAtom) return true; + if (atom != null && jmolAtoms[atoms[0].getMatchingAtom()].getModelIndex() != atom.getModelIndex()) { + return true; } } @@ -304,6 +309,7 @@ // index because this could be a SEARCH [x,x] "sub" atom atoms[patternAtom.index].setMatchingAtom(iAtom); atomNum++; + //System.out.println("smilesSearch " + pattern + " " + atomNum); if (atomNum < patternAtomCount) { // next position... patternAtom = atoms[atomNum]; @@ -345,13 +351,22 @@ if (bsRequired != null && !bsRequired.intersects(bs)) return true; bsReturn.or(bs); + //System.out.println("smilesSearch " + pattern + " " + bs); if (asVector) { - boolean isOK = true; - for (int j = vReturn.size(); --j >= 0 && isOK;) - isOK = !(((BitSet) vReturn.get(j)).equals(bs)); - if (!isOK) - return true; - vReturn.add(bs); + if (getMaps) { + // every map is important always + int[] map = new int[patternAtomCount]; + for (int j = 0; j < patternAtomCount; j++) + map[j] = atoms[j].getMatchingAtom(); + vReturn.add(map); + } else { + boolean isOK = true; + for (int j = vReturn.size(); --j >= 0 && isOK;) + isOK = !(((BitSet) vReturn.get(j)).equals(bs)); + if (!isOK) + return true; + vReturn.add(bs); + } } /* if (!isSilent && Logger.debugging) { @@ -944,6 +959,7 @@ Vector3f vTemp = new Vector3f(); Vector3f vA = new Vector3f(); Vector3f vB = new Vector3f(); + private int getChirality(JmolNode a, JmolNode b, JmolNode c, JmolNode pt) { float d = getNormalThroughPoints((Point3f) a, (Point3f) b, (Point3f) c, vTemp, vA, vB); return (distanceToPlane(vTemp, d, (Point3f) pt) > 0 ? 1 : 2); @@ -966,7 +982,7 @@ String s = "****"; while (s.length() < ringDataMax) s += s; - for (int i = 3; i < ringDataMax + 1; i++) { + for (int i = 6; i < 7/*ringDataMax + 1*/; i++) { Vector v = (Vector) getBitSets("*1" + s.substring(0, i - 2) + "*1", false, ringSets); for (int r = v.size(); --r >= 0;) { Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2010-05-17 19:40:30 UTC (rev 13117) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2010-05-17 20:08:33 UTC (rev 13118) @@ -3,6 +3,10 @@ version=12.0.RC12_dev +# bug fix: SMILES business not working outside of first frame +# new feature: m = compare({2.1},{1.1},"smilesString..." [,"stddev"]) +# does a MATCH of atoms, then a compare + # -------------------------------------------------------------- #version=12.0.RC11 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |