chemaxon.struc
Class CGraph

java.lang.Object
  extended bychemaxon.struc.CGraph
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
MoleculeGraph

public class CGraph
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

Chemical graph.

Version:
3.3.1, 01/27/2004
Author:
Peter Csizmadia
See Also:
CNode, CEdge, Serialized Form

Field Summary
protected  int[][] btab
          Bond table.
protected  int[][] ctab
          Connection table.
protected  int edgeCount
          The number of edges.
protected  CEdge[] edges
          The edges (bonds).
protected  int[] fragIds
          Fragment identifiers.
protected  int[] grinv
          Graph invariants.
protected  long grinvCC
          Graph invariant change count.
protected static int INITIAL_CAPACITY
          Initial capacity of the nodes and edges vectors.
protected  int nFrags
          Number of disconnected fragments.
protected  int nGrinv
          Number of different graph invariants.
protected  int nodeCount
          The number of nodes.
protected  CNode[] nodes
          The nodes (atoms).
protected  CGraph parentGraph
          The structure that contains this graph as a substructure.
protected static int RMCLEANUP_ALL
          Perform all clean-up methods when removing a node or an edge.
protected static int RMCLEANUP_EDGES
          When removing a node or an edge, also remove the edge(s) from the node object(s).
protected static int RMCLEANUP_NONE
          Do not perform any clean-up methods when removing a node or an edge.
protected  int[][] sssr
          SSSR ring node indexes.
protected  CGraph superGraph
          Parent of all parents.
 
Constructor Summary
CGraph()
          Constructs a chemical graph.
CGraph(CGraph p)
          Constructs a chemical graph.
CGraph(CGraph p, int n, int e)
          Constructs a fragment with the specified number of nodes and edges
 
Method Summary
 void add(CEdge edge)
          Adds an edge to the graph.
 void add(CNode node)
          Adds a node to the graph.
protected  void addEdge0(CEdge edge)
          Adds an edge.
protected  int addEdgeWithoutChangingIt(CEdge edge)
          Adds an edge without setting its parentGraph and index fields.
protected  void addNode0(CNode node)
          Adds a node.
protected  int addNodeWithoutChangingIt(CNode node)
          Adds a node without setting its parentGraph and index fields.
 java.lang.Object clone()
          Makes an identical copy of the molecule.
protected  void clonecopy(CGraph graph)
          Copies the clones of nodes and edges of this graph to another one.
 void clonelesscopy(CGraph graph)
          Copy to selection.
 boolean contains(CGraph graph)
          Does the graph contain the specified fragment?
 boolean contains(java.lang.Object o)
          Checks if the graph contains the specified node or edge.
 void findFrag(int i, CGraph frag)
          Determines the subgraph connected to the specified node.
 CGraph[] findFrags(java.lang.Class cl)
          Determines the disconnected fragments and puts them into an array.
 void fuse(CGraph graph)
          Adds those nodes and edges of a graph to this one that are not already elements.
protected  void fuse0(CGraph graph)
          Adds those nodes and edges of a graph to this one that are not already elements.
 int[][] getBtab()
          Gets the edge (bond) table.
 int[][] getCtab()
          Gets the connection table.
 CEdge getEdge(int i)
          Gets an edge.
 int getEdgeCount()
          Gets the number of edges.
 java.util.Vector getEdgeVector()
          Gets the edges.
 CGraph getForefather()
          Gets the first parent.
 int getFragCount()
          Returns the number of fragments.
 int[] getFragIds()
          Gets an array containing the fragment id for each node.
protected  int[] getGrinv()
          Gets the graph invariants array.
 int getGrinv(int[] gi)
          Gets the graph invariants.
 long getGrinvCC()
          Gets the graph invariant change count.
 java.lang.Object getLock()
          Gets the lock object for synchronization.
 CNode getNode(int i)
          Gets a node.
 int getNodeCount()
          Gets the number of nodes.
 java.util.Vector getNodeVector()
          Gets the nodes.
 CGraph getParent()
          Gets the parent graph that contains this substructure.
 int[][] getSSSR()
          Gets the Smallest Set of Smallest Ring node indexes array.
 int indexOf(CEdge edge)
          Gets the index of the specified edge.
 int indexOf(CNode node)
          Gets the index of the specified node.
 boolean isEmpty()
          Ask if the graph is empty or not.
protected  boolean isRealNodeParent()
          Can it be a real node parent?
