From: <ha...@us...> - 2010-04-17 23:24:37
|
Revision: 12880 http://jmol.svn.sourceforge.net/jmol/?rev=12880&view=rev Author: hansonr Date: 2010-04-17 23:24:30 +0000 (Sat, 17 Apr 2010) Log Message: ----------- version=12.0.RC6 # new feature: MO MODEL x.y .... specifies which model to use # # code: atom iterators made thread safe and optimized a bit # # code: parallel processor in place; working; # tested on dual core multiple processor Mac # result -- 8 sec --> 4 sec for the two molecular surfaces # # example PARALLEL code: see http://chemapps.stolaf.edu/jmol/docs/examples-11/data/multProcessorTest.spt # # parallel makeIsos{ # process{isosurface s1 molecular} # process{isosurface s2 molecular; color isosurface green} # } # load 1crn.pdb # t = now() # makeIsos # print now() - t # # parallel: 172ms, not parallel: 281ms MacBook Pro/Windows, two processors # # print "------------------------" # parallel showMOs(i,j) { # process{mo model 1.1 @i} # process{mo model 2.1 @j} # } # # load files "C6H6.smol" "C6H6.smol" # showMOs(22,23) # frame *; # # # # code: ShapeManager created; all shape[] references out of ModelSet # code: preliminary PARALLEL {.... PROCESS {....} ....} # code: Normix3D refactoring # bug fix: set measureAllModels not working properly # bug fix: isosurface renderer subtle improvement for almost-degenerate-vertex triangles # new feature: set monitorEnergy -- preliminary idea only # bug fix: UFF carbonyl out-of-plane calculation coding error does not minimize carbonyl groups correctly Modified Paths: -------------- trunk/Jmol/src/org/jmol/bspt/Bspf.java trunk/Jmol/src/org/jmol/bspt/Bspt.java trunk/Jmol/src/org/jmol/bspt/CubeIterator.java trunk/Jmol/src/org/jmol/bspt/Element.java trunk/Jmol/src/org/jmol/bspt/Leaf.java trunk/Jmol/src/org/jmol/bspt/Node.java trunk/Jmol/src/org/jmol/modelset/AtomIteratorWithinModel.java trunk/Jmol/src/org/jmol/modelset/ModelCollection.java trunk/Jmol/src/org/jmol/script/ParallelProcessor.java trunk/Jmol/src/org/jmol/shapespecial/Polyhedra.java trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/bspt/Bspf.java =================================================================== --- trunk/Jmol/src/org/jmol/bspt/Bspf.java 2010-04-17 21:22:22 UTC (rev 12879) +++ trunk/Jmol/src/org/jmol/bspt/Bspf.java 2010-04-17 23:24:30 UTC (rev 12880) @@ -26,6 +26,8 @@ import javax.vecmath.Point3f; +import org.jmol.util.Logger; + /** * A Binary Space Partitioning Forest *<p> @@ -78,15 +80,15 @@ bspts[i].stats(); } - /* + public void dump() { for (int i = 0; i < bspts.length; ++i) { - Logger.debug(">>>>\nDumping bspt #" + i + "\n>>>>"); + Logger.info(">>>>\nDumping bspt #" + i + "\n>>>>"); bspts[i].dump(); } - Logger.debug("<<<<"); + Logger.info("<<<<"); } - */ + /* public SphereIterator getSphereIterator(int bsptIndex) { if (bsptIndex >= sphereIterators.length) { Modified: trunk/Jmol/src/org/jmol/bspt/Bspt.java =================================================================== --- trunk/Jmol/src/org/jmol/bspt/Bspt.java 2010-04-17 21:22:22 UTC (rev 12879) +++ trunk/Jmol/src/org/jmol/bspt/Bspt.java 2010-04-17 23:24:30 UTC (rev 12880) @@ -24,6 +24,8 @@ import javax.vecmath.Point3f; +import org.jmol.util.Logger; + //import org.jmol.util.Logger; /** @@ -123,15 +125,17 @@ // } } - /* - public void dump() { - eleRoot.dump(0); + + public void dump() { + StringBuffer sb = new StringBuffer(); + eleRoot.dump(0, sb); + Logger.info(sb.toString()); } public String toString() { - return eleRoot.toString(); + return eleRoot.toString(); } - */ + /* Enumeration enum() { Modified: trunk/Jmol/src/org/jmol/bspt/CubeIterator.java =================================================================== --- trunk/Jmol/src/org/jmol/bspt/CubeIterator.java 2010-04-17 21:22:22 UTC (rev 12879) +++ trunk/Jmol/src/org/jmol/bspt/CubeIterator.java 2010-04-17 23:24:30 UTC (rev 12880) @@ -66,8 +66,9 @@ * * @param center * @param radius + * @param hemisphereOnly */ - public void initialize(Point3f center, float radius) { + public void initialize(Point3f center, float radius, boolean hemisphereOnly) { //this.center = center; this.radius = radius; tHemisphere = false; @@ -78,28 +79,10 @@ stack[0] = bspt.eleRoot; sp = 1; findLeftLeaf(); + tHemisphere = hemisphereOnly; } /** - * initialize to return all points within the hemisphere defined - * by center and radius. - *<p> - * the points returned are those that have a coordinate value >= - * to center along the first (x) dimension - *<p> - * Note that if you are iterating through all points, and two - * points are within radius and have the same - * x coordinate, then each will return the other. - * - * @param center - * @param radius - */ - public void initializeHemisphere(Point3f center, float radius) { - initialize(center, radius); - tHemisphere = true; - } - - /** * nulls internal references */ public void release() { @@ -178,7 +161,7 @@ * @param t * @return boolean */ - protected boolean isWithinRadius(Point3f t) { + private boolean isWithinRadius(Point3f t) { dx = t.x - cx; return (!tHemisphere || dx >= 0) && (dx = Math.abs(dx)) <= radius Modified: trunk/Jmol/src/org/jmol/bspt/Element.java =================================================================== --- trunk/Jmol/src/org/jmol/bspt/Element.java 2010-04-17 21:22:22 UTC (rev 12879) +++ trunk/Jmol/src/org/jmol/bspt/Element.java 2010-04-17 23:24:30 UTC (rev 12880) @@ -33,8 +33,8 @@ Bspt bspt; int count; abstract Element addTuple(int level, Point3f tuple); - /* - abstract void dump(int level); - */ + + abstract void dump(int level, StringBuffer sb); + } Modified: trunk/Jmol/src/org/jmol/bspt/Leaf.java =================================================================== --- trunk/Jmol/src/org/jmol/bspt/Leaf.java 2010-04-17 21:22:22 UTC (rev 12879) +++ trunk/Jmol/src/org/jmol/bspt/Leaf.java 2010-04-17 23:24:30 UTC (rev 12880) @@ -24,6 +24,8 @@ import javax.vecmath.Point3f; +import org.jmol.modelset.Atom; + /** * A leaf of Point3f objects in the bsp tree * @@ -73,21 +75,19 @@ return node.addTuple(level, tuple); } - /* - void dump(int level) { + + void dump(int level, StringBuffer sb) { for (int i = 0; i < count; ++i) { - Point3f t = tuples[i]; - for (int j = 0; j < level; ++j) - Logger.debug("."); - for (int dim = 0; dim < dimMax-1; ++dim) - Logger.debug("" + t.getDimensionValue(dim) + ","); - Logger.debug("" + t.getDimensionValue(dimMax - 1)); + Point3f t = tuples[i]; + for (int j = 0; j < level; ++j) + sb.append("."); + sb.append(t).append("Leaf ").append(i).append(": ").append(((Atom) t).getInfo()); } - } + } public String toString() { return "leaf:" + count + "\n"; } - */ + } Modified: trunk/Jmol/src/org/jmol/bspt/Node.java =================================================================== --- trunk/Jmol/src/org/jmol/bspt/Node.java 2010-04-17 21:22:22 UTC (rev 12879) +++ trunk/Jmol/src/org/jmol/bspt/Node.java 2010-04-17 23:24:30 UTC (rev 12880) @@ -113,21 +113,18 @@ return this; } - /* - void dump(int level) { - Logger.debug(""); - eleLE.dump(level + 1); + void dump(int level, StringBuffer sb) { + sb.append("\nnode LEFT" + level); + eleLeft.dump(level + 1, sb); for (int i = 0; i < level; ++i) - Logger.debug("-"); - Logger.debug(">" + splitValue); - eleGE.dump(level + 1); + sb.append("->"); + sb.append(" RIGHT" + level); + eleRight.dump(level + 1, sb); } public String toString() { - return eleLE.toString() + dim + ":" + - splitValue + "\n" + eleGE.toString(); + return eleLeft.toString() + dim + ":" + "\n" + eleRight.toString(); } - */ static float getDimensionValue(Point3f pt, int dim) { return (dim == 0 ? pt.x : dim == 1 ? pt.y : pt.z); Modified: trunk/Jmol/src/org/jmol/modelset/AtomIteratorWithinModel.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/AtomIteratorWithinModel.java 2010-04-17 21:22:22 UTC (rev 12879) +++ trunk/Jmol/src/org/jmol/modelset/AtomIteratorWithinModel.java 2010-04-17 23:24:30 UTC (rev 12880) @@ -38,6 +38,7 @@ private CubeIterator bsptIter; private Bspf bspf; private boolean threadSafe; + private boolean hemisphereOnly; private boolean isZeroBased; private int modelIndex = Integer.MAX_VALUE; @@ -57,15 +58,18 @@ * @param bsSelected * @param isGreaterOnly * @param isZeroBased + * @param hemisphereOnly TODO * @param threadSafe * */ - void initialize(Bspf bspf, BitSet bsSelected, boolean isGreaterOnly, boolean isZeroBased, boolean threadSafe) { + void initialize(Bspf bspf, BitSet bsSelected, boolean isGreaterOnly, + boolean isZeroBased, boolean hemisphereOnly, boolean threadSafe) { this.bspf = bspf; this.bsSelected = bsSelected; this.isGreaterOnly = isGreaterOnly; this.isZeroBased = isZeroBased; + this.hemisphereOnly = hemisphereOnly; this.threadSafe = threadSafe; } @@ -75,9 +79,10 @@ if (modelIndex != this.modelIndex || bsptIter == null) { bsptIter = bspf.getCubeIterator(modelIndex); this.modelIndex = modelIndex; + //bspf.dump(); } zeroBase = (isZeroBased ? firstModelAtom : 0); - if (distance < 0) // distance and center will be added later + if (distance == Integer.MIN_VALUE) // distance and center will be added later return; this.atomIndex = atomIndex; set(center, distance); @@ -86,41 +91,24 @@ public void set(Point3f center, float distance) { if (bsptIter == null) return; - bsptIter.initialize(center, distance); + bsptIter.initialize(center, distance, hemisphereOnly); distanceSquared = distance * distance; } -/* - private int iNext; - public boolean hasNext() { - iNext = (bsptIter == null || !bsptIter.hasMoreElements() ? -1 - : ((Atom) bsptIter.nextElement()).index); - if (atomIndex >= 0) { - while (iNext >= 0) { - if (iNext != atomIndex && iNext > (isGreaterOnly ? atomIndex : -1) - && (bsSelected == null || bsSelected.get(iNext))) - return true; - if (!bsptIter.hasMoreElements()) { - iNext = -1; - break; - } - iNext = ((Atom) bsptIter.nextElement()).index; - } - } - return (iNext >= 0); - } -*/ private int iNext; public boolean hasNext() { - if (atomIndex >= 0) + if (false && atomIndex >= 0) while (bsptIter.hasMoreElements()) { - if ((iNext = ((Atom) bsptIter.nextElement()).index) != atomIndex + Atom a = (Atom) bsptIter.nextElement(); + if ((iNext = a.index) != atomIndex && iNext > (isGreaterOnly ? atomIndex : -1) - && (bsSelected == null || bsSelected.get(iNext))) + && (bsSelected == null || bsSelected.get(iNext))) { return true; + } } else if (bsptIter.hasMoreElements()) { - iNext = ((Atom) bsptIter.nextElement()).index; + Atom a = (Atom) bsptIter.nextElement(); + iNext = a.index; return true; } iNext = -1; @@ -135,6 +123,13 @@ return (bsptIter == null ? -1 : bsptIter.foundDistance2()); } + /** + * turns this into a SPHERICAL iterator + * for "within Distance" measures + * + * @param bsResult + * + */ public void addAtoms(BitSet bsResult) { int iAtom; while (hasNext()) Modified: trunk/Jmol/src/org/jmol/modelset/ModelCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2010-04-17 21:22:22 UTC (rev 12879) +++ trunk/Jmol/src/org/jmol/modelset/ModelCollection.java 2010-04-17 23:24:30 UTC (rev 12880) @@ -1922,7 +1922,7 @@ public AtomIndexIterator getSelectedAtomIterator(BitSet bsSelected, boolean isGreaterOnly, - boolean modelZeroBased) { + boolean modelZeroBased, boolean hemisphereOnly) { //EnvelopeCalculation, IsoSolventReader // This iterator returns only atoms OTHER than the atom specified // and with the specified restrictions. @@ -1931,7 +1931,7 @@ initializeBspf(); AtomIteratorWithinModel iter = new AtomIteratorWithinModel(); - iter.initialize(bspf, bsSelected, isGreaterOnly, modelZeroBased, viewer.isMultiProcessor()); + iter.initialize(bspf, bsSelected, isGreaterOnly, modelZeroBased, hemisphereOnly, viewer.isMultiProcessor()); return iter; } @@ -2147,7 +2147,7 @@ boolean withinAllModels) { BitSet bsResult = new BitSet(); BitSet bsCheck = getIterativeModels(false); - AtomIndexIterator iter = getSelectedAtomIterator(null, false, false); + AtomIndexIterator iter = getSelectedAtomIterator(null, false, false, false); if (withinAllModels) { for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) for (int iModel = modelCount; --iModel >= 0;) { @@ -2213,7 +2213,7 @@ } BitSet bsCheck = getIterativeModels(false); - AtomIndexIterator iter = getSelectedAtomIterator(null, false, false); + AtomIndexIterator iter = getSelectedAtomIterator(null, false, false, false); for (int iModel = modelCount; --iModel >= 0;) { if (!bsCheck.get(iModel)) continue; @@ -2438,8 +2438,7 @@ float minBondDistance = viewer.getMinBondDistance(); float minBondDistance2 = minBondDistance * minBondDistance; int nNew = 0; - initializeBspf(); - if (showRebondTimes && Logger.debugging) + if (showRebondTimes)// && Logger.debugging) Logger.startTimer(); /* * miguel 2006 04 02 note that the way that these loops + iterators are @@ -2465,7 +2464,7 @@ } i0 = bsCheck.nextSetBit(0); } - CubeIterator iter = null; + AtomIndexIterator iter = getSelectedAtomIterator(null, false, false, true); for (int i = i0; i >= 0 && i < atomCount; i = (isAll ? i + 1 : bsCheck.nextSetBit(i + 1))) { boolean isAtomInSetA = (isAll || bsA.get(i)); boolean isAtomInSetB = (isAll || bsB.get(i)); @@ -2480,8 +2479,6 @@ i = models[modelIndex].firstAtomIndex + models[modelIndex].atomCount - 1; continue; } - initializeBspt(modelIndex); - iter = bspf.getCubeIterator(modelIndex); } // Covalent bonds float myBondingRadius = atom.getBondingRadiusFloat(); @@ -2489,10 +2486,10 @@ continue; boolean isFirstExcluded = (bsExclude != null && bsExclude.get(i)); float searchRadius = myBondingRadius + maxBondingRadius + bondTolerance; - iter.initializeHemisphere(atom, searchRadius); - while (iter.hasMoreElements()) { - Atom atomNear = (Atom) iter.nextElement(); - if (atomNear == atom || atomNear.isDeleted()) + setIteratorForAtom(iter, i, searchRadius); + while (iter.hasNext()) { + Atom atomNear = atoms[iter.next()]; + if (atomNear.isDeleted()) continue; int atomIndexNear = atomNear.index; boolean isNearInSetA = (isAll || bsA.get(atomIndexNear)); @@ -2512,7 +2509,7 @@ } iter.release(); } - if (showRebondTimes && Logger.debugging) + if (showRebondTimes)//&& Logger.debugging) Logger.checkTimer("Time to autoBond"); return nNew; } @@ -2593,7 +2590,7 @@ Logger.startTimer(); Point3f C = null; Point3f D = null; - AtomIndexIterator iter = getSelectedAtomIterator(bsB, false, false); + AtomIndexIterator iter = getSelectedAtomIterator(bsB, false, false, false); for (int i = bsA.nextSetBit(0); i >= 0; i = bsA.nextSetBit(i + 1)) { Atom atom = atoms[i]; Modified: trunk/Jmol/src/org/jmol/script/ParallelProcessor.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ParallelProcessor.java 2010-04-17 21:22:22 UTC (rev 12879) +++ trunk/Jmol/src/org/jmol/script/ParallelProcessor.java 2010-04-17 23:24:30 UTC (rev 12880) @@ -40,8 +40,10 @@ if (processes.size() == 0) return; this.viewer = viewer; + viewer.setParallel(true); counter = 0; System.out.println("running " + processes.size() + " processes on " + Viewer.nProcessors + " processesors"); + try { for (int i = processes.size(); --i >= 0;) { counter++; runProcess((Process) processes.remove(0)); @@ -49,6 +51,11 @@ while (counter >= 0) { Thread.yield(); } + } + catch (Exception e) { + // could be memory errors here as well + } + viewer.setParallel(false); } void mergeResults() { Modified: trunk/Jmol/src/org/jmol/shapespecial/Polyhedra.java =================================================================== --- trunk/Jmol/src/org/jmol/shapespecial/Polyhedra.java 2010-04-17 21:22:22 UTC (rev 12879) +++ trunk/Jmol/src/org/jmol/shapespecial/Polyhedra.java 2010-04-17 23:24:30 UTC (rev 12880) @@ -245,7 +245,7 @@ private void buildPolyhedra() { boolean useBondAlgorithm = radius == 0 || bondedOnly; - AtomIndexIterator iter = modelSet.getSelectedAtomIterator(null, false, false); + AtomIndexIterator iter = modelSet.getSelectedAtomIterator(null, false, false, false); for (int i = centers.nextSetBit(0); i >= 0; i = centers.nextSetBit(i + 1)) { Polyhedron p = (haveBitSetVertices ? constructBitSetPolyhedron(i) : useBondAlgorithm ? constructBondsPolyhedron(i) Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2010-04-17 21:22:22 UTC (rev 12879) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2010-04-17 23:24:30 UTC (rev 12880) @@ -1985,6 +1985,7 @@ : "|" + errMsg)); zap(errMsg); setErrorMessage(errMsg); + setParallel(false); } return getErrorMessage(); } @@ -2232,7 +2233,7 @@ public AtomIndexIterator getSelectedAtomIterator(BitSet bsSelected, boolean isGreaterOnly, boolean modelZeroBased) { - return modelSet.getSelectedAtomIterator(bsSelected, isGreaterOnly, modelZeroBased); + return modelSet.getSelectedAtomIterator(bsSelected, isGreaterOnly, modelZeroBased, false); } public void setIteratorForAtom(AtomIndexIterator iterator, int atomIndex, @@ -8322,8 +8323,13 @@ return shapeManager; } + boolean isParallel; + + public void setParallel(boolean TF) { + isParallel = TF; + } public boolean isMultiProcessor() { - return global.multiProcessor; + return global.multiProcessor && isParallel; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |