Class BondedAtom

  • All Implemented Interfaces:
    java.lang.Iterable<BondedAtom>

    public final class BondedAtom
    extends java.lang.Object
    implements java.lang.Iterable<BondedAtom>
    Represents an atom in an organic molecule and its bonds.

    Since references to all other atoms in the molecule can be reached through the methods of this class, it also represents the overall molecule.

    One atom can be connected to another through at least one bond. For example, carbon should have 4 bonds, but may be connected to only 3 other atoms if one of the connections is a double bond.

    For convenience BondedAtom implements the Iterable interface allow you to iterate through all of its neighbors using the enhanced Java for-each loop. See getMolecularWeight in MoleculeAnalyzer for an example.

    • Constructor Summary

      Constructors 
      Constructor Description
      BondedAtom​(ChemicalElement setElement, BondedAtom[] setOtherAtoms, int[] setBondCounts)
      Creates a new atom connected to the given others.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<edu.illinois.cs.cs125.mp5.lib.BondedAtom.BondInfo> getBondInfo()
      Return an iterable list of bond information about all neighboring atoms.
      BondedAtom getConnectedAtom​(int index)
      Convenience method used by the test suite.
      ChemicalElement getElement()
      Gets what element this atom is an instance of.
      boolean hasSubstituent​(java.util.List<BondedAtom> backbone)
      Convenience method for determining of this atom has a substituent.
      int highPrioritySubstituentCount()
      Return the count of high-priority substituents attached to this atom.
      boolean isCarbon()
      Convenience method for determining if this atom is carbon.
      boolean isSubstituent​(java.util.List<BondedAtom> backbone)
      Convenience method for determining if this atom is a substituent.
      java.util.Iterator<BondedAtom> iterator()
      Return an iterator of BondedAtoms connected to this BondedAtom.
      int lowPrioritySubstituentCount​(java.util.List<BondedAtom> backbone)
      Return the count of high-priority substituents attached to this atom.
      java.lang.String nameEndGroup()
      Gets the name of the end group substituent, if any, on this carbon.
      java.lang.String nameSubstituent​(BondedAtom substituent)
      Gets the name of a substituent starting at this carbon.
      java.lang.String toString()
      Returns the string representation of this atom.
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • BondedAtom

        public BondedAtom​(ChemicalElement setElement,
                          BondedAtom[] setOtherAtoms,
                          int[] setBondCounts)
        Creates a new atom connected to the given others.
        Parameters:
        setElement - What element this atom is.
        setOtherAtoms - The distinct other atoms this atom is connected to.
        setBondCounts - The bond counts in each connection.
    • Method Detail

      • getElement

        public ChemicalElement getElement()
        Gets what element this atom is an instance of.
        Returns:
        This atom's element.
      • iterator

        public java.util.Iterator<BondedAtom> iterator()
        Return an iterator of BondedAtoms connected to this BondedAtom.

        This is commonly used by the molecular analysis code to explore the molecule graph.

        Specified by:
        iterator in interface java.lang.Iterable<BondedAtom>
        Returns:
        an iterator of BondedAtoms connected to this BondedAtom.
      • getBondInfo

        public java.util.List<edu.illinois.cs.cs125.mp5.lib.BondedAtom.BondInfo> getBondInfo()
        Return an iterable list of bond information about all neighboring atoms.

        Each BondInfo object includes both a reference to the neighbor and it bond count. It is frequently more convenient to use the other iterator method above that returns BondedAtoms. Only use this if you need both the BondedAtom and the bond count.

        Returns:
        an iterator of BondInfo objects describing our neighbor atoms.
      • getConnectedAtom

        public BondedAtom getConnectedAtom​(int index)
        Convenience method used by the test suite.
        Parameters:
        index - index of the BondedAtom to return
        Returns:
        the BondedAtom at that position or null if the index is invalid
      • isCarbon

        public boolean isCarbon()
        Convenience method for determining if this atom is carbon.
        Returns:
        whether this atom is carbon
      • isSubstituent

        public boolean isSubstituent​(java.util.List<BondedAtom> backbone)
        Convenience method for determining if this atom is a substituent.
        Parameters:
        backbone - the backbone of this molecule to use to identify off-backbone carbons
        Returns:
        whether this atom is a substituent
      • hasSubstituent

        public boolean hasSubstituent​(java.util.List<BondedAtom> backbone)
        Convenience method for determining of this atom has a substituent.

        This could either mean it has an attached substituent or off-backbone carbon.

        Parameters:
        backbone - the backbone of this molecule to use to identify off-backbone carbons
        Returns:
        true if this atom has a connected substituent, and false otherwise
      • highPrioritySubstituentCount

        public int highPrioritySubstituentCount()
        Return the count of high-priority substituents attached to this atom.
        Returns:
        the count of high-priority substituents attached to this atom
      • lowPrioritySubstituentCount

        public int lowPrioritySubstituentCount​(java.util.List<BondedAtom> backbone)
        Return the count of high-priority substituents attached to this atom.
        Parameters:
        backbone - the backbone of this molecule to use to identify off-backbone carbons
        Returns:
        the count of high-priority substituents attached to this atom
      • nameSubstituent

        public java.lang.String nameSubstituent​(BondedAtom substituent)
        Gets the name of a substituent starting at this carbon.

        Assumes that there is no end group on the core/base carbon.

        Parameters:
        substituent - the first atom of the substituent
        Returns:
        the substituent's name, or null if none exists or this atom is not carbon
      • nameEndGroup

        public java.lang.String nameEndGroup()
        Gets the name of the end group substituent, if any, on this carbon.
        Returns:
        the name of any end substituent, or null if none exists or this atom is not carbon
      • toString

        public java.lang.String toString()
        Returns the string representation of this atom.
        Overrides:
        toString in class java.lang.Object
        Returns:
        This atom's element and instance ID.