From: Miguel <mig...@us...> - 2004-05-27 23:04:01
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/viewer/datamodel In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9239/src/org/openscience/jmol/viewer/datamodel Modified Files: Frame.java FrameBuilder.java Log Message: moved more stuff from Frame to FrameBuilder Index: Frame.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/viewer/datamodel/Frame.java,v retrieving revision 1.100 retrieving revision 1.101 diff -u -r1.100 -r1.101 --- Frame.java 27 May 2004 17:35:23 -0000 1.100 +++ Frame.java 27 May 2004 23:03:48 -0000 1.101 @@ -31,7 +31,6 @@ import javax.vecmath.Point3f; import javax.vecmath.Matrix3f; import javax.vecmath.Vector3f; -import java.util.Hashtable; import java.util.BitSet; import java.awt.Rectangle; @@ -47,16 +46,15 @@ Graphics3D g3d; // the maximum BondingRadius seen in this set of atoms // used in autobonding - float maxBondingRadius = 0; - float maxVanderwaalsRadius = 0; + float maxBondingRadius = Integer.MIN_VALUE; + float maxVanderwaalsRadius = Integer.MIN_VALUE; - final static int growthIncrement = 128; - // public short modelIDs[]; - int atomCount = 0; + int atomCount; public Atom[] atoms; Object[] clientAtomReferences; - int bondCount = 0; + int bondCount; public Bond[] bonds; + private final static int growthIncrement = 250; boolean fileCoordinatesAreFractional; public float[] notionalUnitcell; public Matrix3f matrixNotional; @@ -69,16 +67,13 @@ BitSet elementsPresent; BitSet groupsPresent; - public Frame(JmolViewer viewer, String modelTypeName, int atomCount) { + public Frame(JmolViewer viewer, String modelTypeName) { this.viewer = viewer; // NOTE: these strings are interned and are lower case // therefore, we can do == comparisions against string constants // if (modelTypeName == "xyz") { } this.modelTypeName = modelTypeName.toLowerCase().intern(); mmset = new Mmset(this); - // modelIDs = new short[10]; - atoms = new Atom[atomCount]; - bonds = new Bond[atomCount * 2]; this.frameRenderer = viewer.getFrameRenderer(); this.g3d = viewer.g3d; @@ -95,7 +90,6 @@ } public void freeze() { - htAtomMap = null; if (notionalUnitcell != null) doUnitcellStuff(); if (viewer.getAutoBond()) { @@ -103,10 +97,18 @@ (modelTypeName == "pdb" && (bondCount < (atomCount / 2)))) rebond(false); } + if (atomCount < atoms.length) + atoms = (Atom[])Util.setLength(atoms, atomCount); + if (clientAtomReferences != null && + atomCount < clientAtomReferences.length) + clientAtomReferences = + (Object[])Util.setLength(clientAtomReferences, atomCount); + if (bondCount < bonds.length) + bonds = (Bond[])Util.setLength(bonds, bondCount); hackAtomSerialNumbersForAnimations(); - mmset.freeze(); findElementsPresent(); findGroupsPresent(); + mmset.freeze(); } void hackAtomSerialNumbersForAnimations() { @@ -128,31 +130,6 @@ } - void addAtom(Group group, Atom atom, - Object atomUid, Object clientAtomReference) { - if (atomCount == atoms.length) - atoms = (Atom[])Util.setLength(atoms, atomCount + growthIncrement); - atoms[atomCount] = atom; - if (clientAtomReference != null) { - if (clientAtomReferences == null) - clientAtomReferences = new Object[atoms.length]; - else if (clientAtomReferences.length <= atomCount) - clientAtomReferences = - (Object[])Util.setLength(clientAtomReferences, atoms.length); - clientAtomReferences[atomCount] = clientAtomReference; - } - ++atomCount; - htAtomMap.put(atomUid, atom); - if (bspf != null) - bspf.addTuple(atom.modelIndex, atom); - float bondingRadius = atom.getBondingRadiusFloat(); - if (bondingRadius > maxBondingRadius) - maxBondingRadius = bondingRadius; - float vdwRadius = atom.getVanderwaalsRadiusFloat(); - if (vdwRadius > maxVanderwaalsRadius) - maxVanderwaalsRadius = vdwRadius; - } - public int getAtomIndexFromAtomNumber(int atomNumber) { for (int i = atomCount; --i >= 0; ) { if (atoms[i].getAtomNumber() == atomNumber) @@ -201,8 +178,6 @@ return bonds[bondIndex]; } - private Hashtable htAtomMap = new Hashtable(); - private void addBond(Bond bond) { if (bond == null) return; @@ -211,29 +186,6 @@ bonds[bondCount++] = bond; } - public void bondAtoms(Object atomUid1, Object atomUid2, - int order) { - Atom atom1 = (Atom)htAtomMap.get(atomUid1); - if (atom1 == null) { - System.out.println("Frame.bondAtoms cannot find atomUid1?"); - return; - } - Atom atom2 = (Atom)htAtomMap.get(atomUid2); - if (atom2 == null) { - System.out.println("Frame.bondAtoms cannot find atomUid2?"); - return; - } - addBond(atom1.bondMutually(atom2, order)); - } - - public void bondAtoms(Atom atom1, Object clientAtom2, - int order) { - Atom atom2 = (Atom)htAtomMap.get(clientAtom2); - if (atom2 == null) - return; - addBond(atom1.bondMutually(atom2, order)); - } - public void bondAtoms(Atom atom1, Atom atom2, int order) { addBond(atom1.bondMutually(atom2, order)); @@ -273,11 +225,6 @@ public void setShapeProperty(int shapeType, String propertyName, Object value, BitSet bsSelected) { - /* - System.out.println("Frame.setShapeProperty(" + - JmolConstants.shapeClassBases[shapeType] + - "," + propertyName + "," + value + ")"); - */ if (shapes[shapeType] != null) shapes[shapeType].setProperty(propertyName, value, bsSelected); } @@ -436,23 +383,6 @@ } return maxRadius; - - /* - // check the 8 corners of the bounding box - float maxRadius2 = center.distanceSquared(bboxVertices[7]); - for (int i = 7; --i >= 0; ) { - float radius2 = center.distanceSquared(bboxVertices[i]); - if (radius2 > maxRadius2) - maxRadius2 = radius2; - } - if (unitcellVertices != null) { - for (int i = 8; --i >= 0; ) { - float radius2 = center.distanceSquared(bboxVertices[i]); - if (radius2 > maxRadius2) - maxRadius2 = radius2; - } - } - */ } final static int measurementGrowthIncrement = 16; @@ -472,7 +402,7 @@ final static int selectionPixelLeeway = 5; public int findNearestAtomIndex(int x, int y) { - /**************************************************************** + /* * This algorithm assumes that atoms are circles at the z-depth * of their center point. Therefore, it probably has some flaws * around the edges when dealing with intersecting spheres that @@ -657,6 +587,8 @@ public void rebond(boolean deleteFirst) { if (deleteFirst) deleteAllBonds(); + if (maxBondingRadius == Integer.MIN_VALUE) + findMaxRadii(); bondTolerance = viewer.getBondTolerance(); minBondDistance = viewer.getMinBondDistance(); minBondDistance2 = minBondDistance*minBondDistance; @@ -815,6 +747,8 @@ } public float getMaxVanderwaalsRadius() { + if (maxVanderwaalsRadius == Integer.MIN_VALUE) + findMaxRadii(); return maxVanderwaalsRadius; } @@ -882,14 +816,6 @@ matrixEuclideanToFractional = new Matrix3f(); matrixEuclideanToFractional.invert(matrixFractionalToEuclidean); } - /* - System.out.println("matrixNotional\n" + - matrixNotional + - "matrixFractionalToEuclidean\n" + - matrixFractionalToEuclidean + "\n" + - "matrixEuclideanToFractional\n" + - matrixEuclideanToFractional); - */ } final static float toRadians = (float)Math.PI * 2 / 360; @@ -933,7 +859,7 @@ } void putAtomsInsideUnitcell() { - /**************************************************************** + /* * find connected-sets ... aka 'molecules' * convert to fractional coordinates * for each connected-set @@ -1032,6 +958,18 @@ } } + void findMaxRadii() { + for (int i = atomCount; --i >= 0; ) { + Atom atom = atoms[i]; + float bondingRadius = atom.getBondingRadiusFloat(); + if (bondingRadius > maxBondingRadius) + maxBondingRadius = bondingRadius; + float vdwRadius = atom.getVanderwaalsRadiusFloat(); + if (vdwRadius > maxVanderwaalsRadius) + maxVanderwaalsRadius = vdwRadius; + } + } + public BitSet getGroupsPresentBitSet() { return groupsPresent; } Index: FrameBuilder.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/viewer/datamodel/FrameBuilder.java,v retrieving revision 1.35 retrieving revision 1.36 diff -u -r1.35 -r1.36 --- FrameBuilder.java 27 May 2004 17:35:23 -0000 1.35 +++ FrameBuilder.java 27 May 2004 23:03:48 -0000 1.36 @@ -26,6 +26,7 @@ import org.jmol.api.ModelAdapter; import org.openscience.jmol.viewer.*; +import java.util.Hashtable; import javax.vecmath.Point3f; final public class FrameBuilder { @@ -43,12 +44,11 @@ } public Frame buildFrame(Object clientFile) { - initializeBuild(); long timeBegin = System.currentTimeMillis(); String fileTypeName = adapter.getFileTypeName(clientFile); - int atomCount = adapter.getAtomCount(clientFile); + initializeBuild(adapter.getAtomCount(clientFile)); - Frame frame = new Frame(viewer, fileTypeName, atomCount); + Frame frame = new Frame(viewer, fileTypeName); /**************************************************************** * crystal cell must come first, in case atom coordinates @@ -90,9 +90,9 @@ adapter.getBondIterator(clientFile); if (iterBond != null) while (iterBond.hasNext()) - frame.bondAtoms(iterBond.getAtomUid1(), - iterBond.getAtomUid2(), - iterBond.getOrder()); + bondAtoms(iterBond.getAtomUid1(), + iterBond.getAtomUid2(), + iterBond.getOrder()); } ModelAdapter.StructureIterator iterStructure = @@ -106,6 +106,12 @@ iterStructure.getEndSequenceNumber(), iterStructure.getEndInsertionCode()); + frame.atomCount = atomCount; + frame.atoms = atoms; + frame.clientAtomReferences = clientAtomReferences; + frame.bondCount = bondCount; + frame.bonds = bonds; + frame.freeze(); long msToBuild = System.currentTimeMillis() - timeBegin; System.out.println("Build a frame:" + msToBuild + " ms"); @@ -114,6 +120,8 @@ return frame; } + private final static int ATOM_GROWTH_INCREMENT = 2000; + int currentModelID; Model currentModel; char currentChainID; @@ -121,20 +129,43 @@ int currentGroupSequenceNumber; char currentGroupInsertionCode; Group currentGroup; + + int atomCount; + Atom[] atoms; + Object[] clientAtomReferences; + + int bondCount; + Bond[] bonds; + + private final Hashtable htAtomMap = new Hashtable(); + - void initializeBuild() { + void initializeBuild(int atomCountEstimate) { currentModelID = Integer.MIN_VALUE; currentModel = null; currentChainID = '\uFFFF'; currentChain = null; currentGroupInsertionCode = '\uFFFF'; currentGroup = null; + + this.atomCount = 0; + if (atomCountEstimate <= 0) + atomCountEstimate = ATOM_GROWTH_INCREMENT; + atoms = new Atom[atomCountEstimate]; + clientAtomReferences = null; + this.bondCount = 0; + bonds = new Bond[2 * atomCountEstimate]; + htAtomMap.clear(); } void finalizeBuild() { currentModel = null; currentChain = null; currentGroup = null; + atoms = null; + clientAtomReferences = null; + bonds = null; + htAtomMap.clear(); } @@ -180,7 +211,41 @@ isHetero, atomSerial, chainID, vectorX, vectorY, vectorZ); currentGroup.registerAtom(atom); - frame.addAtom(currentGroup, atom, atomUid, clientAtomReference); + + if (atomCount == atoms.length) + atoms = (Atom[])Util.setLength(atoms, atomCount + ATOM_GROWTH_INCREMENT); + atoms[atomCount] = atom; + if (clientAtomReference != null) { + if (clientAtomReferences == null) + clientAtomReferences = new Object[atoms.length]; + else if (clientAtomReferences.length <= atomCount) + clientAtomReferences = + (Object[])Util.setLength(clientAtomReferences, atoms.length); + clientAtomReferences[atomCount] = clientAtomReference; + } + ++atomCount; + htAtomMap.put(atomUid, atom); } + public void bondAtoms(Object atomUid1, Object atomUid2, + int order) { + Atom atom1 = (Atom)htAtomMap.get(atomUid1); + if (atom1 == null) { + System.out.println("bondAtoms cannot find atomUid1?"); + return; + } + Atom atom2 = (Atom)htAtomMap.get(atomUid2); + if (atom2 == null) { + System.out.println("bondAtoms cannot find atomUid2?"); + return; + } + if (bondCount == bonds.length) + bonds = (Bond[])Util.setLength(bonds, + bondCount + 2 * ATOM_GROWTH_INCREMENT); + // note that if the atoms are already bonded then + // Atom.bondMutually(...) will return null + Bond bond = atom1.bondMutually(atom2, order); + if (bond != null) + bonds[bondCount++] = bond; + } } |