From: <ha...@us...> - 2006-04-04 02:37:58
|
Revision: 4896 Author: hansonr Date: 2006-04-03 19:37:45 -0700 (Mon, 03 Apr 2006) ViewCVS: http://svn.sourceforge.net/jmol/?rev=4896&view=rev Log Message: ----------- (1) one-line compiler correction for select connect(n,atom expression) (2) experimenting with dipoles. See http://www.stolaf.edu/people/hansonr/jmol/test/json/dipole.htm this requires: AtomSetCollection -- boolean setAtomSetPartialCharges(String auxKey) Token -- dipole Eval -- dipole() Dipole/Dipoles/DipoleRenderer classes a fundamentally a different class of class -- a non-atom object that is not a mesh and not a Rasmol object. Frame -- some dipole functions. Viewer -- global dipole scale Mostly just bringing bob200603 up to the point I took it to prior to being so rudely interrupted (by my laptop fan failure, not you, Miguel); considering the dipole issues. Modified Paths: -------------- branches/bob200603/Jmol/src/org/jmol/adapter/smarter/AtomSetCollection.java branches/bob200603/Jmol/src/org/jmol/adapter/smarter/SpartanSmolReader.java branches/bob200603/Jmol/src/org/jmol/viewer/Compiler.java branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java branches/bob200603/Jmol/src/org/jmol/viewer/Frame.java branches/bob200603/Jmol/src/org/jmol/viewer/JmolConstants.java branches/bob200603/Jmol/src/org/jmol/viewer/ModelManager.java branches/bob200603/Jmol/src/org/jmol/viewer/Token.java branches/bob200603/Jmol/src/org/jmol/viewer/Viewer.java Added Paths: ----------- branches/bob200603/Jmol/src/org/jmol/viewer/Dipole.java branches/bob200603/Jmol/src/org/jmol/viewer/Dipoles.java branches/bob200603/Jmol/src/org/jmol/viewer/DipolesRenderer.java Modified: branches/bob200603/Jmol/src/org/jmol/adapter/smarter/AtomSetCollection.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/adapter/smarter/AtomSetCollection.java 2006-04-04 02:13:20 UTC (rev 4895) +++ branches/bob200603/Jmol/src/org/jmol/adapter/smarter/AtomSetCollection.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -25,6 +25,7 @@ package org.jmol.adapter.smarter; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Vector; import java.util.Properties; class AtomSetCollection { @@ -357,6 +358,22 @@ atomSetCollectionAuxiliaryInfo.put(key, value); } + /** + * Sets the partial atomic charges based on atomSetCollection auxiliary info + * + * @param auxKey The auxiliary key name that contains the charges + * @return true if the data exist; false if not + */ + + boolean setAtomSetCollectionPartialCharges(String auxKey) { + if (! atomSetCollectionAuxiliaryInfo.containsKey(auxKey)) + return false; + Vector atomData = (Vector) atomSetCollectionAuxiliaryInfo.get(auxKey); + for (int i = atomData.size(); --i >= 0;) + atoms[i].partialCharge = ((Float)atomData.get(i)).floatValue(); + return true; + } + Object getAtomSetCollectionAuxiliaryInfo(String key) { return atomSetCollectionAuxiliaryInfo.get(key); } @@ -433,7 +450,6 @@ setAtomSetProperty(key, value, currentAtomSetIndex); } - /** * Sets auxiliary information for the AtomSet * @@ -445,6 +461,23 @@ } /** + * Sets the partial atomic charges based on atomSet auxiliary info + * + * @param auxKey The auxiliary key name that contains the charges + * @return true if the data exist; false if not + */ + + boolean setAtomSetPartialCharges(String auxKey) { + if (!atomSetAuxiliaryInfo[currentAtomSetIndex].containsKey(auxKey)) + return false; + Vector atomData = (Vector) atomSetAuxiliaryInfo[currentAtomSetIndex] + .get(auxKey); + for (int i = atomData.size(); --i >= 0;) + atoms[i].partialCharge = ((Float) atomData.get(i)).floatValue(); + return true; + } + + /** * Sets the a property for the an AtomSet * * @param key The key for the property Modified: branches/bob200603/Jmol/src/org/jmol/adapter/smarter/SpartanSmolReader.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/adapter/smarter/SpartanSmolReader.java 2006-04-04 02:13:20 UTC (rev 4895) +++ branches/bob200603/Jmol/src/org/jmol/adapter/smarter/SpartanSmolReader.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -27,6 +27,7 @@ import java.io.BufferedReader; import java.util.Vector; import java.util.Hashtable; +import javax.vecmath.Vector3f; class SpartanSmolReader extends AtomSetCollectionReader { @@ -42,10 +43,13 @@ discardLinesUntilStartsWith(reader, "BEGINARCHIVE"); if (discardLinesUntilContains(reader, "GEOMETRY") != null) readAtoms(reader); - if (discardLinesUntilContains(reader, "BEGINPROPARC") != null) + if (discardLinesUntilContains(reader, "BEGINPROPARC") != null) { readProperties(reader); - // if (discardLinesUntilContains(reader, "VIBRATIONAL FREQUENCIES") != null) - // readFrequencies(reader); + if (!atomSetCollection.setAtomSetCollectionPartialCharges("MULCHARGES")) + atomSetCollection.setAtomSetCollectionPartialCharges("Q1_CHARGES"); + if (!atomSetCollection.setAtomSetCollectionPartialCharges("MULCHARGES")) + atomSetCollection.setAtomSetCollectionPartialCharges("Q1_CHARGES"); + } } catch (Exception ex) { ex.printStackTrace(); atomSetCollection.errorMessage = "Could not read file:" + ex; @@ -92,11 +96,24 @@ && (line.length() < 10 || !line.substring(0, 10).equals("ENDPROPARC"))) { if (line.length() >= 4 && line.substring(0, 4).equals("PROP")) readProperty(reader, line); + if (line.length() >= 6 && line.substring(0, 6).equals("DIPOLE")) + readDipole(reader); if (line.length() >= 7 && line.substring(0, 7).equals("VIBFREQ")) readVibFreqs(reader); } } + void readDipole(BufferedReader reader) throws Exception { + //fall-back if no other dipole record + String line = reader.readLine(); + String tokens[] = getTokens(line); + if (tokens.length != 3) + return; + Vector3f dipole = new Vector3f(parseFloat(tokens[0]), + parseFloat(tokens[1]), parseFloat(tokens[2])); + atomSetCollection.setAtomSetCollectionAuxiliaryInfo("dipole", dipole); + } + void readProperty(BufferedReader reader, String line) throws Exception { String tokens[] = getTokens(line); if (tokens.length == 0) Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Compiler.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/Compiler.java 2006-04-04 02:13:20 UTC (rev 4895) +++ branches/bob200603/Jmol/src/org/jmol/viewer/Compiler.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -1152,10 +1152,10 @@ tokenNext(); // ( tok = tokPeek(); if (tok == Token.integer) { - token = tokenNext(); // minimum # of bonds (optional) + token = tokenNext(); // minimum # or exact # of bonds (optional) if (token.intValue < 0) nonnegativeIntegerExpected(); - min = token.intValue; + min = max = token.intValue; token = tokenNext(); tok = token.tok; if (tok == Token.rightparen) // ) Added: branches/bob200603/Jmol/src/org/jmol/viewer/Dipole.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/Dipole.java (rev 0) +++ branches/bob200603/Jmol/src/org/jmol/viewer/Dipole.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -0,0 +1,119 @@ +/* $RCSfile$ + * $Author: hansonr $ + * $Date: 2006-03-05 12:22:08 -0600 (Sun, 05 Mar 2006) $ + * $Revision: 4545 $ + * + * Copyright (C) 2002-2005 The Jmol Development Team + * + * Contact: jmo...@li... + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jmol.viewer; + +import java.util.BitSet; +import javax.vecmath.Vector3f; +import javax.vecmath.Point3f; +import org.jmol.g3d.Graphics3D; + +class Dipole extends Shape { + String dipoleID; + String dipoleInfo; + Vector3f vector; + Point3f origin; + float dipoleValue; + float offsetAngstroms; + int offsetPercent; + boolean visible; + int modelIndex; + short mad; + short colix; + Atom[] atoms = new Atom[2]; //for reference only + + Dipole() { + } + + Dipole(Viewer viewer, String dipoleID, Graphics3D g3d, short colix, short mad, boolean visible) { + this.viewer = viewer; + this.dipoleID = dipoleID; + this.g3d = g3d; + this.colix = colix; + this.mad = mad; + this.visible = visible; + } + + void initShape() { + } + + void setProperty(String propertyName, Object value, BitSet bsSelected) { + } + + void setTranslucent(boolean isTranslucent) { + colix = Graphics3D.setTranslucent(colix, isTranslucent); + } + + void set(Point3f pt1, Point3f pt2) { + origin = new Point3f(pt2); + vector = new Vector3f(pt1); + dipoleInfo = "" + origin + vector; + vector.sub(origin); + vector.scale(-dipoleValue / vector.length()); + if (dipoleValue < 0) + origin.sub(vector); + } + + void set(float value) { + float d = dipoleValue; + dipoleValue = value; + if (vector == null) + return; + vector.scale(dipoleValue / vector.length()); + if (d * dipoleValue < 0) + origin.sub(vector); + } + + void set(Point3f pt1, Point3f pt2, float value) { + set(value); + set(pt1, pt2); + } + + void set(Point3f pt1, Vector3f dipole) { + set(dipole.length()); + Point3f pt2 = new Point3f(pt1); + pt2.add(dipole); + set(pt1, pt2); + } + + void set(Point3f pt1, Vector3f dipole, int direction) { + Vector3f v = new Vector3f(dipole); + v.scale(direction); + Point3f pt2 = new Point3f(pt1); + pt2.add(v); + set(dipole.length()); + set(pt1, pt2); + } + + void set(Atom atom1, Atom atom2, float value) { + set(value); + set(atom1.point3f, atom2.point3f); + } + + void set(int atomIndex1, int atomIndex2, float value) { + set(value); + set(frame.atoms[atomIndex1].point3f, frame.atoms[atomIndex2].point3f); + } + +} Added: branches/bob200603/Jmol/src/org/jmol/viewer/Dipoles.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/Dipoles.java (rev 0) +++ branches/bob200603/Jmol/src/org/jmol/viewer/Dipoles.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -0,0 +1,333 @@ +/* $RCSfile$ + * $Author: hansonr $ + * $Date: 2006-03-12 21:37:51 -0600 (Sun, 12 Mar 2006) $ + * $Revision: 4586 $ + * + * Copyright (C) 2002-2005 The Jmol Development Team + * + * Contact: jmo...@li... + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jmol.viewer; + +import org.jmol.g3d.*; + +import java.util.BitSet; +import java.util.Vector; +import java.util.Hashtable; +import javax.vecmath.Point3f; +import javax.vecmath.Vector3f; + + +class Dipoles extends SelectionIndependentShape { + + final static short DEFAULT_MAD = 3; + final static float DEFAULT_OFFSET = 0.4f; + int dipoleCount; + Dipole[] dipoles = new Dipole[4]; + Dipole currentDipole; + Dipole tempDipole; + Point3f startCoord; + boolean iHaveID; + boolean isBond; + + void initShape() { + colix = Graphics3D.ORANGE; + } + + void setProperty(String propertyName, Object value, BitSet bs) { + + System.out.println(propertyName + " " + value); + if ("init" == propertyName) { + tempDipole = new Dipole(); + tempDipole.dipoleValue = 1; + tempDipole.mad = DEFAULT_MAD; + tempDipole.offsetAngstroms = DEFAULT_OFFSET; + tempDipole.offsetPercent = 0; + iHaveID = false; + isBond = false; + return; + } + + if ("bonds" == propertyName) { + viewer.getBondDipoles(); + currentDipole = null; + isBond = true; + return; + } + + if ("dipoleID" == propertyName) { + String dipoleID = (String) value; + if (dipoleID == null) { + currentDipole = null; + return; + } + tempDipole = currentDipole = findDipole(dipoleID); + iHaveID = true; + return; + } + + if ("on" == propertyName) { + if (currentDipole != null) + currentDipole.visible = true; + else { + for (int i = dipoleCount; --i >= 0;) + dipoles[i].visible = true; + } + return; + } + + if ("off" == propertyName) { + if (currentDipole != null) + currentDipole.visible = false; + else { + for (int i = dipoleCount; --i >= 0;) + dipoles[i].visible = false; + } + return; + } + + if ("color" == propertyName) { + if (value != null) { + colix = Graphics3D.getColix(value); + if (currentDipole != null) { + currentDipole.colix = colix; + } else { + for (int i = dipoleCount; --i >= 0;) { + dipoles[i].colix = colix; + } + } + } + return; + } + + if ("translucency" == propertyName) { + boolean isTranslucent = ("translucent" == value); + if (currentDipole != null) + currentDipole.setTranslucent(isTranslucent); + else { + for (int i = dipoleCount; --i >= 0;) + dipoles[i].setTranslucent(isTranslucent); + } + return; + } + + if ("delete" == propertyName) { + if (currentDipole != null) { + int iCurrent; + for (iCurrent = dipoleCount; dipoles[--iCurrent] != currentDipole;) { + } + for (int j = iCurrent + 1; j < dipoleCount; ++j) + dipoles[j - 1] = dipoles[j]; + dipoles[--dipoleCount] = null; + currentDipole = null; + } else { + for (int i = dipoleCount; --i >= 0;) + dipoles[i] = null; + dipoleCount = 0; + } + return; + } + + if ("startSet" == propertyName) { + startCoord = viewer.getAtomSetCenter((BitSet) value); + tempDipole.set(viewer.getAtomSetCenter(bs), startCoord); + return; + } + + if ("endSet" == propertyName) { + tempDipole.set(startCoord, viewer.getAtomSetCenter((BitSet) value)); + return; + } + + if ("startCoord" == propertyName) { + startCoord = (Point3f) value; + tempDipole.set(viewer.getAtomSetCenter(bs), startCoord); + return; + } + + if ("endCoord" == propertyName) { + tempDipole.set(startCoord, (Point3f) value); + return; + } + + if ("molecular" == propertyName) { + tempDipole.set(new Point3f(0, 0, 0), (Vector3f) value, -1); + return; + } + + if ("dipoleValue" == propertyName) { + tempDipole.set(((Float) value).floatValue()); + return; + } + + if ("dipoleOffset" == propertyName) { + tempDipole.offsetAngstroms = ((Float) value).floatValue(); + if (currentDipole == null) + for (int i = dipoleCount; --i >= 0;) + dipoles[i].offsetAngstroms = tempDipole.offsetAngstroms; + return; + } + + if ("dipoleOffsetPercent" == propertyName) { + tempDipole.offsetPercent = ((Integer) value).intValue(); + if (currentDipole == null) + for (int i = dipoleCount; --i >= 0;) { + dipoles[i].offsetAngstroms = tempDipole.offsetPercent / 100f * dipoles[i].dipoleValue; + System.out.println(i+" "+dipoles[i].offsetAngstroms+" "+ tempDipole.offsetPercent + " "+dipoles[i].dipoleValue); + } + return; + } + + if ("dipoleWidth" == propertyName) { + tempDipole.mad = (short)(((Float) value).floatValue() * 1000); + if (currentDipole == null) + for (int i = dipoleCount; --i >= 0;) + dipoles[i].offsetAngstroms = tempDipole.offsetPercent / 100f * dipoles[i].dipoleValue; + return; + } + + if ("set" == propertyName) { + if (isBond) + return; + if (!iHaveID) { + String dipoleID = "dipole" + dipoleCount; + currentDipole = findDipole(dipoleID, tempDipole.dipoleInfo); + if (tempDipole.offsetPercent != 0) + tempDipole.offsetAngstroms = tempDipole.offsetPercent / 100f * tempDipole.dipoleValue; + setDipole(currentDipole, tempDipole); + } + return; + } + } + + void setDipole (Dipole newDipole, Dipole tempDipole) { + setDipole(newDipole, tempDipole.atoms, tempDipole.dipoleInfo, + tempDipole.dipoleValue, tempDipole.mad, tempDipole.offsetAngstroms, + tempDipole.origin, tempDipole.vector); + } + + void setDipole(Dipole dipole, Atom[] atoms, String dipoleInfo, + float dipoleValue, short mad, float offsetAngstroms, + Point3f origin, Vector3f vector) { + if (atoms[0] != null) { + dipole.atoms[0] = atoms[0]; + dipole.atoms[1] = atoms[1]; + } + dipole.dipoleInfo = dipoleInfo; + dipole.dipoleValue = dipoleValue; + dipole.mad = mad; + dipole.offsetAngstroms = offsetAngstroms; + dipole.origin = new Point3f(origin); + dipole.vector = new Vector3f(vector); + } + + int getDipoleIndex(String dipoleID) { + for (int i = dipoleCount; --i >= 0; ) { + if (dipoles[i] != null && dipoleID.equals(dipoles[i].dipoleID)) + return i; + } + return -1; + } + + int getDipoleIndex(String dipoleID, String dipoleInfo) { + for (int i = dipoleCount; --i >= 0; ) { + if (dipoles[i] != null && dipoleInfo.equals(dipoles[i].dipoleInfo)) + return i; + } + return getDipoleIndex(dipoleID); + } + + int getDipoleIndex(int atomIndex1, int atomIndex2) { + for (int i = dipoleCount; --i >= 0;) { + if (dipoles[i] != null + && dipoles[i].atoms[0] != null + && dipoles[i].atoms[1] != null + && (dipoles[i].atoms[0].atomIndex == atomIndex1 + && dipoles[i].atoms[1].atomIndex == atomIndex2 + || dipoles[i].atoms[1].atomIndex == atomIndex1 + && dipoles[i].atoms[0].atomIndex == atomIndex2)) + return i; + } + return -1; + } + + Dipole findDipole(String dipoleID) { + int dipoleIndex = getDipoleIndex(dipoleID); + if (dipoleIndex >= 0) { + return dipoles[dipoleIndex]; + } + return allocDipole(dipoleID); + } + + Dipole findDipole(int atomIndex1, int atomIndex2) { + int dipoleIndex = getDipoleIndex(atomIndex1, atomIndex2); + if (dipoleIndex >= 0) { + return dipoles[dipoleIndex]; + } + return allocDipole(""); + } + + Dipole findDipole(Atom atom1, Atom atom2) { + int dipoleIndex = getDipoleIndex(atom1.atomIndex, atom2.atomIndex); + if (dipoleIndex >= 0) { + return dipoles[dipoleIndex]; + } + return allocDipole(""); + } + + Dipole findDipole(String dipoleID, String dipoleInfo) { + int dipoleIndex = getDipoleIndex(dipoleID, dipoleInfo); + if (dipoleIndex >= 0) { + return dipoles[dipoleIndex]; + } + return allocDipole(dipoleID); + } + + Dipole allocDipole(String dipoleID) { + dipoles = (Dipole[])Util.ensureLength(dipoles, dipoleCount + 1); + if (dipoleID.length() == 0) + dipoleID = "dipole" + (dipoleCount + 1); + return dipoles[dipoleCount++] = new Dipole(viewer, dipoleID, g3d, colix, DEFAULT_MAD, true); + } + + Vector getShapeDetail() { + Vector V=new Vector(); + Hashtable atomInfo; + for (int i = 0; i < dipoleCount; i++) { + Hashtable info = new Hashtable(); + Dipole dipole = dipoles[i]; + info.put("ID", dipole.dipoleID); + info.put("vector", dipole.vector); + info.put("origin", dipole.origin); + if (dipole.atoms[0] != null) { + atomInfo = new Hashtable(); + viewer.getAtomIdentityInfo(dipole.atoms[0].atomIndex, atomInfo); + Vector atoms = new Vector(); + atoms.add(atomInfo); + atomInfo = new Hashtable(); + viewer.getAtomIdentityInfo(dipole.atoms[1].atomIndex, atomInfo); + atoms.add(atomInfo); + info.put("atoms", atoms); + info.put("magnitude", new Float(dipole.vector.length())); + } + V.add(info); + } + return V; + } +} + Added: branches/bob200603/Jmol/src/org/jmol/viewer/DipolesRenderer.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/DipolesRenderer.java (rev 0) +++ branches/bob200603/Jmol/src/org/jmol/viewer/DipolesRenderer.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -0,0 +1,112 @@ +/* $RCSfile$ + * $Author: hansonr $ + * $Date: 2006-03-16 15:52:18 -0600 (Thu, 16 Mar 2006) $ + * $Revision: 4635 $ + * + * Copyright (C) 2002-2005 The Jmol Development Team + * + * Contact: jmo...@li... + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jmol.viewer; + +import org.jmol.g3d.*; +import javax.vecmath.*; + +class DipolesRenderer extends ShapeRenderer { + + + + float dipoleVectorScale; + void render() { + Dipoles dipoles = (Dipoles) shape; + dipoleVectorScale = viewer.getDipoleScale(); + for (int i = dipoles.dipoleCount; --i >= 0;) { + Dipole dipole = dipoles.dipoles[i]; + //System.out.println("DipolesRenderer" + dipoleVectorScale + " " + i + " " + // + dipole.mad + dipole.visible + dipole.vector + " " + dipole.origin); + if (dipole.mad == 0 || !dipole.visible || dipole.origin == null + || dipole.vector == null || dipole.vector.length() == 0) + continue; + if (transform(dipole)) + renderDipoleVector(dipole); + } + } + + + final Vector3f offset = new Vector3f(); + final Point3f pointCylinderBase = new Point3f(); + final Point3f pointCross = new Point3f(); + final Point3f pointCrossEnd = new Point3f(); + final Point3f pointArrowHeadBase = new Point3f(); + final Point3f pointArrowHeadTip = new Point3f(); + + final Point3i screenCylinderBase = new Point3i(); + final Point3i screenCross = new Point3i(); + final Point3i screenCrossEnd = new Point3i(); + final Point3i screenArrowHeadBase = new Point3i(); + final Point3i screenArrowHeadTip = new Point3i(); + int diameter; + int headWidthPixels; + int crossWidthPixels; + + final static float arrowHeadOffset = 0.8f; + final static float arrowHeadWidthFactor = 4f; + final static float crossOffset = 0.1f; + final static float crossWidth = 0.04f; + + boolean transform(Dipole dipole) { + Vector3f vector = dipole.vector; + offset.set(vector); + offset.scale(dipole.offsetAngstroms / dipole.dipoleValue); + System.out.println("render dipoloe "+offset + dipole.offsetAngstroms); + pointCylinderBase.set(dipole.origin); + pointCylinderBase.add(offset); + pointCross.scaleAdd(dipoleVectorScale * crossOffset, vector, + pointCylinderBase); + pointCrossEnd.scaleAdd(dipoleVectorScale * (crossOffset + crossWidth), + vector, pointCylinderBase); + pointArrowHeadBase.scaleAdd(dipoleVectorScale * arrowHeadOffset, vector, + pointCylinderBase); + pointArrowHeadTip.scaleAdd(dipoleVectorScale, vector, pointCylinderBase); + + viewer.transformPoint(pointCylinderBase, screenCylinderBase); + viewer.transformPoint(pointCross, screenCross); + viewer.transformPoint(pointCrossEnd, screenCrossEnd); + viewer.transformPoint(pointArrowHeadBase, screenArrowHeadBase); + viewer.transformPoint(pointArrowHeadTip, screenArrowHeadTip); + short mad = dipole.mad; + diameter = (mad <= 20) ? mad : viewer.scaleToScreen(screenCylinderBase.z, + mad); + headWidthPixels = (int)(diameter * arrowHeadWidthFactor); + if (headWidthPixels < diameter + 10) + headWidthPixels = diameter + 10; + crossWidthPixels = headWidthPixels; + return true; + } + + void renderDipoleVector(Dipole dipole) { + short colix = dipole.colix; + g3d.fillCylinder(colix, Graphics3D.ENDCAPS_OPEN, diameter, + screenCylinderBase, screenArrowHeadBase); + g3d.fillCylinder(colix, Graphics3D.ENDCAPS_FLAT, crossWidthPixels, + screenCross, screenCrossEnd); + g3d.fillCone(colix, Graphics3D.ENDCAPS_NONE, headWidthPixels, + screenArrowHeadBase, screenArrowHeadTip); + } +} Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java 2006-04-04 02:13:20 UTC (rev 4895) +++ branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -363,6 +363,7 @@ if (logMessages || viewer.getDebugScript()) logDebugScript(); Token token = statement[0]; + //System.out.println(token); switch (token.tok) { case Token.backbone: proteinShape(JmolConstants.SHAPE_BACKBONE); @@ -455,6 +456,9 @@ case Token.vector: vector(); break; + case Token.dipole: + dipole(); + break; case Token.animation: animation(); break; @@ -2254,6 +2258,121 @@ viewer.setVectorScale(scale); } + + void dipole() throws ScriptException { + //dipole intWidth floatMagnitude OFFSET floatOffset {atom1} {atom2} + viewer.loadShape(JmolConstants.SHAPE_DIPOLES); + String propertyName = null; + Object propertyValue = null; + boolean iHaveAtoms = false; + boolean iHaveCoord = false; + boolean iHaveCoord2 = false; + boolean isOffset = false; + boolean isWidth = false; + boolean isNeg = false; + + if (statementLength == 0) { + viewer.setShapeProperty(JmolConstants.SHAPE_DIPOLES, "on", null); + return; + } + viewer.setShapeProperty(JmolConstants.SHAPE_DIPOLES, "init", null); + for (int i = 1; i < statementLength; ++i) { + propertyName = null; + propertyValue = null; + Token token = statement[i]; + switch (token.tok) { + case Token.on: + if (statementLength == 2) + propertyName = "on"; + break; + case Token.off: + if (statementLength == 2) + propertyName = "off"; + break; + case Token.delete: + if (statementLength == 2) + propertyName = "delete"; + break; + case Token.hyphen: + isNeg = true; + continue; + case Token.integer: + if (isOffset) { + if (isNeg) + token.intValue = -token.intValue; + propertyName = "dipoleOffsetPercent"; + propertyValue = new Integer(token.intValue); + isOffset = false; + isWidth = false; + isNeg = false; + } + break; + case Token.decimal: + propertyName = (isWidth ? "dipoleWidth" : isOffset ? "dipoleOffset" + : "dipoleValue"); + propertyValue = new Float((isNeg ? -1 : 1) * floatParameter(i)); + isOffset = false; + isWidth = false; + isNeg = false; + break; + case Token.expressionBegin: + propertyValue = expression(statement, i); + i = endOfExpression; + propertyName = (iHaveAtoms ? "endSet" : "startSet"); + iHaveAtoms = true; + break; + case Token.leftbrace: + // {X, Y, Z} + Point3f pt = getCoordinate(i); + i = endOfExpression; + propertyName = (iHaveCoord ? "endCoord" : "startCoord"); + propertyValue = pt; + iHaveCoord2 = iHaveCoord; + iHaveCoord = true; + break; + case Token.bonds: + propertyName = "bonds"; + break; + case Token.identifier: + String cmd = (String) token.value; + if (cmd.equalsIgnoreCase("offset")) { + isOffset = true; + break; + } + if (cmd.equalsIgnoreCase("width")) { + isWidth = true; + break; + } + if (cmd.equalsIgnoreCase("molecular")) { + propertyValue = viewer.getModelDipole(); + if (propertyValue == null) + break; + iHaveCoord2 = iHaveCoord = true; + propertyName = "molecular"; + break; + } + propertyName = "dipoleID"; + propertyValue = ((String) token.value).toLowerCase(); + break; + default: + invalidArgument(); + } + if (propertyName != null) + viewer.setShapeProperty(JmolConstants.SHAPE_DIPOLES, propertyName, + propertyValue); + } + if (iHaveCoord2 || iHaveAtoms) + viewer.setShapeProperty(JmolConstants.SHAPE_DIPOLES, "set", null); + } + + void dipoleScale() throws ScriptException { + checkLength3(); + float scale = floatParameter(2); + if (scale < -10 || scale > 10) + numberOutOfRange(); + viewer.setDipoleScale(scale); + } + void animationMode() throws ScriptException { float startDelay = 1, endDelay = 1; if (statementLength < 3 || statementLength > 5) @@ -2554,7 +2673,7 @@ Token.meshRibbon, Token.ribbon, Token.rocket, Token.star, Token.axes, Token.boundbox, Token.unitcell, Token.frank, Token.echo, Token.hover, Token.polyhedra, Token.prueba, - Token.pmesh, Token.sasurface, Token.isosurface, Token.draw}; + Token.pmesh, Token.sasurface, Token.isosurface, Token.draw, Token.dipole}; static { if (shapeToks.length != JmolConstants.SHAPE_MAX) { @@ -3716,20 +3835,7 @@ void connect() throws ScriptException { viewer.setShapeProperty(JmolConstants.SHAPE_STICKS, - "maxDistance", new Float(100000000f)); - viewer.setShapeProperty(JmolConstants.SHAPE_STICKS, - "minDistance", new Float(-0.0001)); - viewer.setShapeProperty(JmolConstants.SHAPE_STICKS, - "connectBondOrder", new Short((short)1)); - viewer.setShapeProperty(JmolConstants.SHAPE_STICKS, - "connectMad", new Short((short)-1)); - viewer.setShapeProperty(JmolConstants.SHAPE_STICKS, - "connectExistant", new Boolean(true)); - viewer.setShapeProperty(JmolConstants.SHAPE_STICKS, - "connectNew", new Boolean(true)); - viewer.setShapeProperty(JmolConstants.SHAPE_STICKS, - "sourceSet", null); - + "initConnect", null); if (statementLength == 1) { viewer.rebond(); return; Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Frame.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/Frame.java 2006-04-04 02:13:20 UTC (rev 4895) +++ branches/bob200603/Jmol/src/org/jmol/viewer/Frame.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -2225,4 +2225,41 @@ return V; } + Vector3f getModelDipole() { + Vector3f dipole; + dipole = (Vector3f) mmset.getModelSetAuxiliaryInfo("dipole"); + if (dipole == null) + dipole = (Vector3f) mmset.getModelSetAuxiliaryInfo("DIPOLE_VEC"); + return dipole; + } + + final static float E_ANG_PER_DEBYE = 0.208194f; + void getBondDipoles() { + if (partialCharges == null) + return; + loadShape(JmolConstants.SHAPE_DIPOLES); + Dipoles dipoles = (Dipoles)shapes[JmolConstants.SHAPE_DIPOLES]; + for (int i = bondCount; --i >= 0;) { + if (!bonds[i].isCovalent()) + continue; + Atom atom1 = bonds[i].atom1; + Atom atom2 = bonds[i].atom2; + float c1 = partialCharges[atom1.atomIndex]; + float c2 = partialCharges[atom2.atomIndex]; + if (c1 != c2) { + Dipole dipole = dipoles.findDipole(atom1, atom2); + float value = (c1 - c2) / 2f * atom1.point3f.distance(atom2.point3f) / E_ANG_PER_DEBYE; + if (value < 0) { + dipole.set(atom2, atom1, -value); + System.out.println(atom2.getInfo() + atom1.getInfo() + (-value)); + } else { + dipole.set(atom1, atom2, value); + System.out.println(atom1.getInfo() + atom2.getInfo() + value); + } + } + + } + } + + } Modified: branches/bob200603/Jmol/src/org/jmol/viewer/JmolConstants.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/JmolConstants.java 2006-04-04 02:13:20 UTC (rev 4895) +++ branches/bob200603/Jmol/src/org/jmol/viewer/JmolConstants.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -42,9 +42,8 @@ // for now, just update this by hand // perhaps use ant filter later ... but mth doesn't like it :-( public final static String copyright = "(C) 2006 Jmol Development"; - public final static String version = "10.00.49"; - public final static String cvsDate = - "$Date$"; + public final static String version = "10.00.48"; + public final static String cvsDate = "$Date$"; public final static String date = cvsDate.substring(7, 23); public final static boolean officialRelease = false; @@ -2137,7 +2136,8 @@ //////////////////////////////////////////////////////////////// // do not rearrange/modify these shapes without // updating the String[] shapeBaseClasses below && - // also updating Eval.java to confirm consistent + // also creating a token for this shape in Token.java && + // also updating Eval.java shapeToks to confirm consistent // conversion from tokens to shapes //////////////////////////////////////////////////////////////// @@ -2172,7 +2172,8 @@ public final static int SHAPE_SASURFACE = 25; public final static int SHAPE_ISOSURFACE = 26; public final static int SHAPE_DRAW = 27; - public final static int SHAPE_MAX = 28; + public final static int SHAPE_DIPOLES = 28; + public final static int SHAPE_MAX = 29; //handled in Balls.java: (It's ok that this is SHAPE_MAX) public final static int SHAPE_HALO = SHAPE_MAX; @@ -2186,7 +2187,7 @@ "Strands", "MeshRibbon", "Ribbons", "Rockets", "Stars", "Axes", "Bbcage", "Uccage", "Frank", "Echo", "Hover", "Polyhedra", - "Prueba", "Pmesh", "Sasurface", "Isosurface", "Draw" + "Prueba", "Pmesh", "Sasurface", "Isosurface", "Draw", "Dipoles" }; //////////////////////////////////////////////////////////////// Modified: branches/bob200603/Jmol/src/org/jmol/viewer/ModelManager.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/ModelManager.java 2006-04-04 02:13:20 UTC (rev 4895) +++ branches/bob200603/Jmol/src/org/jmol/viewer/ModelManager.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -1292,5 +1292,15 @@ Vector3f getAtomVector(int atomIndex1, int atomIndex2) { return frame.getAtomVector(atomIndex1, atomIndex2); } - + + Vector3f getModelDipole() { + return frame == null ? null : frame.getModelDipole(); + } + + void getBondDipoles() { + if (frame == null) + return; + frame.getBondDipoles(); + } + } Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Token.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/Token.java 2006-04-04 02:13:20 UTC (rev 4895) +++ branches/bob200603/Jmol/src/org/jmol/viewer/Token.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -180,6 +180,7 @@ final static int isosurface = command | 94; final static int draw = command | 95 | embeddedExpression; final static int getproperty = command | 96; + final static int dipole = command | 97 | embeddedExpression; // parameters final static int ambient = setparam | 0; @@ -511,6 +512,8 @@ "console", new Token(console, onDefault1, "console"), "pmesh", new Token(pmesh, varArgCount, "pmesh"), "draw", new Token(draw, varArgCount, "draw"), + "dipole", new Token(dipole, varArgCount, "dipole"), + "dipoles", null, "polyhedra", new Token(polyhedra,varArgCount, "polyhedra"), "centerat", new Token(centerAt, varArgCount, "centerat"), "isosurface", new Token(isosurface,varArgCount,"isosurface"), Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/Viewer.java 2006-04-04 02:13:20 UTC (rev 4895) +++ branches/bob200603/Jmol/src/org/jmol/viewer/Viewer.java 2006-04-04 02:37:45 UTC (rev 4896) @@ -2945,4 +2945,26 @@ return modelManager.getSpinAxis(axisID, repaintManager.displayModelIndex); } + Vector3f getModelDipole() { + return modelManager.getModelDipole(); + } + + void getBondDipoles() { + modelManager.getBondDipoles(); + return; + } + + float dipoleScale = 1.0f; //for now -- global + public void setDipoleScale(float scale) { + dipoleScale = 1.0f; + } + public float getDipoleScale() { + return dipoleScale; + } + + void getAtomIdentityInfo(int atomIndex, Hashtable info) { + modelManager.getAtomIdentityInfo(atomIndex, info); + } + + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |