// $Id: Fragment.java,v 1.2 2007/02/13 19:08:40 Sasha Buzko Exp $ // // Copyright (c) 2000-2002 San Diego Supercomputer Center (SDSC), // a facility operated jointly by the University of California, // San Diego (UCSD) and General Atomics, San Diego, California, USA. // // Users and possessors of this source code are hereby granted a // nonexclusive, royalty-free copyright and design patent license to // use this code in individual software. License is not granted for // commercial resale, in whole or in part, without prior written // permission from SDSC. This source is provided "AS IS" without express // or implied warranty of any kind. // // For further information, please see: http://mbt.sdsc.edu // // History: // $Log: Fragment.java,v $ // Revision 1.2 2007/02/13 19:08:40 Sasha Buzko // *** empty log message *** // // Revision 1.1 2006/05/20 17:02:06 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:27 Sasha Buzko // Initial commit // // Revision 1.1 2005/11/13 04:35:23 Administrator // *** empty log message *** // // Revision 1.2 2003/10/17 18:19:56 moreland // Fixed a javadoc comment. // // Revision 1.1 2003/07/21 20:47:40 moreland // First implementation of a secondary structure fragment object. // // // Revision 1.0 2002/06/10 23:38:39 moreland // First version. // package edu.sdsc.mbt; import java.util.*; /** * Implements a StructureComponent container for secondary structure fragment * information. This consists of Residue range and the secondary structure type. *

* See the "PROGRAMMING NOTE" section of the StructureComponent class. *

* @see edu.sdsc.mbt.StructureComponent * @see edu.sdsc.mbt.Structure *

* @author John L. Moreland */ public class Fragment extends StructureComponent implements java.lang.Cloneable, java.io.Serializable { // The Chain to which this Fragment belongs. private Chain chain = null; // The start Residue index for this Fragment. // The Residue index is a Chain-level index (not a Structure-level index). private int startResidueIndex = -1; // The end Residue index for this Fragment. // The Residue index is a Chain-level index (not a Structure-level index). private int endResidueIndex = -1; // The secondary structure conformation type assigned to this Fragment. private String conformationType = Conformation.TYPE_UNDEFINED; private Vector residues = new Vector(); // // Constructors // /** * Construct a Fragment for the given start Residue * index, end Residue index, and conformation type. * The Residue index is a Chain-level index (not a Structure-level index). */ public Fragment( int startResidueIndex, int endResidueIndex, String conformationType ) { this.startResidueIndex = startResidueIndex; this.endResidueIndex = endResidueIndex; this.conformationType = conformationType; } /** * Constructor variant used when there will likely be an atom list. */ public Fragment( ) { this.startResidueIndex = -1; this.endResidueIndex = -1; this.conformationType = Conformation.TYPE_UNDEFINED; } // // StructureComponent methods. // /** * Set the chain to which this Fragment belongs (called by chain.addFragment). */ protected void setChain( Chain chain ) { this.chain = chain; } /** * Get the chain to which this Fragment belongs. */ public Chain getChain( ) { return chain; } /** * Copy all of the field values from the parameter object into "this". */ public void copy( StructureComponent structureComponent ) { structure = structureComponent.structure; Fragment fragment = (Fragment) structureComponent; startResidueIndex = fragment.startResidueIndex; endResidueIndex = fragment.endResidueIndex; conformationType = fragment.conformationType; } /** * Clone this object. */ public Object clone( ) throws CloneNotSupportedException { return super.clone( ); } 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; } // // Hash (Object) methods. // /** * Return the hashCode for the Fragment. * This enables Fragment objects that share the same Chain and indexes * to be concidered the "same" Fragment. */ public int hashCode( ) { return (int) ( (long) startResidueIndex + (long) endResidueIndex / 2l ); } /** * One Fragment is equal to another Fragment if the indexes are equal. */ public boolean equals( Object o ) { Fragment f = (Fragment) o; if ( this.startResidueIndex != f.startResidueIndex ) return false; if ( this.endResidueIndex != f.endResidueIndex ) return false; return true; } // // Fragment methods. // /** * Set the start Reisude index for this Fragment. * The Residue index is a Chain-level index (not a Structure-level index). */ public void setStartResidueIndex( int startResidueIndex ) { this.startResidueIndex = startResidueIndex; } /** * Get the start Reisude index for this Fragment. * The Residue index is a Chain-level index (not a Structure-level index). */ public int getStartResidueIndex( ) { return startResidueIndex; } /** * Set the end Reisude index for this Fragment. * The Residue index is a Chain-level index (not a Structure-level index). */ public void setEndResidueIndex( int endResidueIndex ) { this.endResidueIndex = endResidueIndex; } /** * Get the end Reisude index for this Fragment. * The Residue index is a Chain-level index (not a Structure-level index). */ public int getEndResidueIndex( ) { return endResidueIndex; } /** * Set the Conformation type for this Fragment. */ public void setConformationType( String conformationType ) { this.conformationType = conformationType; } /** * Get the Conformation type for this Fragment. */ public String getConformationType( ) { return conformationType; } public void setResidues(Vector residues){ this.residues = residues; } public Vector getResidues(){ return residues; } public int getResidueCount(){ return residues.size(); } public Residue getResidue(int index){ // System.out.println("fragment (" + getResidueCount() + "): getting residue at " + index); return (Residue)residues.elementAt(index); } public int getResidueIndex(Residue residue){ return residues.indexOf(residue); } public int getResidueIndexInChain(Residue residue){ int out = getStartResidueIndex() + residues.indexOf(residue); return out; } private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { out.defaultWriteObject(); } private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { in.defaultReadObject(); } public boolean isVisible(){ return true; } }