chemaxon.struc
Class Sgroup

java.lang.Object
  extended bychemaxon.struc.Sgroup
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
MultipleSgroup, SuperatomSgroup

public class Sgroup
extends java.lang.Object
implements java.io.Serializable

S-group.

Since:
Marvin 3.0
Version:
3.5.2, 12/15/2004
Author:
Peter Csizmadia
See Also:
Serialized Form

Field Summary
static int SCN_EITHER_UNKNOWN
          Either unknown S-group connectivity.
static int SCN_HEAD_TO_HEAD
          Head-to-head S-group connectivity.
static int SCN_HEAD_TO_TAIL
          Head-to-tail S-group connectivity.
protected  SelectionMolecule sgroupGraph
          The S-group's internal structure.
protected  int sgroupType
          The S-group type.
static int SORT_CHILD_PARENT
          Parent-child sort order.
static int SORT_PARENT_CHILD
          Parent-child sort order.
static int SST_ALTERNATING
          Alternating polymer S-group subtype.
static int SST_BLOCK
          Block polymer S-group subtype.
static int SST_RANDOM
          Random polymer S-group subtype.
static int ST_ANY
          Any polymer S-group type.
static int ST_COPOLYMER
          Copolymer S-group type.
static int ST_CROSSLINK
          Crosslink S-group type.
static int ST_DATA
          Data S-group type.
static int ST_FORMULATION
          Formulation S-group type.
static int ST_GENERIC
          Generic S-group type.
static int ST_MER
          Mer S-group type.
static int ST_MIXTURE
          Mixture S-group type.
static int ST_MODIFICATION
          Modification S-group type.
static int ST_MONOMER
          Monomer S-group type.
static int ST_MULTIPLE
          Multiple group S-group type.
static int ST_SRU
          SRU S-group type.
static int ST_SUPERATOM
          Superatom S-group type.
static int XSTATE_C
          S-group is contracted (useful only in GUI!).
static int XSTATE_NONE
          S-group is in an undetermined state.
static int XSTATE_X
          S-group is expanded.
static int XSTATE_XC
          S-group is expanded but its atoms have the same coordinates as in contracted state.
 
Constructor Summary
  Sgroup(Molecule parent, int t)
          Creates an S-group with the specified parent and type.
  Sgroup(Molecule parent, int t, int xstate)
          Creates an S-group with the specified parent and type.
protected Sgroup(Sgroup sg, Molecule m, Sgroup psg)
          Copy constructor.
 
Method Summary
 void add(MolAtom a)
          Adds a new atom to the S-group.
 void addChildSgroup(Sgroup sg)
          Adds a child S-group.
 boolean areChildSgroupsVisible()
          Checks whether the child S-groups are visible.
 Sgroup cloneSgroup(Molecule m, Sgroup psg)
          Gets a new Sgroup instance.
 SelectionMolecule cloneStructure()
          Gets the clone of the structure stored.
 boolean containsAllAtomsOf(Sgroup sg)
          Checks if the S-group contains the atoms of another S-group.
protected  boolean contract(int opts)
          Sets the state to XSTATE_C.
 int countAllAtoms()
          Counts the total number of atoms recursively.
 Molecule createMolecule()
          Creates a molecule object that contains only this group.
protected  boolean expand(int f)
          Sets the state to XSTATE_X or XSTATE_XC.
 MolBond[] findCrossingBonds()
          Finds the crossing bonds.
 Sgroup findSmallestSgroupContaining(MolAtom a)
          Finds the smallest S-group containing the specified node.
 Sgroup findSmallestSgroupOf(MolAtom a)
          Finds the smallest S-group that has the specified node.
 MolAtom getAtom(int i)
          Gets an atom in the S-group.
 MolAtom[] getAtomArray()
          Gets the array of atoms in the S-group.
 int getAtomCount()
          Gets the number of atoms in the S-group.
 Sgroup getChildSgroup(int i)
          Gets a child S-group.
 int getChildSgroupCount()
          Gets the number of child S-groups.
 int getConnectivity()
          Gets S-group connectivity.
 MolAtom[] getCrossingAtoms(MolBond[] xbonds)
          Gets the atoms that have crossing bonds.
 Molecule getParentMolecule()
          Gets the parent molecule.
 Sgroup getParentSgroup()
          Gets the parent S-group.
 SelectionMolecule getSgroupGraph()
          Gets the molecule graph.
 java.lang.String getSubscript()
          Gets the subscript for non-superatom S-groups.
 int getSubType()
          Gets polymer S-group subtype.
 java.lang.String getSuperscript()
          Gets the superscript for non-superatom S-groups.
 int getType()
          Gets S-group type.
 int getXState()
          Gets the expanded/contracted state.
 boolean hasAtom(MolAtom a)
          Is the specified atom an element of this group?
 boolean hasBrackets()
          Checks if brackets should be painted or not.
 int indexOf(MolAtom a)
          Gets the atom index in the S-group graph.
 boolean isBracketVisible()
          Tests whether the bracket is visible.
 boolean isEmpty()
          Is it an empty S-group?
 boolean isVisible()
          Checks whether this group is 'visible' (all parents are expanded in case of superatom S-groups) or not.
 void removeAtom(MolAtom a)
          Removes an atom and its bonds from the S-group.