protected  void makeItSimilar(CGraph g)
          Empty method.
 void mergeNodes(CNode that, CNode a)
          Merges edges of a node with another node, then adds the node to the molecule.
 CGraph newInstance()
          Creates a new CGraph object.
 void pack()
          Reduce memory usage.
 void regenEdges()
          Regenerates the edge vector: remove its elements, then put the edge objects from the nodes into it.
 void removeAll()
          Removes all the nodes and edges.
 void removeAllEdges()
          Removes all edges.
 void removeEdge(CEdge edge)
          Removes an edge by reference.
protected  void removeEdge(CEdge edge, int cleanupFlags)
          Removes an edge by reference.
 void removeEdge(int i)
          Removes an edge from the graph.
protected  void removeEdge(int i, int cleanupFlags)
          Removes an edge from the graph.
 void removeNode(CNode node)
          Removes a node and its edges.
protected  void removeNode(CNode node, int cleanupFlags)
          Removes a node and its edges.
 void removeNode(int i)
          Removes a node and its edges from the graph.
protected  void removeNode(int i, int cleanupFlags)
          Removes a node and its edges from the graph.
protected  void resetCtab()
          An operation performed that changed the connection table and the graph invariants.
protected  void resetGrinvInParents()
          Graph invariants must be recalculated for this graph and all parent graphs.
 void setEdge(int i, CEdge edge)
          Sets the edge at the specified index.
 void setNode(int i, CNode node)
          Sets the node at the specified index.
protected  void setNode0(int i, CNode node)
          Sets the node at the specified index.
 java.lang.String toString()
          Overrides Object.toString() to ease debugging.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INITIAL_CAPACITY

protected static final int INITIAL_CAPACITY
Initial capacity of the nodes and edges vectors.

See Also:
Constant Field Values

RMCLEANUP_NONE

protected static final int RMCLEANUP_NONE
Do not perform any clean-up methods when removing a node or an edge.

Since:
3.1
See Also:
removeNode(CNode, int), removeNode(int, int), removeEdge(CEdge, int), removeEdge(int, int), Constant Field Values

RMCLEANUP_ALL

protected static final int RMCLEANUP_ALL
Perform all clean-up methods when removing a node or an edge.

Since:
3.1
See Also:
removeNode(CNode, int), removeNode(int, int), removeEdge(CEdge, int), removeEdge(int, int), Constant Field Values

RMCLEANUP_EDGES

protected static final int RMCLEANUP_EDGES
When removing a node or an edge, also remove the edge(s) from the node object(s).

Since:
3.1
See Also:
removeNode(CNode, int), removeNode(int, int), removeEdge(CEdge, int), removeEdge(int, int), Constant Field Values

superGraph

protected transient CGraph superGraph
Parent of all parents.


parentGraph

protected transient CGraph parentGraph
The structure that contains this graph as a substructure.


nodes

protected transient CNode[] nodes
The nodes (atoms).


nodeCount

protected transient int nodeCount
The number of nodes.


edges

protected transient CEdge[] edges
The edges (bonds).


edgeCount

protected transient int edgeCount
The number of edges.


sssr

protected transient int[][] sssr
SSSR ring node indexes.


ctab

protected transient int[][] ctab
Connection table.


btab

protected transient int[][] btab
Bond table.


fragIds

protected transient int[] fragIds
Fragment identifiers.


nFrags

protected transient int nFrags
Number of disconnected fragments.


grinv

protected transient int[] grinv
Graph invariants.


nGrinv

protected transient int nGrinv
Number of different graph invariants.


grinvCC

protected transient long grinvCC
Graph invariant change count. The number of times the graph invariants may have changed since the creation of the molecule.

Constructor Detail

CGraph

public CGraph(CGraph p,
              int n,
              int e)
Constructs a fragment with the specified number of nodes and edges

Parameters:
p - the parent graph or null
n - no reallocation needed until the number of nodes is less than this value
e - no reallocation needed until the number of edges is less than this value

CGraph

public CGraph(CGraph p)
Constructs a chemical graph.

Parameters:
p - the parent graph or null

CGraph

public CGraph()
Constructs a chemical graph.

Method Detail

isRealNodeParent

protected boolean isRealNodeParent()
Can it be a real node parent?

Returns:
true
Since:
3.0

getNodeVector

public java.util.Vector getNodeVector()
Gets the nodes.

Returns:
a node vector

getEdgeVector

public java.util.Vector getEdgeVector()
Gets the edges.

Returns:
an edge vector

getNodeCount

public int getNodeCount()
Gets the number of nodes.

Returns:
number of nodes

getNode

