// $Id: Bond.java,v 1.4 2007/02/13 19:08:41 Sasha Buzko Exp $ // // Copyright 2000-2004 The Regents of the University of California. // All Rights Reserved. // // Permission to use, copy, modify and distribute any part of this // Molecular Biology Toolkit (MBT) // for educational, research and non-profit purposes, without fee, and without // a written agreement is hereby granted, provided that the above copyright // notice, this paragraph and the following three paragraphs appear in all // copies. // // Those desiring to incorporate this MBT into commercial products // or use for commercial purposes should contact the Technology Transfer & // Intellectual Property Services, University of California, San Diego, 9500 // Gilman Drive, Mail Code 0910, La Jolla, CA 92093-0910, Ph: (858) 534-5815, // FAX: (858) 534-7345, E-MAIL:invent@ucsd.edu. // // IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING // LOST PROFITS, ARISING OUT OF THE USE OF THIS MBT, EVEN IF THE // UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // THE MBT PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND THE // UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, // UPDATES, ENHANCEMENTS, OR MODIFICATIONS. THE UNIVERSITY OF CALIFORNIA MAKES // NO REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER IMPLIED OR // EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF // MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, OR THAT THE USE OF THE // MBT WILL NOT INFRINGE ANY PATENT, TRADEMARK OR OTHER RIGHTS. // // For further information, please see: http://mbt.sdsc.edu // // History: // $Log: Bond.java,v $ // Revision 1.4 2007/02/13 19:08:41 Sasha Buzko // *** empty log message *** // // Revision 1.3 2006/12/23 06:18:56 Sasha Buzko // md // // Revision 1.2 2006/10/04 18:00:58 Sasha Buzko // *** empty log message *** // // Revision 1.1 2006/05/20 17:02:07 Sasha Buzko // Updated version // // Revision 1.1 2006/04/30 20:14:05 Sasha Buzko // New version of the app // // Revision 1.1 2006/04/15 19:42:28 Sasha Buzko // Initial commit // // Revision 1.5 2006/02/24 22:26:53 Administrator // *** empty log message *** // // Revision 1.4 2006/02/05 22:01:42 Administrator // *** empty log message *** // // Revision 1.3 2005/11/26 04:36:10 Administrator // *** empty log message *** // // Revision 1.2 2005/11/13 23:44:31 Administrator // *** empty log message *** // // Revision 1.14 2005/11/08 20:58:12 moreland // Switched style code to new StructureStyles API. // // Revision 1.13 2005/03/31 21:49:36 moreland // Corrected ClassCastException with addition of instanceof call. // // Revision 1.12 2005/02/15 01:03:12 moreland // Fixed or removed hashCode/equals methods that were causing hash collisions. // // Revision 1.11 2005/02/03 18:16:27 moreland // Constructor and set methods now prevent bonds from connecting an atom to itself. // // Revision 1.10 2004/10/27 20:03:30 moreland // Corrected javadoc SEE references. // // Revision 1.9 2004/06/02 18:23:01 moreland // Added support for bond order. // // Revision 1.8 2004/04/29 22:55:10 moreland // Added ionic bond type. // Improved getBondType method's covalent VS hydrogen bond determination. // // Revision 1.7 2004/04/09 00:17:00 moreland // Updated copyright to new UCSD wording. // // Revision 1.6 2004/02/05 18:36:36 moreland // Now computes distances using the Algebra class methods. // // Revision 1.5 2004/01/29 17:08:15 moreland // Updated copyright and class block comments. // // Revision 1.4 2003/12/20 00:56:38 moreland // Implemented getBondType method using atom distances and element types. // // Revision 1.3 2003/07/11 22:54:26 moreland // Added a "hashCode" and "equal" methods to enable hashing/uniqueness to be based upon the // atoms/children (and regardless of atom order). // // Revision 1.2 2003/04/23 17:16:38 moreland // Removed StructureComponentID/scid and replaced it with a "structure" field // in the StructureComponent base class. // Changed "getType" method to "getStructureComponentType" to return dynamic // SC type (ie: class name). // // Revision 1.1 2003/04/03 23:08:11 moreland // First version. // // Revision 1.2 2002/10/24 17:54:01 moreland // Provides implementation for the improved Structure API/implementation. // // Revision 1.1.1.1 2002/07/16 18:00:18 moreland // Imported sources // // Revision 1.0 2002/06/10 23:38:39 moreland // package edu.sdsc.mbt; import edu.sdsc.mbt.util.*; import edu.sdsc.mbt.viewables.StylesPreferences; import java.util.*; /** * Implements a StructureComponent container for bond information. * This may be a covalent or a hydrogen bond. *
* @author John L. Moreland * @see edu.sdsc.mbt.StructureComponent * @see edu.sdsc.mbt.Atom */ public class Bond extends StructureComponent implements java.lang.Cloneable { /** * Type for a covalent bond (bonding interaction due to electron sharing). */ public static final String TYPE_COVALENT = "Covalent"; /** * Type for a hydrogen bond (bonding interaction due to partial charges). */ public static final String TYPE_HYDROGEN = "Hydrogen"; /** * Type for an ionic bond (bonding interaction due to electrostatic * attraction between cations and anions). */ public static final String TYPE_IONIC = "Ionic"; // The two atoms forming the bond. private Atom atoms[]; // The order of the bond (how many electron pairs are shared). public float order = 1.0f; private int reference; // // Constructors // /** * Constructor variant used when there will likely be no atom list * (eg: when only sequence data is loaded). */ public Bond( Atom atom0, Atom atom1 ) { if (atom0 == atom1) throw new IllegalArgumentException("duplicate atom"); setStructure( atom0.getStructure() ); atoms = new Atom[]{ atom0, atom1 }; reference = 0; } // // StructureComponent methods. // /** * Copy all of the field values from the parameter object into "this". */ public void copy( StructureComponent structureComponent ) { setStructure( structureComponent.getStructure() ); Bond bond = (Bond) structureComponent; atoms[0] = bond.getAtom( 0 ); atoms[1] = bond.getAtom( 1 ); setReferenceAtom(bond.getReferenceAtom()); } /** * Clone this object. */ public Object clone( ) throws CloneNotSupportedException { return super.clone( ); } /** * One Bond is equal to another Bond if they hashCode values are equal. * That is if they contain (in either order) the same two Atom objects. */ public boolean equals( Object o ) { if ( ! (o instanceof Bond) ) return false; Bond b = (Bond) o; if (b.getAtom(0) == this.getAtom(0) && b.getAtom(1) == this.getAtom(1)) return true; if (b.getAtom(0) == this.getAtom(1) && b.getAtom(1) == this.getAtom(0)) return true; return false; } private static String className = null; /** * This method returns the fully qualified name of this class. *
* This name is used by the StructureComponentRegistry class to enable * dynamic registration and discovery of new StructureComponent * sub-classes/types. The name is also used to create a unique integer * indentifier for each type in order to make run-time type comparisons * fast. */ public static String getClassName() { if ( className == null ) className = ((new Throwable()).getStackTrace())[0].getClassName(); return className; } /** * This method returns the fully qualified name of this class. */ public String getStructureComponentType( ) { return className; } // // Bond methods. // /** * Set the bond order (the number of covalently shared electron pairs). * Generally this is a value from 1.0 to 6.0 but may be 1.5 for aromatic * (benzene ring bonds) or 0.0 for unspecified order (the default). *
* @see #getOrder( ) */ public void setOrder( float order ) { if ( (order < 0.0f) || (order > 6.0f) ) throw new IllegalArgumentException( "Invalid order " + order ); //before changing hybridization of atoms, check whether they participate in //other (perhaps higher order) bonds Atom a1 = getAtom(0); Atom a2 = getAtom(1); //check a1 boolean reset = true; Vector bonds = a1.structure.getStructureMap().getBonds(a1); for (int i = 0; i < bonds.size(); i++){ Bond b = (Bond)bonds.get(i); if (b == this) continue; if (b.order > 1.0f){ reset = false; break; } } if (reset){//the atom is not in any other multiple bond, so do your thing //set the correct hybridization if (order == 1.0f) a1.hybridization = Atom.SP3; if (order == 1.5f) a1.hybridization = Atom.SP2;//aromatic if (order == 2.0f) a1.hybridization = Atom.SP2; if (order == 3.0f) a1.hybridization = Atom.SP; } //check a1 reset = true; bonds = a2.structure.getStructureMap().getBonds(a2); for (int i = 0; i < bonds.size(); i++){ Bond b = (Bond)bonds.get(i); if (b == this) continue; if (b.order > 1.0f){ reset = false; break; } } if (reset){ //set the correct hybridization if (order == 1.0f) a2.hybridization = Atom.SP3; if (order == 1.5f) a2.hybridization = Atom.SP2;//aromatic if (order == 2.0f) a2.hybridization = Atom.SP2; if (order == 3.0f) a2.hybridization = Atom.SP; } this.order = order; } /** * This method sets order without editing atoms' hybridization states * it is used in the loading of data with predefined bonding to avoid overwriting of hybridization * data in subsequent passes over atoms that participate in bonds of different orders * @param order */ public void setOrderOnly(float order){ if ( (order < 0.0f) || (order > 6.0f) ) throw new IllegalArgumentException( "Invalid order " + order ); this.order = order; } /** * Get the distance for the bond. */ public double getDistance( ) { if ( atoms == null ) return 0.0; if ( atoms[0] == null ) return 0.0; if ( atoms[1] == null ) return 0.0; return Algebra.distance( atoms[0].coordinate, atoms[1].coordinate ); } public static final double getDistance( Atom atom0, Atom atom1 ) { return Algebra.distance( atom0.coordinate, atom1.coordinate ); } /** * Get the specified Atom record that forms this Bond. */ public Atom getAtom( int index ) { return atoms[index]; } public void setReferenceAtom(int index){ if (index < 0 || index > 1) return; reference = index; } public void setReferenceAtom(Atom atom){ if (atoms[0] == atom) reference = 0; else if (atoms[1] == atom) reference = 1; } public Atom getReferenceAtom(){ return atoms[reference]; } public short render = (short)StylesPreferences.renderingMode; public short quality = (short)StylesPreferences.startupRenderingQuality; public boolean visible = true; public boolean isVisible(){ return visible; } }