protected  void removeBond(MolBond b)
          Removes a bond from the S-group.
 void removeEdges()
          Removes the edge references.
protected static void removeGroupedAtom(MoleculeGraph m, MolAtom a, MolBond[] v)
          Removes an atom from the molecule and remove its specified bonds.
 void replaceAtom(MolAtom olda, MolAtom newa)
          Replace an existing atom by a new one in this S-group and its parent (recursively).
 void setAtom(int i, MolAtom a)
          Sets the specified atom in the S-group graph.
 void setConnectivity(int c)
          Sets S-group connectivity.
 void setGUIStateRecursively(boolean v)
          Sets the expanded/contracted state recursively.
protected  void setParentMolecule(Molecule p)
          Sets the parent molecule.
 void setSgroupGraph(SelectionMolecule smol)
          Sets the molecule graph.
 void setSubscript(java.lang.String s)
          Sets the subscript for non-superatom S-groups.
 void setSubType(int t)
          Sets polymer S-group subtype.
 void setXState(int state)
          Sets the expanded/contracted state.
static void sort(Sgroup[] sgroups, int o)
          Sorts S-groups in parent-child or child-parent order.
 java.lang.String toString()
          Overrides Object.toString() to ease debugging.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ST_SUPERATOM

public static final int ST_SUPERATOM
Superatom S-group type. @see #getType

See Also:
Constant Field Values

ST_MULTIPLE

public static final int ST_MULTIPLE
Multiple group S-group type. @see #getType

See Also:
Constant Field Values

ST_SRU

public static final int ST_SRU
SRU S-group type. @see #getType

See Also:
Constant Field Values

ST_MONOMER

public static final int ST_MONOMER
Monomer S-group type. @see #getType

See Also:
Constant Field Values

ST_MER

public static final int ST_MER
Mer S-group type. @see #getType

See Also:
Constant Field Values

ST_COPOLYMER

public static final int ST_COPOLYMER
Copolymer S-group type. @see #getType

See Also:
Constant Field Values

ST_CROSSLINK

public static final int ST_CROSSLINK
Crosslink S-group type. @see #getType

See Also:
Constant Field Values

ST_MODIFICATION

public static final int ST_MODIFICATION
Modification S-group type. @see #getType

See Also:
Constant Field Values

ST_MIXTURE

public static final int ST_MIXTURE
Mixture S-group type. @see #getType

See Also:
Constant Field Values

ST_FORMULATION

public static final int ST_FORMULATION
Formulation S-group type. @see #getType

See Also:
Constant Field Values

ST_DATA

public static final int ST_DATA
Data S-group type. @see #getType

See Also:
Constant Field Values

ST_ANY

public static final int ST_ANY
Any polymer S-group type. @see #getType

See Also:
Constant Field Values

ST_GENERIC

public static final int ST_GENERIC
Generic S-group type. @see #getType

See Also:
Constant Field Values

SST_ALTERNATING

public static final int SST_ALTERNATING
Alternating polymer S-group subtype. @see #getSubType

See Also:
Constant Field Values

SST_RANDOM

public static final int SST_RANDOM
Random polymer S-group subtype. @see #getSubType

See Also:
Constant Field Values

SST_BLOCK

public static final int SST_BLOCK
Block polymer S-group subtype. @see #getSubType