public CNode getNode(int i)
Gets a node.

Parameters:
i - node index
Returns:
the node object
Since:
2.6

setNode

public void setNode(int i,
                    CNode node)
Sets the node at the specified index.

Parameters:
i - node index
node - new node reference
Since:
2.9

getEdgeCount

public int getEdgeCount()
Gets the number of edges.

Returns:
number of edges

getEdge

public CEdge getEdge(int i)
Gets an edge.

Parameters:
i - edge index
Returns:
the edge object
Since:
2.6

setEdge

public void setEdge(int i,
                    CEdge edge)
Sets the edge at the specified index.

Parameters:
i - edge index
edge - the edge reference
Since:
2.9

add

public void add(CNode node)
Adds a node to the graph.

Parameters:
node - the node object

add

public void add(CEdge edge)
Adds an edge to the graph. If the graph is a superGraph, the edge is also added to its endpoints (two CNode objects).

Parameters:
edge - the edge object

removeNode

public void removeNode(CNode node)
Removes a node and its edges.

Parameters:
node - the node
Since:
2.5

removeNode

public void removeNode(int i)
Removes a node and its edges from the graph.

Parameters:
i - the node index
Since:
2.5

removeEdge

public void removeEdge(CEdge edge)
Removes an edge by reference.

Parameters:
edge - the edge
Since:
2.5

removeEdge

public void removeEdge(int i)
Removes an edge from the graph.

Parameters:
i - the edge index
Since:
2.5

removeAllEdges

public void removeAllEdges()
Removes all edges.


removeAll

public void removeAll()
Removes all the nodes and edges.


regenEdges

public void regenEdges()
Regenerates the edge vector: remove its elements, then put the edge objects from the nodes into it.


indexOf

public int indexOf(CNode node)
Gets the index of the specified node.

Parameters:
node - the node
Returns:
the index, or -1 if not found
Since:
2.7

indexOf

public int indexOf(CEdge edge)
Gets the index of the specified edge.

Parameters:
edge - the edge
Returns:
the index, or -1 if not found
Since:
2.7

contains

public boolean contains(java.lang.Object o)
Checks if the graph contains the specified node or edge.

Parameters:
o - the node or edge object
Returns:
true if the graph contains the object, false otherwise

isEmpty

public boolean isEmpty()
Ask if the graph is empty or not.

Returns:
true if the graph does not contain any nodes or edges.

removeNode

protected void removeNode(CNode node,
                          int cleanupFlags)
Removes a node and its edges.

Parameters:
node - the node
cleanupFlags - extra clean-up methods
Since:
3.1
See Also:
RMCLEANUP_NONE, RMCLEANUP_ALL, RMCLEANUP_EDGES

removeNode

protected void removeNode(int i,
                          int cleanupFlags)
Removes a node and its edges from the graph.

Parameters:
i - the node index
cleanupFlags - extra clean-up methods
Since:
3.1
See Also:
RMCLEANUP_NONE, RMCLEANUP_ALL, RMCLEANUP_EDGES

removeEdge

protected void removeEdge(CEdge edge,
                          int cleanupFlags)
Removes an edge by reference.

Parameters:
edge - the edge
cleanupFlags - extra clean-up methods
Since:
3.1
See Also:
RMCLEANUP_NONE, RMCLEANUP_ALL, RMCLEANUP_EDGES

removeEdge

protected void removeEdge(int i,
                          int cleanupFlags)
Removes an edge from the graph.

Parameters:
i - the edge index
cleanupFlags - extra clean-up methods
Since:
3.1
See Also:
RMCLEANUP_NONE, RMCLEANUP_ALL, RMCLEANUP_EDGES

fuse0

protected void fuse0(CGraph graph)
Adds those nodes and edges of a graph to this one that are not already elements.

Parameters:
graph - the graph

fuse

public void fuse(CGraph graph)
Adds those nodes and edges of a graph to this one that are not already elements.

Parameters:
graph - the other graph

mergeNodes

public void mergeNodes(CNode that,
                       CNode a)
Merges edges of a node with another node, then adds the node to the molecule.

Parameters:
that - the node
a - the other node

contains

public boolean contains(CGraph graph)
Does the graph contain the specified fragment?

Parameters:
graph - the fragment
Returns:
true if it contains the graph, false if not

clonecopy

protected void clonecopy(CGraph graph)
Copies the clones of nodes and edges of this graph to another one.

Parameters:
graph - the target graph

clonelesscopy

public void clonelesscopy(CGraph graph)
Copy to selection. Copies without cloning.

