Package org.openscience.cdk
Class BondRef
- java.lang.Object
-
- org.openscience.cdk.BondRef
-
- All Implemented Interfaces:
Cloneable
,IBond
,ICDKObject
,IChemObject
,IElectronContainer
public class BondRef extends Object implements IBond
A bond ref, references a CDKIBond
indirectly. All methods are passed through to the referenced bond. The reference can be used to override the behaviour of the base bond.- Author:
- John Mayfield
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.openscience.cdk.interfaces.IBond
IBond.Display, IBond.Order, IBond.Stereo
-
-
Field Summary
-
Fields inherited from interface org.openscience.cdk.interfaces.IChemObject
ALIPHATIC, AROMATIC, CONJUGATED, HYDROGEN_BOND_ACCEPTOR, HYDROGEN_BOND_DONOR, IN_RING, MAPPED, NOT_IN_RING, PLACED, REACTIVE_CENTER, SINGLE_OR_DOUBLE, TYPEABLE, VISITED
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(IChemObjectListener col)
Use this to add yourself to this IChemObject as a listener.void
addProperties(Map<Object,Object> properties)
Add properties to this object, duplicate keys will replace any existing value.Iterable<IAtom>
atoms()
Returns the Iterable to atoms making up this bond.void
clear(int flags)
Clear the provided flags.IBond
clone()
Returns a deep clone of this IChemObject.boolean
compare(Object object)
Compares a bond with this bond.boolean
contains(IAtom atom)
Returns true if the given atom participates in this bond.IBond
deref()
Dereference the bond pointer once providing access to the base bond.static IBond
deref(IBond bond)
Utility method to dereference an bond pointer.boolean
equals(Object obj)
int
flags()
Access the current value of the flags for this ChemObject.javax.vecmath.Point2d
get2DCenter()
Returns the geometric 2D center of the bond.javax.vecmath.Point3d
get3DCenter()
Returns the geometric 3D center of the bond.IAtom
getAtom(int position)
Returns an Atom from this bond.int
getAtomCount()
Returns the number of Atoms in this Bond.IAtom
getBegin()
Access the begin (or first) atom of the bond.IChemObjectBuilder
getBuilder()
Returns aIChemObjectBuilder
for the data classes that extend this class.IAtom
getConnectedAtom(IAtom atom)
Returns the other atom in the bond, the atom is connected to the given atom.IAtom[]
getConnectedAtoms(IAtom atom)
Returns all the atoms in the bond connected to the given atom.IAtomContainer
getContainer()
IBond.Display
getDisplay()
Access the bond display style.Integer
getElectronCount()
Returns the number of electrons in this electron container.IAtom
getEnd()
Access the end (or second) atom of the bond.boolean
getFlag(int mask)
Returns the value of a given flag.boolean[]
getFlags()
Returns the whole set of flags.Number
getFlagValue()
Access the internal value used to store the flags.String
getID()
Returns the identifier (ID) of this object.int
getIndex()
int
getListenerCount()
Returns the number of ChemObjectListeners registered with this object.boolean
getNotification()
Returns the flag that indicates whether notification messages are sent around.IBond.Order
getOrder()
Returns the bond order of this bond.IAtom
getOther(IAtom atom)
Returns the other atom in the bond, the atom is connected to the given atom.This method is only correct for two-centre bonds, for n-centre bonds the behaviour is undefined and the more correctIBond.getConnectedAtoms(IAtom)
should be used.Map<Object,Object>
getProperties()
Returns a Map with the IChemObject's properties.<T> T
getProperty(Object description)
Returns a property for the IChemObject - the object is automatically cast to the required type.<T> T
getProperty(Object description, Class<T> c)
Access a property of the given description and cast the specified class.IBond.Stereo
getStereo()
Returns the stereo descriptor for this bond.int
hashCode()
boolean
is(int flags)
Test if a flag(s) are set on this ChemObject.boolean
isAromatic()
Access whether this bond has been marked as aromatic.boolean
isConnectedTo(IBond bond)
Checks whether a bond is connected to another one.boolean
isInRing()
Access whether this bond has been flagged as in a ring.void
notifyChanged()
This should be triggered by an method that changes the content of an object to that the registered listeners can react to it.void
notifyChanged(IChemObjectChangeEvent evt)
This should be triggered by an method that changes the content of an object to that the registered listeners can react to it.void
removeListener(IChemObjectListener col)
Use this to remove a ChemObjectListener from the ListenerList of this IChemObject.void
removeProperty(Object description)
Removes a property for a IChemObject.void
set(int flags)
Set the provided flags.void
setAtom(IAtom atom, int position)
Sets an Atom in this bond.void
setAtoms(IAtom[] atoms)
Sets the array of atoms making up this bond.void
setDisplay(IBond.Display display)
Set the bond display style.void
setElectronCount(Integer count)
Sets the number of electrons in this electron container.void
setFlag(int mask, boolean value)
Sets the value of some flag.void
setFlags(boolean[] newFlags)
Sets the whole set of flags.void
setID(String identifier)
Sets the identifier (ID) of this object.void
setIsAromatic(boolean arom)
Mark this bond as being aromatic.void
setIsInRing(boolean ring)
Mark this bond as being in a ring.void
setNotification(boolean bool)
Set a flag to use or not use notification.void
setOrder(IBond.Order order)
Sets the bond order of this bond.void
setProperties(Map<Object,Object> properties)
Set the properties of this object to the provided map (shallow copy).void
setProperty(Object description, Object property)
Sets a property for a IChemObject.void
setStereo(IBond.Stereo stereo)
Sets the stereo descriptor for this bond.String
toString()
Returns a one line description of this IChemObject.-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.openscience.cdk.interfaces.IBond
getConnectedAtom
-
Methods inherited from interface org.openscience.cdk.interfaces.ICDKObject
getBuilder
-
Methods inherited from interface org.openscience.cdk.interfaces.IChemObject
addListener, addProperties, clear, flags, getFlag, getFlags, getFlagValue, getID, getListenerCount, getNotification, getProperties, getProperty, getProperty, is, notifyChanged, notifyChanged, removeListener, removeProperty, set, setFlag, setFlags, setID, setNotification, setProperties, setProperty
-
-
-
-
Constructor Detail
-
BondRef
public BondRef(IBond bond)
Create a pointer for the provided bond.- Parameters:
bond
- the bond to reference
-
-
Method Detail
-
deref
public static IBond deref(IBond bond)
Utility method to dereference an bond pointer. If the bond is not anBondRef
it simply returns the input.- Parameters:
bond
- the bond- Returns:
- non-pointer bond
-
deref
public IBond deref()
Dereference the bond pointer once providing access to the base bond.- Returns:
- the bond pointed to
-
getElectronCount
public Integer getElectronCount()
Returns the number of electrons in this electron container.- Specified by:
getElectronCount
in interfaceIElectronContainer
- Returns:
- The number of electrons in this electron container.
- See Also:
IElectronContainer.setElectronCount(java.lang.Integer)
-
setElectronCount
public void setElectronCount(Integer count)
Sets the number of electrons in this electron container.- Specified by:
setElectronCount
in interfaceIElectronContainer
- Parameters:
count
- The number of electrons in this electron container.- See Also:
IElectronContainer.getElectronCount()
-
atoms
public Iterable<IAtom> atoms()
Returns the Iterable to atoms making up this bond.- Specified by:
atoms
in interfaceIBond
- Returns:
- An Iterable to atoms participating in this bond
- See Also:
IBond.setAtoms(org.openscience.cdk.interfaces.IAtom[])
-
setAtoms
public void setAtoms(IAtom[] atoms)
Sets the array of atoms making up this bond.- Specified by:
setAtoms
in interfaceIBond
- Parameters:
atoms
- An array of atoms that forms this bond- See Also:
IBond.atoms()
-
getBegin
public IAtom getBegin()
Access the begin (or first) atom of the bond.
-
getEnd
public IAtom getEnd()
Access the end (or second) atom of the bond.
-
getContainer
public IAtomContainer getContainer()
- Specified by:
getContainer
in interfaceIBond
-
getAtomCount
public int getAtomCount()
Returns the number of Atoms in this Bond.- Specified by:
getAtomCount
in interfaceIBond
- Returns:
- The number of Atoms in this Bond
-
getAtom
public IAtom getAtom(int position)
Returns an Atom from this bond.- Specified by:
getAtom
in interfaceIBond
- Parameters:
position
- The position in this bond where the atom is- Returns:
- The atom at the specified position
- See Also:
IBond.setAtom(org.openscience.cdk.interfaces.IAtom, int)
-
getConnectedAtom
public IAtom getConnectedAtom(IAtom atom)
Returns the other atom in the bond, the atom is connected to the given atom. This method is only correct for two-centre bonds, for n-centre bonds the behaviour is undefined and the more correctIBond.getConnectedAtoms(IAtom)
should be used.IAtom beg = bond.getBegin(); IAtom end = bond.getEnd(); // bond.getConnectedAtom(beg) == end // bond.getConnectedAtom(end) == beg
- Specified by:
getConnectedAtom
in interfaceIBond
- Parameters:
atom
- The atom the bond partner is searched of- Returns:
- the connected atom or null if the given atom is not part of the bond
-
getOther
public IAtom getOther(IAtom atom)
Returns the other atom in the bond, the atom is connected to the given atom.This method is only correct for two-centre bonds, for n-centre bonds the behaviour is undefined and the more correctIBond.getConnectedAtoms(IAtom)
should be used.IAtom beg = bond.getBegin(); IAtom end = bond.getEnd(); // bond.getOther(beg) == end // bond.getOther(end) == beg
-
getConnectedAtoms
public IAtom[] getConnectedAtoms(IAtom atom)
Returns all the atoms in the bond connected to the given atom.- Specified by:
getConnectedAtoms
in interfaceIBond
- Parameters:
atom
- The atoms the bond partner is searched of- Returns:
- the connected atoms or null if the given atom is not part of the bond
-
contains
public boolean contains(IAtom atom)
Returns true if the given atom participates in this bond.
-
setAtom
public void setAtom(IAtom atom, int position)
Sets an Atom in this bond.- Specified by:
setAtom
in interfaceIBond
- Parameters:
atom
- The atom to be setposition
- The position in this bond where the atom is to be inserted- See Also:
IBond.getAtom(int)
-
getOrder
public IBond.Order getOrder()
Returns the bond order of this bond.- Specified by:
getOrder
in interfaceIBond
- Returns:
- The bond order of this bond
- See Also:
org.openscience.cdk.CDKConstants for predefined values.
,IBond.setOrder(org.openscience.cdk.interfaces.IBond.Order)
-
setOrder
public void setOrder(IBond.Order order)
Sets the bond order of this bond.- Specified by:
setOrder
in interfaceIBond
- Parameters:
order
- The bond order to be assigned to this bond- See Also:
for predefined values.
,IBond.getOrder()
-
getStereo
public IBond.Stereo getStereo()
Returns the stereo descriptor for this bond.- Specified by:
getStereo
in interfaceIBond
- Returns:
- The stereo descriptor for this bond
- See Also:
IBond.setStereo(org.openscience.cdk.interfaces.IBond.Stereo)
-
setStereo
public void setStereo(IBond.Stereo stereo)
Sets the stereo descriptor for this bond. Note this function will also modify the bond display style.- Specified by:
setStereo
in interfaceIBond
- Parameters:
stereo
- The stereo descriptor to be assigned to this bond.- See Also:
IBond.getStereo()
,IBond.setDisplay(Display)
-
getDisplay
public IBond.Display getDisplay()
Access the bond display style.- Specified by:
getDisplay
in interfaceIBond
- Returns:
- the bond display
-
setDisplay
public void setDisplay(IBond.Display display)
Set the bond display style.- Specified by:
setDisplay
in interfaceIBond
- Parameters:
display
- the display
-
get2DCenter
public javax.vecmath.Point2d get2DCenter()
Returns the geometric 2D center of the bond.- Specified by:
get2DCenter
in interfaceIBond
- Returns:
- The geometric 2D center of the bond
-
get3DCenter
public javax.vecmath.Point3d get3DCenter()
Returns the geometric 3D center of the bond.- Specified by:
get3DCenter
in interfaceIBond
- Returns:
- The geometric 3D center of the bond
-
compare
public boolean compare(Object object)
Compares a bond with this bond.
-
isConnectedTo
public boolean isConnectedTo(IBond bond)
Checks whether a bond is connected to another one. This can only be true if the bonds have an Atom in common.- Specified by:
isConnectedTo
in interfaceIBond
- Parameters:
bond
- The bond which is checked to be connect with this one- Returns:
- True, if the bonds share an atom, otherwise false
-
isAromatic
public boolean isAromatic()
Access whether this bond has been marked as aromatic. The default value is false and you must explicitly perceive aromaticity with one of the available models.- Specified by:
isAromatic
in interfaceIBond
- Returns:
- aromatic status
- See Also:
IChemObject.getFlag(int)
,Aromaticity
-
setIsAromatic
public void setIsAromatic(boolean arom)
Mark this bond as being aromatic.- Specified by:
setIsAromatic
in interfaceIBond
- Parameters:
arom
- aromatic status- See Also:
IChemObject.setFlag(int, boolean)
-
isInRing
public boolean isInRing()
Access whether this bond has been flagged as in a ring. The default value is false and you must explicitly find rings first.- Specified by:
isInRing
in interfaceIBond
- Returns:
- ring status
- See Also:
IChemObject.getFlag(int)
,RingSearch
-
setIsInRing
public void setIsInRing(boolean ring)
Mark this bond as being in a ring.- Specified by:
setIsInRing
in interfaceIBond
- Parameters:
ring
- ring status- See Also:
IChemObject.setFlag(int, boolean)
-
clone
public IBond clone() throws CloneNotSupportedException
Returns a deep clone of this IChemObject.- Specified by:
clone
in interfaceIBond
- Specified by:
clone
in interfaceIChemObject
- Returns:
- Object the clone of this IChemObject.
- Throws:
CloneNotSupportedException
- if the IChemObject cannot be cloned
-
toString
public String toString()
Description copied from interface:IChemObject
Returns a one line description of this IChemObject.- Specified by:
toString
in interfaceIChemObject
- Overrides:
toString
in classObject
- Returns:
- a String representation of this object
-
getBuilder
public IChemObjectBuilder getBuilder()
Returns aIChemObjectBuilder
for the data classes that extend this class.- Specified by:
getBuilder
in interfaceICDKObject
- Returns:
- The
IChemObjectBuilder
matching thisICDKObject
-
addListener
public void addListener(IChemObjectListener col)
Use this to add yourself to this IChemObject as a listener. In order to do so, you must implement the ChemObjectListener Interface.- Specified by:
addListener
in interfaceIChemObject
- Parameters:
col
- the ChemObjectListener- See Also:
IChemObject.removeListener(org.openscience.cdk.interfaces.IChemObjectListener)
-
getListenerCount
public int getListenerCount()
Returns the number of ChemObjectListeners registered with this object.- Specified by:
getListenerCount
in interfaceIChemObject
- Returns:
- the number of registered listeners.
-
removeListener
public void removeListener(IChemObjectListener col)
Use this to remove a ChemObjectListener from the ListenerList of this IChemObject. It will then not be notified of change in this object anymore.- Specified by:
removeListener
in interfaceIChemObject
- Parameters:
col
- The ChemObjectListener to be removed- See Also:
IChemObject.addListener(org.openscience.cdk.interfaces.IChemObjectListener)
-
setNotification
public void setNotification(boolean bool)
Set a flag to use or not use notification. By default it should be set to true.- Specified by:
setNotification
in interfaceIChemObject
- Parameters:
bool
- if true, then notification messages are sent.- See Also:
IChemObject.getNotification()
-
getNotification
public boolean getNotification()
Returns the flag that indicates whether notification messages are sent around.- Specified by:
getNotification
in interfaceIChemObject
- Returns:
- true if messages are sent.
- See Also:
IChemObject.setNotification(boolean)
-
notifyChanged
public void notifyChanged()
This should be triggered by an method that changes the content of an object to that the registered listeners can react to it.- Specified by:
notifyChanged
in interfaceIChemObject
-
notifyChanged
public void notifyChanged(IChemObjectChangeEvent evt)
This should be triggered by an method that changes the content of an object to that the registered listeners can react to it. This is a version of notifyChanged() which allows to propagate a change event while preserving the original origin.- Specified by:
notifyChanged
in interfaceIChemObject
- Parameters:
evt
- A ChemObjectChangeEvent pointing to the source of where the change happend
-
setProperty
public void setProperty(Object description, Object property)
Sets a property for a IChemObject.- Specified by:
setProperty
in interfaceIChemObject
- Parameters:
description
- An object description of the property (most likely a unique string)property
- An object with the property itself- See Also:
IChemObject.getProperty(java.lang.Object)
,IChemObject.removeProperty(java.lang.Object)
-
removeProperty
public void removeProperty(Object description)
Removes a property for a IChemObject.- Specified by:
removeProperty
in interfaceIChemObject
- Parameters:
description
- The object description of the property (most likely a unique string)- See Also:
IChemObject.setProperty(java.lang.Object, java.lang.Object)
,IChemObject.getProperty(java.lang.Object)
-
getProperty
public <T> T getProperty(Object description)
Returns a property for the IChemObject - the object is automatically cast to the required type. This does however mean if the wrong type is provided then a runtime ClassCastException will be thrown.IAtom atom = new Atom("C"); atom.setProperty("number", 1); // set an integer property // access the property and automatically cast to an int Integer number = atom.getProperty("number"); // if the method is in a chain or needs to be nested the type // can be provided methodAcceptingInt(atom.getProperty("number", Integer.class)); // the type cannot be checked and so... String number = atom.getProperty("number"); // ClassCastException // if the type is provided a more meaningful error is thrown atom.getProperty("number", String.class); // IllegalArgumentException
- Specified by:
getProperty
in interfaceIChemObject
- Type Parameters:
T
- generic return type- Parameters:
description
- An object description of the property (most likely a unique string)- Returns:
- The object containing the property. Returns null if property is not set.
- See Also:
IChemObject.setProperty(java.lang.Object, java.lang.Object)
,IChemObject.getProperty(Object, Class)
,IChemObject.removeProperty(java.lang.Object)
-
getProperty
public <T> T getProperty(Object description, Class<T> c)
Access a property of the given description and cast the specified class.IAtom atom = new Atom("C"); atom.setProperty("number", 1); // set an integer property // access the property and automatically cast to an int Integer number = atom.getProperty("number"); // if the method is in a chain or needs to be nested the type // can be provided methodAcceptingInt(atom.getProperty("number", Integer.class)); // the type cannot be checked and so... String number = atom.getProperty("number"); // ClassCastException // if the type is provided a more meaningful error is thrown atom.getProperty("number", String.class); // IllegalArgumentException
- Specified by:
getProperty
in interfaceIChemObject
- Type Parameters:
T
- generic type (of provided class)- Parameters:
description
- description of a property (normally a string)c
- type of the value to be returned- Returns:
- the value stored for the specified description.
- See Also:
IChemObject.getProperty(Object)
,IChemObject.addProperties(java.util.Map)
-
getProperties
public Map<Object,Object> getProperties()
Returns a Map with the IChemObject's properties.- Specified by:
getProperties
in interfaceIChemObject
- Returns:
- The object's properties as an Map
- See Also:
IChemObject.addProperties(java.util.Map<java.lang.Object, java.lang.Object>)
-
getID
public String getID()
Returns the identifier (ID) of this object.- Specified by:
getID
in interfaceIChemObject
- Returns:
- a String representing the ID value
- See Also:
IChemObject.setID(java.lang.String)
-
setID
public void setID(String identifier)
Sets the identifier (ID) of this object.- Specified by:
setID
in interfaceIChemObject
- Parameters:
identifier
- a String representing the ID value- See Also:
IChemObject.getID()
-
setFlag
public void setFlag(int mask, boolean value)
Sets the value of some flag. The flag is a mask from a given CDKConstant (e.g.IChemObject.AROMATIC
orIChemObject.VISITED
). The flags are intrinsic internal properties and should not be used to store custom values, please useIChemObject.setProperty(Object, Object)
.// set this chem object to be aromatic chemObject.setFlag(CDKConstants.ISAROMATIC, Boolean.TRUE); // ... // indicate we have visited this chem object chemObject.setFlag(CDKConstants.VISITED, Boolean.TRUE);
- Specified by:
setFlag
in interfaceIChemObject
- Parameters:
mask
- flag to set the value forvalue
- value to assign to flag- See Also:
IChemObject.getFlag(int)
-
getFlag
public boolean getFlag(int mask)
Returns the value of a given flag. The flag is a mask from a given CDKConstant (e.g.IChemObject.AROMATIC
).if(chemObject.getFlag(CDKConstants.ISAROMATIC)){ // handle aromatic flag on this chem object }
- Specified by:
getFlag
in interfaceIChemObject
- Parameters:
mask
- flag to retrieve the value of- Returns:
- true if the flag
flag_type
is set - See Also:
IChemObject.setFlag(int, boolean)
-
setProperties
public void setProperties(Map<Object,Object> properties)
Set the properties of this object to the provided map (shallow copy). Any existing properties are removed.- Specified by:
setProperties
in interfaceIChemObject
- Parameters:
properties
- map key-value pairs
-
addProperties
public void addProperties(Map<Object,Object> properties)
Add properties to this object, duplicate keys will replace any existing value.- Specified by:
addProperties
in interfaceIChemObject
- Parameters:
properties
- a Map specifying the property values- See Also:
IChemObject.getProperties()
-
setFlags
public void setFlags(boolean[] newFlags)
Sets the whole set of flags. This set will iteratively invokeIChemObject.setFlag(int, boolean)
for each value in the array and useCDKConstants.FLAG_MASKS
to look up the correct mask. If only a single flag is being set it is a lot faster to useIChemObject.setFlag(int, boolean)
.- Specified by:
setFlags
in interfaceIChemObject
- Parameters:
newFlags
- the new flags to set.- See Also:
IChemObject.setFlag(int, boolean)
,IChemObject.getFlags()
-
getFlags
public boolean[] getFlags()
Returns the whole set of flags. This method will create a new array on each invocation and it is recommend you useIChemObject.getFlagValue()
if you need all the flags. For individual flags please useIChemObject.getFlag(int)
- Specified by:
getFlags
in interfaceIChemObject
- Returns:
- the flags.
- See Also:
IChemObject.setFlags(boolean[])
,IChemObject.getFlag(int)
,IChemObject.getFlagValue()
-
getFlagValue
public Number getFlagValue()
Access the internal value used to store the flags. The flags are stored on a single numeric value and are set/cleared.- Specified by:
getFlagValue
in interfaceIChemObject
- Returns:
- numeric representation of the flags
-
set
public void set(int flags)
Description copied from interface:IChemObject
Set the provided flags. Any on-bits in the input parameter are set on in the ChemObject.- Specified by:
set
in interfaceIChemObject
- Parameters:
flags
- the flags
-
clear
public void clear(int flags)
Description copied from interface:IChemObject
Clear the provided flags. Any on-bits in the input parameter are set on in the ChemObject.- Specified by:
clear
in interfaceIChemObject
- Parameters:
flags
- the flags
-
is
public boolean is(int flags)
Description copied from interface:IChemObject
Test if a flag(s) are set on this ChemObject. If multiple flags are provided they must all be set to return true.atom.set(IS_IN_RING); atom.is(IS_IN_RING); // false! atom.is(IS_IN_RING+IS_AROMATIC); // false! atom.set(IS_AROMATIC); atom.is(IS_IN_RING+IS_AROMATIC); // true!
- Specified by:
is
in interfaceIChemObject
- Parameters:
flags
- the flags
-
flags
public int flags()
Description copied from interface:IChemObject
Access the current value of the flags for this ChemObject.- Specified by:
flags
in interfaceIChemObject
- Returns:
- the flag value (32-bit integer)
-
-