See Also:
Constant Field Values

SCN_EITHER_UNKNOWN

public static final int SCN_EITHER_UNKNOWN
Either unknown S-group connectivity. @see #getConnectivity

See Also:
Constant Field Values

SCN_HEAD_TO_HEAD

public static final int SCN_HEAD_TO_HEAD
Head-to-head S-group connectivity. @see #getConnectivity

See Also:
Constant Field Values

SCN_HEAD_TO_TAIL

public static final int SCN_HEAD_TO_TAIL
Head-to-tail S-group connectivity. @see #getConnectivity

See Also:
Constant Field Values

XSTATE_NONE

public static final int XSTATE_NONE
S-group is in an undetermined state.

Since:
Marvin 3.4, 05/04/2004
See Also:
setXState(int), Constant Field Values

XSTATE_X

public static final int XSTATE_X
S-group is expanded.

Since:
Marvin 3.4, 05/04/2004
See Also:
setXState(int), Constant Field Values

XSTATE_C

public static final int XSTATE_C
S-group is contracted (useful only in GUI!).

Since:
Marvin 3.4, 05/04/2004
See Also:
setXState(int), Constant Field Values

XSTATE_XC

public static final int XSTATE_XC
S-group is expanded but its atoms have the same coordinates as in contracted state.

Since:
Marvin 3.4, 05/04/2004
See Also:
setXState(int), Constant Field Values

SORT_PARENT_CHILD

public static final int SORT_PARENT_CHILD
Parent-child sort order.

Since:
Marvin 3.4
See Also:
sort(Sgroup[], int), Constant Field Values

SORT_CHILD_PARENT

public static final int SORT_CHILD_PARENT
Parent-child sort order.

Since:
Marvin 3.4
See Also:
sort(Sgroup[], int), Constant Field Values

sgroupType

protected transient int sgroupType
The S-group type.


sgroupGraph

protected transient SelectionMolecule sgroupGraph
The S-group's internal structure.

Constructor Detail

Sgroup

public Sgroup(Molecule parent,
              int t)
Creates an S-group with the specified parent and type.

Parameters:
parent - the parent molecule
t - S-group type

Sgroup

public Sgroup(Molecule parent,
              int t,
              int xstate)
Creates an S-group with the specified parent and type.

Parameters:
parent - the parent molecule
t - S-group type
xstate - the expanded state
Since:
Marvin 3.4, 05/04/2004
See Also:
setXState(int)

Sgroup

protected Sgroup(Sgroup sg,
                 Molecule m,
                 Sgroup psg)
Copy constructor.

Parameters:
sg - the S-group to copy
m - the new parent molecule
psg - the new parent S-group or null
Since:
Marvin 3.4
Method Detail

setSgroupGraph

public void setSgroupGraph(SelectionMolecule smol)
Sets the molecule graph.

Parameters:
smol - the molecule graph
Since:
Marvin 3.3, 11/03/2003

getSgroupGraph

public SelectionMolecule getSgroupGraph()
Gets the molecule graph.

Returns:
the molecule graph
Since:
Marvin 3.3, 11/03/2003

setParentMolecule

protected final void setParentMolecule(Molecule p)
Sets the parent molecule.

Parameters:
p - the parent molecule

getParentMolecule

public final Molecule getParentMolecule()
Gets the parent molecule.

Returns:
the parent molecule

getChildSgroupCount

public final int getChildSgroupCount()
Gets the number of child S-groups.

Returns:
the number of children
Since:
Marvin 3.4

getChildSgroup

public final Sgroup getChildSgroup(int i)
Gets a child S-group.

Parameters:
i - the child index
Returns:
the child
Since:
Marvin 3.4

addChildSgroup

public final void addChildSgroup(Sgroup sg)
Adds a child S-group.

Parameters:
sg - the child
Since:
Marvin 3.4

findSmallestSgroupContaining

public final Sgroup findSmallestSgroupContaining(MolAtom a)
Finds the smallest S-group containing the specified node. If this parent contains the node, then it searches the children recursively.

Parameters:
a - the node
Returns:
the S-group or null if not found
Since:
Marvin 3.4, 05/05/2004

findSmallestSgroupOf