Parameters:
graph - the target graph (the selection)

clone

public java.lang.Object clone()
Makes an identical copy of the molecule. The new molecule will not be subgraph of the parentGraph of the original one. It will be its own superGraph.

Returns:
the clone

toString

public java.lang.String toString()
Overrides Object.toString() to ease debugging. Returns a string consisting of the classname (without the package name!), the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object.

Returns:
a string representation of the object

getSSSR

public final int[][] getSSSR()
Gets the Smallest Set of Smallest Ring node indexes array. If the SSSR array is not calculated for the molecule, then create it. sssr[i][j] is the j-th node index at the i-th SSSR ring in the molecule.

Returns:
the sssr node index arrays
Since:
3.0

getCtab

public int[][] getCtab()
Gets the connection table. If there is no connection table for the graph, then creates it. ctab[i][j] will be the index of the jth neighbor of the ith node.

Returns:
the ctab array
Since:
2.6

getBtab

public int[][] getBtab()
Gets the edge (bond) table. If there is no edge table for the molecule, then create it. btab[i][j] will be the index of the edge between nodes i and j, or -1 if there is no edge.

Returns:
the btab array
Since:
2.6

getGrinv

public int getGrinv(int[] gi)
Gets the graph invariants.

Parameters:
gi - the output array
Returns:
zero

getGrinv

protected int[] getGrinv()
Gets the graph invariants array.

Returns:
the grinv field
Since:
3.0

getGrinvCC

public final long getGrinvCC()
Gets the graph invariant change count. Returns the number of times the graph invariants may have changed since the creation of the molecule.

Returns:
graph invariant change count

resetGrinvInParents

protected final void resetGrinvInParents()
Graph invariants must be recalculated for this graph and all parent graphs.


getFragCount

public final int getFragCount()
Returns the number of fragments.

Returns:
the number of fragments
Since:
3.01

getFragIds

public final int[] getFragIds()
Gets an array containing the fragment id for each node.

Returns:
array of fragment identifiers
Since:
2.6

findFrags

public final CGraph[] findFrags(java.lang.Class cl)
Determines the disconnected fragments and puts them into an array. Atoms are removed from the original molecule object unless the fragment class is SelectionMolecule.class. The original node order is preserved in the returned fragments. Fragment order is also determined by the original node order. The first fragment is the one containing node 0, the second fragment is the one containing the smallest indexed node not in the first fragment, etc.

Parameters:
cl - create fragment objects of this class
Returns:
array of fragments
Since:
3.0

findFrag

public final void findFrag(int i,
                           CGraph frag)
Determines the subgraph connected to the specified node. Subsequent calls with different node (i) argument are possible because only those nodes and edges are added that are still not elements of frag. Nodes are removed from the original graph object unless the frag is a SelectionMolecule.

Parameters:
i - node index
frag - add the nodes and edges to this CGraph
Since:
2.6

getLock

public final java.lang.Object getLock()
Gets the lock object for synchronization. The lock object is the top parent.

Returns:
the lock object
Since:
2.6

getParent

public final CGraph getParent()
Gets the parent graph that contains this substructure.

Returns:
the parent, or null if this is the supergraph
Since:
2.6

getForefather

public final CGraph getForefather()
Gets the first parent.

Returns:
parent of all parents
Since:
2.9.11

pack

public void pack()
Reduce memory usage.


newInstance

public CGraph newInstance()
Creates a new CGraph object.

Returns:
new CGraph object

makeItSimilar

protected void makeItSimilar(CGraph g)
Empty method.

Parameters:
g - a CGraph object

resetCtab

protected void resetCtab()
An operation performed that changed the connection table and the graph invariants.

Since:
2.6

addNode0

protected void addNode0(CNode node)
Adds a node.

Parameters:
node - the node reference

addNodeWithoutChangingIt

protected final int addNodeWithoutChangingIt(CNode node)
Adds a node without setting its parentGraph and index fields.

Parameters:
node - the node reference
Returns:
the new node index

setNode0

protected void setNode0(int i,
                        CNode node)
Sets the node at the specified index.

Parameters:
i - node index
node - new node reference
Since:
2.10.5

addEdge0

protected void addEdge0(CEdge edge)
Adds an edge.

Parameters:
edge - the edge reference

addEdgeWithoutChangingIt

protected final int addEdgeWithoutChangingIt(CEdge edge)
Adds an edge without setting its parentGraph and index fields.

Parameters:
edge - the edge reference
Returns:
the new edge index