public final Sgroup findSmallestSgroupOf(MolAtom a)
Finds the smallest S-group that has the specified node. If this parent has the node, then it searches the children recursively.

Parameters:
a - the node
Returns:
the S-group or null if not found
Since:
Marvin 3.4, 05/05/2004

getParentSgroup

public final Sgroup getParentSgroup()
Gets the parent S-group.

Returns:
the parent S-group
Since:
Marvin 3.4

getXState

public final int getXState()
Gets the expanded/contracted state. WARNING! This method is under development, do not use it yet!

Returns:
the expanded/contracted state
Since:
Marvin 3.4, 05/04/2004
See Also:
XSTATE_X, XSTATE_C, XSTATE_XC

setXState

public final void setXState(int state)
                     throws java.lang.IllegalArgumentException
Sets the expanded/contracted state. WARNING! This method is under development, do not use it yet!

Parameters:
state - the expanded/contracted state
Throws:
java.lang.IllegalArgumentException - if the group is invisible (it has a non-expanded parent)
Since:
Marvin 3.4, 05/04/2004
See Also:
XSTATE_X, XSTATE_C, XSTATE_XC

setGUIStateRecursively

public final void setGUIStateRecursively(boolean v)
                                  throws java.lang.IllegalArgumentException
Sets the expanded/contracted state recursively. WARNING! This method is under development, do not use it yet!

Parameters:
v - true sets XSTATE_C if previous state was XSTATE_XC, false sets XSTATE_XC if previous state was XSTATE_C, no operation in other cases
Throws:
java.lang.IllegalArgumentException - if the group is invisible (it has a non-expanded parent)
Since:
Marvin 3.4, 05/04/2004
See Also:
setXState(int)

expand

protected boolean expand(int f)
                  throws java.lang.IllegalArgumentException
Sets the state to XSTATE_X or XSTATE_XC.

Parameters:
f - options, only the Expandable.REVERSIBLE_EXPAND and the Expandable.MDL_EXPAND flags are taken into account
Returns:
true
Throws:
java.lang.IllegalArgumentException - if the group is invisible (it has a non-expanded parent)
Since:
Marvin 3.4, 05/04/2004
See Also:
setXState(int)

contract

protected boolean contract(int opts)
                    throws java.lang.IllegalArgumentException
Sets the state to XSTATE_C.

Parameters:
opts - neglected
Returns:
true
Throws:
java.lang.IllegalArgumentException - if the group is invisible (it has a non-expanded parent)
Since:
Marvin 3.4, 05/04/2004
See Also:
setXState(int)

getSuperscript

public java.lang.String getSuperscript()
Gets the superscript for non-superatom S-groups.

Returns:
the superscript

getSubscript

public java.lang.String getSubscript()
Gets the subscript for non-superatom S-groups.

Returns:
the subscript

setSubscript

public void setSubscript(java.lang.String s)
Sets the subscript for non-superatom S-groups.

Parameters:
s - the subscript

getType

public int getType()
Gets S-group type.

Returns:
the type
See Also:
ST_SUPERATOM, ST_MULTIPLE, ST_SRU, ST_MONOMER, ST_MER, ST_COPOLYMER, ST_CROSSLINK, ST_MODIFICATION, ST_MODIFICATION, ST_MIXTURE, ST_FORMULATION, ST_DATA, ST_ANY, ST_GENERIC

getSubType

public int getSubType()
Gets polymer S-group subtype.

Returns:
the type
See Also:
SST_ALTERNATING, SST_RANDOM, SST_BLOCK

setSubType

public void setSubType(int t)
Sets polymer S-group subtype.

Parameters:
t - the type
See Also:
getSubType()

getConnectivity

public int getConnectivity()
Gets S-group connectivity.

Returns:
the connectivity
See Also:
SCN_EITHER_UNKNOWN, SCN_HEAD_TO_HEAD, SCN_HEAD_TO_TAIL

setConnectivity

public void setConnectivity(int c)
Sets S-group connectivity.

Parameters:
c - the connectivity
See Also:
getConnectivity()

hasBrackets

public boolean hasBrackets()
Checks if brackets should be painted or not.

Returns:
always true in the default implementation
Since:
Marvin 3.3

cloneStructure

public final SelectionMolecule cloneStructure()
Gets the clone of the structure stored.

Returns:
the clone

createMolecule

public Molecule createMolecule()
Creates a molecule object that contains only this group.

Returns:
the molecule

getAtomArray

public final MolAtom[] getAtomArray()
Gets the array of atoms in the S-group.

Returns:
the atom array

getAtom

public final MolAtom getAtom(int i)
Gets an atom in the S-group.

Parameters:
i - the atom index
Returns:
the atom

countAllAtoms

public final int countAllAtoms()
Counts the total number of atoms recursively.

Returns:
the number of atoms

isEmpty

public final boolean isEmpty()
Is it an empty S-group?

Returns:
true if the S-group does not contain any atoms, false otherwise

cloneSgroup

public Sgroup cloneSgroup(Molecule m,
                          Sgroup psg)
Gets a new Sgroup instance.

Parameters:
m - the new parent molecule
psg - the new parent S-group
Returns:
the new object
Since:
Marvin 3.4

getAtomCount

public final int getAtomCount()
Gets the number of atoms in the S-group.

Returns:
the number of atoms

indexOf

public int indexOf(MolAtom a)
Gets the atom index in the S-group graph.

Parameters:
a - the atom
Returns:
the index or -1 if not found

hasAtom

public boolean hasAtom(MolAtom a)
Is the specified atom an element of this group?

Parameters:
a - the atom
Returns:
true if it contains the atom, false otherwise
Since:
Marvin 3.4

containsAllAtomsOf

public boolean containsAllAtomsOf(Sgroup sg)
Checks if the S-group contains the atoms of another S-group.

Returns:
true if this S-group contains the specified one
Since:
Marvin 3.4

add

public void add(MolAtom a)
Adds a new atom to the S-group.

Parameters:
a - the atom

setAtom

public void setAtom(int i,
                    MolAtom a)
Sets the specified atom in the S-group graph.

Parameters:
i - the index
a - the atom

removeEdges

public void removeEdges()
Removes the edge references.


removeAtom

public void removeAtom(MolAtom a)
Removes an atom and its bonds from the S-group.

Parameters:
a - the atom

removeBond

protected void removeBond(MolBond b)
Removes a bond from the S-group.

Parameters:
b - the bond

replaceAtom

public void replaceAtom(MolAtom olda,
                        MolAtom newa)
Replace an existing atom by a new one in this S-group and its parent (recursively).

Parameters:
olda - the original atom
newa - the new atom
Since:
3.5.2, 12/15/2004

findCrossingBonds

public MolBond[] findCrossingBonds()
Finds the crossing bonds. Use only when the S-group is expanded.

Returns:
the attachment bonds
Since:
Marvin 3.3

getCrossingAtoms

public MolAtom[] getCrossingAtoms(MolBond[] xbonds)
                           throws java.lang.IllegalArgumentException
Gets the atoms that have crossing bonds.

Parameters:
xbonds - the crossing bonds
Returns:
the attachment atoms
Throws:
java.lang.IllegalArgumentException - if a bond in the specified array is not a crossing bond
Since:
Marvin 3.3

removeGroupedAtom

protected static void removeGroupedAtom(MoleculeGraph m,
                                        MolAtom a,
                                        MolBond[] v)
Removes an atom from the molecule and remove its specified bonds.

Parameters:
m - the molecule graph
a - the atom
v - bonds to remove from the atom, remove all bonds if null
See Also:
CGraph.removeNode(int, int)

areChildSgroupsVisible

public boolean areChildSgroupsVisible()
Checks whether the child S-groups are visible.

Returns:
true if children are visible, false otherwise
Since:
Marvin 3.4

isVisible

public final boolean isVisible()
Checks whether this group is 'visible' (all parents are expanded in case of superatom S-groups) or not.

Returns:
true if the group is visible, false otherwise
Since:
Marvin 3.4

isBracketVisible

public boolean isBracketVisible()
Tests whether the bracket is visible.

Returns:
true if visible, false otherwise
Since:
Marvin 3.5.1, 11/12/2004

sort

public static void sort(Sgroup[] sgroups,
                        int o)
Sorts S-groups in parent-child or child-parent order.

Parameters:
sgroups - the array to sort
o - the sort order
Since:
Marvin 3.4
See Also:
SORT_PARENT_CHILD, SORT_CHILD_PARENT

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
Since:
Marvin 3.4